Fixed ramhorn example
This commit is contained in:
parent
dce29003f1
commit
0bcb85709e
127
src/examples.rs
127
src/examples.rs
@ -777,6 +777,7 @@ pub fn wind_chime_mistake_thing() -> Rule<WindChimeCtxt> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
pub fn ramhorn() -> Rule<()> {
|
pub fn ramhorn() -> Rule<()> {
|
||||||
|
|
||||||
@ -786,52 +787,52 @@ pub fn ramhorn() -> Rule<()> {
|
|||||||
rotate(&v, 0.3).
|
rotate(&v, 0.3).
|
||||||
scale(0.9);
|
scale(0.9);
|
||||||
|
|
||||||
let seed = vec![
|
let (a0, a1, a2, a3, s4, s5, s6, s7);
|
||||||
vertex(-0.5, -0.5, 1.0),
|
let seed = vec_indexed![
|
||||||
vertex(-0.5, 0.5, 1.0),
|
@s4 VertexUnion::Vertex(vertex(-0.5, -0.5, 1.0)),
|
||||||
vertex( 0.5, 0.5, 1.0),
|
@s5 VertexUnion::Vertex(vertex(-0.5, 0.5, 1.0)),
|
||||||
vertex( 0.5, -0.5, 1.0),
|
@s6 VertexUnion::Vertex(vertex( 0.5, 0.5, 1.0)),
|
||||||
|
@s7 VertexUnion::Vertex(vertex( 0.5, -0.5, 1.0)),
|
||||||
|
@a0 VertexUnion::Arg(0),
|
||||||
|
@a1 VertexUnion::Arg(1),
|
||||||
|
@a2 VertexUnion::Arg(2),
|
||||||
|
@a3 VertexUnion::Arg(3),
|
||||||
];
|
];
|
||||||
let next = incr.transform(&seed);
|
let geom = MeshFunc {
|
||||||
let geom = Rc::new(OpenMesh {
|
verts: seed,
|
||||||
alias_verts: vec![0, 1, 2, 3],
|
|
||||||
verts: next,
|
|
||||||
faces: vec![
|
faces: vec![
|
||||||
5, 0, 4,
|
s5, a0, s4,
|
||||||
1, 0, 5,
|
a1, a0, s5,
|
||||||
6, 1, 5,
|
s6, a1, s5,
|
||||||
2, 1, 6,
|
a2, a1, s6,
|
||||||
7, 2, 6,
|
s7, a2, s6,
|
||||||
3, 2, 7,
|
a3, a2, s7,
|
||||||
4, 3, 7,
|
s4, a3, s7,
|
||||||
0, 3, 4,
|
a0, a3, s4,
|
||||||
],
|
],
|
||||||
});
|
};
|
||||||
let final_geom = Rc::new(OpenMesh {
|
let final_geom = MeshFunc {
|
||||||
verts: vec![],
|
verts: vert_args(0..4),
|
||||||
alias_verts: vec![0, 1, 2, 3],
|
|
||||||
faces: vec![
|
faces: vec![
|
||||||
0, 2, 1,
|
0, 2, 1,
|
||||||
0, 3, 2,
|
0, 3, 2,
|
||||||
],
|
],
|
||||||
});
|
};
|
||||||
|
|
||||||
let recur = move |self_: Rc<Rule<()>>| -> RuleEval<()> {
|
let geom2 = Rc::new(geom.transform(&incr));
|
||||||
|
let fgeom2 = Rc::new(final_geom);
|
||||||
|
let recur = rule_fn!(() => |self_, geom2, fgeom2| {
|
||||||
RuleEval {
|
RuleEval {
|
||||||
geom: geom.clone(),
|
geom: geom2,
|
||||||
final_geom: final_geom.clone(),
|
final_geom: fgeom2,
|
||||||
children: vec![
|
children: vec![
|
||||||
Child {
|
child!(self_, incr, s4, s5, s6, s7),
|
||||||
rule: self_.clone(),
|
|
||||||
xf: incr,
|
|
||||||
arg_vals: vec![0,1,2,3],
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
let opening_xform = |i| {
|
let opening_xform = |i| {
|
||||||
let r = FRAC_PI_2 * i;
|
let r = FRAC_PI_2 * (i as f32);
|
||||||
Transform::new().
|
Transform::new().
|
||||||
rotate(&nalgebra::Vector3::z_axis(), r).
|
rotate(&nalgebra::Vector3::z_axis(), r).
|
||||||
translate(0.25, 0.25, 1.0).
|
translate(0.25, 0.25, 1.0).
|
||||||
@ -842,27 +843,26 @@ pub fn ramhorn() -> Rule<()> {
|
|||||||
let start = move |_| -> RuleEval<()> {
|
let start = move |_| -> RuleEval<()> {
|
||||||
|
|
||||||
RuleEval {
|
RuleEval {
|
||||||
geom: Rc::new(OpenMesh {
|
geom: Rc::new(MeshFunc {
|
||||||
verts: vec![
|
verts: vec![
|
||||||
// 'Top' vertices:
|
// 'Top' vertices:
|
||||||
vertex(-0.5, -0.5, 1.0), // 0 (above 9)
|
VertexUnion::Vertex(vertex(-0.5, -0.5, 1.0)), // 0 (above 9)
|
||||||
vertex(-0.5, 0.5, 1.0), // 1 (above 10)
|
VertexUnion::Vertex(vertex(-0.5, 0.5, 1.0)), // 1 (above 10)
|
||||||
vertex( 0.5, 0.5, 1.0), // 2 (above 11)
|
VertexUnion::Vertex(vertex( 0.5, 0.5, 1.0)), // 2 (above 11)
|
||||||
vertex( 0.5, -0.5, 1.0), // 3 (above 12)
|
VertexUnion::Vertex(vertex( 0.5, -0.5, 1.0)), // 3 (above 12)
|
||||||
// Top edge midpoints:
|
// Top edge midpoints:
|
||||||
vertex(-0.5, 0.0, 1.0), // 4 (connects 0-1)
|
VertexUnion::Vertex(vertex(-0.5, 0.0, 1.0)), // 4 (connects 0-1)
|
||||||
vertex( 0.0, 0.5, 1.0), // 5 (connects 1-2)
|
VertexUnion::Vertex(vertex( 0.0, 0.5, 1.0)), // 5 (connects 1-2)
|
||||||
vertex( 0.5, 0.0, 1.0), // 6 (connects 2-3)
|
VertexUnion::Vertex(vertex( 0.5, 0.0, 1.0)), // 6 (connects 2-3)
|
||||||
vertex( 0.0, -0.5, 1.0), // 7 (connects 3-0)
|
VertexUnion::Vertex(vertex( 0.0, -0.5, 1.0)), // 7 (connects 3-0)
|
||||||
// Top middle:
|
// Top middle:
|
||||||
vertex( 0.0, 0.0, 1.0), // 8
|
VertexUnion::Vertex(vertex( 0.0, 0.0, 1.0)), // 8
|
||||||
// 'Bottom' vertices:
|
// 'Bottom' vertices:
|
||||||
vertex(-0.5, -0.5, 0.0), // 9
|
VertexUnion::Vertex(vertex(-0.5, -0.5, 0.0)), // 9
|
||||||
vertex(-0.5, 0.5, 0.0), // 10
|
VertexUnion::Vertex(vertex(-0.5, 0.5, 0.0)), // 10
|
||||||
vertex( 0.5, 0.5, 0.0), // 11
|
VertexUnion::Vertex(vertex( 0.5, 0.5, 0.0)), // 11
|
||||||
vertex( 0.5, -0.5, 0.0), // 12
|
VertexUnion::Vertex(vertex( 0.5, -0.5, 0.0)), // 12
|
||||||
],
|
],
|
||||||
alias_verts: vec![],
|
|
||||||
faces: vec![
|
faces: vec![
|
||||||
// bottom face:
|
// bottom face:
|
||||||
9, 10, 11,
|
9, 10, 11,
|
||||||
@ -879,38 +879,21 @@ pub fn ramhorn() -> Rule<()> {
|
|||||||
// two faces straddling edge from vertex 3:
|
// two faces straddling edge from vertex 3:
|
||||||
12, 3, 7,
|
12, 3, 7,
|
||||||
12, 6, 3,
|
12, 6, 3,
|
||||||
// four faces from edge (0,1, (1,2, (2,3, (3,0):
|
// four faces from edge (0,1), (1,2), (2,3), (3,0):
|
||||||
9, 4, 10,
|
9, 4, 10,
|
||||||
10, 5, 11,
|
10, 5, 11,
|
||||||
11, 6, 12,
|
11, 6, 12,
|
||||||
12, 7, 9,
|
12, 7, 9,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
final_geom: Rc::new(prim::empty_mesh()),
|
final_geom: Rc::new(prim::empty_mesh().to_meshfunc()),
|
||||||
children: vec![
|
children: vec![
|
||||||
Child {
|
child!(rule!(recur, ()), opening_xform(0), 5, 2, 6, 8),
|
||||||
rule: Rc::new(Rule { eval: Rc::new(recur.clone()), ctxt: () }),
|
child!(rule!(recur, ()), opening_xform(1), 4, 1, 5, 8),
|
||||||
xf: opening_xform(0.0),
|
child!(rule!(recur, ()), opening_xform(2), 7, 0, 4, 8),
|
||||||
arg_vals: vec![5,2,6,8],
|
child!(rule!(recur, ()), opening_xform(3), 6, 3, 7, 8),
|
||||||
},
|
|
||||||
Child {
|
|
||||||
rule: Rc::new(Rule { eval: Rc::new(recur.clone()), ctxt: () }),
|
|
||||||
xf: opening_xform(1.0),
|
|
||||||
arg_vals: vec![4,1,5,8],
|
|
||||||
},
|
|
||||||
Child {
|
|
||||||
rule: Rc::new(Rule { eval: Rc::new(recur.clone()), ctxt: () }),
|
|
||||||
xf: opening_xform(2.0),
|
|
||||||
arg_vals: vec![7,0,4,8],
|
|
||||||
},
|
|
||||||
Child {
|
|
||||||
rule: Rc::new(Rule { eval: Rc::new(recur.clone()), ctxt: () }),
|
|
||||||
xf: opening_xform(3.0),
|
|
||||||
arg_vals: vec![6,3,7,8],
|
|
||||||
},
|
|
||||||
// TODO: These vertex mappings appear to be right.
|
// TODO: These vertex mappings appear to be right.
|
||||||
// Explain *why* they are right.
|
// Explain *why* they are right.
|
||||||
// TODO: Factor out the repetition here.
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -918,6 +901,8 @@ pub fn ramhorn() -> Rule<()> {
|
|||||||
Rule { eval: Rc::new(start), ctxt: () }
|
Rule { eval: Rc::new(start), ctxt: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct RamHornCtxt {
|
pub struct RamHornCtxt {
|
||||||
depth: usize,
|
depth: usize,
|
||||||
|
|||||||
@ -121,12 +121,14 @@ mod tests {
|
|||||||
let f = 40;
|
let f = 40;
|
||||||
run_test(examples::twist(f as f32, 128), 100*f, "screw_full", false);
|
run_test(examples::twist(f as f32, 128), 100*f, "screw_full", false);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ramhorn() {
|
fn ramhorn() {
|
||||||
run_test(examples::ramhorn(), 100, "ram_horn3", false);
|
run_test(examples::ramhorn(), 100, "ram_horn3", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
#[test]
|
#[test]
|
||||||
fn ramhorn_branch() {
|
fn ramhorn_branch() {
|
||||||
run_test(examples::ramhorn_branch(24, 0.25), 32, "ram_horn_branch", false);
|
run_test(examples::ramhorn_branch(24, 0.25), 32, "ram_horn_branch", false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user