Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[June18] App bar positioning bug fix #2042 #2212

Merged
merged 9 commits into from
Jun 1, 2018
104 changes: 69 additions & 35 deletions Assets/HoloToolkit-Examples/UX/Scenes/BoundingBoxGizmoExample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.50217825, g: 0.5020953, b: 0.5018046, a: 1}
m_IndirectSpecularColor: {r: 0.50224054, g: 0.5020953, b: 0.501867, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -420,6 +420,24 @@ Transform:
m_PrefabParentObject: {fileID: 4000010330146594, guid: bfdc7f60d7205c84f82a4806a5352d60,
type: 2}
m_PrefabInternal: {fileID: 116723879}
--- !u!1 &170656240 stripped
GameObject:
m_PrefabParentObject: {fileID: 100004, guid: 1e23ec24c22068b4cbf47737c35e277b, type: 3}
m_PrefabInternal: {fileID: 1197191672}
--- !u!64 &170656244
MeshCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 170656240}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 4300000, guid: 1e23ec24c22068b4cbf47737c35e277b, type: 3}
--- !u!1 &503309311
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -950,6 +968,24 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &1191689814 stripped
GameObject:
m_PrefabParentObject: {fileID: 100004, guid: 284d5c2c421022e4f9056fb0a21ff91c, type: 3}
m_PrefabInternal: {fileID: 1222626213}
--- !u!64 &1191689818
MeshCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1191689814}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 1
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 4300000, guid: 284d5c2c421022e4f9056fb0a21ff91c, type: 3}
--- !u!1001 &1197191672
Prefab:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1037,27 +1073,14 @@ MonoBehaviour:
type: 2}
interactingMaterial: {fileID: 2100000, guid: b614a09bc429623478e946d8170b15ae, type: 2}
scaleRate: 4
appBarHoverOffsetZ: 0.05
maxScale: 2
rotationType: 0
handMotionToRotate: 1
boundingBoxPrefab: {fileID: 114030465538688920, guid: 865a8ded6c47efd4285f04f3aebe99e9,
type: 2}
appBarPrefab: {fileID: 114050950401502068, guid: aa610ada334bff640a535f0d23a9a15c,
type: 2}
--- !u!64 &1197191676
MeshCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1197191674}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 4300000, guid: 1e23ec24c22068b4cbf47737c35e277b, type: 3}
--- !u!1001 &1222626213
Prefab:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1145,27 +1168,14 @@ MonoBehaviour:
type: 2}
interactingMaterial: {fileID: 2100000, guid: b614a09bc429623478e946d8170b15ae, type: 2}
scaleRate: 4
appBarHoverOffsetZ: 0.05
maxScale: 2
rotationType: 0
handMotionToRotate: 1
boundingBoxPrefab: {fileID: 114030465538688920, guid: 865a8ded6c47efd4285f04f3aebe99e9,
type: 2}
appBarPrefab: {fileID: 114050950401502068, guid: aa610ada334bff640a535f0d23a9a15c,
type: 2}
--- !u!64 &1222626217
MeshCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1222626215}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 4300000, guid: 284d5c2c421022e4f9056fb0a21ff91c, type: 3}
--- !u!114 &1222626218
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1545,8 +1555,8 @@ CanvasRenderer:
GameObject:
m_PrefabParentObject: {fileID: 100004, guid: aa39033344b08ce4bab10cc11dc6d6b8, type: 3}
m_PrefabInternal: {fileID: 1575359649}
--- !u!64 &1423768206
MeshCollider:
--- !u!65 &1423768206
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
Expand All @@ -1555,10 +1565,8 @@ MeshCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 4300000, guid: aa39033344b08ce4bab10cc11dc6d6b8, type: 3}
m_Size: {x: 2.5053554, y: 2.1822224, z: 1.9755292}
m_Center: {x: 0.26491338, y: 1.1037669, z: -0.00000014901163}
--- !u!1 &1428215743 stripped
GameObject:
m_PrefabParentObject: {fileID: 100002, guid: aa39033344b08ce4bab10cc11dc6d6b8, type: 3}
Expand All @@ -1584,6 +1592,7 @@ MonoBehaviour:
type: 2}
interactingMaterial: {fileID: 2100000, guid: b614a09bc429623478e946d8170b15ae, type: 2}
scaleRate: 4
appBarHoverOffsetZ: 0.05
maxScale: 2
rotationType: 0
handMotionToRotate: 1
Expand Down Expand Up @@ -1849,6 +1858,14 @@ Prefab:
propertyPath: m_LocalPosition.y
value: -0.007
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: aa39033344b08ce4bab10cc11dc6d6b8, type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 400004, guid: aa39033344b08ce4bab10cc11dc6d6b8, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: aa39033344b08ce4bab10cc11dc6d6b8, type: 3}
m_IsPrefabParent: 0
Expand Down Expand Up @@ -1977,6 +1994,7 @@ MonoBehaviour:
type: 2}
interactingMaterial: {fileID: 2100000, guid: b614a09bc429623478e946d8170b15ae, type: 2}
scaleRate: 4
appBarHoverOffsetZ: 0.05
maxScale: 2
rotationType: 0
handMotionToRotate: 1
Expand Down Expand Up @@ -2078,6 +2096,22 @@ CanvasRenderer:
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1722965370}
--- !u!1 &1859408062 stripped
GameObject:
m_PrefabParentObject: {fileID: 100000, guid: aa39033344b08ce4bab10cc11dc6d6b8, type: 3}
m_PrefabInternal: {fileID: 1575359649}
--- !u!65 &1859408066
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1859408062}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1.7544937, y: 0.08, z: 1.7544943}
m_Center: {x: 0, y: -0.0000004379902, z: 0}
--- !u!1 &1946117762
GameObject:
m_ObjectHideFlags: 0
Expand Down
83 changes: 53 additions & 30 deletions Assets/HoloToolkit/UX/Scripts/AppBar/AppBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public class AppBar : InteractionReceiver
/// </summary>
public float HoverOffsetZ = 0f;

