Skip to content

Commit

Permalink
fix(avatarModule): Public functions restored in AvatarController
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgejgnz committed Jun 5, 2021
1 parent 56d0481 commit 0fec907
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="https://imgur.com/QHED9DH.png" height="150" alt="logo"><br>
<a href="https://unity3d.com/es/get-unity/download/archive"><img src="https://img.shields.io/badge/unity-2019.4%20or%20later-green.svg" alt=""></a>
<a href="https://github.com/jorgejgnz/HPTK/blob/master/LICENSE.md"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
<a href="https://github.com/jorgejgnz/HPTK/releases"><img src="https://img.shields.io/badge/version-0.6.1-blue" alt="version"></a>
<a href="https://github.com/jorgejgnz/HPTK/releases"><img src="https://img.shields.io/badge/version-0.6.2-blue" alt="version"></a>
<a href="https://discord.gg/TuzhMZQpDy"><img src="https://img.shields.io/discord/679793598958403620?logo=discord" alt=""></a>
<a href="https://twitter.com/intent/follow?screen_name=jorgejgnz"><img src="https://img.shields.io/twitter/follow/jorgejgnz.svg?label=Follow&amp;style=social" alt=""></a>
</p><br>
Expand Down
61 changes: 23 additions & 38 deletions Runtime/Modules/Avatar/AvatarController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void StartPart(PartModel part)
{
p.body = part.body;
StartPart(p);
}
}
});

if (part is HandModel) HandStart(part as HandModel);
Expand All @@ -138,8 +138,9 @@ public override void ControllerUpdate()
// Update body related controllers
model.bodies.ForEach(r => UpdateBody(r));

// Update proxy-body related controllers
if (HPTK.core.controlsUpdateCalls) model.registry.ForEach(c => c.ControllerUpdate());
// Update registered controllers

if (HPTK.core.controlsUpdateCalls) model.registry.ForEach((c) => { if (c.gameObject.activeSelf) c.ControllerUpdate(); });
}

void UpdateBody(BodyModel body)
Expand Down Expand Up @@ -167,6 +168,8 @@ void UpdateBody(BodyModel body)

body.parts.ForEach(p => { if (p.gameObject.activeSelf) UpdatePart(p); });

// Update registered controllers

if (HPTK.core.controlsUpdateCalls) body.registry.ForEach((c) => { if (c.gameObject.activeSelf) c.ControllerUpdate(); });
}

Expand All @@ -177,7 +180,9 @@ void UpdatePart(PartModel part)

part.bones.ForEach(b => { if (b.gameObject.activeSelf) UpdateBone(b); });

if (HPTK.core.controlsUpdateCalls) part.registry.ForEach(c => { if (c.gameObject.activeSelf) c.ControllerUpdate(); });
// Update registered controllers

if (HPTK.core.controlsUpdateCalls) part.registry.ForEach((c) => { if (c.gameObject.activeSelf) c.ControllerUpdate(); });
}

void UpdateHand(HandModel h)
Expand All @@ -187,16 +192,12 @@ void UpdateHand(HandModel h)
BoneModel shoulderBone;
if (h.side == Side.Left) shoulderBone = h.body.leftArm.shoulder;
else shoulderBone = h.body.rightArm.shoulder;

PointModel shoulder = null;
if (shoulderBone) shoulder = shoulderBone.point;

Vector3 rayDir;

