From 313aa6203f71d4a44357135a91bf2fb0345786b9 Mon Sep 17 00:00:00 2001 From: hodapp Date: Wed, 4 Mar 2020 20:47:13 -0500 Subject: [PATCH] Revert some of 120ede4b --- src/rule.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/rule.rs b/src/rule.rs index 0f593c5..42693e0 100644 --- a/src/rule.rs +++ b/src/rule.rs @@ -102,16 +102,15 @@ impl Rule { // TODO: This logic is more or less right, but it // could perhaps use some un-tupling or something. - let subgeom: Vec<(OpenMesh, Vec)> = rs.children.iter().map(|sub| { + let subgeom: Vec<(OpenMesh, &Vec)> = rs.children.iter().map(|sub| { // Get sub-geometry (still un-transformed): let (submesh, eval) = sub.rule.to_mesh(arg, iters_left - 1); // Tally up eval count: evals += eval; let m2 = submesh.transform(&sub.xf); - - // TODO: Can I avoid the .clone() here? - (m2, sub.vmap.clone()) + + (m2, &sub.vmap) }).collect(); // Connect geometry from this rule (not child rules): @@ -134,8 +133,6 @@ impl Rule { // is, not including any transform of any element of // 'rules'. xf: Mat4, - // Child geometry for 'rules', waiting to be connected: - geom: Vec<(OpenMesh, Vec)>, } let mut geom = prim::empty_mesh(); @@ -149,7 +146,6 @@ impl Rule { rules: eval.children, next: 0, xf: nalgebra::geometry::Transform3::identity().to_homogeneous(), - geom: vec![], }; stack.push(s); geom = eval.geom; @@ -172,18 +168,24 @@ impl Rule { // TODO: This, more elegantly? count += 1; + if count > max_depth { + break; + } let n = stack.len(); // TODO: Just keep a running total. println!("DEBUG: stack has len {}", n); // We can increment/decrement as we push/pop. let s = &mut stack[n-1]; - if s.next >= s.rules.len() || count > max_depth { - // Connect the geometry we accumulated: - println!("DEBUG: Connecting {} parts", s.geom.len()); - geom = geom.connect(&s.geom); + if s.next >= s.rules.len() { // If we've run out of child rules, backtrack: stack.pop(); + // and have the *parent* node (if one) move on: + if n >= 2 { + stack[n-2].next += 1; + } + // (if there isn't one, it makes no difference, + // because the loop will end) continue; } @@ -194,22 +196,21 @@ impl Rule { let eval = f(arg); // Compose child transform to new world transform: - let xf = child.xf * s.xf; // TODO: Check order on this + let xf = s.xf * child.xf; // TODO: Check order on this let new_geom = eval.geom.transform(&xf); - - s.next += 1; - s.geom.push((new_geom, child.vmap.clone())); - // TODO: this clone() shouldn't be necessary + println!("DEBUG: Connecting {} faces, faces={:?}", + new_geom.verts.len(), new_geom.faces); + geom = geom.connect(&vec![(new_geom, &child.vmap)]); // Recurse further (i.e. put more onto stack): let s2 = State { rules: eval.children, next: 0, xf: xf, - geom: vec![], }; stack.push(s2); + }, Rule::EmptyRule => { s.next += 1;