External js library for matrix math (three.js) in After Effects?
Copy link to clipboard
Copied
I'm looking for a way to handle matrices and rotation orders within After Effects. As far as I know there are no built in ways to do this (without doing everything manually). I found ways (expressions) to get the world position/rotation data, but now I need to transform that data (change rotation order for example).
After some googling I found the three.js which seems to have the functionality I want. Can I use this with After Effects somethow? I tried to add it to a script but all I get is errors.
I was following this suggestion how to include external scripts. There seems to by some syntax mismatch in three.js. But same happend when I tried another library (math.js).
Any suggestions?
Copy link to clipboard
Copied
The transforms in AE are hard-coded, so you'd have to transform your results back via another matrix, anyway, or decompose the values to something AE can use, already sacrificing precision in the process. I'm really not sure what you are actually trying to achieve here. You'd also still bump into the other precision issues due to how AE handles certain property stream values and the occasional gimbal lock. There simply is no way to completely replace or reorder the property streams and their evaluation. The rest is too vague. You have not offered any actual system info, no code snippets and well, if there are errors you have to post them, too, or else nobody has even the slightest idea what may be going on.
Mylenium
Copy link to clipboard
Copied
Thanks for the reply, I'll try to ellaborate. The goal is to export/import 3d data to external applications. To do this I need to be able to convert the rotation order among other things. I'm not sure what you mwan with "precision issues"? I do this kind of thing in several other apps and a rotation -> matrix -> rotation would only change on the forth or fifth decimal. But maybe there's something specific to AE?
I found this expression to get the world rotation. Am I right that the u,v,w is the 3x3 rotation matrix?
C = thisComp.layer("child");
u = C.toWorldVec([1,0,0]);
v = C.toWorldVec([0,1,0]);
w = C.toWorldVec([0,0,1]);
Anyway, I guess the main question is this:
Can I use an external math libray for a script? If so, how do I include them for use? I tried with both
$.evalFile(path/to/lib.js);
and
#include "includeme.jsx"
Copy link to clipboard
Copied
To include a file:
// @ include "includeme.jsx"
To point to a separate folder for includes (I use a folder with brackets so that it doesn't get automatically loaded)
// @includepath ".//(external_libs)"
// @include "includeme.jsx"
Though I have to say, I've been finding includes seem to break the VSCode debugger a lot. Running them through AE works.

