Merge branch 'Tryibion-local-origin-multi-mesh'
This commit is contained in:
@@ -609,7 +609,7 @@ namespace FlaxEditor.Viewport
|
||||
base.OnMouseMove(location);
|
||||
|
||||
// Don't allow rubber band selection when gizmo is controlling mouse, vertex painting mode, or cloth painting is enabled
|
||||
bool canStart = !((Gizmos.Active.IsControllingMouse || Gizmos.Active is VertexPaintingGizmo || Gizmos.Active is ClothPaintingGizmo) || IsControllingMouse || IsRightMouseButtonDown);
|
||||
bool canStart = !((Gizmos.Active.IsControllingMouse || Gizmos.Active is VertexPaintingGizmo || Gizmos.Active is ClothPaintingGizmo) || IsControllingMouse || IsRightMouseButtonDown || IsAltKeyDown);
|
||||
_rubberBandSelector.TryCreateRubberBand(canStart, _viewMousePos, ViewFrustum);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
Array<BlendShape> BlendShapes;
|
||||
|
||||
/// <summary>
|
||||
/// Global translation for this mesh to be at it's local origin.
|
||||
/// Local translation for this mesh to be at it's local origin.
|
||||
/// </summary>
|
||||
Vector3 OriginTranslation = Vector3::Zero;
|
||||
|
||||
|
||||
@@ -645,24 +645,10 @@ bool ImportMesh(int32 index, ModelData& result, AssimpImporterData& data, String
|
||||
// Link mesh
|
||||
meshData->NodeIndex = nodeIndex;
|
||||
AssimpNode* curNode = &data.Nodes[meshData->NodeIndex];
|
||||
Vector3 translation = Vector3::Zero;
|
||||
Vector3 scale = Vector3::One;
|
||||
Quaternion rotation = Quaternion::Identity;
|
||||
|
||||
while (true)
|
||||
{
|
||||
translation += curNode->LocalTransform.Translation;
|
||||
scale *= curNode->LocalTransform.Scale;
|
||||
rotation *= curNode->LocalTransform.Orientation;
|
||||
|
||||
if (curNode->ParentIndex == -1)
|
||||
break;
|
||||
curNode = &data.Nodes[curNode->ParentIndex];
|
||||
}
|
||||
|
||||
meshData->OriginTranslation = translation;
|
||||
meshData->OriginOrientation = rotation;
|
||||
meshData->Scaling = scale;
|
||||
|
||||
meshData->OriginTranslation = curNode->LocalTransform.Translation;
|
||||
meshData->OriginOrientation = curNode->LocalTransform.Orientation;
|
||||
meshData->Scaling = curNode->LocalTransform.Scale;
|
||||
|
||||
if (result.LODs.Count() <= lodIndex)
|
||||
result.LODs.Resize(lodIndex + 1);
|
||||
|
||||
@@ -1042,7 +1042,8 @@ bool ProcessMesh(ModelData& result, OpenFbxImporterData& data, const ofbx::Mesh*
|
||||
}*/
|
||||
|
||||
// Get local transform for origin shifting translation
|
||||
auto translation = ToMatrix(aMesh->getGlobalTransform()).GetTranslation();
|
||||
|
||||
auto translation = Float3((float)aMesh->getLocalTranslation().x, (float)aMesh->getLocalTranslation().y, (float)aMesh->getLocalTranslation().z);
|
||||
auto scale = data.GlobalSettings.UnitScaleFactor;
|
||||
if (data.GlobalSettings.CoordAxis == ofbx::CoordSystem_RightHanded)
|
||||
mesh.OriginTranslation = scale * Vector3(translation.X, translation.Y, -translation.Z);
|
||||
|
||||
@@ -1549,23 +1549,25 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
|
||||
|
||||
// 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();
|
||||
auto center = data.LODs[0].Meshes[0]->OriginOrientation * importTransform.Orientation * box.GetCenter() * importTransform.Scale * data.LODs[0].Meshes[0]->Scaling;
|
||||
importTransform.Translation -= center;
|
||||
}
|
||||
|
||||
// Apply the import transformation
|
||||
if (!importTransform.IsIdentity() && data.Nodes.HasItems())
|
||||
if ((!importTransform.IsIdentity() || options.UseLocalOrigin || options.CenterGeometry) && data.Nodes.HasItems())
|
||||
{
|
||||
if (options.Type == ModelType::SkinnedModel)
|
||||
{
|
||||
// Setup other transform options
|
||||
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();
|
||||
auto center = data.LODs[0].Meshes[0]->OriginOrientation * importTransform.Orientation * box.GetCenter() * importTransform.Scale * data.LODs[0].Meshes[0]->Scaling;
|
||||
importTransform.Translation -= center;
|
||||
}
|
||||
|
||||
// Transform the root node using the import transformation
|
||||
auto& root = data.Skeleton.RootNode();
|
||||
Transform meshTransform = root.LocalTransform.WorldToLocal(importTransform).LocalToWorld(root.LocalTransform);
|
||||
@@ -1596,9 +1598,31 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
|
||||
}
|
||||
else
|
||||
{
|
||||
// Transform the root node using the import transformation
|
||||
auto& root = data.Nodes[0];
|
||||
root.LocalTransform = importTransform.LocalToWorld(root.LocalTransform);
|
||||
// Transform the nodes using the import transformation
|
||||
if (data.LODs.HasItems() && data.LODs[0].Meshes.HasItems())
|
||||
{
|
||||
for (int i = 0; i < data.LODs[0].Meshes.Count(); ++i)
|
||||
{
|
||||
auto* meshData = data.LODs[0].Meshes[i];
|
||||
Transform transform = importTransform;
|
||||
if (options.UseLocalOrigin)
|
||||
{
|
||||
transform.Translation -= transform.Orientation * meshData->OriginTranslation * transform.Scale;
|
||||
}
|
||||
if (options.CenterGeometry)
|
||||
{
|
||||
// Calculate the bounding box (use LOD0 as a reference)
|
||||
BoundingBox box = data.LODs[0].GetBox();
|
||||
auto center = meshData->OriginOrientation * transform.Orientation * box.GetCenter() * transform.Scale * meshData->Scaling;
|
||||
transform.Translation -= center;
|
||||
}
|
||||
|
||||
int32 nodeIndex = meshData->NodeIndex;
|
||||
|
||||
auto& node = data.Nodes[nodeIndex];
|
||||
node.LocalTransform = transform.LocalToWorld(node.LocalTransform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user