Progressed with to_mesh_iter (still not quite working)

This commit is contained in:
Chris Hodapp 2020-03-01 19:32:45 -05:00
parent cfae58bed6
commit 6a8f0e14c8
2 changed files with 29 additions and 4 deletions

View File

@ -412,6 +412,15 @@ pub fn main() {
mesh.write_stl_file(&fname).unwrap(); mesh.write_stl_file(&fname).unwrap();
} }
fn run_test_iter<A>(a: A, r: Rule<A>, iters: usize, name: &str) {
println!("Running {}...", name);
let (mesh, nodes) = r.to_mesh_iter(&a, iters);
println!("Merged {} nodes", nodes);
let fname = format!("{}.stl", name);
println!("Writing {}...", fname);
mesh.write_stl_file(&fname).unwrap();
}
run_test(CubeThing::init(), Rule::Recurse(CubeThing::rec), 3, "cube_thing"); run_test(CubeThing::init(), Rule::Recurse(CubeThing::rec), 3, "cube_thing");
// this can't work on its own because the resultant OpenMesh still // this can't work on its own because the resultant OpenMesh still
// has parent references: // has parent references:
@ -419,4 +428,6 @@ pub fn main() {
run_test(CurveHorn::init(), Rule::Recurse(CurveHorn::start), 100, "curve_horn2"); run_test(CurveHorn::init(), Rule::Recurse(CurveHorn::start), 100, "curve_horn2");
run_test(RamHorn::init(), Rule::Recurse(RamHorn::start), 200, "ram_horn"); run_test(RamHorn::init(), Rule::Recurse(RamHorn::start), 200, "ram_horn");
run_test(Twist::init(), Rule::Recurse(Twist::start), 200, "twist"); run_test(Twist::init(), Rule::Recurse(Twist::start), 200, "twist");
run_test_iter(CurveHorn::init(), Rule::Recurse(CurveHorn::start), 100, "curve_horn2_iter");
} }

View File

@ -156,17 +156,30 @@ impl<A> Rule<A> {
}, },
} }
let mut count = 0;
while !stack.is_empty() { while !stack.is_empty() {
// TODO: This, more elegantly?
count += 1;
if count > max_depth {
break;
}
let n = stack.len(); // TODO: Just keep a running total. let n = stack.len(); // TODO: Just keep a running total.
println!("DEBUG: stack has len {}", n);
// We can increment/decrement as we push/pop. // We can increment/decrement as we push/pop.
let s = &mut stack[n-1]; let s = &mut stack[n-1];
if s.next >= s.rules.len() { if s.next >= s.rules.len() {
// If we've run out of child rules, backtrack: // If we've run out of child rules, backtrack:
stack.pop(); stack.pop();
// TODO: If we're backtracking, then the *parent* node // and have the *parent* node (if one) move on:
// needs to have 'next' incremented. if n >= 2 {
stack[n-2].next += 1;
}
// (if there isn't one, it makes no difference,
// because the loop will end)
continue; continue;
} }
@ -179,7 +192,8 @@ impl<A> Rule<A> {
// Compose child transform to new world transform: // Compose child transform to new world transform:
let xf = s.xf * child.xf; // TODO: Check order on this let xf = s.xf * child.xf; // TODO: Check order on this
// TODO: Add in new geometry, transformed with 'xf' let new_geom = eval.geom.transform(&xf);
geom = geom.connect(&vec![(new_geom, &child.vmap)]);
// Recurse further (i.e. put more onto stack): // Recurse further (i.e. put more onto stack):
let s2 = State { let s2 = State {