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

Access Node properties? #189

Open
Secretmapper opened this issue Jul 23, 2018 · 3 comments
Open

Access Node properties? #189

Secretmapper opened this issue Jul 23, 2018 · 3 comments

Comments

@Secretmapper
Copy link

Is there a way to access node properties (like textNode.boundingBox) perhaps through refs?

@macrozone
Copy link
Collaborator

@Secretmapper not yet, but that might make sense for that.

usually you "control" all node properties from react, but in this case, its computed. Are there any more properties that should be readable?

@code-matt
Copy link
Collaborator

code-matt commented Sep 7, 2018

@macrozone for something like position or rotation being updated at 60fps, would it be better to access the native objects this way and avoid RN re-renders for performance reasons ?

@macrozone
Copy link
Collaborator

@code-matt

you cannot access it directly anyway. it always involves serialisation.

in case of rotation, this is what happens:

  • you update the rotation property of your Ar-Component (e.g. with Animated Library) once per frame (requestAnimationFrame)
  • it will serialize these updates and send these to native
  • native part will apply the new values to the internal scenekit-nodes

so the scenekit nodes will reflect whats in your react-tree.

But in case the scenekit nodes gets rotated by something else (e.g. physics), then we have a problem, because you no longer know its real rotation (or even position). In this case, you would need some mechanism to get the new properties from scenekit: either a callback onRotation or similar. or an imperative api to get the current values getNodeProperties (e.g. getNodeProperties(nodeId, "textNode.boundingBox"), or some api on the node's ref as you suggest. But this will involve serialisation anyway.

Some more thoughts:

  • react-native team seems to do some bigger changes regarding js <--> native communication that might help in this case, but i don't know how it will look like.
  • something like shared-memory would be the most efficient way, but i doubt that this is possible given the sandbox nature of most js-vms, but who knows...

And some more tipps about rotation or changing properties quickly:

  • usually the 16ms timeframe is enough to update, but it leads to more cpu usage than needed. And if the js thread is blocked, you get stutters.
  • There is a transition property on ar components, that will use scenekit to change values smoothly to a new value, similar how css transitions work. Use that to smooth things out. You can even experiment with reducing your update-interval-frequency

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

No branches or pull requests

3 participants