Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for accessory dynamic bones causing a faulty baseline to be collected. #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion Shared/Core/BoneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ private void LateUpdate()
}

private readonly Dictionary<BoneModifier, List<BoneModifierData>> _effectsToUpdate = new Dictionary<BoneModifier, List<BoneModifierData>>();

private void ApplyEffects()
{
foreach (var kv in _effectsToUpdate)
Expand Down Expand Up @@ -655,7 +654,21 @@ private IEnumerator CollectBaselineCo()
ModifiersFillInTransforms();

foreach (var modifier in ModifierDict.Values.SelectMany(x => x))
{
var dynamicBoneEnabled = false;

if (modifier.DynamicBone?.enabled == true)
{
dynamicBoneEnabled = true;
modifier.DynamicBone.enabled = false;
}

modifier.CollectBaseline();
if (dynamicBoneEnabled)
{
modifier.DynamicBone.enabled = true;
}
}

yield return CoroutineUtils.WaitForEndOfFrame;

Expand Down Expand Up @@ -939,6 +952,41 @@ private GameObject FindBone(string name, GameObject rootObject, bool noRetry = f
return boneObj;
}

/// <summary>
/// Finds the dynamic bone that is targeting the bone of the given name in the given location. Currently only supporting accessories.
/// </summary>
/// <param name="name"></param>
/// <param name="location"></param>
/// <returns></returns>
public DynamicBone FindDynamicBone(string name, BoneLocation location)
{
if (location < BoneLocation.Accessory)
{
return null;
}

var accId = location - BoneLocation.Accessory;
var rootObj = _ctrl.objAccessory.SafeGet(accId);

foreach (var dynamicBone in rootObj.GetComponents<DynamicBone>())
{
if (dynamicBone.m_Root.name.Equals(name))
{
return dynamicBone;
}

foreach (var child in dynamicBone.m_Root.GetComponentsInChildren<Transform>())
{
if (child.name.Equals(name))
{
return dynamicBone;
}
}
}

return null;
}

/// <summary>
/// Get a dictionary of all bones and their names in a given location.
/// </summary>
Expand Down Expand Up @@ -990,6 +1038,7 @@ public bool AssignBone(BoneModifier modifier)
var boneFound = bone != null;
modifier.BoneTransform = boneFound ? bone.transform : null;
modifier.BoneLocation = loc;
modifier.DynamicBone = FindDynamicBone(modifier.BoneName, modifier.BoneLocation);
return boneFound;
}

Expand Down
6 changes: 6 additions & 0 deletions Shared/Core/BoneModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public BoneModifier(string boneName, BoneModifierData[] coordinateModifiers, Bon
[IgnoreMember]
public Transform BoneTransform { get; internal set; }

/// <summary>
/// DynamicBone component that targets this transform, if any.
/// </summary>
[IgnoreMember]
internal DynamicBone DynamicBone { get; set; }

/// <summary>
/// Actual modifier values, split for different coordinates if required
/// </summary>
Expand Down