Here’s an example I dug up from my archives that might help. It works in AE’s 3D world space (+y is down, +z is away from front view) and calculates the world space orientation of “Layer 1”. The rotation matrix has been reduced down to a couple of sin & cos operations:
L = thisComp.layer(“Layer 1”);
u = L.toWorldVec([1,0,0]);
v = L.toWorldVec([0,1,0]);
w = L.toWorldVec([0,0,1]);
sinb = clamp(w[0],-1,1);
b = Math.asin(sinb);
cosb = Math.cos(b);
if (Math.abs(cosb) > .0005){
c = -Math.atan2(v[0],u[0]);
a = -Math.atan2(w[1],w[2]);
}else{
a = Math.atan2(u[1],v[1]);
c = 0;
}
[radiansToDegrees(a),radiansToDegrees(b),radiansToDegrees(c)]
Dan