Merge pull request #8995 from dotCooCoo/fix/3d-expand-inflate-bevel-twist-curves

3D: Expand Appearance keeps curves on Inflate faces, interior bevel edges and twist cuts
This commit is contained in:
BFlat
2026-11-22 10:53:03 +07:00
committed by GitHub
9 changed files with 619 additions and 57 deletions
+3
View File
@@ -575,3 +575,6 @@ mod tests_inflate_shading;
#[cfg(test)]
mod tests_limits;
#[cfg(test)]
mod tests_curves;
+65 -19
View File
@@ -41,6 +41,11 @@ impl Camera {
let f = perspective_scale(self.eye, v.2);
Point::new(self.origin.x + v.0 * f, self.origin.y + v.1 * f)
}
/// The view-space point at depth `z` that [`Camera::project`] takes to `p`.
pub(super) fn unproject(&self, p: Point, z: f64) -> V3 {
let f = perspective_scale(self.eye, z);
V3((p.x - self.origin.x) / f, (p.y - self.origin.y) / f, z)
}
/// The cosine between a face's outward unit normal `n` and the direction from `at` (both in
/// view space) to the eye: positive when the face is turned towards the viewer.
pub(super) fn facing(&self, at: V3, n: V3) -> f64 {
@@ -271,14 +276,10 @@ impl<'a> Builder<'a> {
/// The band between two partner rings (same length), as one quad per edge, or for a twisted
/// wall with `cuts` (see [`cuts`]) as `cuts[i]` quads along edge `i`. `outward` is the
/// direction (before rotation) the band faces away from the solid, for orienting normals.
pub(super) fn band(&mut self, a: &[V3], b: &[V3], cuts: &[usize], outward: impl Fn(usize) -> V3) -> Result<(), String> {
self.curved_band(a, b, cuts, outward, None, None)
}
/// [`Builder::band`], with `curves` the pieces of curve the rings' edges follow and the
/// outlines at `a` and `b`: a quad whose edge is not cut keeps its edges along the profile curved.
/// With `side`, each quad carries where its corners lie on the side unrolled flat
/// ([`Facet::surface`]).
/// With `curves`, the pieces of curve the rings' edges follow and the outlines at `a` and `b`,
/// each quad keeps its edges along the profile curved. An edge cut into pieces is cut at points
/// of its curve, each piece taking an equal share of the edge's piece of curve. With `side`,
/// each quad carries where its corners lie on the side unrolled flat ([`Facet::surface`]).
pub(super) fn curved_band(
&mut self,
a: &[V3],
@@ -303,9 +304,31 @@ impl<'a> Builder<'a> {
for i in 0..n {
let j = (i + 1) % n;
let pieces = cuts.get(i).copied().unwrap_or(1).max(1);
let span = curves.as_ref().and_then(|w| w.spans.get(i).copied().flatten());
let places = curves.as_ref().map_or([None, None], |w| w.places);
// Where the edge's curve is at share `s` of it.
let t = |s: f64| span.map_or(0.0, |span| span.t0 + (span.t1 - span.t0) * s);
// A cut corner on a ring that follows a curve lies on the curve, moved by the offsets of
// the edge's corners from it (a bevel's miters), eased across the edge as the cap's edge
// eases them, so the pieces' edges follow the same curve as the cap's edge they meet. The
// offsets are eased as drawn, and the corner keeps the depth they give it in view space.
let camera = self.camera;
let corner = |p: V3, q: V3, s: f64, ring: usize| match (span, places.get(ring).copied().flatten()) {
(Some(span), Some(place)) if s > 0.0 && s < 1.0 => {
let (c, c0, c1) = (place(&span, t(s)), place(&span, span.t0), place(&span, span.t1));
let (ep, eq) = (outline::fade(s), outline::fade(1.0 - s));
let (dp, dq) = (p.sub(c0), q.sub(c1));
let z = c.2 + dp.2 * ep + dq.2 * eq;
let (dp, dq) = (camera.project(p) - camera.project(c0), camera.project(q) - camera.project(c1));
let v = camera.unproject(camera.project(c) + dp * ep + dq * eq, z);
if v.0.is_finite() && v.1.is_finite() && v.2.is_finite() { v } else { lerp(p, q, s) }
}
_ => lerp(p, q, s),
};
let ends = [[self.camera.project(a[i]), self.camera.project(a[j])], [self.camera.project(b[i]), self.camera.project(b[j])]];
for k in 0..pieces {
let (s0, s1) = (k as f64 / pieces as f64, (k + 1) as f64 / pieces as f64);
let quad = vec![lerp(a[i], a[j], s0), lerp(a[i], a[j], s1), lerp(b[i], b[j], s1), lerp(b[i], b[j], s0)];
let quad = vec![corner(a[i], a[j], s0, 0), corner(a[i], a[j], s1, 0), corner(b[i], b[j], s1, 1), corner(b[i], b[j], s0, 1)];
// A twist bends the strip between two slices into a saddle: its normal is the whole
// quad's average (Newell's), not one corner's triangle, which leans far to one side.
let mut normal = newell(std::slice::from_ref(&quad));
@@ -343,10 +366,14 @@ impl<'a> Builder<'a> {
});
}
}
if let Some(w) = curves.as_mut().filter(|_| pieces == 1)
&& let Some(span) = w.spans.get(i).copied().flatten()
if let Some(w) = curves.as_mut()
&& let Some(span) = span
{
self.outline(before, |c| c.first().and_then(|quad| outline::wall(&span, quad, w.near, w.far, w.budget)));
// An edge cut on its chord, with no place on the curve for its cut corners,
// stays straight.
let near = w.near.filter(|_| pieces == 1 || w.places[0].is_some());
let far = w.far.filter(|_| pieces == 1 || w.places[1].is_some());
self.outline(before, |c| c.first().and_then(|quad| outline::wall(&span, (t(s0), t(s1)), ends, quad, near, far, w.budget)));
}
}
}
@@ -397,9 +424,15 @@ pub(super) struct WallCurves<'a> {
pub(super) spans: &'a [Option<Span>],
pub(super) near: Option<&'a Along<'a>>,
pub(super) far: Option<&'a Along<'a>>,
/// Where a point of a span's curve lies in view space on the band's two rings, for the corners
/// where a twisted wall's edge is cut ([`cuts`]).
pub(super) places: [Option<&'a Place<'a>>; 2],
pub(super) budget: &'a mut Budget,
}
/// Where the point at `t` on a span's curve lies in view space on one ring.
pub(super) type Place<'a> = dyn Fn(&Span, f64) -> V3 + 'a;
/// Where a band of the side lies on the side unrolled flat ([`super::side`]): the x of each end of
/// each edge of its rings, and the y of its two rings.
pub(super) struct SideBand<'a> {
@@ -704,12 +737,19 @@ pub(crate) fn extrude_faces(path: &PathData, rule: FillRule, bounds: Rect, optio
// and within the sampling tolerance (which the inset rings themselves keep to) where it is.
let sampled = (size / 2000.0).max(0.05);
let maps: Vec<Placing> = steps.iter().map(|s| Placing::new(&camera, bounds.center(), Turn::new(bounds, o.twist, o.taper, s.t), z(s.t))).collect();
let at: Vec<_> = steps
let places: Vec<_> = steps
.iter()
.zip(&maps)
.map(|(s, m)| {
let (w, camera) = (s.inset, &camera);
move |span: &Span, t: f64| camera.project(m.place(offset(span, t, w)))
let w = s.inset;
move |span: &Span, t: f64| m.place(offset(span, t, w))
})
.collect();
let at: Vec<_> = places
.iter()
.map(|place| {
let camera = &camera;
move |span: &Span, t: f64| camera.project(place(span, t))
})
.collect();
// A step that is not inset moves the art point by point, affinely without perspective.
@@ -762,10 +802,16 @@ pub(crate) fn extrude_faces(path: &PathData, rule: FillRule, bounds: Rect, optio
} else {
0.0
};
// The edges a band shares with a cap follow the cap's curves; the edges between two bands
// stay straight, within the sampling tolerance.
let (near, far) = (along.get(k).filter(|_| k == 0), along.get(k + 1).filter(|_| k + 2 == steps.len()));
let curves = (near.is_some() || far.is_some()).then(|| WallCurves { spans: &traced.spans, near, far, budget: &mut budget });
// Each ring of a band follows the outline at its step: the edges a band shares with a cap
// follow the cap's curves, and an edge two bands share follows the same curves in both.
let place = |k: usize| places.get(k).map(|p| p as &Place);
let curves = Some(WallCurves {
spans: &traced.spans,
near: along.get(k),
far: along.get(k + 1),
places: [place(k), place(k + 1)],
budget: &mut budget,
});
let side = unrolled.and_then(|(_, x, y)| Some(SideBand { x, y: [*y.get(k)?, *y.get(k + 1)?] }));
b.curved_band(a, c, pieces, |i| outward(ring, i, face), curves, side)?;
}
+125 -13
View File
@@ -1,7 +1,8 @@
use super::build::{Builder, Built, Camera, Keep, Order, Turn, check_bounds, cuts, fit, newell, outward};
use super::build::{Builder, Built, Camera, Keep, Order, Place, Placing, Turn, WallCurves, check_bounds, cuts, fit, newell, outward};
use super::membrane::{Edges, MAX_MATERIAL_SEGMENTS, Membrane, cell_triangles, clip, crossings, filled, material};
use super::rings::{MAX_SOLID_POINTS, TOO_COMPLEX_SURFACE, curve_pieces, signed_area, solid_rings};
use super::{Facet, FillRule, Inflate, MAX_FACES, MAX_SOLID_FACES, PathData, PlanarFace, Point, Rect, V3, Vec2, View};
use super::outline::{self, Along, Budget, CURVE_TOLERANCE, EdgeCurve};
use super::rings::{MAX_SOLID_POINTS, Ring, Span, TOO_COMPLEX_SURFACE, curve_pieces, signed_area, solid_rings_traced};
use super::{Facet, FillRule, Inflate, MAX_FACES, MAX_SOLID_FACES, ParamCurve, PathData, PlanarFace, Point, Rect, V3, Vec2, View};
/// The slices the sides are cut into: more to follow a twist or taper.
fn slices(o: &Inflate) -> usize {
@@ -11,6 +12,8 @@ fn slices(o: &Inflate) -> usize {
/// A shape to inflate: its rings and the membrane under them on the grid of the bounds.
struct Puff {
rings: Vec<Vec<Point>>,
/// The rings with the piece of curve each edge follows.
traced: Vec<Ring>,
/// The index of the rings' edges.
edges: Edges,
cell: f64,
@@ -50,7 +53,8 @@ fn puff(path: &PathData, rule: FillRule, bounds: Rect, o: &Inflate) -> Result<Op
PUFFED.with(|n| n.set(n.get() + 1));
let size = bounds.width().max(bounds.height());
let most = outline_pieces(path, bounds, o)?;
let rings = solid_rings(path, rule, size, MAX_SOLID_POINTS, most)?;
let traced = solid_rings_traced(path, rule, size, MAX_SOLID_POINTS, most)?;
let rings: Vec<Vec<Point>> = traced.iter().map(|r| r.points.clone()).collect();
if rings.is_empty() {
return Ok(None);
}
@@ -73,7 +77,7 @@ fn puff(path: &PathData, rule: FillRule, bounds: Rect, o: &Inflate) -> Result<Op
}
// A circle of radius r puffs into a half sphere of radius r at 50 % (its membrane peaks at r²/4).
let height = 2.0 * m.peak.sqrt() * o.volume / 50.0;
Ok(Some(Puff { rings, edges, cell, nx, ny, m, height }))
Ok(Some(Puff { rings, traced, edges, cell, nx, ny, m, height }))
}
/// Inflate: the shape puffed out like a cushion, its edge kept where the art's outline is.
@@ -209,6 +213,10 @@ thread_local! {
/// cells together ([`crate::mesh::flat_triangles`]).
pub(super) const MAX_FLAT_WORK: usize = 1 << 26;
/// Most edges of the outline one inflated surface may look at to find the edges of its cells that
/// lie along the outline ([`Edges::holding`]). Past it, the cells' remaining edges stay straight.
pub(super) const MAX_RIM_WORK: usize = 1 << 22;
/// Most corners the pieces of one such cell may have.
pub(super) const MAX_FLAT_CORNERS: usize = 4096;
@@ -242,7 +250,7 @@ fn mark_surface(b: &mut Builder<'_>, before: usize, points: [Point; 3], center:
fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Keep) -> Result<Built, String> {
#[cfg(test)]
INFLATED.with(|n| n.set(n.get() + 1));
let Puff { rings, edges, cell, nx, ny, m, height } = p;
let Puff { rings, traced, edges, cell, nx, ny, m, height } = p;
let outline: Vec<(Rect, vectorcraft_geom::SubPath)> = rings
.iter()
.filter_map(|r| {
@@ -286,6 +294,58 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
let half = o.depth / 2.0;
// The back: turned and scaled by the twist and taper, its puff too.
let back_turn = Turn::new(bounds, o.twist, o.taper, 1.0);
// The outline of the front and the back where the surface meets it, through the art's curves:
// the cells' edges along it follow its curves within the sampling tolerance, as the cells'
// corners there lie on its sampled points and edges.
let mut budget = Budget::default();
let sampled = (bounds.width().max(bounds.height()) / 2000.0).max(0.05);
let (front_map, back_map) =
(Placing::new(&camera, center, Turn::new(bounds, 0.0, 1.0, 0.0), half), Placing::new(&camera, center, back_turn, -half));
let (front_at, back_at) = (
|span: &Span, t: f64| camera.project(front_map.place(span.curve.eval(t))),
|span: &Span, t: f64| camera.project(back_map.place(span.curve.eval(t))),
);
let (front_point, back_point) = (|p: Point| camera.project(front_map.place(p)), |p: Point| camera.project(back_map.place(p)));
let affine = camera.center_and_eye().1.is_none();
let front_rim = Along { at: &front_at, map: Some(&front_point), affine, tolerance: sampled };
let back_rim = Along { at: &back_at, map: Some(&back_point), affine, tolerance: sampled };
// Where each ring's edges start among all the rings' edges, as the edge index counts them.
let starts: Vec<usize> = rings
.iter()
.scan(0usize, |s, r| {
let at = *s;
*s = s.saturating_add(r.len());
Some(at)
})
.collect();
let rim_work = std::cell::Cell::new(MAX_RIM_WORK);
// The pieces of curve the edges of `pieces` (art points, lifted by `lifts`) follow where they
// lie along the outline: an edge whose two ends are on the outline, on one of its edges.
let rim = |pieces: &[Vec<Point>], lifts: &[Vec<f64>]| -> Vec<Vec<Option<EdgeCurve>>> {
pieces
.iter()
.zip(lifts)
.map(|(p, h)| {
let n = p.len();
(0..n)
.map(|k| {
let (a, b) = (*p.get(k)?, *p.get((k + 1) % n)?);
if h.get(k).copied() != Some(0.0) || h.get((k + 1) % n).copied() != Some(0.0) {
return None;
}
let mut work = rim_work.get();
let found = edges.holding(a, b, 1e-9, &mut work);
rim_work.set(work);
let (e, sa, sb) = found?;
let r = starts.partition_point(|s| *s <= e).checked_sub(1)?;
let span = traced.get(r)?.spans.get(e - starts.get(r)?)?.as_ref().copied()?;
let t = |s: f64| span.t0 + (span.t1 - span.t0) * s;
(sa != sb).then(|| (span, t(sa), t(sb)))
})
.collect()
})
.collect()
};
// The grid's cells, those the surface rises steeply across (near the outline) cut into
// halves or quarters each way, so the steep rim is drawn in facets as fine as its curve.
// Every corner sits on one fine lattice (a quarter cell), computed the same way wherever it
@@ -477,7 +537,10 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
if let Some(triangles) = triangles {
let order = if flat { Order::Last } else { Order::Depth };
for points in triangles {
let front = points.map(|q| camera.place(q, half + lift(q)));
let lifts = points.map(&lift);
let front: [V3; 3] = std::array::from_fn(|k| camera.place(points[k], half + lifts[k]));
let found = std::cell::OnceCell::new();
let curves = || found.get_or_init(|| rim(&[points.to_vec()], &[lifts.to_vec()]));
let before = b.facets.len();
let outward = newell(&[front.to_vec()]);
if smoothed {
@@ -485,11 +548,13 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
} else {
b.face(vec![front.to_vec()], outward, order)?;
}
b.outline(before, |c| outline::edges(c, curves(), &front_rim, &mut budget));
if o.map_surface {
mark_surface(&mut b, before, points, center, outward, PlanarFace::Front);
}
if o.both_sides && o.cap {
let back = points.map(|q| camera.place(back_turn.apply(q), -half - lift(q) * back_turn.scale));
let back: [V3; 3] =
std::array::from_fn(|k| camera.place(back_turn.apply(points[k]), -half - lifts[k] * back_turn.scale));
let before = b.facets.len();
let n = newell(&[back.to_vec()]);
// The back winds the same way round as the front, so its outward
@@ -506,6 +571,7 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
} else {
b.face(vec![back.to_vec()], outward, order)?;
}
b.outline(before, |c| outline::edges(c, curves(), &back_rim, &mut budget));
if o.map_surface {
mark_surface(&mut b, before, points, center, outward, PlanarFace::Back);
}
@@ -521,7 +587,11 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
pieces.iter().zip(&lifts).map(|(p, h)| p.iter().zip(h).map(|(q, h)| camera.place(*q, half + h)).collect()).collect();
let n = newell(&front);
let order = if flat { Order::Last } else { Order::Depth };
let found = std::cell::OnceCell::new();
let curves = || found.get_or_init(|| rim(&pieces, &lifts));
let before = b.facets.len();
b.face(front, n, order)?;
b.outline(before, |c| outline::edges(c, curves(), &front_rim, &mut budget));
if o.both_sides && o.cap {
// The back winds the same way round as the front, so its outward normal is
// reversed.
@@ -531,7 +601,9 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
.map(|(p, h)| p.iter().zip(h).map(|(q, h)| camera.place(back_turn.apply(*q), -half - h * back_turn.scale)).collect())
.collect();
let n = newell(&back);
let before = b.facets.len();
b.face(back, V3(-n.0, -n.1, -n.2), order)?;
b.outline(before, |c| outline::edges(c, curves(), &back_rim, &mut budget));
}
}
}
@@ -541,7 +613,12 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
let back: Vec<Vec<V3>> = rings.iter().map(|r| r.iter().map(|p| camera.place(back_turn.apply(*p), -half)).collect()).collect();
// The back turned toward the viewer covers the walls it overlaps, even those nearer than
// its center: twisted walls, and the walls of a fill inside the solid of its stroke.
let before = b.len();
b.face(back, camera.rotate(V3(0.0, 0.0, -1.0)), Order::Last)?;
// The flat back is the art turned and scaled: its curves map exactly without perspective.
let along = Along { tolerance: CURVE_TOLERANCE, ..back_rim };
let traced: Vec<&Ring> = traced.iter().collect();
b.outline(before, |c| outline::face(&traced, c, &along, &mut budget));
}
if o.depth > 0.0 {
// The sides, cut into slices that follow a twist or taper.
@@ -558,10 +635,45 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
if b.len().saturating_add(edges.saturating_mul(slices)) > MAX_SOLID_FACES {
return Err(TOO_COMPLEX_SURFACE.into());
}
let sides = |b: &mut Builder<'_>, pieces: &[Vec<usize>]| -> Result<(), String> {
for (ring, pieces) in rings.iter().zip(pieces) {
// Each slice's ring follows the art's curves, turned and scaled, at its depth.
let maps: Vec<Placing> = (0..=slices)
.map(|k| {
let t = k as f64 / slices as f64;
Placing::new(&camera, center, Turn::new(bounds, o.twist, o.taper, t), half - o.depth * t)
})
.collect();
let places: Vec<_> = maps.iter().map(|m| move |span: &Span, t: f64| m.place(span.curve.eval(t))).collect();
let slice_at: Vec<_> = places
.iter()
.map(|place| {
let camera = &camera;
move |span: &Span, t: f64| camera.project(place(span, t))
})
.collect();
let point_maps: Vec<_> = maps
.iter()
.map(|m| {
let camera = &camera;
move |p: Point| camera.project(m.place(p))
})
.collect();
let along: Vec<Along> = slice_at
.iter()
.zip(&point_maps)
.map(|(at, map)| Along { at, map: Some(map as &dyn Fn(Point) -> Point), affine, tolerance: CURVE_TOLERANCE })
.collect();
let place = |k: usize| places.get(k).map(|p| p as &Place);
let sides = |b: &mut Builder<'_>, pieces: &[Vec<usize>], budget: &mut Budget| -> Result<(), String> {
for ((ring, traced), pieces) in rings.iter().zip(&traced).zip(pieces) {
for k in 0..slices {
b.band(&at(ring, k), &at(ring, k + 1), pieces, |i| outward(ring, i, 0.0))?;
let curves = WallCurves {
spans: &traced.spans,
near: along.get(k),
far: along.get(k + 1),
places: [place(k), place(k + 1)],
budget: &mut *budget,
};
b.curved_band(&at(ring, k), &at(ring, k + 1), pieces, |i| outward(ring, i, 0.0), Some(curves), None)?;
}
}
Ok(())
@@ -578,11 +690,11 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
own_sides = Some((own, b.mesh.take()));
}
}
sides(&mut b, &pieces)?;
sides(&mut b, &pieces, &mut budget)?;
if let Some((own, faces)) = own_sides {
let mut m = Builder::new(&camera, o.cap, false, Keep::Faces);
m.mesh = faces;
match sides(&mut m, &own) {
match sides(&mut m, &own, &mut budget) {
Ok(()) => b.mesh = m.mesh,
Err(_) => b.lose_mesh(),
}
+21
View File
@@ -130,6 +130,27 @@ impl Edges {
}
}
/// The edge that both `a` and `b` lie on within `tolerance`: its index, counted through the
/// rings in order, and how far along it `a` and `b` lie (0 at its start, 1 at its end). Only the
/// bucket of the midpoint of `a` and `b` is looked in, and each edge looked at takes one from
/// `work`, which is not counted against the index's own budget: `None` once `work` is spent.
pub(super) fn holding(&self, a: Point, b: Point, tolerance: f64, work: &mut usize) -> Option<(usize, f64, f64)> {
let m = a.midpoint(b);
let (i, j) = (self.cell(m.x, self.origin.x), self.cell(m.y, self.origin.y));
let bucket = self.buckets.get((j * self.n as isize + i) as usize)?;
for k in bucket {
*work = work.checked_sub(1)?;
let Some(&(p, q)) = self.edges.get(*k as usize) else { continue };
let d = q - p;
if d.hypot2() < 1e-18 || segment_distance(a, p, q) > tolerance || segment_distance(b, p, q) > tolerance {
continue;
}
let along = |v: Point| ((v - p).dot(d) / d.hypot2()).clamp(0.0, 1.0);
return Some((*k as usize, along(a), along(b)));
}
None
}
/// Call `f` with each edge whose bounding box overlaps `r` (an edge in several of the
/// buckets `r` covers comes more than once).
fn each(&self, r: Rect, mut f: impl FnMut(Point, Point)) {
+107 -15
View File
@@ -2,7 +2,7 @@
//! wall along the profile follow the profile's curves as cubics, while each facet's polygon stays
//! the shape that visibility and depth are worked out on.
use vectorcraft_geom::{BezPath, CubicBez, ParamCurve, PathData, Point};
use vectorcraft_geom::{BezPath, CubicBez, ParamCurve, PathData, Point, Vec2};
use super::rings::{Ring, Span};
@@ -75,15 +75,54 @@ fn fit(g: &dyn Fn(f64) -> Point, p: Point, q: Point, a: f64, b: f64, tolerance:
fit(g, p, m, a, mid, tolerance, depth + 1, out) && fit(g, m, q, mid, b, tolerance, depth + 1, out)
}
/// How much of a corner's offset from the outline is left at share `x` of the way from the corner
/// to where the offset is eased out: 1 at the corner, 0 from 1 on, with no slope at either.
pub(super) fn fade(x: f64) -> f64 {
let x = x.clamp(0.0, 1.0);
1.0 - x * x * (3.0 - 2.0 * x)
}
/// 1 at `from`, 0 from `to` on ([`fade`] over `t`).
fn ease(t: f64, from: f64, to: f64) -> f64 {
if to == from { 1.0 } else { fade((t - from) / (to - from)) }
}
/// The edge a piece of a wall's edge is cut from: its corners lie off the outline by `d.0` where
/// the edge starts on its span's curve (`t.0`) and by `d.1` where it ends (`t.1`). Each offset is
/// eased out across the whole edge, as a cap's edge eases it, so the pieces follow the cap's curve.
#[derive(Clone, Copy)]
struct Whole {
t: (f64, f64),
d: (Vec2, Vec2),
}
impl Whole {
/// The outline at `t` on `span`'s curve, moved by the corners' offsets eased across the edge.
fn at(&self, step: &Along, span: &Span, t: f64) -> Point {
(step.at)(span, t) + self.d.0 * ease(t, self.t.0, self.t.1) + self.d.1 * ease(t, self.t.1, self.t.0)
}
}
/// The cubics from `p` to `q` along the piece of `span`'s curve from `t0` to `t1` at `step`, or
/// `None` when they do not fit, or would take the budget past [`MAX_OUTLINE_CURVES`].
///
/// `p` and `q` are the face's own corners, which a bevel's miter can move off the curve's offset
/// where the curve meets another edge at an angle. The difference is eased out from `p` by `fade.0`
/// and into `q` from `fade.1` (the ends of the first and last sampled edge), as the face's polygon
/// does over those edges, so the curves meet the face's corners.
/// does over those edges, so the curves meet the face's corners. With `whole`, the piece is cut from
/// that edge, and the curve it follows is the whole edge's, with `p` and `q` measured from it.
#[allow(clippy::too_many_arguments)]
fn piece(step: &Along, span: &Span, t0: f64, t1: f64, fade: (f64, f64), p: Point, q: Point, budget: &mut Budget) -> Option<Vec<CubicBez>> {
fn piece(
step: &Along,
span: &Span,
t0: f64,
t1: f64,
fade: (f64, f64),
p: Point,
q: Point,
whole: Option<Whole>,
budget: &mut Budget,
) -> Option<Vec<CubicBez>> {
if let Some(map) = step.map {
let c = span.curve.subsegment(t0..t1);
let c = CubicBez::new(p, map(c.p1), map(c.p2), q);
@@ -94,13 +133,9 @@ fn piece(step: &Along, span: &Span, t0: f64, t1: f64, fade: (f64, f64), p: Point
return (budget.0 <= MAX_OUTLINE_CURVES).then(|| vec![c]);
}
}
let (dp, dq) = (p - (step.at)(span, t0), q - (step.at)(span, t1));
// 1 at the end, 0 from `to` on, with no slope at either.
let ease = |t: f64, from: f64, to: f64| {
let x = if to == from { 1.0 } else { ((t - from) / (to - from)).clamp(0.0, 1.0) };
1.0 - x * x * (3.0 - 2.0 * x)
};
let g = |t: f64| (step.at)(span, t) + dp * ease(t, t0, fade.0) + dq * ease(t, t1, fade.1);
let base = |t: f64| whole.map_or_else(|| (step.at)(span, t), |w| w.at(step, span, t));
let (dp, dq) = (p - base(t0), q - base(t1));
let g = |t: f64| base(t) + dp * ease(t, t0, fade.0) + dq * ease(t, t1, fade.1);
let mut out = vec![];
if !fit(&g, p, q, t0, t1, step.tolerance, 0, &mut out) {
return None;
@@ -141,7 +176,7 @@ fn contour(path: &mut BezPath, ring: &Ring, points: &[Point], step: &Along, budg
(j, t1, last) = (j + 1, next.t1, next.t0);
}
let (p, q) = (points.get(i).copied().unwrap_or(first), end(j));
match piece(step, &span, span.t0, t1, (span.t1, last), p, q, budget) {
match piece(step, &span, span.t0, t1, (span.t1, last), p, q, None, budget) {
Some(curves) => {
curved = true;
for c in curves {
@@ -173,11 +208,31 @@ pub(super) fn face(rings: &[&Ring], points: &[Vec<Point>], step: &Along, budget:
/// The outline of a wall's quad `quad` (`a`, `a'`, `b'`, `b` projected: the edge at `near` from
/// `a` to `a'`, then the edge at `far` back from `b'` to `b`), whose edges along the profile follow
/// `span`. An edge without its outline stays straight. `None` when neither edge is curved.
pub(super) fn wall(span: &Span, quad: &[Point], near: Option<&Along>, far: Option<&Along>, budget: &mut Budget) -> Option<PathData> {
/// `span`'s curve from `t.0` to `t.1` (all of `span`, or the piece of it one cut of a twisted wall
/// takes). `ends` are the corners of the whole edges at `near` and at `far` (projected, where each
/// starts and ends on all of `span`), so that a piece follows the curve the whole edge does, as the
/// cap's edge it meets. An edge without its outline stays straight. `None` when neither edge is
/// curved.
#[allow(clippy::too_many_arguments)]
pub(super) fn wall(
span: &Span,
t: (f64, f64),
ends: [[Point; 2]; 2],
quad: &[Point],
near: Option<&Along>,
far: Option<&Along>,
budget: &mut Budget,
) -> Option<PathData> {
let [a, a2, b2, b] = <[Point; 4]>::try_from(quad).ok()?;
let front = near.and_then(|near| piece(near, span, span.t0, span.t1, (span.t1, span.t0), a, a2, budget));
let back = far.and_then(|far| piece(far, span, span.t1, span.t0, (span.t0, span.t1), b2, b, budget));
let (t0, t1) = t;
let whole = |step: &Along, [p, q]: [Point; 2]| {
let d = (p - (step.at)(span, span.t0), q - (step.at)(span, span.t1));
let finite = [d.0, d.1].iter().all(|d| d.x.is_finite() && d.y.is_finite());
finite.then_some(Whole { t: (span.t0, span.t1), d })
};
let [near_ends, far_ends] = ends;
let front = near.and_then(|near| piece(near, span, t0, t1, (t1, t0), a, a2, whole(near, near_ends), budget));
let back = far.and_then(|far| piece(far, span, t1, t0, (t0, t1), b2, b, whole(far, far_ends), budget));
if front.is_none() && back.is_none() {
return None;
}
@@ -195,3 +250,40 @@ pub(super) fn wall(span: &Span, quad: &[Point], near: Option<&Along>, far: Optio
path.close_path();
Some(PathData::from_bezpath(&path))
}
/// A piece of curve one edge of a face follows: the span, and the parameters on its curve where the
/// edge starts and ends.
pub(super) type EdgeCurve = (Span, f64, f64);
/// The outline of a face whose contours `points` (projected) have some edges along pieces of curve:
/// `curves[c][k]` is the piece edge `k` of contour `c` follows, at `step`, or `None` for a straight
/// edge. `None` when no edge is curved.
pub(super) fn edges(points: &[Vec<Point>], curves: &[Vec<Option<EdgeCurve>>], step: &Along, budget: &mut Budget) -> Option<PathData> {
if points.len() != curves.len() || curves.iter().flatten().all(Option::is_none) {
return None;
}
let mut path = BezPath::new();
let mut curved = false;
for (points, curves) in points.iter().zip(curves) {
let n = points.len();
let Some(&first) = points.first() else { continue };
if curves.len() != n {
return None;
}
path.move_to(first);
for (k, c) in curves.iter().enumerate() {
let (p, q) = (points.get(k).copied().unwrap_or(first), points.get((k + 1) % n).copied().unwrap_or(first));
match c.as_ref().and_then(|(span, t0, t1)| piece(step, span, *t0, *t1, (*t1, *t0), p, q, None, budget)) {
Some(cubics) => {
curved = true;
cubics.iter().for_each(|c| path.curve_to(c.p1, c.p2, c.p3));
}
// The edge back to the first point is drawn by `close_path`.
None if k + 1 < n => path.line_to(q),
None => {}
}
}
path.close_path();
}
curved.then(|| PathData::from_bezpath(&path))
}
+1
View File
@@ -106,6 +106,7 @@ pub(super) const DEBRIS: f64 = 1e-6;
/// contours were merged. An empty answer is an answer: contours that cancel (a square drawn twice
/// under even-odd), or that are all thinner than [`DEBRIS`], fill nothing, so nothing is built.
/// Each curve takes at most `most` pieces, on the profile as drawn and on the merged outline.
#[cfg(test)]
pub(super) fn solid_rings(path: &PathData, rule: FillRule, size: f64, limit: usize, most: u32) -> Result<Vec<Vec<Point>>, String> {
Ok(solid_rings_traced(path, rule, size, limit, most)?.into_iter().map(|r| r.points).collect())
}
+283
View File
@@ -0,0 +1,283 @@
use vectorcraft_geom::{BezPath, CubicBez, FillRule, PathData, Point, Rect};
use super::build::Turn;
use super::*;
fn shape(b: &BezPath) -> (PathData, Rect) {
let p = PathData::from_bezpath(b);
let r = p.bounds().unwrap();
(p, r)
}
/// Straight on, without perspective.
fn front() -> View {
View { rotation_x: 0.0, rotation_y: 0.0, rotation_z: 0.0, perspective: 0.0, ..View::default() }
}
/// A circle of four cubics about `c`.
fn circle(c: Point, r: f64) -> BezPath {
let k = 0.552_284_749_830_793_6 * r;
let mut b = BezPath::new();
b.move_to((c.x + r, c.y));
b.curve_to((c.x + r, c.y + k), (c.x + k, c.y + r), (c.x, c.y + r));
b.curve_to((c.x - k, c.y + r), (c.x - r, c.y + k), (c.x - r, c.y));
b.curve_to((c.x - r, c.y - k), (c.x - k, c.y - r), (c.x, c.y - r));
b.curve_to((c.x + k, c.y - r), (c.x + r, c.y - k), (c.x + r, c.y));
b.close_path();
b
}
/// A "D" with its counter: straight stems, round bowls, and corners where they meet.
fn letter_d() -> BezPath {
let mut b = BezPath::new();
b.move_to((0.0, 0.0));
b.line_to((40.0, 0.0));
b.curve_to((95.0, 0.0), (95.0, 100.0), (40.0, 100.0));
b.line_to((0.0, 100.0));
b.close_path();
b.move_to((20.0, 20.0));
b.line_to((20.0, 80.0));
b.line_to((40.0, 80.0));
b.curve_to((70.0, 80.0), (70.0, 20.0), (40.0, 20.0));
b.close_path();
b
}
fn square(x: f64, y: f64, s: f64) -> BezPath {
let mut b = BezPath::new();
b.move_to((x, y));
b.line_to((x + s, y));
b.line_to((x + s, y + s));
b.line_to((x, y + s));
b.close_path();
b
}
/// A path's curved segments, segments and anchors.
fn anatomy(p: &PathData) -> [usize; 3] {
let mut n = [0; 3];
for sp in &p.subpaths {
let count = if sp.closed { sp.anchors.len() } else { sp.anchors.len().saturating_sub(1) };
n[0] += (0..count).filter(|i| !sp.segment_is_line(*i)).count();
n[1] += count;
n[2] += sp.anchors.len();
}
n
}
/// A path's curved segments.
fn curves(p: &PathData) -> Vec<CubicBez> {
let mut out = vec![];
for sp in &p.subpaths {
let count = if sp.closed { sp.anchors.len() } else { sp.anchors.len().saturating_sub(1) };
out.extend((0..count).filter(|i| !sp.segment_is_line(*i)).map(|i| sp.segment(i)));
}
out
}
/// `b` flattened to within 1e-6 pt, each point moved by `map`.
fn fine(b: &BezPath, map: impl Fn(Point) -> Point) -> Vec<Vec<Point>> {
let mut out: Vec<Vec<Point>> = vec![];
vectorcraft_geom::kurbo::flatten(b, 1e-6, |el| match el {
vectorcraft_geom::kurbo::PathEl::MoveTo(p) => out.push(vec![map(p)]),
vectorcraft_geom::kurbo::PathEl::LineTo(p) => out.last_mut().into_iter().for_each(|r| r.push(map(p))),
_ => {}
});
out
}
/// How far `c` lies from the polygons `target` at most, at 33 points along it.
fn farthest(c: &CubicBez, target: &[Vec<Point>]) -> f64 {
(0..=32).map(|k| edge_distance(target, c.eval(f64::from(k) / 32.0))).fold(0.0, f64::max)
}
/// A rounded bevel on both sides steps through many rings between the caps. Every edge along the
/// art's curves, between two bevel steps or two wall slices as well as at a cap, is a cubic: each
/// side facet that follows a curve has both its edges curved, four anchors, and lies within the
/// sampling tolerance of its own polygon. Two visible facets on either side of one ring draw the
/// edge they share as the same curve.
#[test]
fn interior_bevel_edges_keep_the_curves_of_the_art() {
for art in [circle(Point::new(50.0, 50.0), 40.0), letter_d()] {
let (p, b) = shape(&art);
let bevel = Bevel { shape: BevelShape::Rounded, inside: true, width: 4.0, height: 4.0, both_sides: true, ..Bevel::default() };
let o = Extrude { depth: 50.0, bevel: Some(bevel), ..Extrude::default() };
let f = extrude(&p, FillRule::EvenOdd, b, o, View { rotation_x: 20.0, rotation_y: 30.0, ..front() }).unwrap();
let sides: Vec<&Facet> = f.iter().filter(|f| f.side && f.outline.is_some()).collect();
assert!(sides.len() > 40, "{}", sides.len());
for side in &sides {
let path = side.path();
assert_eq!(anatomy(&path), [2, 4, 4], "{path:?}");
for c in curves(&path) {
assert!(farthest(&c, &side.contours) <= 2.0 * 0.05, "{c:?}");
}
}
let all: Vec<(usize, CubicBez)> = sides.iter().enumerate().flat_map(|(k, f)| curves(&f.path()).into_iter().map(move |c| (k, c))).collect();
let mut shared = 0;
for (k, c) in &all {
for (_, d) in all.iter().filter(|(j, d)| j != k && d.p0.distance(c.p3) < 1e-9 && d.p3.distance(c.p0) < 1e-9) {
shared += 1;
let far = (0..=16).map(|u| c.eval(f64::from(u) / 16.0).distance(d.eval(1.0 - f64::from(u) / 16.0))).fold(0.0, f64::max);
assert!(far <= 1e-6, "{far}");
}
}
assert!(shared > 20, "{shared}");
}
}
/// A twist cuts each edge of a wall into pieces at points of the art's curve: every piece keeps
/// both its edges curved, and the pieces at the front draw the cap's edge, within 0.001 pt of the
/// cap's curves without perspective and twice that with it.
#[test]
fn a_twisted_wall_keeps_curves_where_a_twist_cuts_it() {
let art = circle(Point::new(50.0, 50.0), 40.0);
let (p, b) = shape(&art);
// Shallow, so that each slice of the wall is narrower than its edges are long.
let o = Extrude { depth: 2.0, twist: 30.0, ..Extrude::default() };
let turned = View { rotation_x: 20.0, rotation_y: 30.0, ..front() };
for (view, tolerance) in [(turned, outline::CURVE_TOLERANCE), (View { perspective: 60.0, ..turned }, 2.0 * outline::CURVE_TOLERANCE)] {
let f = extrude(&p, FillRule::EvenOdd, b, o, view).unwrap();
let cap = f.iter().find(|f| f.depth == f64::MAX).unwrap();
let corners: Vec<Point> = cap.contours.iter().flatten().copied().collect();
let cap = fine(&cap.path().to_bezpath(), |q| q);
let sides: Vec<&Facet> = f.iter().filter(|f| f.side).collect();
assert!(sides.len() > 64, "{}", sides.len());
let (mut at_cap, mut cut) = (0, 0);
for side in &sides {
let path = side.path();
assert_eq!(anatomy(&path), [2, 4, 4], "{path:?}");
// The cap's curves are fitted within the curve tolerance in perspective.
for c in curves(&path).iter().filter(|c| edge_distance(&cap, c.p0) <= tolerance && edge_distance(&cap, c.p3) <= tolerance) {
at_cap += 1;
// A piece that starts or ends where the twist cuts the edge, between two of the
// cap's sampled points.
if [c.p0, c.p3].iter().any(|q| corners.iter().all(|v| v.distance(*q) > 1e-6)) {
cut += 1;
}
let far = farthest(c, &cap);
assert!(far <= tolerance + 1e-6, "{far}");
}
}
assert!(at_cap > 10 && cut > 5, "{at_cap} at the cap, {cut} of them cut");
}
}
/// A half disc: a straight diameter and a round arc, meeting it at right angles.
fn half_disc() -> BezPath {
let k = 0.552_284_749_830_793_6 * 50.0;
let mut b = BezPath::new();
b.move_to((0.0, 50.0));
b.line_to((100.0, 50.0));
b.curve_to((100.0, 50.0 - k), (50.0 + k, 0.0), (50.0, 0.0));
b.curve_to((50.0 - k, 0.0), (0.0, 50.0 - k), (0.0, 50.0));
b.close_path();
b
}
/// With a bevel, the cap is inset, and its corners where the arc meets the diameter at a right
/// angle lie off the curve's inset by the miter. A twist cuts the band next to the cap into pieces:
/// the pieces that start or end at one of the cap's corners draw the cap's edge, within the cap's
/// sampling tolerance of its curves, with no gap where they meet it.
#[test]
fn twisted_bevel_pieces_meet_the_cap_at_sharp_joins() {
let (p, b) = shape(&half_disc());
let bevel = Bevel { inside: true, width: 4.0, height: 1.0, ..Bevel::default() };
let o = Extrude { depth: 4.0, twist: 30.0, bevel: Some(bevel), ..Extrude::default() };
let turned = View { rotation_x: 20.0, rotation_y: 30.0, ..front() };
for view in [turned, View { perspective: 60.0, ..turned }] {
let f = extrude(&p, FillRule::EvenOdd, b, o, view).unwrap();
let cap = f.iter().find(|f| f.depth == f64::MAX).unwrap();
let corners: Vec<Point> = cap.contours.iter().flatten().copied().collect();
let cap = fine(&cap.path().to_bezpath(), |q| q);
let mut pieces = 0;
for side in f.iter().filter(|f| f.side) {
for c in curves(&side.path()) {
let at_corner = |q: Point| corners.iter().any(|v| v.distance(q) < 1e-6);
// One end at a corner of the cap, the other where the twist cuts the edge.
if at_corner(c.p0) == at_corner(c.p3) {
continue;
}
pieces += 1;
let far = farthest(&c, &cap);
assert!(far <= 2.0 * 0.05 + 1e-6, "{far}: {c:?}");
}
}
assert!(pieces > 10, "{pieces}");
}
}
/// Inflate keeps the art's curves where its faces meet the outline: the flat back is the art
/// turned, one cubic for each of its curves within 0.001 pt; every side facet has both its edges
/// curved; and the front's cells along the outline are curved there, within the sampling
/// tolerance of the art.
#[test]
fn inflate_keeps_the_curves_of_its_outline() {
let art = circle(Point::new(50.0, 50.0), 40.0);
let (p, b) = shape(&art);
let o = Inflate { depth: 20.0, twist: 30.0, ..Inflate::default() };
let behind = View { rotation_y: 180.0, ..front() };
let f = inflate(&p, FillRule::EvenOdd, b, o, behind).unwrap();
let back = f.iter().find(|f| f.depth == f64::MAX).unwrap().path();
assert_eq!(anatomy(&back), [4, 4, 4], "{back:?}");
let camera = Camera::new(behind, b, 1.0);
let turn = Turn::new(b, o.twist, o.taper, 1.0);
let target = fine(&art, |q| camera.project(camera.place(turn.apply(q), -o.depth / 2.0)));
for c in curves(&back) {
assert!(farthest(&c, &target) <= outline::CURVE_TOLERANCE + 1e-6, "{c:?}");
}
for (o, view) in [
(o, View { rotation_x: 20.0, rotation_y: 30.0, ..front() }),
(Inflate { both_sides: true, map_surface: true, ..o }, View { rotation_x: 20.0, rotation_y: 30.0, perspective: 60.0, ..front() }),
] {
let f = inflate(&p, FillRule::EvenOdd, b, o, view).unwrap();
let sides: Vec<&Facet> = f.iter().filter(|f| f.side).collect();
assert!(!sides.is_empty());
assert!(sides.iter().all(|f| anatomy(&f.path())[..2] == [2, 4]), "a side facet with a straight edge along the circle");
let rim: Vec<&Facet> = f.iter().filter(|f| !f.side && f.outline.is_some()).collect();
assert!(rim.len() > 20, "{}", rim.len());
}
// Seen straight on, the front's curved edges are the art's circle.
let f = inflate(&p, FillRule::EvenOdd, b, Inflate::default(), front()).unwrap();
let rim: Vec<CubicBez> = f.iter().filter(|f| f.outline.is_some()).flat_map(|f| curves(&f.path())).collect();
assert!(rim.len() > 20, "{}", rim.len());
let circle = fine(&art, |q| q);
for c in &rim {
assert!(farthest(c, &circle) <= 0.05 + 1e-6, "{c:?}");
}
}
/// A shape of straight edges gets no curves; a tiny circle and a twisted, tapered Inflate keep
/// theirs without points that are not finite.
#[test]
fn straight_tiny_and_twisted_solids_keep_their_curves_bounded() {
let (p, b) = shape(&square(0.0, 0.0, 100.0));
let bevel = Bevel { shape: BevelShape::Rounded, inside: true, width: 4.0, height: 4.0, both_sides: true, ..Bevel::default() };
let view = View { rotation_x: 20.0, rotation_y: 30.0, ..front() };
let f = extrude(&p, FillRule::EvenOdd, b, Extrude { depth: 50.0, twist: 45.0, bevel: Some(bevel), ..Extrude::default() }, view).unwrap();
assert!(f.iter().all(|f| f.outline.is_none()));
let f = inflate(&p, FillRule::EvenOdd, b, Inflate { depth: 20.0, ..Inflate::default() }, view).unwrap();
assert!(f.iter().all(|f| f.outline.is_none()));
let tiny = PathData::from_bezpath(&circle(Point::new(1.0, 1.0), 0.01));
let b = tiny.bounds().unwrap();
for f in [
extrude(
&tiny,
FillRule::NonZero,
b,
Extrude { depth: 0.02, twist: 90.0, bevel: Some(Bevel { width: 0.002, height: 0.002, ..bevel }), ..Extrude::default() },
view,
),
inflate(&tiny, FillRule::NonZero, b, Inflate { depth: 0.02, twist: 360.0, taper: 0.01, both_sides: true, ..Inflate::default() }, view),
] {
let f = f.unwrap();
assert!(f.iter().any(|f| !curves(&f.path()).is_empty()), "no curve on a tiny circle");
for f in f {
for c in curves(&f.path()) {
assert!([c.p0, c.p1, c.p2, c.p3].iter().all(|q| q.x.is_finite() && q.y.is_finite()), "{c:?}");
}
}
}
}
+2 -1
View File
@@ -1690,7 +1690,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Extrude & Bevel and Inflate build detailed shapes: each solid takes up to 65,536 outline points and 163,840 faces (VectorCraft's own limits, was 2,048 points and 32,768 faces), counted before any point is sampled; when the faces do not fit, every curve takes fewer pieces, down to 4. A closed path of 2,000 curves extrudes with a bevel and inflates, and paths of 5,000 and 10,000 curves build at the default settings (`crates/three-d/src/solid/tests_limits.rs`).
- The solids of one Extrude & Bevel (both kinds) or Inflate effect on one object, its fill's, its strokes' and a group's members' together, keep up to 163,840 faces (VectorCraft's own limit). Each solid is built in turn; once their faces pass the limit, no later solid is built, the object draws its source art, and applying or editing the effect, Export 3D Object and Expand as Wireframes report that the 3D surface is too complex. Tests `solids::tests::an_objects_solids_count_their_faces_together`, `a_groups_solids_together_past_the_limit_draw_the_source`, `a_fill_and_strokes_together_past_the_limit_draw_the_source`.
- Inflate at a Volume of 0 % works out each shape's puff only when its solid is built, so no puff is worked out for the shapes after the face limit stops, and the solids are the same bit for bit; with any volume every puff is worked out first, as the highest one places the eye. The shadow builds no solid for a fully transparent fill or stroke. Tests `solid::tests::a_flat_inflate_solves_each_puff_as_its_solid_is_taken`, `a_flat_inflate_solved_as_taken_matches_one_solved_first`, `shadow::tests::an_inflate_shape_that_casts_nothing_builds_no_solid`.
- Extrude & Bevel (both kinds) and Rotate keep the art's curves in the faces they draw, export and expand: caps and the edges of walls and bevels where they meet a cap are cubics with smooth anchors where the art's are, fitted within 0.001 pt in perspective and within the sampling tolerance on a bevel's inset. An edge of a twisted wall that is cut into pieces, a piece of curve that does not fit after 8 halvings, and the curves past 1,048,576 for one solid stay straight (VectorCraft's own values; [three-d.md](three-d.md#what-differs-from-the-public-documentation)). Tests `solid::tests::a_cap_keeps_the_curves_of_the_art`, `a_cap_in_perspective_fits_the_projected_curves`, `a_beveled_cap_and_its_walls_share_their_curves`, `twisted_beveled_tiny_and_degenerate_caps_keep_their_curves`.
- Extrude & Bevel (both kinds) and Rotate keep the art's curves in the faces they draw, export and expand: caps and the edges of walls and bevels where they meet a cap are cubics with smooth anchors where the art's are, fitted within 0.001 pt in perspective and within the sampling tolerance on a bevel's inset. A piece of curve that does not fit after 8 halvings, and the curves past 1,048,576 for one solid stay straight (VectorCraft's own values; [three-d.md](three-d.md#what-differs-from-the-public-documentation)). Tests `solid::tests::a_cap_keeps_the_curves_of_the_art`, `a_cap_in_perspective_fits_the_projected_curves`, `a_beveled_cap_and_its_walls_share_their_curves`, `twisted_beveled_tiny_and_degenerate_caps_keep_their_curves`.
- The edges of Extrude & Bevel's walls and bevels between two bevel steps or two wall slices follow the art's curves too, the same curves on both faces that meet there; a twist cuts a wall's edge at points of the curve, so each piece meets the cap along its curve, a bevel's inset cap included; and Inflate keeps the curves of its flat back, its side walls, and its front and puffed back along the outline (within the sampling tolerance there). Tests `solid::tests_curves::interior_bevel_edges_keep_the_curves_of_the_art`, `a_twisted_wall_keeps_curves_where_a_twist_cuts_it`, `twisted_bevel_pieces_meet_the_cap_at_sharp_joins`, `inflate_keeps_the_curves_of_its_outline`, `straight_tiny_and_twisted_solids_keep_their_curves_bounded`.
- Export 3D Object (Asset Export's menu): an object with Extrude & Bevel, Revolve, Inflate or Rotate becomes a 3D asset whose Format is USDA (the default), USDZ, glTF or OBJ, and Export writes each of its solids as a mesh with a material in its paint's color (`assets.add3D`, `assets.set3DFormat`, `assets.export3D`; [export 3D vector artwork](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/export-3d-vector-artwork.html)).
- Export 3D Object builds each Extrude & Bevel (both kinds) and Inflate solid once: the same build gives the faces that count toward the object's limit and the faces of its mesh, and the meshes match those of a separate build bit for bit. Tests `mesh::tests::a_meshed_solid_is_built_once`, `an_extruded_solid_and_its_mesh_match_the_two_built_apart`, `inflated_solids_and_their_meshes_match_the_two_built_apart`, `solids::tests_mesh::one_build_exports_the_meshes_built_apart`, `a_stroke_past_the_limits_is_left_out_of_the_export`.
- Export 3D Object writes the graphics mapped onto a plane or onto Extrude & Bevel's front and back caps as a PNG texture of each face, the face's color with its graphics drawn flat and unlit over it, on a mesh of that face with texture coordinates, in all four formats (glTF embeds it, USDZ packs it after the layer, OBJ and USDA write `<name>-texture-1.png` beside them; `assets.export3D` `textureSize`, 128 to 4096 pixels, default 1024, VectorCraft's own values; [the help page](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/map-artwork-on-3d-objects.html)). The graphics wrapped around Revolve's side export the same way, as a texture of the side unrolled as the canvas lays it out, on a mesh of the side's triangles, with its end caps and cut sides plain. Materials and lighting are not exported. Tests `a_caps_mesh_corners_go_back_to_the_art_they_were_made_from`, `a_mesh_carries_its_caps_graphics_flat_in_the_arts_plane`, `each_format_carries_a_textured_part_with_its_coordinates_and_picture`, `export_3d_paints_mapped_graphics_on_their_caps_in_every_format`, `a_revolved_sides_corners_lie_where_the_canvas_places_the_unrolled_side`, `a_revolved_sides_layout_matches_its_drawn_faces_at_every_turn`, `export_3d_paints_graphics_mapped_onto_a_revolves_side_in_every_format`, `a_partial_revolve_keeps_its_cut_sides_plain_beside_its_textured_side`.
+12 -9
View File
@@ -689,15 +689,18 @@ out, perspective). No Adobe software, assets, presets or bevel shapes were used.
meet, again on the merged outline, which can have more points (bars crossing in a grid trace every hole between
them); past it, the shape is too complex for the effect.
- The faces drawn, exported and made by **Object › Expand Appearance** keep the shape's curves: the caps of
Extrude & Bevel, the flat face of Rotate, and the edges of the walls and bevels where they meet a cap are cubic
curves, with smooth anchors where the art's are smooth, while visibility and depth are worked out on the
sampled points. Without perspective and bevel each curve maps exactly. With perspective, a curve is split into
cubics until each lies within 0.001 pt of the projected outline. A face inset or outset by a bevel follows its
sampled outline within the sampling tolerance above, one curve for each sampled edge through its two sampled
points, so the cap and the walls next to it draw the edge they share as the same curves. The edges between two bevel steps or two wall slices, a
piece of curve that does not fit after 8 halvings, an edge of a twisted wall cut into pieces, and the curves
past 1,048,576 for one solid stay straight. The tolerances and limits are VectorCraft's own values. Inflate's
faces are polygons.
Extrude & Bevel, the flat face of Rotate, and every edge of the walls and bevels along the art's curves (at a
cap, between two bevel steps and between two wall slices) are cubic curves, with smooth anchors where the
art's are smooth, while visibility and depth are worked out on the sampled points. Without perspective and
bevel each curve maps exactly. With perspective, a curve is split into cubics until each lies within 0.001 pt
of the projected outline. A face inset or outset by a bevel follows its sampled outline within the sampling
tolerance above, one curve for each sampled edge through its two sampled points, so two faces that meet draw
the edge they share as the same curves. A twist cuts a wall's edge into pieces at points of the art's curve,
so each piece follows the same curve as the cap it meets. Inflate keeps the curves of its flat back, of its
side walls and of its front and puffed back where they meet the outline, within the sampling tolerance there;
the inside of a puffed surface stays flat facets. A piece of curve that does not fit after 8 halvings, the
curves past 1,048,576 for one solid, and the cells' edges left once Inflate has looked at 4,194,304 edges of
the outline to find them, stay straight. The tolerances and limits are VectorCraft's own values.
- Inflate also limits the work of filling its grid, which grows with the outline's points times the grid cells its
outline crosses. An outline of tens of thousands of points that crosses nearly every cell (a comb of 4,000 teeth
across the shape) is refused because the 3D surface is too complex; a closed path of 65,536 points round a