Gap 7: Backgrounds animation presets (#1096)

Problem: the built-in animation preset library had no Backgrounds category
(gap 7: 31 presets against After Effects' 621).

Fix: 23 original Backgrounds presets in crates/engine/presets/backgrounds.json,
built from our own generator, noise, colour and stylize effects: Soft Gradient
Drift, Aurora Veil, Slow Fog, Cloud Bank, Dark Smoke, Ember Haze, Magma Flow,
Ice Flow, Pastel Plasma, Cell Drift, Crystal Facets, Hex Mosaic, Mirrored Silk,
Water Caustics, Blueprint Grid, Checker Scroll, Scrolling Stripes, Pulse Rings,
Bokeh Drift, Spotlight Floor, Dawn Sky, Sweeping Light, Grainy Wash.

The preset format gains `expr` (an expression per property, so backgrounds keep
moving for the whole layer) and point parameters written as fractions of the
layer size. Effects & Presets lists them under * Animation Presets > Backgrounds.
Tests: catalogue uniqueness and categories, apply/undo/redo of every preset
(engine), render of every preset with the expression engine: finite,
non-flat, deterministic, moving (host), panel listing and apply (ui-egui).
Sidecar, ATTRIBUTION.md, gaps.md row 7 and effects-parity.md updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-10-12 21:13:05 +02:00
co-authored by Claude Sonnet 5.5
parent 470ea7a3af
commit 51371939ad
10 changed files with 437 additions and 19 deletions
+245
View File
@@ -0,0 +1,245 @@
{
"format": "effectcraft.animationPresets/1",
"notes": "Original EffectCraft background presets (MIT OR Apache-2.0), written from scratch on EffectCraft's own generator, noise, colour and stylize effects. Apply to a solid or any layer with effects. Key times are seconds from the current time; most motion comes from expressions (time-based, so the background keeps moving for the layer's whole duration). Point values are fractions of the layer size; effect paths are the effect's parameter ids.",
"presets": [
{
"id": "softGradientDrift",
"name": "Soft Gradient Drift",
"category": "Backgrounds",
"description": "Four soft colour corners slowly drift around the frame.",
"effects": [
{"effect": "ec.generate.fourcolor", "set": {"positionsColors/color1": [0.1137, 0.1686, 0.3922, 1], "positionsColors/color2": [0.1647, 0.6157, 0.5608, 1], "positionsColors/color3": [0.4824, 0.1765, 0.5608, 1], "positionsColors/color4": [0.9569, 0.6353, 0.3804, 1], "blend": 100}, "expr": {"positionsColors/point1": "[thisComp.width*(0.15+0.1*Math.sin(time*0.7)), thisComp.height*(0.2+0.1*Math.cos(time*0.5))]", "positionsColors/point2": "[thisComp.width*(0.85+0.08*Math.cos(time*0.6)), thisComp.height*(0.15+0.1*Math.sin(time*0.8))]", "positionsColors/point3": "[thisComp.width*(0.2+0.1*Math.sin(time*0.9+1)), thisComp.height*(0.85+0.08*Math.cos(time*0.4))]", "positionsColors/point4": "[thisComp.width*(0.8+0.1*Math.cos(time*0.5+2)), thisComp.height*(0.8+0.1*Math.sin(time*0.7+1))]"}}
]
},
{
"id": "auroraVeil",
"name": "Aurora Veil",
"category": "Backgrounds",
"description": "Tall green curtains of light ripple slowly across a night sky.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 170, "brightness": -40, "complexity": 6, "fractalType": 1, "transform/uniformScaling": false, "transform/scaleWidth": 500, "transform/scaleHeight": 70}, "expr": {"evolution": "time*18", "transform/offset": "[thisComp.width/2 + Math.sin(time*0.3)*thisComp.width*0.2, thisComp.height/2]"}},
{"effect": "ec.color.tint", "set": {"black": [0.0078, 0.0392, 0.0784, 1], "white": [0.302, 1.0, 0.7529, 1], "amount": 100}}
]
},
{
"id": "slowFog",
"name": "Slow Fog",
"category": "Backgrounds",
"description": "Heavy grey-blue fog banks roll gently through the frame.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 75, "brightness": -5, "complexity": 6, "fractalType": 1, "transform/scale": 320}, "expr": {"evolution": "time*14", "transform/offset": "[thisComp.width/2 + time*25, thisComp.height/2]"}},
{"effect": "ec.color.tint", "set": {"black": [0.0588, 0.0941, 0.1333, 1], "white": [0.6235, 0.7059, 0.7765, 1], "amount": 100}}
]
},
{
"id": "cloudBank",
"name": "Cloud Bank",
"category": "Backgrounds",
"description": "Soft cumulus clouds drift across a blue sky.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 130, "brightness": 8, "complexity": 7, "transform/scale": 240}, "expr": {"evolution": "time*10", "transform/offset": "[thisComp.width/2 + time*40, thisComp.height/2]"}},
{"effect": "ec.color.tint", "set": {"black": [0.1843, 0.4353, 0.702, 1], "white": [1.0, 1.0, 1.0, 1], "amount": 100}}
]
},
{
"id": "darkSmoke",
"name": "Dark Smoke",
"category": "Backgrounds",
"description": "Thick dark smoke rises slowly and curls as it goes.",
"effects": [
{"effect": "ec.noise.turbulent", "set": {"contrast": 140, "brightness": -15, "complexity": 6, "transform/scale": 200}, "expr": {"evolution": "time*45", "transform/offset": "[thisComp.width/2, thisComp.height/2 + time*70]"}},
{"effect": "ec.color.tint", "set": {"black": [0.0, 0.0, 0.0, 1], "white": [0.4157, 0.4157, 0.4549, 1], "amount": 100}}
]
},
{
"id": "emberHaze",
"name": "Ember Haze",
"category": "Backgrounds",
"description": "A warm glowing haze of embers, black to deep red to amber.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 120, "brightness": 0, "complexity": 6, "fractalType": 1, "transform/scale": 180}, "expr": {"evolution": "time*30", "transform/offset": "[thisComp.width/2, thisComp.height/2 + time*40]"}},
{"effect": "ec.color.tritone", "set": {"shadows": [0.051, 0.0078, 0.0, 1], "midtones": [0.6275, 0.1569, 0.0, 1], "highlights": [1.0, 0.702, 0.2784, 1]}}
]
},
{
"id": "magmaFlow",
"name": "Magma Flow",
"category": "Backgrounds",
"description": "Fire-coloured plasma that slowly cycles through its palette.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 110, "brightness": 0, "complexity": 6, "transform/scale": 260}, "expr": {"evolution": "time*20"}},
{"effect": "ec.color.colorama", "set": {"outputCycle/usePresetPalette": 2}, "expr": {"inputPhase/phaseShift": "time*30"}}
]
},
{
"id": "iceFlow",
"name": "Ice Flow",
"category": "Backgrounds",
"description": "Cold blue and white veins drift through a frozen field.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 60, "brightness": -5, "complexity": 6, "fractalType": 1, "transform/scale": 300}, "expr": {"evolution": "time*12"}},
{"effect": "ec.color.colorama", "set": {"outputCycle/usePresetPalette": 3, "outputCycle/cycles": 1}, "expr": {"inputPhase/phaseShift": "Math.sin(time*0.4)*40"}}
]
},
{
"id": "pastelPlasma",
"name": "Pastel Plasma",
"category": "Backgrounds",
"description": "Soft pastel plasma with colours that endlessly cycle.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 170, "brightness": 0, "complexity": 6, "transform/scale": 300}, "expr": {"evolution": "time*16"}},
{"effect": "ec.color.colorama", "set": {"outputCycle/usePresetPalette": 7}, "expr": {"inputPhase/phaseShift": "time*25"}}
]
},
{
"id": "cellDrift",
"name": "Cell Drift",
"category": "Backgrounds",
"description": "Bubble-like cells slowly swell and merge in teal tones.",
"effects": [
{"effect": "ec.generate.cellpattern", "set": {"cellPattern": 0, "size": 90, "contrast": 140, "disperse": 1.2}, "expr": {"evolution": "time*40"}},
{"effect": "ec.color.tint", "set": {"black": [0.0157, 0.1255, 0.1686, 1], "white": [0.3725, 0.8902, 0.7843, 1], "amount": 100}}
]
},
{
"id": "crystalFacets",
"name": "Crystal Facets",
"category": "Backgrounds",
"description": "Sharp crystal facets shimmer in warm violet light.",
"effects": [
{"effect": "ec.generate.cellpattern", "set": {"cellPattern": 1, "size": 110, "contrast": 120}, "expr": {"evolution": "time*25"}},
{"effect": "ec.color.tint", "set": {"black": [0.102, 0.0431, 0.1804, 1], "white": [0.8784, 0.6392, 1.0, 1], "amount": 100}}
]
},
{
"id": "hexMosaic",
"name": "Hex Mosaic",
"category": "Backgrounds",
"description": "A hexagon mosaic that glows as fog passes beneath it.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 110, "brightness": 0, "complexity": 6, "transform/scale": 300}, "expr": {"evolution": "time*20", "transform/offset": "[thisComp.width/2 + time*20, thisComp.height/2]"}},
{"effect": "ec.stylize.cchextile", "set": {"radius": 45}},
{"effect": "ec.color.tint", "set": {"black": [0.0392, 0.0588, 0.2392, 1], "white": [0.3216, 0.8196, 1.0, 1], "amount": 100}}
]
},
{
"id": "mirroredSilk",
"name": "Mirrored Silk",
"category": "Backgrounds",
"description": "Flowing silk ribbons mirrored down the centre.",
"effects": [
{"effect": "ec.noise.fractal", "set": {"contrast": 130, "brightness": 0, "complexity": 6, "fractalType": 1, "transform/scale": 260}, "expr": {"evolution": "time*15", "transform/offset": "[thisComp.width/2 + Math.sin(time*0.4)*thisComp.width*0.15, thisComp.height/2]"}},
{"effect": "ec.distort.mirror", "set": {"center": [0.5, 0.5], "angle": 0}},
{"effect": "ec.color.tint", "set": {"black": [0.1686, 0.0392, 0.1176, 1], "white": [1.0, 0.7608, 0.851, 1], "amount": 100}}
]
},
{
"id": "waterCaustics",
"name": "Water Caustics",
"category": "Backgrounds",
"description": "Bright caustic filaments shimmer across a turquoise pool floor.",
"effects": [
{"effect": "ec.noise.turbulent", "set": {"contrast": 120, "brightness": -25, "complexity": 6, "transform/scale": 110, "fractalType": 2}, "expr": {"evolution": "time*60"}},
{"effect": "ec.color.tint", "set": {"black": [0.0, 0.2275, 0.3216, 1], "white": [0.5608, 0.9529, 1.0, 1], "amount": 100}}
]
},
{
"id": "blueprintGrid",
"name": "Blueprint Grid",
"category": "Backgrounds",
"description": "A technical grid slides across a deep blue plate.",
"effects": [
{"effect": "ec.generate.fill", "set": {"allMasks": true, "color": [0.0431, 0.2392, 0.5686, 1]}},
{"effect": "ec.generate.grid", "set": {"width": 16, "height": 16, "border": 1, "color": [0.6235, 0.8314, 1.0, 1], "opacity": 18, "blendingMode": 1}, "expr": {"anchor": "[time*8, time*8]"}},
{"effect": "ec.generate.grid", "set": {"width": 80, "height": 80, "border": 1.5, "color": [0.8471, 0.9373, 1.0, 1], "opacity": 45, "blendingMode": 1}, "expr": {"anchor": "[time*16, time*16]"}}
]
},
{
"id": "checkerScroll",
"name": "Checker Scroll",
"category": "Backgrounds",
"description": "A two-tone checkerboard scrolls diagonally.",
"effects": [
{"effect": "ec.generate.fill", "set": {"allMasks": true, "color": [0.1098, 0.1216, 0.2275, 1]}},
{"effect": "ec.generate.checkerboard", "set": {"sizeFrom": 1, "width": 90, "height": 90, "color": [0.1765, 0.2, 0.3882, 1], "opacity": 100, "blendingMode": 1}, "expr": {"anchor": "[time*45, time*45]"}}
]
},
{
"id": "scrollingStripes",
"name": "Scrolling Stripes",
"category": "Backgrounds",
"description": "Wide vertical stripes slide steadily sideways.",
"effects": [
{"effect": "ec.generate.fill", "set": {"allMasks": true, "color": [0.949, 0.9098, 0.8118, 1]}},
{"effect": "ec.generate.checkerboard", "set": {"sizeFrom": 0, "corner": [0.11, 20], "color": [0.2196, 0.4, 0.2549, 1], "opacity": 100, "blendingMode": 1}, "expr": {"anchor": "[time*60, 0]"}}
]
},
{
"id": "pulseRings",
"name": "Pulse Rings",
"category": "Backgrounds",
"description": "Soft rings expand from the centre in a steady rhythm.",
"effects": [
{"effect": "ec.generate.fill", "set": {"allMasks": true, "color": [0.0235, 0.0784, 0.1686, 1]}},
{"effect": "ec.generate.circle", "set": {"edge": 2, "thickness": 4, "feather/feather": 3, "color": [0.498, 0.9059, 1.0, 1], "blendingMode": 1}, "expr": {"center": "[thisComp.width/2, thisComp.height/2]", "radius": "((time+0)%3)/3*Math.max(thisComp.width,thisComp.height)*0.7", "opacity": "100*Math.pow(1-((time+0)%3)/3, 1.5)"}},
{"effect": "ec.generate.circle", "set": {"edge": 2, "thickness": 4, "feather/feather": 3, "color": [0.498, 0.9059, 1.0, 1], "blendingMode": 1}, "expr": {"center": "[thisComp.width/2, thisComp.height/2]", "radius": "((time+1)%3)/3*Math.max(thisComp.width,thisComp.height)*0.7", "opacity": "100*Math.pow(1-((time+1)%3)/3, 1.5)"}},
{"effect": "ec.generate.circle", "set": {"edge": 2, "thickness": 4, "feather/feather": 3, "color": [0.498, 0.9059, 1.0, 1], "blendingMode": 1}, "expr": {"center": "[thisComp.width/2, thisComp.height/2]", "radius": "((time+2)%3)/3*Math.max(thisComp.width,thisComp.height)*0.7", "opacity": "100*Math.pow(1-((time+2)%3)/3, 1.5)"}}
]
},
{
"id": "bokehDrift",
"name": "Bokeh Drift",
"category": "Backgrounds",
"description": "Out-of-focus lights float lazily over a dark violet backdrop.",
"effects": [
{"effect": "ec.generate.fill", "set": {"allMasks": true, "color": [0.0784, 0.0627, 0.1647, 1]}},
{"effect": "ec.generate.circle", "set": {"radius": 40, "feather/feather": 70, "color": [1.0, 0.6196, 0.7961, 1], "opacity": 32, "blendingMode": 1}, "expr": {"center": "[thisComp.width*(0.12+0.05*Math.sin(time*0.3+0)), thisComp.height*(0.25+0.07*Math.cos(time*0.25+0))]"}},
{"effect": "ec.generate.circle", "set": {"radius": 49, "feather/feather": 70, "color": [0.5608, 0.8275, 1.0, 1], "opacity": 32, "blendingMode": 1}, "expr": {"center": "[thisComp.width*(0.27+0.05*Math.sin(time*0.41+1)), thisComp.height*(0.6+0.07*Math.cos(time*0.32+2))]"}},
{"effect": "ec.generate.circle", "set": {"radius": 58, "feather/feather": 70, "color": [1.0, 0.8471, 0.5412, 1], "opacity": 32, "blendingMode": 1}, "expr": {"center": "[thisComp.width*(0.42+0.05*Math.sin(time*0.52+2)), thisComp.height*(0.45+0.07*Math.cos(time*0.39+4))]"}},
{"effect": "ec.generate.circle", "set": {"radius": 67, "feather/feather": 70, "color": [0.7137, 0.6118, 1.0, 1], "opacity": 32, "blendingMode": 1}, "expr": {"center": "[thisComp.width*(0.57+0.05*Math.sin(time*0.63+3)), thisComp.height*(0.3+0.07*Math.cos(time*0.46+6))]"}},
{"effect": "ec.generate.circle", "set": {"radius": 76, "feather/feather": 70, "color": [0.5412, 1.0, 0.7569, 1], "opacity": 32, "blendingMode": 1}, "expr": {"center": "[thisComp.width*(0.72+0.05*Math.sin(time*0.74+4)), thisComp.height*(0.65+0.07*Math.cos(time*0.53+8))]"}},
{"effect": "ec.generate.circle", "set": {"radius": 85, "feather/feather": 70, "color": [1.0, 0.6196, 0.4784, 1], "opacity": 32, "blendingMode": 1}, "expr": {"center": "[thisComp.width*(0.87+0.05*Math.sin(time*0.8500000000000001+5)), thisComp.height*(0.5+0.07*Math.cos(time*0.6000000000000001+10))]"}}
]
},
{
"id": "spotlightFloor",
"name": "Spotlight Floor",
"category": "Backgrounds",
"description": "A soft pool of light on a dark floor that gently breathes.",
"effects": [
{"effect": "ec.generate.gradientramp", "set": {"shape": 1, "startColor": [0.2902, 0.3608, 0.5216, 1], "endColor": [0.0196, 0.0275, 0.051, 1]}, "expr": {"start": "[thisComp.width/2, thisComp.height*0.45]", "end": "[thisComp.width/2 + thisComp.width*(0.55+0.04*Math.sin(time*1.3)), thisComp.height*0.45]"}},
{"effect": "ec.stylize.ccvignette", "set": {"amount": 35}}
]
},
{
"id": "dawnSky",
"name": "Dawn Sky",
"category": "Backgrounds",
"description": "A night sky warms into sunrise over six seconds.",
"effects": [
{"effect": "ec.generate.gradientramp", "set": {"start": [0.5, 0.0], "end": [0.5, 1.0]}, "keys": {"startColor": [[0, [0.1216, 0.2275, 0.5412, 1]], [6, [0.3569, 0.5255, 0.8392, 1]]], "endColor": [[0, [0.0118, 0.0157, 0.0471, 1]], [6, [1.0, 0.702, 0.4196, 1]]]}, "ease": true}
]
},
{
"id": "sweepingLight",
"name": "Sweeping Light",
"category": "Backgrounds",
"description": "A band of light sweeps repeatedly across a dark slate backdrop.",
"effects": [
{"effect": "ec.generate.gradientramp", "set": {"startColor": [0.0706, 0.0863, 0.1216, 1], "endColor": [0.1451, 0.1686, 0.2275, 1]}},
{"effect": "ec.generate.cclightsweep", "set": {"direction": -30, "width": 60, "sweepIntensity": 70}, "expr": {"center": "[(time%3)/3*thisComp.width*1.6 - thisComp.width*0.3, thisComp.height/2]"}}
]
},
{
"id": "grainyWash",
"name": "Grainy Wash",
"category": "Backgrounds",
"description": "A muted diagonal wash with live film grain.",
"effects": [
{"effect": "ec.generate.gradientramp", "set": {"start": [0.1, 0.1], "end": [0.9, 0.9], "startColor": [0.9098, 0.8353, 0.7686, 1], "endColor": [0.5451, 0.4353, 0.5608, 1]}},
{"effect": "ec.noise.addgrain", "set": {"tweaking/intensity": 2.2, "tweaking/size": 1.4}},
{"effect": "ec.stylize.ccvignette", "set": {"amount": 25}}
]
}
]
}
@@ -0,0 +1,7 @@
asset: backgrounds.json
title: EffectCraft Backgrounds animation presets (Soft Gradient Drift, Aurora Veil, Slow Fog, Cloud Bank, Dark Smoke, Ember Haze, Magma Flow, Ice Flow, Pastel Plasma, Cell Drift, Crystal Facets, Hex Mosaic, Mirrored Silk, Water Caustics, Blueprint Grid, Checker Scroll, Scrolling Stripes, Pulse Rings, Bokeh Drift, Spotlight Floor, Dawn Sky, Sweeping Light, Grainy Wash)
author: EffectCraft contributors
source: original work
license: MIT OR Apache-2.0
added: 2026-10-12 by vangel76 (Claude Code agent, gap 7, #1096)
notes: Effect choices, colours, values and expressions written from scratch for EffectCraft on its own generator, noise, colour and stylize effects; not derived from any Adobe preset (.ffx) or its values.
+38 -13
View File
@@ -1,14 +1,18 @@
//! EffectCraft's own animation preset library (Effects & Presets ▸ * Animation Presets): the
//! Transitions category, original presets built on our Transition effects and layer opacity.
//! Transitions category (original presets built on our Transition effects and layer opacity) and
//! the Backgrounds category (generators, noise and colour effects driven by expressions).
//!
//! Each preset adds effects (with values and keyframes) and/or keys layer properties, starting
//! at the current time, on every selected layer. The library is data
//! (`presets/transitions.json`), written from scratch; nothing comes from After Effects' `.ffx`
//! presets.
//! (`presets/*.json`), written from scratch; nothing comes from After Effects' `.ffx` presets.
//!
//! A preset effect or layer block has `set` (static values), `keys` (`[[seconds, value], …]`
//! from the current time), `expr` (an expression text per property) and `ease`. Values of
//! point parameters are fractions of the layer size, like the effects' own defaults.
use effectcraft_keyframe::Keyframe;
use effectcraft_project::build::Ids;
use effectcraft_project::{Node, Property};
use effectcraft_project::{Expression, Node, ParamUi, Property, Value as KV};
use effectcraft_time::Tick;
use serde_json::{Map, Value, json};
@@ -19,11 +23,19 @@ use crate::{EngineError, Result, Session, cmd, query};
/// The original transition presets (`presets/transitions.json`).
pub const TRANSITIONS_JSON: &str = include_str!("../../presets/transitions.json");
/// The original background presets (`presets/backgrounds.json`).
pub const BACKGROUNDS_JSON: &str = include_str!("../../presets/backgrounds.json");
/// Keys per animated property, so a hostile inline preset can't allocate without bound.
const MAX_KEYS: usize = 256;
/// Longest expression text an inline preset may carry.
const MAX_EXPR: usize = 4096;
fn presets() -> Vec<Value> {
serde_json::from_str::<Value>(TRANSITIONS_JSON).ok().and_then(|v| v.get("presets").and_then(Value::as_array).cloned()).unwrap_or_default()
[TRANSITIONS_JSON, BACKGROUNDS_JSON]
.iter()
.flat_map(|src| serde_json::from_str::<Value>(src).ok().and_then(|v| v.get("presets").and_then(Value::as_array).cloned()).unwrap_or_default())
.collect()
}
fn text<'a>(v: &'a Value, key: &str) -> Option<&'a str> {
@@ -44,11 +56,16 @@ fn find_preset(want: &str) -> Option<Value> {
/// Set `pr` to `v` (when given) and replace its keys with `keys` (`[[seconds, value], …]`,
/// seconds from `at`). Returns false when nothing in the request fits the property.
fn set_prop(pr: &mut Property, v: Option<&Value>, keys: Option<&Value>, at: Tick, ease: bool) -> bool {
fn set_prop(pr: &mut Property, v: Option<&Value>, keys: Option<&Value>, at: Tick, ease: bool, size: [f64; 2]) -> bool {
// Point parameters are written as fractions of the layer size.
let scale = |val: KV| match val {
KV::Vec2(f) if matches!(pr.ui, ParamUi::Point) => KV::Vec2([f[0] * size[0], f[1] * size[1]]),
other => other,
};
let mut ok = true;
if let Some(v) = v {
match json_value(v, &pr.value) {
Some(val) => pr.value = val,
Some(val) => pr.value = scale(val),
None => ok = false,
}
}
@@ -58,7 +75,7 @@ fn set_prop(pr: &mut Property, v: Option<&Value>, keys: Option<&Value>, at: Tick
for k in list.iter().take(MAX_KEYS) {
let t = k.get(0).and_then(Value::as_f64).filter(|t| t.is_finite() && t.abs() <= 86_400.0);
let (Some(t), Some(val)) = (t, k.get(1).and_then(|x| json_value(x, &pr.value))) else { return false };
let mut key = Keyframe::new(at + Tick::from_seconds_f64(t), val);
let mut key = Keyframe::new(at + Tick::from_seconds_f64(t), scale(val));
if pr.hold_only {
key = key.hold();
} else if ease {
@@ -76,22 +93,30 @@ fn set_prop(pr: &mut Property, v: Option<&Value>, keys: Option<&Value>, at: Tick
/// Apply `set` / `keys` maps to the properties under `root`; returns the paths that don't exist
/// or don't take the given values.
fn apply_maps(root: &mut effectcraft_project::PropGroup, spec: &Value, at: Tick) -> Vec<String> {
fn apply_maps(root: &mut effectcraft_project::PropGroup, spec: &Value, at: Tick, size: [f64; 2]) -> Vec<String> {
let ease = spec.get("ease").and_then(Value::as_bool).unwrap_or(false);
let empty = Map::new();
let set = spec.get("set").and_then(Value::as_object).unwrap_or(&empty);
let keys = spec.get("keys").and_then(Value::as_object).unwrap_or(&empty);
let exprs = spec.get("expr").and_then(Value::as_object).unwrap_or(&empty);
let mut skipped = Vec::new();
for (path, v) in set {
if !root.prop_mut(path).is_some_and(|pr| set_prop(pr, Some(v), None, at, false)) {
if !root.prop_mut(path).is_some_and(|pr| set_prop(pr, Some(v), None, at, false, size)) {
skipped.push(path.clone());
}
}
for (path, list) in keys {
if !root.prop_mut(path).is_some_and(|pr| !pr.static_only && set_prop(pr, None, Some(list), at, ease)) {
if !root.prop_mut(path).is_some_and(|pr| !pr.static_only && set_prop(pr, None, Some(list), at, ease, size)) {
skipped.push(path.clone());
}
}
for (path, text) in exprs {
let body = text.as_str().filter(|t| !t.trim().is_empty() && t.len() <= MAX_EXPR);
match (root.prop_mut(path), body) {
(Some(pr), Some(body)) if !pr.static_only => pr.expr = Some(Expression { text: body.to_string(), enabled: true }),
_ => skipped.push(path.clone()),
}
}
skipped
}
@@ -134,13 +159,13 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {
let same = fx.groups().filter(|g| g.match_id == spec.id).count();
let inst = if same == 0 { spec.name.to_string() } else { format!("{} {}", spec.name, same.saturating_add(1)) };
let mut g = effectcraft_effects::instantiate(spec, &mut Ids(&mut next), &inst, *size);
skipped.extend(apply_maps(&mut g, ej, at).into_iter().map(|path| format!("{}/{path}", spec.id)));
skipped.extend(apply_maps(&mut g, ej, at, *size).into_iter().map(|path| format!("{}/{path}", spec.id)));
added.push(g.uid);
fx.children.push(Node::Group(g));
}
}
if let Some(ls) = &layer_spec {
skipped.extend(apply_maps(&mut l.props, ls, at));
skipped.extend(apply_maps(&mut l.props, ls, at, *size));
}
proj.next_id = next;
}
+55 -1
View File
@@ -27,7 +27,7 @@ fn every_transition_preset_applies_and_transitions() {
let list = s.execute("anim.builtinPresets", json!({"category": "Transitions"})).unwrap();
let list = list.as_array().unwrap().clone();
assert!(list.len() >= 20, "{}", list.len());
assert_eq!(crate::animation_presets().len(), list.len());
assert_eq!(crate::animation_presets().iter().filter(|(_, _, c)| c == "Transitions").count(), list.len());
let start = 0.5;
for p in &list {
let id = p["id"].as_str().unwrap();
@@ -72,3 +72,57 @@ fn transition_preset_by_name_and_bad_input() {
let cam = s.execute("layer.newCamera", json!({})).unwrap()["layer"].as_u64().unwrap();
assert!(s.execute("anim.applyBuiltinPreset", json!({"layers": [cam], "preset": "clockReveal"})).is_err());
}
/// Every preset's id and name are unique across the whole library (ids key the panel's
/// automation ids), each sits in a known category, and Text ids don't clash with them.
#[test]
fn preset_catalogue_is_unique_and_categorised() {
let all = crate::animation_presets();
let known = ["Transitions", "Backgrounds"];
let mut ids = std::collections::HashSet::new();
let mut names = std::collections::HashSet::new();
for (id, name, cat) in &all {
assert!(known.contains(&cat.as_str()), "{id}: unknown category {cat}");
assert!(ids.insert(id.to_lowercase()), "duplicate id {id}");
assert!(names.insert(name.to_lowercase()), "duplicate name {name}");
}
for (id, name) in crate::text_presets() {
assert!(!ids.contains(&id.to_lowercase()) && !names.contains(&name.to_lowercase()), "text preset {id} clashes");
}
let n = |c: &str| all.iter().filter(|(_, _, k)| k == c).count();
assert!(n("Backgrounds") >= 15 && n("Transitions") >= 20);
}
#[test]
fn every_background_preset_applies_and_undoes() {
let (mut s, solid) = session();
let list = s.execute("anim.builtinPresets", json!({"category": "Backgrounds"})).unwrap();
let list = list.as_array().unwrap().clone();
assert!(list.len() >= 15, "{}", list.len());
for p in &list {
let id = p["id"].as_str().unwrap();
let r = s.execute("anim.applyBuiltinPreset", json!({"layers": [solid], "preset": id})).unwrap();
assert_eq!(r["skipped"], json!([]), "{id}: every path and expression in the preset applies");
let n = r["effects"].as_array().unwrap().len();
assert!(n >= 1, "{id}");
assert_eq!(s.active_comp().unwrap().layers[0].effects().unwrap().groups().count(), n, "{id}");
s.execute("edit.undo", json!({})).unwrap();
let l = &s.active_comp().unwrap().layers[0];
assert_eq!(l.effects().map_or(0, |fx| fx.groups().count()), 0, "{id}: undo removes the effects");
s.execute("edit.redo", json!({})).unwrap();
s.execute("edit.undo", json!({})).unwrap();
}
}
#[test]
fn preset_expressions_and_point_fractions() {
let (mut s, solid) = session();
s.execute("anim.applyBuiltinPreset", json!({"layers": [solid], "preset": "Spotlight Floor"})).unwrap();
let fx = s.active_comp().unwrap().layers[0].effects().unwrap().groups().next().unwrap().clone();
assert!(fx.prop("start").unwrap().has_expression());
// A point written as a fraction of the layer: Sunrise-style presets keep their defaults at 160x90.
s.execute("anim.applyBuiltinPreset", json!({"layers": [solid], "preset": "dawnSky"})).unwrap();
let ramp = s.active_comp().unwrap().layers[0].effects().unwrap().groups().nth(2).unwrap().clone();
assert_eq!(ramp.prop("end").unwrap().value, effectcraft_keyframe::Value::Vec2([80.0, 90.0]));
assert_eq!(ramp.prop("startColor").unwrap().keys.len(), 2);
}