diff --git a/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs b/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs
index bfad06d94..e3db9e0c9 100644
--- a/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs
+++ b/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs
@@ -51,11 +51,7 @@ namespace UniGLTF.MeshUtility
/// BlendShapeを0クリアするか否か。false の場合 BlendShape の現状を Bake する
/// Avatarを作る関数
///
- public static Dictionary NormalizeHierarchyFreezeMesh(
- GameObject go,
- bool removeScaling = true,
- bool removeRotation = true
- )
+ public static Dictionary NormalizeHierarchyFreezeMesh(GameObject go)
{
//
// 各メッシュから回転・スケールを取り除いてBinding行列を再計算する
@@ -76,29 +72,11 @@ namespace UniGLTF.MeshUtility
bool FreezeRotation, bool FreezeScaling)
{
var boneMap = go.transform.Traverse().ToDictionary(x => x, x => new EuclideanTransform(x.rotation, x.position));
- // Func getSrc = dst =>
- // {
- // foreach (var (k, v) in boneMap)
- // {
- // if (v == dst)
- // {
- // return k;
- // }
- // }
- // throw new NotImplementedException();
- // };
- foreach (var (src, tr) in boneMap)
+ // first, update hierarchy
+ foreach (var src in go.transform.Traverse())
{
- src.position = tr.Translation;
- if (FreezeRotation)
- {
- src.rotation = Quaternion.identity;
- }
- else
- {
- src.rotation = tr.Rotation;
- }
+ var tr = boneMap[src];
if (FreezeScaling)
{
src.localScale = Vector3.one;
@@ -108,6 +86,21 @@ namespace UniGLTF.MeshUtility
throw new NotImplementedException();
}
+ if (FreezeRotation)
+ {
+ src.rotation = Quaternion.identity;
+ }
+ else
+ {
+ src.rotation = tr.Rotation;
+ }
+
+ src.position = tr.Translation;
+ }
+
+ // second, replace mesh
+ foreach (var (src, tr) in boneMap)
+ {
if (newMesh.TryGetValue(src, out var info))
{
info.ReplaceMesh(src.gameObject);
diff --git a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs
index 2ebd9e15d..91c584b1d 100644
--- a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs
+++ b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs
@@ -160,9 +160,7 @@ namespace UniGLTF.MeshUtility
if (FreezeBlendShape || FreezeRotation || FreezeScaling)
{
// MeshをBakeする
- var newMesh = BoneNormalizer.NormalizeHierarchyFreezeMesh(go,
- removeScaling: FreezeScaling,
- removeRotation: FreezeRotation);
+ var newMesh = BoneNormalizer.NormalizeHierarchyFreezeMesh(go);
// - ヒエラルキーから回転・拡縮を除去する
// - BakeされたMeshで置き換える
diff --git a/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs b/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs
index 3a7c5c804..4648bbf7c 100644
--- a/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs
+++ b/Assets/UniGLTF/Runtime/MeshUtility/MeshFreezer.cs
@@ -161,8 +161,6 @@ namespace UniGLTF.MeshUtility
weight3 = 0.0f,
};
srcMesh.boneWeights = Enumerable.Range(0, srcMesh.vertexCount).Select(x => bw).ToArray();
- srcMesh.bindposes = new Matrix4x4[] { Matrix4x4.identity };
-
src.rootBone = src.transform;
src.bones = new[] { src.transform };
src.sharedMesh = srcMesh;