euv_core/game/engine3d/modeling/foliage/struct.rs
1use super::*;
2
3/// Single stochastic or deterministic L-system production rule (`predecessor -> successor`).
4#[derive(Clone, Data, Debug, New, PartialEq)]
5pub struct LSystemRule {
6 /// Non-terminal symbol replaced during rewriting.
7 #[get(type(copy))]
8 pub(crate) predecessor: char,
9 /// Replacement string emitted when this production fires.
10 pub(crate) successor: String,
11 /// Relative selection weight when multiple rules share the same `predecessor`.
12 #[get(type(copy))]
13 pub(crate) weight: f32,
14}
15
16/// Deterministic seeded L-system rewriting grammar used to generate botanical branch skeletons.
17#[derive(Clone, Data, Debug, New, PartialEq)]
18pub struct LSystemGrammar {
19 /// Starting axiom string at iteration `0`.
20 pub(crate) axiom: String,
21 /// Ordered list of production rules.
22 pub(crate) rules: Vec<LSystemRule>,
23}
24
25/// Parametric configuration controlling procedural tree geometry, taper, branching, and canopy scale.
26#[derive(Clone, Copy, Data, Debug, PartialEq)]
27pub struct ProceduralTreeConfig {
28 /// Target botanical species preset.
29 #[get(type(copy))]
30 pub(crate) species: TreeSpecies,
31 /// Number of L-system rewriting iterations (`1..=6`).
32 #[get(type(copy))]
33 pub(crate) iterations: u32,
34 /// Initial trunk base radius.
35 #[get(type(copy))]
36 pub(crate) trunk_radius: f32,
37 /// Base length of a single forward turtle step (`F`).
38 #[get(type(copy))]
39 pub(crate) segment_length: f32,
40 /// Branch turning angle in degrees for `+`, `-`, `&`, `^`, `\`, `/`.
41 #[get(type(copy))]
42 pub(crate) branch_angle_deg: f32,
43 /// Radius taper factor applied on each `!` or segment transition.
44 #[get(type(copy))]
45 pub(crate) radius_decay: f32,
46 /// Segment length decay applied when entering nested branches.
47 #[get(type(copy))]
48 pub(crate) length_decay: f32,
49 /// Radial segment count for tubular branches (`3..=16`).
50 #[get(type(copy))]
51 pub(crate) radial_segments: u32,
52 /// Radius scale of emitted canopy foliage clusters.
53 #[get(type(copy))]
54 pub(crate) leaf_cluster_size: f32,
55 /// Vertical tropism bias (`> 0` grows skyward, `< 0` droops downward).
56 #[get(type(copy))]
57 pub(crate) gravity_bias: f32,
58}
59
60/// Output asset bundle produced by `generate_procedural_tree`.
61#[derive(Clone, Data, Debug, PartialEq)]
62pub struct ProceduralTreeResult {
63 /// Combined multi-material mesh merging trunk/branches and canopy foliage.
64 pub(crate) combined_mesh: Mesh3D,
65 /// Standalone tapered tubular bark/branch skeleton mesh.
66 pub(crate) branch_mesh: Mesh3D,
67 /// Standalone canopy foliage leaf cluster mesh.
68 pub(crate) foliage_mesh: Mesh3D,
69 /// Number of emitted tubular branch segments.
70 #[get(type(copy))]
71 pub(crate) branch_segment_count: usize,
72 /// Number of emitted foliage leaf clusters.
73 #[get(type(copy))]
74 pub(crate) leaf_cluster_count: usize,
75}
76
77/// Internal 3D turtle state pushed and popped on `[` and `]` branch tokens.
78#[derive(Clone, Copy, Data, Debug)]
79pub(crate) struct TurtleState3D {
80 /// Current 3D turtle position.
81 #[get(type(copy))]
82 pub(crate) position: Vec3,
83 /// Unit forward growth heading.
84 #[get(type(copy))]
85 pub(crate) heading: Vec3,
86 /// Unit local left axis orthogonal to `heading`.
87 #[get(type(copy))]
88 pub(crate) left: Vec3,
89 /// Unit local up axis completing the orthonormal frame.
90 #[get(type(copy))]
91 pub(crate) up: Vec3,
92 /// Current branch tube radius.
93 #[get(type(copy))]
94 pub(crate) radius: f32,
95 /// Current forward segment length.
96 #[get(type(copy))]
97 pub(crate) step_length: f32,
98 /// Current branching recursion depth.
99 #[get(type(copy))]
100 pub(crate) depth: u32,
101}