#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:
co-authored by
Claude Opus 5.5
parent
9a7d3e7699
commit
fb5a5e9ac0
@@ -6,7 +6,9 @@
|
||||
//! the paths of nested groups;
|
||||
//! - paint items (fills, strokes, gradient fills/strokes) paint the paths above them, *as modified
|
||||
//! by every operator in the stack* — a Trim Paths below a Stroke still trims it;
|
||||
//! - items higher in the list draw on top.
|
||||
//! - items higher in the list draw on top;
|
||||
//! - surface items (Front, Bevel, Side, Back) colour those surfaces of the Advanced 3D
|
||||
//! extrusion of every paint in their group and its nested groups (the innermost wins).
|
||||
|
||||
use effectcraft_color::{BlendMode, blend_pixel};
|
||||
use effectcraft_effects::Buf;
|
||||
@@ -53,8 +55,14 @@ struct Draw {
|
||||
xf: Mat3,
|
||||
opacity: f32,
|
||||
blend: BlendMode,
|
||||
/// Front / Bevel / Side / Back colours of the paint's extrusion (Advanced 3D).
|
||||
surfaces: SurfaceColors,
|
||||
}
|
||||
|
||||
/// Straight RGB colours of an extrusion's surfaces, by [`effectcraft_model::extrude::Surface`]
|
||||
/// index (Front, Bevel, Side, Back); `None` keeps the paint's colour.
|
||||
pub type SurfaceColors = [Option<[f32; 3]>; 4];
|
||||
|
||||
fn mat_path(path: &BezPath, m: &Mat3) -> BezPath {
|
||||
effectcraft_path::transform(std::slice::from_ref(path), m).pop().unwrap_or_default()
|
||||
}
|
||||
@@ -179,6 +187,7 @@ fn collect(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup, arena: &mut Vec<B
|
||||
let mut draws: Vec<Draw> = Vec::new();
|
||||
let mut live: Vec<usize> = Vec::new();
|
||||
let opacity = |g: &PropGroup| (ctx.f(layer, g, "opacity", 100.0) / 100.0) as f32;
|
||||
let mut surfaces: SurfaceColors = [None; 4];
|
||||
for node in &contents.children {
|
||||
let Node::Group(g) = node else { continue };
|
||||
if !g.enabled {
|
||||
@@ -224,6 +233,7 @@ fn collect(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup, arena: &mut Vec<B
|
||||
xf: Mat3::IDENTITY,
|
||||
opacity: opacity(g),
|
||||
blend: blend_mode(ctx, layer, g),
|
||||
surfaces: [None; 4],
|
||||
});
|
||||
}
|
||||
"stroke" => {
|
||||
@@ -236,6 +246,7 @@ fn collect(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup, arena: &mut Vec<B
|
||||
xf: Mat3::IDENTITY,
|
||||
opacity: opacity(g),
|
||||
blend: blend_mode(ctx, layer, g),
|
||||
surfaces: [None; 4],
|
||||
});
|
||||
}
|
||||
"gfill" | "gstroke" => {
|
||||
@@ -258,6 +269,7 @@ fn collect(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup, arena: &mut Vec<B
|
||||
xf: Mat3::IDENTITY,
|
||||
opacity: opacity(g),
|
||||
blend: blend_mode(ctx, layer, g),
|
||||
surfaces: [None; 4],
|
||||
});
|
||||
}
|
||||
"trim" => {
|
||||
@@ -386,7 +398,24 @@ fn collect(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup, arena: &mut Vec<B
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
m => {
|
||||
if let Some(i) = effectcraft_project::build::SHAPE_SURFACES.iter().position(|(s, _)| *s == m)
|
||||
&& g.get("color").is_some()
|
||||
&& let Some(slot) = surfaces.get_mut(i)
|
||||
{
|
||||
let c = ctx.color(layer, g, "color");
|
||||
*slot = Some([c[0], c[1], c[2]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Surface items colour every paint of the group, wherever they sit in it; nested groups'
|
||||
// own surface items were applied first and win.
|
||||
if surfaces.iter().any(Option::is_some) {
|
||||
for d in &mut draws {
|
||||
for (s, g) in d.surfaces.iter_mut().zip(surfaces) {
|
||||
*s = s.or(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
(draws, live)
|
||||
@@ -622,8 +651,9 @@ pub fn fill_outlines(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup) -> Vec<
|
||||
|
||||
/// The painted regions of a shape layer for Advanced 3D extrusion, bottom paint first: fills
|
||||
/// (gradient fills: the colour half way along) and strokes, each stroke turned into the region
|
||||
/// it covers (outline of the stroke with its width, joins, caps and dashes, overlaps resolved).
|
||||
pub fn extrusion_outlines(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup) -> Vec<(Vec<BezPath>, [f32; 4])> {
|
||||
/// it covers (outline of the stroke with its width, joins, caps and dashes, overlaps resolved),
|
||||
/// with the colours of their extrusion's surfaces.
|
||||
pub fn extrusion_outlines(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup) -> Vec<(Vec<BezPath>, [f32; 4], SurfaceColors)> {
|
||||
let mut arena = Vec::new();
|
||||
let (draws, _) = collect(ctx, layer, contents, &mut arena);
|
||||
draws
|
||||
@@ -641,7 +671,7 @@ pub fn extrusion_outlines(ctx: &EvalCtx, layer: &Layer, contents: &PropGroup) ->
|
||||
Paint::Stroke { color, style } => (*color, vec![stroke_region(&paths, style)?]),
|
||||
Paint::Gradient { g, stroke: Some(style), .. } => (g.sample(0.5), vec![stroke_region(&paths, style)?]),
|
||||
};
|
||||
Some((region, [c[0], c[1], c[2], c[3] * d.opacity]))
|
||||
Some((region, [c[0], c[1], c[2], c[3] * d.opacity], d.surfaces))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -58,9 +58,21 @@ pub struct CharXf {
|
||||
/// Variable Font Axes offsets (axis tag, user units), the first `n_axes` used.
|
||||
pub axes: [([u8; 4], f64); 4],
|
||||
pub n_axes: u8,
|
||||
/// Front / Bevel / Side / Back Color of the extruded character (Advanced 3D), by
|
||||
/// `effectcraft_model::extrude::Surface` index, and the selection each was set with.
|
||||
pub surface: [Option<[f32; 4]>; 4],
|
||||
pub surface_k: [f32; 4],
|
||||
}
|
||||
|
||||
impl CharXf {
|
||||
/// The surface colours of an extrusion painted `base` (the character's fill or stroke):
|
||||
/// each animated surface colour blended over `base` by its selection.
|
||||
pub fn surface_colors(&self, base: [f32; 4]) -> crate::shapes::SurfaceColors {
|
||||
std::array::from_fn(|i| {
|
||||
let (c, k) = (self.surface.get(i).copied().flatten()?, self.surface_k.get(i).copied().unwrap_or(0.0));
|
||||
Some(std::array::from_fn(|d| base[d] + (c[d] - base[d]) * k))
|
||||
})
|
||||
}
|
||||
/// The variable-font axis offsets that move the outline.
|
||||
pub fn axis_deltas(&self) -> Vec<(String, f32)> {
|
||||
self.axes[..self.n_axes as usize]
|
||||
@@ -79,6 +91,10 @@ impl CharXf {
|
||||
}
|
||||
}
|
||||
|
||||
/// Animator property match ids of Front / Bevel / Side / Back Color, in
|
||||
/// `effectcraft_model::extrude::Surface::ALL` order.
|
||||
pub const SURFACE_ANIM_PROPS: [&str; 4] = ["frontColor", "bevelColor", "sideColor", "backColor"];
|
||||
|
||||
/// Animator property match id of a Variable Font Axes property (`axis_wght`).
|
||||
pub const AXIS_PREFIX: &str = "axis_";
|
||||
|
||||
@@ -115,6 +131,8 @@ impl Default for CharXf {
|
||||
blur: [0.0; 2],
|
||||
axes: [([0; 4], 0.0); 4],
|
||||
n_axes: 0,
|
||||
surface: [None; 4],
|
||||
surface_k: [0.0; 4],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,6 +292,7 @@ pub fn char_transforms(ctx: &EvalCtx, layer: &Layer, text: &PropGroup, lay: &Tex
|
||||
let char_range = props.get("characterRange").map(|p| ctx.value(layer, p).as_enum());
|
||||
let char_align = props.get("characterAlignment").map(|p| ctx.value(layer, p).as_enum());
|
||||
let blur = props.get("blur").map(|p| ctx.value(layer, p).as_vec2());
|
||||
let surface = SURFACE_ANIM_PROPS.map(|m| props.get(m).map(|p| ctx.value(layer, p).as_color()));
|
||||
let axes: Vec<([u8; 4], f64)> = props
|
||||
.props()
|
||||
.filter_map(|p| {
|
||||
@@ -385,6 +404,12 @@ pub fn char_transforms(ctx: &EvalCtx, layer: &Layer, text: &PropGroup, lay: &Tex
|
||||
for (tag, v) in &axes {
|
||||
c.add_axis(*tag, v * k);
|
||||
}
|
||||
for ((s, sk), v) in c.surface.iter_mut().zip(&mut c.surface_k).zip(surface) {
|
||||
if let Some(v) = v {
|
||||
*s = Some(v);
|
||||
*sk = (*sk + k as f32).clamp(0.0, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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, ¶ms);
|
||||
// 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, ¶ms);
|
||||
// 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 {
|
||||
|
||||
Reference in New Issue
Block a user