Skip to content

Commit

Permalink
Merge pull request #57 from bjrtx/main
Browse files Browse the repository at this point in the history
Modify Kohli bounding box behaviour
  • Loading branch information
bjrtx authored Apr 30, 2024
2 parents 44e4869 + 76f86f3 commit a5019c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public record JsonRedirectionData {
public List<TransformData> Targets => script.scene.targets.ConvertAll(t => new TransformData(t));
public TransformData PhysicalTarget => script.scene.physicalTarget ? new(script.scene.physicalTarget) : null;
public TransformData VirtualTarget => script.scene.virtualTarget ? new(script.scene.virtualTarget) : null;
public string StrategyDirection => script.scene.forwardTarget != null ? script.scene.forwardTarget.ToString() : null;
public string StrategyDirection => script.scene.forwardTarget != null ? Convert.ToString(script.scene.forwardTarget.ToString()) : null;

public JsonRedirectionData(Interaction script) => this.script = script;
}
Expand All @@ -74,8 +74,8 @@ protected void WriteRecords(Queue<T> records) {
}

private sealed class Unsubscriber : IDisposable {
private HashSet<IObserver<T>> _observers;
private IObserver<T> _observer;
private readonly HashSet<IObserver<T>> _observers;
private readonly IObserver<T> _observer;

public Unsubscriber(HashSet<IObserver<T>> observers, IObserver<T> observer) {
_observers = observers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,26 @@ public class Kohli2010RedirectedTouching : BodyRedirectionTechnique {
public void ComputeDisplacement(Scene scene) {
var x = Array.ConvertAll(scene.referenceParent.GetComponentsInChildren<Transform>(), t => t.position);
var y = Array.ConvertAll(scene.interpolatedParent.GetComponentsInChildren<Transform>(), t => t.position);
if (add_boundaries) {
var bounds = new Bounds(x[0], Vector3.zero);
foreach (var v in x.Concat(y)) {
bounds.Encapsulate(v);
}
bounds.extents *= 2f;
Vector3[] ends = { bounds.min, bounds.max };
var supplementary_fixed = new List<Vector3>(8);
foreach (var a in ends)
foreach (var b in ends)
foreach (var c in ends)
supplementary_fixed.Add(new Vector3(a.x, b.y, c.z));
x = x.Concat(supplementary_fixed).ToArray();
y = y.Concat(supplementary_fixed).ToArray();
}
displace = ThinPlateSpline.SabooSmoothedDisplacementField(
x,
y,
scene.parameters.SmoothingParameter,
scene.parameters.Rescale
);
if (add_boundaries) {
var bounds = new Bounds(x[0], Vector3.zero);
foreach (var v in x.Concat(y)) {
bounds.Encapsulate(v);
}
var sqrRadius = 3 * bounds.extents.sqrMagnitude;

static float f(float x) => x > 0 ? Mathf.Exp(-1 / x) : 0;
static float g(float x) => f(x) / (f(x) + f(1 - x));
float transitionLayerWidth = 0.5F;
float smoothTransition(float x) => 1 - g((x - sqrRadius) / (transitionLayerWidth * sqrRadius));
var old_displace = displace;
displace = (pos) => old_displace(pos) * smoothTransition((pos - bounds.center).sqrMagnitude);
}
}

public override void Redirect(Scene scene) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ struct WorldRedirectionData {
[SerializeField] float[] maxSums;

public void AddTo(float overTime, float rotational, float curvature, float time) {
if (this.maxSums is null || this.maxSums.Length != 3) {
this.maxSums = new float[3];
if (maxSums?.Length != 3) {
maxSums = new float[3];
}
this.overTime += Mathf.Abs(overTime);
this.rotational += Mathf.Abs(rotational);
Expand Down Expand Up @@ -108,9 +108,6 @@ private void StartSendingMessages() {
Thread thread = new(() => SendMessage(client, json));
thread.Start();
redirectionData.Reset();
// redirectionData.overTime = 0f;
// redirectionData.rotational = 0f;
// redirectionData.curvature = 0f;
}
}

Expand Down

0 comments on commit a5019c8

Please sign in to comment.