Skip to content

Commit

Permalink
feat: add damping, shorter hirachy
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackebein committed Aug 13, 2024
1 parent e6d97df commit 2b9f513
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Hackebein's VPM Listing: [vpm.hackebein.dev](https://vpm.hackebein.dev)
* Hide beyond limits: Hides the object if it goes beyond maximum range
* Setup your Tracking costs
* Press Create: Tracker gets generated at 0, 0 if "Apply last position" is unchecked
* Align your object inside the 4th object with the same name at 1:1 IRL scale
* Align your object inside the object with the same serial number at 1:1 IRL scale

Video: https://youtu.be/oxvaUqVMznQ

Expand Down
53 changes: 28 additions & 25 deletions Runtime/SetupTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,33 @@ public SetupTracker(string name, Utility.TrackerType trackerType = Utility.Track

public GameObject AppendObjects(GameObject parent)
{
GameObject ignore = Utility.FindOrCreateGameObject("_ignore", parent);

// Objects for position (x, y, z)
GameObject x = Utility.FindOrCreateEmptyGameObject(name, parent);
GameObject x = Utility.FindOrCreateEmptyGameObject(name, ignore);
GameObject y = Utility.FindOrCreateEmptyGameObject(name, x);
GameObject z = Utility.FindOrCreateEmptyGameObject(name, y);

// Object with constraint for rotation (x, y, z)
GameObject r = Utility.FindOrCreateEmptyGameObject(name, z);
GameObject r = Utility.FindOrCreateEmptyGameObject(name, parent);

// Constraint
// TODO: add linear interpolation
ParentConstraint constraint = r.AddComponent<ParentConstraint>();
constraint.constraintActive = true;
constraint.enabled = true;
constraint.locked = true;
constraint.translationAxis = Axis.None;

ConstraintSource source1 = new ConstraintSource
{
weight = 1,
weight = 0.05f,
sourceTransform = z.transform
};
constraint.AddSource(source1);

ConstraintSource source2 = new ConstraintSource
{
// TODO: add linear interpolation
weight = 0,
weight = 1,
sourceTransform = r.transform
};
constraint.AddSource(source2);
Expand Down Expand Up @@ -167,6 +168,8 @@ public GameObject AppendObjects(GameObject parent)
x.transform.localPosition = new Vector3(defaultPX, 0, 0);
y.transform.localPosition = new Vector3(0, defaultPY, 0);
z.transform.localPosition = new Vector3(0, 0, defaultPZ);
r.transform.localPosition = new Vector3(defaultPX, defaultPY, defaultPZ);
r.transform.localRotation = Quaternion.Euler(defaultRX, defaultRY, defaultRZ);
constraint.SetRotationOffset(0, Quaternion.Euler(defaultRX, defaultRY, defaultRZ).eulerAngles);
}

Expand Down Expand Up @@ -196,29 +199,29 @@ private string[] AxePathAndProperty(string name)
switch (name)
{
case "PX":
path = "ObjectTracking/" + this.name;
path = "ObjectTracking/_ignore/" + this.name;
property = "m_LocalPosition.x";
break;
case "PY":
path = "ObjectTracking/" + this.name + "/" + this.name;
path = "ObjectTracking/_ignore/" + this.name + "/" + this.name;
property = "m_LocalPosition.y";
break;
case "PZ":
path = "ObjectTracking/" + this.name + "/" + this.name + "/" + this.name;
path = "ObjectTracking/_ignore/" + this.name + "/" + this.name + "/" + this.name;
property = "m_LocalPosition.z";
break;
case "RX":
path = "ObjectTracking/" + this.name + "/" + this.name + "/" + this.name + "/" + this.name;
path = "ObjectTracking/" + this.name;
property = "m_RotationOffsets.Array.data[0].x";
// VRC Constraints: Sources.source0.ParentRotationOffset.x
break;
case "RY":
path = "ObjectTracking/" + this.name + "/" + this.name + "/" + this.name + "/" + this.name;
path = "ObjectTracking/" + this.name;
property = "m_RotationOffsets.Array.data[0].y";
// VRC Constraints: Sources.source0.ParentRotationOffset.y
break;
case "RZ":
path = "ObjectTracking/" + this.name + "/" + this.name + "/" + this.name + "/" + this.name;
path = "ObjectTracking/" + this.name;
property = "m_RotationOffsets.Array.data[0].z";
// VRC Constraints: Sources.source0.ParentRotationOffset.z
break;
Expand Down Expand Up @@ -547,19 +550,19 @@ public void AppendResetList(Dictionary<string[], float[]> reset)
{
foreach (KeyValuePair<string[], int[]> axe in Axes())
{
reset.Add(new[] { axe.Key[1], "m_IsActive" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalPosition.x" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalPosition.y" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalPosition.z" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.x" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.y" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.z" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.w" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalScale.x" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalScale.y" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalScale.z" }, new[] { 1f, 1f });
if (axe.Key[0] == "PX") {
reset.Add(new[] { axe.Key[1], "m_RotationOffsets.Array.data[1].weight" }, new[] { 3f, 3f });
if (axe.Key[0].StartsWith("P") || axe.Key[0] == "RX")
{
reset.Add(new[] { axe.Key[1], "m_IsActive" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalPosition.x" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalPosition.y" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalPosition.z" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.x" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.y" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.z" }, new[] { 0f, 0f });
reset.Add(new[] { axe.Key[1], "m_LocalRotation.w" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalScale.x" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalScale.y" }, new[] { 1f, 1f });
reset.Add(new[] { axe.Key[1], "m_LocalScale.z" }, new[] { 1f, 1f });
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Runtime/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ public static AnimationClip CreateClip(string name, Dictionary<string[], float[]
//case "Sources":
// type = typeof( /*VRC CONSTRAINT*/);
// break;
case "m_Sources":
case "m_TranslationOffsets":
case "m_RotationOffsets":
type = typeof(ParentConstraint);
Expand Down

0 comments on commit 2b9f513

Please sign in to comment.