-
World Orientation of Child Object Expression Bug
Hey all! Back again. In 2009, Dan Ebberts was kind enough to share an expression that retrieved the global orientation of a layer regardless if it was parented or not. The post I got it from is here:
https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=13049&univpostid=13049&pview=tThis expression is a little over my head but it became essential to a rather complex template I have been working on. I recently discovered a bug in this expression that has been throwing me for a loop. It has worked so perfectly for so long(literal years) , that I only recently had a project that introduced the specific circumstances that produce a bug. I’m at a point where I need to find a solution to this or my template starts breaking apart. I attempted to research how vectors work in After Effects but even when I tried a slight rewrite myself, I was getting the same exact problem.
It’s a bit hard to to describe, so I made a demo project file for anyone that wants to take a crack at fixing this. I labeled everything and tried to be as clear as possible with how the bug presents itself vs the expected behavior.
https://www.dropbox.com/s/01t8napcrm483sr/Global_Orientation_Bug_Demo.aep?dl=0Basically what happens is when the parent layer get close to or hits specific values, it causes the child orientation to invert. I’ve narrowed it down to these four combinations that causes wrong behavior:
270, 270, 0
90, 270, 0
0, 270, 270
0, 270, 90This will make a lot more sense if you download the demo file-I tried to be as straightforward as I could, it’s very easy to see the problem once it’s happening in front of you. I deeply appreciate anyone willing to take a crack at this. I realize this is a bit difficult so I understand that any time invested helping me out is very generous.
And Dan, if you read this- you’ve helped me far more times than is possible to count and I cannot explain how helpful that expression has been to me as is. Trying to fix this/find alternatives has been breaking my brain all week- so going to see what the creative cow community thinks. Thanks all!
//World Orientation Output
C = thisComp.layer("PARENT");
u = normalize(C.toWorldVec([1,0,0]));
v = normalize(C.toWorldVec([0,1,0]));
w = normalize(C.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)]