mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 00:55:43 +00:00
Merge remote-tracking branch 'upstream/main' into disk-cache-comp-scope
This commit is contained in:
commit
250e52cdc3
51 files changed
+3293
-347
No files matched your search
@@ -167,12 +167,28 @@ function normalize(a) {
|
||||
return l === 0 ? a.map(function () { return 0; }) : div(a, l);
|
||||
}
|
||||
|
||||
// Orientation that points the layer's z axis at `at` with its x axis kept level, in the
|
||||
// Orientation order (Rx · Ry · Rz) and wrapped to [0, 360), as After Effects returns it.
|
||||
function lookAt(from, at) {
|
||||
var d = normalize(sub(__v(at), __v(from)));
|
||||
var x = d[0], y = d[1], z = d[2] || 0;
|
||||
var rx = -Math.asin(Math.max(-1, Math.min(1, y))) * 180 / Math.PI;
|
||||
var ry = Math.atan2(x, z) * 180 / Math.PI;
|
||||
return [rx, ry, 0];
|
||||
var p = Math.asin(Math.max(-1, Math.min(1, -y)));
|
||||
var w = Math.atan2(x, z);
|
||||
var cw = Math.cos(w), sw = Math.sin(w), cp = Math.cos(p), sp = Math.sin(p);
|
||||
// The rotation Ry(w) · Rx(p), written as Orientation angles.
|
||||
var oy = Math.asin(Math.max(-1, Math.min(1, sw * cp)));
|
||||
var ox, oz;
|
||||
if (Math.sqrt(cw * cw + sw * sw * sp * sp) > 1e-9) {
|
||||
ox = Math.atan2(sp, cw * cp);
|
||||
oz = Math.atan2(-sw * sp, cw);
|
||||
} else {
|
||||
ox = Math.atan2(cw * sp, cp);
|
||||
oz = 0;
|
||||
}
|
||||
return [ox, oy, oz].map(function (r) {
|
||||
var a = ((r * 180 / Math.PI) % 360 + 360) % 360;
|
||||
return a >= 360 - 1e-9 || Math.abs(a) < 1e-9 ? 0 : a;
|
||||
});
|
||||
}
|
||||
|
||||
function degreesToRadians(d) { return d * Math.PI / 180; }
|
||||
|
||||
@@ -586,6 +586,12 @@ fn angles_and_look_at() {
|
||||
assert_close!(f.num("degreesToRadians(90)", 0.0), std::f64::consts::FRAC_PI_2);
|
||||
let o = f.ev(f.a, "transform/orientation", "lookAt([0, 0, 0], [100, 0, 100])", 0.0).unwrap().as_vec3();
|
||||
assert!(close(o[1], 45.0) && close(o[0], 0.0), "{o:?}");
|
||||
// After Effects 2026 read-backs of lookAt(position, …) on a layer at [960, 540, 0].
|
||||
for (at, want) in [([1500.0, 200.0, 300.0], [48.5763, 49.9802, 319.0442]), ([500.0, 900.0, -400.0], [221.9872, 319.4766, 210.3184])] {
|
||||
let e = format!("lookAt([960, 540, 0], [{}, {}, {}])", at[0], at[1], at[2]);
|
||||
let o = f.ev(f.a, "transform/orientation", &e, 0.0).unwrap().as_vec3();
|
||||
assert!((0..3).all(|i| (o[i] - want[i]).abs() < 1e-3), "{e}: {o:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// ---- interpolation ----------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user