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
Merged

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

merged 9 commits into from
Jun 1, 2018

Conversation

johnppella
Copy link
Contributor

Overview
This PR addresses Issue #2042
"Bounding Box and App Bar not working as expected for Rectangular Holograms"
The fix causes the appbar to move to a cleaner location on objects that are very long in one dimension.

Changes
The non-axis-aligned bounding box (NAABB) helper functions are now broken out into a separate file: BoundingBoxHelper.cs.

This script contains a function to update the location of the appbar in its Update() loop:
GetNonAABoundingBoxCornerPositions()
This function finds the face of the non-axis aligned bounding cube of an object that is facing a target point. (this point is the headPosition in the example scene.)

This script also contains a static function which finds the same info if it is only needed once.
Included are additional helper functions for getting the edges of a face of the NAABB, the centroid of a face, the midpoint of the edges, the bottom of a face etc.

the Serialized Field AppBarHoverOffsetZ is now exposed at design time to allow the user to set a distance along the face normal that the appbar sits offset from the actual face.

  • Fixes: # 2042

/// <summary>
/// Uses an alternate follow style that works better for very oblong objects
/// </summary>
public 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.

should probably be a property

@@ -108,6 +113,8 @@ public BoundingBox BoundingBox
}
}

public BoundingBoxRig BoundingRig;
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

@david-c-kline david-c-kline changed the base branch from master to june18_dev May 30, 2018 18:14
@cre8ivepark cre8ivepark changed the title Master app bar fix [June18] App bar positioning bug fix #2042 May 31, 2018
@johnppella
Copy link
Contributor Author

changed the two public variables to Properties

@@ -150,6 +186,8 @@ public ButtonTemplate[] DefaultButtons
}
}



Copy link
Contributor

Choose a reason for hiding this comment

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

extra lines?

GameObject clone = GameObject.Instantiate(target);
clone.transform.localRotation = Quaternion.identity;
clone.transform.position = Vector3.zero;
clone.transform.localScale = new Vector3(1,1,1);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: vector3.one

@johnppella
Copy link
Contributor Author

2 more changes- extra space and static call

for (int i = 0; i < boundsPoints.Count; ++i)
{
boundsPoints[i] = target.transform.localToWorldMatrix.MultiplyPoint(boundsPoints[i]);
//boundsPoints[i] += centroid;
Copy link
Contributor

Choose a reason for hiding this comment

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

will we use this later?

GameObject clone = GameObject.Instantiate(targetObject);
clone.transform.localRotation = Quaternion.identity;
clone.transform.position = Vector3.zero;
clone.transform.localScale = new Vector3(1, 1, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit Vector3.one

switch (index)
{
case 0:
return new int[] { 0, 1, 3, 2 };
Copy link
Contributor

Choose a reason for hiding this comment

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

we could make these readonly fields so we don't have to allocate new arrays each time.

return new int[] { 1, 0, 4, 5};
}

return new int[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

public Vector3[] GetFaceEdgeMidpoints(int index)
{
Vector3[] corners = GetFaceCorners(index);
Vector3[] midpoints = new Vector3[4];
Copy link
Contributor

Choose a reason for hiding this comment

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

this could also be a readonly field if we're only ever updating the same 4 array values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corners and midpoints will always have unique values.

return face;
}

return new Vector3[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

could be a cached readonly array

float hightestDotValue = float.MinValue;
for (int i = 0; i < 6; ++i)
{
Vector3 a = (lookAtPoint - GetFaceCentroid(i) ).normalized;
Copy link
Contributor

Choose a reason for hiding this comment

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

some strange formatting on this line.

GameObject clone = GameObject.Instantiate(target);
clone.transform.localRotation = Quaternion.identity;
clone.transform.position = Vector3.zero;
clone.transform.localScale = new Vector3(1, 1, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: vector3.one

/// <param name="target">The gameObject whose bounding box is desired</param>
/// <param name="boundsPoints">the array of 8 points that will be filled</param>
/// <param name="ignoreLayers">a LayerMask variable</param>
public static void GetNonAABoundingBoxCornerPositions(GameObject target, List<Vector3> boundsPoints, LayerMask ignoreLayers)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we have a lot of duplicated code that does almost identical things.

Could consolidate these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes- great idea! both the main functions can share a new static function that does the bulk of the calculations.

Copy link
Contributor

@StephenHodgson StephenHodgson left a comment

Choose a reason for hiding this comment

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

see comments

@johnppella
Copy link
Contributor Author

pushed more changes- including moving duplicated code into static function

Copy link
Contributor

@StephenHodgson StephenHodgson left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for submitting.

@david-c-kline david-c-kline merged commit b363d10 into microsoft:june18_dev Jun 1, 2018
/// The dynamic functions can be used to obtain boundingcube info on an object's Update loop. Operations
/// are minimized in the dynamic use scenario.
/// </summary>
public class BoundingBoxHelper : MonoBehaviour
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a MonoBehaviour? Its only use is with the 'new' keyword, which causes a Unity warning.

image

@@ -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.

/// The dynamic functions can be used to obtain boundingcube info on an object's Update loop. Operations
/// are minimized in the dynamic use scenario.
/// </summary>
public class BoundingBoxHelper : MonoBehaviour
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this class in a namespace?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's also in Utilities, while the rest of bounding box is in UX.

Choose a reason for hiding this comment

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

This was merged a month ago.... Please open a new issue so we can track the needed change(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants