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.

<Instances> whose placements change over the shot move in a video, as they do in a still (#85). A render drew the first frame's list on every frame of a video or an --at list (the row's inst column held one list and said so only in a warning), while a still of a later frame showed it moved. Now the row keeps every distinct list it shows (inst_all, '|' between lists, each frame's list compared with the frame before's) and keys which one each frame shows (inst_k), as a panel's pictures are; a live frame sends its inst, and the fast live path drops to the full one when an Instances' list isn't the one it sent. raea-runtime-scene3d's sync_instances moves the copies (a mesh's, or each of a model's meshes at its place in the model) when the frame's list is another; a list with another count than the copies is the frame's error, and the rows hold the list before it with a warning. The SDK's at, the guide's meshes.md and the manual's rows say a list that changes moves the copies and costs a list a frame. The issue's 20 sliding spheres at 640x360: x-centroid 141.2 at frame 0 and 326.7 at frame 59 in the video (the fed live path, RAEA_LIVE3D_FAST=0 and RAEA_3D=program alike), 327.0 in a --frame 59 still; was 141.1 at 59. The same with a glTF (knot.glb): 142.9 and 326.8, still 327.1. raea-runtime-look tests: lists keyed frame by frame, still ones one column

shinyobjectz8796ceb67cd0
diff --git a/docs/manual/reference/sdk/3d.md b/docs/manual/reference/sdk/3d.md
index b7dfc944..44a32678 100644
--- a/docs/manual/reference/sdk/3d.md
+++ b/docs/manual/reference/sdk/3d.md
@@ -1812,7 +1812,7 @@ copy together). Rotation in radians, XYZ order, as everywhere.
| Field | Type | What it is |
| --- | --- | --- |
| `src` | `string` | a glTF file drawn at every placement: staticFile("models/house.glb"). Without it, a geometry child (or `shape`) and a material child draw a mesh at every placement |
-| `at` (required) | `Instance[]` | where each copy stands. Fixed for the shot: the first frame's list is drawn on every frame (move, turn, scale, hide or recolour the whole set by the Instances' own props) |
+| `at` (required) | `Instance[]` | where each copy stands, this frame: a list that changes moves the copies with it (each distinct list is kept, so a set of thousands moving every frame costs a list a frame; moving the whole set by the Instances' own props costs nothing). How many copies is the first frame's: a frame with another count holds the list before it |
| `name` | `string` | the entity's name, for picking, the inspector and world.* |
| `position` | `Vec3` | where it stands, metres (x, y, z) |
| `rotation` | `Vec3` | radians |
diff --git a/docs/manual/reference/sdk/mesh.md b/docs/manual/reference/sdk/mesh.md
index f315ac90..32a9b4b6 100644
--- a/docs/manual/reference/sdk/mesh.md
+++ b/docs/manual/reference/sdk/mesh.md
@@ -387,7 +387,7 @@ copy together). Rotation in radians, XYZ order, as everywhere.
| Field | Type | What it is |
| --- | --- | --- |
| `src` | `string` | a glTF file drawn at every placement: staticFile("models/house.glb"). Without it, a geometry child (or `shape`) and a material child draw a mesh at every placement |
-| `at` (required) | `Instance[]` | where each copy stands. Fixed for the shot: the first frame's list is drawn on every frame (move, turn, scale, hide or recolour the whole set by the Instances' own props) |
+| `at` (required) | `Instance[]` | where each copy stands, this frame: a list that changes moves the copies with it (each distinct list is kept, so a set of thousands moving every frame costs a list a frame; moving the whole set by the Instances' own props costs nothing). How many copies is the first frame's: a frame with another count holds the list before it |
| `name` | `string` | the entity's name, for picking, the inspector and world.* |
| `position` | `Vec3` | where it stands, metres (x, y, z) |
| `rotation` | `Vec3` | radians |
diff --git a/engine/render/src/engine/raea_plugins.rs b/engine/render/src/engine/raea_plugins.rs
index a5e7cbb3..8b4a29d1 100644
--- a/engine/render/src/engine/raea_plugins.rs
+++ b/engine/render/src/engine/raea_plugins.rs
@@ -112,7 +112,7 @@ pub fn scene3d_systems() -> ScheduleConfigs<ScheduleSystem> {
super::scene3d::instance_models,
super::scene3d::model_shadow_markers,
super::scene3d::toon_models,
- ((super::scene3d::sync_meshes, super::scene3d::sync_pictures, super::shader_ext::sync_shaded, raea_sys_sampler::arrays::sync_arrays, raea_sys_sampler::sync_samplers).chain(), super::toon::sync_toon, (super::scene3d::sync_camera, super::scene3d::sync_post).chain(), super::motion_blur::sync_motion_blur, (super::environment::sync_environment, super::environment::sync_prefiltered, super::environment::sync_suns).chain(), (super::scene3d::sync_light_sets, super::scene3d::sync_lights).chain(), super::scene3d::sync_fog_volumes, super::scene3d::sync_fog_dither, super::scene3d::sync_models, super::scene3d::sync_morphs, super::scene3d::sync_attach, super::grid::grid_models, super::scene3d::sync_bones, super::look::sync_frame_look, super::look::sync_looks, super::compose::sync_passes, super::look::sync_flat, super::paint::sync_paint, super::decal::sync_decals, super::text3d::sync_texts).chain(),
+ ((super::scene3d::sync_meshes, super::scene3d::sync_instances, super::scene3d::sync_pictures, super::shader_ext::sync_shaded, raea_sys_sampler::arrays::sync_arrays, raea_sys_sampler::sync_samplers).chain(), super::toon::sync_toon, (super::scene3d::sync_camera, super::scene3d::sync_post).chain(), super::motion_blur::sync_motion_blur, (super::environment::sync_environment, super::environment::sync_prefiltered, super::environment::sync_suns).chain(), (super::scene3d::sync_light_sets, super::scene3d::sync_lights).chain(), super::scene3d::sync_fog_volumes, super::scene3d::sync_fog_dither, super::scene3d::sync_models, super::scene3d::sync_morphs, super::scene3d::sync_attach, super::grid::grid_models, super::scene3d::sync_bones, super::look::sync_frame_look, super::look::sync_looks, super::compose::sync_passes, super::look::sync_flat, super::paint::sync_paint, super::decal::sync_decals, super::text3d::sync_texts).chain(),
// --clay and --review's clay half: every standard surface grey, after the rows set their colours
super::scene3d::clay::clay_materials,
)
diff --git a/runtime/look/src/instances.rs b/runtime/look/src/instances.rs
index c6ccd837..251c467e 100644
--- a/runtime/look/src/instances.rs
+++ b/runtime/look/src/instances.rs
@@ -1,7 +1,7 @@
//! <Instances> (sdk/render 3d/instances.tsx): a Mesh or Model whose props carry `at`, its placements 9 numbers a copy
//! (position, XYZ euler radians, scale), written as the row's `inst` column: 10 numbers a copy (position, rotation as
//! a quaternion xyzw, scale), space-separated. The engine draws one copy per placement, sharing the mesh and material
-//! (runtime/scene3d's instance.rs; rows from runtime/scene). The placements are the first frame's; a later frame's differing list is warned of.
+//! (runtime/scene3d's instance.rs; rows from runtime/scene). Placements that change over the shot are keyed (inst_all, inst_k).
use super::*;
use bevy::math::{EulerRot, Quat};
@@ -23,14 +23,34 @@ fn packed(at: &[Value]) -> Option<String> {
Some(nums.join(" "))
}
-/// The `inst` column of a mesh or model row whose part is an <Instances>.
-pub fn instances_column(row: &mut BTreeMap<String, V>, its: &[Item]) {
+/// The `inst` column of a mesh or model row whose part is an <Instances>: its first frame's placements. When they change
+/// over the shot (#85), every list it shows goes in `inst_all` ("|" between lists) and which one each frame shows is keyed
+/// as `inst_k`, as a panel's pictures are (src_k): the engine moves its copies to the frame's (scene3d sync_instances).
+/// The count is the first frame's: a frame with another count holds the list before it.
+pub fn instances_column(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item]) {
let Some(Value::Array(at)) = its[0].props.get("at") else { return };
- if its.iter().skip(1).any(|i| !matches!(i.props.get("at"), Some(Value::Array(a)) if std::ptr::eq(a, at) || a == at)) {
- eprintln!("WARN Instances {}: its placements change over the shot; the first frame's are drawn", its[0].props.get("name").and_then(Value::as_str).unwrap_or("?"));
+ let Some(first) = packed(at) else { return };
+ // each frame's list against the one before it only (a frame's list is the frame before's object when React kept it)
+ let (mut lists, mut k, mut before, mut recounted) = (vec![first], Vec::with_capacity(its.len()), at, false);
+ for it in its {
+ let a = match it.props.get("at") { Some(Value::Array(a)) => a, _ => before };
+ if !std::ptr::eq(a, before) && a != before {
+ if a.len() == at.len() && let Some(s) = packed(a) {
+ lists.push(s);
+ before = a;
+ } else {
+ recounted = true;
+ }
+ }
+ k.push((lists.len() - 1) as f64);
}
- if let Some(s) = packed(at) {
- row.insert("inst".into(), V::S(s));
+ if recounted {
+ eprintln!("WARN Instances {}: how many copies it has changes over the shot; a frame with another count holds the placements before it", its[0].props.get("name").and_then(Value::as_str).unwrap_or("?"));
+ }
+ row.insert("inst".into(), V::S(lists[0].clone()));
+ if lists.len() > 1 {
+ row.insert("inst_all".into(), V::S(lists.join("|")));
+ exact(p, row, id, "inst_k", &k);
}
}
@@ -44,3 +64,33 @@ pub fn model_shadows(row: &mut BTreeMap<String, V>, its: &[Item]) {
row.insert("receive".into(), V::N(0.0));
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn part(x: f64) -> Item {
+ let at = serde_json::json!({"at": [x, 0, 0, 0, 0, 0, 1, 1, 1, x + 1.0, 0, 0, 0, 0, 0, 1, 1, 1]});
+ Item { kind: "mesh", props: std::sync::Arc::new(at.as_object().unwrap().clone()), shape: None, material: None, world: Default::default() }
+ }
+
+ // #85: a video drew the first frame's placements on every frame
+ #[test]
+ fn placements_that_change_are_keyed_frame_by_frame() {
+ let (mut p, mut row) = (Program::default(), BTreeMap::new());
+ instances_column(&mut p, &mut row, "m0", &[part(0.0), part(0.0), part(2.0), part(5.0)]);
+ assert_eq!(row.get("inst"), Some(&V::S("0 0 0 0 -0 0 1 1 1 1 1 0 0 0 -0 0 1 1 1 1".into())));
+ let Some(V::S(all)) = row.get("inst_all") else { panic!("inst_all: {row:?}") };
+ assert_eq!(all.split('|').count(), 3, "one list a change: {all}");
+ assert!(all.split('|').nth(2).unwrap().starts_with("5 0 0 "));
+ let k: Vec<f64> = p.keys[&("m0".to_string(), "inst_k".to_string())].iter().map(|k| k.1).collect();
+ assert_eq!(k, [0.0, 0.0, 1.0, 2.0]);
+ }
+
+ #[test]
+ fn still_placements_are_one_column() {
+ let (mut p, mut row) = (Program::default(), BTreeMap::new());
+ instances_column(&mut p, &mut row, "m0", &[part(1.0), part(1.0)]);
+ assert!(row.contains_key("inst") && !row.contains_key("inst_all") && p.keys.is_empty());
+ }
+}
diff --git a/runtime/scene/src/fast.rs b/runtime/scene/src/fast.rs
index faa2abc5..c9ac9408 100644
--- a/runtime/scene/src/fast.rs
+++ b/runtime/scene/src/fast.rs
@@ -62,6 +62,8 @@ impl LiveScene {
}
// a panel showing another picture (`current` kept the last): the full path, which sends the new src
if it.kind == "panel" && self.panel_srcs.get(key.as_str()).map(String::as_str) != it.props.get("src").and_then(Value::as_str) { return None }
+ // an <Instances> placed elsewhere (`current` sent its list): the full path, which sends the new one (#85)
+ if self.rows[id].sent.contains_key("inst") && { let mut r = BTreeMap::new(); instances_column(&mut Program::default(), &mut r, id, std::slice::from_ref(it)); r.get("inst") != self.rows[id].sent.get("inst") } { return None }
parts.push((i, id));
}
}
diff --git a/runtime/scene/src/live.rs b/runtime/scene/src/live.rs
index e9b83230..30777355 100644
--- a/runtime/scene/src/live.rs
+++ b/runtime/scene/src/live.rs
@@ -61,8 +61,8 @@ pub(crate) const MORPH_COLS: [&str; 64] = ["morph0", "morph1", "morph2", "morph3
pub(crate) fn live_dynamic(kind: &str) -> &'static [&'static str] {
match kind {
"light" => &["lux", "lumens", "x", "y", "z", "dir_x", "dir_y", "dir_z", "rot_qx", "rot_qy", "rot_qz", "rot_qw", "inner", "outer", "frame_sets", "frame_set_i"],
- "mesh" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "col_r", "col_g", "col_b", "rough", "metal", "emissive_k", "opacity", "sh_r", "sh_g", "sh_b", "rim_k", "spec_k", "outline_w", "pass"],
- "model" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "anim_t", "mix0_t", "mix0_w", "mix1_t", "mix1_w", "mix2_t", "mix2_w", "mix3_t", "mix3_w", "morph0", "morph1", "morph2", "morph3", "morph4", "morph5", "morph6", "morph7", "morph8", "morph9", "morph10", "morph11", "morph12", "morph13", "morph14", "morph15", "morph16", "morph17", "morph18", "morph19", "morph20", "morph21", "morph22", "morph23", "morph24", "morph25", "morph26", "morph27", "morph28", "morph29", "morph30", "morph31", "morph32", "morph33", "morph34", "morph35", "morph36", "morph37", "morph38", "morph39", "morph40", "morph41", "morph42", "morph43", "morph44", "morph45", "morph46", "morph47", "morph48", "morph49", "morph50", "morph51", "morph52", "morph53", "morph54", "morph55", "morph56", "morph57", "morph58", "morph59", "morph60", "morph61", "morph62", "morph63", "g0_w", "g0_t", "g1_w", "g1_t", "g2_w", "g2_t", "g3_w", "g3_t", "g4_w", "g4_t", "g5_w", "g5_t", "g6_w", "g6_t", "g7_w", "g7_t", "g8_w", "g8_t", "g9_w", "g9_t", "g10_w", "g10_t", "g11_w", "g11_t", "g12_w", "g12_t", "g13_w", "g13_t", "g14_w", "g14_t", "g15_w", "g15_t", "look", "glitch_explode", "glitch_scramble", "glitch_jitter", "glitch_snap", "glitch_smear_x", "glitch_smear_y", "glitch_smear_z", "glitch_seed", "cloth_frame", "screen_power", "pass"],
+ "mesh" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "col_r", "col_g", "col_b", "rough", "metal", "emissive_k", "opacity", "sh_r", "sh_g", "sh_b", "rim_k", "spec_k", "outline_w", "pass", "inst"],
+ "model" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "anim_t", "mix0_t", "mix0_w", "mix1_t", "mix1_w", "mix2_t", "mix2_w", "mix3_t", "mix3_w", "morph0", "morph1", "morph2", "morph3", "morph4", "morph5", "morph6", "morph7", "morph8", "morph9", "morph10", "morph11", "morph12", "morph13", "morph14", "morph15", "morph16", "morph17", "morph18", "morph19", "morph20", "morph21", "morph22", "morph23", "morph24", "morph25", "morph26", "morph27", "morph28", "morph29", "morph30", "morph31", "morph32", "morph33", "morph34", "morph35", "morph36", "morph37", "morph38", "morph39", "morph40", "morph41", "morph42", "morph43", "morph44", "morph45", "morph46", "morph47", "morph48", "morph49", "morph50", "morph51", "morph52", "morph53", "morph54", "morph55", "morph56", "morph57", "morph58", "morph59", "morph60", "morph61", "morph62", "morph63", "g0_w", "g0_t", "g1_w", "g1_t", "g2_w", "g2_t", "g3_w", "g3_t", "g4_w", "g4_t", "g5_w", "g5_t", "g6_w", "g6_t", "g7_w", "g7_t", "g8_w", "g8_t", "g9_w", "g9_t", "g10_w", "g10_t", "g11_w", "g11_t", "g12_w", "g12_t", "g13_w", "g13_t", "g14_w", "g14_t", "g15_w", "g15_t", "look", "glitch_explode", "glitch_scramble", "glitch_jitter", "glitch_snap", "glitch_smear_x", "glitch_smear_y", "glitch_smear_z", "glitch_seed", "cloth_frame", "screen_power", "pass", "inst"],
"panel" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "screen_power", "screen_bright", "pass", "sheet_frame", "sheet_cols", "sheet_rows", "src"],
"decal" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "col_r", "col_g", "col_b", "opacity", "rough", "metal"],
_ => &[],
diff --git a/runtime/scene/src/models.rs b/runtime/scene/src/models.rs
index 56e79daf..6c004003 100644
--- a/runtime/scene/src/models.rs
+++ b/runtime/scene/src/models.rs
@@ -131,7 +131,7 @@ pub(crate) fn models_rows(tr: &Tracks, names: &[String], p: &mut Program) {
meshseq::cloth_columns(p, &mut row, &id, &its);
placement(p, &mut row, &id, &its);
visible(p, &mut row, &id, &track);
- instances_column(&mut row, &its);
+ instances_column(p, &mut row, &id, &its);
model_shadows(&mut row, &its);
pass_column(p, &mut row, &id, &its, &names);
p.spawns.push(("model".into(), vec![row]));
diff --git a/runtime/scene/src/parts.rs b/runtime/scene/src/parts.rs
index f33c1cf9..2d513831 100644
--- a/runtime/scene/src/parts.rs
+++ b/runtime/scene/src/parts.rs
@@ -264,7 +264,7 @@ pub(crate) fn meshes_rows(tr: &Tracks, names: &[String], p: &mut Program) {
row.insert("receive".into(), V::N(0.0));
}
layers_column(&mut row, &its[0].props);
- instances_column(&mut row, &its);
+ instances_column(p, &mut row, &id, &its);
// its geometry's own vertex attributes (JSON, Mesh3d `attributes`), from the first frame: raea-sys-mesh with_attributes
if let Some(Value::String(a)) = its[0].props.get("attributes") {
row.insert("attributes".into(), V::S(a.clone()));
diff --git a/runtime/scene3d/src/instance.rs b/runtime/scene3d/src/instance.rs
index 4b57c10b..566cce9e 100644
--- a/runtime/scene3d/src/instance.rs
+++ b/runtime/scene3d/src/instance.rs
@@ -16,11 +16,82 @@ pub struct Instanced;
/// A row's `inst`: 10 numbers a copy (position, rotation xyzw, scale).
pub fn placements(t: &Tup) -> Result<Option<Vec<Transform>>, String> {
let Some(V::S(s)) = t.vals.get("inst") else { return Ok(None) };
- let n: Vec<f32> = s.split_ascii_whitespace().map(|x| x.parse::<f32>().map_err(|e| format!("{}: inst: {e}", t.id))).collect::<Result<_, _>>()?;
+ parsed(&t.id, s).map(Some)
+}
+
+fn parsed(id: &str, s: &str) -> Result<Vec<Transform>, String> {
+ let mut n: Vec<f32> = vec![];
+ for x in s.split_ascii_whitespace() {
+ n.push(x.parse().map_err(|e| format!("{id}: inst: {x}: {e}"))?);
+ }
if n.len() % 10 != 0 {
- return Err(format!("{}: inst is 10 numbers a copy, got {}", t.id, n.len()));
+ return Err(format!("{id}: inst is 10 numbers a copy, got {}", n.len()));
+ }
+ Ok(n.chunks(10).map(|c| Transform { translation: Vec3::new(c[0], c[1], c[2]), rotation: Quat::from_xyzw(c[3], c[4], c[5], c[6]).normalize(), scale: Vec3::new(c[7], c[8], c[9]) }).collect())
+}
+
+/// An <Instances> whose placements may change (#85): the lists a render's row shows (`inst_all`; which one a frame
+/// shows is keyed as `inst_k`) and the one shown, or a live row's `inst` as last applied; and where each of a placement's
+/// copies sits in it (a model's meshes, in the model; a mesh's one copy, at the placement). Copies are its children,
+/// placement by placement.
+#[derive(Component)]
+pub struct Placements {
+ lists: Vec<String>,
+ shown: usize,
+ live: String,
+ parts: Vec<Mat4>,
+}
+
+impl Placements {
+ pub(crate) fn of(t: &Tup) -> Placements {
+ let all = match t.vals.get("inst_all") { Some(V::S(s)) => s.split('|').map(str::to_string).collect(), _ => vec![] };
+ let live = match t.vals.get("inst") { Some(V::S(s)) => s.clone(), _ => String::new() };
+ Placements { lists: all, shown: 0, live, parts: vec![] }
+ }
+}
+
+/// Each <Instances>' copies moved to the frame's placements when they're another list than the one shown: a render's
+/// `inst_k`, or a live row's `inst`. A frame whose list has another count than the copies is an error.
+pub fn sync_instances(frame: Res<FrameRows>, mut q: Query<(Entity, &mut Placements, &Children)>, mut ts: Query<&mut Transform>, mut error: ResMut<Error>) {
+ for (e, mut pl, kids) in &mut q {
+ if pl.parts.is_empty() {
+ continue;
+ }
+ let Some(v) = frame.vals(e) else { continue };
+ // a live row's own list first (a render's `inst` is its first frame's on every frame, so it never differs)
+ let s = match (v.get("inst"), v.get("inst_k")) {
+ (Some(V::S(s)), _) if *s != pl.live => {
+ pl.live = s.clone();
+ s.clone()
+ }
+ (_, Some(k)) if !pl.lists.is_empty() => {
+ let k = (k.num().round().max(0.0) as usize).min(pl.lists.len() - 1);
+ if k == pl.shown {
+ continue;
+ }
+ pl.shown = k;
+ pl.lists[k].clone()
+ }
+ _ => continue,
+ };
+ let at = match parsed(&format!("{e}"), &s) {
+ Ok(at) if at.len() * pl.parts.len() == kids.len() => at,
+ Ok(at) => {
+ error.0.get_or_insert(format!("Instances: a frame has {} placements where it began with {}; the count can't change", at.len(), kids.len() / pl.parts.len()));
+ continue;
+ }
+ Err(err) => {
+ error.0.get_or_insert(err);
+ continue;
+ }
+ };
+ let places = at.iter().flat_map(|tr| pl.parts.iter().map(move |local| Transform::from_matrix(tr.to_matrix() * *local)));
+ for (kid, want) in kids.iter().zip(places) {
+ if let Ok(mut t) = ts.get_mut(kid) {
+ *t = want;
+ }
+ }
}
- Ok(Some(n.chunks(10).map(|c| Transform { translation: Vec3::new(c[0], c[1], c[2]), rotation: Quat::from_xyzw(c[3], c[4], c[5], c[6]).normalize(), scale: Vec3::new(c[7], c[8], c[9]) }).collect()))
}
/// The markers a copy takes from its parent: shadows cast and received, render layers.
@@ -52,7 +123,7 @@ pub fn instance_mesh(world: &mut World, e: Entity, t: &Tup) -> Result<(), String
};
let Some(mesh) = world.entity_mut(e).take::<Mesh3d>() else { return Err(format!("mesh {}: no mesh to instance", t.id)) };
let m = markers(world, e);
- world.entity_mut(e).insert(Instanced);
+ world.entity_mut(e).insert((Instanced, Placements { parts: vec![Mat4::IDENTITY], ..Placements::of(t) }));
for tr in at {
spawn_copy(world, e, mesh.clone(), mat.clone(), tr, &m);
}
@@ -114,6 +185,9 @@ pub fn instance_models(world: &mut World) {
for r in roots {
world.entity_mut(r).despawn();
}
+ if let Some(mut pl) = world.get_mut::<Placements>(e) {
+ pl.parts = parts.iter().map(|p| p.2).collect();
+ }
world.entity_mut(e).insert(Instanced);
}
}
diff --git a/runtime/scene3d/src/model.rs b/runtime/scene3d/src/model.rs
index 672d69cf..489bef24 100644
--- a/runtime/scene3d/src/model.rs
+++ b/runtime/scene3d/src/model.rs
@@ -15,6 +15,10 @@ pub fn model(world: &mut World, e: Entity, t: &Tup, inserted: &[Tup], dir: &Path
let shaders = super::model_shaders(t)?;
let sampler = raea_sys_sampler::Sampling::col(&t.vals, "sampler").map_err(|e| format!("model {}: {e}", t.id))?;
let inst = model_placements(t)?;
+ // placements that change over the shot: moved by sync_instances once the scene is copied to them
+ if inst.is_some() {
+ world.entity_mut(e).insert(Placements::of(t));
+ }
// `shadow={false}`, `receiveShadow={false}`: on the model, then on each of its meshes once spawned (model_shadow_markers)
if t.vals.get("shadow").is_some_and(|v| !v.truthy()) {
world.entity_mut(e).insert(bevy::light::NotShadowCaster);
diff --git a/sdk/guides/craft/bevy/meshes.md b/sdk/guides/craft/bevy/meshes.md
index bd430286..b06992fd 100644
--- a/sdk/guides/craft/bevy/meshes.md
+++ b/sdk/guides/craft/bevy/meshes.md
@@ -28,9 +28,10 @@
- `<Instances src={staticFile("tree.glb")} at={placements} />` draws one glTF at every placement, loaded once and drawn
by the GPU as instances; without `src`, a geometry child (or `shape={solid}`) and a material child draw a mesh at
- every placement. Each placement is `{ position, rotation?, scale? }` (radians). The list is the first frame's for the
- whole shot: move, turn, scale or hide the set with the Instances' own props. Copies share one surface and play no
- clip. `shadow={false}` for grass and flowers by the thousand.
+ every placement. Each placement is `{ position, rotation?, scale? }` (radians). A list that changes moves the copies
+ (each distinct list is kept, so thousands moving every frame cost a list a frame); moving, turning, scaling or hiding
+ the whole set with the Instances' own props costs nothing. The count is the first frame's. Copies share one surface and
+ play no clip. `shadow={false}` for grass and flowers by the thousand.
- `scatter({ area: { min: [x0, z0], max: [x1, z1] }, count, spacing, avoid, margin, clearOf, seed, yaw, tilt, scale,
y, density })` makes the placements: seeded (the same every frame, render and play), at least `spacing` apart, off
the `avoid` boxes, on the ground height `y(x, z)`, kept where `density(x, z)` says. Call it once at module level.
diff --git a/sdk/render/src/3d/instances.tsx b/sdk/render/src/3d/instances.tsx
index 1681ceb2..4e9e7f60 100644
--- a/sdk/render/src/3d/instances.tsx
+++ b/sdk/render/src/3d/instances.tsx
@@ -19,8 +19,9 @@ export interface InstancesProps {
/** a glTF file drawn at every placement: staticFile("models/house.glb"). Without it, a geometry child (or `shape`)
* and a material child draw a mesh at every placement */
src?: string;
- /** where each copy stands. Fixed for the shot: the first frame's list is drawn on every frame (move, turn, scale,
- * hide or recolour the whole set by the Instances' own props) */
+ /** where each copy stands, this frame: a list that changes moves the copies with it (each distinct list is kept, so a
+ * set of thousands moving every frame costs a list a frame; moving the whole set by the Instances' own props costs
+ * nothing). How many copies is the first frame's: a frame with another count holds the list before it */
at: Instance[];
/** the entity's name, for picking, the inspector and world.* */
name?: string;