Mixedrealitytoolkit-unity: Bounding Box and App Bar not working as expected for Rectangular Holograms

Created on 3 May 2018  路  19Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Overview

The Bounding box for hololens works very well for squared holograms like a chair, cube, small toy but for something like truck which length is very large compared to it's breadth, the app bar is far away from the hologram, as it takes the maximum scale side as start.
When Scaling up or scaling down the truck, the app bar goes in to the truck when scaled town very small, and moves very far from hologram when scaled up.
It would be really helpful if i get a solution for this quick, I'm short on time, please respond quickly, Thank you!

Expected Behavior

When Scaling up or down a hologram , the app bar should adjust according to that so that the bar doesn't goes in to hologram or don't more far way.

Actual Behavior

when the Bounding box Rig is attached to hologram which is of rectangular shape like a big truck, while scaling up or down or while rotating the hologram with sphere handles, the app bar gets into hologram or moves too far away from hologram

Steps to reproduce

Import a truck like model which is of rectangular shape whose length is relatively very large to it's breadth , add bounding box rig to it and you can experience the above mentioned issues

Unity Editor Version

Unity2017.2.1f1

Mixed Reality Toolkit Release Version

UX Controls

Most helpful comment

Hello,

I faced the same problem recently and i fixed it in the AppBar.cs script.

You need to change a few things in the _FollowingBoundingBox_ function.

First of all, i normalized each forwards vector.
forwards[0] = boundingBox.transform.forward.normalized;

Then in the for loop, you don't want to use the _MaxScaleXY_ value for two reasons:

  • Y axis is the height here, what we want is the 'Z' scale, corresponding to the forward axis of the bounding box.
  • We only need half of this value, because (in my case at least) the BoundingBox.transform.position is at the center of our object.

My fix is below, it's a quick fix, that probably required enhancement :

for (int i = 0; i < forwards.Length; i++)
            {
                Vector3 nextPosition = boundingBox.transform.position +
                (forwards[i] * ((i %2 == 0)?-scale.z/2.0f : -scale.x / 2.0f)) +
                (Vector3.up * (-scale.y * HoverOffsetYScale));

                float distance = Vector3.Distance(nextPosition, headPosition);
                if (distance < closestSoFar)
                {
                    closestSoFar = distance;
                    finalPosition = nextPosition;
                    finalForward = forwards[i];
                }
            }

Important part is about _maxXYScale_ being replaced by ((i %2 == 0)?-scale.z/2.0f : -scale.x / 2.0f))

This, i believe, solved the issue for me.

_NB:_ I changed a lot of things in my Bounding Box Rig behaviour so i can only rotate object along Y axis and them along XZ plane. This fix may cause trouble if you rotate along X or Z.

All 19 comments

I have the same problem. I use a regular gameobject and, if it is longer than usual, the AppBar goes to inside of my gameobject, that is, inside of the bounding box. Is there already some approach for this problem?

Thanks.

One thing you can do to get over that is, through a custom script through which based on Object's Y rotation, you can change the APP bar's Z offset so that the App Bar doesn't go into or far away from Game object......I'm sure there will be more stable fix to this which i guess would be updated shortly....!

Yeah! I am creating a script to fix the problem. The reason for which I wrote to this post was because I hoped that there would be an easier solution for this problem.

Thank you for your prompt reply.

Even with that custom script, one issue you may encounter is, even though you are changing z offset based on object's rotation, the app bar may goes into weird position or disappear when the user starts to rotate around the hologram, as the original system changes the app bar orientation even on user's head movement and head orientation angle,

Sorry for the late reply. Unfortunately I cannot create a custom class. I create a GameObject dynamically and when it is displayed in my scene, the AppBar is created with it. AppBar takes some seconds to be created and, when it is displayed in the scene, it goes to inside of my object. Therefore, I need to spend that time so that I can calculate the distance between the initial point of my GameObject and AppBar.

