From 12db3507be853e1f3103353e2be0bfaf8d74563a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 5 Feb 2024 16:21:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?rotation=20=E3=82=82=E3=81=97=E3=81=8F?= =?UTF-8?q?=E3=81=AF=20scaling=20=E3=81=A0=E3=81=91=E3=82=92=20freeze=20?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=81=AE=E3=81=AF=E9=9B=A3=E3=81=97=E3=81=8B?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=80=82=20=E4=B8=A1=E6=96=B9=E3=82=84?= =?UTF-8?q?=E3=82=8B=E3=81=8B=E3=82=84=E3=82=89=E3=81=AA=E3=81=84=E3=81=8B?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/MeshUtility/MeshUtilityDialog.cs | 5 ++--- .../Runtime/MeshUtility/GltfMeshUtility.cs | 16 ++++------------ .../Runtime/SkinnedMeshUtility/VrmMeshUtility.cs | 2 +- .../Runtime/MeshUtility/Vrm10MeshUtility.cs | 4 ++-- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs b/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs index c2a923b83..91628b012 100644 --- a/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs +++ b/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs @@ -301,9 +301,8 @@ namespace UniGLTF.MeshUtility bool MeshFreezeGui() { var blendShape = ToggleIsModified("BlendShape", ref MeshUtility.FreezeBlendShape); - var scale = ToggleIsModified("Scale", ref MeshUtility.FreezeScaling); - var rotation = ToggleIsModified("Rotation", ref MeshUtility.FreezeRotation); - return blendShape || scale || rotation; + var rotationAndScaling = ToggleIsModified("RotationAndScaling", ref MeshUtility.FreezeRotationAndScaling); + return blendShape || rotationAndScaling; } protected virtual bool MeshIntegrateGui() diff --git a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs index 8c1323655..f8c98298f 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs @@ -31,15 +31,7 @@ namespace UniGLTF.MeshUtility /// - Node /// - InverseBindMatrices /// - public bool FreezeScaling = true; - - /// - /// Same as VRM-0 normalization - /// - Mesh - /// - Node - /// - InverseBindMatrices - /// - public bool FreezeRotation = false; + public bool FreezeRotationAndScaling = false; public List MeshIntegrationGroups = new List(); @@ -172,15 +164,15 @@ namespace UniGLTF.MeshUtility public virtual (List, List) Process( GameObject target, IEnumerable groupCopy) { - if (FreezeBlendShape || FreezeRotation || FreezeScaling) + if (FreezeBlendShape || FreezeRotationAndScaling) { // MeshをBakeする - var meshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(target, FreezeRotation); + var meshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(target, FreezeRotationAndScaling); // - ヒエラルキーから回転・拡縮を除去する // - BakeされたMeshで置き換える // - bindPoses を再計算する - BoneNormalizer.Replace(target, meshMap, FreezeRotation, FreezeScaling); + BoneNormalizer.Replace(target, meshMap, FreezeRotationAndScaling, FreezeRotationAndScaling); } var newList = new List(); diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs index e559f453b..55bbfb177 100644 --- a/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs +++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs @@ -108,7 +108,7 @@ namespace VRM // TODO: update: firstPerson offset var (list, newList) = base.Process(target, copyGroup); - if (FreezeBlendShape || FreezeRotation || FreezeScaling) + if (FreezeBlendShape || FreezeRotationAndScaling) { var animator = target.GetComponent(); var newAvatar = AvatarDescription.RecreateAvatar(animator); diff --git a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs index 2fb0a2748..27527c108 100644 --- a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs +++ b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs @@ -11,7 +11,7 @@ namespace UniVRM10 { public Vrm10MeshUtility() { - FreezeRotation = true; + FreezeRotationAndScaling = true; } bool _generateFirstPerson = false; @@ -115,7 +115,7 @@ namespace UniVRM10 // TODO: update: firstPerson offset var (list, newList) = base.Process(target, groupCopy); - if (FreezeBlendShape || FreezeRotation || FreezeScaling) + if (FreezeBlendShape || FreezeRotationAndScaling) { var animator = target.GetComponent(); var newAvatar = AvatarDescription.RecreateAvatar(animator); From 7e07c5806ed05aaa57cbcb956681598d229cd519 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 5 Feb 2024 16:41:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?blendshape=20rotation=20scaling=20=E3=81=8C?= =?UTF-8?q?=E3=81=BE=E3=81=A8=E3=82=81=E3=81=A6=E5=87=A6=E7=90=86=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit blendshape を除外するには処理前にすべて 0 に戻す処理が必要。 前はやっているところもあったのだけど、 undo とか事後に値を復帰させるか否かなど、 選択肢とトレードオフがあります。 --- .../Editor/MeshUtility/MeshUtilityDialog.cs | 4 +--- .../Runtime/MeshUtility/BoneNormalizer.cs | 9 ++------- .../Runtime/MeshUtility/GltfMeshUtility.cs | 16 ++++------------ .../SkinnedMeshUtility/VRMBoneNormalizer.cs | 5 +++-- .../Runtime/SkinnedMeshUtility/VrmMeshUtility.cs | 2 +- .../Runtime/MeshUtility/Vrm10MeshUtility.cs | 4 ++-- 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs b/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs index 91628b012..c2feca8ff 100644 --- a/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs +++ b/Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs @@ -300,9 +300,7 @@ namespace UniGLTF.MeshUtility bool MeshFreezeGui() { - var blendShape = ToggleIsModified("BlendShape", ref MeshUtility.FreezeBlendShape); - var rotationAndScaling = ToggleIsModified("RotationAndScaling", ref MeshUtility.FreezeRotationAndScaling); - return blendShape || rotationAndScaling; + return ToggleIsModified("BlendShapeRotationScaling", ref MeshUtility.FreezeBlendShapeRotationAndScaling); } protected virtual bool MeshIntegrateGui() diff --git a/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs b/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs index 637abf24e..191d3f522 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs @@ -49,13 +49,8 @@ namespace UniGLTF.MeshUtility /// 回転とスケールを除去し、BlendShape の現状を焼き付けた版を作成する(まだ、アタッチしない) /// public static Dictionary NormalizeHierarchyFreezeMesh( - GameObject go, bool freezeRotation) + GameObject go) { - if (!freezeRotation) - { - throw new NotImplementedException("WIP"); - } - var result = new Dictionary(); foreach (var src in go.transform.Traverse()) { @@ -108,4 +103,4 @@ namespace UniGLTF.MeshUtility } } } -} \ No newline at end of file +} diff --git a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs index f8c98298f..32b5d30cc 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs @@ -23,15 +23,7 @@ namespace UniGLTF.MeshUtility /// - Node /// - InverseBindMatrices /// - public bool FreezeBlendShape = false; - - /// - /// Same as VRM-0 normalization - /// - Mesh - /// - Node - /// - InverseBindMatrices - /// - public bool FreezeRotationAndScaling = false; + public bool FreezeBlendShapeRotationAndScaling = false; public List MeshIntegrationGroups = new List(); @@ -164,15 +156,15 @@ namespace UniGLTF.MeshUtility public virtual (List, List) Process( GameObject target, IEnumerable groupCopy) { - if (FreezeBlendShape || FreezeRotationAndScaling) + if (FreezeBlendShapeRotationAndScaling) { // MeshをBakeする - var meshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(target, FreezeRotationAndScaling); + var meshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(target); // - ヒエラルキーから回転・拡縮を除去する // - BakeされたMeshで置き換える // - bindPoses を再計算する - BoneNormalizer.Replace(target, meshMap, FreezeRotationAndScaling, FreezeRotationAndScaling); + BoneNormalizer.Replace(target, meshMap, true, true); } var newList = new List(); diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs index 7f1a25d14..f7b19239d 100644 --- a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs +++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs @@ -76,9 +76,10 @@ namespace VRM } // Transform の回転とスケールを Mesh に適用します。 + // - BlendShape は現状がbakeされます // - 回転とスケールが反映された新しい Mesh が作成されます - // - Transform の回転とスケールはクリアされます。world position を維持します。 - var newMeshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(go, true); + // - Transform の回転とスケールはクリアされます。world position を維持します + var newMeshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(go); // SkinnedMeshRenderer.sharedMesh と MeshFilter.sharedMesh を新しいMeshで置き換える BoneNormalizer.Replace(go, newMeshMap, true, true); diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs index 55bbfb177..49c8d020d 100644 --- a/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs +++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs @@ -108,7 +108,7 @@ namespace VRM // TODO: update: firstPerson offset var (list, newList) = base.Process(target, copyGroup); - if (FreezeBlendShape || FreezeRotationAndScaling) + if (FreezeBlendShapeRotationAndScaling) { var animator = target.GetComponent(); var newAvatar = AvatarDescription.RecreateAvatar(animator); diff --git a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs index 27527c108..cafb06db5 100644 --- a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs +++ b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs @@ -11,7 +11,7 @@ namespace UniVRM10 { public Vrm10MeshUtility() { - FreezeRotationAndScaling = true; + FreezeBlendShapeRotationAndScaling = true; } bool _generateFirstPerson = false; @@ -115,7 +115,7 @@ namespace UniVRM10 // TODO: update: firstPerson offset var (list, newList) = base.Process(target, groupCopy); - if (FreezeBlendShape || FreezeRotationAndScaling) + if (FreezeBlendShapeRotationAndScaling) { var animator = target.GetComponent(); var newAvatar = AvatarDescription.RecreateAvatar(animator);