Added some really badly-written mapping... fix it later
This commit is contained in:
parent
751f772897
commit
436cb0bbc4
@ -22,8 +22,8 @@ fn curve_horn_start() -> RuleStep {
|
|||||||
},
|
},
|
||||||
final_geom: prim::empty_mesh(),
|
final_geom: prim::empty_mesh(),
|
||||||
children: vec![
|
children: vec![
|
||||||
(Rule::Recurse(curve_horn_thing_rule), id),
|
(Rule::Recurse(curve_horn_thing_rule), id, vec![0,1,2,3]),
|
||||||
(Rule::Recurse(curve_horn_thing_rule), flip180),
|
(Rule::Recurse(curve_horn_thing_rule), flip180, vec![3,2,1,0]),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
// TODO: Fix the consequences of the 180 flip
|
// TODO: Fix the consequences of the 180 flip
|
||||||
@ -77,7 +77,7 @@ fn curve_horn_thing_rule() -> RuleStep {
|
|||||||
geom: geom,
|
geom: geom,
|
||||||
final_geom: final_geom,
|
final_geom: final_geom,
|
||||||
children: vec![
|
children: vec![
|
||||||
(Rule::Recurse(curve_horn_thing_rule), m),
|
(Rule::Recurse(curve_horn_thing_rule), m, vec![0,1,2,3]),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,11 +102,11 @@ fn cube_thing_rule() -> RuleStep {
|
|||||||
geometry::Rotation3::from_axis_angle(z, -qtr).to_homogeneous(),
|
geometry::Rotation3::from_axis_angle(z, -qtr).to_homogeneous(),
|
||||||
];
|
];
|
||||||
|
|
||||||
let gen_rulestep = |rot: &Mat4| -> (Rule, Mat4) {
|
let gen_rulestep = |rot: &Mat4| -> (Rule, Mat4, Vec<usize>) {
|
||||||
let m: Mat4 = rot *
|
let m: Mat4 = rot *
|
||||||
Matrix4::new_scaling(0.5) *
|
Matrix4::new_scaling(0.5) *
|
||||||
geometry::Translation3::new(6.0, 0.0, 0.0).to_homogeneous();
|
geometry::Translation3::new(6.0, 0.0, 0.0).to_homogeneous();
|
||||||
(Rule::Recurse(cube_thing_rule), m)
|
(Rule::Recurse(cube_thing_rule), m, vec![])
|
||||||
};
|
};
|
||||||
|
|
||||||
RuleStep {
|
RuleStep {
|
||||||
@ -171,10 +171,10 @@ fn ram_horn_start() -> RuleStep {
|
|||||||
},
|
},
|
||||||
final_geom: prim::empty_mesh(),
|
final_geom: prim::empty_mesh(),
|
||||||
children: vec![
|
children: vec![
|
||||||
(Rule::Recurse(ram_horn), opening_xform(0.0)),
|
(Rule::Recurse(ram_horn), opening_xform(0.0), vec![0,4,8,7]),
|
||||||
(Rule::Recurse(ram_horn), opening_xform(std::f32::consts::FRAC_PI_2)),
|
(Rule::Recurse(ram_horn), opening_xform(std::f32::consts::FRAC_PI_2), vec![1,5,8,4]),
|
||||||
(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*2.0), vec![2,6,8,5]),
|
||||||
(Rule::Recurse(ram_horn), opening_xform(std::f32::consts::FRAC_PI_2*3.0)),
|
(Rule::Recurse(ram_horn), opening_xform(std::f32::consts::FRAC_PI_2*3.0), vec![3,7,8,6]),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ fn ram_horn() -> RuleStep {
|
|||||||
geom: geom,
|
geom: geom,
|
||||||
final_geom: final_geom,
|
final_geom: final_geom,
|
||||||
children: vec![
|
children: vec![
|
||||||
(Rule::Recurse(ram_horn), incr),
|
(Rule::Recurse(ram_horn), incr, vec![0,1,2,3]),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,13 +84,13 @@ impl OpenMesh {
|
|||||||
stl_io::write_stl(writer, triangles.iter())
|
stl_io::write_stl(writer, triangles.iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect(&self, others: &Vec<OpenMesh>) -> OpenMesh {
|
pub fn connect(&self, others: &Vec<(OpenMesh, Vec<usize>)>) -> OpenMesh {
|
||||||
|
|
||||||
// Copy body vertices & faces:
|
// Copy body vertices & faces:
|
||||||
let mut verts: Vec<Vertex> = self.verts.clone();
|
let mut verts: Vec<Vertex> = self.verts.clone();
|
||||||
let mut faces = self.faces.clone();
|
let mut faces = self.faces.clone();
|
||||||
|
|
||||||
for other in others {
|
for (other,mapping) in others {
|
||||||
|
|
||||||
// body_offset corresponds to the position in 'verts' at
|
// body_offset corresponds to the position in 'verts' at
|
||||||
// which we're appending everything in 'other.verts' -
|
// which we're appending everything in 'other.verts' -
|
||||||
@ -107,7 +107,7 @@ impl OpenMesh {
|
|||||||
Tag::Body(n) => Tag::Body(n + body_offset),
|
Tag::Body(n) => Tag::Body(n + body_offset),
|
||||||
// Since 'self' vertices are in the same order,
|
// Since 'self' vertices are in the same order,
|
||||||
// parent vertex references retain same index:
|
// parent vertex references retain same index:
|
||||||
Tag::Parent(n) => Tag::Body(*n),
|
Tag::Parent(n) => Tag::Body(mapping[*n]),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/rule.rs
15
src/rule.rs
@ -24,8 +24,8 @@ pub struct RuleStep {
|
|||||||
pub final_geom: OpenMesh,
|
pub final_geom: OpenMesh,
|
||||||
|
|
||||||
// Child rules, paired with the transform that will be applied to
|
// Child rules, paired with the transform that will be applied to
|
||||||
// all of their geometry
|
// all of their geometry and parent vertex mappings
|
||||||
pub children: Vec<(Rule, Mat4)>,
|
pub children: Vec<(Rule, Mat4, Vec<usize>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rule {
|
impl Rule {
|
||||||
@ -59,16 +59,17 @@ impl Rule {
|
|||||||
let rs: RuleStep = f();
|
let rs: RuleStep = f();
|
||||||
|
|
||||||
// Get sub-geometry (from child rules) and transform it:
|
// Get sub-geometry (from child rules) and transform it:
|
||||||
let subgeom: Vec<(OpenMesh, Mat4, u32)> = rs.children.iter().map(|(subrule, subxform)| {
|
let subgeom: Vec<(OpenMesh, Mat4, u32, Vec<usize>)> = rs.children.iter().map(|(subrule, subxform, mapping)| {
|
||||||
let (m,n) = subrule.to_mesh(iters_left - 1);
|
let (m,n) = subrule.to_mesh(iters_left - 1);
|
||||||
(m, *subxform, n)
|
(m, *subxform, n, mapping.clone())
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// Tally up node count:
|
// Tally up node count:
|
||||||
subgeom.iter().for_each(|(_,_,n)| nodes += n);
|
subgeom.iter().for_each(|(_,_,n,_)| nodes += n);
|
||||||
|
|
||||||
let g: Vec<OpenMesh> = subgeom.iter().map(|(m,x,_)| m.transform(*x)).collect();
|
|
||||||
|
|
||||||
|
let g: Vec<(OpenMesh, Vec<usize>)> = subgeom.iter().map(|(m,x,_,mv)| (m.transform(*x), mv.clone())).collect();
|
||||||
|
// TODO: Not clone twice
|
||||||
|
|
||||||
// Connect geometry from this rule (not child rules):
|
// Connect geometry from this rule (not child rules):
|
||||||
return (rs.geom.connect(&g), nodes);
|
return (rs.geom.connect(&g), nodes);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user