I know that I can calculate that distance and set the Z offset so that the AppBar goes to outside of my GameObject. However, it is not real, that is, I would like that the Z offset of the AppBar could be calculated before it is created with my GameObject, but it is not possible because I would not know the distance. For that reason, I am waiting for the problem to be solved.

@johnppella is looking into this. Thanks!

@Cris21395 If that's the problem, the possible solution would be to enter into the play mode and manually adjust the Zoffset in Appbar in inspector until the App bar come out of the gameobject and note down the zoffset value and exit from play mode and entering the noted down Zoffset value to Appbar Prefab in Project Folder, so next time the object's gets instantiated, the app bar should be appearing fine

You are right, but I cannot do that. Due to the fact that I create holograms dynamically, they can have a different length so this solution does not solve my problem.

Thanks anyway.

OK, if you creating a lot of them, then that's definitely a problem, but if you are dealing with a bunch of holograms , you could just duplicate the AppBar prefabs with corresponding App Bar assigned to holograms.

Hello,

I faced the same problem recently and i fixed it in the AppBar.cs script.

You need to change a few things in the _FollowingBoundingBox_ function.

First of all, i normalized each forwards vector.
forwards[0] = boundingBox.transform.forward.normalized;

Then in the for loop, you don't want to use the _MaxScaleXY_ value for two reasons:

  • Y axis is the height here, what we want is the 'Z' scale, corresponding to the forward axis of the bounding box.
  • We only need half of this value, because (in my case at least) the BoundingBox.transform.position is at the center of our object.

My fix is below, it's a quick fix, that probably required enhancement :

for (int i = 0; i < forwards.Length; i++)
            {
                Vector3 nextPosition = boundingBox.transform.position +
                (forwards[i] * ((i %2 == 0)?-scale.z/2.0f : -scale.x / 2.0f)) +
                (Vector3.up * (-scale.y * HoverOffsetYScale));

                float distance = Vector3.Distance(nextPosition, headPosition);
                if (distance < closestSoFar)
                {
                    closestSoFar = distance;
                    finalPosition = nextPosition;
                    finalForward = forwards[i];
                }
            }

Important part is about _maxXYScale_ being replaced by ((i %2 == 0)?-scale.z/2.0f : -scale.x / 2.0f))

This, i believe, solved the issue for me.

_NB:_ I changed a lot of things in my Bounding Box Rig behaviour so i can only rotate object along Y axis and them along XZ plane. This fix may cause trouble if you rotate along X or Z.

Thank you so much!! It worked for me. I tried to solve the problem with a different script because I did not want to change the the AppBar.cs, but it was very hard since you cannot access to some important variables. Also, thanks for the explanation; you have explained it very clear.

