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

AR hit test #4892

Merged
merged 21 commits into from
Aug 24, 2021
Merged

AR hit test #4892

merged 21 commits into from
Aug 24, 2021

Conversation

AdaRoseCannon
Copy link
Contributor

Description:

Add support for hit-test for Augmented Reality headsets and handsets. I haven't been able to test on real headset hardware so please test there if you can, it should work but I've only tested in an emulator.

This is dependent on #4890 to be merged first here is a link to the comparison between the branches:

https://github.com/AdaRoseCannon/aframe/compare/background-lighting-estimation...AdaRoseCannon:ar-hit-test?expand=1

Changes proposed:

  • Add a new ar-hit-test component.

Additionally, if you want, I could add support for letting it do hit-testing in VR by doing raytracing against the scene to allow developers to build a uniform AR/VR experience but I am not sure how you'd feel about that.

@AdaRoseCannon AdaRoseCannon changed the title Ar hit test AR hit test Jul 27, 2021
@AdaRoseCannon AdaRoseCannon mentioned this pull request Jul 27, 2021
10 tasks
@dmarcos
Copy link
Member

dmarcos commented Jul 28, 2021

Awesome thanks! Once we merge #4890 I look into this.

@dmarcos
Copy link
Member

dmarcos commented Jul 29, 2021

I merged #4890. I think this needs a rebase.

@dmarcos
Copy link
Member

dmarcos commented Jul 30, 2021

We should replace the existing ar-hit-test component of the model viewer example with the new one

@AdaRoseCannon
Copy link
Contributor Author

AdaRoseCannon commented Jul 30, 2021

Note to self: test how well the reticle auto-sizing works with a really off centre model.

As expected it broke, this has now been fixed

@AdaRoseCannon
Copy link
Contributor Author

Note to self: Add anchor support

@AdaRoseCannon
Copy link
Contributor Author

AdaRoseCannon commented Aug 4, 2021

Note to self: See if the hit-test bbox calculations can be leveraged to reposition the directional light in the helper
Note: directional light can't be re positioned but maybe I could update the orthogonal camera settings.

@AdaRoseCannon
Copy link
Contributor Author

AdaRoseCannon commented Aug 4, 2021

The reticle texture is now automatically generated from the model being moved it only renders the texture when the model is changed

Here is a video of it in action: https://twitter.com/AdaRoseCannon/status/1422986340178747404

Needs:

  • Cleaning up
  • Options for whether to do this behaviour
  • Controls for how much of the model to use

@AdaRoseCannon
Copy link
Contributor Author

Anchors are working well, I have found an issue with the Spinosaurus Demo where the rotation of the model is not preserved so the feet of the dinosaur don't match footprints going to identify next

@AdaRoseCannon
Copy link
Contributor Author

The issue was that the camera was rotated by 90 degrees which wasn't visible for my other model because it had 90 degrees rotational symmetry!

The issue is fixed now: https://twitter.com/AdaRoseCannon/status/1425051509679661058

@AdaRoseCannon
Copy link
Contributor Author

I just updated the model-viewer example it works well.

@AdaRoseCannon
Copy link
Contributor Author

Because of the nested objects to support the rotation it wasn't generating the model footprints well so I set it to use the image version instead.

@dmarcos
Copy link
Member

dmarcos commented Aug 11, 2021

It might need rebase. I think I see commits from previous PR

@AdaRoseCannon
Copy link
Contributor Author

Rebased.


[hit-test]: https://immersive-web.github.io/hit-test/

This component uses the WebXR hit-test API to position virtual objects in the real world. Remember to request the `hit-test` optional feature to allow it work.
Copy link
Member

Choose a reason for hiding this comment

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

Can we perhaps automate this? The ar-hit-test component adds hit-test to WebXR/optionalFeatures?

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 I was thinking that but no other components do it.

If we do this then I think also:

  • webxr should add DOM-Overlay if required
  • background should add lighting-estimation
  • this should also add anchors as well as hit-test

