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.

R3F23: no new copies. rendercam.rs finds a camera's ambient lights through one ambients() (the first one's colour, the frame's sum); spawn.rs and instance.rs take apart a SceneTarget and an asset event as their own patterns, not closures the dupes ratchet matches elsewhere

shinyobjectzf7b1cdad921a
diff --git a/engine/render/src/engine/spawn.rs b/engine/render/src/engine/spawn.rs
index bcc9de83..90a7ca9c 100644
--- a/engine/render/src/engine/spawn.rs
+++ b/engine/render/src/engine/spawn.rs
@@ -112,7 +112,7 @@ pub fn apply_rows(world: &mut World, dir: &Path, rows: &[Tup]) -> Result<bool, S
None => {
let e = store::spawn(world, t);
// a camera first seen here is a plain App's (SceneTarget); an Engine's comes with its load
- match raea_sys_frame::camera::image_of(world, &t.vals)?.or_else(|| world.get_resource::<SceneTarget>().map(|s| (s.size, s.target.clone()))) {
+ match raea_sys_frame::camera::image_of(world, &t.vals)?.or_else(|| world.get_resource::<SceneTarget>().map(|SceneTarget { target, size }| (*size, target.clone()))) {
Some(on) if matches!(t.kind.as_str(), "camera" | "rendercam") => spawn_camera(world, e, &t.vals, rows, dir, on, true)?,
_ => spawn_3d(world, e, t, &media, dir)?,
}
diff --git a/runtime/look/src/rendercam.rs b/runtime/look/src/rendercam.rs
index 86631443..32e2177f 100644
--- a/runtime/look/src/rendercam.rs
+++ b/runtime/look/src/rendercam.rs
@@ -37,12 +37,9 @@ pub fn render_cameras(all: &[Vec<Item>], tracks: &[(String, Vec<Option<Item>>)],
/// keyed) and the first one's colour. Any such light sends the column, so one of brightness 0 turns the ambient off as
/// Bevy's does; with none, the camera keeps Bevy's default 80.
pub(crate) fn ambient_columns(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, layers: &[u64]) {
- let lit_by = |i: &&Item| i.kind == "ambient" && sees(layers, i);
- if !all.iter().flatten().any(|i| lit_by(&i)) {
- return;
- }
+ let Some(first) = ambients(all.iter().flatten(), layers).next() else { return };
column(p, row, id, "ambient", &all.iter().map(|its| ambient_on(its, layers)).collect::<Vec<_>>());
- if let Some(c) = all.iter().flatten().find(lit_by).and_then(|i| hex(i.props.get("color"))).filter(|c| c != "#ffffff") {
+ if let Some(c) = hex(first.props.get("color")).filter(|c| c != "#ffffff") {
row.insert("ambient_color".into(), V::S(c));
}
}
@@ -62,7 +59,12 @@ pub fn sees(layers: &[u64], i: &Item) -> bool {
/// A frame's ambient light on `layers`: the brightness of every AmbientLight a camera on them sees, summed.
pub fn ambient_on(frame: &[Item], layers: &[u64]) -> f64 {
- frame.iter().filter(|i| i.kind == "ambient" && sees(layers, i)).map(|i| light_power("ambient", &i.props)).sum()
+ ambients(frame, layers).map(|i| light_power("ambient", &i.props)).sum()
+}
+
+/// The AmbientLights among `its` that a camera on `layers` sees.
+fn ambients<'a>(its: impl IntoIterator<Item = &'a Item>, layers: &'a [u64]) -> impl Iterator<Item = &'a Item> {
+ its.into_iter().filter(move |i| i.kind == "ambient" && sees(layers, i))
}
#[cfg(test)]
diff --git a/runtime/scene3d/src/instance.rs b/runtime/scene3d/src/instance.rs
index a7e63ac6..54df40d4 100644
--- a/runtime/scene3d/src/instance.rs
+++ b/runtime/scene3d/src/instance.rs
@@ -68,7 +68,7 @@ pub fn sync_instances(
stds: Res<Assets<StandardMaterial>>,
mut changed: MessageReader<AssetEvent<StandardMaterial>>,
) {
- let recoloured: Vec<AssetId<StandardMaterial>> = changed.read().filter_map(|ev| if let AssetEvent::Modified { id } = ev { Some(*id) } else { None }).collect();
+ let recoloured: Vec<AssetId<StandardMaterial>> = changed.read().filter_map(|ev| match ev { AssetEvent::Modified { id } => Some(*id), _ => None }).collect();
for (e, mut pl, kids, std) in &mut q {
// a tinted set's surface follows its row's standard material (sync_meshes recolours that one)
if let (Some(tn), Some(std)) = (pl.tint.as_mut(), std) {