mozilla / aframe-xr

INACTIVE - http://mzl.la/ghe-archive - System / Components to build WebXR experiences with A-frame
https://mozilla.github.io/aframe-xr/
MIT License
183 stars 36 forks source link

hit-test does not make the position of the added entity instantly available #7

Closed Utopiah closed 2 months ago

Utopiah commented 6 years ago

As briefly discussed with @arturitu , not necessarily a bug but when in https://github.com/mozilla/aframe-xr/blob/master/examples/ar/hit_test/index.html#L35 I try to access the position of the added entity I get 0 0 0 even after a hit.

Results of some naive tests:

//displayCoord(entity); // not OK, getting 0 0 0
// scene.flushToDOM(); displayCoord(entity); // not OK
// entity.flushToDOM(); displayCoord(entity); // not OK
// entity.components.position.flushToDOM(); displayCoord(entity); // not OK

setTimeout( () => { displayCoord(entity); } , 100 ); // always OK
//setTimeout( () => { displayCoord(entity); } , 10 ); // OK the vast majority of the time BUT not always!

This wasn't necessarily the expected usage but the behavior might be surprising for some so suggestions welcomed.

blairmacintyre commented 6 years ago

In hit_test.js, after setting the anchorOffset here, before emitting the event that's triggering the above code, the code in the xranchor component's update method needs to be called.

https://github.com/mozilla/aframe-xr/blob/24a0a6906c13e87c889d3f6d04cae9be91f69304/examples/lib/hit-test.js#L102

Someone could factor out the code from update that sets the position and orientation of the entity, and add a setter for setting the anchorOffset that runs that method. Then the values would be set immediately.

Otherwise they aren't set till the next update on that component