mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 04:38:29 +00:00
3D: build each solid as its mesh is exported
Mesh export checked the object's solids together by building all of them before the first mesh. It now builds and counts each solid as the loop reaches it, so a mesh past the triangle budget stops the export before the solids after it are built.
This commit is contained in:
@@ -1449,8 +1449,8 @@ fn meshes_for(fx: &Effect, shapes: &[Profile], total: &mut usize, limit: usize)
|
||||
}
|
||||
let (parts, bounds) = solid_parts(shapes, b);
|
||||
// The solids the art draws, past the limits of the object's solids together as it is
|
||||
// ([`built_solids`]), each solid's faces dropped once counted.
|
||||
let drawn: Vec<bool> = built_solids(&fx.id, &p, &parts, bounds, MAX_OBJECT_FACES).map(|r| r.map(|f| f.is_some())).collect::<Result<_, _>>()?;
|
||||
// ([`built_solids`]), each built and its faces counted as the loop reaches it, then dropped.
|
||||
let drawn = built_solids(&fx.id, &p, &parts, bounds, MAX_OBJECT_FACES).map(|r| r.map(|f| f.is_some()));
|
||||
// Inflate lays out every puff at once (they share one eye); each Inflate and Extrude & Bevel
|
||||
// solid and its mesh are built as the loop reaches them.
|
||||
let mut inflated = (fx.id == INFLATE).then(|| {
|
||||
@@ -1460,7 +1460,7 @@ fn meshes_for(fx: &Effect, shapes: &[Profile], total: &mut usize, limit: usize)
|
||||
let extrude = if fx.id == CLASSIC_EXTRUDE { classic_extrude_options(&p) } else { extrude_options(&p) };
|
||||
for ((item, member, area, rule, _, _), drawn) in parts.iter().zip(drawn) {
|
||||
let item: &AppearanceItem = item;
|
||||
if !drawn {
|
||||
if !drawn? {
|
||||
// A stroke the art leaves out is left out of the meshes too; Inflate's next puff
|
||||
// still belongs to the next part.
|
||||
if let Some(built) = inflated.as_mut() {
|
||||
|
||||
@@ -59,6 +59,20 @@ fn the_meshes_of_one_object_share_one_triangle_budget() {
|
||||
assert!(meshes_for(effect, &shapes, &mut total, MAX_MESH_TRIANGLES).is_err_and(|e| e.contains("too complex")));
|
||||
}
|
||||
|
||||
/// A mesh past the budget stops the export before the solids after it are built.
|
||||
#[test]
|
||||
fn the_solids_after_a_mesh_past_the_budget_are_not_built() {
|
||||
let mut n = square_node(1, 100.0);
|
||||
n.appearance.effects.push(fx(EXTRUDE, json!({})));
|
||||
let first = three_d_meshes(&n).unwrap()[0].mesh.triangles.len();
|
||||
let shapes = [Profile { path: profile(&n).unwrap().0, rule: FillRule::NonZero, items: solid_paints(&n), opacity: 1.0, scopes: vec![] }];
|
||||
let Some(effect) = n.appearance.effects.first() else { panic!("no effect") };
|
||||
let mut total = MAX_MESH_TRIANGLES - first + 1;
|
||||
SOLIDS_BUILT.with(|b| b.set(0));
|
||||
assert!(meshes_for(effect, &shapes, &mut total, MAX_MESH_TRIANGLES).is_err_and(|e| e.contains("too complex")));
|
||||
assert_eq!(SOLIDS_BUILT.with(std::cell::Cell::get), 1, "the stroke's solid is never built");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn revolve_stops_at_the_first_mesh_past_the_budget() {
|
||||
// The fill revolves into a mesh; the stroke's profile, copied 1000 times, is too complex to
|
||||
|
||||
Reference in New Issue
Block a user