Fixed some examples, then broke them further.

I need to add in some sort of parent vertex mapping layer.
This commit is contained in:
Chris Hodapp 2020-02-21 21:46:23 -05:00
parent 19de80da81
commit 751f772897
2 changed files with 86 additions and 47 deletions

View File

@ -2,7 +2,10 @@
## Highest priority:
- Try a more complex case with multiple exit groups
- See `ram_horn_*` and `curve_horn_*` TODOs: these are both solved by
some sort of parent-vertex-mapping layer. The only other way around
this that I need is to require that rule functions exist in
explictly separate forms.
- Consider trampolining `to_mesh`. My call stack seems needlessly
deep in spots. Can I make tail-recursive?
@ -16,8 +19,6 @@
## If I'm bored:
- See `curve_horn_start` comments; can I elegantly solve this issue of
how to connect an exit vertex multiple places?
- Fix links in tri_mesh docs that use relative paths & do a PR?
- Look in https://www.nalgebra.org/quick_reference/# for "pour
obtain". Can I fix this somehow? Looks like a French-ism that made

View File

@ -118,73 +118,111 @@ fn cube_thing_rule() -> RuleStep {
// Conversion from Python & automata_scratch
fn ram_horn_start() -> RuleStep {
let id = nalgebra::geometry::Transform3::identity().to_homogeneous();
let flip180 = nalgebra::geometry::Rotation3::from_axis_angle(
&nalgebra::Vector3::y_axis(),
std::f32::consts::PI).to_homogeneous();
let opening_xform = |i| {
(geometry::Translation3::new(0.0, 0.0, -1.0).to_homogeneous() *
Matrix4::new_scaling(0.5) *
geometry::Translation3::new(0.25, 0.25, 1.0).to_homogeneous() *
geometry::Rotation3::from_axis_angle(
&nalgebra::Vector3::z_axis(), i).to_homogeneous())
};
RuleStep {
geom: OpenMesh {
verts: vec![
// 'Bottom' vertices:
vertex(-0.5, -0.5, -0.5), // 0
vertex(-0.5, 0.5, -0.5), // 1
vertex( 0.5, 0.5, -0.5), // 2
vertex( 0.5, -0.5, -0.5), // 3
// 'Top' vertices:
vertex(-0.5, -0.5, 0.5), // 4 (above 0)
vertex(-0.5, 0.5, 0.5), // 5 (above 1)
vertex( 0.5, 0.5, 0.5), // 6 (above 2)
vertex( 0.5, -0.5, 0.5), // 7 (above 3)
vertex(-0.5, -0.5, 1.0), // 0 (above 9)
vertex(-0.5, 0.5, 1.0), // 1 (above 10)
vertex( 0.5, 0.5, 1.0), // 2 (above 11)
vertex( 0.5, -0.5, 1.0), // 3 (above 12)
// Top edge midpoints:
vertex(-0.5, 0.0, 0.5), // 8 (connects 4-5)
vertex( 0.0, 0.5, 0.5), // 9 (connects 5-6)
vertex( 0.5, 0.0, 0.5), // 10 (connects 6-7)
vertex( 0.0, -0.5, 0.5), // 11 (connects 7-4)
vertex(-0.5, 0.0, 1.0), // 4 (connects 0-1)
vertex( 0.0, 0.5, 1.0), // 5 (connects 1-2)
vertex( 0.5, 0.0, 1.0), // 6 (connects 2-3)
vertex( 0.0, -0.5, 1.0), // 7 (connects 3-0)
// Top middle:
vertex( 0.0, 0.0, 0.5),
vertex( 0.0, 0.0, 1.0), // 8
// 'Bottom' vertices:
vertex(-0.5, -0.5, 0.0), // 9
vertex(-0.5, 0.5, 0.0), // 10
vertex( 0.5, 0.5, 0.0), // 11
vertex( 0.5, -0.5, 0.0), // 12
],
faces: vec![
// bottom face:
Tag::Body(0), Tag::Body(1), Tag::Body(2),
Tag::Body(0), Tag::Body(2), Tag::Body(3),
Tag::Body(9), Tag::Body(10), Tag::Body(11),
Tag::Body(9), Tag::Body(11), Tag::Body(12),
// two faces straddling edge from vertex 0:
Tag::Body(0), Tag::Body(4), Tag::Body(8),
Tag::Body(0), Tag::Body(11), Tag::Body(4),
Tag::Body(9), Tag::Body(0), Tag::Body(4),
Tag::Body(9), Tag::Body(7), Tag::Body(0),
// two faces straddling edge from vertex 1:
Tag::Body(1), Tag::Body(5), Tag::Body(9),
Tag::Body(1), Tag::Body(8), Tag::Body(5),
Tag::Body(10), Tag::Body(1), Tag::Body(5),
Tag::Body(10), Tag::Body(4), Tag::Body(1),
// two faces straddling edge from vertex 2:
Tag::Body(2), Tag::Body(6), Tag::Body(10),
Tag::Body(2), Tag::Body(9), Tag::Body(6),
Tag::Body(11), Tag::Body(2), Tag::Body(6),
Tag::Body(11), Tag::Body(5), Tag::Body(2),
// two faces straddling edge from vertex 3:
Tag::Body(3), Tag::Body(7), Tag::Body(11),
Tag::Body(3), Tag::Body(10), Tag::Body(7),
Tag::Body(12), Tag::Body(3), Tag::Body(7),
Tag::Body(12), Tag::Body(6), Tag::Body(3),
// four faces from edge (0,1), (1,2), (2,3), (3,0):
Tag::Body(0), Tag::Body(8), Tag::Body(1),
Tag::Body(1), Tag::Body(9), Tag::Body(2),
Tag::Body(2), Tag::Body(10), Tag::Body(3),
Tag::Body(3), Tag::Body(11), Tag::Body(0),
Tag::Body(9), Tag::Body(4), Tag::Body(10),
Tag::Body(10), Tag::Body(5), Tag::Body(11),
Tag::Body(11), Tag::Body(6), Tag::Body(12),
Tag::Body(12), Tag::Body(7), Tag::Body(9),
],
},
final_geom: prim::empty_mesh(),
children: vec![
(Rule::Recurse(ram_horn), id), // exit group 0
(Rule::Recurse(ram_horn), id), // exit group 1
(Rule::Recurse(ram_horn), id), // exit group 2
(Rule::Recurse(ram_horn), id), // exit group 3
(Rule::Recurse(ram_horn), opening_xform(0.0)),
(Rule::Recurse(ram_horn), opening_xform(std::f32::consts::FRAC_PI_2)),
(Rule::Recurse(ram_horn), opening_xform(std::f32::consts::FRAC_PI_2*2.0)),
(Rule::Recurse(ram_horn), opening_xform(std::f32::consts::FRAC_PI_2*3.0)),
],
}
}
fn ram_horn() -> RuleStep {
// Incomplete
let v = Unit::new_normalize(Vector3::new(-1.0, 0.0, 1.0));
let incr: Mat4 = Matrix4::new_scaling(0.9) *
geometry::Rotation3::from_axis_angle(&v, 0.3).to_homogeneous() *
geometry::Translation3::new(0.0, 0.0, 0.8).to_homogeneous();
let seed = vec![
vertex(-0.5, -0.5, 1.0),
vertex(-0.5, 0.5, 1.0),
vertex( 0.5, 0.5, 1.0),
vertex( 0.5, -0.5, 1.0),
];
let next = seed.iter().map(|v| incr * v).collect();
let geom = OpenMesh {
verts: next,
faces: vec![
Tag::Body(1), Tag::Parent(0), Tag::Body(0),
Tag::Parent(1), Tag::Parent(0), Tag::Body(1),
Tag::Body(2), Tag::Parent(1), Tag::Body(1),
Tag::Parent(2), Tag::Parent(1), Tag::Body(2),
Tag::Body(3), Tag::Parent(2), Tag::Body(2),
Tag::Parent(3), Tag::Parent(2), Tag::Body(3),
Tag::Body(0), Tag::Parent(3), Tag::Body(3),
Tag::Parent(0), Tag::Parent(3), Tag::Body(0),
// TODO: These are correct once the recursion is already
// going - but they are wrong at the start! Note how I'm
// never using the 'midpoint' vertex from the parent,
// Tag::Parent(8).
],
};
let final_geom = OpenMesh {
verts: vec![],
faces: vec![
Tag::Parent(0), Tag::Parent(2), Tag::Parent(1),
Tag::Parent(0), Tag::Parent(3), Tag::Parent(2),
// TODO: Parent in 'final_geom' refers always to vertices
// in 'geom' - right?
],
};
RuleStep {
geom: OpenMesh {
verts: vec![],
faces: vec![],
},
final_geom: prim::empty_mesh(),
children: vec![],
geom: geom,
final_geom: final_geom,
children: vec![
(Rule::Recurse(ram_horn), incr),
],
}
}
@ -202,5 +240,5 @@ pub fn main() {
run_test(Rule::Recurse(cube_thing_rule), 3, "cube_thing");
//run_test(Rule::Recurse(curve_horn_thing_rule), 100, "curve_horn_thing");
run_test(Rule::Recurse(curve_horn_start), 100, "curve_horn2");
run_test(Rule::Recurse(ram_horn_start), 10, "ram_horn");
run_test(Rule::Recurse(ram_horn_start), 200, "ram_horn");
}