Skip to content

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

Merge pull request #1160 from nanox333/fix/1063-levels-alpha-name

Brandon Thomasbb4972a88636
diff --cc crates/script/src/tests.rs
index c25d889e6,27812b825..2c821e6ad
--- a/crates/script/src/tests.rs
+++ b/crates/script/src/tests.rs
@@@ -1231,129 -1011,20 +1231,147 @@@ fn scripted_text_range_selector_resolve
assert_eq!(o.result, json!([1, "ADBE Text Selector", 50, 100, "ADBE Text Percent Offset"]));
}
+/// `setInterpolationTypeAtKey` and `setTemporalEaseAtKey` (`keys.interpolation` / `keys.velocity`)
+/// act on effect parameters too, not just transform properties (#994).
+#[test]
+fn effect_parameter_interpolation_and_ease() {
+ let mut s = session();
+ let o = ok(
+ &mut s,
+ r#"
+ var c = app.project.items.addComp("E", 100, 100, 1, 5, 25);
+ var l = c.layers.addNull();
+ var slider = l.property("ADBE Effect Parade").addProperty("ADBE Slider Control").property(1);
+ slider.setValuesAtTimes([0, 1, 2], [0, 50, 100]);
+ slider.setInterpolationTypeAtKey(1, KeyframeInterpolationType.BEZIER, KeyframeInterpolationType.BEZIER);
+ slider.setTemporalEaseAtKey(2, [new KeyframeEase(0, 16.67)], [new KeyframeEase(0, 33.33)]);
+ var point = l.property("ADBE Effect Parade").addProperty("ADBE Point3D Control").property(1);
+ point.setValuesAtTimes([0, 1], [[0, 0, 0], [50, 50, 50]]);
+ point.setInterpolationTypeAtKey(1, KeyframeInterpolationType.BEZIER, KeyframeInterpolationType.BEZIER);
+ [slider.keyInInterpolationType(1) == KeyframeInterpolationType.BEZIER,
+ slider.keyOutInterpolationType(1) == KeyframeInterpolationType.BEZIER,
+ slider.keyInTemporalEase(2)[0].influence,
+ slider.keyOutTemporalEase(2)[0].influence,
+ point.keyInInterpolationType(1) == KeyframeInterpolationType.BEZIER];
+ "#,
+ );
+ assert_eq!(o.result, json!([true, true, 16.67, 33.33, true]));
+}
+
+/// #808: sourcePointToComp and compPointToSource follow the layer's transform.
+#[test]
+fn source_point_conversions_follow_the_layer_transform() {
+ let mut s = session();
+ let o = ok(
+ &mut s,
+ r#"
+ var comp = app.project.items.addComp("Repro", 1920, 1080, 1, 10, 25);
+ var layer = comp.layers.addSolid([1, 0, 0], "S", 200, 100, 1);
+ layer.transform.position.setValue([400, 300]);
+ layer.transform.scale.setValue([50, 50]);
+ var a = layer.sourcePointToComp([0, 0]);
+ var b = layer.compPointToSource([400, 300]);
+ [a[0], a[1], b[0], b[1]]
+ "#,
+ );
+ let v = o.result;
+ let near = |x: &Value, want: f64| x.as_f64().is_some_and(|g| (g - want).abs() < 1e-6);
+ assert!(near(&v[0], 350.0) && near(&v[1], 275.0), "{v}");
+ assert!(near(&v[2], 100.0) && near(&v[3], 50.0), "{v}");
+}
+
+/// #1063: a script asks a light's options for After Effects' "ADBE Casts Shadows".
+#[test]
+fn light_options_accept_the_after_effects_casts_shadows_name() {
+ let mut s = session();
+ let o = ok(
+ &mut s,
+ r#"
+ var comp = app.project.items.addComp("Repro", 1920, 1080, 1, 10, 25);
+ var light = comp.layers.addLight("Key", [100, 100]);
+ var c = light.property("ADBE Light Options Group").property("ADBE Casts Shadows");
+ c == null ? "null" : c.name
+ "#,
+ );
+ assert_ne!(o.result, json!("null"), "{:?}", o.result);
+}
+
+/// A Google Earth Studio camera export: transform and camera shortcuts on the camera layer, keys
+/// set through them, and Convert Expression to Keyframes run on the selected property (#1077).
+#[test]
+fn earth_studio_style_script_keys_the_camera() {
+ let mut s = session();
+ let o = ok(
+ &mut s,
+ r#"
+ var comp = app.project.items.addComp("Orbit", 1920, 1080, 1, 1, 10);
+ comp.openInViewer();
+ var cam = comp.layers.addCamera("Camera", ["960", "540"]);
+ cam.locked = true;
+ var pos = cam.position, rx = cam.xRotation, ry = cam.yRotation, rz = cam.zRotation, zoom = cam.zoom;
+ cam.autoOrient = AutoOrientType.NO_AUTO_ORIENT;
+ var ints = comp.layers.addNull();
+ ints.name = "ints";
+ ints.threeDLayer = true;
+ ints.position.setValuesAtTimes([0, 0.5], [[100, 200, 300], [110, 220, 330]]);
+ rx.setValuesAtTimes([0, 0.5], [181, 182]);
+ ry.setValuesAtTimes([0, 0.5], [39, 38]);
+ rz.setValuesAtTimes([0, 0.5], [87, 86]);
+ pos.expression = 'thisComp.layer("ints").transform.position';
+ var id = app.findMenuCommandId("Convert Expression to Keyframes");
+ if (id && pos.canSetExpression && pos.expressionEnabled) {
+ pos.selected = true;
+ app.executeCommand(id);
+ pos.selected = false;
+ ints.remove();
+ }
+ zoom.setValueAtTime(0, 1500);
+ zoom.setValueAtTime(0.5, 1600);
+ [pos.numKeys, rx.numKeys, ry.numKeys, rz.numKeys, zoom.numKeys, comp.numLayers,
+ cam.pointOfInterest.matchName, cam.orientation.matchName, cam.depthOfField.matchName,
+ cam.focusDistance.matchName, cam.aperture.matchName, cam.blurLevel.matchName]
+ "#,
+ );
+ assert_eq!(
+ o.result,
+ json!([
+ 10,
+ 2,
+ 2,
+ 2,
+ 2,
+ 1,
+ "ADBE Anchor Point",
+ "ADBE Orientation",
+ "ADBE Camera Depth of Field",
+ "ADBE Camera Focus Distance",
+ "ADBE Camera Aperture",
+ "ADBE Camera Blur Level"
+ ])
+ );
+ let (_, c) = comp_named(&s, "Orbit");
+ let cam = layer(c, "Camera");
+ let p = cam.props.prop("transform/position").unwrap();
+ assert_eq!(p.keys[5].value, KV::Vec3([110.0, 220.0, 330.0]));
+ assert!(!p.expr.as_ref().unwrap().enabled);
+ assert_eq!(cam.props.prop("transform/rotationX").unwrap().keys[1].value, KV::Scalar(182.0));
+ assert_eq!(cam.props.prop("cameraOptions/zoom").unwrap().keys[1].value, KV::Scalar(1600.0));
+}
++
+ /// Pro Levels2's Alpha controls sit one group down (under Alpha), so a script finds them by their
+ /// name on the effect as well as through the group (#1063).
+ #[test]
+ fn scripted_levels_alpha_controls_resolve_from_the_effect() {
+ let mut s = session();
+ let o = ok(
+ &mut s,
+ r#"
+ var c = app.project.items.addComp("Levels", 320, 180, 1, 3, 30);
+ var l = c.layers.addSolid([1, 0, 0], "S", 320, 180, 1);
+ var fx = l.property("ADBE Effect Parade").addProperty("ADBE Pro Levels2");
+ fx.property("Alpha Input White").setValue(0.5);
+ [fx.property("Alpha").property("Alpha Input White").value, fx.property("Alpha Input White").value]
+ "#,
+ );
+ assert_eq!(o.result, json!([0.5, 0.5]));
+ }