-
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
Switching between global/local rotation (for Viro3DObject) #332
Comments
Hey @Sejadis, thanks for reaching out. We actually do support Quaternions - you can view the documentation on them here. Saying that, you should still be able to grab the world transform of a given node, and then to extract the Quaternion rotation from that. Hope that helps! Do let us know if you are having troubles with this! |
Hey @dthian thanks for the answer. |
Apologies, i was thinking about ViroCore instead of ViroReact. No, they are not interchangeable at the javascript layer. When you mention "Switch between global and local", did you mean convert? You should be able to grab the world transform through async calls, and local transforms through props for most Viro controls. The only caveat here is in dynamic situations where the object is constantly moved by the renderer via animations, physics, etc. From the above, it sounds like the rotation that you are providing to set with is a global one, since "rotation values from the server considers each axis to always point in the same direction world wise". Since the rotation props set on a Viro3DObject represents a local rotation, you can't really just apply that same rotation values directly from the server without defects, especially if any parent node of the 3D object is rotated (it probably wouldn't work). Unfortunately, there isn't a way currently to set the world transform directly on a ViroNode, only local. Having said that, a mitigation may be possible: to instead find the desired local rotation to be set on your Viro3DObject that properly represents the world rotation given by your servers. Thus, we'll need to find the localRotation, given the current world rotation of that ViroObject3D parent's node, and your desired world rotation. That is:
Where you can get currentWorld Rotation through getTransformAsync(). Also, the parentWorldRot is the rotation (with getTransformAsync) of the parent node of the Viro3DObject. This should ideally realign your Viro3DObject towards the world rotation provided by your servers, by setting a properly calculated local rotation on your 3D object. Is this something that you have tried? If you are having problems with the above, please let us know, and provide the full code, and as well as input rotation values from your servers. Hope that helps! |
Having said that as well, the above mitigation is kind of gnarly. While the mitigation is implemented, in the mean time we can also file a story to implement a feature that makes it easier to convert to and from world transforms to local transforms. For example:
Where the transforms must include rot,scale,pos, and the conversion is done with respect to that node. How does this sound? |
Is there a way to switch between global and local rotation for objects?
We get rotation values from the server that considers each axis to always point in the same direction world wise
The rotation values given to the Viro3DObjects seem to get used as local rotation so applying our rotation values results in different angles when the rotation contains more than 1 axis
A bit OT: having support for Quaternions would be nice :)
The text was updated successfully, but these errors were encountered: