Skip to content

Commit

Permalink
Option for SpacePin visualizer to put graphics relative to space pins…
Browse files Browse the repository at this point in the history
…, rather than relative to origin. (microsoft#295)
  • Loading branch information
fast-slow-still authored Jun 14, 2022
1 parent b20e15f commit 33016f0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Assets/WorldLocking.Tools/Scripts/SpacePinMeshVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class SpacePinMeshVisualizer : MonoBehaviour
public float verticalOffset = -1.65f;
public float textVerticalOffset = -1.45f;

[Tooltip("Disable this to have SpacePin visualizations appear offset vertically from SpacePin positions.")]
public bool verticalFromOrigin = true;

public Material wireFrameMaterial = null;
public Material meshMaterial = null;
public Material extrapolatedMeshMaterial = null;
Expand Down Expand Up @@ -176,9 +179,12 @@ private Mesh GenerateTriangulationWireFrameMesh()

Array.Copy(originalVertices, 4, vertices, 0, originalVertices.Length - 4);

for (int i = 0; i < vertices.Length; i++)
if (verticalFromOrigin)
{
vertices[i].y = 0.0f;
for (int i = 0; i < vertices.Length; i++)
{
vertices[i].y = 0.0f;
}
}

wholeMesh.vertices = vertices;
Expand Down Expand Up @@ -408,7 +414,10 @@ private void CalculatePinPositionsFromCurrentInterpolant()
currentBoundaryVertexIDx = hasBoundaryVertex ? currentBoundaryVertexIDx : -1;

Vector3 lockedHeadPosition = GetLockedHeadPosition();
lockedHeadPosition.y = 0.0f;
if (verticalFromOrigin)
{
lockedHeadPosition.y = 0.0f;
}

firstPinPosition = currentBoundaryVertexIDx == 0 ? lockedHeadPosition : triangulator.Vertices[currentInterpolant.idx[0] + 4];
secondPinPosition = currentBoundaryVertexIDx == 1 ? lockedHeadPosition : triangulator.Vertices[currentInterpolant.idx[1] + 4];
Expand All @@ -419,7 +428,10 @@ private void CalculatePinPositionsFromCurrentInterpolant()
//secondPinPosition = new Vector3(1.0f, 0.0f, 1.0f);
//thirdPinPosition = new Vector3(-1.0f,0.0f,-1.0f);

firstPinPosition.y = secondPinPosition.y = thirdPinPosition.y = 0.0f;
if (verticalFromOrigin)
{
firstPinPosition.y = secondPinPosition.y = thirdPinPosition.y = 0.0f;
}
}

/// <summary>
Expand Down Expand Up @@ -616,8 +628,9 @@ private void Update()
private void TransformFromLockedToGlobal()
{
Pose globalFromLocked = GetGlobalFromLocked();
globalFromLocked.position += new Vector3(0.0f, verticalOffset, 0.0f);
transform.SetGlobalPose(globalFromLocked);
Pose lockedPose = new Pose(new Vector3(0.0f, verticalOffset, 0.0f), Quaternion.identity);
Pose globalPose = globalFromLocked.Multiply(lockedPose);
transform.SetGlobalPose(globalPose);
}
}
}

0 comments on commit 33016f0

Please sign in to comment.