Code improvement
This commit is contained in:
parent
03948b8b01
commit
998683a881
@ -2,6 +2,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
using Humanoid.Tracking;
|
using Humanoid.Tracking;
|
||||||
|
using Passer.Tracking;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class ArmPredictor : Humanoid.ArmSensor {
|
public class ArmPredictor : Humanoid.ArmSensor {
|
||||||
@ -10,6 +11,10 @@ namespace Passer.Humanoid {
|
|||||||
get { return Tracker.Status.Tracking; }
|
get { return Tracker.Status.Tracking; }
|
||||||
set { }
|
set { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
@ -21,6 +26,10 @@ namespace Passer.Humanoid {
|
|||||||
set { }
|
set { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public bool armSwing;
|
public bool armSwing;
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
protected Vector3 foot2hand;
|
protected Vector3 foot2hand;
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
|
using Passer.Tracking;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class HeadAnimator : HeadSensor {
|
public class HeadAnimator : HeadSensor {
|
||||||
public bool headAnimation = true;
|
public bool headAnimation = true;
|
||||||
public bool faceAnimation = true;
|
public bool faceAnimation = true;
|
||||||
|
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
#region Update
|
#region Update
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
if (!headTarget.humanoid.animatorEnabled || !enabled || headTarget.humanoid.targetsRig.runtimeAnimatorController != null)
|
if (!headTarget.humanoid.animatorEnabled || !enabled || headTarget.humanoid.targetsRig.runtimeAnimatorController != null)
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
|
using Passer.Tracking;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class HeadPredictor : HeadSensor {
|
public class HeadPredictor : HeadSensor {
|
||||||
private Vector3 positionalVelocity;
|
private Vector3 positionalVelocity;
|
||||||
private Quaternion rotationalVelocity;
|
private Quaternion rotationalVelocity;
|
||||||
|
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Start(HumanoidControl _humanoid, Transform targetTransform) {
|
public override void Start(HumanoidControl _humanoid, Transform targetTransform) {
|
||||||
base.Start(_humanoid, targetTransform);
|
base.Start(_humanoid, targetTransform);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
using Humanoid.Tracking;
|
using Passer.Tracking;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class LegAnimator : LegSensor {
|
public class LegAnimator : LegSensor {
|
||||||
|
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private LegAnimator leftAnimator;
|
private LegAnimator leftAnimator;
|
||||||
private LegAnimator rightAnimator;
|
private LegAnimator rightAnimator;
|
||||||
|
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
using Humanoid.Tracking;
|
using Passer.Tracking;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class TorsoAnimator : TorsoSensor {
|
public class TorsoAnimator : TorsoSensor {
|
||||||
|
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public enum BodyRotation {
|
public enum BodyRotation {
|
||||||
HeadRotation = 1,
|
HeadRotation = 1,
|
||||||
HeadAndHandRotation = 2,
|
HeadAndHandRotation = 2,
|
||||||
|
@ -10,7 +10,7 @@ namespace Passer.Humanoid {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An sensors used on the arm of a Humanoid
|
/// An sensors used on the arm of a Humanoid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ArmSensor : HumanoidSensor {
|
public abstract class ArmSensor : HumanoidSensor {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The HandTarget for this sensor
|
/// The HandTarget for this sensor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,7 +24,7 @@ namespace Passer.Humanoid {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The sensor used for this arm
|
/// The sensor used for this arm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SensorComponent sensorComponent;
|
//public SensorComponent sensorComponent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The skeleton for the hand
|
/// The skeleton for the hand
|
||||||
@ -367,7 +367,7 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
public class ArmController : Humanoid.ArmSensor {
|
public abstract class ArmController : Humanoid.ArmSensor {
|
||||||
protected Humanoid.Tracking.Sensor.ID sensorID;
|
protected Humanoid.Tracking.Sensor.ID sensorID;
|
||||||
protected Controller controllerInput;
|
protected Controller controllerInput;
|
||||||
public Humanoid.Tracking.ArmController oldController;
|
public Humanoid.Tracking.ArmController oldController;
|
||||||
|
@ -6,14 +6,14 @@ using UnityEditor;
|
|||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
using Passer.Tracking;
|
using Passer.Tracking;
|
||||||
|
|
||||||
public class HeadSensor : HumanoidSensor {
|
public abstract class HeadSensor : HumanoidSensor {
|
||||||
protected HeadTarget headTarget {
|
protected HeadTarget headTarget {
|
||||||
get { return target as HeadTarget; }
|
get { return target as HeadTarget; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HumanoidControl humanoid => headTarget.humanoid;
|
protected HumanoidControl humanoid => headTarget.humanoid;
|
||||||
|
|
||||||
public SensorComponent sensorComponent;
|
//public SensorComponent sensorComponent;
|
||||||
protected new Tracking.HeadSensor sensor;
|
protected new Tracking.HeadSensor sensor;
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,30 +4,33 @@ namespace Passer.Humanoid {
|
|||||||
using Passer.Tracking;
|
using Passer.Tracking;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class HumanoidSensor : Sensor {
|
public abstract class HumanoidSensor : Sensor {
|
||||||
|
|
||||||
public HumanoidSensor() {
|
public HumanoidSensor() {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public new HumanoidTracker tracker;
|
|
||||||
public new virtual HumanoidTracker tracker => null;
|
public new virtual HumanoidTracker tracker => null;
|
||||||
|
|
||||||
protected Tracking.Sensor sensor;
|
protected Tracking.Sensor sensor;
|
||||||
|
|
||||||
|
public SensorComponent sensorComponent;
|
||||||
|
/// <summary>
|
||||||
|
/// Returns sensorComponent and creates a new sensorComponent if it does not exist
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract SensorComponent GetSensorComponent();
|
||||||
|
|
||||||
[System.NonSerialized]
|
[System.NonSerialized]
|
||||||
public const string _name = "";
|
public const string _name = "";
|
||||||
public override string name { get { return _name; } }
|
public override string name { get { return _name; } }
|
||||||
|
|
||||||
//public Transform sensorTransform;
|
|
||||||
|
|
||||||
public Vector3 sensor2TargetPosition;
|
public Vector3 sensor2TargetPosition;
|
||||||
public Quaternion sensor2TargetRotation;
|
public Quaternion sensor2TargetRotation;
|
||||||
|
|
||||||
#region Start
|
#region Start
|
||||||
//public virtual void Init(HumanoidTracker _tracker) {
|
|
||||||
// tracker = _tracker;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public virtual void Start(HumanoidControl _humanoid, Transform targetTransform) {
|
public virtual void Start(HumanoidControl _humanoid, Transform targetTransform) {
|
||||||
target = targetTransform.GetComponent<Target>();
|
target = targetTransform.GetComponent<Target>();
|
||||||
|
@ -6,13 +6,12 @@ using UnityEditor;
|
|||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
using Passer.Tracking;
|
using Passer.Tracking;
|
||||||
|
|
||||||
public class LegSensor : HumanoidSensor {
|
public abstract class LegSensor : HumanoidSensor {
|
||||||
protected FootTarget footTarget => target as FootTarget;
|
protected FootTarget footTarget => target as FootTarget;
|
||||||
|
|
||||||
protected HumanoidControl humanoid => footTarget.humanoid;
|
protected HumanoidControl humanoid => footTarget.humanoid;
|
||||||
|
|
||||||
public SensorComponent sensorComponent;
|
//public SensorComponent sensorComponent;
|
||||||
//protected new Tracking.LegSensor sensor;
|
|
||||||
|
|
||||||
#region Manage
|
#region Manage
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace Passer {
|
namespace Passer {
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class Sensor {
|
public abstract class Sensor {
|
||||||
public bool enabled;
|
public bool enabled;
|
||||||
public virtual Tracker.Status status { get; set; }
|
public virtual Tracker.Status status { get; set; }
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ using UnityEditor;
|
|||||||
namespace Passer.Humanoid {
|
namespace Passer.Humanoid {
|
||||||
using Passer.Tracking;
|
using Passer.Tracking;
|
||||||
|
|
||||||
public class TorsoSensor : HumanoidSensor {
|
public abstract class TorsoSensor : HumanoidSensor {
|
||||||
|
|
||||||
protected HipsTarget hipsTarget {
|
protected HipsTarget hipsTarget {
|
||||||
get { return (HipsTarget)target; }
|
get { return (HipsTarget)target; }
|
||||||
@ -14,7 +14,7 @@ namespace Passer.Humanoid {
|
|||||||
|
|
||||||
protected HumanoidControl humanoid => hipsTarget.humanoid;
|
protected HumanoidControl humanoid => hipsTarget.humanoid;
|
||||||
|
|
||||||
public SensorComponent sensorComponent;
|
//public SensorComponent sensorComponent;
|
||||||
protected new Tracking.TorsoSensor sensor;
|
protected new Tracking.TorsoSensor sensor;
|
||||||
|
|
||||||
#region Manage
|
#region Manage
|
||||||
|
@ -12,9 +12,9 @@ namespace Passer {
|
|||||||
/// The tracking status
|
/// The tracking status
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum Status {
|
public enum Status {
|
||||||
Unavailable, //< The tracking device is not available
|
Unavailable, ///< The tracking device is not available
|
||||||
Present, //< The tracking device is available but not tracking
|
Present, ///< The tracking device is available but not tracking
|
||||||
Tracking //< The tracking device is actively tracking
|
Tracking ///< The tracking device is actively tracking
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -22,40 +22,13 @@ namespace Passer.Tracking {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TrackerComponent : MonoBehaviour {
|
public class TrackerComponent : MonoBehaviour {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The status of the tracking device
|
||||||
|
/// </summary>
|
||||||
public Tracker.Status status;
|
public Tracker.Status status;
|
||||||
|
|
||||||
protected Transform realWorld;
|
protected Transform realWorld;
|
||||||
|
|
||||||
//[SerializeField]
|
|
||||||
//protected bool _show = true;
|
|
||||||
//public virtual bool show {
|
|
||||||
// set {
|
|
||||||
// if (value == true && !_show) {
|
|
||||||
// renderTracker = true;
|
|
||||||
|
|
||||||
// _show = true;
|
|
||||||
// }
|
|
||||||
// else if (value == false && _show) {
|
|
||||||
// renderTracker = false;
|
|
||||||
|
|
||||||
// _show = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// get {
|
|
||||||
// return _show;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//protected bool renderTracker {
|
|
||||||
// set {
|
|
||||||
// UnityEngine.Debug.Log("tracker show " + value);
|
|
||||||
// Renderer[] renderers = this.GetComponentsInChildren<Renderer>();
|
|
||||||
// foreach (Renderer renderer in renderers)
|
|
||||||
// renderer.enabled = value;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
protected virtual void Start() { }
|
protected virtual void Start() { }
|
||||||
|
|
||||||
protected virtual void Update() { }
|
protected virtual void Update() { }
|
||||||
|
@ -11,6 +11,26 @@ namespace Passer.Humanoid {
|
|||||||
#if hCUSTOM
|
#if hCUSTOM
|
||||||
public override HumanoidTracker tracker => humanoid.unityXR;
|
public override HumanoidTracker tracker => humanoid.unityXR;
|
||||||
#endif
|
#endif
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
if (sensorComponent != null)
|
||||||
|
return sensorComponent;
|
||||||
|
|
||||||
|
Vector3 position = handTarget.transform.TransformPoint(handTarget.isLeft ? -0.1F : 0.1F, -0.05F, 0.04F);
|
||||||
|
Quaternion localRotation = handTarget.isLeft ? Quaternion.Euler(180, 90, 90) : Quaternion.Euler(180, -90, -90);
|
||||||
|
Quaternion rotation = handTarget.transform.rotation * localRotation;
|
||||||
|
#if hSTEAMVR
|
||||||
|
if (UnityXRDevice.xrDevice == UnityXRDevice.XRDeviceType.OpenVR) {
|
||||||
|
SteamVR steamVR = unityXR.trackerComponent as SteamVR;
|
||||||
|
controller = steamVR.GetController(handTarget.isLeft, position, rotation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
UnityXR unityXRcomponent = unityXR.trackerComponent as UnityXR;
|
||||||
|
controller = unityXRcomponent.GetController(handTarget.isLeft, position, rotation);
|
||||||
|
}
|
||||||
|
return controller as SensorComponent;
|
||||||
|
}
|
||||||
|
|
||||||
protected UnityXRTracker unityXR => humanoid.unityXR;
|
protected UnityXRTracker unityXR => humanoid.unityXR;
|
||||||
|
|
||||||
|
@ -10,12 +10,23 @@ namespace Passer.Humanoid {
|
|||||||
get { return "Unity XR"; }
|
get { return "Unity XR"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#if hCUSTOM
|
|
||||||
public override HumanoidTracker tracker => humanoid.unityXR;
|
public override HumanoidTracker tracker => humanoid.unityXR;
|
||||||
#endif
|
|
||||||
|
|
||||||
protected UnityXRTracker unityXR {
|
public UnityXR unityXR => tracker.trackerComponent as UnityXR;
|
||||||
get { return humanoid.unityXR; }
|
//protected UnityXRTracker unityXR => humanoid.unityXR;
|
||||||
|
|
||||||
|
public override SensorComponent GetSensorComponent() {
|
||||||
|
if (sensorComponent != null)
|
||||||
|
return sensorComponent;
|
||||||
|
|
||||||
|
if (tracker.trackerComponent == null)
|
||||||
|
tracker.CheckTracker(humanoid);
|
||||||
|
|
||||||
|
Vector3 position = headTarget.transform.TransformPoint(headTarget.head2eyes);
|
||||||
|
Quaternion rotation = headTarget.transform.rotation;
|
||||||
|
UnityXR unityXRtracker = tracker.trackerComponent as UnityXR;
|
||||||
|
sensorComponent = unityXRtracker.GetHmd(position, rotation);
|
||||||
|
return sensorComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Manage
|
#region Manage
|
||||||
@ -26,15 +37,15 @@ namespace Passer.Humanoid {
|
|||||||
if (this.headTarget == null)
|
if (this.headTarget == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (unityXR.trackerComponent == null) {
|
if (tracker.trackerComponent == null) {
|
||||||
unityXR.CheckTracker(humanoid);
|
tracker.CheckTracker(humanoid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabled && unityXR.trackerComponent != null && unityXR.trackerComponent.enabled) {
|
if (enabled && tracker.trackerComponent != null && tracker.trackerComponent.enabled) {
|
||||||
if (sensorComponent == null) {
|
if (sensorComponent == null) {
|
||||||
Vector3 position = headTarget.transform.TransformPoint(headTarget.head2eyes);
|
Vector3 position = headTarget.transform.TransformPoint(headTarget.head2eyes);
|
||||||
Quaternion rotation = headTarget.transform.rotation;
|
Quaternion rotation = headTarget.transform.rotation;
|
||||||
UnityXR unityXRtracker = unityXR.trackerComponent as UnityXR;
|
UnityXR unityXRtracker = tracker.trackerComponent as UnityXR;
|
||||||
sensorComponent = unityXRtracker.GetHmd(position, rotation);
|
sensorComponent = unityXRtracker.GetHmd(position, rotation);
|
||||||
}
|
}
|
||||||
if (sensorComponent != null)
|
if (sensorComponent != null)
|
||||||
@ -55,6 +66,20 @@ namespace Passer.Humanoid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UnityXRHmd GetSensor() {
|
||||||
|
Vector3 position = headTarget.transform.TransformPoint(headTarget.head2eyes);
|
||||||
|
Quaternion rotation = headTarget.transform.rotation;
|
||||||
|
UnityXR unityXRtracker = tracker.trackerComponent as UnityXR;
|
||||||
|
return GetSensor(position, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UnityXRHmd GetSensor(Vector3 position, Quaternion rotation) {
|
||||||
|
if (sensorComponent == null) {
|
||||||
|
sensorComponent = unityXR.GetHmd(position, rotation);
|
||||||
|
}
|
||||||
|
return sensorComponent as UnityXRHmd;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Start
|
#region Start
|
||||||
@ -77,7 +102,7 @@ namespace Passer.Humanoid {
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
UnityXR unityXRtracker = unityXR.trackerComponent as UnityXR;
|
UnityXR unityXRtracker = tracker.trackerComponent as UnityXR;
|
||||||
sensorComponent = unityXRtracker.GetHmd(position, rotation);
|
sensorComponent = unityXRtracker.GetHmd(position, rotation);
|
||||||
}
|
}
|
||||||
if (sensorComponent != null)
|
if (sensorComponent != null)
|
||||||
@ -88,7 +113,7 @@ namespace Passer.Humanoid {
|
|||||||
sensor2TargetPosition = -headTarget.head2eyes;
|
sensor2TargetPosition = -headTarget.head2eyes;
|
||||||
|
|
||||||
if (sensorComponent != null)
|
if (sensorComponent != null)
|
||||||
sensorComponent.StartComponent(unityXR.trackerComponent.transform);
|
sensorComponent.StartComponent(tracker.trackerComponent.transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -98,7 +123,7 @@ namespace Passer.Humanoid {
|
|||||||
protected bool calibrated = false;
|
protected bool calibrated = false;
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
status = Tracker.Status.Unavailable;
|
status = Tracker.Status.Unavailable;
|
||||||
if (unityXR.trackerComponent == null || !unityXR.trackerComponent.enabled || !enabled)
|
if (tracker.trackerComponent == null || !tracker.trackerComponent.enabled || !enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sensorComponent == null)
|
if (sensorComponent == null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user