Small refactor
This commit is contained in:
parent
2c9a273540
commit
84b7bd0b21
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
## Highest priority:
|
## Highest priority:
|
||||||
|
|
||||||
- Do transforms compose in the *reverse* of automata_scratch? This
|
- Implement some of the tougher examples from the above too, e.g. the
|
||||||
appears to be the case.
|
triple nested spiral. See `examples.py`.
|
||||||
|
|
||||||
## Important but less critical:
|
## Important but less critical:
|
||||||
|
|
||||||
@ -16,8 +16,6 @@
|
|||||||
- Docs on modules
|
- Docs on modules
|
||||||
- Grep for all TODOs in code, really.
|
- Grep for all TODOs in code, really.
|
||||||
- Look at everything in README.md in automata_scratch.
|
- Look at everything in README.md in automata_scratch.
|
||||||
- Implement some of the tougher examples from the above too, e.g. the
|
|
||||||
triple nested spiral. See `examples.py`.
|
|
||||||
|
|
||||||
## If I'm bored:
|
## If I'm bored:
|
||||||
|
|
||||||
|
|||||||
@ -15,9 +15,9 @@ struct CurveHorn {
|
|||||||
|
|
||||||
impl CurveHorn {
|
impl CurveHorn {
|
||||||
|
|
||||||
fn init() -> CurveHorn {
|
fn init() -> (CurveHorn, Rule<CurveHorn>) {
|
||||||
let y = &Vector3::y_axis();
|
let y = &Vector3::y_axis();
|
||||||
CurveHorn {
|
let c = CurveHorn {
|
||||||
seed: vec![
|
seed: vec![
|
||||||
vertex(-0.5, -0.5, 0.0),
|
vertex(-0.5, -0.5, 0.0),
|
||||||
vertex(-0.5, 0.5, 0.0),
|
vertex(-0.5, 0.5, 0.0),
|
||||||
@ -31,7 +31,8 @@ impl CurveHorn {
|
|||||||
incr: geometry::Rotation3::from_axis_angle(y, 0.1).to_homogeneous() *
|
incr: geometry::Rotation3::from_axis_angle(y, 0.1).to_homogeneous() *
|
||||||
Matrix4::new_scaling(0.95) *
|
Matrix4::new_scaling(0.95) *
|
||||||
geometry::Translation3::new(0.0, 0.0, 0.2).to_homogeneous(),
|
geometry::Translation3::new(0.0, 0.0, 0.2).to_homogeneous(),
|
||||||
}
|
};
|
||||||
|
(c, Rule { eval: Self::start })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&self) -> RuleEval<Self> {
|
fn start(&self) -> RuleEval<Self> {
|
||||||
@ -108,8 +109,8 @@ struct CubeThing {
|
|||||||
|
|
||||||
impl CubeThing {
|
impl CubeThing {
|
||||||
|
|
||||||
fn init() -> CubeThing {
|
fn init() -> (CubeThing, Rule<CubeThing>) {
|
||||||
CubeThing {}
|
(CubeThing {}, Rule { eval: Self::rec })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rec(&self) -> RuleEval<Self> {
|
fn rec(&self) -> RuleEval<Self> {
|
||||||
@ -156,8 +157,8 @@ struct RamHorn {
|
|||||||
|
|
||||||
impl RamHorn {
|
impl RamHorn {
|
||||||
|
|
||||||
fn init() -> RamHorn {
|
fn init() -> (RamHorn, Rule<RamHorn>) {
|
||||||
RamHorn{}
|
(RamHorn{}, Rule { eval: Self::start })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conversion from Python & automata_scratch
|
// Conversion from Python & automata_scratch
|
||||||
@ -300,7 +301,7 @@ struct Twist {
|
|||||||
|
|
||||||
impl Twist {
|
impl Twist {
|
||||||
|
|
||||||
pub fn init() -> Twist {
|
pub fn init() -> (Twist, Rule<Twist>) {
|
||||||
let subdiv = 2;
|
let subdiv = 2;
|
||||||
let seed = vec![
|
let seed = vec![
|
||||||
vertex(-0.5, 0.0, -0.5),
|
vertex(-0.5, 0.0, -0.5),
|
||||||
@ -309,7 +310,7 @@ impl Twist {
|
|||||||
vertex(-0.5, 0.0, 0.5),
|
vertex(-0.5, 0.0, 0.5),
|
||||||
];
|
];
|
||||||
let seed_sub = util::subdivide_cycle(&seed, subdiv);
|
let seed_sub = util::subdivide_cycle(&seed, subdiv);
|
||||||
Twist {
|
let t = Twist {
|
||||||
dx0: 2.0,
|
dx0: 2.0,
|
||||||
dy: 0.1,
|
dy: 0.1,
|
||||||
ang: 0.1,
|
ang: 0.1,
|
||||||
@ -317,7 +318,8 @@ impl Twist {
|
|||||||
seed: seed,
|
seed: seed,
|
||||||
seed_sub: seed_sub,
|
seed_sub: seed_sub,
|
||||||
subdiv: subdiv,
|
subdiv: subdiv,
|
||||||
}
|
};
|
||||||
|
(t, Rule { eval: Self::start })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meant to be a copy of twist_from_gen from Python & automata_scratch
|
// Meant to be a copy of twist_from_gen from Python & automata_scratch
|
||||||
@ -403,7 +405,7 @@ pub fn main() {
|
|||||||
println!("vs2={:?}", vs2);
|
println!("vs2={:?}", vs2);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_test<A>(a: A, r: Rule<A>, iters: u32, name: &str) {
|
fn run_test<A>((a, r): (A, Rule<A>), iters: u32, name: &str) {
|
||||||
println!("Running {}...", name);
|
println!("Running {}...", name);
|
||||||
let (mesh, nodes) = r.to_mesh(&a, iters);
|
let (mesh, nodes) = r.to_mesh(&a, iters);
|
||||||
println!("Evaluated {} rules", nodes);
|
println!("Evaluated {} rules", nodes);
|
||||||
@ -412,7 +414,7 @@ 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) {
|
fn run_test_iter<A>((a, r): (A, Rule<A>), iters: usize, name: &str) {
|
||||||
println!("Running {}...", name);
|
println!("Running {}...", name);
|
||||||
let (mesh, nodes) = r.to_mesh_iter(&a, iters);
|
let (mesh, nodes) = r.to_mesh_iter(&a, iters);
|
||||||
println!("Evaluated {} rules", nodes);
|
println!("Evaluated {} rules", nodes);
|
||||||
@ -420,7 +422,7 @@ pub fn main() {
|
|||||||
println!("Writing {}...", fname);
|
println!("Writing {}...", fname);
|
||||||
mesh.write_stl_file(&fname).unwrap();
|
mesh.write_stl_file(&fname).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
run_test(CubeThing::init(), Rule { eval: CubeThing::rec }, 3, "cube_thing");
|
run_test(CubeThing::init(), Rule { eval: 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
|
||||||
@ -431,11 +433,11 @@ pub fn main() {
|
|||||||
run_test(Twist::init(), Rule { eval: Twist::start }, 200, "twist");
|
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(CubeThing::init(), 3, "cube_thing2");
|
||||||
run_test_iter(CurveHorn::init(), Rule { eval: CurveHorn::start }, 100, "curve_horn2_iter");
|
run_test_iter(CurveHorn::init(), 100, "curve_horn2_iter");
|
||||||
run_test_iter(RamHorn::init(), Rule { eval: RamHorn::start }, 100, "ram_horn2");
|
run_test_iter(RamHorn::init(), 100, "ram_horn2");
|
||||||
// TODO: If I increase the above from 100 to ~150, Blender reports
|
// 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
|
// that the very tips are non-manifold. I am wondering if this is
|
||||||
// some sort of numerical precision issue.
|
// some sort of numerical precision issue.
|
||||||
run_test_iter(Twist::init(), Rule { eval: Twist::start }, 200, "twist2");
|
run_test_iter(Twist::init(), 200, "twist2");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use crate::openmesh::{OpenMesh, Tag, Mat4};
|
use crate::openmesh::{OpenMesh, Tag, Mat4};
|
||||||
use crate::prim;
|
//use crate::prim;
|
||||||
|
|
||||||
/// Definition of a rule. In general, a `Rule`:
|
/// Definition of a rule. In general, a `Rule`:
|
||||||
///
|
///
|
||||||
@ -9,7 +9,6 @@ use crate::prim;
|
|||||||
pub struct Rule<A> {
|
pub struct Rule<A> {
|
||||||
pub eval: fn (&A) -> RuleEval<A>,
|
pub eval: fn (&A) -> RuleEval<A>,
|
||||||
}
|
}
|
||||||
// TODO: Rename rules?
|
|
||||||
// TODO: It may be possible to have just a 'static' rule that requires
|
// TODO: It may be possible to have just a 'static' rule that requires
|
||||||
// no function call.
|
// no function call.
|
||||||
// TODO: Do I benefit with Rc<Rule> below so Rule can be shared?
|
// TODO: Do I benefit with Rc<Rule> below so Rule can be shared?
|
||||||
@ -158,7 +157,7 @@ impl<A> Rule<A> {
|
|||||||
eval_count += 1;
|
eval_count += 1;
|
||||||
|
|
||||||
// Make an updated world transform:
|
// Make an updated world transform:
|
||||||
let xf = s.xf * child.xf; // TODO: Check order on this
|
let xf = s.xf * child.xf;
|
||||||
|
|
||||||
// This rule produced some geometry which we'll
|
// This rule produced some geometry which we'll
|
||||||
// combine with the 'global' geometry:
|
// combine with the 'global' geometry:
|
||||||
@ -221,7 +220,6 @@ impl<A> Rule<A> {
|
|||||||
// eval.children), remove it - we're done with it.
|
// eval.children), remove it - we're done with it.
|
||||||
s.next += 1;
|
s.next += 1;
|
||||||
if s.next >= s.rules.len() {
|
if s.next >= s.rules.len() {
|
||||||
let m = stack.len();
|
|
||||||
stack.pop();
|
stack.pop();
|
||||||
n -= 1;
|
n -= 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user