From 0fec907a212c9f49fb1ee651ba1274b725e6c6ed Mon Sep 17 00:00:00 2001 From: jorgejgnz Date: Sat, 5 Jun 2021 12:35:30 +0200 Subject: [PATCH] fix(avatarModule): Public functions restored in AvatarController --- README.md | 2 +- Runtime/Modules/Avatar/AvatarController.cs | 61 ++++++++-------------- Samples/Prefabs/Pheasy/Dumbbell.prefab | 53 ++----------------- 3 files changed, 27 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 9976a74..bfdbe31 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ logo
License: MIT - version + version


diff --git a/Runtime/Modules/Avatar/AvatarController.cs b/Runtime/Modules/Avatar/AvatarController.cs index c4dafe4..2dee5aa 100644 --- a/Runtime/Modules/Avatar/AvatarController.cs +++ b/Runtime/Modules/Avatar/AvatarController.cs @@ -121,7 +121,7 @@ void StartPart(PartModel part) { p.body = part.body; StartPart(p); - } + } }); if (part is HandModel) HandStart(part as HandModel); @@ -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) @@ -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(); }); } @@ -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) @@ -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 rayRepr in h.ray.reprs) + foreach (KeyValuePair 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; @@ -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); @@ -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) { @@ -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) diff --git a/Samples/Prefabs/Pheasy/Dumbbell.prefab b/Samples/Prefabs/Pheasy/Dumbbell.prefab index 8309ae2..05d292d 100644 --- a/Samples/Prefabs/Pheasy/Dumbbell.prefab +++ b/Samples/Prefabs/Pheasy/Dumbbell.prefab @@ -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 @@ -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 @@ -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 @@ -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: