Some more notes and tried other examples with to_mesh_iter

This commit is contained in:
Chris Hodapp 2020-03-06 15:38:25 -05:00
parent 52914b2588
commit 111933c30e
2 changed files with 16 additions and 20 deletions

View File

@ -421,6 +421,7 @@ pub fn main() {
mesh.write_stl_file(&fname).unwrap();
}
/*
run_test(CubeThing::init(), Rule { eval: CubeThing::rec }, 3, "cube_thing");
// this can't work on its own because the resultant OpenMesh still
// has parent references:
@ -428,6 +429,13 @@ pub fn main() {
run_test(CurveHorn::init(), Rule { eval: CurveHorn::start }, 100, "curve_horn2");
run_test(RamHorn::init(), Rule { eval: RamHorn::start }, 200, "ram_horn");
run_test(Twist::init(), Rule { eval: Twist::start }, 200, "twist");
*/
run_test_iter(CubeThing::init(), Rule { eval: CubeThing::rec }, 3, "cube_thing2");
run_test_iter(CurveHorn::init(), Rule { eval: CurveHorn::start }, 100, "curve_horn2_iter");
run_test_iter(RamHorn::init(), Rule { eval: RamHorn::start }, 100, "ram_horn2");
// TODO: If I increase the above from 100 to ~150, Blender reports
// that the very tips are non-manifold. I am wondering if this is
// some sort of numerical precision issue.
run_test_iter(Twist::init(), Rule { eval: Twist::start }, 200, "twist2");
}

View File

@ -151,12 +151,9 @@ impl<A> Rule<A> {
// s = the 'current' state:
let s = &mut stack[n-1];
let depth = s.depth;
// TODO: remove
//println!("DEBUG: stack has len {}; depth={}", n, depth);
let child = &s.rules[s.next];
// Evaluate the rule:
let child = &s.rules[s.next];
let mut eval = (child.rule.eval)(arg);
eval_count += 1;
@ -169,10 +166,6 @@ impl<A> Rule<A> {
// See if we can still recurse further:
if depth <= 0 {
// TODO: remove
//println!("DEBUG: backtracing, depth={}, s.next = {}, s.rules.len() = {}",
// depth, s.next, s.rules.len());
// As we're stopping recursion, we need to connect
// final_geom with all else in order to actually close
// geometry properly:
@ -205,21 +198,18 @@ impl<A> Rule<A> {
continue;
}
// TODO: remove
//println!("DEBUG: Connecting {} faces, vmap={:?}, faces={:?}",
// new_geom.verts.len(), child.vmap, new_geom.faces);
let (g, offsets) = geom.connect(&vec![(new_geom, &child.vmap)]);
geom = g;
// 'new_geom' may itself be parent geometry for
// something in 'eval.children' (via Tag::Parent),
// and vmap is there to resolve those Tag::Parent
// references to the right vertices in 'new_geom'.
// 'eval.children' (via Tag::Parent), and vmap is there to
// resolve Tag::Parent references to the right vertices in
// 'new_geom'.
//
// However, we connect() on the global geometry
// which we merged 'new_geom' into, not 'new_geom'
// directly. To account for this, we must shift
// vmap by the offset that 'geom.connect' gave us:
// However, we connect() on the global geometry which we
// merged 'new_geom' into, not 'new_geom' directly. To
// account for this, we must shift vmap by the offset that
// 'geom.connect' gave us:
for (offset, child) in offsets.iter().zip(eval.children.iter_mut()) {
child.vmap = child.vmap.iter().map(|n| {
n + offset
@ -248,8 +238,6 @@ impl<A> Rule<A> {
}
}
// TODO: Handle final_geom
return (geom, eval_count);
}