Mixedrealitytoolkit-unity: Bounds Control With Non Uniform Scale Issues

Created on 1 Dec 2020  路  6Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Overview

When using the bounds control with scale configuration set to non uniform the object can have erratically and move in unintuitive ways.

I was able to reproduce this behaviour using the boundscontrols found in the MRTK sample scene just by setting the scale mode to non uniform.

Expected behavior

The object should be moveable on a single axis related to the handle selected.

Actual behavior

The object sometimes seems to move along a completely different axis and moves at inconsistent speeds making it impossible to use.

Steps to reproduce

_(Links to sample github project preferred)_

Unity editor version

2019.4.6f1

Mixed Reality Toolkit release version

2.5

Bug

Most helpful comment

I will test this when I have the opportunity, but looking through the PR I am not sure it will fix the issue. I have found this issue while FlattenAxis is set to 'Do Not Flatten'. It looks like it's related to rotation in some way. Parenting the object under a rotated parent causes the erratic behaviour.

Will report back after testing latest changes though to be sure.

All 6 comments

This should have already been fixed in #8923. Please try out the dev branch and let us know if you are still experiencing the problem.

I will test this when I have the opportunity, but looking through the PR I am not sure it will fix the issue. I have found this issue while FlattenAxis is set to 'Do Not Flatten'. It looks like it's related to rotation in some way. Parenting the object under a rotated parent causes the erratic behaviour.

Will report back after testing latest changes though to be sure.

Tried with dev branch this morning and the problem is still there.

  • Create an empty game object and set it's x rotation to 45
  • Create a cube as a child of the empty object and set it up as a bounds control
  • Set the scale to be non uniform with not axis being flattened
  • Scale behaviour is unstable and broken

I was able to reproduce with Unity 2019.4.15f1 and HoloLens 2 remoting.

After some work today we have come up with something that looks like a solution. Within BoundsControl.TransformTarget(HandleType transformType) we made the following changes:

Vector3 initialDist = (initialGrabPoint - oppositeCorner);
Vector3 currentDist = (currentGrabPoint - oppositeCorner);
becomes
Vector3 initialDist = Target.transform.InverseTransformVector(initialGrabPoint - oppositeCorner);
Vector3 currentDist = Target.transform.InverseTransformVector(currentGrabPoint - oppositeCorner);

and

var originalRelativePosition = initialPositionOnGrabStart - oppositeCorner;
var newPosition = originalRelativePosition.Div(initialScaleOnGrabStart).Mul(Target.transform.localScale) + oppositeCorner;
becomes
Vector3 originalRelativePosition = Target.transform.InverseTransformDirection(initialPositionOnGrabStart - oppositeCorner);
var newPosition = Target.transform.TransformDirection(originalRelativePosition.Mul(scaleFactor)) + oppositeCorner;

Thanks for sharing that with us! I'll take a look as soon as possible and in the meantime please feel free to open a PR for the change.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amfdeluca picture amfdeluca  路  3Comments

StephenHodgson picture StephenHodgson  路  3Comments

DanAndersen picture DanAndersen  路  3Comments

overedge picture overedge  路  3Comments

markgrossnickle picture markgrossnickle  路  3Comments