From 021fa81e19a07eba5c35dcd538d6bad8640d09c0 Mon Sep 17 00:00:00 2001 From: Katy Fox Date: Wed, 10 Jan 2024 16:43:20 -0500 Subject: [PATCH] #161 control spec gizmos --- CCL.Types/Proxies/Controls/ButtonProxy.cs | 8 ++ CCL.Types/Proxies/Controls/LeverProxy.cs | 75 +++++++++++++++++++ CCL.Types/Proxies/Controls/PullerProxy.cs | 8 ++ CCL.Types/Proxies/Controls/RotaryProxy.cs | 44 +++++++++++ .../Proxies/Controls/ToggleSwitchProxy.cs | 44 +++++++++++ .../Proxies/Indicators/IndicatorGaugeProxy.cs | 40 ++++++++++ .../Indicators/IndicatorScalerProxy.cs | 21 ++++++ .../Indicators/IndicatorSliderProxy.cs | 19 +++++ 8 files changed, 259 insertions(+) diff --git a/CCL.Types/Proxies/Controls/ButtonProxy.cs b/CCL.Types/Proxies/Controls/ButtonProxy.cs index bbc39a17..50dfa484 100644 --- a/CCL.Types/Proxies/Controls/ButtonProxy.cs +++ b/CCL.Types/Proxies/Controls/ButtonProxy.cs @@ -37,5 +37,13 @@ private void OnValidate() [Header("VR")] public bool disableTouchUse; public VRButtonAlias overrideUseButton; + + private void OnDrawGizmos() + { + Vector3 pressedOffset = transform.TransformPoint(Vector3.back * linearLimit); + + Gizmos.color = Color.green; + Gizmos.DrawLine(transform.position, pressedOffset); + } } } diff --git a/CCL.Types/Proxies/Controls/LeverProxy.cs b/CCL.Types/Proxies/Controls/LeverProxy.cs index c7d08008..e0016c9e 100644 --- a/CCL.Types/Proxies/Controls/LeverProxy.cs +++ b/CCL.Types/Proxies/Controls/LeverProxy.cs @@ -63,5 +63,80 @@ private void OnValidate() public AudioClip drag; public AudioClip limitHit; public bool limitVibration; + + protected const float GIZMO_RADIUS = 0.1f; + protected const int GIZMO_SEGMENTS = 40; + protected static readonly Color START_COLOR = new Color(0.65f, 0, 0); + protected static readonly Color END_COLOR = new Color(0, 0.65f, 0); + + private void OnDrawGizmos() + { + Color startColor = invertDirection ? END_COLOR : START_COLOR; + Color endColor = invertDirection ? START_COLOR : END_COLOR; + + Vector3 massCenter = ModelUtil.GetModelCenterline(gameObject); + Vector3 massZeroVector = transform.InverseTransformPoint(massCenter); + Vector3 gizmoZeroVector = Vector3.ProjectOnPlane(massZeroVector, jointAxis); + + float massLength = massZeroVector.magnitude; + Vector3 massPivot = Vector3.Project(massZeroVector, jointAxis); + + Gizmos.color = Color.blue; + Gizmos.DrawLine(transform.position, transform.TransformPoint(massPivot)); + + if (useSteppedJoint && (notches > 0)) + { + float rayCount = notches - 1; + + // draw ray segments + for (int i = 0; i <= rayCount; i++) + { + Gizmos.color = Color.Lerp(startColor, endColor, i / rayCount); + + float rotateAngle = Mathf.Lerp(jointLimitMin, jointLimitMax, i / rayCount); + Quaternion rotation = Quaternion.AngleAxis(rotateAngle, jointAxis); + + // projected sweep + Vector3 rayVector = transform.TransformPoint((rotation * gizmoZeroVector) * GIZMO_RADIUS); + Gizmos.DrawLine(transform.position, rayVector); + + // center of mass sweep + rayVector = transform.TransformPoint(rotation * massZeroVector); + Gizmos.DrawLine(transform.TransformPoint(massPivot), rayVector); + } + } + else + { + // draw semi-circle + Vector3 lastVector = transform.position; + Vector3 lastMassVector = transform.TransformPoint(massPivot); + + for (int i = 0; i <= GIZMO_SEGMENTS; i++) + { + Gizmos.color = Color.Lerp(startColor, endColor, (float)i / GIZMO_SEGMENTS); + + float rotateAngle = Mathf.Lerp(jointLimitMin, jointLimitMax, (float)i / GIZMO_SEGMENTS); + Quaternion rotation = Quaternion.AngleAxis(rotateAngle, jointAxis); + + // projected sweep + Vector3 nextVector = transform.TransformPoint((rotation * gizmoZeroVector) * GIZMO_RADIUS); + Vector3 nextMassVector = transform.TransformPoint(rotation * massZeroVector); + + if (i == 0 || i == GIZMO_SEGMENTS) + { + Gizmos.DrawLine(transform.position, nextVector); + Gizmos.DrawLine(transform.TransformPoint(massPivot), nextMassVector); + } + if (i != 0) + { + Gizmos.DrawLine(lastVector, nextVector); + Gizmos.DrawLine(lastMassVector, nextMassVector); + } + + lastVector = nextVector; + lastMassVector = nextMassVector; + } + } + } } } diff --git a/CCL.Types/Proxies/Controls/PullerProxy.cs b/CCL.Types/Proxies/Controls/PullerProxy.cs index 20504beb..f54ed2c8 100644 --- a/CCL.Types/Proxies/Controls/PullerProxy.cs +++ b/CCL.Types/Proxies/Controls/PullerProxy.cs @@ -43,5 +43,13 @@ private void OnValidate() public AudioClip notch; public AudioClip drag; public AudioClip limitHit; + + private void OnDrawGizmos() + { + Vector3 movedOffset = transform.TransformPoint(Vector3.up * linearLimit); + + Gizmos.color = Color.green; + Gizmos.DrawLine(transform.position, movedOffset); + } } } diff --git a/CCL.Types/Proxies/Controls/RotaryProxy.cs b/CCL.Types/Proxies/Controls/RotaryProxy.cs index fcbffbcd..1d74d160 100644 --- a/CCL.Types/Proxies/Controls/RotaryProxy.cs +++ b/CCL.Types/Proxies/Controls/RotaryProxy.cs @@ -55,5 +55,49 @@ private void OnValidate() public AudioClip notch; public AudioClip drag; public AudioClip limitHit; + + + protected const int GIZMO_SLICE_SIZE = 10; + protected const float GIZMO_RADIUS = 0.02f; + protected static readonly Color START_COLOR = new Color(0.65f, 0, 0); + protected static readonly Color END_COLOR = new Color(0, 0.65f, 0); + + private void OnDrawGizmos() + { + Vector3 lastVector = transform.position; + Vector3 lastOpp = transform.position; + + foreach (float end in new[] { jointLimitMin, jointLimitMax }) + { + if (jointStartingPos != end) + { + float totalSweep = Mathf.Abs(end - jointStartingPos); + int gizmoSegments = Mathf.FloorToInt(totalSweep / GIZMO_SLICE_SIZE); + + for (int i = 0; i <= gizmoSegments; i++) + { + Gizmos.color = Color.Lerp(START_COLOR, END_COLOR, (float)i / gizmoSegments); + Vector3 radialVector = (Quaternion.AngleAxis( + Mathf.Lerp(jointStartingPos, end, (float)i / gizmoSegments), jointAxis) + * Vector3.forward).normalized; + + Vector3 nextVector = transform.TransformPoint(radialVector * GIZMO_RADIUS); + Vector3 oppositeVector = transform.TransformPoint(radialVector * -GIZMO_RADIUS); + + if (i != 0) + { + Gizmos.DrawLine(lastVector, nextVector); + Gizmos.DrawLine(lastOpp, oppositeVector); + } + + Gizmos.DrawLine(transform.position, nextVector); + Gizmos.DrawLine(transform.position, oppositeVector); + + lastVector = nextVector; + lastOpp = oppositeVector; + } + } + } + } } } diff --git a/CCL.Types/Proxies/Controls/ToggleSwitchProxy.cs b/CCL.Types/Proxies/Controls/ToggleSwitchProxy.cs index b1e1be23..be46425f 100644 --- a/CCL.Types/Proxies/Controls/ToggleSwitchProxy.cs +++ b/CCL.Types/Proxies/Controls/ToggleSwitchProxy.cs @@ -34,5 +34,49 @@ private void OnValidate() [Header("VR")] public Vector3 touchInteractionAxis = Vector3.up; public bool disableTouchUse; + + + protected const float GIZMO_RADIUS = 0.05f; + protected const int GIZMO_SEGMENTS = 10; + protected static readonly Color START_COLOR = new Color(0.65f, 0, 0); + protected static readonly Color END_COLOR = new Color(0, 0.65f, 0); + + private void OnDrawGizmos() + { + Vector3 massCenter = ModelUtil.GetModelCenterline(gameObject); + Vector3 massZeroVector = transform.InverseTransformPoint(massCenter); + Vector3 gizmoZeroVector = Vector3.ProjectOnPlane(massZeroVector, jointAxis); + Vector3 massPivot = Vector3.Project(massZeroVector, jointAxis); + + Vector3 lastVector = transform.position; + Vector3 lastMassVector = transform.TransformPoint(massPivot); + + // draw ray segments + for (int i = 0; i <= GIZMO_SEGMENTS; i++) + { + Gizmos.color = Color.Lerp(START_COLOR, END_COLOR, (float)i / GIZMO_SEGMENTS); + + float rotateAngle = Mathf.Lerp(jointLimitMin, jointLimitMax, (float)i / GIZMO_SEGMENTS); + Quaternion rotation = Quaternion.AngleAxis(rotateAngle, jointAxis); + + // projected sweep + Vector3 nextVector = transform.TransformPoint((rotation * gizmoZeroVector) * GIZMO_RADIUS); + Vector3 nextMassVector = transform.TransformPoint(rotation * massZeroVector); + + if (i == 0 || i == GIZMO_SEGMENTS) + { + Gizmos.DrawLine(transform.position, nextVector); + Gizmos.DrawLine(transform.TransformPoint(massPivot), nextMassVector); + } + if (i != 0) + { + Gizmos.DrawLine(lastVector, nextVector); + Gizmos.DrawLine(lastMassVector, nextMassVector); + } + + lastVector = nextVector; + lastMassVector = nextMassVector; + } + } } } diff --git a/CCL.Types/Proxies/Indicators/IndicatorGaugeProxy.cs b/CCL.Types/Proxies/Indicators/IndicatorGaugeProxy.cs index 141fb7fc..4dec4f06 100644 --- a/CCL.Types/Proxies/Indicators/IndicatorGaugeProxy.cs +++ b/CCL.Types/Proxies/Indicators/IndicatorGaugeProxy.cs @@ -15,5 +15,45 @@ public class IndicatorGaugeProxy : IndicatorProxy public bool unclamped; public Vector3 rotationAxis = Vector3.forward; public float gizmoRadius = 0.1f; + + + protected const float GIZMO_RADIUS = 0.1f; + protected const int GIZMO_SEGMENTS = 20; + protected static readonly Color END_COLOR = new Color(0, 0, 0.65f); + protected static readonly Color START_COLOR = new Color(0.65f, 0, 0); + + private void OnDrawGizmos() + { + if (!needle) + { + return; + } + + Vector3 massCenter = ModelUtil.GetModelCenterline(gameObject); + Vector3 massZeroVector = transform.InverseTransformPoint(massCenter); + Vector3 massPivot = Vector3.Project(massZeroVector, rotationAxis); + + Vector3 lastVector = Vector3.zero; + for (int i = 0; i <= GIZMO_SEGMENTS; i++) + { + Color segmentColor = Color.Lerp(START_COLOR, END_COLOR, (float)i / GIZMO_SEGMENTS); + + Quaternion rotation = Quaternion.AngleAxis(Mathf.Lerp(minAngle, maxAngle, (float)i / GIZMO_SEGMENTS), rotationAxis); + Vector3 nextVector = transform.TransformPoint(rotation * massZeroVector); + + Gizmos.color = segmentColor; + if (i == 0 || i == GIZMO_SEGMENTS) + { + Gizmos.DrawLine(transform.TransformPoint(massPivot), nextVector); + } + + if (i != 0) + { + Gizmos.DrawLine(lastVector, nextVector); + } + + lastVector = nextVector; + } + } } } diff --git a/CCL.Types/Proxies/Indicators/IndicatorScalerProxy.cs b/CCL.Types/Proxies/Indicators/IndicatorScalerProxy.cs index 14fe4930..714945ea 100644 --- a/CCL.Types/Proxies/Indicators/IndicatorScalerProxy.cs +++ b/CCL.Types/Proxies/Indicators/IndicatorScalerProxy.cs @@ -12,5 +12,26 @@ public class IndicatorScalerProxy : IndicatorProxy public Transform indicatorToScale; public Vector3 startScale = Vector3.one; public Vector3 endScale = Vector3.one; + + public void OnDrawGizmos() + { + if (!indicatorToScale) return; + + Vector3 worldCenter = ModelUtil.GetModelCenterline(gameObject); + Vector3 localCenter = transform.InverseTransformPoint(worldCenter); + Vector3 worldStart = transform.TransformPoint(Vector3.Scale(localCenter, startScale)); + Vector3 worldEnd = transform.TransformPoint(Vector3.Scale(localCenter, endScale)); + + float tickScale = Vector3.Distance(worldStart, worldEnd) * 0.1f; + Vector3 axis = (worldEnd - worldStart).normalized; + Vector3 perpendicular = (axis.z < axis.x) ? new Vector3(axis.y, -axis.x, 0) : new Vector3(0, -axis.z, axis.y); + + Gizmos.color = Color.blue; + Gizmos.DrawLine(worldStart, worldEnd); + Gizmos.color = Color.red; + Gizmos.DrawLine(worldStart + perpendicular * tickScale, worldStart + perpendicular * -tickScale); + Gizmos.color = Color.green; + Gizmos.DrawLine(worldEnd + perpendicular * tickScale, worldEnd + perpendicular * -tickScale); + } } } diff --git a/CCL.Types/Proxies/Indicators/IndicatorSliderProxy.cs b/CCL.Types/Proxies/Indicators/IndicatorSliderProxy.cs index 8ff509ad..a8b4a7d0 100644 --- a/CCL.Types/Proxies/Indicators/IndicatorSliderProxy.cs +++ b/CCL.Types/Proxies/Indicators/IndicatorSliderProxy.cs @@ -12,5 +12,24 @@ public class IndicatorSliderProxy : IndicatorProxy public Transform pointer; public Vector3 startPosition = -Vector3.right; public Vector3 endPosition = Vector3.right; + + public void OnDrawGizmos() + { + if (!pointer) return; + + Vector3 worldStart = pointer.parent.TransformPoint(startPosition); + Vector3 worldEnd = pointer.parent.TransformPoint(endPosition); + + float tickScale = Vector3.Distance(startPosition, endPosition) * 0.1f; + Vector3 axis = (worldEnd - worldStart).normalized; + Vector3 perpendicular = (axis.z < axis.x) ? new Vector3(axis.y, -axis.x, 0) : new Vector3(0, -axis.z, axis.y); + + Gizmos.color = Color.blue; + Gizmos.DrawLine(worldStart, worldEnd); + Gizmos.color = Color.red; + Gizmos.DrawLine(worldStart + perpendicular * tickScale, worldStart + perpendicular * -tickScale); + Gizmos.color = Color.green; + Gizmos.DrawLine(worldEnd + perpendicular * tickScale, worldEnd + perpendicular * -tickScale); + } } }