M9.6: text animation depth (selectors, animator properties, per-char 3D, path text, presets)

Range selector complete (units, based on, modes, shapes, smoothness, ease
high/low, randomize), Wiggly and Expression selectors combined by mode;
all AE animator properties incl. line anchor, character offset/value,
skew axis, tracking type, fill/stroke HSB+opacity, blur; More Options
(anchor grouping, fill & stroke order, inter-character blending); Path
Options (text on a mask path); per-character 3D rendered as planes in
the 3D compositor; text animation commands and original presets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-02 00:01:19 -04:00
co-authored by Claude Opus 5.5
parent d73f199f38
commit c5cf189e1a
24 changed files with 2912 additions and 284 deletions
-35
View File
@@ -816,32 +816,6 @@ fn set_text(s: &mut Session, p: &Value) -> Result<Value> {
Ok(Value::Null)
}
fn add_animator(s: &mut Session, p: &Value) -> Result<Value> {
let (cid, lid) = layer_p(s, p, "layer.addTextAnimator")?;
let props: Vec<String> = match p.get("properties").or(p.get("property")) {
Some(Value::Array(a)) => a.iter().filter_map(|v| v.as_str().map(str::to_string)).collect(),
Some(Value::String(x)) => vec![x.clone()],
_ => vec!["opacity".into()],
};
let uid = s.edit("Add Text Animator", None, |proj, _| {
let mut next = proj.next_id;
let mut ids = Ids(&mut next);
let list: Vec<_> = props.iter().filter_map(|k| build::text_anim_prop(&mut ids, k)).collect();
if list.is_empty() {
return Err(bad("layer.addTextAnimator", "unknown animator property"));
}
let l = layer_mut(proj, cid, lid)?;
let anims = l.props.group_mut("text/animators").ok_or_else(|| bad("layer.addTextAnimator", "not a text layer"))?;
let name = format!("Animator {}", anims.children.len() + 1);
let g = build::text_animator(&mut ids, &name, list);
let uid = g.uid;
anims.children.push(g.into());
proj.next_id = next;
Ok(uid)
})?;
Ok(json!({"animator": uid}))
}
fn transform_op(s: &mut Session, p: &Value) -> Result<Value> {
let (cid, ids) = layers_p(s, p)?;
let op = str_p(p, "op").unwrap_or("reset").to_string();
@@ -1019,15 +993,6 @@ pub fn specs() -> Vec<CommandSpec> {
has_layers,
set_text
),
cmd!(
"layer.addTextAnimator",
"Animate Text",
["Animation"],
None,
"{layer?, properties: [position|scale|rotation|opacity|fillColor|tracking|…]}",
has_layers,
add_animator
),
cmd!(
"layer.transform",
"Transform",
+2
View File
@@ -14,6 +14,7 @@ mod mask;
mod prop;
mod query;
mod render_queue;
mod text_anim;
mod three_d;
mod time;
@@ -75,6 +76,7 @@ pub fn command_specs() -> &'static [CommandSpec] {
v.extend(comp::specs());
v.extend(layer::specs());
v.extend(three_d::specs());
v.extend(text_anim::specs());
v.extend(layer_time::specs());
v.extend(prop::specs());
v.extend(anim::specs());
+423
View File
@@ -0,0 +1,423 @@
//! Text animation: Animation ▸ Animate Text / Add Text Selector, the Timeline's "Animate:" and
//! "Add:" pop-ups, Enable Per-character 3D, and EffectCraft's own text animator presets.
use effectcraft_keyframe::{Keyframe, Value as KV};
use effectcraft_project::build::{self, Ids};
use effectcraft_project::{Layer, LayerSource, Node, PropGroup};
use effectcraft_time::Tick;
use serde_json::{Value, json};
use super::{CommandSpec, b_p, bad, has_comp, layer_mut, layer_p, str_p};
use crate::{Result, Session, cmd, query};
/// The original text animator presets (`presets/text_animators.json`).
pub const PRESETS_JSON: &str = include_str!("../../presets/text_animators.json");
fn presets() -> Vec<Value> {
serde_json::from_str::<Value>(PRESETS_JSON).ok().and_then(|v| v.get("presets").and_then(Value::as_array).cloned()).unwrap_or_default()
}
/// Enabled when a text layer is selected.
fn has_text_layer(s: &Session) -> std::result::Result<(), String> {
has_comp(s)?;
let comp = s.active_comp().ok_or("no composition is open")?;
if s.state.selected_layers.iter().any(|id| comp.layer(*id).is_some_and(|l| matches!(l.source, LayerSource::Text))) {
Ok(())
} else {
Err("select a text layer first".into())
}
}
/// Enabled when a selected text layer has an animator.
fn has_animator(s: &Session) -> std::result::Result<(), String> {
has_text_layer(s)?;
let comp = s.active_comp().ok_or("no composition is open")?;
let any =
s.state.selected_layers.iter().filter_map(|id| comp.layer(*id)).any(|l| l.props.group("text/animators").is_some_and(|a| a.groups().next().is_some()));
if any { Ok(()) } else { Err("add a text animator first".into()) }
}
fn per_char_on(l: &Layer) -> bool {
l.props.prop("text/perChar3d").is_some_and(|p| p.value.as_bool())
}
/// The animator a command targets: `animator` (uid or 1-based index), else the animator holding
/// a selected property, else the last one.
fn animator_uid(s: &Session, l: &Layer, p: &Value, cmd: &str) -> Result<u64> {
let anims = l.props.group("text/animators").ok_or_else(|| bad(cmd, "not a text layer"))?;
let list: Vec<&PropGroup> = anims.groups().collect();
if let Some(v) = p.get("animator") {
let n = v.as_u64().ok_or_else(|| bad(cmd, "`animator` must be a uid or 1-based index"))?;
if let Some(g) = list.iter().find(|g| g.uid == n) {
return Ok(g.uid);
}
return list.get((n as usize).wrapping_sub(1)).map(|g| g.uid).ok_or_else(|| bad(cmd, format!("no animator {n}")));
}
for (lid, uid) in &s.state.selected_props {
if *lid != l.id {
continue;
}
if let Some(g) = list.iter().find(|g| g.uid == *uid || g.find(*uid).is_some() || g.find_group(*uid).is_some()) {
return Ok(g.uid);
}
}
list.last().map(|g| g.uid).ok_or_else(|| bad(cmd, "the layer has no text animators"))
}
/// Add the properties of `kind` to an animator's Properties group (skipping ones it has).
fn add_props(ids: &mut Ids, anim: &mut PropGroup, kind: &str, three_d: bool) -> usize {
let list = build::text_anim_props(ids, kind, three_d);
let props = match anim.sub_mut("properties") {
Some(p) => p,
None => {
let g = ids.group("properties", "Properties");
anim.children.push(g.into());
anim.sub_mut("properties").expect("just added")
}
};
let mut n = 0;
for pr in list {
if props.get(&pr.match_id).is_none() {
props.children.push(pr.into());
n += 1;
}
}
n
}
fn kinds_p(p: &Value) -> Vec<String> {
match p.get("properties").or(p.get("property")) {
Some(Value::Array(a)) => a.iter().filter_map(|v| v.as_str().map(str::to_string)).collect(),
Some(Value::String(x)) => vec![x.clone()],
_ => vec!["opacity".into()],
}
}
fn add_animator(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "layer.addTextAnimator";
let (cid, lid) = layer_p(s, p, C)?;
let kinds = kinds_p(p);
if kinds.iter().any(|k| k == "perChar3d") {
return enable_per_char(s, &json!({"layer": lid.0, "comp": cid.0}));
}
let uid = s.edit("Add Text Animator", None, |proj, _| {
let mut next = proj.next_id;
let mut ids = Ids(&mut next);
let l = layer_mut(proj, cid, lid)?;
let three = per_char_on(l);
let anims = l.props.group_mut("text/animators").ok_or_else(|| bad(C, "not a text layer"))?;
let name = str_p(p, "name").map(str::to_string).unwrap_or_else(|| format!("Animator {}", anims.children.len() + 1));
let mut g = build::text_animator(&mut ids, &name, vec![]);
let added: usize = kinds.iter().map(|k| add_props(&mut ids, &mut g, k, three)).sum();
if added == 0 {
return Err(bad(C, "unknown animator property"));
}
let uid = g.uid;
anims.children.push(g.into());
proj.next_id = next;
Ok(uid)
})?;
Ok(json!({"animator": uid}))
}
fn add_animator_prop(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "layer.addTextAnimatorProperty";
let (cid, lid) = layer_p(s, p, C)?;
let kinds = kinds_p(p);
if let Some(k) = kinds.iter().find(|k| !build::TEXT_ANIMATOR_KINDS.iter().any(|(id, _)| id == k)) {
return Err(bad(C, format!("unknown animator property {k}")));
}
let layer = s.project.comp(cid).and_then(|c| c.layer(lid)).cloned().ok_or_else(|| bad(C, "no layer"))?;
let auid = animator_uid(s, &layer, p, C)?;
s.edit("Add Text Animator Property", None, |proj, _| {
let mut next = proj.next_id;
let mut ids = Ids(&mut next);
let l = layer_mut(proj, cid, lid)?;
let three = per_char_on(l);
let anim = l.props.find_group_mut(auid).ok_or_else(|| bad(C, "no such animator"))?;
for k in &kinds {
add_props(&mut ids, anim, k, three);
}
proj.next_id = next;
Ok(())
})?;
Ok(json!({"animator": auid}))
}
fn add_selector(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "layer.addTextSelector";
let (cid, lid) = layer_p(s, p, C)?;
let kind = str_p(p, "kind").unwrap_or("range").to_ascii_lowercase();
let layer = s.project.comp(cid).and_then(|c| c.layer(lid)).cloned().ok_or_else(|| bad(C, "no layer"))?;
let auid = animator_uid(s, &layer, p, C)?;
let uid = s.edit("Add Text Selector", None, |proj, _| {
let mut next = proj.next_id;
let mut ids = Ids(&mut next);
let l = layer_mut(proj, cid, lid)?;
let anim = l.props.find_group_mut(auid).ok_or_else(|| bad(C, "no such animator"))?;
let sels = match anim.sub_mut("selectors") {
Some(g) => g,
None => {
let g = ids.group("selectors", "Selectors");
anim.children.insert(0, g.into());
anim.sub_mut("selectors").expect("just added")
}
};
let (m, label) = match kind.as_str() {
"range" => ("rangeSelector", "Range Selector"),
"wiggly" => ("wigglySelector", "Wiggly Selector"),
"expression" => ("expressionSelector", "Expression Selector"),
_ => return Err(bad(C, "kind must be range, wiggly or expression")),
};
let n = sels.groups().filter(|g| g.match_id == m).count() + 1;
let g = build::text_selector(&mut ids, &kind, &format!("{label} {n}")).ok_or_else(|| bad(C, "unknown selector kind"))?;
let uid = g.uid;
sels.children.push(g.into());
proj.next_id = next;
Ok(uid)
})?;
Ok(json!({"selector": uid, "animator": auid}))
}
/// Show / hide Z components and X / Y rotation on every animator.
fn set_animators_3d(ids: &mut Ids, l: &mut Layer, on: bool) {
let Some(anims) = l.props.group_mut("text/animators") else { return };
for c in anims.children.iter_mut() {
let Node::Group(a) = c else { continue };
let Some(props) = a.sub_mut("properties") else { continue };
for c in props.children.iter_mut() {
if let Node::Prop(p) = c
&& matches!(p.match_id.as_str(), "anchor" | "position" | "scale")
{
p.shown_dims = if on { 3 } else { 2 };
if let KV::Vec2(v) = p.value {
p.value = KV::Vec3([v[0], v[1], if p.match_id == "scale" { 100.0 } else { 0.0 }]);
}
}
}
let has_rot = props.get("rotation").is_some();
if on && has_rot && props.get("rotationX").is_none() {
let at = props.children.iter().position(|c| c.match_id() == "rotation").unwrap_or(0);
let rx = ids.prop("rotationX", "X Rotation", KV::Scalar(0.0)).with_ui(effectcraft_project::ParamUi::Angle);
let ry = ids.prop("rotationY", "Y Rotation", KV::Scalar(0.0)).with_ui(effectcraft_project::ParamUi::Angle);
props.children.insert(at, ry.into());
props.children.insert(at, rx.into());
}
if !on {
props.children.retain(|c| !matches!(c.match_id(), "rotationX" | "rotationY"));
}
if let Some(r) = props.get_mut("rotation") {
r.name = if on { "Z Rotation".into() } else { "Rotation".into() };
}
}
}
fn enable_per_char(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "layer.enablePerChar3D";
let (cid, lid) = layer_p(s, p, C)?;
let cur = s.project.comp(cid).and_then(|c| c.layer(lid)).map(per_char_on).unwrap_or(false);
let on = b_p(p, "enabled").unwrap_or(if p.get("toggle").and_then(Value::as_bool) == Some(true) { !cur } else { true });
s.edit(if on { "Enable Per-character 3D" } else { "Disable Per-character 3D" }, None, |proj, _| {
let mut next = proj.next_id;
let mut ids = Ids(&mut next);
let l = layer_mut(proj, cid, lid)?;
if !matches!(l.source, LayerSource::Text) {
return Err(bad(C, "not a text layer"));
}
if l.props.prop("text/perChar3d").is_none() {
let mut pc = ids.prop("perChar3d", "Per-character 3D", KV::Bool(false)).with_ui(effectcraft_project::ParamUi::Hidden);
pc.static_only = true;
if let Some(t) = l.props.sub_mut("text") {
t.children.insert(1, pc.into());
}
}
if let Some(pr) = l.props.prop_mut("text/perChar3d") {
pr.value = KV::Bool(on);
}
// Per-character 3D makes the layer 3D (as in AE).
if on {
l.switches.three_d = true;
}
set_animators_3d(&mut ids, l, on);
proj.next_id = next;
Ok(())
})?;
Ok(json!({"perChar3d": on}))
}
/// JSON → property value shaped like `like`.
fn json_value(v: &Value, like: &KV) -> Option<KV> {
Some(match v {
Value::Bool(b) => match like {
KV::Bool(_) => KV::Bool(*b),
_ => KV::Scalar(if *b { 1.0 } else { 0.0 }),
},
Value::Number(n) => {
let x = n.as_f64()?;
match like {
KV::Enum(_) => KV::Enum(x.max(0.0) as u32),
KV::Bool(_) => KV::Bool(x != 0.0),
_ => KV::Scalar(x),
}
}
Value::Array(a) => {
let c: Vec<f64> = a.iter().filter_map(Value::as_f64).collect();
like.with_components(&c)
}
_ => return None,
})
}
fn set_path(g: &mut PropGroup, path: &str, v: &Value, keys: Option<&Value>, at: Tick, ease: bool) {
let Some(pr) = g.prop_mut(path) else { return };
if let Some(val) = json_value(v, &pr.value) {
pr.value = val;
}
let Some(Value::Array(list)) = keys else { return };
let mut ks = Vec::new();
for k in list {
let (Some(t), Some(val)) = (k.get(0).and_then(Value::as_f64), k.get(1).and_then(|x| json_value(x, &pr.value))) else { continue };
let mut key = Keyframe::new(at + Tick::from_seconds_f64(t), val);
if pr.hold_only {
key = key.hold();
} else if ease {
key = key.eased();
}
ks.push(key);
}
if !ks.is_empty() {
pr.value = ks[0].value.clone();
pr.keys = ks;
}
}
fn apply_preset(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "layer.applyTextPreset";
let (cid, lid) = layer_p(s, p, C)?;
let want = str_p(p, "preset").ok_or_else(|| bad(C, "`preset` id or name required"))?.to_string();
let preset = presets()
.into_iter()
.find(|x| x.get("id").and_then(Value::as_str) == Some(&want) || x.get("name").and_then(Value::as_str).is_some_and(|n| n.eq_ignore_ascii_case(&want)))
.ok_or_else(|| bad(C, format!("no preset {want}")))?;
let name = preset.get("name").and_then(Value::as_str).unwrap_or("Preset").to_string();
let now = s.time();
let uids = s.edit(&format!("Apply Text Preset {name}"), None, |proj, _| {
let mut next = proj.next_id;
let mut ids = Ids(&mut next);
let l = layer_mut(proj, cid, lid)?;
let at = l.layer_time(now);
let three = per_char_on(l);
let anims_json = preset.get("animators").and_then(Value::as_array).cloned().unwrap_or_default();
let anims = l.props.group_mut("text/animators").ok_or_else(|| bad(C, "not a text layer"))?;
let mut uids = Vec::new();
for a in &anims_json {
let aname = a.get("name").and_then(Value::as_str).unwrap_or("Animator");
let mut g = build::text_animator(&mut ids, aname, vec![]);
let ease = a.get("ease").and_then(Value::as_bool).unwrap_or(false);
if let Some(Value::Object(props)) = a.get("properties") {
for (m, v) in props {
add_props(&mut ids, &mut g, m, three);
let keys = a.get("keys").and_then(|k| k.get(m));
if let Some(pg) = g.sub_mut("properties") {
set_path(pg, m, v, keys, at, ease);
}
}
}
for (i, sj) in a.get("selectors").and_then(Value::as_array).cloned().unwrap_or_default().iter().enumerate() {
let kind = sj.get("kind").and_then(Value::as_str).unwrap_or("range");
let Some(sels) = g.sub_mut("selectors") else { continue };
if !(i == 0 && kind == "range") {
let label = match kind {
"wiggly" => "Wiggly Selector 1",
"expression" => "Expression Selector 1",
_ => "Range Selector 2",
};
if let Some(sg) = build::text_selector(&mut ids, kind, label) {
sels.children.push(sg.into());
}
}
let Some(Node::Group(sel)) = sels.children.last_mut() else { continue };
let ease = sj.get("ease").and_then(Value::as_bool).unwrap_or(false);
if let Some(Value::Object(set)) = sj.get("set") {
for (path, v) in set {
set_path(sel, path, v, None, at, ease);
}
}
if let Some(Value::Object(keys)) = sj.get("keys") {
for (path, list) in keys {
let cur = sel.prop(path).map(|p| p.value.clone());
if let Some(cur) = cur {
let v = serde_json::to_value(cur.components().first().copied().unwrap_or(0.0)).unwrap_or_default();
set_path(sel, path, &v, Some(list), at, ease);
}
}
}
}
uids.push(g.uid);
anims.children.push(g.into());
}
proj.next_id = next;
Ok(uids)
})?;
Ok(json!({"animators": uids}))
}
fn list_presets(_: &mut Session, _: &Value) -> Result<Value> {
Ok(Value::Array(presets().iter().map(|p| json!({"id": p.get("id"), "name": p.get("name"), "description": p.get("description")})).collect()))
}
fn list_kinds(_: &mut Session, _: &Value) -> Result<Value> {
Ok(Value::Array(build::TEXT_ANIMATOR_KINDS.iter().filter(|(k, _)| *k != "-").map(|(k, l)| json!({"property": k, "label": l})).collect()))
}
pub fn specs() -> Vec<CommandSpec> {
vec![
cmd!(
"layer.addTextAnimator",
"Animate Text",
[],
None,
"{layer?, properties: [anchor|position|scale|skew|rotation|opacity|transformAll|lineAnchor|lineSpacing|characterOffset|characterValue|blur|fillColor|fillHue|fillSaturation|fillBrightness|fillOpacity|strokeColor|strokeHue|strokeSaturation|strokeBrightness|strokeOpacity|strokeWidth|tracking|perChar3d], name?}",
has_text_layer,
add_animator
),
cmd!(
"layer.addTextAnimatorProperty",
"Add Property",
[],
None,
"{layer?, animator?: uid|index, property: (see layer.addTextAnimator)}",
has_animator,
add_animator_prop
),
cmd!(
"layer.addTextSelector",
"Add Text Selector",
[],
None,
"{layer?, animator?: uid|index, kind: range|wiggly|expression}",
has_animator,
add_selector
),
cmd!(
"layer.enablePerChar3D",
"Enable Per-character 3D",
["Animation", "Animate Text"],
None,
"{layer?, enabled?: bool, toggle?: bool}",
has_text_layer,
enable_per_char
),
cmd!(
"layer.applyTextPreset",
"Apply Text Animation Preset",
[],
None,
"{layer?, preset: typewriter|fadeUpCharacters|bounceInWords|trackingIn|scramble|blurIn|jitter|dropInLines}",
has_text_layer,
apply_preset
),
query!("text.presets", "Text Animation Presets", "{}", list_presets),
query!("text.animatorProperties", "Text Animator Properties", "{}", list_kinds),
]
}
+2 -2
View File
@@ -383,7 +383,7 @@ pub fn demo_project() -> Project {
{
let mut ids = Ids(&mut next);
let pos = build::text_anim_prop(&mut ids, "position").map(|mut pr| {
pr.value = Value::Vec2([0.0, 90.0]);
pr.value = Value::Vec3([0.0, 90.0, 0.0]);
pr
});
let op = build::text_anim_prop(&mut ids, "opacity").map(|mut pr| {
@@ -391,7 +391,7 @@ pub fn demo_project() -> Project {
pr
});
let sc = build::text_anim_prop(&mut ids, "scale").map(|mut pr| {
pr.value = Value::Vec2([60.0, 60.0]);
pr.value = Value::Vec3([60.0, 60.0, 100.0]);
pr
});
let mut a = build::text_animator(&mut ids, "Animator 1", [pos, op, sc].into_iter().flatten().collect());
+2
View File
@@ -419,6 +419,8 @@ mod tests;
#[cfg(test)]
mod tests_3d;
#[cfg(test)]
mod tests_text;
#[cfg(test)]
mod tests_timeline;
/// Font families available to text layers (bundled + scanned system fonts).
+172
View File
@@ -0,0 +1,172 @@
//! Text animation commands: animators, properties, selectors, per-character 3D, presets (with
//! undo/redo and serde round-trips).
use effectcraft_keyframe::Value as KV;
use effectcraft_project::{Node, Project, PropGroup};
use serde_json::json;
use crate::Session;
fn session() -> (Session, u64) {
let mut s = Session::default();
s.execute("comp.new", json!({"name": "C", "width": 640, "height": 360, "duration": 4})).unwrap();
let t = s.execute("layer.newText", json!({"text": "Hello World", "size": 60})).unwrap()["layer"].as_u64().unwrap();
(s, t)
}
fn text_group(s: &Session) -> PropGroup {
s.active_comp().unwrap().layers[0].props.sub("text").unwrap().clone()
}
fn matches(g: &PropGroup) -> Vec<String> {
g.children.iter().map(|c| c.match_id().to_string()).collect()
}
#[test]
fn animate_text_adds_animators_with_companion_properties() {
let (mut s, t) = session();
let r = s.execute("layer.addTextAnimator", json!({"layer": t, "properties": ["skew", "tracking", "characterOffset"]})).unwrap();
assert!(r["animator"].as_u64().is_some());
let tg = text_group(&s);
let a = tg.group("animators/#1").unwrap();
assert_eq!(
matches(a.sub("properties").unwrap()),
["skew", "skewAxis", "trackingType", "tracking", "characterAlignment", "characterRange", "characterOffset"]
);
assert_eq!(matches(a.sub("selectors").unwrap()), ["rangeSelector"]);
// Every Animate entry is accepted.
for (k, _) in effectcraft_project::build::TEXT_ANIMATOR_KINDS.iter().filter(|(k, _)| *k != "-") {
s.execute("layer.addTextAnimator", json!({"layer": t, "property": k})).unwrap_or_else(|e| panic!("{k}: {e}"));
}
assert!(s.execute("layer.addTextAnimator", json!({"layer": t, "property": "nope"})).is_err());
// All Transform Properties.
s.execute("layer.addTextAnimator", json!({"layer": t, "property": "transformAll"})).unwrap();
let tg = text_group(&s);
let last = tg.sub("animators").unwrap().groups().last().unwrap().clone();
assert_eq!(matches(last.sub("properties").unwrap()), ["anchor", "position", "scale", "skew", "skewAxis", "rotation", "opacity"]);
// Rendering with every property present works.
let cid = s.active_comp_id().unwrap();
let _ = s.render(cid, s.time(), Default::default());
}
#[test]
fn add_property_and_selectors_with_undo_redo() {
let (mut s, t) = session();
s.execute("layer.addTextAnimator", json!({"layer": t, "property": "position"})).unwrap();
s.execute("layer.addTextAnimatorProperty", json!({"layer": t, "animator": 1, "property": "fillHue"})).unwrap();
assert!(s.execute("layer.addTextAnimatorProperty", json!({"layer": t, "animator": 1, "property": "bogus"})).is_err());
for kind in ["wiggly", "expression", "range"] {
s.execute("layer.addTextSelector", json!({"layer": t, "kind": kind})).unwrap();
}
assert!(s.execute("layer.addTextSelector", json!({"layer": t, "kind": "other"})).is_err());
let tg = text_group(&s);
let a = tg.group("animators/#1").unwrap();
assert_eq!(matches(a.sub("properties").unwrap()), ["position", "fillHue"]);
let sels = a.sub("selectors").unwrap();
assert_eq!(matches(sels), ["rangeSelector", "wigglySelector", "expressionSelector", "rangeSelector"]);
let names: Vec<&str> = sels.children.iter().map(Node::name).collect();
assert_eq!(names, ["Range Selector 1", "Wiggly Selector 1", "Expression Selector 1", "Range Selector 2"]);
// Expression selector carries the default amount expression; wiggly defaults to Intersect.
let ex = sels.group("expressionSelector").unwrap();
assert!(ex.get("amount").unwrap().has_expression());
assert_eq!(sels.group("wigglySelector").unwrap().get("mode").unwrap().value, KV::Enum(2));
let cid = s.active_comp_id().unwrap();
let a1 = s.render(cid, s.time(), Default::default());
let a2 = s.render(cid, s.time(), Default::default());
assert_eq!(a1.data, a2.data, "wiggly text renders deterministically");
// Undo the three selector additions and the property, redo them.
for _ in 0..3 {
s.execute("edit.undo", json!({})).unwrap();
}
assert_eq!(matches(text_group(&s).group("animators/#1/selectors").unwrap()), ["rangeSelector"]);
s.execute("edit.undo", json!({})).unwrap();
assert_eq!(matches(text_group(&s).group("animators/#1/properties").unwrap()), ["position"]);
for _ in 0..4 {
s.execute("edit.redo", json!({})).unwrap();
}
assert_eq!(text_group(&s).group("animators/#1/selectors").unwrap().children.len(), 4);
}
#[test]
fn per_character_3d_toggles_layer_and_dimensions() {
let (mut s, t) = session();
s.execute("layer.addTextAnimator", json!({"layer": t, "properties": ["position", "rotation"]})).unwrap();
s.execute("layer.enablePerChar3D", json!({"layer": t})).unwrap();
let l = s.active_comp().unwrap().layers[0].clone();
assert!(l.switches.three_d);
assert_eq!(l.props.prop("text/perChar3d").unwrap().value, KV::Bool(true));
let props = l.props.group("text/animators/#1/properties").unwrap();
assert_eq!(props.get("position").unwrap().shown_dims, 3);
assert_eq!(matches(props), ["position", "rotationX", "rotationY", "rotation"]);
assert_eq!(props.get("rotation").unwrap().name, "Z Rotation");
// New animators get 3D properties too.
s.execute("layer.addTextAnimator", json!({"layer": t, "property": "rotation"})).unwrap();
assert_eq!(matches(text_group(&s).group("animators/#2/properties").unwrap()), ["rotationX", "rotationY", "rotation"]);
// Renders through the 3D path.
s.execute("prop.set", json!({"layer": t, "path": "text/animators/#1/properties/rotationY", "value": 45})).unwrap();
let cid = s.active_comp_id().unwrap();
let img = s.render(cid, s.time(), Default::default());
assert!(img.data.iter().any(|p| p[3] > 0.5));
s.execute("edit.undo", json!({})).unwrap();
s.execute("edit.undo", json!({})).unwrap();
s.execute("edit.undo", json!({})).unwrap();
let l = s.active_comp().unwrap().layers[0].clone();
assert!(!l.switches.three_d);
assert_eq!(matches(l.props.group("text/animators/#1/properties").unwrap()), ["position", "rotation"]);
// Disable removes X / Y rotation again.
s.execute("edit.redo", json!({})).unwrap();
s.execute("layer.enablePerChar3D", json!({"layer": t, "enabled": false})).unwrap();
let l = s.active_comp().unwrap().layers[0].clone();
assert_eq!(matches(l.props.group("text/animators/#1/properties").unwrap()), ["position", "rotation"]);
assert_eq!(l.props.prop("text/perChar3d").unwrap().value, KV::Bool(false));
}
#[test]
fn presets_apply_render_and_round_trip() {
let (mut s, t) = session();
let list = s.execute("text.presets", json!({})).unwrap();
let ids: Vec<String> = list.as_array().unwrap().iter().map(|p| p["id"].as_str().unwrap().to_string()).collect();
assert!(ids.len() >= 5 && ids.len() <= 8, "{ids:?}");
let cid = s.active_comp_id().unwrap();
for id in &ids {
let before = s.active_comp().unwrap().layers[0].props.group("text/animators").unwrap().children.len();
let r = s.execute("layer.applyTextPreset", json!({"layer": t, "preset": id})).unwrap();
assert!(!r["animators"].as_array().unwrap().is_empty(), "{id}");
let after = s.active_comp().unwrap().layers[0].props.group("text/animators").unwrap().children.len();
assert!(after > before, "{id}");
for secs in [0.0, 0.7, 3.0] {
let _ = s.render(cid, effectcraft_time::Tick::from_seconds_f64(secs), effectcraft_render::RenderOpts { scale: 0.25, ..Default::default() });
}
s.execute("edit.undo", json!({})).unwrap();
assert_eq!(s.active_comp().unwrap().layers[0].props.group("text/animators").unwrap().children.len(), before, "{id}");
}
// Typewriter: the start keyframes reveal the text over time.
s.execute("layer.applyTextPreset", json!({"layer": t, "preset": "Typewriter"})).unwrap();
let opts = effectcraft_render::RenderOpts { scale: 0.5, ..Default::default() };
let cov = |img: &effectcraft_render::Image| img.data.iter().filter(|p| p[3] > 0.5).count();
let a = cov(&s.render(cid, effectcraft_time::Tick::from_seconds_f64(0.0), opts));
let b = cov(&s.render(cid, effectcraft_time::Tick::from_seconds_f64(1.0), opts));
let c = cov(&s.render(cid, effectcraft_time::Tick::from_seconds_f64(3.0), opts));
assert!(a < b && b < c, "{a} {b} {c}");
// Every selector kind and More / Path Options survive a save/load round trip.
s.execute("layer.addTextSelector", json!({"layer": t, "kind": "wiggly"})).unwrap();
s.execute("layer.addTextSelector", json!({"layer": t, "kind": "expression"})).unwrap();
s.execute("layer.enablePerChar3D", json!({"layer": t})).unwrap();
let json = s.project.to_json();
let back = Project::from_json(&json).unwrap();
assert_eq!(*s.project, back);
let tg = text_group(&s);
for m in ["pathOptions", "moreOptions"] {
assert!(tg.sub(m).is_some(), "{m}");
}
assert!(matches(tg.sub("pathOptions").unwrap()).contains(&"forceAlignment".to_string()));
}
#[test]
fn menus_have_text_animation_entries() {
let (s, _) = session();
let spec = crate::commands::find("layer.enablePerChar3D").unwrap();
assert_eq!(spec.menu, ["Animation", "Animate Text"]);
assert!(s.is_enabled("layer.enablePerChar3D"));
assert!(!s.is_enabled("layer.addTextSelector"), "needs an animator");
}