Torso/head bone detection without avatar
This commit is contained in:
parent
67126399e6
commit
40a8ef2e4d
@ -22,7 +22,7 @@ namespace Passer.Humanoid {
|
||||
base.Start(humanoid, targetTransform);
|
||||
target = targetTransform.GetComponent<FootTarget>();
|
||||
|
||||
if (Application.isPlaying) {
|
||||
if (Application.isPlaying && humanoid.leftFootTarget.foot.target.transform != null && humanoid.rightFootTarget.foot.target.transform != null) {
|
||||
footSeparation = Vector3.Distance(humanoid.leftFootTarget.foot.target.transform.position, humanoid.rightFootTarget.foot.target.transform.position) / 2;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Passer.Humanoid {
|
||||
using System.ComponentModel;
|
||||
using Tracking;
|
||||
|
||||
[System.Serializable]
|
||||
@ -1308,8 +1309,9 @@ namespace Passer.Humanoid {
|
||||
#endregion
|
||||
|
||||
#region Configuration
|
||||
|
||||
/// <summary>
|
||||
/// Scans the humanoid to retrieve all bones
|
||||
/// Scans the humanoid using Mecanum to retrieve all bones
|
||||
/// </summary>
|
||||
public void RetrieveBones() {
|
||||
hipsTarget.RetrieveBones();
|
||||
@ -1320,6 +1322,19 @@ namespace Passer.Humanoid {
|
||||
leftFootTarget.RetrieveBones();
|
||||
rightFootTarget.RetrieveBones();
|
||||
}
|
||||
|
||||
public void RetrieveBonesFrom(Transform rootBone) {
|
||||
if (avatarRig != null) {
|
||||
RetrieveBones();
|
||||
return;
|
||||
}
|
||||
|
||||
hipsTarget.RetrieveBonesWithoutAvatar(rootBone);
|
||||
headTarget.RetrieveBonesWithoutAvatar(rootBone);
|
||||
|
||||
leftHandTarget.RetrieveBonesWithoutAvatar(rootBone);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Update
|
||||
@ -2476,8 +2491,13 @@ namespace Passer.Humanoid {
|
||||
/// </summary>
|
||||
/// <returns>The position of the humanoid</returns>
|
||||
public Vector3 GetHumanoidPosition() {
|
||||
Vector3 footPosition = (leftFootTarget.foot.target.transform.position + rightFootTarget.foot.target.transform.position) / 2;
|
||||
Vector3 footBase = new Vector3(footPosition.x, transform.position.y, footPosition.z);
|
||||
Vector3 footBase;
|
||||
if (leftFootTarget.foot.target.transform != null && rightFootTarget.foot.target.transform != null) {
|
||||
Vector3 footPosition = (leftFootTarget.foot.target.transform.position + rightFootTarget.foot.target.transform.position) / 2;
|
||||
footBase = new Vector3(footPosition.x, transform.position.y, footPosition.z);
|
||||
} else {
|
||||
footBase = this.transform.position;
|
||||
}
|
||||
return footBase;
|
||||
}
|
||||
//public Vector3 GetHumanoidPosition2() {
|
||||
|
@ -24,7 +24,8 @@ namespace Passer.Humanoid {
|
||||
if (humanoid.isRemote)
|
||||
return;
|
||||
|
||||
grabSocket.handTarget = this;
|
||||
if (grabSocket != null)
|
||||
grabSocket.handTarget = this;
|
||||
|
||||
// Gun Interaction pointer creates an Event System
|
||||
// First solve that before enabling this warning
|
||||
@ -859,7 +860,7 @@ namespace Passer.Humanoid {
|
||||
|
||||
if (grabbedHandle != null)
|
||||
LetGoHandle(grabbedHandle);
|
||||
|
||||
|
||||
handRigidbody.mass = 1;
|
||||
}
|
||||
this.grabbedRigidbody = false;
|
||||
|
@ -75,9 +75,9 @@ namespace Passer.Humanoid {
|
||||
distal.boneId = firstBoneId + 2;
|
||||
|
||||
//metaCarpal.RetrieveBones(humanoid);
|
||||
proximal.RetrieveBones(humanoid);
|
||||
intermediate.RetrieveBones(humanoid);
|
||||
distal.RetrieveBones(humanoid);
|
||||
proximal.RetrieveBones();
|
||||
intermediate.RetrieveBones();
|
||||
distal.RetrieveBones();
|
||||
}
|
||||
|
||||
public void MatchTargetToAvatar() {
|
||||
@ -346,7 +346,7 @@ namespace Passer.Humanoid {
|
||||
//private Quaternion localDefaultRotation;
|
||||
|
||||
public TargetedPhalanges(TargetedFinger finger, HumanoidTarget.TargetedBone nextBone)
|
||||
: base(nextBone) {
|
||||
: base(finger.fingers.handTarget.humanoid, nextBone) {
|
||||
|
||||
this.finger = finger;
|
||||
}
|
||||
|
@ -51,16 +51,29 @@ namespace Passer.Humanoid {
|
||||
///
|
||||
[HelpURL("https://passervr.com/apis/HumanoidControl/Unity/class_passer_1_1_humanoid_1_1_foot_target.html")]
|
||||
public class FootTarget : HumanoidTarget {
|
||||
public bool isLeft;
|
||||
public Side side;
|
||||
|
||||
public FootTarget() {
|
||||
/// <summary>
|
||||
/// Pseudo-constructor because Unity does not use real constructors with arguments
|
||||
/// </summary>
|
||||
/// <param name="humanoid">The humanoid for this foot target</param>
|
||||
/// <param name="isLeft">Is this the left foot taget?</param>
|
||||
public void Constructor(HumanoidControl humanoid, bool isLeft) {
|
||||
this.humanoid = humanoid;
|
||||
upperLeg = new TargetedUpperLegBone(this);
|
||||
lowerLeg = new TargetedLowerLegBone(this);
|
||||
foot = new TargetedFootBone(this);
|
||||
toes = new TargetedToesBone(this);
|
||||
|
||||
this.isLeft = isLeft;
|
||||
this.side = isLeft ? Side.Left : Side.Right;
|
||||
this.otherFoot = isLeft ? humanoid.rightFootTarget : humanoid.leftFootTarget;
|
||||
|
||||
this.InitSubTargets();
|
||||
}
|
||||
|
||||
public bool isLeft;
|
||||
public Side side;
|
||||
|
||||
public FootTarget otherFoot;
|
||||
|
||||
public LegMovements legMovements = new LegMovements();
|
||||
@ -195,7 +208,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedUpperLegBone : TargetedBone {
|
||||
private FootTarget footTarget;
|
||||
|
||||
public TargetedUpperLegBone(FootTarget footTarget) : base(footTarget.lowerLeg) {
|
||||
public TargetedUpperLegBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.lowerLeg) {
|
||||
this.footTarget = footTarget;
|
||||
}
|
||||
|
||||
@ -239,7 +252,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedLowerLegBone : TargetedBone {
|
||||
private FootTarget footTarget;
|
||||
|
||||
public TargetedLowerLegBone(FootTarget footTarget) : base(footTarget.foot) {
|
||||
public TargetedLowerLegBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.foot) {
|
||||
this.footTarget = footTarget;
|
||||
}
|
||||
|
||||
@ -282,7 +295,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedFootBone : TargetedBone {
|
||||
private FootTarget footTarget;
|
||||
|
||||
public TargetedFootBone(FootTarget footTarget) : base(footTarget.toes) {
|
||||
public TargetedFootBone(FootTarget footTarget) : base(footTarget.humanoid, footTarget.toes) {
|
||||
this.footTarget = footTarget;
|
||||
}
|
||||
|
||||
@ -353,7 +366,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedToesBone : TargetedBone {
|
||||
private FootTarget footTarget;
|
||||
|
||||
public TargetedToesBone(FootTarget footTarget) {
|
||||
public TargetedToesBone(FootTarget footTarget) : base(footTarget.humanoid) {
|
||||
this.footTarget = footTarget;
|
||||
}
|
||||
|
||||
@ -488,7 +501,8 @@ namespace Passer.Humanoid {
|
||||
targetTransform.position = oldTarget.transform.position;
|
||||
targetTransform.rotation = oldTarget.transform.rotation;
|
||||
|
||||
FootTarget footTarget = Constructor(humanoid, oldTarget.isLeft, targetTransform);
|
||||
FootTarget footTarget = targetTransform.gameObject.AddComponent<FootTarget>();
|
||||
footTarget.Constructor(humanoid, oldTarget.isLeft);
|
||||
if (footTarget.isLeft)
|
||||
humanoid.leftFootTarget = footTarget;
|
||||
else
|
||||
@ -528,10 +542,10 @@ namespace Passer.Humanoid {
|
||||
}
|
||||
|
||||
public void RetrieveBones() {
|
||||
upperLeg.RetrieveBones(humanoid);
|
||||
lowerLeg.RetrieveBones(humanoid);
|
||||
foot.RetrieveBones(humanoid);
|
||||
toes.RetrieveBones(humanoid);
|
||||
upperLeg.RetrieveBones();
|
||||
lowerLeg.RetrieveBones();
|
||||
foot.RetrieveBones();
|
||||
toes.RetrieveBones();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -705,17 +719,6 @@ namespace Passer.Humanoid {
|
||||
|
||||
#endif
|
||||
|
||||
private static FootTarget Constructor(HumanoidControl humanoid, bool isLeft, Transform targetTransform) {
|
||||
FootTarget footTarget = targetTransform.gameObject.AddComponent<FootTarget>();
|
||||
footTarget.humanoid = humanoid;
|
||||
footTarget.isLeft = isLeft;
|
||||
footTarget.side = isLeft ? Side.Left : Side.Right;
|
||||
footTarget.otherFoot = isLeft ? humanoid.rightFootTarget : humanoid.leftFootTarget;
|
||||
|
||||
footTarget.InitSubTargets();
|
||||
return footTarget;
|
||||
}
|
||||
|
||||
public override void NewComponent(HumanoidControl _humanoid) {
|
||||
humanoid = _humanoid;
|
||||
isLeft = (this == humanoid.leftFootTarget);
|
||||
@ -744,12 +747,12 @@ namespace Passer.Humanoid {
|
||||
|
||||
if (foot.bone.transform != null)
|
||||
soleThicknessFoot = foot.bone.transform.position.y - humanoid.transform.position.y;
|
||||
else
|
||||
else if (foot.target.transform != null)
|
||||
soleThicknessFoot = foot.target.transform.position.y - humanoid.transform.position.y;
|
||||
|
||||
if (toes.bone.transform != null && ground != null)
|
||||
soleThicknessToes = toes.bone.transform.position.y - humanoid.transform.position.y;
|
||||
else
|
||||
else if (foot.target.transform != null)
|
||||
soleThicknessToes = soleThicknessFoot;
|
||||
|
||||
legMovements.Start(humanoid, this);
|
||||
@ -799,7 +802,8 @@ namespace Passer.Humanoid {
|
||||
|
||||
footTarget = footTargetTransform.GetComponent<FootTarget>();
|
||||
if (footTarget == null) {
|
||||
footTarget = Constructor(humanoid, isLeft, footTargetTransform);
|
||||
footTarget = footTargetTransform.gameObject.AddComponent<FootTarget>();
|
||||
footTarget.Constructor(humanoid, isLeft);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,13 @@ namespace Passer.Humanoid {
|
||||
[System.Serializable]
|
||||
[HelpURL("https://passervr.com/apis/HumanoidControl/Unity/class_passer_1_1_humanoid_1_1_hand_target.html")]
|
||||
public partial class HandTarget : HumanoidTarget {
|
||||
public HandTarget() {
|
||||
/// <summary>
|
||||
/// Pseudo-constructor because Unity does not use real constructors
|
||||
/// </summary>
|
||||
/// <param name="humanoid">The humanoid for this hand target</param>
|
||||
/// <param name="isLeft">Is this the left hand target?</param>
|
||||
public void Constructor(HumanoidControl humanoid, bool isLeft) {
|
||||
this.humanoid = humanoid;
|
||||
shoulder = new TargetedShoulderBone(this);
|
||||
upperArm = new TargetedUpperArmBone(this);
|
||||
forearm = new TargetedForearmBone(this);
|
||||
@ -116,6 +122,11 @@ namespace Passer.Humanoid {
|
||||
};
|
||||
|
||||
fingers = new FingersTarget(this);
|
||||
|
||||
this.isLeft = isLeft;
|
||||
this.side = isLeft ? Side.Left : Side.Right;
|
||||
this.outward = this.isLeft ? Vector3.left : Vector3.right;
|
||||
InitSubTargets();
|
||||
}
|
||||
|
||||
#if pCEREBELLUM
|
||||
@ -379,7 +390,7 @@ namespace Passer.Humanoid {
|
||||
get { return hand; }
|
||||
}
|
||||
public Transform stretchlessTarget;
|
||||
private readonly TargetedBone[] subTargets;
|
||||
private TargetedBone[] subTargets;
|
||||
|
||||
#region Shoulder
|
||||
|
||||
@ -389,7 +400,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedShoulderBone : TargetedBone {
|
||||
private HandTarget handTarget;
|
||||
|
||||
public TargetedShoulderBone(HandTarget handTarget) : base(handTarget.upperArm) {
|
||||
public TargetedShoulderBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.upperArm) {
|
||||
this.handTarget = handTarget;
|
||||
bone.jointLimitations = true;
|
||||
}
|
||||
@ -417,6 +428,13 @@ namespace Passer.Humanoid {
|
||||
}
|
||||
}
|
||||
|
||||
public override Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
bone.transform = FindTransformByPartialName(rootBone, "shoulder");
|
||||
if (bone.transform == null)
|
||||
bone.transform = FindTransformByPartialName(rootBone, "clavicle");
|
||||
return bone.transform;
|
||||
}
|
||||
|
||||
public override Quaternion DetermineRotation() {
|
||||
Quaternion torsoRotation;
|
||||
if (handTarget.humanoid.hipsTarget.chest.bone.transform != null)
|
||||
@ -451,7 +469,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedUpperArmBone : TargetedBone {
|
||||
private HandTarget handTarget;
|
||||
|
||||
public TargetedUpperArmBone(HandTarget handTarget) : base(handTarget.forearm) {
|
||||
public TargetedUpperArmBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.forearm) {
|
||||
this.handTarget = handTarget;
|
||||
}
|
||||
|
||||
@ -472,6 +490,11 @@ namespace Passer.Humanoid {
|
||||
}
|
||||
}
|
||||
|
||||
public override Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
bone.transform = FindTransformByPartialName(rootBone, "up");
|
||||
return bone.transform;
|
||||
}
|
||||
|
||||
public override Quaternion DetermineRotation() {
|
||||
Vector3 upperArmBoneDirection = (handTarget.forearm.bone.transform.position - bone.transform.position).normalized;
|
||||
|
||||
@ -502,7 +525,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedForearmBone : TargetedBone {
|
||||
private HandTarget handTarget;
|
||||
|
||||
public TargetedForearmBone(HandTarget handTarget) : base(handTarget.hand) {
|
||||
public TargetedForearmBone(HandTarget handTarget) : base(handTarget.humanoid, handTarget.hand) {
|
||||
this.handTarget = handTarget;
|
||||
}
|
||||
|
||||
@ -564,7 +587,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedHandBone : TargetedBone {
|
||||
private HandTarget handTarget;
|
||||
|
||||
public TargetedHandBone(HandTarget handTarget) {
|
||||
public TargetedHandBone(HandTarget handTarget) : base(handTarget.humanoid) {
|
||||
this.handTarget = handTarget;
|
||||
}
|
||||
|
||||
@ -695,7 +718,10 @@ namespace Passer.Humanoid {
|
||||
targetTransform.position = oldTarget.transform.position;
|
||||
targetTransform.rotation = oldTarget.transform.rotation;
|
||||
|
||||
HandTarget handTarget = Constructor(humanoid, oldTarget.isLeft, targetTransform);
|
||||
//HandTarget handTarget = Constructor(humanoid, oldTarget.isLeft, targetTransform);
|
||||
HandTarget handTarget = targetTransform.gameObject.AddComponent<HandTarget>();
|
||||
handTarget.Constructor(humanoid, oldTarget.isLeft);
|
||||
|
||||
if (oldTarget.isLeft) {
|
||||
humanoid.leftHandTarget = handTarget;
|
||||
//handTarget.otherHand = humanoid.rightHandTarget;
|
||||
@ -804,11 +830,22 @@ namespace Passer.Humanoid {
|
||||
|
||||
public void RetrieveBones() {
|
||||
foreach (TargetedBone subTarget in subTargets)
|
||||
subTarget.RetrieveBones(humanoid);
|
||||
subTarget.RetrieveBones();
|
||||
|
||||
fingers.RetrieveBones(this);
|
||||
}
|
||||
|
||||
public void RetrieveBonesWithoutAvatar(Transform rootBone) {
|
||||
Transform arm = HumanoidTarget.FindTransformByPartialName(humanoid.headTarget.neck.parent.bone.transform, isLeft ? "left" : "right");
|
||||
if (arm == null)
|
||||
arm = HumanoidTarget.FindTransformByPartialName(humanoid.headTarget.neck.parent.bone.transform, isLeft ? "_L" : "_R");
|
||||
// This can still find the left side of the head....
|
||||
shoulder.RetrieveBoneWithoutAvatar(arm);
|
||||
upperArm.RetrieveBoneWithoutAvatar(arm);
|
||||
forearm.RetrieveBoneWithoutAvatar(arm);
|
||||
hand.RetrieveBoneWithoutAvatar(arm);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Settings
|
||||
@ -1225,18 +1262,6 @@ namespace Passer.Humanoid {
|
||||
#endif
|
||||
}
|
||||
|
||||
// This function is called only when the humanoid is created
|
||||
private static HandTarget Constructor(HumanoidControl humanoid, bool isLeft, Transform handTargetTransform) {
|
||||
HandTarget handTarget = handTargetTransform.gameObject.AddComponent<HandTarget>();
|
||||
handTarget.humanoid = humanoid;
|
||||
handTarget.isLeft = isLeft;
|
||||
handTarget.side = isLeft ? Side.Left : Side.Right;
|
||||
handTarget.outward = handTarget.isLeft ? Vector3.left : Vector3.right;
|
||||
|
||||
handTarget.InitSubTargets();
|
||||
return handTarget;
|
||||
}
|
||||
|
||||
public override void NewComponent(HumanoidControl _humanoid) {
|
||||
humanoid = _humanoid;
|
||||
isLeft = (this == humanoid.leftHandTarget);
|
||||
@ -1347,8 +1372,10 @@ namespace Passer.Humanoid {
|
||||
}
|
||||
|
||||
handTarget = handTargetTransform.GetComponent<HandTarget>();
|
||||
if (handTarget == null)
|
||||
handTarget = Constructor(humanoid, isLeft, handTargetTransform);
|
||||
if (handTarget == null) {
|
||||
handTarget = handTargetTransform.gameObject.AddComponent<HandTarget>();
|
||||
handTarget.Constructor(humanoid, isLeft);
|
||||
}
|
||||
}
|
||||
|
||||
if (isLeft)
|
||||
|
@ -65,7 +65,12 @@ namespace Passer.Humanoid {
|
||||
[HelpURL("https://passervr.com/apis/HumanoidControl/Unity/class_passer_1_1_humanoid_1_1_head_target.html")]
|
||||
public class HeadTarget : HumanoidTarget {
|
||||
|
||||
public HeadTarget() {
|
||||
/// <summary>
|
||||
/// Pseudo-constructor because Unity does not use real constructors with arguments
|
||||
/// </summary>
|
||||
/// <param name="humanoid">The humanoid for this head target</param>
|
||||
public void Constructor(HumanoidControl humanoid) {
|
||||
this.humanoid = humanoid;
|
||||
neck = new TargetedNeckBone(this);
|
||||
head = new TargetedHeadBone(this);
|
||||
#if hFACE
|
||||
@ -310,7 +315,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedHeadBone : TargetedBone {
|
||||
private HeadTarget headTarget;
|
||||
|
||||
public TargetedHeadBone(HeadTarget headTarget) {
|
||||
public TargetedHeadBone(HeadTarget headTarget) : base(headTarget.humanoid) {
|
||||
this.headTarget = headTarget;
|
||||
|
||||
boneId = Bone.Head;
|
||||
@ -325,6 +330,14 @@ namespace Passer.Humanoid {
|
||||
nextBone = null;
|
||||
}
|
||||
|
||||
public override Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
if (parent.bone.transform != null)
|
||||
bone.transform = FindTransformByPartialName(parent.bone.transform, "head");
|
||||
else
|
||||
bone.transform = FindTransformByPartialName(rootBone, "head");
|
||||
return bone.transform;
|
||||
}
|
||||
|
||||
public override Quaternion DetermineRotation() {
|
||||
if (headTarget == null)
|
||||
return Quaternion.identity;
|
||||
@ -386,13 +399,14 @@ namespace Passer.Humanoid {
|
||||
#endregion
|
||||
|
||||
#region Neck
|
||||
|
||||
public TargetedNeckBone neck = null;
|
||||
|
||||
[System.Serializable]
|
||||
public class TargetedNeckBone : TargetedBone {
|
||||
public HeadTarget headTarget;
|
||||
|
||||
public TargetedNeckBone(HeadTarget headTarget) {
|
||||
public TargetedNeckBone(HeadTarget headTarget) : base(headTarget.humanoid) {
|
||||
this.headTarget = headTarget;
|
||||
boneId = Bone.Neck;
|
||||
|
||||
@ -411,6 +425,15 @@ namespace Passer.Humanoid {
|
||||
nextBone = headTarget.head;
|
||||
}
|
||||
|
||||
public override Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
Init();
|
||||
if (parent.bone.transform != null)
|
||||
bone.transform = FindTransformByPartialName(parent.bone.transform, "neck");
|
||||
else
|
||||
bone.transform = FindTransformByPartialName(rootBone, "neck");
|
||||
return bone.transform;
|
||||
}
|
||||
|
||||
public override Quaternion DetermineRotation() {
|
||||
if (headTarget == null)
|
||||
return Quaternion.identity;
|
||||
@ -434,6 +457,7 @@ namespace Passer.Humanoid {
|
||||
return tension;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void InitSubTargets() {
|
||||
@ -557,14 +581,19 @@ namespace Passer.Humanoid {
|
||||
}
|
||||
|
||||
public void RetrieveBones() {
|
||||
neck.RetrieveBones(humanoid);
|
||||
head.RetrieveBones(humanoid);
|
||||
neck.RetrieveBones();
|
||||
head.RetrieveBones();
|
||||
#if hFACE
|
||||
face.InitComponent();
|
||||
face.RetrieveBones(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void RetrieveBonesWithoutAvatar(Transform rootBone) {
|
||||
neck.RetrieveBoneWithoutAvatar(rootBone);
|
||||
head.RetrieveBoneWithoutAvatar(rootBone);
|
||||
}
|
||||
|
||||
public static void GetDefaultNeck(Animator rig, ref Transform boneTransform) {
|
||||
GetDefaultBone(rig, ref boneTransform, HumanBodyBones.Neck, "Neck", "neck");
|
||||
if (boneTransform == null) {
|
||||
@ -826,7 +855,7 @@ namespace Passer.Humanoid {
|
||||
headTarget = headTargetTransform.GetComponent<HeadTarget>();
|
||||
if (headTarget == null) {
|
||||
headTarget = headTargetTransform.gameObject.AddComponent<HeadTarget>();
|
||||
headTarget.humanoid = humanoid;
|
||||
headTarget.Constructor(humanoid);
|
||||
}
|
||||
humanoid.headTarget = headTarget;
|
||||
}
|
||||
|
@ -41,7 +41,12 @@ namespace Passer.Humanoid {
|
||||
[HelpURL("https://passervr.com/apis/HumanoidControl/Unity/class_passer_1_1_humanoid_1_1_hips_target.html")]
|
||||
public partial class HipsTarget : HumanoidTarget {
|
||||
|
||||
public HipsTarget() {
|
||||
/// <summary>
|
||||
/// Pseudo-constructor because Unity does not use real constructors with arguments
|
||||
/// </summary>
|
||||
/// <param name="humanoid">The humanoid for this hips target</param>
|
||||
public void Constructor(HumanoidControl humanoid) {
|
||||
this.humanoid = humanoid;
|
||||
chest = new TargetedChestBone(this);
|
||||
spine = new TargetedSpineBone(this);
|
||||
hips = new TargetedHipsBone(this);
|
||||
@ -165,7 +170,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedChestBone : TargetedBone {
|
||||
private HipsTarget hipsTarget;
|
||||
|
||||
public TargetedChestBone(HipsTarget hipsTarget) {
|
||||
public TargetedChestBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) {
|
||||
this.hipsTarget = hipsTarget;
|
||||
boneId = Bone.Chest;
|
||||
}
|
||||
@ -178,6 +183,14 @@ namespace Passer.Humanoid {
|
||||
boneId = Bone.Chest;
|
||||
}
|
||||
|
||||
public override Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
bone.transform = FindTransformByPartialName(rootBone, "chest");
|
||||
if (bone.transform == null)
|
||||
bone.transform = FindTransformByPartialName(rootBone, "spine2");
|
||||
return bone.transform;
|
||||
|
||||
}
|
||||
|
||||
public override Quaternion DetermineRotation() {
|
||||
if (nextBone.bone.transform == null)
|
||||
return Quaternion.identity;
|
||||
@ -211,7 +224,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedSpineBone : TargetedBone {
|
||||
private HipsTarget hipsTarget;
|
||||
|
||||
public TargetedSpineBone(HipsTarget hipsTarget) {
|
||||
public TargetedSpineBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) {
|
||||
this.hipsTarget = hipsTarget;
|
||||
boneId = Bone.Spine;
|
||||
}
|
||||
@ -225,6 +238,11 @@ namespace Passer.Humanoid {
|
||||
boneId = Bone.Spine;
|
||||
}
|
||||
|
||||
public override Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
bone.transform = FindTransformByPartialName(rootBone, "spine");
|
||||
return bone.transform;
|
||||
}
|
||||
|
||||
public override Quaternion DetermineRotation() {
|
||||
Vector3 spineUpDirection = hipsTarget.humanoid.up;
|
||||
if (nextBone != null && nextBone.bone.transform != null)
|
||||
@ -254,7 +272,7 @@ namespace Passer.Humanoid {
|
||||
public class TargetedHipsBone : TargetedBone {
|
||||
public HipsTarget hipsTarget;
|
||||
|
||||
public TargetedHipsBone(HipsTarget hipsTarget) {
|
||||
public TargetedHipsBone(HipsTarget hipsTarget) : base(hipsTarget.humanoid) {
|
||||
this.hipsTarget = hipsTarget;
|
||||
boneId = Bone.Hips;
|
||||
}
|
||||
@ -270,10 +288,11 @@ namespace Passer.Humanoid {
|
||||
boneId = Bone.Hips;
|
||||
}
|
||||
|
||||
public override void RetrieveBones(HumanoidControl humanoid) {
|
||||
base.RetrieveBones(humanoid);
|
||||
public override Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
bone.transform = FindTransformByPartialName(rootBone, "hips");
|
||||
if (bone.transform == null)
|
||||
HumanoidTarget.GetDefaultBone(humanoid.transform, ref bone.transform, "Default_simple|Hips");
|
||||
bone.transform = FindTransformByPartialName(rootBone, "pelvis");
|
||||
return bone.transform;
|
||||
}
|
||||
|
||||
public Vector3 GetForward() {
|
||||
@ -430,9 +449,15 @@ namespace Passer.Humanoid {
|
||||
}
|
||||
|
||||
public void RetrieveBones() {
|
||||
hips.RetrieveBones(humanoid);
|
||||
spine.RetrieveBones(humanoid);
|
||||
chest.RetrieveBones(humanoid);
|
||||
hips.RetrieveBones();
|
||||
spine.RetrieveBones();
|
||||
chest.RetrieveBones();
|
||||
}
|
||||
|
||||
public void RetrieveBonesWithoutAvatar(Transform rootBone) {
|
||||
hips.RetrieveBoneWithoutAvatar(rootBone);
|
||||
spine.RetrieveBoneWithoutAvatar(rootBone);
|
||||
chest.RetrieveBoneWithoutAvatar(rootBone);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -530,7 +555,7 @@ namespace Passer.Humanoid {
|
||||
|
||||
// We need the neck.bone to measure the chest length. This can be null when the avatar is changed
|
||||
if (humanoid.headTarget.neck.bone.transform == null)
|
||||
humanoid.headTarget.neck.RetrieveBones(humanoid);
|
||||
humanoid.headTarget.neck.RetrieveBones();
|
||||
//HeadTarget.GetDefaultNeck(humanoid.avatarRig, ref humanoid.headTarget.neck.bone.transform);
|
||||
humanoid.headTarget.neck.SetTargetPositionToAvatar();
|
||||
|
||||
@ -598,7 +623,7 @@ namespace Passer.Humanoid {
|
||||
hipsTarget = hipsTargetTransform.GetComponent<HipsTarget>();
|
||||
if (hipsTarget == null) {
|
||||
hipsTarget = hipsTargetTransform.gameObject.AddComponent<HipsTarget>();
|
||||
hipsTarget.humanoid = humanoid;
|
||||
hipsTarget.Constructor(humanoid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,34 +213,49 @@ namespace Passer.Humanoid {
|
||||
// 1 = MCS / Morph3D
|
||||
// 2 = AutoDesk
|
||||
public static void GetDefaultBone(Animator rig, ref Transform boneTransform, params string[] boneNames) {
|
||||
GetDefaultBoneByName(rig.transform, ref boneTransform, boneNames);
|
||||
}
|
||||
|
||||
public static void GetDefaultBoneByName(Transform root, ref Transform boneTransform, params string[] boneNames) {
|
||||
if (boneTransform != null)
|
||||
// We already have found a bone
|
||||
return;
|
||||
|
||||
for (int i = 0; i < boneNames.Length; i++) {
|
||||
if (boneNames[i] == null)
|
||||
foreach (string boneName in boneNames) {
|
||||
if (string.IsNullOrEmpty(boneName))
|
||||
continue;
|
||||
|
||||
boneTransform = rig.transform.FindDeepChild(boneNames[i]);
|
||||
boneTransform = root.FindDeepChild(boneName);
|
||||
if (boneTransform != null)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetDefaultBone(Transform root, ref Transform boneTransform, params string[] boneNames) {
|
||||
if (boneTransform != null)
|
||||
return;
|
||||
/// <summary>
|
||||
/// Recursively find a Transform whose name contains the partialName
|
||||
/// </summary>
|
||||
/// <param name="transform">The starting transform for the search</param>
|
||||
/// <param name="partialName">The string which should be inside by the name</param>
|
||||
/// <returns>The found Transform or null when no Transform has been found</returns>
|
||||
/// <remarks>The search stops at transforms with more than 1 child</remarks>
|
||||
public static Transform FindTransformByPartialName(Transform transform, string partialName) {
|
||||
if (transform == null)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < boneNames.Length; i++) {
|
||||
if (boneNames[i] == null)
|
||||
continue;
|
||||
// Case-insensitive string.Contains
|
||||
if (transform.name.IndexOf(partialName, System.StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return transform;
|
||||
|
||||
boneTransform = root.FindDeepChild(boneNames[i]);
|
||||
if (boneTransform != null)
|
||||
return;
|
||||
Transform foundTransform = null;
|
||||
for (int childIx = 0; childIx < transform.childCount; childIx++) {
|
||||
foundTransform = FindTransformByPartialName(transform.GetChild(childIx), partialName);
|
||||
if (foundTransform != null)
|
||||
return foundTransform;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public abstract void UpdateMovements(HumanoidControl humanoid);
|
||||
|
||||
public abstract void MatchTargetsToAvatar();
|
||||
@ -396,9 +411,16 @@ namespace Passer.Humanoid {
|
||||
[System.NonSerialized]
|
||||
public TargetedBone nextBone;
|
||||
|
||||
public TargetedBone() { }
|
||||
protected HumanoidControl humanoid;
|
||||
|
||||
public TargetedBone(TargetedBone _nextBone) {
|
||||
public TargetedBone(HumanoidControl humanoid) {
|
||||
if (humanoid == null)
|
||||
throw new System.Exception("Humanoid may not be null");
|
||||
this.humanoid = humanoid;
|
||||
}
|
||||
public TargetedBone(HumanoidControl humanoid, TargetedBone _nextBone) {
|
||||
if (humanoid == null)
|
||||
throw new System.Exception("Humanoid may not be null");
|
||||
nextBone = _nextBone;
|
||||
}
|
||||
|
||||
@ -415,19 +437,36 @@ namespace Passer.Humanoid {
|
||||
return obj.transform;
|
||||
}
|
||||
|
||||
public virtual void RetrieveBones(HumanoidControl humanoid) {
|
||||
if (humanoid.targetsRig != null)
|
||||
GetDefaultTargetBone(humanoid.targetsRig, ref target.transform, boneId);
|
||||
if (humanoid.avatarRig != null)
|
||||
GetDefaultBone(humanoid.avatarRig, ref bone.transform, boneId);
|
||||
public virtual void RetrieveBones() {
|
||||
if (this.humanoid == null)
|
||||
return;
|
||||
|
||||
if (this.humanoid.targetsRig != null)
|
||||
GetDefaultTargetBone(this.humanoid.targetsRig, ref target.transform, boneId);
|
||||
if (this.humanoid.avatarRig != null)
|
||||
GetDefaultBone(this.humanoid.avatarRig, ref bone.transform, boneId);
|
||||
}
|
||||
|
||||
public void RetrieveBone(HumanoidControl humanoid, HumanBodyBones boneID) {
|
||||
if ((bone.transform == null || bone.transform == null) && humanoid.avatarRig != null) {
|
||||
bone.transform = humanoid.avatarRig.GetBoneTransform(boneID);
|
||||
public void RetrieveBone(HumanBodyBones boneID) {
|
||||
if ((bone.transform == null || bone.transform == null) && this.humanoid.avatarRig != null) {
|
||||
bone.transform = this.humanoid.avatarRig.GetBoneTransform(boneID);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Transform RetrieveBoneWithoutAvatar(Transform rootBone) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//public static Transform RetrieveBoneByName(Transform rootBone, string transformName) {
|
||||
// Transform parentTransform;
|
||||
// //if (this.parent != null && this.parent.bone.transform != null)
|
||||
// // parentTransform = this.parent.bone.transform;
|
||||
// //else
|
||||
// parentTransform = rootBone;
|
||||
|
||||
// return HumanoidTarget.FindTransformByPartialName(parentTransform, transformName);
|
||||
//}
|
||||
|
||||
public virtual Quaternion DetermineRotation() {
|
||||
if (target.transform != null)
|
||||
return target.transform.rotation;
|
||||
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86153051f48cf8c488177d8f1b7aedaa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
x
Reference in New Issue
Block a user