Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Scale Composition: scale the Point of Interest depth of a camera or light under a 2D parent

Marco Arnulfofc7882b0eed5
diff --git a/crates/engine/src/cmd/comp_more.rs b/crates/engine/src/cmd/comp_more.rs
index 00f1bb200..940c09f8d 100644
--- a/crates/engine/src/cmd/comp_more.rs
+++ b/crates/engine/src/cmd/comp_more.rs
@@ -197,7 +197,7 @@ fn scale_comp(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(pr) = tr.get_mut("positionZ") {
scale_prop(pr, f);
}
- for name in ["position", "scale"] {
+ for name in ["position", "poi", "scale"] {
if let Some(pr) = tr.get_mut(name) {
scale_prop_z(pr, f);
}
diff --git a/crates/engine/src/tests/scale_comp.rs b/crates/engine/src/tests/scale_comp.rs
index 27397e744..28cc1ba88 100644
--- a/crates/engine/src/tests/scale_comp.rs
+++ b/crates/engine/src/tests/scale_comp.rs
@@ -243,6 +243,21 @@ fn scale_comp_scales_once_through_a_camera_under_a_scaled_null() {
assert!(near, "{held0:?} → {held1:?}");
}
+#[test]
+fn scale_comp_scales_the_point_of_interest_depth_of_a_camera_under_a_2d_null() {
+ let mut s = comp(200, 100);
+ let cam = s.execute("layer.newCamera", json!({})).unwrap()["layer"].as_u64().unwrap();
+ let rig = s.execute("layer.newNull", json!({})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("layer.setParent", json!({"layers": [cam], "parent": rig})).unwrap();
+ s.execute("prop.set", json!({"layer": cam, "path": "transform/position", "value": [10, 20, -1000]})).unwrap();
+ s.execute("prop.set", json!({"layer": cam, "path": "transform/poi", "value": [10, 20, 200]})).unwrap();
+
+ s.execute("comp.scale", json!({"factor": 2})).unwrap();
+ // The 2D null carries X and Y; the camera's own Z doubles at both ends, so it looks the same way.
+ assert_eq!(v3(&s, cam, "transform/position", 0.0), [10.0, 20.0, -2000.0]);
+ assert_eq!(v3(&s, cam, "transform/poi", 0.0), [10.0, 20.0, 400.0]);
+}
+
#[test]
fn scale_comp_refuses_a_bad_factor_and_changes_nothing() {
let mut s = comp(640, 360);