diff --git a/Editor/HumanoidControl/Targets/HandTarget_Editor.cs b/Editor/HumanoidControl/Targets/HandTarget_Editor.cs index 8a37d7c..045fdc9 100644 --- a/Editor/HumanoidControl/Targets/HandTarget_Editor.cs +++ b/Editor/HumanoidControl/Targets/HandTarget_Editor.cs @@ -145,8 +145,6 @@ namespace Passer.Humanoid { InteractionPointerButton(handTarget); serializedObject.ApplyModifiedProperties(); - //serializedObject.Update(); - //serializedObject.ApplyModifiedProperties(); } public static HandTarget Inspector(HandTarget handTarget, string name) { @@ -439,8 +437,8 @@ namespace Passer.Humanoid { if (showSettings) { EditorGUI.indentLevel++; - // Cannot use serializedPropery because showRealObjects is a getter/setter - bool showRealObjects = EditorGUILayout.Toggle("Show Real Objects", handTarget.showRealObjects); + SerializedProperty showObjectsProp = serializedObject.FindProperty("_showRealObjects"); + bool showRealObjects = EditorGUILayout.Toggle("Show Real Objects", showObjectsProp.boolValue); if (showRealObjects != handTarget.showRealObjects) { handTarget.showRealObjects = showRealObjects; handTarget.ShowSensors(showRealObjects, true); diff --git a/Editor/Tools/Handle_Editor.cs b/Editor/Tools/Handle_Editor.cs index ca16355..6c545a7 100644 --- a/Editor/Tools/Handle_Editor.cs +++ b/Editor/Tools/Handle_Editor.cs @@ -4,6 +4,7 @@ using UnityEngine; namespace Passer { using Humanoid; + [CanEditMultipleObjects] [CustomEditor(typeof(Handle), true)] public class Handle_Editor : Editor { @@ -42,9 +43,14 @@ namespace Passer { //if (HumanoidPreferences.help) // EditorGUILayout.HelpBox("Component to specify behaviour when grabbing the GameObject", MessageType.None); - handle.hand = (Handle.Hand)EditorGUILayout.EnumPopup("Hand", handle.hand); - handle.grabType = (Handle.GrabType)EditorGUILayout.EnumPopup("Grab type", handle.grabType); - handle.range = EditorGUILayout.FloatField("Range", handle.range); + SerializedProperty handProp = serializedObject.FindProperty(nameof(Handle.hand)); + handProp.intValue = (int)(Handle.Hand)EditorGUILayout.EnumPopup("Hand", (Handle.Hand)handProp.intValue); + + SerializedProperty grabTypeProp = serializedObject.FindProperty(nameof(Handle.grabType)); + grabTypeProp.intValue = (int)(Handle.GrabType)EditorGUILayout.EnumPopup("Grab type", (Handle.GrabType)grabTypeProp.intValue); + + SerializedProperty rangeProp = serializedObject.FindProperty(nameof(Handle.range)); + rangeProp.floatValue = EditorGUILayout.FloatField("Range", rangeProp.floatValue); HandPoseInspector(handle); CheckHandTarget(handle); diff --git a/Runtime/HumanoidControl/Scripts/Extensions/UnityXR/UnityXRController.cs b/Runtime/HumanoidControl/Scripts/Extensions/UnityXR/UnityXRController.cs index cd54ada..a042e37 100644 --- a/Runtime/HumanoidControl/Scripts/Extensions/UnityXR/UnityXRController.cs +++ b/Runtime/HumanoidControl/Scripts/Extensions/UnityXR/UnityXRController.cs @@ -11,6 +11,12 @@ namespace Passer.Tracking { protected XRNode xrNode; + protected enum LoadedDeviceType { + None, + Oculus, + OpenXR, + } + protected LoadedDeviceType loadedDevice = LoadedDeviceType.None; public GameObject model; #region Manage @@ -130,6 +136,12 @@ namespace Passer.Tracking { InputDevices.deviceConnected += OnDeviceConnected; InputDevices.deviceDisconnected += OnDeviceDisconnected; + + if (XRSettings.loadedDeviceName == "oculus display") + loadedDevice = LoadedDeviceType.Oculus; + else if (XRSettings.loadedDeviceName == "OpenXR Display") + loadedDevice = LoadedDeviceType.OpenXR; + } /// @@ -188,6 +200,8 @@ namespace Passer.Tracking { Quaternion rotation; if (isTracked && device.TryGetFeatureValue(CommonUsages.deviceRotation, out rotation)) { + if (loadedDevice == LoadedDeviceType.OpenXR) + rotation *= Quaternion.AngleAxis(45, Vector3.right); transform.rotation = trackerTransform.rotation * rotation; rotationConfidence = 1; status = Tracker.Status.Tracking; diff --git a/Runtime/HumanoidControl/Scripts/HumanoidControl.cs b/Runtime/HumanoidControl/Scripts/HumanoidControl.cs index 1cb6d07..bb17943 100644 --- a/Runtime/HumanoidControl/Scripts/HumanoidControl.cs +++ b/Runtime/HumanoidControl/Scripts/HumanoidControl.cs @@ -470,7 +470,7 @@ namespace Passer.Humanoid { OnChangeAvatarEvent?.Invoke(); } - public void InitializeAvatar() { + public virtual void InitializeAvatar() { avatarRig = GetAvatar(this.gameObject); // Move the animator controller to the targets rig for proper animation support @@ -2085,7 +2085,7 @@ namespace Passer.Humanoid { hitNormal = Vector3.zero; } - public bool IsMyRigidbody(Rigidbody rigidbody) { + public virtual bool IsMyRigidbody(Rigidbody rigidbody) { return rigidbody != null && ( rigidbody == humanoidRigidbody || diff --git a/Runtime/HumanoidControl/Scripts/Interaction/HandInteraction.cs b/Runtime/HumanoidControl/Scripts/Interaction/HandInteraction.cs index 3ff62ed..cb42708 100644 --- a/Runtime/HumanoidControl/Scripts/Interaction/HandInteraction.cs +++ b/Runtime/HumanoidControl/Scripts/Interaction/HandInteraction.cs @@ -114,7 +114,7 @@ namespace Passer.Humanoid { } } - private void DeterminePalmPosition() { + protected void DeterminePalmPosition() { if (hand.bone.transform == null) return; @@ -658,13 +658,16 @@ namespace Passer.Humanoid { return false; } + // We need to determine this here because the kinematic state + // can change when grabbing + grabbedKinematicRigidbody = objRigidbody.isKinematic; + if (objRigidbody.isKinematic) GrabStaticWithoutHandle(objRigidbody.gameObject); else GrabRigidbodyParenting(objRigidbody); grabbedRigidbody = true; - grabbedKinematicRigidbody = objRigidbody.isKinematic; return true; } diff --git a/Runtime/HumanoidControl/Scripts/Physics/HandPhysics.cs b/Runtime/HumanoidControl/Scripts/Physics/HandPhysics.cs index 06acd71..9194e02 100644 --- a/Runtime/HumanoidControl/Scripts/Physics/HandPhysics.cs +++ b/Runtime/HumanoidControl/Scripts/Physics/HandPhysics.cs @@ -23,7 +23,7 @@ namespace Passer.Humanoid { } [HideInInspector] - protected Rigidbody handRigidbody; + public Rigidbody handRigidbody; protected virtual void Initialize() { if (handTarget == null) @@ -186,7 +186,7 @@ namespace Passer.Humanoid { #region Force - protected Vector3 CalculateForce() { + protected virtual Vector3 CalculateForce() { /* //Vector3 locationDifference = handTarget.stretchlessTarget.position - handTarget.handRigidbody.position; //Debug.DrawLine(handTarget.stretchlessTarget.position, handTarget.handRigidbody.position); @@ -204,7 +204,7 @@ namespace Passer.Humanoid { return force; } - public Vector3 CalculateForce(Vector3 position, Vector3 targetPosition, bool damping = false) { + public virtual Vector3 CalculateForce(Vector3 position, Vector3 targetPosition, bool damping = false) { Vector3 force = (targetPosition - position) * handTarget.strength; if (damping) force += CalculateForceDamper(); @@ -212,9 +212,9 @@ namespace Passer.Humanoid { } private const float damping = 12; - private float lastDistanceTime; - private Vector3 lastDistanceToTarget; - private Vector3 CalculateForceDamper() { + protected float lastDistanceTime; + protected Vector3 lastDistanceToTarget; + protected virtual Vector3 CalculateForceDamper() { Vector3 distanceToTarget = handTarget.hand.bone.transform.position - handTarget.hand.target.transform.position; float deltaTime = Time.fixedTime - lastDistanceTime; @@ -237,7 +237,7 @@ namespace Passer.Humanoid { return damper; } - protected void ApplyForce(Vector3 force) { + protected virtual void ApplyForce(Vector3 force) { if (float.IsNaN(force.magnitude)) return; @@ -266,7 +266,7 @@ namespace Passer.Humanoid { #endif } - protected void ApplyForceAtPosition(Vector3 force, Vector3 position) { + protected virtual void ApplyForceAtPosition(Vector3 force, Vector3 position) { if (float.IsNaN(force.magnitude)) return; @@ -280,7 +280,7 @@ namespace Passer.Humanoid { #region Torque - protected Vector3 CalculateTorque() { + protected virtual Vector3 CalculateTorque() { Quaternion sollRotation = handTarget.hand.target.transform.rotation * handTarget.hand.target.toBoneRotation; Quaternion istRotation = handTarget.hand.bone.transform.rotation; Quaternion dRot = sollRotation * Quaternion.Inverse(istRotation); @@ -295,7 +295,7 @@ namespace Passer.Humanoid { return torque; } - protected Vector3 CalculateWristTorque() { + protected virtual Vector3 CalculateWristTorque() { //Vector3 wristTension = target.GetWristTension(); // Not stable @@ -311,7 +311,7 @@ namespace Passer.Humanoid { ApplyTorqueAtPosition(torque, handTarget.hand.bone.transform.position); } - protected void ApplyTorqueAtPosition(Vector3 torque, Vector3 posToApply) { + protected virtual void ApplyTorqueAtPosition(Vector3 torque, Vector3 posToApply) { if (float.IsNaN(torque.magnitude)) return; @@ -677,7 +677,7 @@ namespace Passer.Humanoid { handTarget.grabbedObject.SendMessage("OnCollisionEnter", collision, SendMessageOptions.DontRequireReceiver); } - public void OnCollisionStay(Collision collision) { + public virtual void OnCollisionStay(Collision collision) { if (collision.rigidbody != null && collision.rigidbody.gameObject == handTarget.grabbedObject) // Don't collide with the things you are holding return; diff --git a/Runtime/HumanoidControl/Scripts/Physics/HandSocket.cs b/Runtime/HumanoidControl/Scripts/Physics/HandSocket.cs index a99b380..7993853 100644 --- a/Runtime/HumanoidControl/Scripts/Physics/HandSocket.cs +++ b/Runtime/HumanoidControl/Scripts/Physics/HandSocket.cs @@ -13,17 +13,17 @@ namespace Passer.Humanoid { /// This is the HandTarget of the hand to which the socket is attached public HandTarget handTarget; - protected override void MoveHandleToSocket(Transform socketTransform, Handle handle) { - DebugLog("MoveHandleToHand"); + //protected override void MoveHandleToSocket(Transform socketTransform, Handle handle) { + // DebugLog("MoveHandleToHand"); - Transform handleTransform = handle.GetComponent(); - Rigidbody handleRigidbody = handle.GetComponentInParent(); - if (handleRigidbody != null) - handleTransform = handleRigidbody.transform; + // Transform handleTransform = handle.GetComponent(); + // Rigidbody handleRigidbody = handle.GetComponentInParent(); + // if (handleRigidbody != null) + // handleTransform = handleRigidbody.transform; - handleTransform.rotation = handle.RotationTo(socketTransform.rotation) * handleTransform.rotation; - handleTransform.position += handle.TranslationTo(socketTransform.position); - } + // handleTransform.rotation = handle.RotationTo(socketTransform.rotation) * handleTransform.rotation; + // handleTransform.position += handle.TranslationTo(socketTransform.position); + //} protected override void MoveSocketToHandle(Transform socketTransform, Handle handle) { DebugLog("MoveHandToHandle"); @@ -155,7 +155,7 @@ namespace Passer.Humanoid { DestroyedJoints destroyedJoints = objRigidbody.GetComponent(); // Check if we are grabbing a hand - BasicHandPhysics handPhysics = objRigidbody.GetComponent(); + BasicHandPhysics handPhysics = objRigidbody.GetComponentInParent(); if (handPhysics != null) { // We are grabbing a hand if (thisRigidbody == null) { DebugLog("Cannot attach to hand because this handRigidbody is not present"); diff --git a/Runtime/HumanoidControl/Scripts/Pose/BonePose.cs b/Runtime/HumanoidControl/Scripts/Pose/BonePose.cs index 57cef19..9ac0f47 100644 --- a/Runtime/HumanoidControl/Scripts/Pose/BonePose.cs +++ b/Runtime/HumanoidControl/Scripts/Pose/BonePose.cs @@ -40,17 +40,18 @@ namespace Passer.Humanoid { HumanoidTarget.TargetedBone referenceBone = humanoid.GetBone(referenceBoneRef.boneId); if (referenceBoneRef.boneId != Bone.None && referenceBone.target.transform != null) { referencePosition = referenceBone.target.transform.position; - referenceRotation = referenceBone.bone.targetRotation; + referenceRotation = referenceBone.target.transform.rotation; //referenceBone.bone.targetRotation; referenceScale = referenceBone.target.transform.lossyScale; } else { - referencePosition = humanoid.transform.position; + referencePosition = targetedBone.TargetBasePosition(); // humanoid.transform.position; referenceRotation = humanoid.transform.rotation; referenceScale = humanoid.transform.lossyScale; } if (setTranslation) - targetedBone.target.transform.position = targetedBone.TargetBasePosition() + Vector3.Lerp(Vector3.zero, referenceRotation * translation, value); + //targetedBone.target.transform.position = targetedBone.TargetBasePosition() + Vector3.Lerp(Vector3.zero, referenceRotation * translation, value); + targetedBone.target.transform.position = referencePosition + Vector3.Lerp(Vector3.zero, referenceRotation * translation, value); if (setRotation) targetedBone.target.transform.rotation = Quaternion.Slerp(targetedBone.TargetBaseRotation(), referenceRotation * rotation, value); if (setScale) diff --git a/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs b/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs index 69988ab..c74a3f6 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/HandTarget.cs @@ -650,7 +650,7 @@ namespace Passer.Humanoid { #endregion - private void InitSubTargets() { + protected void InitSubTargets() { //foreach (TargetedBone subTarget in subTargets) // subTarget.Init(); shoulder.Init(); diff --git a/Runtime/HumanoidControl/Scripts/Targets/Target.cs b/Runtime/HumanoidControl/Scripts/Targets/Target.cs index fe2b0ca..752c9a4 100644 --- a/Runtime/HumanoidControl/Scripts/Targets/Target.cs +++ b/Runtime/HumanoidControl/Scripts/Targets/Target.cs @@ -17,6 +17,7 @@ namespace Passer { /// public abstract class Target : MonoBehaviour { + [SerializeField] protected bool _showRealObjects = true; /// /// show the target meshes diff --git a/Runtime/Tools/Physics/HybridPhysics.cs b/Runtime/Tools/Physics/HybridPhysics.cs index 805b1c6..951b60c 100644 --- a/Runtime/Tools/Physics/HybridPhysics.cs +++ b/Runtime/Tools/Physics/HybridPhysics.cs @@ -90,7 +90,7 @@ namespace Passer { } virtual protected void UpdateKinematicRigidbody() { - if (mode == PhysicsMode.NonKinematic || + if (mode == PhysicsMode.NonKinematic || thisRigidbody.mass > kinematicMass || thisRigidbody.GetComponent() != null ) { @@ -183,7 +183,7 @@ namespace Passer { // The sweeptests fail quite often... //RaycastHit hit; //if (!thisRigidbody.SweepTest(target.transform.position - thisRigidbody.position, out hit)) - hasCollided = false; + hasCollided = false; } } @@ -581,8 +581,10 @@ namespace Passer { if (colliders == null) return; - foreach (Collider c in colliders) - c.isTrigger = false; + foreach (Collider c in colliders) { + if (c != null) + c.isTrigger = false; + } } /// @@ -597,8 +599,10 @@ namespace Passer { if (colliders == null) return; - foreach (Collider c in colliders) - c.isTrigger = false; + foreach (Collider c in colliders) { + if (c != null) + c.isTrigger = false; + } } #endregion