How do I get the euler angles of bones?

Recommended Posts

I'm trying to get the initial euler angles of the bones right when my model is loaded.

I tried this:

bone.getLocalMatrix().decompose(vec1, quat, vec2);
quat.toEulerAnglesToRef(vec3);

but the values I'm getting in vec3 are not correct.

The angles I want are relative to the parent bone.

Share on other sites

have you try a Vector4() and not Vector3 for EuleurAngles

Share on other sites

I didn't.

toEulerAnglesToRef takes a Vector3:

`public toEulerAnglesToRef(result: Vector3): Quaternion {            //result is an EulerAngles in the in the z-x-z convention            var qx = this.x;            var qy = this.y;            var qz = this.z;            var qw = this.w;            var qxy = qx * qy;            var qxz = qx * qz;            var qwy = qw * qy;            var qwz = qw * qz;            var qwx = qw * qx;            var qyz = qy * qz;            var sqx = qx * qx;            var sqy = qy * qy;            var determinant = sqx + sqy;            if (determinant !== 0.000 && determinant !== 1.000) {                result.x = Math.atan2(qxz + qwy, qwx - qyz);                result.y = Math.acos(1 - 2 * determinant);                result.z = Math.atan2(qxz - qwy, qwx + qyz);            } else {                if (determinant === 0.0) {                    result.x = 0.0;                    result.y = 0.0;                    result.z = Math.atan2(qxy - qwz, 0.5 - sqy - qz * qz); //actually, degeneracy gives us choice with x+z=Math.atan2(qxy-qwz,0.5-sqy-qz*qz)                } else //determinant == 1.000                {                    result.x = Math.atan2(qxy - qwz, 0.5 - sqy - qz * qz); //actually, degeneracy gives us choice with x-z=Math.atan2(qxy-qwz,0.5-sqy-qz*qz)                    result.y = Math.PI;                    result.z = 0.0;                }            }            return this;        }`
Share on other sites

I just notice this comment in the toEulerAnglesToRef function:

//result is an EulerAngles in the in the z-x-z convention

I'm thinking I'm going have to do some research on how to get an x-y-z euler from a matrix.  Heck, I'll probably just end up hard coded the angles into my code.

Share on other sites

Hi,

I'm not very familiar with all this, but it seems the conversion from z-x-z to x-y-z convention is pretty complicated.

Basically you're looking to have the yaw/pitch/roll angles of your bone, right? If that's what you specifically need, then I guess BabylonJS doesn't have the right function for you. Although transforming a quaternion to x-y-z euler angles should be as feasible as what's currently implemented.

At any rate, please keep us informed on your progress: rotation issues are common and sometimes complicated, especially with quaternions involved.

Share on other sites

I just needed the z angle of the bones.  This is what ended up working for me:

`var ang = Math.atan2(boneLocalMatrix.m[4], boneLocalMatrix.m[5]);`

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×