react-native-arkit icon indicating copy to clipboard operation
react-native-arkit copied to clipboard

Access Node properties?

Open Secretmapper opened this issue 7 years ago • 3 comments

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

Secretmapper avatar Jul 23 '18 12:07 Secretmapper

@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?

macrozone avatar Sep 06 '18 09:09 macrozone

@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 ?

code-matt avatar Sep 07 '18 00:09 code-matt

@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

macrozone avatar Sep 07 '18 12:09 macrozone