foreach(KeyValuePair<string,ReprModel> rayRepr in h.ray.reprs)
foreach (KeyValuePair<string, ReprModel> rayRepr in h.ray.reprs)
{
rayDir = Vector3.zero;

if (shoulder && shoulder.reprs.ContainsKey(rayRepr.Key))
{
rayDir = (rayRepr.Value.transformRef.position - shoulder.reprs[rayRepr.Key].transformRef.position).normalized;
Expand All @@ -205,9 +206,7 @@ void UpdateHand(HandModel h)
{
rayDir = Quaternion.Lerp(h.body.torso.head.reprs[rayRepr.Key].transformRef.rotation, h.palmNormal.reprs[rayRepr.Key].transformRef.rotation, 0.5f) * Vector3.forward;
}

if (rayDir != Vector3.zero) rayRepr.Value.transformRef.forward = rayDir;

if (h.palmNormal.reprs.ContainsKey(rayRepr.Key) && h.palmNormal.reprs[rayRepr.Key].transformRef)
{
rayRepr.Value.transformRef.gameObject.SetActive(Vector3.Dot(h.palmNormal.reprs[rayRepr.Key].transformRef.forward, rayRepr.Value.transformRef.forward) > 0.0f);
Expand All @@ -218,7 +217,7 @@ void UpdateHand(HandModel h)

void UpdateFinger(FingerModel f) { }

void UpdateBone(BoneModel bone) { }
void UpdateBone(BoneModel b) { }

public float GetFingerLength(FingerModel finger)
{
Expand Down Expand Up @@ -362,42 +361,28 @@ public void FingerStart(FingerModel finger)
AvatarHelpers.GetBonesFromRootToTip(finger, finger.bonesFromRootToTip);
}

public Quaternion GetLocalRotation(BoneModel b, string reprKey, bool relativeToParentBone)
public Quaternion GetLocalRotation(ReprModel repr)
{
if (!b.parent || !relativeToParentBone) return b.point.reprs[reprKey].transformRef.localRotation;

if (!b.parent.point.reprs.ContainsKey(reprKey))
{
Debug.LogWarning("Parent of bone " + b.name + ", " + b.parent.name + ", does not have a " + reprKey + " representation. Getting localRotation");
return b.point.reprs[reprKey].transformRef.localRotation;
}

return Quaternion.Inverse(b.parent.point.reprs[reprKey].transformRef.rotation) * b.point.reprs[reprKey].transformRef.rotation;
if (!repr.parent || !repr.relativeToParentBone) return repr.transformRef.localRotation;
return Quaternion.Inverse(repr.parent.transformRef.rotation) * repr.transformRef.rotation;
}

public Quaternion GetWorldFromLocalRotation(Quaternion newLocalRot, BoneModel b, string reprKey, bool relativeToParentBone)
public Quaternion GetWorldFromLocalRotation(Quaternion newLocalRot, ReprModel repr)
{
if (!b.parent || !relativeToParentBone) return b.point.reprs[reprKey].transformRef.parent.rotation * newLocalRot;
return b.parent.point.reprs[reprKey].transformRef.rotation * newLocalRot;
if (!repr.parent || !repr.relativeToParentBone) return repr.transformRef.parent.rotation * newLocalRot;
return repr.parent.transformRef.rotation * newLocalRot;
}

public Vector3 GetLocalPosition(BoneModel b, string reprKey, bool relativeToParentBone)
public Vector3 GetLocalPosition(ReprModel repr)
{
if (!b.parent || !relativeToParentBone) return b.point.reprs[reprKey].transformRef.localPosition;

if (!b.parent.point.reprs.ContainsKey(reprKey))
{
Debug.LogWarning("Parent of bone " + b.name + ", " + b.parent.name + ", does not have a " + reprKey + " representation. Getting localPosition");
return b.point.reprs[reprKey].transformRef.localPosition;
}

return b.parent.point.reprs[reprKey].transformRef.InverseTransformPoint(b.point.reprs[reprKey].transformRef.position);
if (!repr.parent || !repr.relativeToParentBone) return repr.transformRef.localPosition;
return repr.parent.transformRef.InverseTransformPoint(repr.transformRef.position);
}

public Vector3 GetWorldFromLocalPoition(Vector3 newLocalPos, BoneModel b, string reprKey, bool relativeToParentBone)
public Vector3 GetWorldFromLocalPoition(Vector3 newLocalPos, ReprModel repr)
{
if (!b.parent || !relativeToParentBone) return b.point.reprs[reprKey].transformRef.parent.TransformPoint(newLocalPos);
return b.parent.point.reprs[reprKey].transformRef.TransformPoint(newLocalPos);
if (!repr.parent || !repr.relativeToParentBone) return repr.transformRef.parent.TransformPoint(newLocalPos);
return repr.parent.transformRef.TransformPoint(newLocalPos);
}

public float GetProcessedAngleZ(Quaternion rotation)
Expand Down
53 changes: 3 additions & 50 deletions Samples/Prefabs/Pheasy/Dumbbell.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ GameObject:
- component: {fileID: 5511998641604690945}
- component: {fileID: 5511998641604690944}
- component: {fileID: 5511998641604691007}
- component: {fileID: 5511998641604691006}
- component: {fileID: 5511998641604691005}
m_Layer: 8
m_Name: Cylinder
m_TagString: Untagged
Expand Down Expand Up @@ -98,53 +96,6 @@ MeshCollider:
m_Convex: 1
m_CookingOptions: 30
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!54 &5511998641604691006
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5511998641604691003}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &5511998641604691005
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5511998641604691003}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d15de70d95a419b45acb6e5ca9092518, type: 3}
m_Name:
m_EditorClassIdentifier:
centerOfMass: {fileID: 0}
targets: []
colliders: []
collisionNotifier: {fileID: 0}
triggerNotifiers: []
safeMode: 1
maxVelocity: 20
maxAngularVelocity: 12.5
maxDepenetrationVelocity: 1
maxErrorAllowed: 0.5
ignoreCollisionsOnStart: 0
relations: []
onInit:
m_PersistentCalls:
m_Calls: []
disableEditModeAfterFrames: -1
axis: {fileID: 0}
axisScale: 0.02
ignoring: []
--- !u!1 &5511998641995786358
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -399,12 +350,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d15de70d95a419b45acb6e5ca9092518, type: 3}
m_Name:
m_EditorClassIdentifier:
rb: {fileID: 0}
centerOfMass: {fileID: 0}
targets: []
colliders: []
collisionNotifier: {fileID: 0}
triggerNotifiers: []
safeMode: 1
gradualMode: 1
maxVelocity: 20
maxAngularVelocity: 12.5
maxDepenetrationVelocity: 1
Expand All @@ -414,9 +367,9 @@ MonoBehaviour:
onInit:
m_PersistentCalls:
m_Calls: []
disableEditModeAfterFrames: -1
axis: {fileID: 0}
axisScale: 0.02
editMode: 1
ignoring: []
--- !u!114 &5511998642587595782
MonoBehaviour:
Expand Down

0 comments on commit 0fec907

Please sign in to comment.