Merge branch 'main' of http://gitlab.passervr.com/passer/unity/humanoidcontrol4_free
This commit is contained in:
commit
ba8d8cf6e0
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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;
|
||||
|
@ -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 ||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<Transform>();
|
||||
Rigidbody handleRigidbody = handle.GetComponentInParent<Rigidbody>();
|
||||
if (handleRigidbody != null)
|
||||
handleTransform = handleRigidbody.transform;
|
||||
// Transform handleTransform = handle.GetComponent<Transform>();
|
||||
// Rigidbody handleRigidbody = handle.GetComponentInParent<Rigidbody>();
|
||||
// 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<DestroyedJoints>();
|
||||
|
||||
// Check if we are grabbing a hand
|
||||
BasicHandPhysics handPhysics = objRigidbody.GetComponent<BasicHandPhysics>();
|
||||
BasicHandPhysics handPhysics = objRigidbody.GetComponentInParent<BasicHandPhysics>();
|
||||
if (handPhysics != null) { // We are grabbing a hand
|
||||
if (thisRigidbody == null) {
|
||||
DebugLog("Cannot attach to hand because this handRigidbody is not present");
|
||||
|
@ -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)
|
||||
|
@ -650,7 +650,7 @@ namespace Passer.Humanoid {
|
||||
|
||||
#endregion
|
||||
|
||||
private void InitSubTargets() {
|
||||
protected void InitSubTargets() {
|
||||
//foreach (TargetedBone subTarget in subTargets)
|
||||
// subTarget.Init();
|
||||
shoulder.Init();
|
||||
|
@ -17,6 +17,7 @@ namespace Passer {
|
||||
/// </summary>
|
||||
public abstract class Target : MonoBehaviour {
|
||||
|
||||
[SerializeField]
|
||||
protected bool _showRealObjects = true;
|
||||
/// <summary>
|
||||
/// show the target meshes
|
||||
|
@ -90,7 +90,7 @@ namespace Passer {
|
||||
}
|
||||
|
||||
virtual protected void UpdateKinematicRigidbody() {
|
||||
if (mode == PhysicsMode.NonKinematic ||
|
||||
if (mode == PhysicsMode.NonKinematic ||
|
||||
thisRigidbody.mass > kinematicMass ||
|
||||
thisRigidbody.GetComponent<Joint>() != 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user