Skip to content

Commit

Permalink
fix(automaticHandSetup): Automatic rig mapping once slave fingers arr…
Browse files Browse the repository at this point in the history
…ay is reordered
  • Loading branch information
jorgejgnz committed Oct 26, 2020
1 parent 3277be8 commit b6d9ffd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
40 changes: 26 additions & 14 deletions Runtime/Components/AutomaticHandSetup.cs
Expand Up @@ -533,20 +533,6 @@ void SetupSlaveHandModel(SlaveHandModel handModel, Transform slaveWrist)
SlaveBoneModel slaveBone = boneModelObj.AddComponent<SlaveBoneModel>();
slaveBone.transformRef = fingerTransforms[b];

/* SLAVE BONE MODEL SPECIFIC
*/

// Simple automatic rig mapping
if (f > handModel.proxyHand.master.fingers.Length - 1)
Debug.LogError("Trying to access a non-existing finger!");
else if (b > handModel.proxyHand.master.fingers[f].bones.Length - 1)
Debug.LogError("Trying to access a non-existing bone!");
else if (handModel.proxyHand.master.fingers[f] != null && handModel.proxyHand.master.fingers[f].bones[b] != null)
slaveBone.masterBone = handModel.proxyHand.master.fingers[f].bones[b] as MasterBoneModel;

/*
*/

bones.Add(slaveBone);
}

Expand Down Expand Up @@ -607,6 +593,32 @@ void SetupSlaveHandModel(SlaveHandModel handModel, Transform slaveWrist)
if (handModel.pinky) fingers.Add(handModel.pinky);

handModel.fingers = fingers.ToArray();

// Operations that depends on having master.fingers and slave.fingers in the correct order
for (f = 0; f < handModel.fingers.Length; f++)
{
for (int b = 0; b < handModel.fingers[f].bones.Length; b++)
{
/* SLAVE BONE MODEL SPECIFIC
*/

SlaveBoneModel slaveBone = handModel.fingers[f].bones[b] as SlaveBoneModel;

// Simple automatic rig mapping
if (f > handModel.proxyHand.master.fingers.Length - 1)
Debug.LogError("Trying to access a non-existing finger!");

else if (b > handModel.proxyHand.master.fingers[f].bones.Length - 1)
Debug.LogError("Trying to access a non-existing bone!");

else if (handModel.proxyHand.master.fingers[f] != null && handModel.proxyHand.master.fingers[f].bones[b] != null)
slaveBone.masterBone = handModel.proxyHand.master.fingers[f].bones[b] as MasterBoneModel;

/*
*/
}
}

}

void SetupGhostHandModel(HandModel handModel, Transform ghostWrist)
Expand Down
10 changes: 9 additions & 1 deletion Runtime/Debug/FromHandToArmature.cs
Expand Up @@ -11,10 +11,18 @@
public class FromHandToArmature : MonoBehaviour
{
public bool onDrawGizmos = true;
public bool onUpdate = true;

public HandModel hand;

public Space space;

void Update()
{
if (onUpdate)
ApplyToArmature();
}

public void ApplyToArmature()
{
if (!hand)
Expand Down Expand Up @@ -75,7 +83,7 @@ public void ApplyToArmature()

private void OnDrawGizmos()
{
if (!onDrawGizmos)
if (!onDrawGizmos || onUpdate)
return;

ApplyToArmature();
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Modules/Avatar/AvatarController.cs
Expand Up @@ -26,7 +26,7 @@ private void Start()

private void Update()
{
if (model.followsCamera && core.model.trackedCamera)
if (model.followsCamera && core.model.trackedCamera && model.headSight)
{
model.headSight.position = core.model.trackedCamera.position;
model.headSight.rotation = core.model.trackedCamera.rotation;
Expand Down
9 changes: 6 additions & 3 deletions Runtime/Modules/Avatar/AvatarModel.cs
Expand Up @@ -43,11 +43,14 @@ public class AvatarModel : HPTKModel
private void Awake()
{
// Array
hands = new ProxyHandModel[2] { leftHand, rightHand };
List<ProxyHandModel> handsList = new List<ProxyHandModel>();
if (leftHand) handsList.Add(leftHand);
if (rightHand) handsList.Add(rightHand);
hands = handsList.ToArray();

// Shoulder tips
leftHand.shoulderTip = shoulderLeft;
rightHand.shoulderTip = shoulderRight;
if (leftHand) leftHand.shoulderTip = shoulderLeft;
if (rightHand) rightHand.shoulderTip = shoulderRight;

// Referrences to parent
for (int i = 0; i < hands.Length; i++)
Expand Down

0 comments on commit b6d9ffd

Please sign in to comment.