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.

Split crates back under 2000 lines: raea-sys-mesh and raea-runtime-scene2d

shinyobjectz5f5e7190dbb1
diff --git a/Cargo.lock b/Cargo.lock
index b2df9b6e..bf962f31 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14936,11 +14936,22 @@ dependencies = [
"raea-core-review",
"raea-core-scene",
"raea-runtime-look",
+ "raea-runtime-scene2d",
"raea-sys-procmat",
"raea-sys-wear",
"serde_json",
]
+[[package]]
+name = "raea-runtime-scene2d"
+version = "0.1.0"
+dependencies = [
+ "raea-core-program",
+ "raea-core-scene",
+ "raea-runtime-look",
+ "serde_json",
+]
+
[[package]]
name = "raea-runtime-scene3d"
version = "0.1.0"
@@ -15312,11 +15323,21 @@ dependencies = [
"raea-core-shape",
"raea-io-net",
"raea-sys-frame",
+ "raea-sys-mesh",
"raea-sys-sampler",
"resvg 0.48.1",
"serde_json",
]
+[[package]]
+name = "raea-sys-mesh"
+version = "0.1.0"
+dependencies = [
+ "bevy",
+ "raea-core-shape",
+ "serde_json",
+]
+
[[package]]
name = "raea-sys-meshseq"
version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
index dec6988a..7969d312 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -106,6 +106,7 @@ members = [
"systems/look",
"systems/compose",
"systems/material",
+ "systems/mesh",
"systems/post",
"systems/fog",
"systems/fog-half",
@@ -141,6 +142,7 @@ members = [
"runtime/sound",
"runtime/look",
"runtime/scene",
+ "runtime/scene2d",
"runtime/shared",
"apps/check",
"apps/workspace",
diff --git a/runtime/look/src/lib.rs b/runtime/look/src/lib.rs
index 38cbc096..11e0f879 100644
--- a/runtime/look/src/lib.rs
+++ b/runtime/look/src/lib.rs
@@ -10,6 +10,8 @@ use serde_json::{Map, Value};
mod camera;
pub use camera::*;
mod instances;
+mod parts;
+pub use parts::*;
pub use instances::*;
/// Bloom of intensity 1: Bevy's natural preset.
@@ -487,3 +489,4 @@ fn keyed<'a>(p: &mut Program, kind: &str, target: Option<&str>, tag: &str, each:
n += 1;
}
}
+
diff --git a/runtime/look/src/parts.rs b/runtime/look/src/parts.rs
new file mode 100644
index 00000000..374df4b8
--- /dev/null
+++ b/runtime/look/src/parts.rs
@@ -0,0 +1,31 @@
+//! Row helpers a part of any kind shares: shown on some frames, a sprite sheet's cell, a keyed colour.
+
+use super::*;
+
+/// A part shown only on some frames: `visible` keyed (0 on the frames it's missing from)
+pub fn visible(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, track: &[Option<Item>]) {
+ if track.iter().any(Option::is_none) {
+ let on: Vec<f64> = track.iter().map(|t| t.is_some() as u8 as f64).collect();
+ column(p, row, id, "visible", &on);
+ }
+}
+
+/// A sprite sheet (`grid` [columns, rows], from the first frame): the cell `frame` shows, keyed (an <ImagePlane>'s,
+/// a <Sprite>'s)
+pub fn sheet(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item]) {
+ if let Some(Value::Array(g)) = its[0].props.get("grid") {
+ if let [c, r] = g.as_slice() {
+ row.insert("sheet_cols".into(), V::N(c.as_f64().unwrap_or(1.0)));
+ row.insert("sheet_rows".into(), V::N(r.as_f64().unwrap_or(1.0)));
+ column(p, row, id, "sheet_frame", &its.iter().map(|i| n(&i.props, "frame", 0.0).floor()).collect::<Vec<_>>());
+ }
+ }
+}
+
+/// `color` keyed as col_r, col_g, col_b (`default` where a frame has none)
+pub fn tint(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item], default: &str) {
+ let colors: Vec<[f64; 3]> = its.iter().map(|i| rgb(&hex(i.props.get("color")).unwrap_or(default.into()))).collect();
+ for (c, name) in ["col_r", "col_g", "col_b"].iter().enumerate() {
+ exact(p, row, id, name, &colors.iter().map(|v| v[c]).collect::<Vec<_>>());
+ }
+}
diff --git a/runtime/scene/Cargo.toml b/runtime/scene/Cargo.toml
index e39bfb7e..51bf0c2d 100644
--- a/runtime/scene/Cargo.toml
+++ b/runtime/scene/Cargo.toml
@@ -10,6 +10,7 @@ description = "A composition's 3D as raea-render rows: the camera, lights, meshe
raea-core-scene = { path = "../../core/scene" }
raea-core-program = { path = "../../core/program" }
raea-runtime-look = { path = "../look" }
+raea-runtime-scene2d = { path = "../scene2d" }
bevy = { version = "=0.20.0", default-features = false, features = ["std"] }
serde_json = "1"
# a material's `wear` prop as its row's columns
diff --git a/runtime/scene/src/lib.rs b/runtime/scene/src/lib.rs
index 0be4537e..2f7c3080 100644
--- a/runtime/scene/src/lib.rs
+++ b/runtime/scene/src/lib.rs
@@ -27,7 +27,6 @@ mod fast;
/// Gaussian splats' rows (<Splat>).
mod splat;
/// 2D parts' rows (<Sprite>, <Shape2D>).
-mod sprite2d;
/// <Instances>: a mesh or model row's placements (its `inst` column).
/// Baked simulations' and glitches' rows (<MeshSequence>, <Goo>, glitch props).
mod meshseq;
@@ -206,12 +205,6 @@ pub fn items_of(scene: &[Node3]) -> Vec<Item> {
out
}
-fn visible(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, track: &[Option<Item>]) {
- if track.iter().any(Option::is_none) {
- let on: Vec<f64> = track.iter().map(|t| t.is_some() as u8 as f64).collect();
- column(p, row, id, "visible", &on);
- }
-}
/// A part's composition pass on each frame (`pass`: 0 "scene", from 1 the piece's passes), stepped.
fn pass_column(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item], names: &[String]) {
@@ -349,8 +342,8 @@ fn rows_into_of(all: &[Vec<Item>], tr: &Tracks, p: &mut Program) {
// gaussian splats (<Splat>): splat.rs
splat::rows(&tr.splats, p);
// 2D over the 3D (<Sprite>, <Shape2D>): sprite2d.rs
- sprite2d::sprites(&tr.sprites, p);
- sprite2d::shapes(&tr.shapes2d, p);
+ raea_runtime_scene2d::sprites(&tr.sprites, p);
+ raea_runtime_scene2d::shapes(&tr.shapes2d, p);
// baked simulations (<MeshSequence>, <Goo>): meshseq.rs
meshseq::rows(&tr.meshseqs, p);
}
diff --git a/runtime/scene/src/models.rs b/runtime/scene/src/models.rs
index b1554794..b9a824c1 100644
--- a/runtime/scene/src/models.rs
+++ b/runtime/scene/src/models.rs
@@ -188,26 +188,6 @@ pub(crate) fn panels_rows(tr: &Tracks, names: &[String], p: &mut Program) {
}
}
-/// A sprite sheet (`grid` [columns, rows], from the first frame): the cell `frame` shows, keyed (an <ImagePlane>'s,
-/// a <Sprite>'s)
-pub(crate) fn sheet(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item]) {
- if let Some(Value::Array(g)) = its[0].props.get("grid") {
- if let [c, r] = g.as_slice() {
- row.insert("sheet_cols".into(), V::N(c.as_f64().unwrap_or(1.0)));
- row.insert("sheet_rows".into(), V::N(r.as_f64().unwrap_or(1.0)));
- column(p, row, id, "sheet_frame", &its.iter().map(|i| n(&i.props, "frame", 0.0).floor()).collect::<Vec<_>>());
- }
- }
-}
-
-/// `color` keyed as col_r, col_g, col_b (`default` where a frame has none)
-pub(crate) fn tint(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item], default: &str) {
- let colors: Vec<[f64; 3]> = its.iter().map(|i| rgb(&hex(i.props.get("color")).unwrap_or(default.into()))).collect();
- for (c, name) in ["col_r", "col_g", "col_b"].iter().enumerate() {
- exact(p, row, id, name, &colors.iter().map(|v| v[c]).collect::<Vec<_>>());
- }
-}
-
/// decals: the picture and its surface from the first frame; placement, colour and opacity keyed (a stain that
/// spreads, a label that fades in)
pub(crate) fn decals_rows(tr: &Tracks, p: &mut Program) {
diff --git a/runtime/scene2d/Cargo.toml b/runtime/scene2d/Cargo.toml
new file mode 100644
index 00000000..161d9a76
--- /dev/null
+++ b/runtime/scene2d/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "raea-runtime-scene2d"
+version = "0.1.0"
+edition = "2024"
+license = "FSL-1.1-ALv2"
+publish = false
+description = "2D parts' rows (<Sprite>, <Shape2D>): the picture, sheet and shape, and the place, cell, colour and opacity keyed"
+
+[dependencies]
+raea-core-scene = { path = "../../core/scene" }
+raea-core-program = { path = "../../core/program" }
+raea-runtime-look = { path = "../look" }
+serde_json = "1"
diff --git a/runtime/scene/src/sprite2d.rs b/runtime/scene2d/src/lib.rs
similarity index 91%
rename from runtime/scene/src/sprite2d.rs
rename to runtime/scene2d/src/lib.rs
index 18381603..cbf089e6 100644
--- a/runtime/scene/src/sprite2d.rs
+++ b/runtime/scene2d/src/lib.rs
@@ -1,8 +1,16 @@
//! 2D parts' rows (`<Sprite>`, `<Shape2D>` in sdk/render's 3d/sprite.tsx): a `sprite` or `shape2d` row each, read by
//! raea-sys-sprite. The picture, sheet and shape come from the first frame; the place, the sheet's cell, the colour and
-//! the opacity are keyed per frame.
+//! the opacity are keyed per frame. raea-runtime-scene makes them with the 3D parts' rows.
-use super::*;
+use std::collections::BTreeMap;
+
+use raea_core_program::ir::{Program, V};
+use raea_core_scene::*;
+use raea_runtime_look::*;
+use serde_json::Value;
+
+/// a part's name and its props on each frame (None where it's missing), as raea-runtime-scene tracks it
+type Track = (String, Vec<Option<Item>>);
/// A 2D part's place (composition px from the top left, y down; radians clockwise; scale; draw order), its colour and
/// its opacity, each keyed.
@@ -30,7 +38,7 @@ fn place2d(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item
}
/// Sprites: the picture, its sheet and size from the first frame; place, cell, tint and opacity keyed.
-pub(super) fn sprites(tracks: &[Track], p: &mut Program) {
+pub fn sprites(tracks: &[Track], p: &mut Program) {
for (k, (_, track)) in tracks.iter().enumerate() {
let its = filled(track);
let id = format!("sprite{k}");
@@ -65,7 +73,7 @@ pub(super) fn sprites(tracks: &[Track], p: &mut Program) {
}
/// Flat shapes: the shape and its size from the first frame; place, colour and opacity keyed.
-pub(super) fn shapes(tracks: &[Track], p: &mut Program) {
+pub fn shapes(tracks: &[Track], p: &mut Program) {
for (k, (_, track)) in tracks.iter().enumerate() {
let its = filled(track);
let id = format!("shape2d{k}");
diff --git a/systems/material/Cargo.toml b/systems/material/Cargo.toml
index 2c2ac75e..a174b5f2 100644
--- a/systems/material/Cargo.toml
+++ b/systems/material/Cargo.toml
@@ -23,6 +23,7 @@ serde_json = "1"
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "hdr"] }
raea-io-net = { path = "../../io/net" }
raea-core-shape = { path = "../../core/shape" }
+raea-sys-mesh = { path = "../mesh" }
# a texture given as a data:image/svg+xml URL, drawn on the CPU (the resvg raea-runtime-js draws SVG with)
resvg = { version = "=0.48.1", default-features = false, features = ["text"], optional = true }
diff --git a/systems/material/src/lib.rs b/systems/material/src/lib.rs
index 1ec7a351..151115ee 100644
--- a/systems/material/src/lib.rs
+++ b/systems/material/src/lib.rs
@@ -14,7 +14,7 @@ pub mod decal;
pub mod fields;
pub mod lightmap;
pub mod maps;
-pub mod mesh;
+pub use raea_sys_mesh as mesh;
pub mod surface;
pub mod toon;
pub mod shadow_only;
diff --git a/systems/mesh/Cargo.toml b/systems/mesh/Cargo.toml
new file mode 100644
index 00000000..ab110b99
--- /dev/null
+++ b/systems/mesh/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "raea-sys-mesh"
+version = "0.1.0"
+edition = "2024"
+license = "FSL-1.1-ALv2"
+publish = false
+description = "A row's mesh from JSON: one of Bevy's primitives by name (rings and extrusions too), meshed by Bevy's own meshers, or a buffer mesh's own vertex buffers"
+
+[dependencies]
+bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "3d_bevy_render"] }
+serde_json = "1"
+raea-core-shape = { path = "../../core/shape" }
diff --git a/systems/material/src/mesh.rs b/systems/mesh/src/lib.rs
similarity index 98%
rename from systems/material/src/mesh.rs
rename to systems/mesh/src/lib.rs
index 13b6d09f..91b91d27 100644
--- a/systems/material/src/mesh.rs
+++ b/systems/mesh/src/lib.rs
@@ -1,4 +1,7 @@
-use super::*;
+//! A row's mesh from JSON: one of Bevy's primitive shapes by name, meshed by Bevy's own meshers (rings and extrusions
+//! of its 2D ones too), or a buffer mesh's own vertex buffers. raea-sys-material re-exports it as its `mesh`.
+
+use bevy::prelude::*;
/// A <BufferMesh>'s vertex colours (`colors`: r, g, b, a in linear light for each vertex, or "#rrggbb" sRGB each),
/// laid out per triangle corner as buffer_tris lays its positions; None without them. StandardMaterial multiplies its
diff --git a/tools/layers.toml b/tools/layers.toml
index 63cecf10..8bc855ab 100644
--- a/tools/layers.toml
+++ b/tools/layers.toml
@@ -100,6 +100,7 @@ raea-sys-environment = "systems"
raea-sys-look = "systems"
raea-sys-compose = "systems"
raea-sys-material = "systems"
+raea-sys-mesh = "systems"
raea-sys-framepass = "systems"
raea-sys-compute = "systems"
raea-sys-sampler = "systems"
@@ -128,6 +129,7 @@ raea-runtime-plugins = "runtime"
raea-runtime-live = "runtime"
raea-runtime-look = "runtime"
raea-runtime-scene = "runtime"
+raea-runtime-scene2d = "runtime"
raea-runtime-shared = "runtime"
raea-page = "runtime"
raea-app-check = "apps"
@@ -171,6 +173,8 @@ seetool = "tools"
raea-sys-frame = true
# a row's standard material and its maps (meshseq builds its mesh's on it)
raea-sys-material = true
+# a row's mesh from JSON, Bevy's primitives by name (materials and reflected Mesh handles build on it)
+raea-sys-mesh = true
# how a texture is read (materials, shaders and models set it the same way)
raea-sys-sampler = true
# a shader's inputs, accessors and registration (surface shaders and frame passes share them)