From b2fea4fa6c8c6fd99eabb1773a187a427ac66216 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 5 Feb 2023 22:42:37 +0900 Subject: [PATCH] fix: bone processing in RemoveMeshInBoxProcessor --- Editor/Processors/SkinnedMeshes/MeshInfo2.cs | 6 ++++-- Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs index f7d56685d..8da22c28e 100644 --- a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs +++ b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs @@ -432,7 +432,7 @@ private Vertex(Vertex vertex) public Vertex Clone() => new Vertex(this); - public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2) + public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2, Matrix4x4 rendererWorldToLocalMatrix) { var position = Position; @@ -449,7 +449,9 @@ public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2) var boneMat = transformMat * bone.Bindpose; MulAdd(ref matrix, boneMat, weight); } - return matrix * position; + + matrix = rendererWorldToLocalMatrix * matrix; + return matrix * new Vector4(position.x, position.y, position.z, 1f); } // UnityEngine doesn't provide Matrix4x4 + Matrix4x4 and Matrix4x4 * float. diff --git a/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs b/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs index 0a574858c..adfaef658 100644 --- a/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs @@ -16,7 +16,7 @@ public override void Process(OptimizerSession session, MeshInfo2 target, MeshInf // Vertex.AdditionalTemporal: 0 if in box, 1 if out of box foreach (var vertex in target.Vertices) { - Vector3 actualPosition = Target.transform.worldToLocalMatrix * vertex.ComputeActualPosition(target); + var actualPosition = vertex.ComputeActualPosition(target, Target.transform.worldToLocalMatrix); vertex.AdditionalTemporal = Component.boxes.Any(x => x.ContainsVertex(actualPosition)) ? 0 : 1; }