From cf4dfb0fdb54357ddb4844d469820097d08aad72 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 8 Dec 2023 18:30:48 +0900 Subject: [PATCH] =?UTF-8?q?BoneWeight=20=E3=81=AE=E7=84=A1=E3=81=84=20Skin?= =?UTF-8?q?ndedMeshRenderer=20=E3=81=B8=E3=81=AE=20bake=20transform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/UniGLTF/Runtime/MeshUtility/MeshExtensions.cs | 7 +++++-- Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) 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; }