diff --git a/crates/three-d/src/mesh/tests_attributes.rs b/crates/three-d/src/mesh/tests_attributes.rs index bbd766a9b9..40313c0e60 100644 --- a/crates/three-d/src/mesh/tests_attributes.rs +++ b/crates/three-d/src/mesh/tests_attributes.rs @@ -220,6 +220,35 @@ fn caps_take_their_art_points_and_the_side_runs_around_the_outline_and_front_to_ } } +#[test] +fn the_parts_of_one_object_place_their_caps_and_planes_in_its_shared_bounds() { + // A small part inside the 100 by 60 pt bounds of its object: its front, back and plane corners + // take their art points in the object's bounds, as a larger part's do, not in its own. + let (big, r) = rectangle(0.0, 0.0, 100.0, 60.0); + let (small, _) = rectangle(10.0, 10.0, 20.0, 20.0); + let on_shared = |m: &Mesh, what: &str| { + let mut seen = 0; + for (t, part) in m.triangles.iter().zip(&m.parts) { + if !matches!(part, MeshPart::Front | MeshPart::Back) { + continue; + } + for &i in t { + let (q, uv) = (m.positions[i as usize], m.uvs[i as usize]); + // The art at (x, y) lies at (x - 50, 30 - y) in the mesh. + assert!((uv[0] - (q[0] + 50.0) / 100.0).abs() < 1e-9 && (uv[1] - (30.0 - q[1]) / 60.0).abs() < 1e-9, "{what} {q:?} {uv:?}"); + seen += 1; + } + } + assert!(seen > 0, "{what}"); + }; + on_shared(&extrude_mesh(&small, FillRule::NonZero, r, Extrude::default(), front()).unwrap(), "extrude"); + on_shared(&plane_mesh(&small, FillRule::NonZero, r, front()).unwrap(), "plane"); + let deep = Inflate { depth: 10.0, ..Inflate::default() }; + for (k, m) in inflate_meshes(&[(&big, FillRule::NonZero), (&small, FillRule::NonZero)], r, deep, front()).enumerate() { + on_shared(&m.unwrap(), &format!("inflate {k}")); + } +} + #[test] fn revolves_side_runs_around_the_sweep_and_along_the_profile() { let (line, lr) = line_profile(); diff --git a/crates/three-d/src/solid/build.rs b/crates/three-d/src/solid/build.rs index 69c0d114a4..d335ac0911 100644 --- a/crates/three-d/src/solid/build.rs +++ b/crates/three-d/src/solid/build.rs @@ -1001,8 +1001,9 @@ pub(crate) fn extrude_faces(path: &PathData, rule: FillRule, bounds: Rect, optio (steps.first(), maps.first(), along.first(), 1.0, PlanarFace::Front, MeshPart::Front), (steps.last(), maps.last(), along.last(), -1.0, PlanarFace::Back, MeshPart::Back), ]; - // Each cap's corners take their art points, before any twist or taper, in the art's bounds. - let area = rings_bounds(rings.iter().copied()); + // Each cap's corners take their art points, before any twist or taper, in `bounds`, which + // every part of one object shares. + let area = bounds; for (s, map, along, n, end, part) in caps { let (Some(s), Some(map)) = (s, map) else { continue }; let before = b.len(); @@ -1217,9 +1218,9 @@ pub(crate) fn plane_faces(path: &PathData, rule: FillRule, bounds: Rect, view: V let up = camera.rotate(V3(0.0, 0.0, 1.0)); let n = if camera.facing(V3::default(), up) < 0.0 { V3(-up.0, -up.1, -up.2) } else { up }; let m = Placing::new(&camera, bounds.center(), Turn::new(bounds, 0.0, 1.0, 0.0), 0.0); - // The plane's corners take their art points in the art's bounds. + // The plane's corners take their art points in `bounds`, which every part of one object shares. let (x, y, origin) = m.frame(); - let plane = Attrs::Planar(PlaneUv { origin, x, y, area: rings_bounds(rings.iter().map(|r| r.points.as_slice())) }); + let plane = Attrs::Planar(PlaneUv { origin, x, y, area: bounds }); b.face(contours, n, Order::Last, MeshPart::Front, |_| plane)?; b.end(0, PlanarFace::Front); let at = |span: &Span, t: f64| camera.project(m.place(span.curve.eval(t))); diff --git a/crates/three-d/src/solid/inflate.rs b/crates/three-d/src/solid/inflate.rs index 5e11fd4b59..97b9e25d21 100644 --- a/crates/three-d/src/solid/inflate.rs +++ b/crates/three-d/src/solid/inflate.rs @@ -1,6 +1,5 @@ use super::build::{ - Attrs, BandMesh, Builder, Built, Camera, Keep, Order, Placing, PlaneUv, Turn, along_ring, check_bounds, cuts, fit, newell, outward, rings_bounds, - share, + Attrs, BandMesh, Builder, Built, Camera, Keep, Order, Placing, PlaneUv, Turn, along_ring, check_bounds, cuts, fit, newell, outward, share, }; 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}; @@ -282,9 +281,10 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee if n.dot(n) > 0.5 { n } else { V3(0.0, 0.0, 1.0) } }; let smooth = view.shade && view.has_colored_lights(); - // For a mesh, a point of the front or back takes its art point in the shape's bounds, and on a - // puffed surface its own normal, front or back (turned as the back is). - let area = rings_bounds(rings.iter().map(Vec::as_slice)); + // For a mesh, a point of the front or back takes its art point in `bounds`, which every shape + // inflated together shares, and on a puffed surface its own normal, front or back (turned as + // the back is). + let area = bounds; let uv = |q: Point| [share(q.x, area.x0, area.x1), share(q.y, area.y0, area.y1)]; let puffed = height > 0.0; let back_normal = |n: V3, turn: &Turn| V3(turn.cos * n.0 - turn.sin * n.1, turn.sin * n.0 + turn.cos * n.1, -n.2); diff --git a/docs/three-d.md b/docs/three-d.md index afbbb2a996..8f0ef2455b 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -109,8 +109,8 @@ normals and triangles, a mesh carries: the smoothing rule and the 60° crease are VectorCraft's own. - **Texture coordinates** for every corner, each from 0 to 1, u to the right and v down, as glTF 2.0 places `TEXCOORD_0` (). Caps, Rotate's plane and Inflate's - front and back take each corner's art point, before any twist or taper, in the art's bounds; the back is not - mirrored. Extrude & Bevel's bevels and walls and Inflate's walls take u along each contour of the outline from its + front and back take each corner's art point, before any twist or taper, in the bounds of the whole object, which all + of its parts share; the back is not mirrored. Extrude & Bevel's bevels and walls and Inflate's walls take u along each contour of the outline from its first point, as the distance over the contour's length, so the seam at the first point has corners at both 0 and 1, and v across the side from the front cap's edge to the back cap's. Revolve's side takes u around the sweep from its start and v along each contour of the profile; its end caps span the disk they close, and its cut sides take each