diff --git a/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs b/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs index f4a37a4bb..22cc35a7b 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs @@ -76,9 +76,12 @@ namespace UniGLTF.MeshUtility return dst; } - public static void ApplyRotationAndScale(this Mesh src, Matrix4x4 m) + public static void ApplyRotationAndScale(this Mesh src, Matrix4x4 m, bool removeTranslation = true) { - m.SetColumn(3, new Vector4(0, 0, 0, 1)); // remove translation + if (removeTranslation) + { + m.SetColumn(3, new Vector4(0, 0, 0, 1)); // remove translation + } src.ApplyMatrix(m); } diff --git a/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs b/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs index fcd185a04..f16c8bed2 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs @@ -147,9 +147,13 @@ namespace UniGLTF.MeshUtility if (!hasBoneWeight) { // Before bake, bind no weight bones - //Debug.LogFormat("no weight: {0}", srcMesh.name); srcMesh = srcMesh.Copy(true); + var rootBone = src.rootBone ?? src.transform; + srcMesh.ApplyRotationAndScale(rootBone.localToWorldMatrix, false); + + Debug.LogFormat($"apply: {src.transform} {rootBone}"); + var bw = new BoneWeight { boneIndex0 = 0, @@ -162,8 +166,8 @@ namespace UniGLTF.MeshUtility weight3 = 0.0f, }; srcMesh.boneWeights = Enumerable.Range(0, srcMesh.vertexCount).Select(x => bw).ToArray(); - src.rootBone = src.transform; - src.bones = new[] { src.transform }; + src.rootBone = rootBone; + src.bones = new[] { rootBone }; src.sharedMesh = srcMesh; }