Skip to content

Commit

Permalink
improvement hand target alignment / arm length measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
Ibodan committed Aug 26, 2018
1 parent 29ef49d commit 7682444
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CustomAvatar/AvatarMeasurement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public static float MeasureHeight(GameObject avatarGameObject, Transform viewPoi

var leftShoulder = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm).position;
var rightShoulder = animator.GetBoneTransform(HumanBodyBones.RightUpperArm).position;
var leftElbow = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm).position;
var leftHand = animator.GetBoneTransform(HumanBodyBones.LeftHand).position;
return Vector3.Distance(leftHand, leftShoulder) * 2.0f + Vector3.Distance(leftShoulder, rightShoulder);
return (Vector3.Distance(leftElbow, leftShoulder) + Vector3.Distance(leftHand, leftElbow)) * 2.0f + Vector3.Distance(leftShoulder, rightShoulder);
}
}
}
12 changes: 6 additions & 6 deletions CustomAvatar/PlayerAvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,23 @@ void fixGrip(HumanBodyBones littleFingerBoneName, HumanBodyBones indexFingerBone
var wrist = animator.GetBoneTransform(wristBoneName);
var elbow = animator.GetBoneTransform(elbowBoneName);

var universalRotation = Quaternion.LookRotation(indexFinger.position - littleFinger.position, wrist.position - elbow.position);
var anatomicBaseRotation = Quaternion.LookRotation(indexFinger.position - littleFinger.position, wrist.position - elbow.position);
var fingerThickness = (littleFinger.position - indexFinger.position).magnitude;
fixTargetOffset.Scale(new Vector3(0.05f, fingerThickness, 0.05f));
var universalPosition = indexFinger.position;
var anatomicBasePosition = indexFinger.position;
var rotationToPose = Quaternion.FromToRotation(baseArmDirection, wrist.position - elbow.position);

handTarget.parent = null;
handObject.localPosition = universalPosition + (rotationToPose * fixTargetOffset);
handObject.localRotation = universalRotation * fixRotation;
handObject.position = anatomicBasePosition + (rotationToPose * fixTargetOffset);
handObject.localRotation = anatomicBaseRotation * fixRotation;
handTarget.parent = handObject;

handTarget.rotation = wrist.rotation;
handTarget.position = wrist.position;

Plugin.Log("Grip fix applied. " + universalPosition);
Plugin.Log("Grip fix applied. " + anatomicBasePosition);
}
var targetOffset = new Vector3(-0.37f, -0.34f, 0.85f);
var targetOffset = new Vector3(-0.52f, -0.34f, 0.99f);
var rotation = new Quaternion(0.005924877f, 0.294924f, 0.9530304f, -0.06868639f);
fixGrip(HumanBodyBones.LeftLittleProximal, HumanBodyBones.LeftIndexProximal, HumanBodyBones.LeftHand, HumanBodyBones.LeftLowerArm,
_currentSpawnedPlayerAvatar.GameObject.transform.Find("LeftHand"),
Expand Down

0 comments on commit 7682444

Please sign in to comment.