Skip to content

Commit

Permalink
Merge pull request #2238 from ousttrue/fix/hide_not_impl_option
Browse files Browse the repository at this point in the history
rotation もしくは scaling だけを freeze するのは難しかった。
  • Loading branch information
ousttrue committed Feb 8, 2024
2 parents 226df16 + 7e07c58 commit ccd3a12
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 36 deletions.
5 changes: 1 addition & 4 deletions Assets/UniGLTF/Editor/MeshUtility/MeshUtilityDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,7 @@ protected bool ToggleIsModified(string label, ref bool value)

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;
return ToggleIsModified("BlendShapeRotationScaling", ref MeshUtility.FreezeBlendShapeRotationAndScaling);
}

protected virtual bool MeshIntegrateGui()
Expand Down
9 changes: 2 additions & 7 deletions Assets/UniGLTF/Runtime/MeshUtility/BoneNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ private static MeshAttachInfo CreateMeshInfo(Transform src)
/// 回転とスケールを除去し、BlendShape の現状を焼き付けた版を作成する(まだ、アタッチしない)
/// </summary>
public static Dictionary<Transform, MeshAttachInfo> NormalizeHierarchyFreezeMesh(
GameObject go, bool freezeRotation)
GameObject go)
{
if (!freezeRotation)
{
throw new NotImplementedException("WIP");
}

var result = new Dictionary<Transform, MeshAttachInfo>();
foreach (var src in go.transform.Traverse())
{
Expand Down Expand Up @@ -108,4 +103,4 @@ public static void Replace(GameObject go, Dictionary<Transform, MeshAttachInfo>
}
}
}
}
}
24 changes: 4 additions & 20 deletions Assets/UniGLTF/Runtime/MeshUtility/GltfMeshUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,7 @@ public class GltfMeshUtility
/// - Node
/// - InverseBindMatrices
/// </summary>
public bool FreezeBlendShape = false;

/// <summary>
/// Same as VRM-0 normalization
/// - Mesh
/// - Node
/// - InverseBindMatrices
/// </summary>
public bool FreezeScaling = true;

/// <summary>
/// Same as VRM-0 normalization
/// - Mesh
/// - Node
/// - InverseBindMatrices
/// </summary>
public bool FreezeRotation = false;
public bool FreezeBlendShapeRotationAndScaling = false;

public List<MeshIntegrationGroup> MeshIntegrationGroups = new List<MeshIntegrationGroup>();

Expand Down Expand Up @@ -172,15 +156,15 @@ public virtual IEnumerable<MeshIntegrationGroup> CopyInstantiate(GameObject go,
public virtual (List<MeshIntegrationResult>, List<GameObject>) Process(
GameObject target, IEnumerable<MeshIntegrationGroup> groupCopy)
{
if (FreezeBlendShape || FreezeRotation || FreezeScaling)
if (FreezeBlendShapeRotationAndScaling)
{
// MeshをBakeする
var meshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(target, FreezeRotation);
var meshMap = BoneNormalizer.NormalizeHierarchyFreezeMesh(target);

// - ヒエラルキーから回転・拡縮を除去する
// - BakeされたMeshで置き換える
// - bindPoses を再計算する
BoneNormalizer.Replace(target, meshMap, FreezeRotation, FreezeScaling);
BoneNormalizer.Replace(target, meshMap, true, true);
}

var newList = new List<GameObject>();
Expand Down
5 changes: 3 additions & 2 deletions Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public static void Execute(GameObject go, bool forceTPose)
}

// 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);
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM/Runtime/SkinnedMeshUtility/VrmMeshUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public override (List<UniGLTF.MeshUtility.MeshIntegrationResult>, List<GameObjec
// TODO: update: firstPerson offset
var (list, newList) = base.Process(target, copyGroup);

if (FreezeBlendShape || FreezeRotation || FreezeScaling)
if (FreezeBlendShapeRotationAndScaling)
{
var animator = target.GetComponent<Animator>();
var newAvatar = AvatarDescription.RecreateAvatar(animator);
Expand Down
4 changes: 2 additions & 2 deletions Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Vrm10MeshUtility : UniGLTF.MeshUtility.GltfMeshUtility
{
public Vrm10MeshUtility()
{
FreezeRotation = true;
FreezeBlendShapeRotationAndScaling = true;
}

bool _generateFirstPerson = false;
Expand Down Expand Up @@ -115,7 +115,7 @@ public override (List<UniGLTF.MeshUtility.MeshIntegrationResult>, List<GameObjec
// TODO: update: firstPerson offset
var (list, newList) = base.Process(target, groupCopy);

if (FreezeBlendShape || FreezeRotation || FreezeScaling)
if (FreezeBlendShapeRotationAndScaling)
{
var animator = target.GetComponent<Animator>();
var newAvatar = AvatarDescription.RecreateAvatar(animator);
Expand Down

0 comments on commit ccd3a12

Please sign in to comment.