Add being able to set origin of mesh to the local mesh origin. fix centering several meshes.
This commit is contained in:
@@ -372,6 +372,7 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj
|
||||
SERIALIZE(Scale);
|
||||
SERIALIZE(Rotation);
|
||||
SERIALIZE(Translation);
|
||||
SERIALIZE(UseLocalOrigin);
|
||||
SERIALIZE(CenterGeometry);
|
||||
SERIALIZE(Duration);
|
||||
SERIALIZE(FramesRange);
|
||||
@@ -418,6 +419,7 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi
|
||||
DESERIALIZE(Scale);
|
||||
DESERIALIZE(Rotation);
|
||||
DESERIALIZE(Translation);
|
||||
DESERIALIZE(UseLocalOrigin);
|
||||
DESERIALIZE(CenterGeometry);
|
||||
DESERIALIZE(Duration);
|
||||
DESERIALIZE(FramesRange);
|
||||
@@ -1089,11 +1091,16 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
|
||||
// Prepare import transformation
|
||||
Transform importTransform(options.Translation, options.Rotation, Float3(options.Scale));
|
||||
if (options.UseLocalOrigin && data.LODs.HasItems() && data.LODs[0].Meshes.HasItems())
|
||||
{
|
||||
importTransform.Translation -= importTransform.Orientation * data.LODs[0].Meshes[0]->OriginTranslation * importTransform.Scale;
|
||||
}
|
||||
if (options.CenterGeometry && data.LODs.HasItems() && data.LODs[0].Meshes.HasItems())
|
||||
{
|
||||
// Calculate the bounding box (use LOD0 as a reference)
|
||||
BoundingBox box = data.LODs[0].GetBox();
|
||||
importTransform.Translation -= box.GetCenter();
|
||||
auto center = data.LODs[0].Meshes[0]->OriginOrientation * importTransform.Orientation * box.GetCenter() * importTransform.Scale * data.LODs[0].Meshes[0]->Scaling;
|
||||
importTransform.Translation -= center;
|
||||
}
|
||||
const bool applyImportTransform = !importTransform.IsIdentity();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user