is that okay to do in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think it should work. the init method of ar-hit-test handles the setup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the best way to do this?

var features = new Set(this.el.systems.webxr.data.optionalFeatures);
features.add('hit-test');
features.add('anchors');
this.el.setAttribute('webxr', 'optionalFeatures', Array.from())

Doesn't work, I think Systems don't handle the 3 argument setAttribute like components do.

IS it okay to update this.el.systems.webxr.data.optionalFeatures directly?

Copy link
Member

@dmarcos dmarcos Aug 16, 2021

Choose a reason for hiding this comment

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

I don't love much the API we have know (array typed properties are rare) but you can do.

  var optionalFeaturesArray = sceneEl.getAttribute('webxr').optionalFeatures;
  optionalFeaturesArray.push('hit-test');
  sceneEl.setAttribute('webxr', {optionalFeatures: optionalFeaturesArray});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And that won't set the Overlay element and required features to null right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was setting the OverlayElement to null so I did the following to ensure all the settings were preserved.

    // Update WebXR to support light-estimation
    var webxrData = this.el.getAttribute('webxr');
    var optionalFeaturesArray = webxrData.optionalFeatures;
    if (!optionalFeaturesArray.includes('light-estimation')) {
      optionalFeaturesArray.push('light-estimation');
      this.el.setAttribute('webxr', webxrData);
    }

if (hitTest.createAnchor) {
hitTest.createAnchor()
.then(function (anchor) {
anchorToObject3D.set(anchor, options);
Copy link
Member

@dmarcos dmarcos Aug 11, 2021

Choose a reason for hiding this comment

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

Is better to use a map vs. a regular object here? object3D has an id that could be used as object key. I don't have much experience working with Maps so I could be talking non sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're already using Maps and they make more semantic sense in this case since it is how they are supposed to be used.

tempVec3.copy(offset);
tempQuaternion.copy(pose.transform.orientation);
tempVec3.applyQuaternion(tempQuaternion);
object3D.position.sub(tempVec3);
Copy link
Member

Choose a reason for hiding this comment

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

Is sub more clear than add in this context? I usually associate offset with addition but don't fully understand yet the full context here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah i'm not adding an additional offset.

At the beginning I calculate the offset the object's position versus the center of the calculated reticle.
I subtract this offset when the user places the object so that it lines up optically with the reticle

@dmarcos
Copy link
Member

dmarcos commented Aug 11, 2021

Looking good 👍 Left a few comments. Thanks so much

@AdaRoseCannon
Copy link
Contributor Author

Thanks for the feedback, i'll fix most of those and left comments for the ones I think should stay.

I am on holiday for the next few days so i'll update the PR with fixes on Monday.

@AdaRoseCannon
Copy link
Contributor Author

Addressed all other comments, just need feedback on this one regarding the best way to update the webxr system.

@AdaRoseCannon
Copy link
Contributor Author

WebXR system now updates OptionalDependencies automatically which is a lot more convenient to users and something which has caught me out many times before.

@dmarcos
Copy link
Member

dmarcos commented Aug 22, 2021

@AdaRoseCannon Thanks for the patience. Code looks good. I don't have an Android / AR phone to test at the moment. Is this ready to go?

@AdaRoseCannon
Copy link
Contributor Author

I think so, I am currently writing a more advanced demo using it thoroughly which will hopefully unearth anything weird but I think it's fine

@AdaRoseCannon
Copy link
Contributor Author

Found some issues regarding dynamically changing ar-hit-test.target fixing now

@AdaRoseCannon
Copy link
Contributor Author

It doesn't handle the case very well where the object you are trying to position is inside another object which has scale. I'll look into fixing it but it might be too flaky and might be easier to tell people to just not do that.

@dmarcos
Copy link
Member

dmarcos commented Aug 24, 2021

Thanks so much! This is awesome. Love the work and patience with me 😄

@dmarcos dmarcos merged commit fdf6f62 into aframevr:master Aug 24, 2021
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.

2 participants