I am working on L-system interpreter and I use quaternion as internal representation of rotation. I need to export result to ThreeJs JavaScript scene and I found json scene as the best way how to do that.
I found one example of scene on https://github.com/mrdoob/three.js/blob/master/examples/scenes/test_scene.js but there is nothing about quaternion rotations.
So I used help at http://threejs.org/io/s/quaternion and found, that THREE.Object3D has properties quaternion and useQuaternion but It seems to do not work, the error is raised by scene loader (probably because of missing "rotation" attribute, see EDIT at the end):
"obj": {
...
"quaternion": [0.38268343236509,0,0,0.923879532511287],
"useQuaternion": true
}
I've also tried to convert quaternion to Euler angles but It wont work for me, probably because of other order of applying of angles (I assume order Y, Z, X). In the above example, quaternion is representing rotation about the Z axis (pitch) by 135 degrees which is converted to Euler angles [pi,pi,pi/4] but it is displayed not correct in the scene.
Following picture shows blocks each rotated by 11 deg more than other by Z axis. Axes are X(red), Y(green) and Z (blue). The upper half is rotated incorrectly due to incorrect conversion quaternion to Euclid (I used this page for implementation: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/ ).
EDIT: After further examination the error raised by scene loader is because of missing "rotation" attribute on object. Following output do not throw error and scene is loaded but it is wrong (in the same way as shown image) because quaternion rotations are ignored.
"obj": {
...
"rotation": [3.14159265358979,3.14159265358979,0.785398163397449],
"quaternion": [0.38268343236509,0,0,0.923879532511287],
"useQuaternion": true
}