private bool useTightFollow = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing tooltip with summary description.


/// <summary>
/// Uses an alternate follow style that works better for very oblong objects
/// </summary>
public bool UseTightFollow
{
get
{
return useTightFollow;
}

set
{
useTightFollow = value;
}
}

/// <summary>
/// Class used for building toolbar buttons
/// (not yet in use)
Expand Down Expand Up @@ -108,6 +126,24 @@ public BoundingBox BoundingBox
}
}

private BoundingBoxRig boundingRig;

/// <summary>
/// a reference to the boundingBoxRig that the appbar turns on and off
/// </summary>
public BoundingBoxRig BoundingRig
{
get
{
return boundingRig;
}

set
{
boundingRig = value;
}
}

public GameObject SquareButtonPrefab;

public int NumDefaultButtons
Expand Down Expand Up @@ -151,6 +187,7 @@ public ButtonTemplate[] DefaultButtons
}

public AppBarDisplayTypeEnum DisplayType = AppBarDisplayTypeEnum.Manipulation;

public AppBarStateEnum State = AppBarStateEnum.Default;

/// <summary>
Expand Down Expand Up @@ -182,6 +219,7 @@ public ButtonTemplate[] DefaultButtons
private int numDefaultButtons;
private int numHiddenButtons;
private int numManipulationButtons;
private BoundingBoxHelper helper;

public void Reset()
{
Expand All @@ -193,6 +231,7 @@ public void Reset()
public void Start()
{
State = AppBarStateEnum.Default;

if (interactables.Count == 0)
{
RefreshTemplates();
Expand All @@ -206,6 +245,8 @@ public void Start()
CreateButton(buttons[i], CustomButtonIconProfile);
}
}

helper = new BoundingBoxHelper();
}

protected override void InputClicked(GameObject obj, InputClickedEventData eventData)
Expand Down Expand Up @@ -320,43 +361,25 @@ private void FollowBoundingBox(bool smooth)
}

// Show our buttons
baseRenderer.SetActive(true);

