From 7afb190db19bf5998cc4763e2da0ea3c16d84dac Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Thu, 2 May 2024 22:16:47 +0200
Subject: [PATCH 01/12] Add tools for tracking Guardian
---
.../Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs | 14 ++++++++++++++
.../Scripts/Utils/Guardian.cs.meta | 11 +++++++++++
2 files changed, 25 insertions(+)
create mode 100644 Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs
create mode 100644 Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs.meta
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs
new file mode 100644
index 00000000..6964ef58
--- /dev/null
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs
@@ -0,0 +1,14 @@
+using UnityEngine;
+
+///
+/// Stub class for getting Guardian boundaries, if configured.
+///
+public class Guardian : MonoBehaviour {
+ private void Update() {
+ bool configured = OVRManager.boundary.GetConfigured();
+ if (configured) {
+ Vector3[] geometry = OVRManager.boundary.GetGeometry(OVRBoundary.BoundaryType.PlayArea);
+ Debug.Log($"Boundary has {geometry.Length} points.");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs.meta b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs.meta
new file mode 100644
index 00000000..140da6e0
--- /dev/null
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 01ef33b40b21e4141b7f19c12e5a136a
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
From cd4a1c2332f5c912e7b5905392dc6be8bf73c49e Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Thu, 2 May 2024 23:04:14 +0200
Subject: [PATCH 02/12] Lint logging classes
---
.../Logging/{Unsubscriber.cs => HashSetUnsubscriber.cs} | 0
.../{Unsubscriber.cs.meta => HashSetUnsubscriber.cs.meta} | 0
.../Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs | 8 ++++----
.../Visuo-Haptic Toolkit/Scripts/Logging/Logging.cs | 7 +++----
.../Redirection/Body Redirection/BodyRedirection.cs | 2 +-
5 files changed, 8 insertions(+), 9 deletions(-)
rename Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/{Unsubscriber.cs => HashSetUnsubscriber.cs} (100%)
rename Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/{Unsubscriber.cs.meta => HashSetUnsubscriber.cs.meta} (100%)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Unsubscriber.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/HashSetUnsubscriber.cs
similarity index 100%
rename from Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Unsubscriber.cs
rename to Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/HashSetUnsubscriber.cs
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Unsubscriber.cs.meta b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/HashSetUnsubscriber.cs.meta
similarity index 100%
rename from Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Unsubscriber.cs.meta
rename to Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/HashSetUnsubscriber.cs.meta
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs
index d9531126..9c2e3da7 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs
@@ -45,7 +45,7 @@ public record JsonRedirectionData {
/// target selection strategy, if any, or the empty string.
///
public string Strategy => script switch {
- WorldRedirection => (script as WorldRedirection).strategy.ToString(),
+ WorldRedirection wr => wr.strategy.ToString(),
BodyRedirection => String.Empty,
_ => String.Empty
};
@@ -55,9 +55,9 @@ public record JsonRedirectionData {
/// technique, if any, or the empty string.
///
public string Technique => script switch {
- WorldRedirection => (script as WorldRedirection).Technique.ToString(),
- BodyRedirection => (script as BodyRedirection).Technique.ToString(),
- _ => ""
+ WorldRedirection wr => wr.Technique.ToString(),
+ BodyRedirection br => br.Technique.ToString(),
+ _ => String.Empty
};
public bool Redirecting => script.redirect;
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Logging.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Logging.cs
index 40bff02d..ac46d099 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Logging.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/Logging.cs
@@ -19,9 +19,9 @@ namespace VHToolkit.Logging {
public record RedirectionData {
public DateTime timeStamp = DateTime.Now;
public string Technique => script switch {
- WorldRedirection => (script as WorldRedirection).Technique.ToString(),
- BodyRedirection => (script as BodyRedirection).Technique.ToString(),
- _ => ""
+ WorldRedirection wr => wr.Technique.ToString(),
+ BodyRedirection br => br.Technique.ToString(),
+ _ => String.Empty
};
public Interaction script;
@@ -119,7 +119,6 @@ private sealed class FileObserver : AbstractFileObserver {
}
public override void OnNext(RedirectionData value) {
- csvWriter.Context.RegisterClassMap();
csvWriter.WriteRecord(value);
csvWriter.NextRecord();
}
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Body Redirection/BodyRedirection.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Body Redirection/BodyRedirection.cs
index 57dab38d..88b9c15c 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Body Redirection/BodyRedirection.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Body Redirection/BodyRedirection.cs
@@ -35,7 +35,7 @@ public class BodyRedirection : Interaction {
/// Updates the techniqueInstance according to the enumeration technique chosen.
///
private void UpdateTechnique() {
- techniqueInstance = _technique switch {
+ techniqueInstance = Technique switch {
BRTechnique.None => new NoBodyRedirection(),
BRTechnique.Reset => new ResetBodyRedirection(),
BRTechnique.Azmandian2016Body => new Azmandian2016Body(),
From 7d0a5021703dcedd47b2ba2e5af16cea98e28ce3 Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Fri, 3 May 2024 20:54:55 +0200
Subject: [PATCH 03/12] Misc lint
---
.../Redirection/RedirectionTechnique.cs | 4 +-
.../Redirection/BodyRedirectionEditor.cs | 40 ++++++++------
.../Visualisation/APFGradientVisuals.cs | 52 +++++++------------
.../ProjectSettings/EditorBuildSettings.asset | 2 +-
4 files changed, 46 insertions(+), 52 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/RedirectionTechnique.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/RedirectionTechnique.cs
index ecf06d0b..47c0fcb6 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/RedirectionTechnique.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/RedirectionTechnique.cs
@@ -1,8 +1,8 @@
namespace VHToolkit.Redirection {
abstract public class RedirectionTechnique {
///
- /// This abstract method redirects the Scene transforms according to the other parameters and the equations
- /// defined in the corresponding techniques. It needs to be overriden by a child class, and it is called on Update() in *Redirection classes.
+ /// Redirect redirects the Scene transforms according to the other parameters and the equations
+ /// defined in the corresponding techniques. It needs to be overriden in children classes, and is called on Update() in *Redirection classes.
///
public abstract void Redirect(Scene scene);
}
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
index 17bf01a8..9c370c2f 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
@@ -30,23 +30,24 @@ public class BodyRedirectionEditor : Editor {
readonly HashSet bufferTechniques = new() { nameof(Han2018InterpolatedReach), nameof(Azmandian2016Body), nameof(Geslain2022Polynom), nameof(Cheng2017Sparse) };
readonly HashSet noThresholdTechniques = new() { nameof(Poupyrev1996GoGo), nameof(Lecuyer2000Swamp), nameof(Samad2019Weight) };
+ private SerializedProperty Find(string name) => serializedObject.FindProperty(name);
private void OnEnable() {
- technique = serializedObject.FindProperty("_technique");
- techniqueInstance = serializedObject.FindProperty("techniqueInstance");
+ technique = Find("_technique");
+ techniqueInstance = Find("techniqueInstance");
- limbs = serializedObject.FindProperty("scene.limbs");
- physicalHead = serializedObject.FindProperty("scene.physicalHead");
- virtualHead = serializedObject.FindProperty("scene.virtualHead");
- physicalTarget = serializedObject.FindProperty("scene.physicalTarget");
- virtualTarget = serializedObject.FindProperty("scene.virtualTarget");
- origin = serializedObject.FindProperty("scene.origin");
- referenceSurface = serializedObject.FindProperty("scene.referenceParent");
- interpolatedSurface = serializedObject.FindProperty("scene.interpolatedParent");
+ limbs = Find("scene.limbs");
+ physicalHead = Find("scene.physicalHead");
+ virtualHead = Find("scene.virtualHead");
+ physicalTarget = Find("scene.physicalTarget");
+ virtualTarget = Find("scene.virtualTarget");
+ origin = Find("scene.origin");
+ referenceSurface = Find("scene.referenceParent");
+ interpolatedSurface = Find("scene.interpolatedParent");
- redirect = serializedObject.FindProperty("redirect");
- parameters = serializedObject.FindProperty("scene.parameters");
+ redirect = Find("redirect");
+ parameters = Find("scene.parameters");
}
private void MakePropertyField(SerializedProperty property, string text, string tooltip = null) {
@@ -71,7 +72,8 @@ public override void OnInspectorGUI() {
if (techniqueName == nameof(Azmandian2016Hybrid)) {
MakePropertyField(physicalHead, "Physical Head", "The Transform of the VR headset worn by the user.");
MakePropertyField(virtualHead, "Virtual Head", "");
- } else if (techniqueName == nameof(Poupyrev1996GoGo)) {
+ }
+ else if (techniqueName == nameof(Poupyrev1996GoGo)) {
MakePropertyField(physicalHead, "Physical Head", "");
}
@@ -95,7 +97,8 @@ public override void OnInspectorGUI() {
if (techniqueName == nameof(Kohli2010RedirectedTouching)) {
MakePropertyField(referenceSurface, "Reference Surface", "Points on the physical surface that the physical hand of the user explores. This Transform should be the parent of the points. The order of points is matched with the order of interpolated surface.");
MakePropertyField(interpolatedSurface, "Interpolated Surface", "Points on the virtual surface that the virtual hand of the user will explore when touching the physical surface.This Transform should be the parent of the points. The order of points is matched with the order of reference surface.");
- } else {
+ }
+ else {
MakePropertyField(physicalTarget, "Physical Target", "");
MakePropertyField(virtualTarget, "Virtual Target", "");
MakePropertyField(origin, "Origin", "");
@@ -105,10 +108,12 @@ public override void OnInspectorGUI() {
if (techniqueName == nameof(Kohli2010RedirectedTouching)) {
MakePropertyField(parametersObject.FindProperty("SmoothingParameter"), "Smoothing", "");
MakePropertyField(parametersObject.FindProperty("Rescale"), "Rescale", "");
- } else if (techniqueName == nameof(Geslain2022Polynom)) {
+ }
+ else if (techniqueName == nameof(Geslain2022Polynom)) {
MakePropertyField(parametersObject.FindProperty("redirectionLateness"), "Redirection Lateness (a2)");
MakePropertyField(parametersObject.FindProperty("controlPoint"), "ControlPoint");
- } else if (techniqueName == nameof(Poupyrev1996GoGo)) {
+ }
+ else if (techniqueName == nameof(Poupyrev1996GoGo)) {
MakePropertyField(parametersObject.FindProperty("GoGoCoefficient"), "Coefficient");
MakePropertyField(parametersObject.FindProperty("GoGoActivationDistance"), "Activation Distance");
}
@@ -122,7 +127,8 @@ public override void OnInspectorGUI() {
MakePropertyField(parametersObject.FindProperty("SwampSquareLength"), "Square Side Length");
MakePropertyField(parametersObject.FindProperty("SwampCDRatio"), "C/D Ratio");
}
- } else {
+ }
+ else {
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Threshold Parameters", EditorStyles.largeLabel);
MakePropertyField(parametersObject.FindProperty(nameof(ParametersToolkit.HorizontalAngles)), "Max Horizontal Angles");
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs
index 7d2d8aa5..93765828 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs
@@ -10,14 +10,14 @@
public class GradientVisuals : MonoBehaviour {
// PROPERTIES //
- [Range(0.5f, 5f)] public float refreshRate;
+ [Range(0.5f, 5f)] public float refreshRateInSeconds;
// public heatmap
[Header("Heatmap")]
[InspectorName("Enable Heatmap")] public bool heatmapEnabled;
public GameObject heatmapQuadPrefab;
[Range(1, 64)][Tooltip("The higher the finer")] public int heatmapMeshFineness;
- [Range(1, 10)] public float heatmapClampValue = 1;
+ [Range(1, 10)] public float heatmapClampValue = 1f;
// public vectors
[Header("Vector Field")]
@@ -34,13 +34,13 @@ public class GradientVisuals : MonoBehaviour {
// private heatmap
private bool hmEnabledCurrentState;
- private float[] hmDensityTable;
+ private readonly float[] hmDensityTable = new float[4096];
private Renderer hmRenderer;
private GameObject hmQuad;
// private vector
private bool vfEnabledCurrentState;
- private List vfVectors;
+ private readonly List vfVectors = new();
[SerializeField] private WorldRedirection script;
@@ -50,8 +50,6 @@ public class GradientVisuals : MonoBehaviour {
#region "Main"
void Start() {
- hmDensityTable = new float[4096];
- vfVectors = new();
UpdateRepulsiveFunc();
InvokeRepeating(nameof(Checks), 3f, 3f);
}
@@ -146,9 +144,6 @@ private bool InitHeatmap() {
CloseHeatmap();
}
- var hmStepX = width / heatmapMeshFineness;
- var hmStepZ = depth / heatmapMeshFineness;
-
hmQuad = Instantiate(heatmapQuadPrefab, this.transform);
hmQuad.transform.position = 0.5f * (min + max);
hmQuad.transform.localScale = new Vector2(width, depth);
@@ -157,7 +152,7 @@ private bool InitHeatmap() {
hmRenderer = hmQuad.GetComponent();
UpdateHeatmap();
- InvokeRepeating(nameof(UpdateHeatmap), 1f, refreshRate);
+ InvokeRepeating(nameof(UpdateHeatmap), 1f, refreshRateInSeconds);
return true;
}
@@ -167,13 +162,11 @@ private bool InitHeatmap() {
///
private void UpdateHeatmap() {
if (!heatmapEnabled) { return; }
-
- var hmStepX = width / heatmapMeshFineness;
- var hmStepZ = depth / heatmapMeshFineness;
+ var hmSteps = (max - min) / heatmapMeshFineness;
for (int z = 0; z < heatmapMeshFineness; z++) {
for (int x = 0; x < heatmapMeshFineness; x++) {
- Vector3 position = new(min.x + (x + 1 / 2) * hmStepX, 0, min.z + (z + 1 / 2) * hmStepZ);
+ Vector3 position = min + Vector3.Scale(new(x + 1 / 2, 0f, z + 1 / 2), hmSteps);
hmDensityTable[x + (z * heatmapMeshFineness)] = ((Vector2)MathTools.Gradient3(repulsiveFunction, position)).magnitude;
}
}
@@ -207,37 +200,32 @@ private bool InitVectorField() {
CloseVectorField();
return false;
}
-
if (vfEnabledCurrentState) {
CloseVectorField();
}
-
- int i = 0;
+ var vmSteps = (max - min) / vectorMeshFineness;
+ int index = 0;
for (int z = 0; z < vectorMeshFineness; z++) {
for (int x = 0; x < vectorMeshFineness; x++) {
- GameObject vectorObj = new($"vector_{i++}", typeof(SpriteRenderer));
-
- Vector3 position = new(min.x + (x + 1 / 2) * (width / vectorMeshFineness), 0, min.z + ((z + 1 / 2) * (depth / vectorMeshFineness)));
+ GameObject vectorObj = new($"vector_{index++}", typeof(SpriteRenderer));
+ Vector3 position = min + Vector3.Scale(new(x + 1 / 2, 0f, z + 1 / 2), vmSteps);
Vector2 gradient = MathTools.Gradient3(repulsiveFunction, position);
+ vectorObj.transform.SetParent(transform);
- vectorObj.transform.parent = this.transform;
- vectorObj.transform.position = new(position.x, transform.position.y + 0.001f, position.z);
-
- if (!float.IsNaN(gradient.x) && !float.IsNaN(gradient.y)) {
- float angleInDegrees = Mathf.Atan2(gradient.y, gradient.x) * Mathf.Rad2Deg;
- vectorObj.transform.rotation = Quaternion.Euler(-90, 0, angleInDegrees);
- vectorObj.GetComponent().sprite = vfArrow;
- }
- else {
- vectorObj.GetComponent().sprite = vfWarning;
- }
+ var (angleInDegrees, sprite) = (float.IsNaN(gradient.x) || float.IsNaN(gradient.y)) ?
+ (0f, vfWarning) : (Mathf.Atan2(gradient.y, gradient.x) * Mathf.Rad2Deg, vfArrow);
+ vectorObj.transform.SetPositionAndRotation(
+ new(position.x, transform.position.y + 0.001f, position.z),
+ Quaternion.Euler(-90, 0, angleInDegrees)
+ );
+ vectorObj.GetComponent().sprite = sprite;
vfVectors.Add(vectorObj);
}
}
UpdateVectorField();
- InvokeRepeating(nameof(UpdateVectorField), 1f, refreshRate);
+ InvokeRepeating(nameof(UpdateVectorField), 1f, refreshRateInSeconds);
return true;
}
diff --git a/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset b/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset
index 19f76d63..8cb73128 100644
--- a/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset
+++ b/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset
@@ -23,7 +23,7 @@ EditorBuildSettings:
path: Assets/Demo Scenes/Azmandian 3 Cubes/Static Floating Cubes.unity
guid: 885a34dea4cdceb4fb2045466d51655a
m_configObjects:
- Unity.XR.Oculus.Settings: {fileID: 11400000, guid: dddd8483c93d8dc4e9f76ebac819c68d, type: 2}
+ Unity.XR.Oculus.Settings: {fileID: 11400000, guid: 755c5043d51c4b8469858eb1afffe2e8, type: 2}
Unity.XR.OpenVR.Settings: {fileID: 11400000, guid: b6bf661543b159f4f93e0c7221185c37, type: 2}
com.unity.xr.management.loader_settings: {fileID: 11400000, guid: 59bb4fa2062df8549bae6e1c8690288b, type: 2}
com.unity.xr.openxr.settings4: {fileID: 11400000, guid: f15c911359537b241b84e33fd34fbf49, type: 2}
From 1ccb449ef195393c84db5f8f13895047036ccef8 Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Fri, 3 May 2024 22:20:39 +0200
Subject: [PATCH 04/12] Start rewriting BodyRedirectionEditor.cs
---
.../Scripts/Redirection/Interaction.cs | 22 +++++----
.../Redirection/BodyRedirectionEditor.cs | 46 +++++++++----------
2 files changed, 37 insertions(+), 31 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
index f6eec476..02b48d73 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
@@ -3,20 +3,26 @@
using UnityEngine;
namespace VHToolkit.Redirection {
+
+ [System.AttributeUsage(System.AttributeTargets.All, Inherited = false, AllowMultiple = true)]
+ public abstract class BRTAttribute : System.Attribute { }
+ public sealed class ShowHeadAttribute : BRTAttribute { }
+ public sealed class HasBufferAttribute : BRTAttribute { }
+ public sealed class HasThresholdAttribute : BRTAttribute { }
public enum BRTechnique {
None,
Reset,
[InspectorName("")] SEPARATOR1, // Adds a visual separator in the drop-down inspector
// Hand Redirection techniques
- Han2018TranslationalShift,
- Han2018InterpolatedReach,
- Azmandian2016Body,
- Azmandian2016Hybrid,
- Cheng2017Sparse,
- Geslain2022Polynom,
- Poupyrev1996GoGo,
+ [HasThreshold] Han2018TranslationalShift,
+ [HasBuffer, HasThreshold] Han2018InterpolatedReach,
+ [HasBuffer, HasThreshold] Azmandian2016Body,
+ [ShowHead, HasThreshold] Azmandian2016Hybrid,
+ [HasBuffer, HasThreshold] Cheng2017Sparse,
+ [HasBuffer, HasThreshold] Geslain2022Polynom,
+ [ShowHead] Poupyrev1996GoGo,
[InspectorName(" ")] SEPARATOR2,
- Kohli2010RedirectedTouching,
+ [HasThreshold] Kohli2010RedirectedTouching,
[InspectorName(" ")] SEPARATOR3,
// Pseudo-haptic techiques
Lecuyer2000Swamp,
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
index 9c370c2f..efa77079 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
@@ -5,6 +5,9 @@
using VHToolkit.Redirection.PseudoHaptics;
using VHToolkit.Redirection.Interpolation3D;
+using System;
+using VHToolkit.Redirection;
+using System.Linq;
namespace VHToolkit.Redirection.BodyRedirection {
///
@@ -26,10 +29,7 @@ public class BodyRedirectionEditor : Editor {
SerializedProperty redirect;
SerializedProperty parameters;
SerializedObject parametersObject;
-
- readonly HashSet bufferTechniques = new() { nameof(Han2018InterpolatedReach), nameof(Azmandian2016Body), nameof(Geslain2022Polynom), nameof(Cheng2017Sparse) };
- readonly HashSet noThresholdTechniques = new() { nameof(Poupyrev1996GoGo), nameof(Lecuyer2000Swamp), nameof(Samad2019Weight) };
-
+ readonly HashSet actualNoThresholdTechniques = new() { BRTechnique.Poupyrev1996GoGo, BRTechnique.Lecuyer2000Swamp, BRTechnique.Samad2019Weight };
private SerializedProperty Find(string name) => serializedObject.FindProperty(name);
private void OnEnable() {
@@ -67,14 +67,16 @@ public override void OnInspectorGUI() {
// Scene
MakePropertyField(limbs, "User Limbs", "A list of tracked user limbs.");
- string techniqueName = technique.enumNames[technique.enumValueIndex];
+ Enum.TryParse(technique.enumNames[technique.enumValueIndex], out BRTechnique actualTechnique);
- if (techniqueName == nameof(Azmandian2016Hybrid)) {
+ var enumType = typeof(BRTechnique);
+ var memberInfos = enumType.GetMember(actualTechnique.ToString());
+ var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == enumType);
+ if (enumValueMemberInfo.IsDefined(typeof(ShowHeadAttribute), false)) {
MakePropertyField(physicalHead, "Physical Head", "The Transform of the VR headset worn by the user.");
- MakePropertyField(virtualHead, "Virtual Head", "");
}
- else if (techniqueName == nameof(Poupyrev1996GoGo)) {
- MakePropertyField(physicalHead, "Physical Head", "");
+ if (actualTechnique == BRTechnique.Azmandian2016Hybrid) {
+ MakePropertyField(virtualHead, "Virtual Head", "");
}
EditorGUILayout.Space(5);
@@ -94,7 +96,7 @@ public override void OnInspectorGUI() {
parametersObject = new SerializedObject(parameters.objectReferenceValue);
parametersObject.Update();
- if (techniqueName == nameof(Kohli2010RedirectedTouching)) {
+ if (actualTechnique == BRTechnique.Kohli2010RedirectedTouching) {
MakePropertyField(referenceSurface, "Reference Surface", "Points on the physical surface that the physical hand of the user explores. This Transform should be the parent of the points. The order of points is matched with the order of interpolated surface.");
MakePropertyField(interpolatedSurface, "Interpolated Surface", "Points on the virtual surface that the virtual hand of the user will explore when touching the physical surface.This Transform should be the parent of the points. The order of points is matched with the order of reference surface.");
}
@@ -105,30 +107,28 @@ public override void OnInspectorGUI() {
}
- if (techniqueName == nameof(Kohli2010RedirectedTouching)) {
+ if (actualTechnique == BRTechnique.Kohli2010RedirectedTouching) {
MakePropertyField(parametersObject.FindProperty("SmoothingParameter"), "Smoothing", "");
MakePropertyField(parametersObject.FindProperty("Rescale"), "Rescale", "");
}
- else if (techniqueName == nameof(Geslain2022Polynom)) {
- MakePropertyField(parametersObject.FindProperty("redirectionLateness"), "Redirection Lateness (a2)");
- MakePropertyField(parametersObject.FindProperty("controlPoint"), "ControlPoint");
+ else if (actualTechnique == BRTechnique.Geslain2022Polynom) {
+ // TODO broken
+ //MakePropertyField(parametersObject.FindProperty("redirectionLateness"), "Redirection Lateness (a2)");
+ //MakePropertyField(parametersObject.FindProperty("controlPoint"), "ControlPoint");
}
- else if (techniqueName == nameof(Poupyrev1996GoGo)) {
+ else if (actualTechnique == BRTechnique.Poupyrev1996GoGo) {
MakePropertyField(parametersObject.FindProperty("GoGoCoefficient"), "Coefficient");
MakePropertyField(parametersObject.FindProperty("GoGoActivationDistance"), "Activation Distance");
}
- if (bufferTechniques.Contains(techniqueName)) {
+ if (enumValueMemberInfo.IsDefined(typeof(HasBufferAttribute), false)) {
MakePropertyField(parametersObject.FindProperty("RedirectionBuffer"), "Redirection Buffer");
}
-
- if (noThresholdTechniques.Contains(techniqueName)) {
- if (techniqueName == nameof(Lecuyer2000Swamp)) {
- MakePropertyField(parametersObject.FindProperty("SwampSquareLength"), "Square Side Length");
- MakePropertyField(parametersObject.FindProperty("SwampCDRatio"), "C/D Ratio");
- }
+ if (actualTechnique == BRTechnique.Lecuyer2000Swamp) {
+ MakePropertyField(parametersObject.FindProperty("SwampSquareLength"), "Square Side Length");
+ MakePropertyField(parametersObject.FindProperty("SwampCDRatio"), "C/D Ratio");
}
- else {
+ if (enumValueMemberInfo.IsDefined(typeof(HasThresholdAttribute), false)) {
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Threshold Parameters", EditorStyles.largeLabel);
MakePropertyField(parametersObject.FindProperty(nameof(ParametersToolkit.HorizontalAngles)), "Max Horizontal Angles");
From 1047ced78b8099cb8b66e2ba2486b29a6c6b2742 Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Fri, 3 May 2024 23:05:44 +0200
Subject: [PATCH 05/12] Start rewriting WorldRedirectionEditor.cs
---
.../Scripts/Redirection/Interaction.cs | 22 +++++----
.../Redirection/WorldRedirectionEditor.cs | 47 +++++++++++++------
2 files changed, 44 insertions(+), 25 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
index 02b48d73..113472a7 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
@@ -5,10 +5,12 @@
namespace VHToolkit.Redirection {
[System.AttributeUsage(System.AttributeTargets.All, Inherited = false, AllowMultiple = true)]
- public abstract class BRTAttribute : System.Attribute { }
- public sealed class ShowHeadAttribute : BRTAttribute { }
- public sealed class HasBufferAttribute : BRTAttribute { }
- public sealed class HasThresholdAttribute : BRTAttribute { }
+ public abstract class EditorRedirectionAttribute : System.Attribute { }
+ public sealed class ShowHeadAttribute : EditorRedirectionAttribute { }
+ public sealed class HasBufferAttribute : EditorRedirectionAttribute { }
+ public sealed class HasThresholdAttribute : EditorRedirectionAttribute { }
+ public sealed class HasStrategyAttribute : EditorRedirectionAttribute { }
+ public sealed class HasTargetsAttribute : EditorRedirectionAttribute { }
public enum BRTechnique {
None,
Reset,
@@ -36,10 +38,10 @@ public enum WRTechnique {
None,
Reset,
[InspectorName("")] SEPARATOR1,
- Razzaque2001OverTimeRotation,
- Razzaque2001Rotational,
- Razzaque2001Curvature,
- Razzaque2001Hybrid,
+ [HasStrategy] Razzaque2001OverTimeRotation,
+ [HasStrategy] Razzaque2001Rotational,
+ [HasStrategy] Razzaque2001Curvature,
+ [HasStrategy] Razzaque2001Hybrid,
Azmandian2016World,
Steinicke2008Translational
}
@@ -47,9 +49,9 @@ public enum WRTechnique {
public enum WRStrategy {
NoSteering,
[InspectorName("")] SEPARATOR1,
- SteerToCenter,
+ [HasTargets] SteerToCenter,
SteerToOrbit,
- SteerToMultipleTargets,
+ [HasTargets] SteerToMultipleTargets,
SteerInDirection,
[InspectorName(" ")] SEPARATOR2,
APF_PushPull
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs
index f0626b74..6b4abbf2 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs
@@ -2,6 +2,8 @@
using UnityEditor;
using System.Collections.Generic;
+using System;
+using System.Linq;
namespace VHToolkit.Redirection.WorldRedirection {
///
@@ -61,13 +63,16 @@ public override void OnInspectorGUI() {
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("User Parameters", EditorStyles.largeLabel);
- string techniqueName = technique.enumNames[technique.enumValueIndex];
+ Enum.TryParse(technique.enumNames[technique.enumValueIndex], out WRTechnique actualTechnique);
+ var enumType = typeof(WRTechnique);
+ var memberInfos = enumType.GetMember(actualTechnique.ToString());
+ var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == enumType);
MakePropertyField(limbs, "User Limbs", "A list of tracked user limbs.");
MakePropertyField(physicalHead, "Physical Head", "Transform tracking the user's real head");
MakePropertyField(virtualHead, "Virtual Head", "Transform tracking the user's virtual head");
- if (techniqueName == nameof(Azmandian2016World)) {
+ if (actualTechnique == WRTechnique.Azmandian2016World) {
MakePropertyField(physicalTarget, "Physical Target");
MakePropertyField(virtualTarget, "Virtual Target");
MakePropertyField(origin, "Origin");
@@ -92,18 +97,21 @@ public override void OnInspectorGUI() {
parametersObject.Update();
EditorGUILayout.Space(2);
- if (techniqueName == nameof(Razzaque2001OverTimeRotation)) {
+ if (actualTechnique == WRTechnique.Razzaque2001OverTimeRotation) {
MakePropertyField(parametersObject.FindProperty("RotationalError"), "Rotational Error");
MakePropertyField(parametersObject.FindProperty("OverTimeRotation"), "Over Time Rotation Rate");
- } else if (techniqueName == nameof(Razzaque2001Rotational)) {
+ }
+ else if (actualTechnique == WRTechnique.Razzaque2001Rotational) {
MakePropertyField(parametersObject.FindProperty("RotationalError"), "Rotational Error");
MakePropertyField(parametersObject.FindProperty("GainsRotational"), "Rotational Gains");
MakePropertyField(parametersObject.FindProperty("RotationalThreshold"), "Rotational Threshold");
- } else if (techniqueName == nameof(Razzaque2001Curvature)) {
+ }
+ else if (actualTechnique == WRTechnique.Razzaque2001Curvature) {
MakePropertyField(parametersObject.FindProperty("RotationalError"), "Rotational Error");
MakePropertyField(parametersObject.FindProperty("CurvatureRadius"), "Curvature Radius");
MakePropertyField(parametersObject.FindProperty("WalkingThreshold"), "Walking Threshold");
- } else if (techniqueName == nameof(Razzaque2001Hybrid)) {
+ }
+ else if (actualTechnique == WRTechnique.Razzaque2001Hybrid) {
MakePropertyField(parametersObject.FindProperty("RotationalError"), "Rotational Error");
MakePropertyField(enableOverTime, "Enable Over Time Rotation");
if (enableOverTime.boolValue)
@@ -143,37 +151,46 @@ public override void OnInspectorGUI() {
script.techniqueInstance = Razzaque2001Hybrid.Max();
break;
}
- } else if (techniqueName == nameof(Azmandian2016World)) {
+ }
+ else if (actualTechnique == WRTechnique.Azmandian2016World) {
MakePropertyField(parametersObject.FindProperty("GainsRotational"), "Gains Rotational");
- } else if (techniqueName == nameof(Steinicke2008Translational)) {
+ }
+ else if (actualTechnique == WRTechnique.Steinicke2008Translational) {
MakePropertyField(parametersObject.FindProperty("GainsTranslational"), "Translational Gains");
}
// Hides targets, dampening and smoothing if
- if (strategyTechniques.Contains(techniqueName)) {
+ if (enumValueMemberInfo.IsDefined(typeof(HasStrategyAttribute), false)) {
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Strategy Parameters", EditorStyles.largeLabel);
MakePropertyField(strategy, "Target selection strategy");
- if (targetsStrategies.Contains(strategy.enumNames[strategy.enumValueIndex])) {
+ Enum.TryParse(strategy.enumNames[strategy.enumValueIndex], out WRStrategy actualStrategy);
+ var strategyEnumType = typeof(WRStrategy);
+ var strategyMemberInfos = strategyEnumType.GetMember(actualStrategy.ToString());
+ var strategyEnumValueMemberInfo = strategyMemberInfos.FirstOrDefault(m => m.DeclaringType == strategyEnumType);
+
+ if (strategyEnumValueMemberInfo.IsDefined(typeof(HasTargetsAttribute), false)) {
MakePropertyField(targetsScene, "Targets");
MakePropertyField(applyDampening, "Apply Dampening");
MakePropertyField(parametersObject.FindProperty("DampeningDistanceThreshold"), "Dampening Distance Threshold");
MakePropertyField(parametersObject.FindProperty("DampeningRange"), "Dampening Range");
MakePropertyField(applySmoothing, "Apply Smoothing");
MakePropertyField(parametersObject.FindProperty("SmoothingFactor"), "Smoothing Factor");
- } else if (strategy.enumNames[strategy.enumValueIndex] == nameof(SteerToOrbit)) {
+ }
+ else if (actualStrategy == WRStrategy.SteerToOrbit) {
MakePropertyField(targetsScene, "Targets");
var steerToOrbitRadius = parametersObject.FindProperty("SteerToOrbitRadius");
EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PropertyField(steerToOrbitRadius, new GUIContent("Steer To Orbit Radius"));
- EditorGUILayout.Space(20);
- EditorGUILayout.LabelField("Rotation Rate: " + (360f / (2 * Mathf.PI * steerToOrbitRadius.floatValue)).ToString("N2") + " °/m/s");
+ EditorGUILayout.PropertyField(steerToOrbitRadius, new GUIContent("Steer To Orbit Radius"));
+ EditorGUILayout.Space(20);
+ EditorGUILayout.LabelField("Rotation Rate: " + (360f / (2 * Mathf.PI * steerToOrbitRadius.floatValue)).ToString("N2") + " °/m/s");
GUILayout.EndHorizontal();
- } else if (strategy.enumNames[strategy.enumValueIndex] == nameof(SteerInDirection)) {
+ }
+ else if (actualStrategy == WRStrategy.SteerInDirection) {
MakePropertyField(direction, "Direction");
}
}
From b15b50142b434e843b56c36d08c2dbaefb09cd10 Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Sat, 4 May 2024 00:37:19 +0200
Subject: [PATCH 06/12] Add Guardian segments computation
---
.../Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs | 2 +-
.../Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs | 12 +++++++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs
index 585fbd05..d0a120ef 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs
@@ -7,7 +7,7 @@ namespace VHToolkit {
/// Provide language features not present in this version of .Net.
///
static class Future {
- public static IEnumerable<(TFirst First, TSecond Second)> Zip(
+ public static IEnumerable<(TFirst, TSecond)> Zip(
this IEnumerable first,
IEnumerable second
) => first.Zip(second, resultSelector: (x, y) => (x, y));
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs
index 6964ef58..b88a46ec 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Guardian.cs
@@ -1,4 +1,8 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
using UnityEngine;
+using VHToolkit;
///
/// Stub class for getting Guardian boundaries, if configured.
@@ -11,4 +15,10 @@ private void Update() {
Debug.Log($"Boundary has {geometry.Length} points.");
}
}
-}
\ No newline at end of file
+
+ static private List<(Vector3, Vector3)> BarrierSegments() {
+ var geometry = OVRManager.boundary.GetGeometry(OVRBoundary.BoundaryType.PlayArea);
+ return geometry.Zip(geometry.Skip(1).Append(geometry.First())).ToList();
+ }
+}
+
From de8ca114b4ebfe8aa107fc10fe2bfe23a5ec9c51 Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Sat, 4 May 2024 16:19:54 +0200
Subject: [PATCH 07/12] Remove unnecessary fields
---
.../Utils/Editor/Redirection/WorldRedirectionEditor.cs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs
index 6b4abbf2..c91607b9 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/WorldRedirectionEditor.cs
@@ -22,8 +22,6 @@ public class WorldRedirectionEditor : Editor {
enableOverTime, enableRotational, enableCurvature,
parameters;
SerializedObject parametersObject;
- readonly HashSet strategyTechniques = new() { "Razzaque2001OverTimeRotation", "Razzaque2001Rotational", "Razzaque2001Curvature", "Razzaque2001Hybrid" };
- readonly HashSet targetsStrategies = new() { "SteerToCenter", "SteerToMultipleTargets" };
private void OnEnable() {
technique = serializedObject.FindProperty("_technique");
@@ -186,7 +184,7 @@ public override void OnInspectorGUI() {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(steerToOrbitRadius, new GUIContent("Steer To Orbit Radius"));
EditorGUILayout.Space(20);
- EditorGUILayout.LabelField("Rotation Rate: " + (360f / (2 * Mathf.PI * steerToOrbitRadius.floatValue)).ToString("N2") + " °/m/s");
+ EditorGUILayout.LabelField($"Rotation Rate: {(360f / (2 * Mathf.PI * steerToOrbitRadius.floatValue)).ToString("N2")} °/m/s");
GUILayout.EndHorizontal();
}
From c9b8107499954f81c29888c382bdc9c619f4a615 Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Thu, 23 May 2024 00:17:52 +0200
Subject: [PATCH 08/12] Misc
---
.../Redirection/BodyRedirectionEditor.cs | 1 -
.../Scripts/Visualisation/Socket.cs | 68 +++++++++++++------
2 files changed, 47 insertions(+), 22 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
index efa77079..d75a4a20 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
@@ -29,7 +29,6 @@ public class BodyRedirectionEditor : Editor {
SerializedProperty redirect;
SerializedProperty parameters;
SerializedObject parametersObject;
- readonly HashSet actualNoThresholdTechniques = new() { BRTechnique.Poupyrev1996GoGo, BRTechnique.Lecuyer2000Swamp, BRTechnique.Samad2019Weight };
private SerializedProperty Find(string name) => serializedObject.FindProperty(name);
private void OnEnable() {
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs
index 0fc90978..212599a6 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/Socket.cs
@@ -13,7 +13,7 @@ namespace VHToolkit.Logging {
[Serializable]
- struct WorldRedirectionData {
+ public struct WorldRedirectionData {
[SerializeField] public float overTime, rotational, curvature;
[SerializeField] public float overTimeSum, rotationalSum, curvatureSum;
[SerializeField] float time;
@@ -43,11 +43,54 @@ public void Reset() {
this.curvature = 0f;
}
}
+ public class VisualizerWrapper : IObserver {
+ private string filename;
+ private string pythonPath;
+ private IDisposable unsubscriber;
+
+ public void Subscribe(IObservable observable) => unsubscriber = observable?.Subscribe(this);
+
+ public VisualizerWrapper(string filename, string pythonPath) {
+ this.filename = filename;
+ this.pythonPath = pythonPath;
+ if (filename is null || !filename.EndsWith(".py") || !File.Exists(filename)) {
+ Debug.LogWarning($"Invalid Python script {filename}.");
+ }
+ else if (pythonPath is null || !pythonPath.EndsWith(".exe") || !File.Exists(pythonPath)) {
+ Debug.LogWarning($"Invalid Python executable path {filename}.");
+ }
+ else {
+ Debug.Log($"Launch visualizer with Python {pythonPath}.");
+ // TODO not great for non-windows
+ System.Diagnostics.Process p = new() {
+ StartInfo = new System.Diagnostics.ProcessStartInfo(pythonPath, filename) {
+ RedirectStandardOutput = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ }
+ };
+ p.Start();
+ }
+ }
+
+ public void OnCompleted() {
+ throw new NotImplementedException();
+ }
+
+ public void OnError(Exception error) {
+ throw new NotImplementedException();
+ }
+
+ void IObserver.OnNext(WorldRedirectionData value) {
+ throw new NotImplementedException();
+ }
+ }
public class Socket : MonoBehaviour, IObservable {
private Scene scene;
private WorldRedirection script;
private DateTime startTime;
+
private readonly HashSet> observers = new();
private TcpClient client;
@@ -74,25 +117,8 @@ private void Start() {
}
public void LaunchVisualizer() {
-
- if (filename is null || !filename.EndsWith(".py") || !File.Exists(filename)) {
- Debug.LogWarning($"Invalid Python script {filename}.");
- }
- else if (pythonPath is null || !pythonPath.EndsWith(".exe") || !File.Exists(pythonPath)) {
- Debug.LogWarning($"Invalid Python executable path {filename}.");
- }
- else {
- Debug.Log($"Launch visualizer with Python {pythonPath}.");
- // TODO not great for non-windows
- System.Diagnostics.Process p = new() {
- StartInfo = new System.Diagnostics.ProcessStartInfo(pythonPath, filename) {
- RedirectStandardOutput = true,
- UseShellExecute = false,
- CreateNoWindow = true
- }
- };
- p.Start();
- }
+ var wrapper = new VisualizerWrapper(filename, pythonPath);
+ wrapper.Subscribe(this);
}
private void GetClient() {
@@ -136,7 +162,7 @@ private void Update() {
(float)(DateTime.Now - startTime).TotalSeconds);
}
- IDisposable IObservable.Subscribe(IObserver observer) {
+ public IDisposable Subscribe(IObserver observer) {
observers.Add(observer);
return new HashSetUnsubscriber(observers, observer);
}
From 8efa0ad823ba06a22d683364977fc89c109eeed0 Mon Sep 17 00:00:00 2001
From: bjrtx <57685415+bjrtx@users.noreply.github.com>
Date: Thu, 23 May 2024 01:24:59 +0200
Subject: [PATCH 09/12] Introduce fall-off exponent
---
.../Scripts/Utils/Backport.cs | 3 +
.../Scripts/Utils/Gradient.cs | 9 ++-
.../Utils/PhysicalEnvironmentCalibration.cs | 78 +++++++++----------
3 files changed, 43 insertions(+), 47 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs
index d0a120ef..166b1971 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Backport.cs
@@ -44,6 +44,9 @@ public static TSource MinBy(this IEnumerable source, Fun
}
return result;
}
+
+ public static IEnumerable<(T, T)> CyclicPairs(this List list) => list.Zip(list.Skip(1).Append(list.First()));
+
}
}
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs
index efb6fb2e..25a6a4e4 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using MathNet.Numerics.Distributions;
namespace VHToolkit {
public static class MathTools {
@@ -34,11 +35,11 @@ public static Vector2 Gradient2(Func function, Vector2 x) {
) / (2 * eps);
}
- public static Func RepulsivePotential3D(List obstacles) =>
- (x) => obstacles.Sum(o => 1 / Vector3.Distance(x, o.ClosestPoint(x)));
+ public static Func RepulsivePotential3D(List obstacles, float exponent = 1f) =>
+ (x) => obstacles.Sum(o => 1 / Mathf.Pow(Vector3.Distance(x, o.ClosestPoint(x)), exponent));
- public static Func RepulsivePotential3D(List obstacles) =>
- (x) => obstacles.Sum(o => 1 / (x - o).sqrMagnitude);
+ public static Func RepulsivePotential3D(List obstacles, float exponent = 1f) =>
+ (x) => obstacles.Sum(o => 1 / Mathf.Pow(Vector3.Distance(x, o), exponent));
public static Vector2 Gradient2v2(Vector2 x, List obstaclescolliders) {
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/PhysicalEnvironmentCalibration.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/PhysicalEnvironmentCalibration.cs
index 7128c033..36fdf704 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/PhysicalEnvironmentCalibration.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/PhysicalEnvironmentCalibration.cs
@@ -3,50 +3,42 @@
using UnityEngine;
using VHToolkit;
-using VHToolkit.Redirection;
public class PhysicalEnvironmentCalibration : MonoBehaviour {
- [SerializeField] private float eps = 0.01f;
- [SerializeField] private Transform user;
- [SerializeField] private List bounds;
-
- // Start is called before the first frame update
- void Start() {
-
- }
-
- // Update is called once per frame
- void Update() {
- List obs = new();
-
- var dir = (bounds.First() - bounds.Last()).normalized;
- int n = (int)(Vector3.Distance(bounds.Last(), bounds.First()) / eps);
- for (int j = 0; j < n; j++) {
- obs.Add(bounds.Last() + (j + 0.5f) * eps * dir);
- }
- for (int i = 1; i < bounds.Count; i++) {
- dir = (bounds[i] - bounds[i - 1]).normalized;
- n = (int) (Vector3.Distance(bounds[i - 1], bounds[i]) / eps);
- for (int j = 0; j < n; j++) {
- obs.Add(bounds[i - 1] + (j + 0.5f) * eps * dir);
- }
- }
- Debug.Log(obs.Count);
- obs.ForEach(o => Debug.Log(o));
-
- Debug.DrawRay(user.position, ComputeGradient(user, obs).normalized);
- }
-
- private void OnDrawGizmos() {
- for (int i = 1; i < bounds.Count; i++) {
- Gizmos.DrawLine(bounds[i - 1], bounds[i]);
- }
- Gizmos.DrawLine(bounds.Last(), bounds.First());
- }
-
- private Vector3 ComputeGradient(Transform user, List dividedObstacles) => Vector3.ProjectOnPlane(MathTools.Gradient3(
- MathTools.RepulsivePotential3D(dividedObstacles),
- MathTools.ProjectToHorizontalPlaneV3(user.position)
- ), Vector3.up);
+ [SerializeField] private float eps = 0.01f;
+ [SerializeField] private Transform user;
+ [SerializeField] private List bounds;
+
+ // Start is called before the first frame update
+ void Start() {
+
+ }
+
+ // Update is called once per frame
+ void Update() {
+ var obs = bounds.CyclicPairs().SelectMany(
+ p => {
+ var dir = (p.Item1 - p.Item2).normalized;
+ var n = (int)(Vector3.Distance(p.Item1, p.Item2) / eps);
+ return Enumerable.Range(0, n).Select(j => p.Item1 + (j + 0.5f) * eps * dir);
+ }
+ ).ToList();
+
+ Debug.Log(obs.Count);
+ obs.ForEach(o => Debug.Log(o));
+
+ Debug.DrawRay(user.position, ComputeGradient(user, obs).normalized);
+ }
+
+ private void OnDrawGizmos() {
+ foreach (var (first, second) in bounds.CyclicPairs()) {
+ Gizmos.DrawLine(first, second);
+ }
+ }
+
+ private Vector3 ComputeGradient(Transform user, List dividedObstacles) => Vector3.ProjectOnPlane(MathTools.Gradient3(
+ MathTools.RepulsivePotential3D(dividedObstacles),
+ MathTools.ProjectToHorizontalPlaneV3(user.position)
+ ), Vector3.up);
}
From ecc9e7bbd12a3d3b96cc17ecf5cb0ffa5defc7ec Mon Sep 17 00:00:00 2001
From: benoitgeslain
Date: Tue, 25 Jun 2024 11:07:58 +0200
Subject: [PATCH 10/12] Exposed add_boundaries parameter
---
.../Scripts/Parameters/ParametersToolkit.cs | 4 ++--
.../Scripts/Redirection/3DInterpolation/Techniques.cs | 4 ++--
.../Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs | 1 +
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs
index 970e8567..fbced868 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs
@@ -67,7 +67,6 @@ public class ParametersToolkit : ScriptableObject {
[Tooltip("The weights used for the Razzaque2001Hybrid technique using the WeightedSum function.")]
public Vector3 HybridWeights = new(1f, 1f, 1f);
-
//
// 3D Interpolation
//
@@ -77,7 +76,8 @@ public class ParametersToolkit : ScriptableObject {
public float SmoothingParameter;
[Tooltip("Whether to apply rescaling before using thin-plate interpolation.")]
public bool Rescale;
-
+ [Tooltip("TODO")]
+ public bool add_boundaries = true;
//
// Pseudo-Haptic
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs
index db3bec7e..e5e919fb 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/3DInterpolation/Techniques.cs
@@ -14,7 +14,6 @@ namespace VHToolkit.Redirection.Interpolation3D {
public class Kohli2010RedirectedTouching : BodyRedirectionTechnique {
Func displace = null;
- bool add_boundaries = true;
///
/// Compute the displacement vector field, which should be done only on init and whenever its parameters change for efficiency reasons.
@@ -28,7 +27,8 @@ public void ComputeDisplacement(Scene scene) {
scene.parameters.SmoothingParameter,
scene.parameters.Rescale
);
- if (add_boundaries) {
+ Debug.Log(scene.parameters.add_boundaries);
+ if (scene.parameters.add_boundaries) {
var bounds = new Bounds(x[0], Vector3.zero);
foreach (var v in x.Concat(y)) {
bounds.Encapsulate(v);
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
index d75a4a20..b1a4952a 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Editor/Redirection/BodyRedirectionEditor.cs
@@ -109,6 +109,7 @@ public override void OnInspectorGUI() {
if (actualTechnique == BRTechnique.Kohli2010RedirectedTouching) {
MakePropertyField(parametersObject.FindProperty("SmoothingParameter"), "Smoothing", "");
MakePropertyField(parametersObject.FindProperty("Rescale"), "Rescale", "");
+ MakePropertyField(parametersObject.FindProperty("add_boundaries"), "Add Boundaries", "");
}
else if (actualTechnique == BRTechnique.Geslain2022Polynom) {
// TODO broken
From f8d3f05818ea27db36133cd4bfcf4407c8f0c0ab Mon Sep 17 00:00:00 2001
From: benoitgeslain
Date: Tue, 25 Jun 2024 11:46:15 +0200
Subject: [PATCH 11/12] renamed WR strategies
---
.../Corridor/Scenes/RedirectionCorridor.unity | 56 +++++++------------
.../Medium Parameters (Recommended).asset | 4 ++
.../Scripts/Parameters/ParametersToolkit.cs | 8 +++
.../Scripts/Redirection/Interaction.cs | 3 +-
.../World Redirection/Strategies.cs | 23 +++++---
.../World Redirection/WorldRedirection.cs | 3 +-
.../Scripts/Utils/Gradient.cs | 5 --
.../Visualisation/APFGradientVisuals.cs | 2 +-
.../Scripts/Visualisation/WRVisuals.cs | 4 +-
.../ProjectSettings/EditorBuildSettings.asset | 2 +-
10 files changed, 53 insertions(+), 57 deletions(-)
diff --git a/Visuo-haptic Toolkit/Assets/Demo Scenes/Corridor/Scenes/RedirectionCorridor.unity b/Visuo-haptic Toolkit/Assets/Demo Scenes/Corridor/Scenes/RedirectionCorridor.unity
index 60a89534..d39e93c5 100644
--- a/Visuo-haptic Toolkit/Assets/Demo Scenes/Corridor/Scenes/RedirectionCorridor.unity
+++ b/Visuo-haptic Toolkit/Assets/Demo Scenes/Corridor/Scenes/RedirectionCorridor.unity
@@ -1093,6 +1093,10 @@ PrefabInstance:
propertyPath: physicalHead
value:
objectReference: {fileID: 141383211}
+ - target: {fileID: 3150399032746346357, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
+ propertyPath: m_Enabled
+ value: 1
+ objectReference: {fileID: 0}
- target: {fileID: 3345062529341880481, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
propertyPath: m_LocalPosition.x
value: 0
@@ -1147,7 +1151,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 7088029602675669135, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
propertyPath: strategy
- value: 7
+ value: 8
objectReference: {fileID: 0}
- target: {fileID: 7088029602675669135, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
propertyPath: m_Enabled
@@ -1233,9 +1237,21 @@ PrefabInstance:
propertyPath: scene.limbs.Array.data[1].virtualLimb.Array.data[1]
value:
objectReference: {fileID: 3300481182696120806}
+ - target: {fileID: 7284946694485075413, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
+ propertyPath: filename
+ value: C:\Users\Ben\projects\toolkit\python\RedirectionPlotter.py
+ objectReference: {fileID: 0}
+ - target: {fileID: 7284946694485075413, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
+ propertyPath: m_Enabled
+ value: 1
+ objectReference: {fileID: 0}
+ - target: {fileID: 7284946694485075413, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
+ propertyPath: pythonPath
+ value: C:\Users\Ben\anaconda3\envs\toolkit\python.exe
+ objectReference: {fileID: 0}
m_RemovedComponents:
- - {fileID: 3527750865740220717, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
- - {fileID: 2164931620210237325, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
+ - {fileID: 0}
+ - {fileID: 0}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
@@ -1245,12 +1261,6 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 200869264966477082, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
insertIndex: -1
addedObject: {fileID: 358983268}
- - targetCorrespondingSourceObject: {fileID: 200869264966477082, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
- insertIndex: -1
- addedObject: {fileID: 358983272}
- - targetCorrespondingSourceObject: {fileID: 200869264966477082, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
- insertIndex: -1
- addedObject: {fileID: 358983261}
- targetCorrespondingSourceObject: {fileID: 200869264966477082, guid: 7e46c8eb8c13fdb429130703b04c8216, type: 3}
insertIndex: -1
addedObject: {fileID: 358983277}
@@ -1282,20 +1292,6 @@ MonoBehaviour:
redirectionAmount: 180
start: {fileID: 2099766480}
end: {fileID: 1861591714}
---- !u!114 &358983261
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 358983253}
- m_Enabled: 1
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: 51d618b1b4dddf44a8b914838ac6e9b6, type: 3}
- m_Name:
- m_EditorClassIdentifier:
- logDirectoryPath: LoggedData\
- optionalFilenamePrefix:
--- !u!114 &358983268
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -1310,20 +1306,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
physicalCorridor: {fileID: 1617016940}
virtualCorridor: {fileID: 646063775}
---- !u!114 &358983272
-MonoBehaviour:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 358983253}
- m_Enabled: 0
- m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: bb5310432868de244b86ddcc9c3aa8c1, type: 3}
- m_Name:
- m_EditorClassIdentifier:
- filename: C:\Users\Public\Documents\UnityWP\Toolkit Illusions\Visuo-haptic-Illusions-Toolkit\python\RedirectionPlotter.py
- pythonPath: C:\Users\guest\anaconda3\envs\plt\python.exe
--- !u!114 &358983277
MonoBehaviour:
m_ObjectHideFlags: 0
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/Medium Parameters (Recommended).asset b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/Medium Parameters (Recommended).asset
index c76f040e..932c90eb 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/Medium Parameters (Recommended).asset
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/Medium Parameters (Recommended).asset
@@ -34,6 +34,9 @@ MonoBehaviour:
DampeningRange: 1.57
SmoothingFactor: 0.2
SteerToOrbitRadius: 5
+ obstaclesFallOffFactor: 2.656
+ usersFallOffFactor: 3.091
+ scaleMultipler: 2.5
OverTimeRotation: 0.1
GainsTranslational: {x: 1, y: 1, z: 1}
GainsRotational:
@@ -43,5 +46,6 @@ MonoBehaviour:
HybridWeights: {x: 1, y: 1, z: 1}
SmoothingParameter: 0
Rescale: 0
+ add_boundaries: 0
SwampSquareLength: 0.25
SwampCDRatio: 0.75
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs
index fbced868..533cde5c 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Parameters/ParametersToolkit.cs
@@ -55,6 +55,14 @@ public class ParametersToolkit : ScriptableObject {
[Tooltip("The radius of the orbit around which the user is redirected with the SteerToOrbit techniques described in [TODO]")]
public float SteerToOrbitRadius = 5f;
+ // APF params
+ [Tooltip("")]
+ public float obstaclesFallOffFactor = 2.656f;
+ [Tooltip("")]
+ public float usersFallOffFactor = 3.091f;
+ [Tooltip("")]
+ public float scaleMultipler = 2.5f;
+
// Techniques params
[Tooltip("The maximum rotation that can be applied to the user's point of view in rotation along the vertical axis (Y). Value is in °/s.")]
public float OverTimeRotation = 0.2f;
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
index 113472a7..df1fa6a1 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/Interaction.cs
@@ -54,7 +54,8 @@ public enum WRStrategy {
[HasTargets] SteerToMultipleTargets,
SteerInDirection,
[InspectorName(" ")] SEPARATOR2,
- APF_PushPull
+ Thomas2019APF_PushPull,
+ Messinger2019APF
}
public enum HybridAggregate {
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs
index 0963f047..b71414a8 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs
@@ -68,21 +68,26 @@ public class SteerInDirection : WorldRedirectionStrategy {
public override Vector3 SteerTo(Scene scene) => scene.physicalHead.rotation * scene.strategyDirection;
}
- public class APFP2R : WorldRedirectionStrategy {
+ public class Thomas2019APF_PushPull : WorldRedirectionStrategy {
/// A list of colliders, each of which will create a repulsive potential field.
public List colliders;
- public APFP2R() {
- colliders = GameObject.FindGameObjectsWithTag("Obstacle").Select(o => o.GetComponent()).ToList();
+ public Thomas2019APF_PushPull() {
+ colliders = GameObject.FindGameObjectsWithTag("Obstacle").Select(o => o.GetComponent()).ToList();
// colliders.ForEach(o => o.transform.position = MathTools.ProjectToHorizontalPlaneV3(o.transform.position));
}
- public override Vector3 SteerTo(Scene scene) => ComputeGradient(scene);
+ public override Vector3 SteerTo(Scene scene) => ComputeGradient(scene);
- private Vector3 ComputeGradient(Scene scene) => Vector3.ProjectOnPlane(MathTools.Gradient3(
- MathTools.RepulsivePotential3D(colliders),
+ private Vector3 ComputeGradient(Scene scene) => Vector3.ProjectOnPlane(MathTools.Gradient3(
+ MathTools.RepulsivePotential3D(colliders),
MathTools.ProjectToHorizontalPlaneV3(scene.physicalHead.position)
- ), Vector3.up);
- }
-}
\ No newline at end of file
+ ), Vector3.up);
+ }
+
+ public class Messinger2019APF : WorldRedirectionStrategy {
+
+
+ }
+}
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/WorldRedirection.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/WorldRedirection.cs
index c17ca7e9..b77f85d8 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/WorldRedirection.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/WorldRedirection.cs
@@ -43,7 +43,8 @@ private void UpdateTechnique() {
WRStrategy.SteerToOrbit => new SteerToOrbit(),
WRStrategy.SteerToMultipleTargets => new SteerToMultipleTargets(),
WRStrategy.SteerInDirection => new SteerInDirection(),
- WRStrategy.APF_PushPull => new APFP2R(),
+ WRStrategy.Thomas2019APF_PushPull => new Thomas2019APF_PushPull(),
+ WRStrategy.Messinger2019APF => new Messinger2019APF(),
_ => null
};
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs
index 25a6a4e4..9771663c 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Utils/Gradient.cs
@@ -51,11 +51,6 @@ public static Vector2 Gradient2v2(Vector2 x, List obstaclescolliders
) / (2 * eps);
}
-
-
-
-
-
// The potential is given as || x - goal || / 2.
public static Vector2 GradientOfAttractivePotential(Vector2 goal, Vector2 x) => (x - goal).normalized / 2;
public readonly struct PositionAndRotation2D {
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs
index 93765828..555dc960 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/APFGradientVisuals.cs
@@ -99,7 +99,7 @@ private void UpdateRepulsiveFunc() {
CancelInvoke(nameof(UpdateVectorField));
// get gameobjects with obstacle tag
- obstaclesCollider = ((APFP2R)script.strategyInstance).colliders;
+ obstaclesCollider = ((Thomas2019APF_PushPull)script.strategyInstance).colliders;
// Compute the bounding box and repulsive function for all colliders
if (obstaclesCollider.Any()) {
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/WRVisuals.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/WRVisuals.cs
index c80d847c..5f4da999 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/WRVisuals.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Visualisation/WRVisuals.cs
@@ -51,8 +51,8 @@ private void LateUpdate() {
case WRStrategy.SteerInDirection:
SteerInDirection(scene);
break;
- case WRStrategy.APF_PushPull:
- (WRMainScript.strategyInstance as APFP2R).colliders.ForEach(o => Debug.DrawLine(scene.physicalHead.position, o.ClosestPoint(scene.physicalHead.position), Color.Lerp(Color.clear, Color.yellow, 1 / Vector3.Distance(scene.physicalHead.position, o.ClosestPoint(scene.physicalHead.position)))));
+ case WRStrategy.Thomas2019APF_PushPull:
+ (WRMainScript.strategyInstance as Thomas2019APF_PushPull).colliders.ForEach(o => Debug.DrawLine(scene.physicalHead.position, o.ClosestPoint(scene.physicalHead.position), Color.Lerp(Color.clear, Color.yellow, 1 / Vector3.Distance(scene.physicalHead.position, o.ClosestPoint(scene.physicalHead.position)))));
// (WRMainScript.strategyInstance as APFP2R).colliders.ForEach(o => {
// Debug.Log($"{o.gameObject.name} : {1 / Vector3.Distance(scene.physicalHead.position, o.ClosestPoint(scene.physicalHead.position))}");
// });
diff --git a/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset b/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset
index 8cb73128..02734116 100644
--- a/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset
+++ b/Visuo-haptic Toolkit/ProjectSettings/EditorBuildSettings.asset
@@ -23,7 +23,7 @@ EditorBuildSettings:
path: Assets/Demo Scenes/Azmandian 3 Cubes/Static Floating Cubes.unity
guid: 885a34dea4cdceb4fb2045466d51655a
m_configObjects:
- Unity.XR.Oculus.Settings: {fileID: 11400000, guid: 755c5043d51c4b8469858eb1afffe2e8, type: 2}
+ Unity.XR.Oculus.Settings: {fileID: 11400000, guid: 03cfe8516045454468242db0acd316fd, type: 2}
Unity.XR.OpenVR.Settings: {fileID: 11400000, guid: b6bf661543b159f4f93e0c7221185c37, type: 2}
com.unity.xr.management.loader_settings: {fileID: 11400000, guid: 59bb4fa2062df8549bae6e1c8690288b, type: 2}
com.unity.xr.openxr.settings4: {fileID: 11400000, guid: f15c911359537b241b84e33fd34fbf49, type: 2}
From a972e31a51abae856689ab508c9b63e7c6b2e0a3 Mon Sep 17 00:00:00 2001
From: benoitgeslain
Date: Tue, 25 Jun 2024 11:48:03 +0200
Subject: [PATCH 12/12] renamed WR strategies
---
.../Scripts/Redirection/World Redirection/Strategies.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs
index b71414a8..9196f50f 100644
--- a/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs
+++ b/Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Redirection/World Redirection/Strategies.cs
@@ -88,6 +88,6 @@ private Vector3 ComputeGradient(Scene scene) => Vector3.ProjectOnPlane(MathTools
public class Messinger2019APF : WorldRedirectionStrategy {
-
+ public override Vector3 SteerTo(Scene scene) => Vector3.forward;
}
}