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.

BK2: one lay() for both bakes, so the same request gives the same atlas by construction

shinyobjectz0b8ec429cb7b
diff --git a/docs/bake.feature b/docs/bake.feature
index 51e28c42..3778208d 100644
--- a/docs/bake.feature
+++ b/docs/bake.feature
@@ -130,7 +130,7 @@ Feature: Light baked by raea: bounce light into lightmaps on raea's own ray trac
Scenario: BK2. Each texel's place in the world
Given the plan
| crate | file | lines | job |
- | raea-sys-atlas | systems/atlas/src/lib.rs | 120 | the atlas both bakes share, split out of raea-sys-weathering (it was at 1999 of 2000 lines and a system may build only on a facility): Ask, layout() |
+ | raea-sys-atlas | systems/atlas/src/lib.rs | 130 | the atlas both bakes share, split out of raea-sys-weathering (it was at 1999 of 2000 lines and a system may build only on a facility): Ask, layout() |
| raea-sys-atlas | systems/atlas/src/scene.rs | 323 | moved from raea-sys-weathering as it was |
| raea-sys-atlas | systems/atlas/src/charts.rs | 436 | moved |
| raea-sys-atlas | systems/atlas/src/merge.rs | 193 | moved |
diff --git a/docs/wear.feature b/docs/wear.feature
index d4fafa1b..fc995cb7 100644
--- a/docs/wear.feature
+++ b/docs/wear.feature
@@ -67,8 +67,8 @@ Feature: raea/wear, weathering that has a cause
code: plaster, brick, sandstone, granite, wood, iron, zinc, copper, slate, felt, glass, enamel, brass, ground
And the crate, as built
| file | lines | job |
- | systems/weathering/src/lib.rs | 211 | the request, its content key, the store, the bake's steps |
- | systems/atlas/src/lib.rs | 112 | raea-sys-atlas (a facility, split out 11-23): Ask (up, north, density, max_side from the request's env), layout() alone |
+ | systems/weathering/src/lib.rs | 208 | the request, its content key, the store, the bake's steps |
+ | systems/atlas/src/lib.rs | 121 | raea-sys-atlas (a facility, split out 11-23): Ask (up, north, density, max_side from the request's env), lay() for both bakes, layout() alone |
| systems/glb/src/lib.rs | 208 | raea-sys-glb (a facility): the .glb read, unused data dropped, written |
| systems/atlas/src/scene.rs | 323 | glTF to triangles with a class each, and back with TEXCOORD_1 |
| systems/atlas/src/charts.rs | 436 | charts, their orientation and packing, texel to surface point |
diff --git a/systems/atlas/src/lib.rs b/systems/atlas/src/lib.rs
index 14aa1e59..5727fcb6 100644
--- a/systems/atlas/src/lib.rs
+++ b/systems/atlas/src/lib.rs
@@ -78,6 +78,17 @@ pub fn dir(v: &Value, k: &str, d: Vec3) -> R<Vec3> {
}
}
+/// A bake request's model laid out: its triangles, their ray mesh, the atlas, and when the charts began (both bakes
+/// start here, so the same request gives them the same atlas).
+pub fn lay(bytes: &[u8], req: &Value) -> R<(scene::Scene, parry3d::shape::TriMesh, charts::Atlas, std::time::Instant)> {
+ let ask = Ask::of(req.get("env").unwrap_or(&Value::Null))?;
+ let sc = scene::read(bytes, &Classes::of(req.get("classes").unwrap_or(&Value::Null))?)?;
+ let mesh = rays::mesh_of(&sc);
+ let t = std::time::Instant::now();
+ let at = charts::build(&sc, &ask, &mesh)?;
+ Ok((sc, mesh, at, t))
+}
+
/// A texel of the atlas and the surface point under it in world units (charts.rs: its centre's point when that's in a
/// triangle, else the nearest point within 0.75 of a texel of its chart's edge), the triangle's normal, the triangle.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -104,9 +115,7 @@ pub struct Layout {
}
pub fn layout(bytes: &[u8], req: &Value) -> R<Layout> {
- let ask = Ask::of(req.get("env").unwrap_or(&Value::Null))?;
- let sc = scene::read(bytes, &Classes::of(req.get("classes").unwrap_or(&Value::Null))?)?;
- let at = charts::build(&sc, &ask, &rays::mesh_of(&sc))?;
+ let (sc, _, at, _) = lay(bytes, req)?;
let texels = at.texels.iter().map(|t| Texel { x: t.x, y: t.y, p: t.p.to_array(), n: t.n.to_array(), tri: t.tri }).collect();
Ok(Layout { glb: scene::write(&sc, &at)?, w: at.w, h: at.h, density: at.density, charts: at.charts, hidden: at.hidden, texels })
}
diff --git a/systems/lightbake/src/texels.rs b/systems/lightbake/src/texels.rs
index ade888f1..02e5603d 100644
--- a/systems/lightbake/src/texels.rs
+++ b/systems/lightbake/src/texels.rs
@@ -77,7 +77,10 @@ fn world_mesh(glb: &[u8]) -> Result<TriMesh, String> {
while let Some((node, parent)) = stack.pop() {
let l = node.transform().matrix();
let m: [[f32; 4]; 4] = std::array::from_fn(|c| std::array::from_fn(|r| (0..4).map(|k| parent[k][r] * l[c][k]).sum()));
- for prim in node.mesh().iter().flat_map(|m| m.primitives()).filter(|p| p.mode() == gltf::mesh::Mode::Triangles) {
+ for prim in node.mesh().iter().flat_map(|m| m.primitives()) {
+ if !matches!(prim.mode(), gltf::mesh::Mode::Triangles) {
+ continue;
+ }
let r = prim.reader(|b| if b.index() == 0 { blob } else { None });
let base = pos.len() as u32;
pos.extend(r.read_positions().ok_or("a primitive with no positions")?.map(|p| Vec3::from(std::array::from_fn(|i| m[0][i] * p[0] + m[1][i] * p[1] + m[2][i] * p[2] + m[3][i]))));
diff --git a/systems/weathering/src/lib.rs b/systems/weathering/src/lib.rs
index 036959d7..a503f5a8 100644
--- a/systems/weathering/src/lib.rs
+++ b/systems/weathering/src/lib.rs
@@ -178,13 +178,10 @@ pub fn bake(store: &Path, src: &Path, req: &Value) -> R<Value> {
Ok(out)
}
-/// What the cause bake and a layout alone start from: the world, the triangles, their ray mesh, the atlas (and its start).
+/// The request's world, and its model laid out as raea_sys_atlas::layout lays it (the same atlas, by construction).
fn lay(bytes: &[u8], req: &Value) -> R<(Env, scene::Scene, parry3d::shape::TriMesh, charts::Atlas, Instant)> {
let env = Env::of(req.get("env").unwrap_or(&Value::Null))?;
- let sc = scene::read(bytes, &Classes::of(req.get("classes").unwrap_or(&Value::Null))?)?;
- let mesh = raea_sys_atlas::rays::mesh_of(&sc);
- let t = Instant::now();
- let at = charts::build(&sc, &env.ask(), &mesh)?;
+ let (sc, mesh, at, t) = raea_sys_atlas::lay(bytes, req)?;
Ok((env, sc, mesh, at, t))
}