Skip to content

The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.

Meshes are edited in place (#163)

Yujia766d54d5ec17
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 2643491..22467d2 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -2730,6 +2730,23 @@ geometric normal through a function on a mirrored mesh, vertex colours on one (e
traversal); the flattening of an instance against the build's flattening, mirrored too; a mirrored model's build; a
copy mirrored in place; an emitting instanced object added, changed and removed in place against a build.
+**Meshes are edited in place (2026-11-18, scene step E, second part).** With every mesh an instance, what the
+scene does to one is a change of its instance, not a rebuild. Hidden or shown (itself, or a group above it): the
+instance's mask; a hidden mesh is built as an instance no ray sees, its row without power (`Instance::masked`,
+`show_meshes`). A still mesh's first move: its instance moves from then on, and one that emits has its emitters as
+moving ones, a new run of the light list (`Changes::started`, `start_moving`). Its geometry changed, the mesh
+re-created or removed, a group of meshes removed, a movable mesh added: in place whether or not the scene said it
+edits the mesh (`world::edits_in_place`; `dynamicGeometry` now only keeps room for it at the build). A placement
+without size is an unseen instance everywhere: built so, moved so, a posed rigid model's node too. A still model
+whose instance is all of it is hidden, moved and removed the same way (`whole`).
+Still a rebuild: a mesh of several materials changed or added; a mesh shown after its geometry changed while it was
+hidden; a model hidden when the scene was built, or with triangles flattened beside its instance; an animated model's
+first move; a hidden mesh under software traversal without units.
+Tests, each against a build's light list, weights and picture: meshes hidden and shown (still, emitting, hidden at
+the build, a group, moved while hidden); a still mesh's first move (emitting, plain, a group, one built without
+size); meshes changed without the scene's word (a shared geometry, a re-creation, a movable one added, removals); a
+still model hidden, removed and moved. `volume/grid-rebuild-live` rebuilds by adding a group.
+
**A mesh is an instance of its geometry's mesh (2026-11-18, scene step E, first part).** A mesh was an instance
only where scene code asked (`dynamicGeometry`) or a body drove it; every other one was flattened into the
still scene's world-space groups, a movable one re-transformed on the CPU at each move. Now every shown mesh with a
diff --git a/packages/scene/src/core.ts b/packages/scene/src/core.ts
index c6e7b6d..77603cd 100644
--- a/packages/scene/src/core.ts
+++ b/packages/scene/src/core.ts
@@ -509,9 +509,10 @@ export class Object3D {
touched(this);
}
/**
- * UE Mobility "Movable": the frame script moves it (and everything under it) every frame; the renderer keeps its
- * triangles apart and updates them in place. Fixed objects that move become movable at their first move, which
- * rebuilds the scene once.
+ * The frame script moves it (and everything under it) every frame. A mesh or a still model moves in place by its
+ * instance whether this is set or not, and is movable from its first move. What the renderer draws another way (an
+ * animated model, an instanced object or a light's card under it) has its triangles kept apart by this; without
+ * it, the first move rebuilds the scene once.
*/
get movable(): boolean {
return this._movable;
@@ -1201,9 +1202,9 @@ export class Mesh extends Object3D {
declare private _material: MeshStandardMaterial | MeshStandardMaterial[];
declare private _dynamicGeometry: boolean;
/**
- * The mesh's geometry will change at run time (a new `geometry`, `needsUpdate`), or meshes like it come and go:
- * the renderer gives it its own acceleration structure, so those changes apply in place instead of rebuilding the
- * scene. Off by default: static meshes share the scene's (faster to trace, cheaper in memory).
+ * The mesh's geometry will change at run time (a new `geometry`, `needsUpdate`), or meshes like it come and go.
+ * Any mesh's geometry changes in place; this says so beforehand, and the renderer keeps room for the changes when
+ * it builds the scene instead of growing it at the first one.
*/
get dynamicGeometry(): boolean {
return this._dynamicGeometry ?? false;
diff --git a/renderer/src/lib.rs b/renderer/src/lib.rs
index cc1dfba..dbc0b8c 100644
--- a/renderer/src/lib.rs
+++ b/renderer/src/lib.rs
@@ -715,6 +715,8 @@ pub fn prepare_as(hwrt: bool, units: bool, sc: &mut scene::Scene, timings: &mut
let n = scene::number_emitters(&mut sc.attrs[pool_first + m.first as usize..pool_first + (m.first + m.count) as usize], &sc.materials);
assert_eq!(n, m.emitters, "a mesh's emitters as the build counted them");
}
+ // (And the instances hidden at the build, `Instance::masked`: where they stand when they are shown is theirs to
+ // bound then, in the light tree's moving subtree.)
let moving = sc.retained.moving_records();
for r in 0..sc.instances.len() {
let m = sc.meshes[sc.instances[r].mesh as usize];
@@ -728,7 +730,7 @@ pub fn prepare_as(hwrt: bool, units: bool, sc: &mut scene::Scene, timings: &mut
let (a, b) = (m.first as usize, (m.first + m.count) as usize);
let attrs = &sc.attrs[pool_first + a..pool_first + b];
let numbered = |k: usize| (attrs[k].x[3].to_bits() as usize).checked_sub(1).map(|n| (n, attrs[k].uv[3].to_bits()));
- for (e, w) in instance_emitters(&sc.instances[r], r as u32, &sc.pool_tris[a..b], (pool_first + a) as u32, &numbered, m.emitters as usize, &sc.materials, moving.contains(&(r as u32))) {
+ for (e, w) in instance_emitters(&sc.instances[r], r as u32, &sc.pool_tris[a..b], (pool_first + a) as u32, &numbered, m.emitters as usize, &sc.materials, moving.contains(&(r as u32)) || sc.instances[r].masked) {
gpu_emitter_tris.push(GpuEmitterTri::of(&e, w, 0));
emitter_tris.push(e);
}
@@ -1646,9 +1648,9 @@ mod units_tests {
assert_eq!(su.tris.len(), 2 * ground, "still triangles: the card's only");
let u = su.units.as_ref().expect("the scene has units");
assert!(sf.units.is_none() && sf.instances.is_empty(), "flattened: no instance is left");
- // Nine instances and the ground: four meshes shown, one hidden (no instance at all), five of the instanced mesh
- // of which one is hidden: eight units in the top tree, and the ground.
- assert_eq!((su.instances.len(), u.count as usize), (9 + ground, 8 + ground), "{:?}", su.instances.iter().map(|i| (i.name.clone(), i.hidden)).collect::<Vec<_>>());
+ // Ten instances and the ground: four meshes shown, one hidden (an instance no ray sees), five of the instanced
+ // mesh of which one is hidden: eight units in the top tree, and the ground.
+ assert_eq!((su.instances.len(), u.count as usize), (10 + ground, 8 + ground), "{:?}", su.instances.iter().map(|i| (i.name.clone(), i.hidden)).collect::<Vec<_>>());
assert!(gpu::instance_features(&su) & gpu::F_UNITS != 0 && gpu::instance_features(&sf) & gpu::F_UNITS == 0);
assert_eq!((pu.params.motion[2].to_bits(), pu.params.motion[3].to_bits() as usize), (u.layout.top_first, 8 + ground));
// The flattened scene holds every instance's triangles; the scene with units holds each mesh's once.
diff --git a/renderer/src/live/edits.rs b/renderer/src/live/edits.rs
index 25db39c..ab17d16 100644
--- a/renderer/src/live/edits.rs
+++ b/renderer/src/live/edits.rs
@@ -288,11 +288,22 @@ impl Grow<'_> {
}
}
+/// Whether an object's instance is all of it, so that an edit can hide, move or take out the object by it: a mesh's,
+/// or a still model's whose mesh has nothing flattened at each placement beside.
+pub(super) fn whole(i: &scene::InstanceRef, instances: &[scene::Instance], meshes: &[scene::InstMesh]) -> bool {
+ i.mesh.own() || (matches!(i.mesh, scene::MeshKind::Model) && instances.get(i.instance as usize).is_some_and(|x| meshes.get(x.mesh as usize).is_some_and(|m| m.rest_count == 0)))
+}
+
/// An object removed or hidden in place is no longer drawn: hidden where its record's value is (`LiveCore::pick`
/// skips it). The mesh it was an instance of, if it was drawn as one: a user fewer (`drop_mesh_user`).
pub(super) fn undraw(draw: Option<&scene::Draw>, instances: &mut [scene::Instance], procs: &mut [scene::ProcObject]) -> Option<u32> {
match draw? {
- scene::Draw::Instance(i) => instances.get_mut(i.instance as usize).and_then(|i| (!std::mem::replace(&mut i.hidden, true)).then_some(i.mesh)),
+ scene::Draw::Instance(i) => instances.get_mut(i.instance as usize).and_then(|i| {
+ // (One hidden by its object's visibility still had its mesh.)
+ let held = !i.hidden || i.masked;
+ (i.hidden, i.masked) = (true, false);
+ held.then_some(i.mesh)
+ }),
scene::Draw::Procedural(j) => {
if let Some(p) = procs.get_mut(*j as usize) {
p.hidden = true;
@@ -350,6 +361,7 @@ impl LiveCore {
changes.lights.insert(id);
true
}
+ Some(crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { animation: None, .. } | crate::world::Kind::Group) => self.show_meshes(world, id, &mut changes, &mut top),
_ => false,
};
if !done {
@@ -370,10 +382,11 @@ impl LiveCore {
changes.structural = true;
}
}
- // An object an edit placed (its record is the room's) moves in place only as an instance does: a mesh a body
- // drives, while it is drawn. Any other rebuilds.
+ // An object an edit placed (its record is the room's) moves in place as an instance does (a still one from its
+ // first move: `start_moving`), unless an edit took the instance out while the object was hidden; procedural
+ // geometry an edit placed rebuilds.
let stuck = |id: &u32| match self.sc.tables.retained.proxies.get(id).map(|p| &p.draw) {
- Some(scene::Draw::Instance(i)) => self.sc.edit.in_room(i.instance as usize) && !(i.moves && self.sc.instances.get(i.instance as usize).is_some_and(|i| !i.hidden)),
+ Some(scene::Draw::Instance(i)) => self.sc.edit.in_room(i.instance as usize) && self.sc.instances.get(i.instance as usize).is_none_or(|i| i.hidden && !i.masked),
Some(scene::Draw::Procedural(j)) => self.sc.edit.in_room(self.sc.proc_first + *j as usize),
_ => false,
};
@@ -414,17 +427,18 @@ impl LiveCore {
}
}
}
- if !changes.promoted_geometry.is_empty() {
- eprintln!("live: {}: geometry changed, now with its own BLAS (this once rebuilds; set `dynamicGeometry` or the attribute's DynamicDrawUsage to avoid it)", changes.promoted_geometry.join(", "));
- self.fallback = Some("promote".into());
- self.fallbacks += 1;
- }
if !changes.promoted.is_empty() {
eprintln!("live: {} moved, now movable (this once rebuilds; set `movable = true` in the scene code to avoid it)", changes.promoted.join(", "));
}
// Moved movable subtrees: their drawables are re-transformed with the posed models, their lights rewritten in
// the light table.
let mut dynamic = changes.poses.clone();
+ // Still objects that moved for the first time: their meshes' instances move from now on, or the scene rebuilds.
+ for id in std::mem::take(&mut changes.started) {
+ if !changes.structural && !self.start_moving(world, id) {
+ changes.structural = true;
+ }
+ }
let mut placed = vec![];
let mut procs_moved = vec![];
let mut instanced_moved = vec![];
@@ -433,10 +447,12 @@ impl LiveCore {
for k in world.subtree_with(*id, &children) {
match &world.objects[&k].kind {
crate::world::Kind::Light(crate::desc::Light::Rect { visible: true, .. }) | crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { .. } => {
- if world.shown(k) {
+ // (A mesh hidden by its visibility keeps its instance, which moves with it.)
+ let inst = self.sc.tables.retained.instance(k).filter(|i| i.moves).copied();
+ let masked = inst.is_some_and(|i| self.sc.instances.get(i.instance as usize).is_some_and(|x| x.masked));
+ if world.shown(k) || masked {
// Movable models placed as instances move their transform (with a shared pose too); the rest
// re-transform triangles.
- let inst = self.sc.tables.retained.instance(k).filter(|i| i.moves).copied();
match inst.map(|i| i.instance) {
Some(i) if !changes.poses.contains(&k) || inst.is_some_and(|i| matches!(i.mesh, scene::MeshKind::Pose(_))) => placed.push((k, i)),
_ => {
@@ -490,6 +506,7 @@ impl LiveCore {
self.move_procs(world, &procs_moved, &mut top);
}
let placed_ok = shared_ok && (placed.is_empty() || (!changes.structural && self.move_instances(world, &placed, &mut top)));
+ changes.powers.extend(self.flipped.drain(..));
let t_rigid = Instant::now();
let rigid_ok = placed_ok && (rigid.is_empty() || (!changes.structural && self.repose_rigid(world, &rigid, &mut top)?));
self.cpu_skin_ms += t_rigid.elapsed().as_secs_f32() * 1000.0;
@@ -556,6 +573,7 @@ impl LiveCore {
}
let Some(d) = applied else {
let t = Instant::now();
+ self.pending_emitters.clear();
self.rebuild(world)?;
self.rebuild_ms += t.elapsed().as_secs_f32() * 1e3;
if changes.camera {
@@ -577,7 +595,8 @@ impl LiveCore {
up.heap.write(q, Table::Objects, 0, bytemuck::cast_slice(&e.objects));
}
if d.materials || d.emitters || std::mem::take(&mut self.emitters_reweigh) {
- let new = self.add_material_emitters(world);
+ let mut new = self.add_material_emitters(world);
+ new.append(&mut self.pending_emitters);
self.write_emitters(&new);
} else if d.deferred {
self.send_powers();
@@ -737,11 +756,112 @@ impl LiveCore {
self.lit_changed = self.frame.max(1);
}
+ /// An instance that came back, or went unseen: its emitters' areas and centres as it stands now (an unseen one's
+ /// are its mesh's own: `placed_emitter`), for their weights.
+ fn weigh_run(&mut self, r: u32) {
+ let LoadedScene { tables, instances, pool_tris, edit, .. } = &mut self.sc;
+ let Some(inst) = instances.get(r as usize) else { return };
+ let run = emitter_run(&tables.emitter_tris, instances, r);
+ for j in run.clone() {
+ let e = tables.emitter_tris[j];
+ if e.area > 0.0 {
+ let (area, c, _) = crate::placed_emitter(inst, &pool_tris[e.tri as usize - edit.pool_first], e.mat, &tables.materials);
+ (tables.emitter_tris[j].area, tables.emitter_tris[j].c) = (area, c);
+ }
+ }
+ self.emitters_reweigh |= !run.is_empty();
+ }
+
+ /// A still object's first move, in place: the meshes under it (itself, if it is one) move by their instances from
+ /// now on (`InstanceRef::moves`), and one that emits has its emitters as moving ones: a new run of the light list
+ /// (the light tree keeps the old one where it stood, at no weight). False where something under it is drawn
+ /// another way: the caller rebuilds.
+ fn start_moving(&mut self, world: &World, id: u32) -> bool {
+ let children = world.children();
+ let sub = world.subtree_with(id, &children);
+ // (Nothing is changed unless all of it can be.)
+ let held = |k: &u32| match &world.objects[k].kind {
+ crate::world::Kind::Group | crate::world::Kind::Camera(_) => true,
+ crate::world::Kind::Light(l) => !matches!(l, crate::desc::Light::Rect { visible: true, .. }),
+ crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { animation: None, .. } => {
+ self.sc.tables.retained.instance(*k).is_some_and(|i| whole(i, &self.sc.instances, &self.sc.meshes) && self.sc.instances.get(i.instance as usize).is_some_and(|x| !x.hidden || x.masked))
+ }
+ _ => false,
+ };
+ if !sub.iter().all(held) {
+ return false;
+ }
+ let LoadedScene { tables, instances, gpu_instances, pool_tris, edit, .. } = &mut self.sc;
+ for k in sub {
+ let Some(scene::Draw::Instance(i)) = tables.retained.proxies.get_mut(&k).map(|p| &mut p.draw) else { continue };
+ if std::mem::replace(&mut i.moves, true) {
+ continue;
+ }
+ let r = i.instance;
+ let old = emitter_run(&tables.emitter_tris, instances, r);
+ if old.is_empty() || tables.emitter_tris[old.clone()].iter().all(|e| e.moves) {
+ continue;
+ }
+ let first = tables.emitter_tris.len() as u32;
+ let inst = &mut instances[r as usize];
+ // (Where this commit's move places it: `move_instances`, next.)
+ let (to, _) = scene::placed_world(world.world_matrix(k), inst.world.w_axis.truncate());
+ for j in old {
+ let e = crate::EmitterTri { moves: true, in_tree: false, ..tables.emitter_tris[j] };
+ tables.emitter_tris[j].area = 0.0;
+ let w = pool_tris[e.tri as usize - edit.pool_first].map(|v| glam::Vec3A::from(to.transform_point3(v.into())));
+ self.pending_emitters.push((tables.emitter_tris.len() as u32, crate::GpuEmitterTri::of(&e, w, 0)));
+ tables.emitter_tris.push(e);
+ }
+ inst.first_emitter = first;
+ if let Some(rec) = gpu_instances.get_mut(r as usize) {
+ rec.n[2][3] = f32::from_bits(first);
+ }
+ self.emitters_reweigh = true;
+ }
+ true
+ }
+
+ /// An object shown or hidden by its `visible`, in place: the meshes and still models under it (itself, if it is one) each by its
+ /// instance's mask above the triangles, where no ray sees a hidden one, and its row's power (`Tables::apply`: a
+ /// hidden mesh's emitters at no weight). False where something under it is drawn another way, or a mesh is not
+ /// such an instance (the build flattened it, or an edit took it out while it was hidden): the caller rebuilds.
+ fn show_meshes(&mut self, world: &World, id: u32, changes: &mut crate::world::Changes, build: &mut gpu::TopBuild) -> bool {
+ let children = world.children();
+ for k in world.subtree_with(id, &children) {
+ match &world.objects[&k].kind {
+ crate::world::Kind::Group | crate::world::Kind::Camera(_) => {}
+ crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { animation: None, .. } => {
+ let Some(r) = self.sc.tables.retained.instance(k).filter(|i| whole(i, &self.sc.instances, &self.sc.meshes)).map(|i| i.instance as usize) else { return false };
+ let Some(inst) = self.sc.instances.get_mut(r) else { return false };
+ if inst.hidden && !inst.masked {
+ return false;
+ }
+ // (Where it stands: it may have moved, or lost its size, while it was hidden.)
+ let (w, gone) = scene::placed_world(world.world_matrix(k), inst.world.w_axis.truncate());
+ let unseen = gone || !world.shown(k);
+ if inst.hidden == unseen {
+ continue;
+ }
+ let Some(mut top) = gpu::Top::of(&mut self.sc.up.accel, &mut self.sc.up.units) else { return false };
+ (inst.hidden, inst.masked) = (unseen, unseen);
+ top.moved(top.inst_base() + r, w, Some((inst.cast_shadow, unseen)));
+ build.instances = true;
+ changes.powers.insert(k);
+ self.weigh_run(r as u32);
+ }
+ _ => return false,
+ }
+ }
+ true
+ }
+
/// Moves movable instances: their kernel records (the old transform kept as the previous frame's, for motion
/// vectors), their object entries' pivots and their TLAS transforms (hardware traversal) or their units (software
/// traversal, units.rs); the commit builds what is above them (`build_top`). No triangles change. False when it
/// cannot (software traversal without units, or an instance that is no unit): the caller rebuilds.
pub(super) fn move_instances(&mut self, world: &World, placed: &[(u32, u32)], build: &mut gpu::TopBuild) -> bool {
+
// (Hardware traversal's TLAS instances, or software traversal's units; neither: the caller rebuilds.)
let Some(mut top) = gpu::Top::of(&mut self.sc.up.accel, &mut self.sc.up.units) else { return false };
let size = std::mem::size_of::<scene::GpuInstance>() as u64;
@@ -775,13 +895,25 @@ impl LiveCore {
let o = &mut self.sc.tables.objects[inst.object as usize * st];
(o[0], o[1], o[2]) = (pivot.x, pivot.y, pivot.z);
let slot = top.inst_base() + i as usize;
- top.moved(slot, w, Some((inst.cast_shadow, gone || inst.hidden)));
+ // (Unseen while it has no size, or its object is hidden: `Instance::masked`. Its row's power follows.)
+ let unseen = gone || !world.shown(node);
+ let flipped = inst.hidden != unseen;
+ (inst.hidden, inst.masked) = (unseen, unseen);
+ top.moved(slot, w, Some((inst.cast_shadow, unseen)));
self.inst_moving.push(i);
+ if flipped {
+ self.flipped.push(node);
+ }
}
if merged {
self.sc.up.heap.write(q, Table::Instances, lo as u64 * size, bytemuck::cast_slice(&self.sc.gpu_instances[lo..=hi]));
}
self.sc.up.heap.write(q, Table::Objects, 0, bytemuck::cast_slice(&self.sc.tables.objects));
+ for k in 0..self.flipped.len() {
+ if let Some(r) = self.sc.tables.retained.instance(self.flipped[k]).map(|i| i.instance) {
+ self.weigh_run(r);
+ }
+ }
self.fill_moved(placed.iter().map(|&(_, i)| i));
self.inst_moved = true;
build.instances = true;
@@ -884,8 +1016,8 @@ impl LiveCore {
q.write_buffer(&up.attrs, (first_tri * std::mem::size_of::<scene::GpuTriAttr>()) as u64, bytemuck::cast_slice(&a));
let numbered = |j: usize| (a[j].x[3].to_bits() as usize).checked_sub(1).map(|slot| (slot, a[j].uv[3].to_bits()));
for r in 0..instances.len() {
- // (A record no object draws any more has none.)
- if instances[r].mesh != k || instances[r].hidden {
+ // (A record no object draws any more has none; one hidden by its object's visibility has.)
+ if instances[r].mesh != k || (instances[r].hidden && !instances[r].masked) {
continue;
}
let old = emitter_run(&tables.emitter_tris, instances, r as u32);
@@ -1288,6 +1420,8 @@ impl LiveCore {
for &(i, w) in &placements {
let inst = &mut self.sc.instances[i as usize];
let old = self.sc.gpu_instances[i as usize];
+ // (A node its clip scales to nothing: at a point, where no ray sees it.)
+ let (w, gone) = scene::placed_world(w, inst.world.w_axis.truncate());
inst.world = w;
let mut r = inst.gpu(old.info[0], [old.info[3], old.n[0][3].to_bits()]);
r.p = old.m;
@@ -1296,6 +1430,7 @@ impl LiveCore {
let row = |k: usize| [w.x_axis[k], w.y_axis[k], w.z_axis[k], w.w_axis[k]];
if let Some(t) = accel.tlas[accel.inst_base + i as usize].as_mut() {
t.transform = [row(0), row(1), row(2)].concat().try_into().unwrap();
+ t.mask = gpu::instance_mask(inst.cast_shadow, gone || inst.hidden);
}
// (Rigid models' instances are theirs alone: no other update this commit placed them.)
self.inst_moving.push(i);
@@ -1646,7 +1781,7 @@ impl LiveCore {
let Some(mut top) = gpu::Top::of(&mut up.accel, &mut up.units) else {
// Software traversal without units. With units on, that is a scene without an instance yet: the first
// one brings the unit walk into the kernel (F_UNITS), as hardware traversal's first brings F_INST.
- let first = crate::units_on(true) && ch.added.iter().any(|id| matches!(world.objects.get(id).map(|o| &o.kind), Some(Kind::Mesh { own_blas: true, .. } | Kind::Instanced { procedural: false, .. })));
+ let first = crate::units_on(true) && ch.added.iter().any(|id| matches!(world.objects.get(id).map(|o| &o.kind), Some(Kind::Mesh { .. } | Kind::Instanced { procedural: false, .. })));
return Err(if first { "the scene's first instanced mesh (kernel feature)" } else { "software traversal" }.into());
};
// The objects to place again: those added, and those whose geometry was replaced.
@@ -1654,10 +1789,9 @@ impl LiveCore {
if !ch.geometries.is_empty() {
for (id, o) in &world.objects {
match &o.kind {
- Kind::Procedural { geometry, .. } | Kind::Mesh { geometry, own_blas: true, .. } if ch.geometries.contains(geometry) => {
+ Kind::Procedural { geometry, .. } | Kind::Mesh { geometry, .. } if ch.geometries.contains(geometry) => {
todo.insert(*id);
}
- Kind::Mesh { geometry, .. } if ch.geometries.contains(geometry) => return Err("a flattened mesh's geometry changed".into()),
// (One added this commit is placed with its geometry as it is.)
Kind::Instanced { geometry, .. } if ch.geometries.contains(geometry) && !ch.added.contains(id) => return Err("an instanced mesh's geometry changed".into()),
_ => {}
@@ -1710,11 +1844,12 @@ impl LiveCore {
continue;
}
emitters_changed |= release(*id, tables, instances);
- let at = slot_of(*id, edit, tables);
- // Drawn, and not at a record an edit can clear (a model the build placed, anything it flattened): a rebuild
- // takes it out.
+ // (A still model the build placed, whose instance is all of it, is taken out by it too.)
+ let at = slot_of(*id, edit, tables).or_else(|| tables.retained.instance(*id).filter(|i| whole(i, instances, meshes)).map(|i| (inst_base + i.instance as usize, i.instance as usize)));
+ // Drawn, and not at a record an edit can clear (a model with triangles flattened beside its instance,
+ // anything the build flattened): a rebuild takes it out.
if at.is_none() && tables.retained.proxies.contains_key(id) {
- return Err("an object the build placed otherwise (a model, something it flattened) removed".into());
+ return Err("an object the build placed otherwise (a model in parts, something it flattened) removed".into());
}
let proxy = tables.retained.proxies.remove(id);
if let Some((slot, record)) = at {
@@ -1854,13 +1989,13 @@ impl LiveCore {
if let Some(k) = was {
drop_mesh_user(k, edit, tables, meshes);
}
- let inst = scene::Instance { mesh, world: m, object: object as u32, cast_shadow: im.casts(o.cast_shadow), name: o.name.clone(), sub: None, hidden: false, first_emitter: 0 };
+ let inst = scene::Instance { mesh, world: m, object: object as u32, cast_shadow: im.casts(o.cast_shadow), name: o.name.clone(), sub: None, hidden: false, masked: false, first_emitter: 0 };
let gpu = top.record(inst.gpu((edit.pool_first as u32) + im.first, im.part_offsets()), mesh, inst.cast_shadow);
let (lo, hi) = im.placed_bounds(m);
let entry = scene::object_row(m.transform_point3(glam::Vec3::ZERO), o.power, hi - lo, o.custom, [1.0; 3]);
(at.map(|(_, r)| r), gpu, Placed::Mesh(inst), entry)
}
- Kind::Mesh { own_blas: true, .. } | Kind::Instanced { procedural: false, .. } => {
+ Kind::Mesh { .. } | Kind::Instanced { procedural: false, .. } => {
// An own-BLAS mesh, or (added in place) an instanced mesh: their mesh made alike.
let (geometry, material, capacity) = match &o.kind {
Kind::Mesh { geometry, material, .. } => (*geometry, *material, None),
@@ -1871,9 +2006,9 @@ impl LiveCore {
if features & gpu::F_INST == 0 {
return Err("the scene's first instanced mesh (kernel feature)".into());
}
- // What the build flattens instead (scene.rs: a placement without size, or instancing off).
+ // A placement without size (a build places it, unseen at a point), or instancing off (it flattens).
if m.determinant() == 0.0 || std::env::var("THREERT_INSTANCING").is_ok_and(|v| v == "0") {
- return Err("a mesh without size, or instancing off (the build flattens it)".into());
+ return Err("a mesh without size, or instancing off".into());
}
let mat = *tables.retained.materials.get(material).ok_or("unknown material")?;
let gm = tables.materials[mat as usize];
@@ -2073,7 +2208,7 @@ impl LiveCore {
};
let (st, size) = (tables.stride, std::mem::size_of::<scene::GpuInstance>());
if instances.len() < r0 + cap {
- let filler = scene::Instance { mesh, world: glam::Mat4::IDENTITY, object: 0, cast_shadow: false, name: String::new(), sub: None, hidden: true, first_emitter: 0 };
+ let filler = scene::Instance { mesh, world: glam::Mat4::IDENTITY, object: 0, cast_shadow: false, name: String::new(), sub: None, hidden: true, masked: false, first_emitter: 0 };
instances.resize(r0 + cap, filler);
}
if gpu_instances.len() < r0 + cap {
@@ -2083,7 +2218,7 @@ impl LiveCore {
tables.objects.resize((o0 + cap) * st, [0.0; 4]);
}
for (i, &(wm, hidden)) in placed.iter().enumerate() {
- let mut inst = scene::Instance { mesh, world: wm, object: (o0 + i) as u32, cast_shadow: im.casts(o.cast_shadow), name: o.name.clone(), sub: Some(i as u32), hidden, first_emitter: 0 };
+ let mut inst = scene::Instance { mesh, world: wm, object: (o0 + i) as u32, cast_shadow: im.casts(o.cast_shadow), name: o.name.clone(), sub: Some(i as u32), hidden, masked: false, first_emitter: 0 };
// A copy of a mesh that emits: its emitters, a run at the light list's end; moving ones
// (`update_instanced` changes the copies in place), a hidden copy's at no weight.
if im.emitters > 0 {
@@ -2111,13 +2246,13 @@ impl LiveCore {
*tables.retained.proxy(id) = scene::Proxy { object: None, card: None, draw: scene::Draw::Instanced(scene::InstancedPlace { first: r0 as u32, capacity: cap as u32, object: o0 as u32, mesh: Some(mesh), drawn: t.count }) };
continue;
}
- let inst = scene::Instance { mesh, world: m, object: object as u32, cast_shadow: im.casts(o.cast_shadow), name: o.name.clone(), sub: None, hidden: false, first_emitter: 0 };
+ let inst = scene::Instance { mesh, world: m, object: object as u32, cast_shadow: im.casts(o.cast_shadow), name: o.name.clone(), sub: None, hidden: false, masked: false, first_emitter: 0 };
let gpu = top.record(inst.gpu((edit.pool_first as u32) + im.first, im.part_offsets()), mesh, inst.cast_shadow);
let (lo, hi) = im.placed_bounds(m);
let entry = scene::object_row(m.transform_point3(glam::Vec3::ZERO), o.power, hi - lo, o.custom, [1.0; 3]);
(at.map(|(_, r)| r), gpu, Placed::Mesh(inst), entry)
}
- _ => return Err("not an object with its own BLAS".into()),
+ _ => return Err("not an object an edit places".into()),
};
// Its record, TLAS instance and object entry: where it had them, or new ones from the room.
let (slot, record) = match (at, record) {
@@ -2147,7 +2282,7 @@ impl LiveCore {
inst.first_emitter = first as u32;
gpu.n[2][3] = f32::from_bits(first as u32);
let (a, b) = (im.first as usize, (im.first + im.count) as usize);
- let made = crate::instance_emitters(inst, record as u32, &pool_tris[a..b], (edit.pool_first + a) as u32, &|k| Some((k, mat)), im.emitters as usize, &tables.materials, o.driven);
+ let made = crate::instance_emitters(inst, record as u32, &pool_tris[a..b], (edit.pool_first + a) as u32, &|k| Some((k, mat)), im.emitters as usize, &tables.materials, o.driven || world.movable(id));
for (j, (e, w)) in made.into_iter().enumerate() {
new_emitters.push(((first + j) as u32, crate::GpuEmitterTri::of(&e, w, 0)));
match tables.emitter_tris.get_mut(first + j) {
@@ -2184,7 +2319,7 @@ impl LiveCore {
let mesh = if matches!(o.kind, Kind::Model { .. }) { scene::MeshKind::Model } else { scene::MeshKind::Own };
instances[record] = inst;
// (A mesh a body drives moves as an instance does, as the build's: `commit`.)
- scene::Draw::Instance(scene::InstanceRef { instance: record as u32, mesh, moves: o.driven })
+ scene::Draw::Instance(scene::InstanceRef { instance: record as u32, mesh, moves: o.driven || world.movable(id) })
}
};
let st = tables.stride;
diff --git a/renderer/src/live/inplace_tests.rs b/renderer/src/live/inplace_tests.rs
index 2fef0ad..5a3df61 100644
--- a/renderer/src/live/inplace_tests.rs
+++ b/renderer/src/live/inplace_tests.rs
@@ -191,10 +191,10 @@ fn edits_in_place_leave_what_a_build_does() {
assert!(!live.commit(&mut w).unwrap() && live.cam == away && live.view.dof.is_some(), "a depth of field and an exposure: the view stays");
w.set_camera_desc(6, camera(40.0, Some(3.0), manual(2.0))).unwrap();
assert!(!live.commit(&mut w).unwrap() && live.cam == live.view.camera && live.cam != away, "a lens: the view takes the scene's camera");
- // A commit that rebuilds (another mesh) and brings another preset with it.
- w.set_object(13, "more".into(), None, Kind::Mesh { geometry: 3, material: 1, own_blas: false, materials: vec![] }, true, false).unwrap();
+ // A commit that rebuilds (another group: what a build places) and brings another preset with it.
+ w.set_object(13, "more".into(), None, Kind::Group, true, false).unwrap();
w.set_settings(Settings { preset: "cinematic".into(), overrides: Some(serde_json::json!({ "post": { "vignette": 0.3 } })), ..w.settings.clone() });
- assert!(live.commit(&mut w).unwrap(), "another mesh: a rebuild");
+ assert!(live.commit(&mut w).unwrap(), "another group: a rebuild");
let mut fresh = open(&w).unwrap();
(picture(&mut live, 1), picture(&mut fresh, 1));
same_state("a rebuild with another preset", &live, &fresh);
@@ -907,6 +907,8 @@ fn a_material_that_starts_emitting_lights_its_meshes_instances_as_a_build_does()
let mesh = |geometry, material, materials| Kind::Mesh { geometry, material, own_blas: false, materials };
w.set_object(13, "one".into(), None, mesh(3, 6, vec![]), true, false).unwrap();
w.set_transform(13, Vec3::new(-0.6, -0.5, 0.8), glam::Quat::IDENTITY, Vec3::ONE).unwrap();
+ w.set_object(33, "third".into(), None, mesh(3, 6, vec![]), true, false).unwrap();
+ w.set_transform(33, Vec3::new(-0.1, -0.1, 1.2), glam::Quat::from_rotation_y(-0.4), Vec3::ONE).unwrap();
w.set_object(14, "other".into(), None, mesh(3, 6, vec![]), true, true).unwrap();
w.set_transform(14, Vec3::new(0.5, -0.5, 0.9), glam::Quat::from_rotation_y(0.5), Vec3::ONE).unwrap();
w.set_object(15, "two".into(), None, mesh(7, 5, vec![5, 6]), true, false).unwrap();
@@ -938,6 +940,9 @@ fn a_material_that_starts_emitting_lights_its_meshes_instances_as_a_build_does()
assert_eq!(mesh_of(&live, 13), mesh_of(&live, 14), "the two objects share their mesh");
let two = mesh_of(&live, 15) as usize;
assert_eq!((live.sc.meshes[two].count, live.sc.meshes[two].emitters), (32, 16), "the mesh of two materials: one emits");
+ // (A third object of the shared mesh, hidden when the material starts: it has its emitters when it is shown.)
+ w.set_visible(33, false).unwrap();
+ assert!(!live.commit(&mut w).unwrap(), "a mesh hidden, {with} a light tree: in place ({:?})", live.fallback);
w.set_material(6, late(30.0));
let what = format!("a material started emitting in place, {with} a light tree");
assert!(!live.commit(&mut w).unwrap(), "{what}: in place ({:?})", live.fallback);
@@ -949,6 +954,11 @@ fn a_material_that_starts_emitting_lights_its_meshes_instances_as_a_build_does()
};
assert_eq!((moving(&live, 13), moving(&live, 14)), (vec![false; 2], vec![true; 2]), "{what}: the movable one's emitters move");
lit_as_a_build(&what, &mut live, &mut open(&w).unwrap());
+ w.set_visible(33, true).unwrap();
+ let what = format!("a mesh hidden when its material started emitting, shown, {with} a light tree");
+ assert!(!live.commit(&mut w).unwrap(), "{what}: in place ({:?})", live.fallback);
+ list_is_its_triangles(&what, &live);
+ lit_as_a_build(&what, &mut live, &mut open(&w).unwrap());
if live.g.hwrt {
w.set_object(29, "added".into(), None, Kind::Mesh { geometry: 3, material: 8, own_blas: true, materials: vec![] }, true, false).unwrap();
w.set_transform(29, Vec3::new(-0.2, 0.1, 1.0), glam::Quat::IDENTITY, Vec3::ONE).unwrap();
@@ -980,3 +990,309 @@ fn a_material_that_starts_emitting_lights_its_meshes_instances_as_a_build_does()
assert!(live.commit(&mut w).unwrap(), "a material an instanced object has too started emitting, {with} a light tree: a rebuild");
}
}
+
+/// A mesh hidden or shown by its `visible` is drawn and lit as a build draws it, in place: a still mesh, one that
+/// emits, one hidden when the scene was built, a group of two, a movable one moved while it was hidden. With and
+/// without a light tree. After each: no rebuild, the light list is its triangles, the weights and the picture are a
+/// build's. A mesh whose geometry changed while it was hidden is drawn again by a rebuild.
+#[test]
+fn meshes_hidden_and_shown_in_place_are_drawn_as_a_build_draws_them() {
+ let presets = crate::default_presets_dir();
+ let open = |w: &World| gpu::Gpu::new().and_then(|g| LiveCore::new(g, w, Path::new("."), &presets, 96, 54));
+ let quad = |s: f32| Geometry { positions: vec![-s, -s, 0.0, s, -s, 0.0, s, s, 0.0, -s, s, 0.0], normals: [0.0, 0.0, 1.0].repeat(4), uvs: vec![0.0; 8], indices: vec![0, 1, 2, 0, 2, 3], groups: vec![], colors: vec![] };
+ for tree in [false, true] {
+ let mut w = world();
+ let mesh = |geometry, material, own_blas| Kind::Mesh { geometry, material, own_blas, materials: vec![] };
+ let place = |w: &mut World, id: u32, name: &str, parent: Option<u32>, kind: Kind, movable: bool, at: [f32; 3]| {
+ w.set_object(id, name.into(), parent, kind, true, movable).unwrap();
+ w.set_transform(id, Vec3::from(at), glam::Quat::from_rotation_y(0.3), Vec3::ONE).unwrap();
+ };
+ // A lamp hidden at the build, a group of two panels, a movable panel, a mesh the scene edits (a geometry of
+ // its own).
+ place(&mut w, 13, "late", None, mesh(3, 5, false), false, [-0.6, 0.6, 1.2]);
+ // (Stretched: the area it has when it is shown is not its mesh's own.)
+ w.set_transform(13, Vec3::new(-0.6, 0.6, 1.2), glam::Quat::from_rotation_y(0.3), Vec3::new(1.6, 0.6, 1.0)).unwrap();
+ w.set_visible(13, false).unwrap();
+ w.set_object(14, "group".into(), None, Kind::Group, true, false).unwrap();
+ place(&mut w, 15, "a", Some(14), mesh(3, 1, false), false, [0.5, -0.5, 0.6]);
+ place(&mut w, 16, "b", Some(14), mesh(3, 1, false), false, [0.0, -0.6, 0.9]);
+ place(&mut w, 21, "mover", None, mesh(3, 1, false), true, [0.7, 0.5, 0.5]);
+ w.set_geometry(8, quad(0.2)).unwrap();
+ place(&mut w, 22, "own", None, mesh(8, 1, true), false, [-0.7, -0.5, 0.9]);
+ if tree {
+ strip(&mut w);
+ }
+ let mut live = match open(&w) {
+ Ok(c) => c,
+ Err(e) => return eprintln!("skipped: {e}"),
+ };
+ w.take_changes();
+ picture(&mut live, 4);
+ let with = if tree { "with" } else { "without" };
+ let hidden = |c: &LiveCore, id: u32| {
+ let i = &c.sc.instances[c.sc.tables.retained.instance(id).expect("a mesh is an instance").instance as usize];
+ (i.hidden, i.masked)
+ };
+ assert_eq!((hidden(&live, 13), hidden(&live, 12)), ((true, true), (false, false)), "a mesh hidden at the build is an instance no ray sees");
+ let emitters = |c: &LiveCore, id: u32| {
+ let (t, r) = (&c.sc.tables, c.sc.tables.retained.instance(id).unwrap().instance);
+ t.emitter_tris.iter().filter(|e| e.inst == r && e.area > 0.0).map(|e| (crate::emitter_power(e, &t.materials, &t.objects, t.stride) > 0.0, e.moves)).collect::<Vec<_>>()
+ };
+ assert_eq!((emitters(&live, 13), emitters(&live, 12)), (vec![(false, true); 2], vec![(true, false); 2]), "its emitters weigh nothing, and are the moving subtree's when it is shown");
+ type Edit = (&'static str, Box<dyn Fn(&mut World)>);
+ let show = |id: u32, on: bool| -> Box<dyn Fn(&mut World)> { Box::new(move |w| w.set_visible(id, on).unwrap()) };
+ let edits: Vec<Edit> = vec![
+ ("a panel hidden", show(11, false)),
+ ("the panel shown", show(11, true)),
+ ("the lamp hidden", show(12, false)),
+ ("the lamp shown", show(12, true)),
+ ("a lamp hidden at the build shown", show(13, true)),
+ ("that lamp hidden again", show(13, false)),
+ ("a group of two hidden", show(14, false)),
+ ("the group shown", show(14, true)),
+ ("a movable mesh hidden", show(21, false)),
+ ("the movable mesh moved while hidden", Box::new(|w| w.set_transform(21, Vec3::new(-0.1, 0.2, 1.3), glam::Quat::from_rotation_z(0.4), Vec3::ONE).unwrap())),
+ ("the movable mesh shown where it moved to", show(21, true)),
+ ];
+ for (what, edit) in &edits {
+ let what = format!("{what}, {with} a light tree");
+ edit(&mut w);
+ let rebuilt = live.commit(&mut w).unwrap();
+ // (Software traversal may rebuild for a move: the picture holds either way.)
+ assert!(!rebuilt || (!live.g.hwrt && what.contains("moved")), "{what}: in place ({:?})", live.fallback);
+ if live.sc.tables.emitter_tris.iter().any(|e| e.area > 0.0) {
+ list_is_its_triangles(&what, &live);
+ }
+ // (Where each instance stands, hidden or not: its record's too.)
+ for id in [11, 12, 13, 15, 16, 21] {
+ let r = live.sc.tables.retained.instance(id).unwrap().instance as usize;
+ let (at, rec) = (w.world_matrix(id), live.sc.gpu_instances[r].m);
+ assert!(live.sc.instances[r].world.abs_diff_eq(at, 1e-5), "{what}: object {id}'s instance stands where the object does");
+ let rows = at.transpose().to_cols_array();
+ assert!(rec.iter().flatten().zip(&rows[..12]).all(|(a, b)| (a - b).abs() <= 1e-5), "{what}: object {id}'s record stands where the object does");
+ }
+ lit_as_a_build(&what, &mut live, &mut open(&w).unwrap());
+ }
+ assert_eq!((hidden(&live, 13), hidden(&live, 11), hidden(&live, 21)), ((true, true), (false, false), (false, false)), "{with} a light tree: as the world has them");
+ // Its geometry changed while it was hidden: the instance an edit took out is no longer its own to show.
+ if live.g.hwrt {
+ w.set_visible(22, false).unwrap();
+ assert!(!live.commit(&mut w).unwrap(), "a mesh the scene edits hidden, {with} a light tree: in place ({:?})", live.fallback);
+ let its = live.sc.instances[live.sc.tables.retained.instance(22).unwrap().instance as usize].mesh;
+ w.set_geometry(8, quad(0.35)).unwrap();
+ assert!(!live.commit(&mut w).unwrap(), "its geometry changed while hidden, {with} a light tree: in place ({:?})", live.fallback);
+ assert_eq!(hidden(&live, 22), (true, false), "taken out by the edit");
+ assert_eq!(live.sc.edit.users.get(&its).copied().unwrap_or(0), 0, "and its mesh has no user left");
+ w.set_visible(22, true).unwrap();
+ assert!(live.commit(&mut w).unwrap(), "shown after its geometry changed, {with} a light tree: a rebuild");
+ let what = format!("a mesh shown after its geometry changed while hidden, {with} a light tree");
+ lit_as_a_build(&what, &mut live, &mut open(&w).unwrap());
+ }
+ }
+}
+
+/// A still mesh's first move is its instance's, in place, and it moves in place from then on: one that emits (its
+/// emitters are moving ones from now on), a plain one, a group of two, and a lamp built without size that is given
+/// one. With and without a light tree. After each: no rebuild, the light list is its triangles, the picture is a
+/// build's.
+#[test]
+fn a_still_mesh_moves_in_place_from_its_first_move() {
+ let presets = crate::default_presets_dir();
+ let open = |w: &World| gpu::Gpu::new().and_then(|g| LiveCore::new(g, w, Path::new("."), &presets, 96, 54));
+ for tree in [false, true] {
+ let mut w = world();
+ let mesh = |geometry, material| Kind::Mesh { geometry, material, own_blas: false, materials: vec![] };
+ w.set_object(14, "group".into(), None, Kind::Group, true, false).unwrap();
+ for (id, at) in [(15, Vec3::new(0.5, -0.5, 0.6)), (16, Vec3::new(0.0, -0.6, 0.9))] {
+ w.set_object(id, format!("o{id}"), Some(14), mesh(3, 1), true, false).unwrap();
+ w.set_transform(id, at, glam::Quat::from_rotation_y(0.3), Vec3::ONE).unwrap();
+ }
+ // (A lamp built without size: an instance no ray sees, until it is given one.)
+ w.set_object(18, "seed".into(), None, mesh(3, 5), true, false).unwrap();
+ w.set_transform(18, Vec3::new(-0.7, -0.5, 1.1), glam::Quat::IDENTITY, Vec3::ZERO).unwrap();
+ if tree {
+ strip(&mut w);
+ }
+ let mut live = match open(&w) {
+ Ok(c) => c,
+ Err(e) => return eprintln!("skipped: {e}"),
+ };
+ w.take_changes();
+ picture(&mut live, 4);
+ let with = if tree { "with" } else { "without" };
+ let moves = |c: &LiveCore, id: u32| {
+ let i = c.sc.tables.retained.instance(id).expect("a mesh is an instance");
+ (i.moves, c.sc.tables.emitter_tris.iter().filter(|e| e.inst == i.instance && e.area > 0.0).map(|e| e.moves).collect::<Vec<_>>())
+ };
+ assert_eq!((moves(&live, 12), moves(&live, 11).0, moves(&live, 15).0), ((false, vec![false; 2]), false, false), "still meshes, as built");
+ let seed = &live.sc.instances[live.sc.tables.retained.instance(18).expect("a mesh without size is an instance").instance as usize];
+ assert!(seed.hidden && seed.masked && seed.world.determinant() != 0.0, "built without size: unseen, at a point");
+ type Edit = (&'static str, Box<dyn Fn(&mut World)>);
+ let to = |id: u32, at: [f32; 3], turn: f32| -> Box<dyn Fn(&mut World)> { Box::new(move |w| w.set_transform(id, Vec3::from(at), glam::Quat::from_rotation_z(turn), Vec3::ONE).unwrap()) };
+ let edits: Vec<Edit> = vec![
+ ("the still lamp moved", to(12, [0.3, 0.5, 1.3], 0.4)),
+ ("the lamp moved again", to(12, [-0.2, 0.4, 1.4], -0.2)),
+ ("a still panel moved", to(11, [-0.6, 0.2, 0.7], 0.3)),
+ ("a still group of two moved", to(14, [0.1, 0.15, 0.2], 0.2)),
+ ("the group moved again", to(14, [-0.1, 0.1, 0.1], 0.0)),
+ ("a lamp built without size given its size", to(18, [-0.7, -0.5, 1.1], 0.3)),
+ ];
+ for (what, edit) in &edits {
+ let what = format!("{what}, {with} a light tree");
+ edit(&mut w);
+ let builds = live.top_builds;
+ let rebuilt = live.commit(&mut w).unwrap();
+ // (Software traversal without units has no instance to move, and rebuilds: the picture holds either way.)
+ assert!(!(rebuilt && live.g.hwrt), "{what}: in place ({:?})", live.fallback);
+ assert_eq!(live.top_builds - builds, u32::from(!rebuilt), "{what}: one build above the triangles");
+ list_is_its_triangles(&what, &live);
+ forget(&mut live);
+ let (a, b) = (picture(&mut live, 64), picture(&mut open(&w).unwrap(), 64));
+ assert!(apart(&a, &b) < 0.5, "{what}: the picture is {:.2} steps from a build's", apart(&a, &b));
+ }
+ if live.g.hwrt {
+ assert_eq!((moves(&live, 12), moves(&live, 11).0, moves(&live, 15).0, moves(&live, 16).0), ((true, vec![true; 2]), true, true, true), "{with} a light tree: they move from now on");
+ }
+ }
+}
+
+/// Meshes the scene did not say it edits change in place as those it did: a geometry two of them use replaced (one
+/// emits), one re-created with another geometry, a movable one added and moved, a still one added and moved, the
+/// movable one hidden, moved and shown, one removed, a group of two removed.
+/// With and without a light tree. After each: no rebuild, the light list is its triangles, the weights and the picture
+/// are a build's. (Hardware traversal: its room for edits grows from nothing.)
+#[test]
+fn meshes_change_in_place_whether_or_not_the_scene_said_so() {
+ let presets = crate::default_presets_dir();
+ let open = |w: &World| gpu::Gpu::new().and_then(|g| LiveCore::new(g, w, Path::new("."), &presets, 96, 54));
+ let quad = |s: f32| Geometry { positions: vec![-s, -s, 0.0, s, -s, 0.0, s, s, 0.0, -s, s, 0.0], normals: [0.0, 0.0, 1.0].repeat(4), uvs: vec![0.0; 8], indices: vec![0, 1, 2, 0, 2, 3], groups: vec![], colors: vec![] };
+ for tree in [false, true] {
+ let mut w = world();
+ let mesh = |geometry, material| Kind::Mesh { geometry, material, own_blas: false, materials: vec![] };
+ w.set_object(14, "group".into(), None, Kind::Group, true, false).unwrap();
+ for (id, at) in [(15, Vec3::new(0.5, -0.5, 0.6)), (16, Vec3::new(0.0, -0.6, 0.9))] {
+ w.set_object(id, format!("o{id}"), Some(14), mesh(3, 1), true, false).unwrap();
+ w.set_transform(id, at, glam::Quat::from_rotation_y(0.3), Vec3::ONE).unwrap();
+ }
+ if tree {
+ strip(&mut w);
+ }
+ let mut live = match open(&w) {
+ Ok(c) if c.g.hwrt => c,
+ Ok(_) => return eprintln!("skipped: no hardware RT"),
+ Err(e) => return eprintln!("skipped: {e}"),
+ };
+ w.take_changes();
+ picture(&mut live, 4);
+ assert!(!live.sc.tables.retained.has_own_instances(), "the scene said of no mesh that it edits it");
+ type Edit = (&'static str, Box<dyn Fn(&mut World)>);
+ let edits: Vec<Edit> = vec![
+ ("a geometry two meshes use replaced", Box::new(move |w| w.set_geometry(3, quad(0.4)).unwrap())),
+ ("a mesh re-created with another geometry", Box::new(move |w| w.set_object(10, "wall".into(), None, mesh(3, 1), true, false).unwrap())),
+ (
+ "a movable mesh added",
+ Box::new(move |w| {
+ w.set_object(13, "mover".into(), None, mesh(3, 1), true, true).unwrap();
+ w.set_transform(13, Vec3::new(-0.7, 0.6, 0.8), glam::Quat::IDENTITY, Vec3::ONE).unwrap();
+ }),
+ ),
+ ("the added mesh moved", Box::new(|w| w.set_transform(13, Vec3::new(-0.3, 0.7, 1.0), glam::Quat::from_rotation_z(0.5), Vec3::ONE).unwrap())),
+ // (What an edit placed moves as what the build placed does: a still one from its first move, a hidden one
+ // while it is hidden.)
+ (
+ "a still mesh added",
+ Box::new(move |w| {
+ w.set_object(18, "still".into(), None, mesh(3, 1), true, false).unwrap();
+ w.set_transform(18, Vec3::new(0.7, 0.6, 0.6), glam::Quat::IDENTITY, Vec3::ONE).unwrap();
+ }),
+ ),
+ ("the still added mesh moved", Box::new(|w| w.set_transform(18, Vec3::new(0.6, 0.3, 0.9), glam::Quat::from_rotation_z(-0.3), Vec3::ONE).unwrap())),
+ ("the added movable mesh hidden", Box::new(|w| w.set_visible(13, false).unwrap())),
+ ("the added movable mesh moved while hidden", Box::new(|w| w.set_transform(13, Vec3::new(-0.6, 0.2, 1.2), glam::Quat::IDENTITY, Vec3::ONE).unwrap())),
+ ("the added movable mesh shown", Box::new(|w| w.set_visible(13, true).unwrap())),
+ (
+ "the lamp removed",
+ Box::new(|w| {
+ w.remove(12);
+ }),
+ ),
+ (
+ "a group of two meshes removed",
+ Box::new(|w| {
+ w.remove(14);
+ }),
+ ),
+ ];
+ for (what, edit) in &edits {
+ let what = format!("{what}, {} a light tree", if tree { "with" } else { "without" });
+ edit(&mut w);
+ assert!(!live.commit(&mut w).unwrap(), "{what}: in place ({:?})", live.fallback);
+ if live.sc.tables.emitter_tris.iter().any(|e| e.area > 0.0) {
+ list_is_its_triangles(&what, &live);
+ }
+ lit_as_a_build(&what, &mut live, &mut open(&w).unwrap());
+ }
+ }
+}
+
+/// A still model whose instance is all of it (tests/render/data/panel.glb: a grey quad and a quad that only emits) is
+/// hidden, shown, removed and moved in place as a mesh is. With and without a light tree. After each: no rebuild, the
+/// light list is its triangles, the picture is a build's (and the weights, until one has moved).
+#[test]
+fn a_still_model_is_hidden_removed_and_moved_in_place() {
+ let presets = crate::default_presets_dir();
+ let open_at_root = |w: &World| gpu::Gpu::new().and_then(|g| LiveCore::new(g, w, Path::new(".."), &presets, 96, 54));
+ let model = || Kind::Model { uri: "tests/render/data/panel.glb".into(), nodes: None, animation: None, functions: vec![] };
+ for tree in [false, true] {
+ let mut w = world();
+ // (The lamp away: the models' panels light the scene.)
+ w.set_visible(12, false).unwrap();
+ for (id, at) in [(30, Vec3::new(-0.6, -0.5, 0.6)), (31, Vec3::new(0.5, 0.4, 0.7)), (32, Vec3::new(0.0, 0.6, 0.5))] {
+ w.set_object(id, format!("m{id}"), None, model(), true, false).unwrap();
+ w.set_transform(id, at, glam::Quat::from_rotation_y(0.4), Vec3::splat(0.05)).unwrap();
+ }
+ if tree {
+ strip(&mut w);
+ }
+ let mut live = match open_at_root(&w) {
+ Ok(c) => c,
+ Err(e) => return eprintln!("skipped: {e}"),
+ };
+ w.take_changes();
+ picture(&mut live, 4);
+ let with = if tree { "with" } else { "without" };
+ if live.g.hwrt {
+ assert!(matches!(&live.sc.tables.retained.proxies[&30].draw, scene::Draw::Instance(i) if !i.moves && matches!(i.mesh, scene::MeshKind::Model)), "a still model's proxy has its instance");
+ }
+ type Edit = (&'static str, bool, Box<dyn Fn(&mut World)>);
+ let edits: Vec<Edit> = vec![
+ ("a still model hidden", true, Box::new(|w| w.set_visible(30, false).unwrap())),
+ ("the model shown", true, Box::new(|w| w.set_visible(30, true).unwrap())),
+ (
+ "a still model removed",
+ true,
+ Box::new(|w| {
+ w.remove(32);
+ }),
+ ),
+ ("a still model moved", false, Box::new(|w| w.set_transform(31, Vec3::new(0.3, 0.2, 1.0), glam::Quat::from_rotation_y(-0.3), Vec3::splat(0.05)).unwrap())),
+ ("the model moved again", false, Box::new(|w| w.set_transform(31, Vec3::new(0.1, 0.3, 1.1), glam::Quat::from_rotation_z(0.3), Vec3::splat(0.05)).unwrap())),
+ ];
+ for (what, weights, edit) in &edits {
+ let what = format!("{what}, {with} a light tree");
+ edit(&mut w);
+ let rebuilt = live.commit(&mut w).unwrap();
+ assert!(!(rebuilt && live.g.hwrt), "{what}: in place ({:?})", live.fallback);
+ list_is_its_triangles(&what, &live);
+ let mut fresh = open_at_root(&w).unwrap();
+ if *weights {
+ lit_as_a_build(&what, &mut live, &mut fresh);
+ } else {
+ // (A moving emitter's centre is not kept on the CPU: the picture alone.)
+ forget(&mut live);
+ let (a, b) = (picture(&mut live, 64), picture(&mut fresh, 64));
+ assert!(apart(&a, &b) < 0.5, "{what}: the picture is {:.2} steps from a build's", apart(&a, &b));
+ }
+ }
+ }
+}
diff --git a/renderer/src/live/mod.rs b/renderer/src/live/mod.rs
index 69911e1..a3eeb00 100644
--- a/renderer/src/live/mod.rs
+++ b/renderer/src/live/mod.rs
@@ -339,6 +339,10 @@ pub struct LiveCore {
/// An instanced object's emitting copies changed size or were shown or hidden in this commit: the emitters are
/// weighed again once at its end.
emitters_reweigh: bool,
+ /// Emitters made in place this commit, for `write_emitters` (`start_moving`: a still mesh's, moving from now on).
+ pending_emitters: Vec<(u32, crate::GpuEmitterTri)>,
+ /// Objects whose instance a move hid or brought back this commit (a placement without size): their rows' power.
+ flipped: Vec<u32>,
/// Likewise for the deforming meshes of shared poses (`repose_groups`): the span they took (relative to the dynamic
/// tail, past its end) and whether this frame re-skinned any.
pose_span: Option<(usize, usize)>,
@@ -538,7 +542,7 @@ impl LiveCore {
// brings it, `gpu::loop_guard_of`.)
let guard_read = (gpu::loop_guard_of(!g.hwrt).is_some() && targets.kernel.guard.is_some())
.then(|| (g.device.create_buffer(&wgpu::BufferDescriptor { label: Some("loop guard read"), size: 4, usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false }), Arc::new(AtomicU32::new(0))));
- let mut core = LiveCore { top_builds: 0, particle_spawns: Default::default(), grid_sources: Default::default(), g, passes, targets, sc, view, env, presets: presets.to_path_buf(), assets: assets.to_path_buf(), w, h, seq: 0, aspect: w as f32 / h as f32, cam, prev_cam: cam, frame: 0, history_len: 0.0, reset: true, bloom: ([0.0; 6], [0.0; 6]), vignette: 0.0, post: [0.0; 4], blur: (0.0, 0.0), inflight: Default::default(), gpu_ms: 0.0, gpu_frame: 0, gpu_trace_ms: 0.0, edit_ms: 0.0, instanced_ms: 0.0, build_ms: 0.0, edit_split: EditSplit::default(), rebuild_ms: 0.0, fallback: None, fallbacks: 0, bounces: 4, rays: true, view_mode: std::env::var("THREERT_VIEW_MODE").ok().and_then(|v| v.parse().ok()).unwrap_or(0), fixed_dt: None, motion_blur_off: false, triangles, scene_name, time: 0.0, frame_dt: 1.0 / 60.0, last_frame: Instant::now(), post_key: String::new(), render_scale: 1.0, dynamic_res: false, min_scale: MIN_SCALE, display_scale: 1.0, over_budget: (0, 0), born: Instant::now(), governed: Instant::now(), profile, timer, raster, cache, kernel_bg, tl_kernel_bg, prev_span: None, reposed: false, emitters_moved: false, emitters_reweigh: false, pose_span: None, pose_reposed: false, inst_moving: vec![], inst_moved: false, prev_isz: (0, 0), light_tiles: None, lit_changed: 0, spark_lights: false, shown_spp: 1, cpu_skin_ms: 0.0, cpu_upload_ms: 0.0, gpu_blas_ms: 0.0, cpu_wait_ms: 0.0, guard_trips: guard_read.as_ref().map(|_| 0), guard_read };
+ let mut core = LiveCore { pending_emitters: vec![], flipped: vec![], top_builds: 0, particle_spawns: Default::default(), grid_sources: Default::default(), g, passes, targets, sc, view, env, presets: presets.to_path_buf(), assets: assets.to_path_buf(), w, h, seq: 0, aspect: w as f32 / h as f32, cam, prev_cam: cam, frame: 0, history_len: 0.0, reset: true, bloom: ([0.0; 6], [0.0; 6]), vignette: 0.0, post: [0.0; 4], blur: (0.0, 0.0), inflight: Default::default(), gpu_ms: 0.0, gpu_frame: 0, gpu_trace_ms: 0.0, edit_ms: 0.0, instanced_ms: 0.0, build_ms: 0.0, edit_split: EditSplit::default(), rebuild_ms: 0.0, fallback: None, fallbacks: 0, bounces: 4, rays: true, view_mode: std::env::var("THREERT_VIEW_MODE").ok().and_then(|v| v.parse().ok()).unwrap_or(0), fixed_dt: None, motion_blur_off: false, triangles, scene_name, time: 0.0, frame_dt: 1.0 / 60.0, last_frame: Instant::now(), post_key: String::new(), render_scale: 1.0, dynamic_res: false, min_scale: MIN_SCALE, display_scale: 1.0, over_budget: (0, 0), born: Instant::now(), governed: Instant::now(), profile, timer, raster, cache, kernel_bg, tl_kernel_bg, prev_span: None, reposed: false, emitters_moved: false, emitters_reweigh: false, pose_span: None, pose_reposed: false, inst_moving: vec![], inst_moved: false, prev_isz: (0, 0), light_tiles: None, lit_changed: 0, spark_lights: false, shown_spp: 1, cpu_skin_ms: 0.0, cpu_upload_ms: 0.0, gpu_blas_ms: 0.0, cpu_wait_ms: 0.0, guard_trips: guard_read.as_ref().map(|_| 0), guard_read };
core.spark_lights = core.sc.tables.emitter_tris.iter().any(|e| e.nominal);
core.apply_post();
Ok(core)
diff --git a/renderer/src/scene.rs b/renderer/src/scene.rs
index 57bfb2b..a93117a 100644
--- a/renderer/src/scene.rs
+++ b/renderer/src/scene.rs
@@ -131,6 +131,10 @@ pub struct Instance {
/// hidden (`instance_world`: TLAS mask 0, never flattened or picked).
pub sub: Option<u32>,
pub hidden: bool,
+ /// Hidden by its object's visibility (`World::shown`) or for a placement without size (`placed_world`), which
+ /// keep its mesh and its place above the triangles: it comes back in place. (One that an edit took out is hidden
+ /// and not this: a rebuild draws it again.)
+ pub masked: bool,
/// Its first emitter in the light list, if its mesh has emitters (`InstMesh::emitters`): set where the list is
/// made (lib.rs `prepare`, the live edits); the record carries it (n2.w), for the rays that hit an emitter of it.
pub first_emitter: u32,
@@ -1409,11 +1413,13 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se
let shown = w.shown(*id);
let flags = if n.cast_shadow { 0 } else { TRI_NO_SHADOW };
match &n.kind {
- Kind::Mesh { geometry, material, own_blas, materials: mesh_mats } if shown && instancing && m.determinant() != 0.0 => {
+ Kind::Mesh { geometry, material, own_blas, materials: mesh_mats } if instancing => {
// A mesh is an instance of its geometry's mesh: the triangles in model space in the pool, one BLAS,
// shared by the objects of the same geometry and materials, whatever those are (`mesh_class`: a
// cutout or glass is a part of the mesh; one that emits has each instance's emitters in the light
- // list, `InstMesh::emitters`). A move is the instance's transform (`InstanceRef::moves`).
+ // list, `InstMesh::emitters`). A move is the instance's transform (`InstanceRef::moves`). One that is
+ // hidden (`World::shown`), or placed without size (`placed_world`), is an instance too, which no ray
+ // sees and whose row has no power: it comes back in place (`Instance::masked`).
let g = w.geometries.get(geometry).ok_or_else(|| anyhow!("object {}: unknown geometry {geometry}", n.name))?;
let mat = *retained.materials.get(material).ok_or_else(|| anyhow!("object {}: unknown material {material}", n.name))?;
// Several materials: each geometry group's triangles with its own (three.js's material array).
@@ -1444,14 +1450,16 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se
}
};
if let Some(mesh) = mesh {
+ let (m, gone) = placed_world(m, Vec3::ZERO);
+ let unseen = !shown || gone;
let (lo, hi) = meshes[mesh as usize].placed_bounds(m);
let pivot = m.transform_point3(Vec3::ZERO);
let size = hi - lo;
let oi = (objects.len() / stride) as u32;
- objects.extend_from_slice(&object_row(pivot, n.power, size, n.custom, [1.0; 3])[..stride]);
+ objects.extend_from_slice(&object_row(pivot, if unseen { 0.0 } else { n.power }, size, n.custom, [1.0; 3])[..stride]);
retained.edits_meshes |= *own_blas || n.driven;
*retained.proxy(*id) = Proxy { object: Some(oi), card: None, draw: Draw::Instance(InstanceRef { instance: instances.len() as u32, mesh: MeshKind::Own, moves: n.driven || w.movable(*id) }) };
- instances.push(Instance { mesh, world: m, object: oi, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, first_emitter: 0 });
+ instances.push(Instance { mesh, world: m, object: oi, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: unseen, masked: unseen, first_emitter: 0 });
}
}
Kind::Instanced { geometry, procedural, materials: mats, capacity } if shown => {
@@ -1509,7 +1517,7 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se
for (i, &(wm, hidden)) in placed.iter().enumerate() {
let (lo, hi) = meshes[mesh as usize].placed_bounds(wm);
objects.extend_from_slice(&copy_row(entry(i, wm, Vec3::from(hi - lo)), emits && hidden)[..stride]);
- instances.push(Instance { mesh, world: wm, object: object + i as u32, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: Some(i as u32), hidden, first_emitter: 0 });
+ instances.push(Instance { mesh, world: wm, object: object + i as u32, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: Some(i as u32), hidden, masked: false, first_emitter: 0 });
}
}
continue;
@@ -1663,7 +1671,7 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se
let count = classed[..FLAT].iter().map(Vec::len).sum::<usize>() as u32;
meshes.push(InstMesh { first: first_pool, count, opaque: classed[0].len() as u32, glass: classed[2].len() as u32, rest_first: 0, rest_count: 0, lo, hi, deforms: false, emitters });
rigid.instances.push((*ni, instances.len() as u32));
- instances.push(Instance { mesh: meshes.len() as u32 - 1, world: w_n, object: oi, cast_shadow: meshes[meshes.len() - 1].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, first_emitter: 0 });
+ instances.push(Instance { mesh: meshes.len() as u32 - 1, world: w_n, object: oi, cast_shadow: meshes[meshes.len() - 1].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, masked: false, first_emitter: 0 });
}
for &(k, mat) in &classed[FLAT] {
let t = &local[k].1;
@@ -1745,7 +1753,7 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se
let oi = (objects.len() / stride) as u32;
objects.extend_from_slice(&object_row(pivot, n.power, size, n.custom, [1.0; 3])[..stride]);
let i = instances.len() as u32;
- instances.push(Instance { mesh, world: m, object: oi, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, first_emitter: 0 });
+ instances.push(Instance { mesh, world: m, object: oi, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, masked: false, first_emitter: 0 });
*retained.proxy(*id) = Proxy { object: Some(oi), card: None, draw: Draw::Instance(InstanceRef { instance: i, mesh: MeshKind::Pose(g), moves: true }) };
retained.pose_groups[g as usize].members.push((*id, i));
continue;
@@ -1813,7 +1821,7 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se
let oi = (objects.len() / stride) as u32;
objects.extend_from_slice(&object_row(pivot, n.power, size, n.custom, [1.0; 3])[..stride]);
retained.proxy(*id).object = Some(oi);
- let inst = Instance { mesh, world: m, object: oi, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, first_emitter: 0 };
+ let inst = Instance { mesh, world: m, object: oi, cast_shadow: meshes[mesh as usize].casts(n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, masked: false, first_emitter: 0 };
// Its glass / function triangles as ordinary world-space ones (same object).
for k in im.rest_first..im.rest_first + im.rest_count {
let (t, a, _) = inst.flat(&rest_tris[k as usize], &rest_attrs[k as usize], None);
@@ -1824,9 +1832,10 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se
if tris.len() as u32 > first {
tri_nodes.push((n.name.clone(), first, tris.len() as u32));
}
- // (A model that does not move keeps no instance of its own here: `Draw::Fixed`.)
- if movable {
- retained.proxy(*id).draw = Draw::Instance(InstanceRef { instance: instances.len() as u32, mesh: MeshKind::Model, moves: true });
+ // (Its proxy has the instance where the instance is all of it: one with triangles flattened at
+ // its placement beside is the build's to change, `Draw::Fixed`.)
+ if im.rest_count == 0 {
+ retained.proxy(*id).draw = Draw::Instance(InstanceRef { instance: instances.len() as u32, mesh: MeshKind::Model, moves: movable });
}
instances.push(inst);
continue;
@@ -2564,7 +2573,7 @@ mod instance_tests {
let local = tri_attr(p, n, uv, None, 7);
for (w, mirrored) in [(keeps, false), (keeps * Mat4::from_scale(Vec3::new(-1.0, 1.0, 1.0)), true)] {
assert_eq!(mirrors(w), mirrored);
- let inst = Instance { mesh: 0, world: w, object: 3, cast_shadow: true, name: "x".into(), sub: None, hidden: false, first_emitter: 0 };
+ let inst = Instance { mesh: 0, world: w, object: 3, cast_shadow: true, name: "x".into(), sub: None, hidden: false, masked: false, first_emitter: 0 };
assert_eq!(inst.gpu(0, [0, 0]).n[1][3].to_bits(), if mirrored { INST_MIRRORED } else { 0 }, "the record says whether it mirrors");
let (placed, got, got_colors) = inst.flat(&[p[0].into(), p[1].into(), p[2].into()], &local, Some(colors));
// The world-space triangle: its vertices in the order the build flattens a placement in.
@@ -2599,7 +2608,7 @@ mod instance_tests {
let mats = [opaque, cutout];
let p = [Vec3::ZERO, Vec3::X, Vec3::Y];
let a = |m: u32| tri_attr(p, [Vec3::Z; 3], [Vec2::ZERO, Vec2::X, Vec2::Y], None, m);
- let inst = |shadow: bool| Instance { mesh: 0, world: Mat4::IDENTITY, object: 0, cast_shadow: shadow, name: "x".into(), sub: None, hidden: false, first_emitter: 0 };
+ let inst = |shadow: bool| Instance { mesh: 0, world: Mat4::IDENTITY, object: 0, cast_shadow: shadow, name: "x".into(), sub: None, hidden: false, masked: false, first_emitter: 0 };
assert_eq!(instance_tri_flags(&inst(true), &a(0), &mats), 0);
assert_eq!(instance_tri_flags(&inst(true), &a(1), &mats), TRI_MASKED);
assert_eq!(instance_tri_flags(&inst(false), &a(1), &mats), TRI_MASKED | TRI_NO_SHADOW);
diff --git a/renderer/src/tables.rs b/renderer/src/tables.rs
index caa9c4a..2c1c86f 100644
--- a/renderer/src/tables.rs
+++ b/renderer/src/tables.rs
@@ -110,12 +110,16 @@ impl Tables {
let o = w.objects.get(id).ok_or_else(|| anyhow!("unknown object {id}"))?;
if let Some(oi) = self.retained.object(*id) {
let row = oi as usize * self.stride;
+ // (The row of a mesh or a model that is hidden, or placed without size, has no power: its instance's emitters at
+ // no weight until it comes back.)
+ let unseen = matches!(o.kind, Kind::Mesh { .. } | Kind::Model { .. }) && (!w.shown(*id) || scene::placed_world(w.world_matrix(*id), glam::Vec3::ZERO).1);
+ let power = if unseen { 0.0 } else { o.power.max(0.0) };
if self.defer_powers {
self.deferred.retain(|p| p.0 != row);
- self.deferred.push((row, o.power.max(0.0), now));
+ self.deferred.push((row, power, now));
d.deferred = true;
} else {
- self.put_powers(&[(row, o.power.max(0.0), now)]);
+ self.put_powers(&[(row, power, now)]);
d.objects = true;
d.emitters = true;
}
diff --git a/renderer/src/units.rs b/renderer/src/units.rs
index 46221df..b53e97c 100644
--- a/renderer/src/units.rs
+++ b/renderer/src/units.rs
@@ -1339,7 +1339,7 @@ mod tests {
fn record(&self, mesh: usize, world: Mat4, cast: bool) -> GpuInstance {
let (first, _, root, ..) = self.meshes[mesh].unwrap();
- let inst = crate::scene::Instance { mesh: mesh as u32, world, object: 0, cast_shadow: cast, name: String::new(), sub: None, hidden: false, first_emitter: 0 };
+ let inst = crate::scene::Instance { mesh: mesh as u32, world, object: 0, cast_shadow: cast, name: String::new(), sub: None, hidden: false, masked: false, first_emitter: 0 };
unit_record(inst.gpu(first, [0, 0]), root, cast)
}
@@ -1953,7 +1953,7 @@ mod tests {
// A built tree is a level short of the bound: two of them joined are at it.
assert!(check_tree(&build_sah(&(0..1 << 12).map(|k| (Vec3A::splat(k as f32), Vec3A::splat(k as f32 + 1.0))).collect::<Vec<_>>(), 12).0, 64, |_, _| Ok(())).unwrap() <= 12);
// The record's word for a placement by a translation alone.
- let rec = |world: Mat4| unit_record(crate::scene::Instance { mesh: 0, world, object: 0, cast_shadow: true, name: String::new(), sub: None, hidden: false, first_emitter: 0 }.gpu(0, [0, 0]), 9, true);
+ let rec = |world: Mat4| unit_record(crate::scene::Instance { mesh: 0, world, object: 0, cast_shadow: true, name: String::new(), sub: None, hidden: false, masked: false, first_emitter: 0 }.gpu(0, [0, 0]), 9, true);
let shifted = |m: Mat4| rec(m).n[1][3].to_bits() & UNIT_SHIFTED != 0;
assert!(shifted(Mat4::IDENTITY));
assert!(shifted(Mat4::from_translation(Vec3::new(3.0, -2.0, 0.5))));
diff --git a/renderer/src/units_cost.rs b/renderer/src/units_cost.rs
index 8ad86d0..b222162 100644
--- a/renderer/src/units_cost.rs
+++ b/renderer/src/units_cost.rs
@@ -409,7 +409,7 @@ fn units_pile() {
let made = (u.kept.builds - was.0, u.kept.changes - was.1, u.kept.refits - was.2);
// At rest: the kernel's buffers as a session would have written them.
for (j, p) in pieces.iter().enumerate() {
- let inst = scene::Instance { mesh, world: pose(p, 1.0), object: 0, cast_shadow: true, name: String::new(), sub: None, hidden: false, first_emitter: 0 };
+ let inst = scene::Instance { mesh, world: pose(p, 1.0), object: 0, cast_shadow: true, name: String::new(), sub: None, hidden: false, masked: false, first_emitter: 0 };
l.instances[first_rec + j] = units::unit_record(inst.gpu(first_tri, [tris.len() as u32, 0]), root as u32, true);
}
let at = u.layout.top_first as usize;
diff --git a/renderer/src/world.rs b/renderer/src/world.rs
index 272c5b4..d972a0a 100644
--- a/renderer/src/world.rs
+++ b/renderer/src/world.rs
@@ -308,10 +308,9 @@ pub struct Changes {
pub moved: HashSet<u32>,
/// Objects made movable by their first move (that move rebuilds once).
pub promoted: Vec<String>,
- /// Meshes given their own BLAS (`own_blas`) by their geometry's first change, updated or replaced, without scene
- /// code's `dynamicGeometry` (three.js code changes geometry without telling): that change rebuilds once, the next
- /// apply in place. Frame log `fallback: promote`.
- pub promoted_geometry: Vec<String>,
+ /// Still meshes, or groups, that moved for the first time (and are movable from now on): the renderer moves their
+ /// instances in place where it can (live/edits.rs `start_moving`), and rebuilds where it cannot.
+ pub started: HashSet<u32>,
/// Objects created (or re-created) in this batch: the rebuild builds them where they are, so setting their
/// transform is not a move.
pub created: HashSet<u32>,
@@ -343,9 +342,10 @@ impl Changes {
}
}
-/// An object kind whose geometry lives in its own BLAS (one TLAS instance per object): its edits apply in place.
-pub fn own_blas(k: &Kind) -> bool {
- matches!(k, Kind::Procedural { .. } | Kind::Mesh { own_blas: true, .. })
+/// An object kind that is an instance of its geometry (one TLAS instance per object): its edits apply in place.
+/// (`Kind::Mesh::own_blas`, scene code's `dynamicGeometry`, says that the scene edits it: the build keeps room for that.)
+pub fn edits_in_place(k: &Kind) -> bool {
+ matches!(k, Kind::Procedural { .. } | Kind::Mesh { .. })
}
#[derive(Clone)]
@@ -462,21 +462,10 @@ impl World {
if g.positions.iter().any(|v| !v.is_finite()) {
return Err(anyhow!("geometry {id}: a position is not finite"));
}
- // A geometry only meshes with their own BLAS use is replaced in place; one a flattened mesh uses rebuilds. A new
- // id no object uses yet: nothing to look for (the scan over every object cost ~40 µs a geometry at 10 k objects).
+ // A geometry meshes use is replaced in place (their instances' mesh: live/edits.rs `edit_geometry`); one an
+ // instanced object uses rebuilds. A new id no object uses yet: nothing to look for (the scan over every object
+ // cost ~40 µs a geometry at 10 k objects).
let new = self.geometries.insert(id, Arc::new(g)).is_none();
- if !new {
- // Flattened meshes of a geometry that changes: promoted to their own BLAS (once; this change rebuilds).
- for o in self.objects.values_mut() {
- if let Kind::Mesh { geometry, own_blas: own @ false, .. } = &mut o.kind {
- if *geometry == id {
- *own = true;
- self.changes.structural = true;
- self.changes.promoted_geometry.push(o.name.clone());
- }
- }
- }
- }
if !self.changes.structural {
if !new && self.objects.values().any(|o| matches!(o.kind, Kind::Instanced { geometry, procedural: false, .. } if geometry == id)) {
self.changes.structural = true;
@@ -548,30 +537,26 @@ impl World {
return Err(anyhow!("object {name}: a volume's majorant must be a finite number > 0 (1/m), not {majorant}"));
}
}
- // A mesh given another geometry: promoted to its own BLAS if it was not (this swap rebuilds once, the next apply
- // in place); a promotion stays.
+ // A mesh given another geometry is one the scene edits from now on (the build keeps room for that); it stays so.
if let (Some(Kind::Mesh { geometry: old, own_blas: was, .. }), Kind::Mesh { geometry, own_blas, .. }) = (self.objects.get(&id).map(|o| &o.kind), &mut kind) {
- if *was && !*own_blas {
+ if *was || (*old != *geometry && !self.changes.created.contains(&id)) {
*own_blas = true;
- } else if !*own_blas && *old != *geometry && !self.changes.created.contains(&id) {
- *own_blas = true;
- self.changes.promoted_geometry.push(name.clone());
}
}
- // An object with its own BLAS and no movable ancestor is built in place: a new one, or one re-created with the
- // same kind of object, parent and shadow flag (scene code swapping its geometry or materials). Anything else
- // rebuilds.
+ // A mesh is placed in place: a new one, or one re-created with the same kind of object, parent and shadow flag
+ // (scene code swapping its geometry or materials). So is procedural geometry with no movable ancestor. Anything
+ // else rebuilds.
// (Movable as the build sees it: the object or any ancestor, `movable`.)
let static_parent = parent.is_none_or(|p| !self.objects.contains_key(&p) || !self.movable(p));
+ let mesh = matches!(kind, Kind::Mesh { .. });
// A new instanced mesh or static model is placed in place too (ROADMAP § 6 step 5; live/edits.rs `edit_geometry`
// says when it cannot); changing one still rebuilds.
let placed_new = !self.objects.contains_key(&id) && matches!(kind, Kind::Instanced { procedural: false, .. } | Kind::Model { animation: None, .. });
- let fresh = (own_blas(&kind) || placed_new)
- && !movable
- && static_parent
+ let fresh = (edits_in_place(&kind) || placed_new)
+ && (mesh || (!movable && static_parent))
&& match self.objects.get(&id) {
None => true,
- Some(o) => !self.movable(id) && o.parent == parent && o.cast_shadow == cast_shadow && std::mem::discriminant(&o.kind) == std::mem::discriminant(&kind) && own_blas(&o.kind),
+ Some(o) => (mesh || !self.movable(id)) && o.parent == parent && o.cast_shadow == cast_shadow && std::mem::discriminant(&o.kind) == std::mem::discriminant(&kind) && edits_in_place(&o.kind),
};
match &kind {
Kind::Instanced { capacity, .. } => {
@@ -711,12 +696,21 @@ impl World {
// The atmosphere's sun (time of day): its light rewritten and the sky re-baked in place (live/edits.rs `move_sun`).
self.changes.sun = true;
} else {
- // Fixed geometry moved: from now on it is movable. This move rebuilds once, to set its triangles apart.
- self.changes.structural = true;
+ // Fixed geometry moved: from now on it is movable. A mesh, a still model, or a group, is its instances' to move
+ // (`Changes::started`); anything else rebuilds once, to set its triangles apart.
+ let held = matches!(o.kind, Kind::Mesh { .. } | Kind::Model { animation: None, .. } | Kind::Group) && !sun && !is_camera && !self.changes.created.contains(&id);
if !sun && !is_camera && !self.changes.created.contains(&id) {
let o = self.objects.get_mut(&id).unwrap();
o.movable = true;
- self.changes.promoted.push(o.name.clone());
+ if !held {
+ self.changes.promoted.push(o.name.clone());
+ }
+ }
+ if held {
+ self.changes.moved.insert(id);
+ self.changes.started.insert(id);
+ } else {
+ self.changes.structural = true;
}
}
}
@@ -784,13 +778,16 @@ impl World {
let o = self.objects.get_mut(&id).ok_or_else(|| anyhow!("unknown object {id}"))?;
if o.visible != visible {
o.visible = visible;
- // In place: what keeps its slot in the build while hidden (`hidden_built`), and lights, which always
- // have theirs (not a rect light's card, which is geometry, nor the sun, whose colour is the sky bake's).
+ // In place: what keeps its slot in the build while hidden (`hidden_built`; a mesh, as a hidden instance),
+ // and lights, which always have theirs (not a rect light's card, which is geometry, nor the sun, whose
+ // colour is the sky bake's).
let sun = matches!(self.environment.sky, desc::Sky::Atmosphere { sun: Some(s), .. } if s == id);
let o = &self.objects[&id];
let in_place = match &o.kind {
Kind::Particles { emitter_area, .. } => *emitter_area <= 0.0,
Kind::Volume { .. } => true,
+ // (A mesh's or a still model's instance by its mask, a group's each: the renderer says whether it can.)
+ Kind::Mesh { .. } | Kind::Model { animation: None, .. } | Kind::Group => true,
Kind::Light(l) => !sun && !matches!(l, desc::Light::Rect { visible: true, .. }),
_ => false,
};
@@ -953,17 +950,18 @@ impl World {
doomed.extend(self.objects.iter().filter(|(_, o)| o.parent == Some(p)).map(|(i, _)| *i));
k += 1;
}
- // A lone object with its own BLAS, an instanced mesh or a static model is removed in place (or never added, if it
- // came in this batch; live/edits.rs `edit_geometry` rebuilds for what it cannot take out).
- if let [only] = doomed[..] {
- if self.objects.get(&only).is_some_and(|o| own_blas(&o.kind) || matches!(o.kind, Kind::Instanced { procedural: false, .. } | Kind::Model { animation: None, .. })) {
- self.instanced.remove(&only);
- self.objects.remove(&only);
- if !self.changes.added.remove(&only) {
- self.changes.removed.insert(only);
+ // A mesh, procedural geometry, or a group of those, is removed in place, and so is a lone instanced mesh or static
+ // model (or never added, if it came in this batch; live/edits.rs `edit_geometry` rebuilds for what it cannot
+ // take out).
+ let alone = |o: &Object| doomed.len() == 1 && matches!(o.kind, Kind::Instanced { procedural: false, .. } | Kind::Model { animation: None, .. });
+ if doomed.iter().all(|d| self.objects.get(d).is_some_and(|o| edits_in_place(&o.kind) || alone(o) || (doomed.len() > 1 && matches!(o.kind, Kind::Group)))) {
+ for d in &doomed {
+ self.instanced.remove(d);
+ if self.objects.remove(d).is_some_and(|o| !matches!(o.kind, Kind::Group)) && !self.changes.added.remove(d) {
+ self.changes.removed.insert(*d);
}
- return doomed;
}
+ return doomed;
}
for &d in &doomed {
self.instanced.remove(&d);
@@ -1330,10 +1328,12 @@ mod tests {
}
w.set_visible(1, false).unwrap();
assert!(w.hidden_built(1) && !w.hidden_built(2), "a hidden volume keeps its place in the build; a light always has one");
- for id in [3, 5] {
- w.set_visible(id, false).unwrap();
- assert!(w.take_changes().structural, "{id}: a rect light's card and a group are geometry");
- }
+ w.set_visible(3, false).unwrap();
+ assert!(w.take_changes().structural, "a rect light's card is geometry");
+ // (A group, as a mesh: the renderer hides its meshes' instances, or says it cannot.)
+ w.set_visible(5, false).unwrap();
+ let c = w.take_changes();
+ assert!(!c.structural && c.shown.contains(&5), "a group: for the renderer to hide in place");
let inner = Kind::Volume { function: "f".into(), params: vec![], shape: 0, majorant: 1.0, g: 0.0, homogeneous: false, animated: false, grid: None };
w.set_object(6, "inner".into(), Some(5), inner, false, false).unwrap();
w.set_visible(6, false).unwrap();
@@ -1435,26 +1435,24 @@ mod tests {
w.set_proc_geometry(3, "f".into(), vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0], vec![]).unwrap();
w.set_object(3, "proc".into(), None, Kind::Procedural { geometry: 3, materials: vec![1] }, true, false).unwrap();
assert!(w.take_changes().structural, "the first commit builds the scene");
- // Replacing geometry: in place for objects with their own BLAS, a rebuild for a flattened mesh's.
+ // Replacing geometry: in place, whether or not the scene said it edits the mesh.
w.set_geometry(1, tri()).unwrap();
w.set_proc_geometry(3, "f".into(), vec![0.0, 0.0, 0.0, 2.0, 2.0, 2.0], vec![]).unwrap();
let c = w.take_changes();
assert!(!c.structural && c.geometries.contains(&1) && c.geometries.contains(&3) && c.edits());
w.set_geometry(2, tri()).unwrap();
let c = w.take_changes();
- assert!(c.structural && c.promoted_geometry == ["flat"], "a flattened mesh's geometry: promoted to its own BLAS, once");
- assert!(matches!(w.objects[&2].kind, Kind::Mesh { own_blas: true, .. }));
- w.set_geometry(2, tri()).unwrap();
- assert!(!w.take_changes().structural, "promoted: in place");
- // A flattened mesh given another geometry: promoted (that swap rebuilds once); the promotion stays.
+ assert!(!c.structural && c.geometries.contains(&2), "a mesh's geometry the scene did not say it edits: in place too");
+ // A mesh given another geometry is one the scene edits from now on (the build keeps room for that), and stays so.
w.set_object(12, "lod".into(), None, Kind::Mesh { geometry: 1, material: 1, own_blas: false, materials: vec![] }, true, false).unwrap();
- w.take_changes();
+ let c = w.take_changes();
+ assert!(!c.structural && c.added.contains(&12) && matches!(w.objects[&12].kind, Kind::Mesh { own_blas: false, .. }), "a new mesh: placed in place");
w.set_object(12, "lod".into(), None, Kind::Mesh { geometry: 2, material: 1, own_blas: false, materials: vec![] }, true, false).unwrap();
let c = w.take_changes();
- assert!(c.structural && c.promoted_geometry == ["lod"] && matches!(w.objects[&12].kind, Kind::Mesh { own_blas: true, .. }));
+ assert!(!c.structural && c.added.contains(&12) && matches!(w.objects[&12].kind, Kind::Mesh { own_blas: true, .. }));
w.set_object(12, "lod".into(), None, Kind::Mesh { geometry: 1, material: 1, own_blas: false, materials: vec![] }, true, false).unwrap();
let c = w.take_changes();
- assert!(!c.structural && c.added.contains(&12) && matches!(w.objects[&12].kind, Kind::Mesh { own_blas: true, .. }), "promoted: in place");
+ assert!(!c.structural && c.added.contains(&12) && matches!(w.objects[&12].kind, Kind::Mesh { own_blas: true, .. }), "it stays one the scene edits");
w.remove(12);
w.take_changes();
// Added (placed where it is: its transform is not a move), re-created with other geometry, removed.
@@ -1469,19 +1467,33 @@ mod tests {
w.set_object(5, "brief".into(), None, Kind::Procedural { geometry: 3, materials: vec![1] }, true, false).unwrap();
w.remove(5);
assert!(!w.take_changes().any());
- // Not in place: a movable one, another kind, a flattened mesh removed, an object with children.
+ // Not in place: movable procedural geometry, another kind.
w.set_object(6, "mover".into(), None, Kind::Procedural { geometry: 3, materials: vec![1] }, true, true).unwrap();
assert!(w.take_changes().structural, "movable");
w.set_object(1, "own".into(), None, Kind::Procedural { geometry: 3, materials: vec![1] }, true, false).unwrap();
assert!(w.take_changes().structural, "another kind");
+ // In place: a movable mesh added (its instance moves), any mesh removed, an object with children that are
+ // meshes, procedural geometry or groups.
+ w.set_object(13, "moving".into(), None, Kind::Mesh { geometry: 1, material: 1, own_blas: false, materials: vec![] }, true, true).unwrap();
+ let c = w.take_changes();
+ assert!(!c.structural && c.added.contains(&13), "a movable mesh: placed in place");
w.set_object(11, "flat2".into(), None, Kind::Mesh { geometry: 1, material: 1, own_blas: false, materials: vec![] }, true, false).unwrap();
w.take_changes();
w.remove(11);
- assert!(w.take_changes().structural, "a flattened mesh removed");
+ let c = w.take_changes();
+ assert!(!c.structural && c.removed.contains(&11), "a mesh the scene did not say it edits, removed");
w.set_object(7, "child".into(), Some(4), Kind::Procedural { geometry: 3, materials: vec![1] }, true, false).unwrap();
+ w.set_object(14, "set".into(), Some(4), Kind::Group, true, false).unwrap();
+ w.take_changes();
+ assert_eq!(w.remove(4).len(), 3);
+ let c = w.take_changes();
+ assert!(!c.structural && c.removed.iter().copied().collect::<std::collections::BTreeSet<_>>() == [4, 7].into(), "with children: each taken out, the group has nothing drawn");
+ // Not in place: something else among them.
+ w.set_object(15, "set".into(), None, Kind::Group, true, false).unwrap();
+ w.set_object(16, "lamp".into(), Some(15), Kind::Light(serde_json::from_value(serde_json::json!({ "type": "point", "color": [1, 1, 1], "castShadow": true, "intensity": 1, "range": 0, "radius": 0.01 })).unwrap()), true, false).unwrap();
w.take_changes();
- w.remove(4);
- assert!(w.take_changes().structural, "with children");
+ w.remove(15);
+ assert!(w.take_changes().structural, "a group with a light");
// Under a still group in a movable subtree (`movable` walks the ancestors, as the build does).
w.set_object(8, "rig".into(), None, Kind::Group, true, true).unwrap();
w.set_object(9, "still".into(), Some(8), Kind::Group, true, false).unwrap();
@@ -1614,7 +1626,7 @@ mod tests {
assert!(w.take_changes().promoted.is_empty(), "placing a new object is not a move");
w.set_transform(1, Vec3::Y, Quat::IDENTITY, Vec3::ONE).unwrap();
let c = w.take_changes();
- assert!(c.structural && c.promoted == ["a"], "fixed geometry's first move rebuilds, making it movable");
+ assert!(!c.structural && c.promoted.is_empty() && c.started.contains(&1) && c.moved.contains(&1) && w.objects[&1].movable, "a still mesh's first move: its instance's, and it is movable from now on");
w.set_transform(1, Vec3::Z, Quat::IDENTITY, Vec3::ONE).unwrap();
let c = w.take_changes();
assert!(!c.structural && c.moved.contains(&1), "then it moves in place");
diff --git a/tests/render/volume-grid-rebuild-live.ts b/tests/render/volume-grid-rebuild-live.ts
index 5af03f2..a30a19e 100644
--- a/tests/render/volume-grid-rebuild-live.ts
+++ b/tests/render/volume-grid-rebuild-live.ts
@@ -1,8 +1,9 @@
// What a grid program has simulated survives a rebuild of the live scene (gpu.rs `carry_grids`): volume/grid-program's
-// grid, 1.5 a second into every cell, in the real-time renderer for 24 frames; after 12 the frame script hides a mesh
-// out of view, a structural change (the scene is built again). The grid holds 0.6 as if nothing had happened, and the
-// wall behind the absorber reads 2 e^-1.2 = 0.6024. (Started again at the rebuild it held 0.3: 1.098.)
-import { BoxGeometry, DensityGrid, GridProgram, Mesh, MeshStandardMaterial, VolumeMesh } from "@threert/scene";
+// grid, 1.5 a second into every cell, in the real-time renderer for 24 frames; after 12 the frame script adds a group,
+// which a build places (the scene is built again; hiding a mesh, as this did, is an edit in place now). The grid holds
+// 0.6 as if nothing had happened, and the wall behind the absorber reads 2 e^-1.2 = 0.6024. (Started again at the
+// rebuild it held 0.3: 1.098.)
+import { BoxGeometry, DensityGrid, GridProgram, Group, Mesh, MeshStandardMaterial, VolumeMesh } from "@threert/scene";
import { defineGame } from "@threert/gameplay";
import { CENTER, camera, result, sceneWithSky, type TestMeta } from "./lib.ts";
import { GRID_MEDIUM } from "./volume-grid-uniform.ts";
@@ -21,7 +22,6 @@ const FILL = new GridProgram("test_fill_rebuild", {
});
let frames = 0;
-let extra: Mesh;
export default defineGame<Record<string, never>>({
state: {},
setup: () => {
@@ -31,12 +31,10 @@ export default defineGame<Record<string, never>>({
wall.position.set(0, 0, -2);
const box = new VolumeMesh({ volume: GRID_MEDIUM.with({ Density: 2 }), majorant: 2, grid: new DensityGrid({ size: [16, 16, 8], program: FILL.with({ Rate: 1.5 }) }) });
box.scale.set(2, 2, 1);
- extra = new Mesh(new BoxGeometry(1, 1, 1), new MeshStandardMaterial({ name: "extra", color: 0x808080 }));
- extra.position.set(0, 0, 20);
- return result(scene, camera(scene, [0, 0, 5], [0, 0, 0]), [wall, box, extra]);
+ return result(scene, camera(scene, [0, 0, 5], [0, 0, 0]), [wall, box]);
},
- frame() {
- if (++frames === 12) extra.visible = false;
+ frame(f) {
+ if (++frames === 12) f.scene.add(new Group());
},
handlers: {},
});
diff --git a/tests/three-compat/README.md b/tests/three-compat/README.md
index bfab4f4..87931f9 100644
--- a/tests/three-compat/README.md
+++ b/tests/three-compat/README.md
@@ -23,8 +23,7 @@ written, the page around it (DOM, window, requestAnimationFrame, asset loaders)
exponential fog (95 % at `far`; FogExp2's e-folding distance).
- **Light decay is physical** (inverse square) whatever `decay` says.
- **`object.id`** is the stable id scene code sets (picking, events); until one is set, a number, as three.js's.
-- **Geometry that changes at run time**: `attribute.setUsage(DynamicDrawUsage)` gives the mesh its own acceleration
- structure; without it, the first change rebuilds the scene once and promotes the mesh (frame log `fallback`
- "promote").
+- **Geometry that changes at run time** is replaced in place; `attribute.setUsage(DynamicDrawUsage)` says so
+ beforehand, and the renderer keeps room for the changes when it builds the scene.
- Not drawn (noted `unsupported`): vertex colours, wireframe, `BackSide` (drawn double-sided). Missing: `Shape` /
`ExtrudeGeometry`.