Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitGeslain committed Mar 11, 2024
2 parents 478272b + b9dbb8f commit 4a57f88
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 358983253}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 51d618b1b4dddf44a8b914838ac6e9b6, type: 3}
m_Name:
Expand Down Expand Up @@ -1231,8 +1231,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: bb5310432868de244b86ddcc9c3aa8c1, type: 3}
m_Name:
m_EditorClassIdentifier:
filename: C:\Users\ms-vr\projects\unity\toolkit\python\RedirectionPlotter.py
pythonPath: C:\Users\ms-vr\anaconda3\envs\plot\python.exe
--- !u!1 &398215666
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2332,8 +2330,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: bb5310432868de244b86ddcc9c3aa8c1, type: 3}
m_Name:
m_EditorClassIdentifier:
filename:
pythonPath:
--- !u!1 &858473990
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ public class CorridorRedirection : MonoBehaviour {
[SerializeField] private Transform start, end;
private float NormalizedDistance => Mathf.InverseLerp(start.position.z, end.position.z, UserHead.position.z);

private void Start() => redirectionScript = this.GetComponent<WorldRedirection>();

private void Update() {
private void Start() => redirectionScript = GetComponent<WorldRedirection>();

private void Update() {
redirectionApplied = redirectionScript.GetAngularRedirection().eulerAngles.y;
if (redirectionApplied > redirectionAmount) {
redirectionScript.StopRedirection();
} else {
redirectionScript.StartRedirection();
}
redirectionScript.redirect = redirectionApplied < redirectionAmount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ public class CorridorRepresentation : MonoBehaviour {

private WorldRedirection script;

private void Start() {
script = this.GetComponent<WorldRedirection>();
}
private void Start() => script = GetComponent<WorldRedirection>();

private void Update() {
virtualCorridor.SetPositionAndRotation(physicalCorridor.position, physicalCorridor.rotation);
virtualCorridor.position = physicalCorridor.position + script.scene.GetHeadToHeadVector();
virtualCorridor.SetPositionAndRotation(physicalCorridor.position + script.scene.GetHeadToHeadVector(), physicalCorridor.rotation);
virtualCorridor.RotateAround(script.scene.physicalHead.position, Vector3.up, -script.scene.HeadToHeadRedirection.eulerAngles.y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ GameObject:
- component: {fileID: 3345062529341880481}
- component: {fileID: 7088029602675669135}
- component: {fileID: 3621196646475796290}
- component: {fileID: 2164931620210237325}
- component: {fileID: 3527750865740220717}
m_Layer: 0
m_Name: ToolkitWorldRedirection
m_TagString: Untagged
Expand Down Expand Up @@ -54,13 +52,10 @@ MonoBehaviour:
physicalHead: {fileID: 0}
virtualHead: {fileID: 0}
physicalTarget: {fileID: 0}
physicalTargetPosition: {x: 0, y: 0, z: 0}
virtualTarget: {fileID: 0}
virtualTargetPosition: {x: 0, y: 0, z: 0}
origin: {fileID: 0}
targets:
- {fileID: 0}
radius: 5
applyDampening: 0
applySmoothing: 0
selectedTarget: {fileID: 0}
Expand All @@ -70,8 +65,14 @@ MonoBehaviour:
previousHeadPosition: {x: 0, y: 0, z: 0}
previousHeadRotation: {x: 0, y: 0, z: 0, w: 0}
previousRedirection: 0
strategyDirection: {x: 0, y: 0, z: 0}
parameters: {fileID: 0}
aggregateFunction: 0
enableHybridOverTime: 1
enableHybridRotational: 1
enableHybridCurvature: 1
redirect: 1
technique: 2
_technique: 0
strategy: 3
--- !u!114 &3621196646475796290
MonoBehaviour:
Expand All @@ -86,34 +87,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
targetPrefab: {fileID: 84340963187888445, guid: 786584c1c713db54b9cad6864b80089b, type: 3}
active: {fileID: 0}
inactive: {fileID: 2100000, guid: fdc7faebe87ef18468772439a4b880b2, type: 2}
activeMaterial: {fileID: 0}
inactiveMaterial: {fileID: 0}
orbitResolution: 3
--- !u!114 &2164931620210237325
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 200869264966477082}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f426d30751fd5b14c9c1093c441414b3, type: 3}
m_Name:
m_EditorClassIdentifier:
physicalHead: {fileID: 0}
world: {fileID: 0}
characteristics: 100
--- !u!114 &3527750865740220717
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 200869264966477082}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a9825707130c9eb4a9c129292679e71c, type: 3}
m_Name:
m_EditorClassIdentifier:
parameters: {fileID: 11400000, guid: c39097e50bc3898498d2edf378be3a21, type: 2}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using UnityEngine;

using VHToolkit.Demo;

namespace VHToolkit.Calibration {

public class QuickCalibration : MonoBehaviour {
[SerializeField] private Transform physicalHead;
[SerializeField] private Transform world;

private void Update() {
private void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Debug.Log("Resetting world position");
world.SetPositionAndRotation(new(physicalHead.position.x, 0f, physicalHead.position.z),
Quaternion.Euler(0f, physicalHead.rotation.eulerAngles.y, 0f));
// this.GetComponent<CorridorRedirection>().state = 0;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class JsonLogging : MonoBehaviour {
private string fileName;
private readonly int bufferSize = 10; // number of records kept before writing to disk

private List<JsonRedirectionData> records = new();
private Queue<JsonRedirectionData> records = new();

private Interaction script;

Expand All @@ -76,7 +76,7 @@ private void Start() {
}

private void Update() {
void writeRecords<Data>(List<Data> records) {
void writeRecords<Data>(Queue<Data> records) {
if (records.Count > bufferSize) {
using var writer = new StreamWriter(fileName, append: true);
foreach (var record in records) {
Expand All @@ -86,15 +86,14 @@ void writeRecords<Data>(List<Data> records) {
}
}

records.Add(new JsonRedirectionData(script));
records.Enqueue(new JsonRedirectionData(script));
writeRecords(records);
}

public void CreateNewFile() {
Debug.Log("Create Json log file.");
Directory.CreateDirectory(logDirectoryPath);
fileName = $"{logDirectoryPath}{optionalFilenamePrefix}{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.jsonl";
records = new List<JsonRedirectionData>();
records = new Queue<JsonRedirectionData>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public override void Redirect(Scene scene) {
public class ResetBodyRedirection : BodyRedirectionTechnique {

public override void Redirect(Scene scene) {
foreach ((var limb, var t) in scene.limbs.Zip(scene.GetLimbInstantTranslation())) {
limb.virtualLimb.ForEach(vlimb => vlimb.Translate(t + t.magnitude * scene.parameters.ResetRedirectionCoeff * (limb.physicalLimb.position - vlimb.position).normalized, relativeTo: Space.World));
foreach (var (limb, t) in scene.limbs.Zip(scene.GetLimbInstantTranslation())) {
limb.virtualLimb.ForEach(vlimb => vlimb.Translate(t + t.magnitude * Toolkit.Instance.parameters.ResetRedirectionCoeff * (limb.physicalLimb.position - vlimb.position).normalized, relativeTo: Space.World));
};
}
}
Expand All @@ -153,7 +153,7 @@ public override void Redirect(Scene scene) {
public class NoBodyRedirection : BodyRedirectionTechnique {

public override void Redirect(Scene scene) {
foreach ((var limb, var t) in scene.limbs.Zip(scene.GetLimbInstantTranslation())) {
foreach (var (limb, t) in scene.limbs.Zip(scene.GetLimbInstantTranslation())) {
limb.virtualLimb.ForEach(vlimb => vlimb.Translate(t, relativeTo: Space.World));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ namespace VHToolkit.Redirection {
/// <summary>
/// This is the base class for the visuo-haptic techniques managers such as BodyRedirection.
/// </summary>
public class Interaction : MonoBehaviour {
public class Interaction : MonoBehaviour {
public Scene scene;
public bool redirect = false;

public void StartRedirection() => redirect = true;

public void StopRedirection() => redirect = false;

public List<Transform> GetPhysicalLimbs() => scene.limbs.ConvertAll(limb => limb.physicalLimb);

public void AddPhysicalLimb(Transform physicalLimb, IEnumerable<Transform> virtualLimbs) => scene.limbs.Add(new(physicalLimb, virtualLimbs.ToList()));
Expand All @@ -24,5 +20,5 @@ public class Interaction : MonoBehaviour {
public List<Limb> GetLimbs() => scene.limbs;

public void SetLimbs(IEnumerable<Limb> limbs) => scene.limbs = limbs.ToList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public override Vector3 SteerTo(Scene scene) {
float bearing(Transform t) => Vector3.Angle(
Vector3.ProjectOnPlane(scene.physicalHead.forward, Vector3.up),
Vector3.ProjectOnPlane(t.position - scene.physicalHead.position, Vector3.up));
scene.selectedTarget = scene.targets.MinBy(bearing);
scene.selectedTarget = scene.targets.Where(t => t != null).MinBy(bearing);
if (scene.selectedTarget == null) {
Debug.LogWarning("Using SteerToMultipleTargets but scene.targets is empty or all-null.");
return scene.physicalHead.forward;
}
return scene.selectedTarget.position - scene.physicalHead.position;
}
}
Expand All @@ -56,8 +60,6 @@ class SteerInDirection : WorldRedirectionStrategy {
/// </summary>
/// <param name="scene"></param>
/// <returns></returns>
public override Vector3 SteerTo(Scene scene) {
return scene.physicalHead.rotation * scene.strategyDirection;
}
public override Vector3 SteerTo(Scene scene) => scene.physicalHead.rotation * scene.strategyDirection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public static TSource MinBy<TSource, TKey>(this IEnumerable<TSource> source, Fun
TSource result = default;
TKey value = default;
foreach (var x in source) {
var newValue = keySelector(x);
if (result is null || newValue.CompareTo(value) < 0) {
result = x;
value = newValue;
if (x != null) {
var newValue = keySelector(x);
if (result is null || newValue.CompareTo(value) < 0) {
result = x;
value = newValue;
}
}
}
return result;
Expand Down
Loading

0 comments on commit 4a57f88

Please sign in to comment.