Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
FO13: a street tree's roots show only in its pit, sized to the tree
shinyobjectzbf95366d5495
diff --git a/systems/foliage/src/lib.rs b/systems/foliage/src/lib.rsindex 2f28d8fd..bc102a60 100644--- a/systems/foliage/src/lib.rs+++ b/systems/foliage/src/lib.rs@@ -70,6 +70,8 @@ pub struct Plant {pub nodes: Vec<Node>,pub bark: Mesh,pub leaves: Vec<Mesh>,+ /// its pit's radius (m from the trunk): the open soil its roots show in, for the ground to draw+ pub pit: f32,}impl Plant {@@ -87,10 +89,10 @@ pub fn grow(req: &Request) -> Result<Plant, String> {let mut rng = Rng::new(req.seed ^ hash_str(sp.id));let (nodes, env) = grow::grow(sp, req, &mut rng);let mut bark = tube::bark(sp, req, &nodes);- roots::foot(sp, req, &nodes, &mut bark);+ let pit = roots::foot(sp, req, &nodes, &mut bark);let cover = atlas::cover(&atlas(sp, req.seed)).max(0.05);let leaves = leaves::leaves(sp, req, &nodes, &env, cover, &mut rng);- Ok(Plant { nodes, bark, leaves })+ Ok(Plant { nodes, bark, leaves, pit })}/// The plant as a .glb: material "bark", and "leaf-0" to "leaf-7" over the species' atlas (alpha mask, both sides).diff --git a/systems/foliage/src/roots.rs b/systems/foliage/src/roots.rsindex 68215bfd..820d2375 100644--- a/systems/foliage/src/roots.rs+++ b/systems/foliage/src/roots.rs@@ -24,6 +24,12 @@ use crate::{Mesh, Request, Rng, hash_str};const DEPTH: f32 = 0.3;/// How steeply a root dives once it's under the soil (m down a metre out)const DIVE: f32 = 0.8;+/// The street tree's pit (m from the trunk's centre), the open soil its roots show in: 0.6 m past the flare and never+/// under 1 m (ASSUMED: a 2 m pit, wider round a big trunk). Past it the roots are under the paving. The plant carries+/// it (Plant::pit) for the ground to draw the same pit.+pub(crate) fn pit(sp: &Species, r_dbh: f32) -> f32 {+ (sp.flare * r_dbh + 0.6).max(1.0)+}struct Root {a: f32,@@ -40,20 +46,22 @@ struct Run {show: f32,}-/// The foot onto the bark: the flare on every level, the roots on the nearest (a request with no pruning).-pub(crate) fn foot(sp: &Species, req: &Request, nodes: &[Node], m: &mut Mesh) {- let Some(trunk) = branches(nodes).into_iter().next() else { return };+/// The foot onto the bark: the flare on every level, the roots on the nearest (a request with no pruning). Returns+/// the tree's pit.+pub(crate) fn foot(sp: &Species, req: &Request, nodes: &[Node], m: &mut Mesh) -> f32 {+ let Some(trunk) = branches(nodes).into_iter().next() else { return 1.0 };+ let r_dbh = nodes[trunk[0]].r;+ let pit = pit(sp, r_dbh);if trunk.len() < 2 || sp.roots == 0 {- return;+ return pit;}let mut rng = Rng::new(req.seed ^ hash_str(sp.id) ^ hash_str("roots"));let n = sp.roots as usize;let roots: Vec<Root> = (0..n).map(|i| Root { a: TAU * (i as f32 + rng.range(-0.3, 0.3)) / n as f32, size: rng.range(0.55, 1.0) }).collect();flare(sp, req, nodes, &trunk, &roots, m);if req.prune > 0.0 {- return;+ return pit;}- let r_dbh = nodes[trunk[0]].r;let (c, _) = along_trunk(nodes, &trunk, 0.0);let mut forks = vec![];for root in &roots {@@ -61,15 +69,17 @@ pub(crate) fn foot(sp: &Species, req: &Request, nodes: &[Node], m: &mut Mesh) {let surf = (sp.surface * rng.range(0.6, 1.4)).clamp(0.05, 0.7);// half the trunk's radius at its biggest (ASSUMED); its top stands up to twice its own half-height by the// trunk on the species that show their roots most (ASSUMED); it meets the soil 1.6-3 trunk radii out, longer- // on those species (0.5-0.9 m on a 0.32 m radius, Lee 2022's range)+ // on those species (0.5-0.9 m on a 0.32 m radius, Lee 2022's range), and inside the pit, its widest side and+ // its wander clear of the paving's edgelet r0 = 0.5 * r_dbh * root.size;let tall0 = r0 * ASPECT.0.sqrt();+ let inside = pit - 0.5 * r_dbh - r0 - 0.08;let run = Run {start: Vec3::new(c.x, 0.0, c.z) + dir * (0.5 * r_dbh),heading: root.a,r0,t0: (3.0 * surf * tall0).min(2.0 * tall0),- show: (r_dbh * (1.6 + 1.4 * root.size) * (0.55 + surf) * rng.range(0.85, 1.15)).clamp(0.25, 1.4),+ show: (r_dbh * (1.6 + 1.4 * root.size) * (0.55 + surf) * rng.range(0.85, 1.15)).clamp(0.25, 1.4).min(inside.max(0.2)),};let fork = draw(m, &run, &mut rng);if root.size > 0.75 {@@ -81,6 +91,7 @@ pub(crate) fn foot(sp: &Species, req: &Request, nodes: &[Node], m: &mut Mesh) {let turn = if rng.f() < 0.5 { -1.0 } else { 1.0 } * rng.range(0.5, 0.9);draw(m, &Run { heading: f.heading + turn, r0: 0.6 * f.r0, show: f.show * rng.range(0.5, 0.8), ..f }, &mut rng);}+ pit}/// A root's section, height over width: where it leaves the trunk and where it meets the soil (ASSUMED)diff --git a/systems/foliage/src/tests.rs b/systems/foliage/src/tests.rsindex c14c2209..fd47a2f0 100644--- a/systems/foliage/src/tests.rs+++ b/systems/foliage/src/tests.rs@@ -84,6 +84,9 @@ fn every_species_grows() {let req = Request { species: sp.id.into(), height: 12.0, width: 12.0 / sp.height_per_width, clear: 2.5, seed: 7, leaves: 3_000, prune: 0.0 };let t = grow(&req).unwrap();assert!(t.nodes.len() > 200 && t.leaf_count() > 500, "{}: {} nodes, {} leaves", sp.id, t.nodes.len(), t.leaf_count());+ // its roots show only in its pit: past it they're under the paving+ let reach = t.bark.pos.iter().filter(|p| p[1] > 0.0 && p[1] < 0.5).map(|p| p[0].hypot(p[2])).fold(0.0, f32::max);+ assert!(reach < t.pit && t.pit >= 1.0, "{}: bark above the ground {reach:.2} m from the trunk, its pit {:.2} m", sp.id, t.pit);}}@@ -111,7 +114,9 @@ fn grow_files() {let id = r["id"].as_str().unwrap();std::fs::write(out.join(format!("{id}.glb")), &bytes).unwrap();atlas(crate::species(&req.species).unwrap(), req.seed).save(out.join(format!("{id}-atlas.png"))).unwrap();- println!("{id}: {} nodes, {} bark triangles, {} leaves, grown in {ms} ms, {} KB", t.nodes.len(), t.bark.tris(), t.leaf_count(), bytes.len() / 1024);+ // the pit the ground draws round it+ std::fs::write(out.join(format!("{id}.json")), serde_json::json!({ "pit": (t.pit * 100.0).round() / 100.0 }).to_string()).unwrap();+ println!("{id}: pit {:.2} m, {} nodes, {} bark triangles, {} leaves, grown in {ms} ms, {} KB", t.pit, t.nodes.len(), t.bark.tris(), t.leaf_count(), bytes.len() / 1024);}}