-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
Support toJSON in Quaternion class #25424
Comments
I'm fine with adding |
Maybe as an array, like |
I'm fine with arrays, too. In the three.js JSON Object/Scene format, matrix and vector properties like the local matrix or the center of a bounding sphere are already serialized as arrays. |
I guess that's fine too, as long as everything is consistent (currently Vector3 does not export as an array) |
You can get what you are after by calling const quat = new Quaternion();
// change rotation
const json = JSON.stringify( quat.toArray() ) When you read it back in use const data = JSON.parse( json )
const quatFromJson = new Quaternion().fromArray( data );
You might find it's less than optimal as a storage representation for the same information. |
The problem with this suggestion is that you often can't execute such code since the JSON serialization happens indirectly when performing certain operations. Having a |
Description
Similarly to this request it would be nice to have a clean toJSON serialization for the Quaternion class. Currently the
JSON.stringify()
results in{"isQuaternion":true,"_x":0,"_y":0,"_z":0,"_w":1}
Solution
The preferred output should be
{"x":0,"y":0,"z":0,"w":1}
Alternatives
Probably not a viable alternative: Maybe a serialization toolset in a separate class/lib ?
Additional context
No response
The text was updated successfully, but these errors were encountered: