Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitGeslain committed Jun 26, 2024
2 parents 0694103 + a972e31 commit f2f5e16
Show file tree
Hide file tree
Showing 24 changed files with 308 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public record JsonRedirectionData {
/// target selection strategy, if any, or the empty string.
/// </value>
public string Strategy => script switch {
WorldRedirection => (script as WorldRedirection).strategy.ToString(),
WorldRedirection wr => wr.strategy.ToString(),
BodyRedirection => String.Empty,
_ => String.Empty
};
Expand All @@ -55,9 +55,9 @@ public record JsonRedirectionData {
/// technique, if any, or the empty string.
/// </value>
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,7 +119,6 @@ private sealed class FileObserver : AbstractFileObserver<RedirectionData> {
}

public override void OnNext(RedirectionData value) {
csvWriter.Context.RegisterClassMap<RedirectionDataMap>();
csvWriter.WriteRecord(value);
csvWriter.NextRecord();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -67,7 +75,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
//
Expand All @@ -77,7 +84,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace VHToolkit.Redirection.Interpolation3D {
public class Kohli2010RedirectedTouching : BodyRedirectionTechnique {

Func<Vector3, Vector3> displace = null;
bool add_boundaries = true;

/// <summary>
/// Compute the displacement vector field, which should be done only on init and whenever its parameters change for efficiency reasons.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BodyRedirection : Interaction {
/// Updates the techniqueInstance according to the enumeration technique chosen.
/// </summary>
private void UpdateTechnique() {
techniqueInstance = _technique switch {
techniqueInstance = Technique switch {
BRTechnique.None => new NoBodyRedirection(),
BRTechnique.Reset => new ResetBodyRedirection(),
BRTechnique.Azmandian2016Body => new Azmandian2016Body(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
using UnityEngine;

namespace VHToolkit.Redirection {

[System.AttributeUsage(System.AttributeTargets.All, Inherited = false, AllowMultiple = true)]
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,
[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,
Expand All @@ -30,23 +38,24 @@ public enum WRTechnique {
None,
Reset,
[InspectorName("")] SEPARATOR1,
Razzaque2001OverTimeRotation,
Razzaque2001Rotational,
Razzaque2001Curvature,
Razzaque2001Hybrid,
[HasStrategy] Razzaque2001OverTimeRotation,
[HasStrategy] Razzaque2001Rotational,
[HasStrategy] Razzaque2001Curvature,
[HasStrategy] Razzaque2001Hybrid,
Azmandian2016World,
Steinicke2008Translational
}

public enum WRStrategy {
NoSteering,
[InspectorName("")] SEPARATOR1,
SteerToCenter,
[HasTargets] SteerToCenter,
SteerToOrbit,
SteerToMultipleTargets,
[HasTargets] SteerToMultipleTargets,
SteerInDirection,
[InspectorName(" ")] SEPARATOR2,
APF_PushPull
Thomas2019APF_PushPull,
Messinger2019APF
}

public enum HybridAggregate {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace VHToolkit.Redirection {
abstract public class RedirectionTechnique {
/// <summary>
/// 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.
/// <c>Redirect</c> 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.
/// </summary>
public abstract void Redirect(Scene scene);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/// <value>A list of colliders, each of which will create a repulsive potential field.</value>
public List<Collider> colliders;

public APFP2R() {
colliders = GameObject.FindGameObjectsWithTag("Obstacle").Select(o => o.GetComponent<Collider>()).ToList();
public Thomas2019APF_PushPull() {
colliders = GameObject.FindGameObjectsWithTag("Obstacle").Select(o => o.GetComponent<Collider>()).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);
}
}
), Vector3.up);
}

public class Messinger2019APF : WorldRedirectionStrategy {

public override Vector3 SteerTo(Scene scene) => Vector3.forward;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace VHToolkit {
/// Provide language features not present in this version of .Net.
/// </summary>
static class Future {
public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(
public static IEnumerable<(TFirst, TSecond)> Zip<TFirst, TSecond>(
this IEnumerable<TFirst> first,
IEnumerable<TSecond> second
) => first.Zip(second, resultSelector: (x, y) => (x, y));
Expand Down Expand Up @@ -44,6 +44,9 @@ public static TSource MinBy<TSource, TKey>(this IEnumerable<TSource> source, Fun
}
return result;
}

public static IEnumerable<(T, T)> CyclicPairs<T>(this List<T> list) => list.Zip(list.Skip(1).Append(list.First()));

}

}
Loading

0 comments on commit f2f5e16

Please sign in to comment.