I tried to use this fix (#2042) in my project.

It seems I can't scale an object with the appbar moving along when the mesh is chlidren of the BoundingBoxRig anymore.

Project 1 :
I have the old BoundingBoxRig on an object named "Model_Icosa". I am scaling the children "Platonic".

oldbbchild

This is the result :

oldbb

Project 2 : I have the fixed BoundingBoxRig on an object named "GameObject". I am scaling the children "Cube".

newbbchild

this is the result :

newbb

It seems the new BoundingBoxRig does not take children in account. Am I right ?

I change the function AddAABoundingBoxes in BoundingBoxHelper to this :

    /// <summary>
    /// This function expands the box defined by the first param 'points' to include the second bounding box 'pointsToAdd'. The
    /// result is found in the points variable.
    /// </summary>
    /// <param name="points">the boudning box points representing box A</param>
    /// <param name="pointsToAdd">the bounding box points representing box B</param>
    public static void AddAABoundingBoxes(List<Vector3> points, Vector3[] pointsToAdd)
    {
        if (points.Count < 8)
        {
            points.Clear();
            points.AddRange(pointsToAdd);
            return;
        }
        for (int i = 0; i < pointsToAdd.Length; ++i)
        {
            if (pointsToAdd[i].x < points[0].x)
            {
                points[0] = new Vector3(pointsToAdd[i].x, points[0].y, points[0].z);
                points[1] = new Vector3(pointsToAdd[i].x, points[1].y, points[1].z);
                points[2] = new Vector3(pointsToAdd[i].x, points[2].y, points[2].z);
                points[3] = new Vector3(pointsToAdd[i].x, points[3].y, points[3].z);
            }
            if (pointsToAdd[i].x > points[4].x)
            {
                points[4] = new Vector3(pointsToAdd[i].x, points[4].y, points[4].z);
                points[5] = new Vector3(pointsToAdd[i].x, points[5].y, points[5].z);
                points[6] = new Vector3(pointsToAdd[i].x, points[6].y, points[6].z);
                points[7] = new Vector3(pointsToAdd[i].x, points[7].y, points[7].z);
            }
            if (pointsToAdd[i].y < points[0].y)
            {
                points[0] = new Vector3(points[0].x, pointsToAdd[i].y, points[0].z);
                points[1] = new Vector3(points[1].x, pointsToAdd[i].y, points[1].z);
                points[4] = new Vector3(points[4].x, pointsToAdd[i].y, points[4].z);
                points[5] = new Vector3(points[5].x, pointsToAdd[i].y, points[5].z);
            }
            if (pointsToAdd[i].y > points[2].y)
            {
                points[2] = new Vector3(points[2].x, pointsToAdd[i].y, points[2].z);
                points[3] = new Vector3(points[3].x, pointsToAdd[i].y, points[3].z);
                points[6] = new Vector3(points[6].x, pointsToAdd[i].y, points[6].z);
                points[7] = new Vector3(points[7].x, pointsToAdd[i].y, points[7].z);
            }
            if (pointsToAdd[i].z < points[0].z)
            {
                points[0] = new Vector3(points[0].x, points[0].y, pointsToAdd[i].z);
                points[2] = new Vector3(points[2].x, points[2].y, pointsToAdd[i].z);
                points[6] = new Vector3(points[6].x, points[6].y, pointsToAdd[i].z);
                points[4] = new Vector3(points[4].x, points[4].y, pointsToAdd[i].z);
            }
            if (pointsToAdd[i].z > points[1].z)
            {
                points[1] = new Vector3(points[1].x, points[1].y, pointsToAdd[i].z);
                points[5] = new Vector3(points[5].x, points[5].y, pointsToAdd[i].z);
                points[7] = new Vector3(points[7].x, points[7].y, pointsToAdd[i].z);
                points[3] = new Vector3(points[3].x, points[3].y, pointsToAdd[i].z);
            }
        }
    }

because points[X] wasn't setted correctly when using .Set()

but it does not correct the issue I mentionned earlier

So you merged this even though the BoundingBoxRig does not take children in account ? :open_mouth:

Beside in the merged code, I see that .Set() is still used in the AddAABoundingBoxes function

@ThomasAstrakhan Are you saying the original issue wasn't fixed by #2212? Please reopen if so. Otherwise, if there are new problems, please file new issues.

@keveleigh I think the Bounding Box and App Bar are not working as expected for Rectangular Holograms.

@coolpad007 think the expected behavior is

Expected Behavior
When Scaling up or down a hologram , the app bar should adjust according to that so that the bar doesn't goes in to hologram or don't more far way.

And if you look at my comment ( https://github.com/Microsoft/MixedRealityToolkit-Unity/issues/2042#issuecomment-401012159 ) it doesn't fit the expected behavior.

I can't reopen this issue.

Yesterday I updated my project with 2017.4.1.0 release. The solution for the problem of the AppBar does not work as expected. The movement is not good and it does not rotate aorund the hologram.

I had to use the solution provided by @Cyhzault and make some changes to the script so that the icons appear correctly. As @ThomasAstrakhan said, it would be grate if this issue could be reopened so that the problem can be solved.

@cre8ivepark @johnppella Hello. Is there any news about this issue ?
I mean, the appbar does not follow an object if the object is in children of the target. It's kind of a big issue.

Please upgrade to MRTK v2 as a lot of these are addressed in the updated version.

Was this page helpful?
0 / 5 - 0 ratings