// Get positions for each side of the bounding box
// Choose the one that's closest to us
forwards[0] = boundingBox.transform.forward;
forwards[1] = boundingBox.transform.right;
forwards[2] = -boundingBox.transform.forward;
forwards[3] = -boundingBox.transform.right;
Vector3 scale = boundingBox.TargetBoundsLocalScale;
float maxXYScale = Mathf.Max(scale.x, scale.y);
float closestSoFar = Mathf.Infinity;
baseRenderer.SetActive(true);

//calculate best follow position for AppBar
Vector3 finalPosition = Vector3.zero;
Vector3 finalForward = Vector3.zero;
Vector3 headPosition = Camera.main.transform.position;

for (int i = 0; i < forwards.Length; i++)
LayerMask ignoreLayers = new LayerMask();
List<Vector3> boundsPoints = new List<Vector3>();
if (boundingBox != null)
{
Vector3 nextPosition = boundingBox.transform.position +
(forwards[i] * -maxXYScale) +
(Vector3.up * (-scale.y * HoverOffsetYScale));
helper.UpdateNonAABoundingBoxCornerPositions(boundingBox.Target, boundsPoints, ignoreLayers);
int followingFaceIndex = helper.GetIndexOfForwardFace(headPosition);
Vector3 faceNormal = helper.GetFaceNormal(followingFaceIndex);

float distance = Vector3.Distance(nextPosition, headPosition);
if (distance < closestSoFar)
{
closestSoFar = distance;
finalPosition = nextPosition;
finalForward = forwards[i];
}
//finally we have new position
finalPosition = helper.GetFaceBottomCentroid(followingFaceIndex) + (faceNormal * HoverOffsetZ);
}

// Apply hover offset
finalPosition += (finalForward * -HoverOffsetZ);

// Follow our bounding box
transform.position = smooth ?
Vector3.Lerp(transform.position, finalPosition, 0.5f) :
finalPosition;
transform.position = smooth ? Vector3.Lerp(transform.position, finalPosition, 0.5f) : finalPosition;

// Rotate on the y axis
Vector3 eulerAngles = Quaternion.LookRotation((boundingBox.transform.position - finalPosition).normalized, Vector3.up).eulerAngles;
Expand Down
33 changes: 33 additions & 0 deletions Assets/HoloToolkit/UX/Scripts/BoundingBoxes/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,19 @@ public static void GetRenderBoundsPoints(GameObject target, List<Vector3> bounds
}
}

public static Bounds GetRenderBounds(GameObject target)
{
Bounds bounds = new Bounds();
Renderer[] renderers = target.GetComponentsInChildren<Renderer>();
for (int i = 0; i < renderers.Length; ++i)
{
var rendererObj = renderers[i];
bounds.ExpandToContain(rendererObj.bounds);
}

return bounds;
}

/// <summary>
/// GetMeshFilterBoundsPoints - gets boundingbox points using MeshFilter method.
/// </summary>
Expand Down Expand Up @@ -601,6 +614,26 @@ public static void GetMeshFilterBoundsPoints(GameObject target, List<Vector3> bo
}
}

public static void GetNonAxisAlignedBB_Corners(GameObject target, List<Vector3> boundsPoints)
{
LayerMask mask = new LayerMask();

GameObject clone = GameObject.Instantiate(target);
clone.transform.localRotation = Quaternion.identity;
clone.transform.position = Vector3.zero;
clone.transform.localScale = Vector3.one;
BoundingBox.GetMeshFilterBoundsPoints(clone, boundsPoints, mask);
Vector3 centroid = target.transform.position;
GameObject.Destroy(clone);

#if UNITY_2017_1_OR_NEWER
for (int i = 0; i < boundsPoints.Count; ++i)
{
boundsPoints[i] = target.transform.localToWorldMatrix.MultiplyPoint(boundsPoints[i]);
}
#endif // UNITY_2017_1_OR_NEWER
}

private static Vector3[] corners = null;
private static Vector3[] rectTransformCorners = new Vector3[4];
#endregion
Expand Down
Loading