#315: Front / Bevel / Side / Back Color for extruded shapes and text

Problem: In Advanced 3D, an extruded shape or text layer was one mesh in
its paint colour. After Effects colours the front, bevel, side and back
of an extrusion separately (shape Contents ▸ Add ▸ Front/Bevel/Side/Back,
text Animate ▸ Front/Bevel/Side/Back), and EffectCraft had none of it.

Fix: The extruder can split its mesh by surface (front cap, bevel rings,
walls, back cap). Shape layers get Front / Bevel / Side / Back contents
items (layer.addShapeItem kinds frontColor…backColor, one item per
group, colouring every paint of the group and its nested groups; the
innermost wins). Text animators get Front / Bevel / Side / Back Color,
blended over the character's fill or stroke by the selection. Paints
with a surface colour render as one mesh per surface. Menus, the
Contents Add: pop-up and the menu translations list them. The other
surface material properties (Ambient, Diffuse, Specular, Metal,
Reflection, ...) remain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-10-11 12:05:36 +02:00
co-authored by Claude Opus 5.5
parent 9a7d3e7699
commit fb5a5e9ac0
15 changed files with 413 additions and 44 deletions
+27 -16
View File
@@ -543,10 +543,11 @@ pub fn extrusion_params(ctx: &EvalCtx, layer: &Layer) -> Option<model::extrude::
/// space). Fills and strokes are both extruded (a stroke as the region it covers, bevelled like
/// the fill), stacked in the layer's paint order (see [`model::extrude::extrude_stacked`]).
/// Text extrudes each character in its own space, so per-character 3D animation (position,
/// rotation, scale in Z) carries over.
/// rotation, scale in Z) carries over. A paint whose Front / Bevel / Side / Back are coloured
/// (shape surface items, text animators) comes as one mesh per surface, in that order.
pub fn extruded_meshes(ctx: &EvalCtx, layer: &Layer, p: &model::extrude::ExtrudeParams) -> Vec<(Primitive, [f32; 4], Mat4)> {
// (paths, colour, mesh → layer, stacking level)
let mut groups: Vec<(Vec<kurbo::BezPath>, [f32; 4], Mat4, usize)> = vec![];
// (paths, colour, mesh → layer, stacking level, surface colours)
let mut groups: Vec<(Vec<kurbo::BezPath>, [f32; 4], Mat4, usize, crate::shapes::SurfaceColors)> = vec![];
match layer.source {
LayerSource::Text => {
if let Some(tg) = crate::text::text_geom(ctx, layer) {
@@ -561,13 +562,13 @@ pub fn extruded_meshes(ctx: &EvalCtx, layer: &Layer, p: &model::extrude::Extrude
let op = (g.xf.opacity / 100.0).clamp(0.0, 1.0) as f32;
if g.apply_fill && g.fill[3] * op > 0.0 {
let c = [g.fill[0], g.fill[1], g.fill[2], g.fill[3] * op];
groups.push((vec![g.local.clone()], c, g.m, usize::from(!stroke_on_top)));
groups.push((vec![g.local.clone()], c, g.m, usize::from(!stroke_on_top), g.xf.surface_colors(c)));
}
if g.stroke_width > 0.0 && g.stroke[3] * op > 0.0 {
let st = effectcraft_path::StrokeStyle { width: g.stroke_width, join: effectcraft_path::Join::Round, ..Default::default() };
if let Some(region) = crate::shapes::stroke_region(std::slice::from_ref(&g.local), &st) {
let c = [g.stroke[0], g.stroke[1], g.stroke[2], g.stroke[3] * op];
groups.push((vec![region], c, g.m, usize::from(stroke_on_top)));
groups.push((vec![region], c, g.m, usize::from(stroke_on_top), g.xf.surface_colors(c)));
}
}
}
@@ -575,22 +576,32 @@ pub fn extruded_meshes(ctx: &EvalCtx, layer: &Layer, p: &model::extrude::Extrude
}
LayerSource::Shape => {
if let Some(c) = layer.props.sub("contents") {
groups = crate::shapes::extrusion_outlines(ctx, layer, c).into_iter().enumerate().map(|(k, (ps, c))| (ps, c, Mat4::IDENTITY, k)).collect();
groups =
crate::shapes::extrusion_outlines(ctx, layer, c).into_iter().enumerate().map(|(k, (ps, c, s))| (ps, c, Mat4::IDENTITY, k, s)).collect();
}
}
_ => {}
}
groups
.into_iter()
.filter_map(|(paths, color, m, level)| {
let cs: Vec<Vec<[f64; 2]>> = paths.iter().flat_map(|bp| contours(bp, 0.25)).collect();
let outlines = model::extrude::group_contours(cs);
if outlines.is_empty() {
return None;
let mut out = vec![];
for (paths, color, m, level, surfaces) in groups {
let cs: Vec<Vec<[f64; 2]>> = paths.iter().flat_map(|bp| contours(bp, 0.25)).collect();
let outlines = model::extrude::group_contours(cs);
if outlines.is_empty() {
continue;
}
if surfaces.iter().all(Option::is_none) {
out.push((model::extrude::extrude_stacked(&outlines, p, level), color, m));
continue;
}
for (mesh, s) in model::extrude::extrude_surfaces_stacked(&outlines, p, level).into_iter().zip(surfaces) {
if mesh.indices.is_empty() {
continue;
}
Some((model::extrude::extrude_stacked(&outlines, p, level), color, m))
})
.collect()
let c = s.map_or(color, |s| [s[0], s[1], s[2], color[3]]);
out.push((mesh, c, m));
}
}
out
}
fn extruded_layer(r: &Renderer, ctx: &EvalCtx, layer: &Layer, p: &model::extrude::ExtrudeParams, b: &mut Builder) {
+79
View File
@@ -313,6 +313,85 @@ fn extruded_text_renders_as_a_mesh() {
assert!(img.data.iter().filter(|q| q[3] > 0.5).count() > 200);
}
#[test]
fn shape_surface_items_colour_the_extruded_surfaces() {
let (mut p, cid) = project(200, 200);
add(&mut p, cid, LayerSource::Shape, |l| {
l.switches.three_d = true;
let mut next = 10_000u64;
let ids = &mut build::Ids(&mut next);
let surface = |ids: &mut build::Ids, m: &str, c: [f64; 4]| {
let mut g = build::shape_surface(ids, m).unwrap();
g.children.push(build::shape_surface_prop(ids, "color").unwrap().into());
if let Some(effectcraft_project::Node::Prop(pr)) = g.children.last_mut() {
pr.value = Value::Color(c);
}
g
};
// A white square whose group colours its sides green; the layer's Contents colour every
// front blue and every side red, but the group's own Side wins.
let rect = build::shape_rect(ids, [80.0, 80.0], [0.0, 0.0], 0.0);
let fill = build::shape_fill(ids, [1.0, 1.0, 1.0, 1.0]);
let side = surface(ids, "side", [0.0, 1.0, 0.0, 1.0]);
let group = build::shape_group(ids, "Group 1", vec![rect, fill, side]);
let front = surface(ids, "front", [0.0, 0.0, 1.0, 1.0]);
let outer_side = surface(ids, "side", [1.0, 0.0, 0.0, 1.0]);
let contents = l.props.sub_mut("contents").unwrap();
contents.children.extend([group.into(), front.into(), outer_side.into()]);
l.props.children.push(build::extrusion_geometry_options(ids).into());
set(l, "geometryOptions/extrusionDepth", Value::Scalar(40.0));
set(l, "transform/position", Value::Vec3([100.0, 100.0, 0.0]));
});
let ctx = crate::EvalCtx { project: &p, comp_id: cid, comp: p.comp(cid).unwrap(), time: Tick::ZERO, expr: None, footage: None };
let l = &ctx.comp.layers[0];
let params = scene::extrusion_params(&ctx, l).unwrap();
let meshes = scene::extruded_meshes(&ctx, l, &params);
// No bevel: Front, Side and Back (the Back keeps the fill's white).
let colours: Vec<[f32; 4]> = meshes.iter().map(|m| m.1).collect();
assert_eq!(colours, [[0.0, 0.0, 1.0, 1.0], [0.0, 1.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0]]);
assert!(meshes[0].0.normals.iter().all(|n| n[2] < -0.99), "front cap");
assert!(meshes[1].0.normals.iter().all(|n| n[2].abs() < 1e-6), "walls");
// Rendered (unlit: base colours) at an angle: the blue face and the green side both show.
p.comp_mut(cid).unwrap().layers[0].props.prop_mut("transform/rotationY").unwrap().value = Value::Scalar(50.0);
let img = render(&p, cid);
let blue = img.data.iter().filter(|q| q[3] > 0.99 && q[2] > 0.9 && q[0] < 0.1 && q[1] < 0.1).count();
let green = img.data.iter().filter(|q| q[3] > 0.99 && q[1] > 0.9 && q[0] < 0.1 && q[2] < 0.1).count();
assert!(blue > 200 && green > 50, "blue {blue}, green {green}");
}
#[test]
fn text_animators_colour_the_extruded_surfaces() {
let (mut p, cid) = project(200, 100);
add(&mut p, cid, LayerSource::Text, |l| {
l.switches.three_d = true;
let doc = effectcraft_keyframe::TextDoc { text: "IO".into(), size: 60.0, fill: [1.0, 1.0, 1.0, 1.0], apply_fill: true, ..Default::default() };
set(l, "text/sourceText", Value::Text(Box::new(doc)));
let mut next = 10_000u64;
let ids = &mut build::Ids(&mut next);
let props = ["sideColor", "bevelColor"].iter().flat_map(|k| build::text_anim_props(ids, k, false)).collect();
let anim = build::text_animator(ids, "Animator 1", props);
l.props.group_mut("text/animators").unwrap().children.push(anim.into());
set(l, "text/animators/#1/properties/sideColor", Value::Color([0.0, 1.0, 0.0, 1.0]));
// Half the selection: the bevel colour blends half way over the fill.
set(l, "text/animators/#1/selectors/#1/advanced/amount", Value::Scalar(50.0));
l.props.children.push(build::extrusion_geometry_options(ids).into());
set(l, "geometryOptions/extrusionDepth", Value::Scalar(30.0));
set(l, "geometryOptions/bevelStyle", Value::Enum(1));
});
let ctx = crate::EvalCtx { project: &p, comp_id: cid, comp: p.comp(cid).unwrap(), time: Tick::ZERO, expr: None, footage: None };
let l = &ctx.comp.layers[0];
let params = scene::extrusion_params(&ctx, l).unwrap();
let meshes = scene::extruded_meshes(&ctx, l, &params);
// Two characters × (Front, Bevel, Side, Back).
assert_eq!(meshes.len(), 8);
for m in meshes.chunks(4) {
assert_eq!(m[0].1, [1.0, 1.0, 1.0, 1.0], "front keeps the fill");
assert_eq!(m[1].1, [1.0, 0.5, 0.5, 1.0], "bevel: red half way over white");
assert_eq!(m[2].1, [0.5, 1.0, 0.5, 1.0], "side: green half way over white");
assert_eq!(m[3].1, [1.0, 1.0, 1.0, 1.0], "back keeps the fill");
}
}
// ---------------------------------------------------------------- motion blur, blend modes, mattes
fn solid(p: &mut Project, color: [f32; 3], w: u32, h: u32) -> ItemId {