#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
@@ -203,9 +203,44 @@ fn rings(style: BevelStyle, bevel: f64, depth: f64) -> Vec<(f64, f64)> {
|
||||
out
|
||||
}
|
||||
|
||||
/// A surface of an extruded mesh, which After Effects colours and shades separately (the
|
||||
/// Front / Bevel / Side / Back material groups).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Surface {
|
||||
/// The front cap (facing the camera, on the layer plane).
|
||||
Front,
|
||||
/// The bevelled rings between the caps and the walls (front and back).
|
||||
Bevel,
|
||||
/// The straight walls.
|
||||
Side,
|
||||
/// The back cap.
|
||||
Back,
|
||||
}
|
||||
|
||||
impl Surface {
|
||||
pub const ALL: [Surface; 4] = [Surface::Front, Surface::Bevel, Surface::Side, Surface::Back];
|
||||
/// Index into [`Surface::ALL`] (and into the primitives of [`extrude_surfaces`]).
|
||||
pub fn index(self) -> usize {
|
||||
self as usize
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the extruded mesh of outlines (one primitive, material 0).
|
||||
pub fn extrude(outlines: &[Outline], p: &ExtrudeParams) -> Primitive {
|
||||
let mut prim = Primitive { material: Some(0), ..Default::default() };
|
||||
build(outlines, p, false).into_iter().next().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// [`extrude`] split by surface: one primitive (material 0) per [`Surface`], in
|
||||
/// [`Surface::ALL`] order. Together they hold the same triangles as [`extrude`].
|
||||
pub fn extrude_surfaces(outlines: &[Outline], p: &ExtrudeParams) -> [Primitive; 4] {
|
||||
let mut v = build(outlines, p, true).into_iter();
|
||||
std::array::from_fn(|_| v.next().unwrap_or_default())
|
||||
}
|
||||
|
||||
/// The extruded mesh in one primitive (`split` false) or one per [`Surface`].
|
||||
fn build(outlines: &[Outline], p: &ExtrudeParams, split: bool) -> Vec<Primitive> {
|
||||
let mut prims = vec![Primitive { material: Some(0), ..Default::default() }; if split { 4 } else { 1 }];
|
||||
let slot = |s: Surface| if split { s.index() } else { 0 };
|
||||
let depth = p.depth.max(1e-3);
|
||||
let push = |prim: &mut Primitive, pos: [f64; 3], n: [f64; 3]| -> u32 {
|
||||
prim.positions.push([pos[0] as f32, pos[1] as f32, pos[2] as f32]);
|
||||
@@ -271,10 +306,11 @@ pub fn extrude(outlines: &[Outline], p: &ExtrudeParams) -> Primitive {
|
||||
};
|
||||
let (ni, nj) = (vn(i), vn(j));
|
||||
let nrm = |xy: P, pr: (f64, f64)| [xy[0] * pr.0, xy[1] * pr.0, pr.1];
|
||||
let ai = push(&mut prim, ring_pos[ci][k][i], nrm(ni, pa));
|
||||
let aj = push(&mut prim, ring_pos[ci][k][j], nrm(nj, pa));
|
||||
let bj = push(&mut prim, ring_pos[ci][k + 1][j], nrm(nj, pb));
|
||||
let bi = push(&mut prim, ring_pos[ci][k + 1][i], nrm(ni, pb));
|
||||
let Some(prim) = prims.get_mut(slot(if is_wall { Surface::Side } else { Surface::Bevel })) else { continue };
|
||||
let ai = push(prim, ring_pos[ci][k][i], nrm(ni, pa));
|
||||
let aj = push(prim, ring_pos[ci][k][j], nrm(nj, pa));
|
||||
let bj = push(prim, ring_pos[ci][k + 1][j], nrm(nj, pb));
|
||||
let bi = push(prim, ring_pos[ci][k + 1][i], nrm(ni, pb));
|
||||
prim.indices.extend([ai, aj, bj, ai, bj, bi]);
|
||||
}
|
||||
}
|
||||
@@ -286,10 +322,11 @@ pub fn extrude(outlines: &[Outline], p: &ExtrudeParams) -> Primitive {
|
||||
let tris = triangulate(&outer2, &holes2);
|
||||
let flat: Vec<(usize, usize)> = (0..cs.len()).flat_map(|ci| (0..cs[ci].pts.len()).map(move |i| (ci, i))).collect();
|
||||
for (front, nz) in [(true, -1.0), (false, 1.0)] {
|
||||
let Some(prim) = prims.get_mut(slot(if front { Surface::Front } else { Surface::Back })) else { continue };
|
||||
let base = prim.positions.len() as u32;
|
||||
for &(ci, i) in &flat {
|
||||
let r = if front { 0 } else { ring_pos[ci].len() - 1 };
|
||||
push(&mut prim, ring_pos[ci][r][i], [0.0, 0.0, nz]);
|
||||
push(prim, ring_pos[ci][r][i], [0.0, 0.0, nz]);
|
||||
}
|
||||
for t in &tris {
|
||||
let (a, b, c) = (base + t[0] as u32, base + t[1] as u32, base + t[2] as u32);
|
||||
@@ -297,7 +334,7 @@ pub fn extrude(outlines: &[Outline], p: &ExtrudeParams) -> Primitive {
|
||||
}
|
||||
}
|
||||
}
|
||||
prim
|
||||
prims
|
||||
}
|
||||
|
||||
/// Gap (pixels) between stacked extrusions of one layer: paint drawn later (a stroke over its
|
||||
@@ -309,9 +346,22 @@ pub const STACK_GAP: f64 = 0.02;
|
||||
/// `level × STACK_GAP` towards the camera (−z).
|
||||
pub fn extrude_stacked(outlines: &[Outline], p: &ExtrudeParams, level: usize) -> Primitive {
|
||||
let mut prim = extrude(outlines, p);
|
||||
stack(&mut prim, level);
|
||||
prim
|
||||
}
|
||||
|
||||
/// [`extrude_surfaces`] at stacking level `level` (see [`extrude_stacked`]).
|
||||
pub fn extrude_surfaces_stacked(outlines: &[Outline], p: &ExtrudeParams, level: usize) -> [Primitive; 4] {
|
||||
let mut prims = extrude_surfaces(outlines, p);
|
||||
for prim in &mut prims {
|
||||
stack(prim, level);
|
||||
}
|
||||
prims
|
||||
}
|
||||
|
||||
fn stack(prim: &mut Primitive, level: usize) {
|
||||
let dz = (level as f64 * STACK_GAP) as f32;
|
||||
for v in &mut prim.positions {
|
||||
v[2] -= dz;
|
||||
}
|
||||
prim
|
||||
}
|
||||
|
||||
@@ -308,6 +308,35 @@ fn bevels_shrink_the_caps() {
|
||||
assert!(c.positions.len() > m.positions.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extrusions_split_into_front_bevel_side_and_back() {
|
||||
use super::extrude::{Surface, extrude_surfaces, extrude_surfaces_stacked};
|
||||
let square = Outline { outer: vec![[0.0, 0.0], [100.0, 0.0], [100.0, 100.0], [0.0, 100.0]], holes: vec![] };
|
||||
let p = ExtrudeParams { bevel: BevelStyle::Angular, bevel_depth: 10.0, hole_bevel: 1.0, depth: 50.0 };
|
||||
let whole = extrude(std::slice::from_ref(&square), &p);
|
||||
let parts = extrude_surfaces(std::slice::from_ref(&square), &p);
|
||||
// The parts hold exactly the triangles of the whole mesh.
|
||||
assert_eq!(parts.iter().map(|m| m.triangle_count()).sum::<usize>(), whole.triangle_count());
|
||||
let [front, bevel, side, back] = &parts;
|
||||
// Caps: flat, at the layer plane (front, facing −z) and at the extrusion depth (back, +z).
|
||||
assert!(front.positions.iter().all(|q| q[2] == 0.0) && front.normals.iter().all(|n| n[2] < -0.99));
|
||||
assert!(back.positions.iter().all(|q| q[2] == 50.0) && back.normals.iter().all(|n| n[2] > 0.99));
|
||||
// Walls: the full outline, between the bevels (z 10..40), with sideways normals.
|
||||
assert!(side.positions.iter().all(|q| (10.0..=40.0).contains(&q[2])) && side.normals.iter().all(|n| n[2].abs() < 1e-6));
|
||||
assert!(side.positions.iter().any(|q| q[0] == 0.0));
|
||||
// Bevels: slanted between the caps and the walls, front and back.
|
||||
assert!(bevel.triangle_count() > 0 && bevel.normals.iter().all(|n| n[2].abs() > 0.1 && n[2].abs() < 0.99));
|
||||
assert!(bevel.positions.iter().any(|q| q[2] == 0.0) && bevel.positions.iter().any(|q| q[2] == 50.0));
|
||||
assert_eq!(Surface::ALL.map(Surface::index), [0, 1, 2, 3]);
|
||||
// Without a bevel there is nothing on the Bevel surface.
|
||||
let flat = extrude_surfaces(std::slice::from_ref(&square), &ExtrudeParams { bevel: BevelStyle::None, ..p });
|
||||
assert_eq!(flat[Surface::Bevel.index()].triangle_count(), 0);
|
||||
assert!(flat[Surface::Side.index()].triangle_count() > 0);
|
||||
// Stacked like `extrude_stacked`.
|
||||
let up = extrude_surfaces_stacked(std::slice::from_ref(&square), &p, 2);
|
||||
assert!(up[0].positions.iter().all(|q| (q[2] + 2.0 * super::extrude::STACK_GAP as f32).abs() < 1e-6));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contours_group_into_outlines_by_nesting() {
|
||||
let sq = |x: f64, y: f64, s: f64| vec![[x, y], [x + s, y], [x + s, y + s], [x, y + s]];
|
||||
|
||||
Reference in New Issue
Block a user