Hello everyone ! I’m porting an application developed in Godot Engine that receives a set of rotations and displays a character that executes them on the screen:
In GodotEngine the code that rotates the joints correctly is this:
func set_bone_rot(bone, ang):
var b = skeleton.find_bone(bone)
var bone_rest_inv = skeleton.get_bone_rest(b).affine_inverse()
var bone_rest = skeleton.get_bone_rest(b)
var newpose = bone_rest_inv*bone_rest
newpose= newpose.rotated(Vector3(1.0, 0.0, 0.0),ang.x)
newpose = newpose.rotated(Vector3(0.0, 1.0, 0.0),ang.z)
newpose = newpose.rotated(Vector3(0.0, 0.0, 1.0),ang.y)
My code in threejs is like this at this moment:
function setBoneRotation(boneName, ang){
var bone = scene.getObjectByName(boneName);
var rotation = new THREE.Quaternion();
var quat = new THREE.Quaternion();
var vx = new THREE.Vector3( 1, 0, 0 );
var vy = new THREE.Vector3( 0, 1, 0 );
var vz = new THREE.Vector3( 0, 0, 1 );
quat.setFromAxisAngle( vx, ang.x );
rotation.multiply( quat );
quat.setFromAxisAngle( vy, ang.y );
rotation.multiply( quat );
quat.setFromAxisAngle( vz, ang.z );
rotation.multiply( quat );
bone.setRotationFromQuaternion(rotation);
}
I notice that the rotations in the three.js resemble the correct articulation but somehow it is distorted. Could someone tell me if there is any necessary transformation that I am not doing?
As an additional data im using a Collada Model loaded with ColladaLoader
Sample video with godotEngine https://youtu.be/7LUikSU8hhI
Sample video with three.js https://youtu.be/vTs_6ozCWi8
Thanks Guys !
Enzo