-
Notifications
You must be signed in to change notification settings - Fork 485
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
Storing ARHitTestResults in ViroARScene parent state? #292
Comments
Hey @MayeulGarreau, the performARHitTest API is actually a property of the ViroARScene and as such needs to be called on a ViroARScene object. If you'd like to have a reference to this control from another part of your code (like the callback of the 2D button), you can simply create a reference to it to call the hit test function:
Do let us know if you have problems with the above. |
Hi @dthian , thanks for your quick and awesome answer! I've implemented what you said on my code (based on the Hello World example) but when I run app there is an error: undefined is not an object (evaluating: '_this.arSceneRef.getCameraOrientationAsync'). Maybe the following code may help you to identifies what went wrong?
Thanks again for your help and sorry I'm not really used to references and stuff! |
Hey @MayeulGarreau, no worries, it's all good. In your code example above, you have saved a reference to the ViroARScene in HelloWorldSceneAR through 'this'. However, you are also attempting to access it outside of the HelloWorldSceneAR scope from App.js, causing the undefined behavior. Another approach we can take, is that we could 'tell' HelloWorldSceneAR to perform the hit test, and then in HelloWorldSceneAR define the _onCameraARHitTest() function correctly accesses ViroARScene's 'this' within the correct scope. This also helps separate AR functionality to AR classes, while updating your 2D UI separately. However, with the current Viro Classes, this doesn't work in this case due to the nature of the Viro Scene Navigator class - The HelloWorldSceneAR may not yet been inflated by the navigator, kind of like React's own SceneNav. As such, we'll have to make a few tweaks to ViroARSceneNavigator: Within ViroARSceneNavigator, please replace the _renderSceneStackItems() function with this below. Note this effectively enables the referencing of the active scene.
Then, within your HelloWorldAR.js file you can perform all the AR items you'd like, and confine them to a helper function to be triggered. Note that we also must bind the callback to our class in the constructor:
Finally, we can then refer to this triggerCustomUpdate function via the refs we have previously plumbed through the arSceneNavigator: this.nav.activeScene.triggerCustomUpdate. We can then trigger the triggerCustomUpdate() from the click event within App.js:
I hacked a solution together and this appears to work well. This should get you unblocked for now, please let me know if you are experiencing any difficulties with the above. |
Hey, waaah amazing, thank you so much for this very complete answer! I wouldn’t have been able to handle it alone. I’m actually implementing it, I’ll keep in touch! |
Hi @dthian , it's me again, sorry for the double post! Thank you one more time, I worked on the solution you gave and it's perfectly doing the job 👍. I just have another question regarding the next step of what we talked before: I now try to keep updated the ViroARScene with the data in App.js state. So I thought that things like...
or:
... would work, but it's not! Do you have any ideas? Thanks again! |
Hey @MayeulGarreau, previously the examples were accessing Viro scene data and components, from the context of your App.js. If instead you want to access App.js data, from the context of your App.js, it would be different - you would have to pass data through to your scene. To do that you can use viroAppProps. How to achieve that should be thoroughly explained in this issue. Let me know if you have any questions or difficulties with the above. |
Hi, Sorry for the delay of my answer! I fully implemented it, it works fine. Thanks a lot for your help! I close the issue :) |
Sounds good @MayeulGarreau. Note that you will have to re-apply the patch above if you ever upgrade ViroReact in the future. I've filed a bug internally so that we can consider making a more permanent fix. Just an FYI. |
Hi @dthian , sorry to bother you again on this previsoulsy closed issue! I am migrating my app state to Redux at the moment. I want to connect the component where exists the This error appears when I change The parent component is also connected to Redux. the Do you know what my mistake is? Thank you in advance for your help and have a nice day! |
Hi!
I would like to:
Having studied carrefully the ViroARSample, I then did my best to follow the general React rules on "lifting state up", but I still can't find a way to solve this problem.
Do you have any advice for me?
Thanks in advance for your help!
The text was updated successfully, but these errors were encountered: