Skip to content

Conversation

@jloehr
Copy link
Contributor

@jloehr jloehr commented Apr 7, 2022

Overview

As described in the issue, when touching a volume, a long distance raycast through the entire scene was used for the poke pointer. This long distance raycast was often hitting other colliders in more packed scenes or certain set-ups.

This change introduces proper penetration distance calculation for touched NearInteractionTouchableVolume. This in turn allows for more narrow raycasting, raising the chance of hitting the correct object in the scene.

With the correct distance to the surface of a touched volume, we can also now properly sort touched volumes, resolving intersecting and nested touchable volumes.

Video of the fix in action:

Unity_qAXjDIhoom.mp4

Changes

Verification

This optional section is a place where you can detail the specific type of verification
you want from reviewers. For example, if you want reviewers to checkout the PR locally
and validate the functionality of specific scenarios, provide instructions
on the specific scenarios and what you want verified.

If there are specific areas of concern or question feel free to highlight them here so
that reviewers can watch out for those issues.

As a reviewer, it is possible to check out this change locally by using the following
commands (substituting {PR_ID} with the ID of this pull request):

git fetch origin pull/{PR_ID}/head:name_of_local_branch

git checkout name_of_local_branch

Julian Löhr added 3 commits April 7, 2022 14:24
For packed scenes the huge ray range used for Touchable volumes, regularly hits arbitrary colliders in the scene, instead of the actual touched object. Touchable volumes will now properly calculate the penetration distance into the object. Further PokePointer ray has been adjusted to only cast through the very touchable volume.
@keveleigh
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@david-c-kline david-c-kline requested a review from RogPodge May 3, 2022 20:34
Copy link
Contributor

@RogPodge RogPodge left a comment

Choose a reason for hiding this comment

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

Initial check seems good. I need some time to try it out myself and investigate if there's a way to do this without the additional performance hit of another raycast.

@jloehr do you have time to revisit this? Otherwise, do I have permission to clone and implement any changes that might be required? I really appreciate you contributing this valuable fix (and including unit tests!!)

// Return value less than zero so that when poke pointer is inside object, it will not raise a touch up event.
float rayScale = 1.1f;
Vector3 outsidePoint = TouchableCollider.bounds.center + normal * (TouchableCollider.bounds.extents.magnitude * rayScale);
if (TouchableCollider.Raycast(new Ray(outsidePoint, -normal), out RaycastHit raycastHit, TouchableCollider.bounds.size.magnitude * rayScale))
Copy link
Contributor

Choose a reason for hiding this comment

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

I have some concerns about performing a raycast everything this calculation is done. Is there a way to calculate the distance using the existing normal vector?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to search for other ways, but didn't find any.
TouchableCollider ususally is a BoxCollider, but can also be any arbitrary collider including a complex mesh collider. So doing any math based upon that assumption basically resolves to a raycast.
Also keep in mind, this raycast is only executed if we're already touching a volume and only for volumes we're touching. Further it's NOT a Physics.Raycast but a Collider.Raycast which is only considering the given collider. Therefore should be hopefully cheap (especially if its a primitive collider).

@jloehr
Copy link
Contributor Author

jloehr commented May 4, 2022

@RogPodge I do have some spare time to revisit this, so hit me up with suggestions.

@RogPodge
Copy link
Contributor

RogPodge commented May 4, 2022

@RogPodge I do have some spare time to revisit this, so hit me up with suggestions.

Thanks! Can you address the first PR comment I left? I'll add more as I get chances to dig through the PR.

@RogPodge
Copy link
Contributor

RogPodge commented May 4, 2022

Also a heads up, can you retarget this to https://github.com/microsoft/MixedRealityToolkit-Unity/tree/prerelease/2.8.0, since we're going to be cutting a release soon and would really like to get this in!

@jloehr
Copy link
Contributor Author

jloehr commented May 5, 2022

Also a heads up, can you retarget this to https://github.com/microsoft/MixedRealityToolkit-Unity/tree/prerelease/2.8.0, since we're going to be cutting a release soon and would really like to get this in!

You mean, retargeting this PR to merge into the 2.8.0 prelease branch, right?

@RogPodge
Copy link
Contributor

RogPodge commented May 5, 2022

Yep!

@jloehr jloehr changed the base branch from main to prerelease/2.8.0 May 6, 2022 07:12
@jloehr
Copy link
Contributor Author

jloehr commented May 6, 2022

Also a heads up, can you retarget this to https://github.com/microsoft/MixedRealityToolkit-Unity/tree/prerelease/2.8.0, since we're going to be cutting a release soon and would really like to get this in!

Done! Surprisingly no merge conflicts and tests are still fine on my local system.

@RogPodge
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@RogPodge RogPodge merged commit ce987fe into microsoft:prerelease/2.8.0 May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PokePointer and TouchableVolumes not working reliable in packed scenes

3 participants