Skip to content

armgit / raea

Public Imported from GitHub
0

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.

The lane's last house checks: two copies in apps/direction's check folded away, and the contact lint's feet, wall and face helpers live in core/scene parts.rs, so raea-sys-contact keeps room for LX7's plan

shinyobjectz64d97bac8fe7
diff --git a/apps/direction/src/check.rs b/apps/direction/src/check.rs
index f8d598f8..56be436c 100644
--- a/apps/direction/src/check.rs
+++ b/apps/direction/src/check.rs
@@ -279,19 +279,21 @@ fn check_one(tsx: &Path, id: Option<String>, rules: &[Rule], args: &[String], wh
Ok(Checked { file: tsx.to_path_buf(), id, found: finding::ranked(found), waits, render, shots, fps })
}
-/// Whether a file names SolariLighting.
-fn names(p: &Path) -> bool {
- std::fs::read_to_string(p).unwrap_or_default().contains("SolariLighting")
-}
-
/// Whether a composition is lit by traced light: its file, or a .tsx beside it or a folder down, names SolariLighting.
fn traced(tsx: &Path) -> bool {
- if names(tsx) {
- return true;
- }
- let Some(dir) = tsx.parent() else { return false };
+ let mut files = vec![tsx.to_path_buf()];
let tsxs = |d: &Path| -> Vec<PathBuf> { std::fs::read_dir(d).into_iter().flatten().flatten().map(|e| e.path()).collect() };
- tsxs(dir).into_iter().flat_map(|p| if p.is_dir() { tsxs(&p) } else { vec![p] }).filter(|p| p.extension().is_some_and(|x| x == "tsx")).any(|p| names(&p))
+ if let Some(dir) = tsx.parent() {
+ files.extend(tsxs(dir).into_iter().flat_map(|p| if p.is_dir() { tsxs(&p) } else { vec![p] }).filter(|p| p.extension().is_some_and(|x| x == "tsx")));
+ }
+ for f in files {
+ if let Ok(text) = std::fs::read_to_string(&f) {
+ if text.contains("SolariLighting") {
+ return true;
+ }
+ }
+ }
+ false
}
/// The findings of the newest hold of each frame of a composition (`raea light steady`), from its project's record.
@@ -303,9 +305,12 @@ fn light_held(tsx: &Path, id: Option<&str>) -> Vec<Finding> {
if e.by != "raea light steady" || e.of != of {
continue;
}
- let mut mine = e.findings;
- if let Some(id) = id {
- mine.retain(|f| f.about.iter().any(|a| a.name == id));
+ let mut mine = Vec::new();
+ for f in e.findings {
+ let mut about = f.about.iter().map(|a| a.name.as_str());
+ if id.is_none_or(|id| about.any(|n| n == id)) {
+ mine.push(f);
+ }
}
if let Some(frame) = mine.first().and_then(|f| f.frames) {
newest.insert(frame[0], mine);
diff --git a/core/scene/src/parts.rs b/core/scene/src/parts.rs
index f6c83ede..2154440a 100644
--- a/core/scene/src/parts.rs
+++ b/core/scene/src/parts.rs
@@ -225,6 +225,54 @@ pub fn ray_tri(o: Vec3, d: Vec3, [a, b, c]: [Vec3; 3]) -> Option<f32> {
(t >= 0.0).then_some(t)
}
+/// The part's lowest points (its feet): its vertices within a millimetre (or 2% of its height) of its lowest, and
+/// points across the faces lying there (a slab's corners overhang what holds it up; its middle doesn't), about 4 n at most.
+pub fn feet(p: &Part, n: usize) -> Vec<Vec3> {
+ let tol = (0.02 * (p.hi.y - p.lo.y)).clamp(0.0005, 0.003);
+ let low = |q: &Vec3| q.y <= p.lo.y + tol;
+ let mut v: Vec<Vec3> = p.tris.iter().flatten().filter(|q| low(q)).copied().collect();
+ let bases: Vec<&[Vec3; 3]> = p.tris.iter().filter(|t| t.iter().all(low)).collect();
+ let area: f32 = bases.iter().map(|t| 0.5 * (t[1] - t[0]).cross(t[2] - t[0]).length()).sum();
+ if area > 0.0 {
+ // about n points over the base, spread by area
+ let step = (area / n as f32).sqrt();
+ for t in bases {
+ let long = (t[1] - t[0]).length().max((t[2] - t[1]).length()).max((t[0] - t[2]).length());
+ let m = ((long / step).ceil() as usize).clamp(1, 32);
+ for i in 0..=m {
+ for j in 0..=(m - i) {
+ let (a, b) = (i as f32 / m as f32, j as f32 / m as f32);
+ v.push(t[0] + (t[1] - t[0]) * a + (t[2] - t[0]) * b);
+ }
+ }
+ }
+ }
+ v.sort_by(|a, b| (a.x, a.z, a.y).partial_cmp(&(b.x, b.z, b.y)).unwrap_or(std::cmp::Ordering::Equal));
+ v.dedup_by(|a, b| (*a - *b).length() < 1e-4);
+ if v.len() > 4 * n {
+ let k = v.len() as f32 / (4 * n) as f32;
+ v = (0..4 * n).map(|i| v[(i as f32 * k) as usize]).collect();
+ }
+ v
+}
+
+/// A wall, or a piece of one (the strip of wall over a window, the window in it): no thicker than WALL_THICK, at least
+/// WALL_WIDE across and WALL_TALL high (metres; the kitchen's strip over its back window is 9.6 cm).
+const WALL_THICK: f32 = 0.35;
+const WALL_WIDE: f32 = 0.8;
+const WALL_TALL: f32 = 0.05;
+/// Whether a part is a wall or a piece of one: thin, wide and high.
+pub fn wall(p: &Part) -> bool {
+ let e = p.hi - p.lo;
+ e.y >= WALL_TALL && e.x.min(e.z) <= WALL_THICK && e.x.max(e.z) >= WALL_WIDE
+}
+
+/// A wall's face area, for which of two is set into the other.
+pub fn face(p: &Part) -> f32 {
+ let e = p.hi - p.lo;
+ e.y * e.x.max(e.z)
+}
+
/// Whether a part's own material gives off light (a lamp's panel, a neon tube): any of its emissive's red, green or
/// blue above zero. A model's materials are in its file and aren't read here.
pub fn glows(it: &Item) -> bool {
diff --git a/systems/contact/src/lint.rs b/systems/contact/src/lint.rs
index ee77f80c..42c23223 100644
--- a/systems/contact/src/lint.rs
+++ b/systems/contact/src/lint.rs
@@ -14,7 +14,7 @@ use std::collections::HashMap;
use bevy::math::{Mat4, Vec3};
use serde_json::{json, Value};
-use raea_core_scene::{Item, Part, base_ident, glows, label, parts_of, ray_tri, unparked};
+use raea_core_scene::{Item, Part, base_ident, face, feet, glows, label, parts_of, ray_tri, unparked, wall};
use super::solid_of;
@@ -33,11 +33,6 @@ const SUNK_SHARE: f32 = 0.1;
/// A door this far in front of the carcass behind it, the carcass covering it, is hung on it (doors stand off their
/// cupboard's frame by a reveal; the kitchen pack's by up to 2 cm).
const CARCASS: f32 = 0.025;
-/// A wall, or a piece of one (the strip of wall over a window, the window in it): no thicker than WALL_THICK, at least
-/// WALL_WIDE across and WALL_TALL high (metres; the kitchen's strip over its back window is 9.6 cm).
-const WALL_THICK: f32 = 0.35;
-const WALL_WIDE: f32 = 0.8;
-const WALL_TALL: f32 = 0.05;
/// A part this big across its footprint (m²) with nothing under it is the ground.
const GROUND: f32 = 1.0;
/// The xz grid the scene's triangles are binned in, metres.
@@ -118,49 +113,6 @@ enum Rest {
Ground,
}
-/// The part's lowest points (its feet): its vertices within a millimetre (or 2% of its height) of its lowest, and
-/// points across the faces lying there (a slab's corners overhang what holds it up; its middle doesn't), at most FEET.
-fn feet(p: &Part) -> Vec<Vec3> {
- let tol = (0.02 * (p.hi.y - p.lo.y)).clamp(0.0005, 0.003);
- let low = |q: &Vec3| q.y <= p.lo.y + tol;
- let mut v: Vec<Vec3> = p.tris.iter().flatten().filter(|q| low(q)).copied().collect();
- let bases: Vec<&[Vec3; 3]> = p.tris.iter().filter(|t| t.iter().all(low)).collect();
- let area: f32 = bases.iter().map(|t| 0.5 * (t[1] - t[0]).cross(t[2] - t[0]).length()).sum();
- if area > 0.0 {
- // about FEET points over the base, spread by area
- let step = (area / FEET as f32).sqrt();
- for t in bases {
- let long = (t[1] - t[0]).length().max((t[2] - t[1]).length()).max((t[0] - t[2]).length());
- let m = ((long / step).ceil() as usize).clamp(1, 32);
- for i in 0..=m {
- for j in 0..=(m - i) {
- let (a, b) = (i as f32 / m as f32, j as f32 / m as f32);
- v.push(t[0] + (t[1] - t[0]) * a + (t[2] - t[0]) * b);
- }
- }
- }
- }
- v.sort_by(|a, b| (a.x, a.z, a.y).partial_cmp(&(b.x, b.z, b.y)).unwrap_or(std::cmp::Ordering::Equal));
- v.dedup_by(|a, b| (*a - *b).length() < 1e-4);
- if v.len() > 4 * FEET {
- let k = v.len() as f32 / (4 * FEET) as f32;
- v = (0..4 * FEET).map(|i| v[(i as f32 * k) as usize]).collect();
- }
- v
-}
-
-/// Whether a part is a wall or a piece of one: thin, wide and high.
-fn wall(p: &Part) -> bool {
- let e = p.hi - p.lo;
- e.y >= WALL_TALL && e.x.min(e.z) <= WALL_THICK && e.x.max(e.z) >= WALL_WIDE
-}
-
-/// A wall's face area, for which of two is set into the other.
-fn face(p: &Part) -> f32 {
- let e = p.hi - p.lo;
- e.y * e.x.max(e.z)
-}
-
/// The wall each part is set into (a sill in the wall under it; a window, itself a wall's piece, in a bigger one), if
/// any: its box passes more than 3 mm into the wall's thickness. What's set into a wall and the wall are mounted on each
/// other, and neither is sunk into the other.
@@ -185,7 +137,7 @@ fn rest_of(parts: &[Part], grid: &Grid, insets: &[Option<usize>], i: usize) -> R
let height = p.hi.y - p.lo.y;
// how far above a foot a surface may be and still be the one it stands in (sunk): half its height, at most NEAR
let up = (0.5 * height).min(NEAR);
- let feet = feet(p);
+ let feet = feet(p, FEET);
// each foot: the highest surface of another part from `up` above it down
let mut best: Option<(f32, usize, u32, Vec3)> = None;
let mut nearest_below: Option<(usize, u32, f32)> = None;