diff --git a/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs b/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs index d9bb59ba7..2c1c01747 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs @@ -168,12 +168,13 @@ namespace UniGLTF.MeshUtility src.ClearBlendShapes(); foreach (var blendshape in blendshapes) { - // blendshape の normal, tangent はちゃんと動作しなかった。 - // position とロジックが違うのかもしれない。詳細不明。 - // 法線に不要な変化が発生し、MToon の outline が乱れたりする。 - // 変化しないようにする。 src.AddBlendShapeFrame(blendshape.Name, blendshape.FrameWeight, - blendshape.Vertices, null, null); + blendshape.Vertices, + // 法線は import / export 対象 + blendshape.Normals, + // tangent は import / export の扱いが無い + null + ); } } } diff --git a/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs b/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs index d6ec269ef..572c95e1a 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs @@ -143,10 +143,13 @@ namespace UniGLTF.MeshUtility } // BakeMesh - var mesh = src.sharedMesh.Copy(false, ".baked"); - // TODO: scale に関する第2引数があるが true にすると mesh がつぶれた。どうやって使うのか + var mesh = new Mesh + { + name = src.sharedMesh.name + ".baked" + }; + // memo: BakeMesh(mesh, useScale) という第2引数がある src.BakeMesh(mesh); - CopyBlendShapes(src, mesh); + BakeBlendShapes(src, mesh); // apply SkinnedMesh.transform rotation var m = Matrix4x4.TRS(Vector3.zero, src.transform.rotation, Vector3.one); @@ -183,7 +186,7 @@ namespace UniGLTF.MeshUtility src.sharedMesh = srcMesh; } - private static void CopyBlendShapes(SkinnedMeshRenderer src, Mesh mesh) + private static void BakeBlendShapes(SkinnedMeshRenderer src, Mesh mesh) { var srcMesh = src.sharedMesh; @@ -247,7 +250,7 @@ namespace UniGLTF.MeshUtility Vector3[] normals = blendShapeMesh.normals; for (int j = 0; j < normals.Length; ++j) { - normals[j] = normals[j] - meshNormals[j]; + normals[j] = normals[j].normalized - meshNormals[j].normalized; } Vector3[] tangents = blendShapeMesh.tangents.Select(x => (Vector3)x).ToArray(); @@ -255,7 +258,7 @@ namespace UniGLTF.MeshUtility { for (int j = 0; j < tangents.Length; ++j) { - tangents[j] = tangents[j] - meshTangents[j]; + tangents[j] = tangents[j].normalized - meshTangents[j].normalized; } }