Skip to content

Commit

Permalink
Merge pull request #1345 from anatawa12/merge-bone-with-fix
Browse files Browse the repository at this point in the history
chore: make error for MergeBone with MergePB rotation mode fix
  • Loading branch information
anatawa12 authored Nov 14, 2024
2 parents 35554cf + bfb8547 commit 500ef3c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog].
### Added

### Changed
- Make error for MergeBone with MergePB rotation mode fix `#1345`
- This was not working as expected in previous version so I made this error.
- We may add support or change behavior in the future release

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The format is based on [Keep a Changelog].
- AAO 1.8.0 introduced BlendShape support for Merge Skinned Mesh, but new default mode "Rename to avoid conflicts" would increase number of BlendShape.
- This feature is added to relax this problem by automatically merging multiple BlendShapes of one Mesh.
- With this feature, you can use rename mode without performance loss.
- Fix mode for PhysBone Limits in Merge PhysBone `#665` `#1336`
- Fix mode for PhysBone Limits in Merge PhysBone `#665` `#1336` `#1345`
- In addition to existing `Copy` and `Override`, we added `Fix` mode.
- This mode will try to correct roll axis by rotating bone.
- This feature allows you to configure the mode for PhysBone Limits in Merge PhysBone.
Expand Down
21 changes: 13 additions & 8 deletions Editor/Processors/MergePhysBoneProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,18 @@ internal static void DoMerge(MergePhysBone merge, BuildContext? context)
}
}

var newIgnores = new List<Transform>();
var originalBones = new List<Transform>();
// fix rotations
foreach (var physBone in sourceComponents)
FixYawPitch(physBone, root, context, newIgnores);
FixYawPitch(physBone, root, context, originalBones);

if (originalBones.Any(x => x.GetComponent<MergeBone>()))
{
BuildLog.LogError("MergePhysBone:error:limit-rotation-fix-merge-bone");
}

// fix configurations
merged.ignoreTransforms = merged.ignoreTransforms.Concat(newIgnores).ToList();
merged.ignoreTransforms = merged.ignoreTransforms.Concat(originalBones).ToList();

var sourceComponent = sourceComponents[0];
var chainLength = sourceComponent.BoneChainLength();
Expand Down Expand Up @@ -236,7 +241,7 @@ public static void FixYawPitch(
VRCPhysBoneBase physBone,
Transform root,
BuildContext? context,
List<Transform> newIgnores)
List<Transform> originalBones)
{
// Already fixed; nothing to do!
if (physBone.limitRotation.Equals(Vector3.zero)) return;
Expand All @@ -246,7 +251,7 @@ public static void FixYawPitch(

var ignoreTransforms = new HashSet<Transform>(physBone.ignoreTransforms);

RotateRecursive(physBone, physBone.GetTarget(), root, maxChainLength, 0, ignoreTransforms, newIgnores);
RotateRecursive(physBone, physBone.GetTarget(), root, maxChainLength, 0, ignoreTransforms, originalBones);
}

/*
Expand Down Expand Up @@ -293,7 +298,7 @@ private static void RotateRecursive(VRCPhysBoneBase physBone,
int totalDepth,
int depth,
HashSet<Transform> ignoreTransforms,
List<Transform> newIgnores)
List<Transform> originalBones)
{
Vector3 targetLocation;

Expand Down Expand Up @@ -365,7 +370,7 @@ private static void RotateRecursive(VRCPhysBoneBase physBone,
// move old bone to child of newBone
transform.SetParent(newBone.transform, true);

newIgnores.Add(transform);
originalBones.Add(transform);

//var rotationQuaternion = Quaternion.Euler(0, -thisRotation, 0);

Expand All @@ -375,7 +380,7 @@ private static void RotateRecursive(VRCPhysBoneBase physBone,
//child.localRotation = rotationQuaternion * child.localRotation;

if (ignoreTransforms.Contains(child)) continue;
RotateRecursive(physBone, child, newBone.transform, totalDepth, depth + 1, ignoreTransforms, newIgnores);
RotateRecursive(physBone, child, newBone.transform, totalDepth, depth + 1, ignoreTransforms, originalBones);
}
}

Expand Down
3 changes: 3 additions & 0 deletions Localization/en-us.po
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ msgstr "Components"
msgid "MergePhysBone:warning:limit-rotation-fix-animation"
msgstr "Limit Rotation mode is Fix but physBone affected transforms are animated."

msgid "MergePhysBone:warning:limit-rotation-fix-animation"
msgstr "Merge Bone on PhysBone for Merge PhysBone with Limit Rotation mode Fix does not work and completely unsupported."

msgid "MergePhysBone:warning:limit-rotation-fix-animation:description"
msgstr "This is not supported with Limit Rotation mode Fix for now."

Expand Down

0 comments on commit 500ef3c

Please sign in to comment.