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.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
A posed skinned model is a mesh of its own (#182)
Yujia044bfe5cac2c
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 8a94b26..83d8b27 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -2776,6 +2776,25 @@ in-place tests' world, rows given back; two models in a shared pose posed again(tests/render/data/arm.glb, a skinned strip of two materials); `geometry/emitter-model-live` (a model's emittingsection that is not its first, the model a unit under software traversal).+**A posed skinned model is a mesh of its own (2026-11-21).** Models in the same pose (the same clip and time) shared+one mesh, found by the build; one of them taking another pose had to leave it, and that rebuilt the scene (and a+rebuild grouped whichever models then happened to be in one pose). A model alone in its pose was no mesh at all:+world-space triangles, skinned on the CPU. Now every posed skinned model is an instance of a mesh of its own+(`scene::Skinned`), skinned by the pass at each new pose, never shared: another clip or time is in place whatever the+others do, and the model is hidden and shown in place by its instance (hidden, a new pose skins nothing; shown, it+is skinned as it is posed then). What the pass reads of a model is still one copy for all its placements. The+grouping, its key and the switch that turned it off are gone.+Still a rebuild: a skinned model added or removed; one hidden when the scene was built, shown; every pose under+software traversal (the next step). Still world-space triangles skinned on the CPU: a model with emitting triangles.+Measured, a crowd of 150 walkers (8 walk phases), hardware traversal, the builds in turn at 60 fps: a frame's commit+3.3 ms with a mesh a walker, against 2.1 with the 8 shared meshes and 2.9 before the pass; the BLAS builds 0.6 ms+against 0.24. With the CPU skin the same 150 meshes cost 20 ms of commit (40 fps): the reason the pass came first.+Tests: two models in one pose are two meshes skinned from one copy of the model's corners, posed again in place,+and one posed alone in place; one hidden, posed and moved while hidden, shown (under software traversal, hidden and+shown by a rebuild); four models of two files, each mesh's triangles, attributes and BLAS input on the GPU against+the CPU skin, one posed alone and the others' left as they were, one moved alone. 10 mutations of the new logic:+nine fail a test natively, the tenth (a model hidden where it has no instance to mask) under software traversal.+**Meshes that deform are skinned on the GPU (2026-11-21).** A new pose of a shared pose's mesh was skinned on theCPU and every triangle of it sent again: 180 bytes each (its vertices, its shading attributes, the BLAS's input).Now the CPU sends the pose's matrices (48 bytes a joint) and a compute pass skins the mesh where it liesdiff --git a/docs/RUNTIME.md b/docs/RUNTIME.mdindex 802ce6a..5c8b31e 100644--- a/docs/RUNTIME.md+++ b/docs/RUNTIME.md@@ -1175,7 +1175,7 @@ procedural objects (`trace_procs`: the ray into the object's space, a tree of itas vertex colours are; gpu.rs `KernelVariant::flags`): the file's walk, a call at the end of the still walk, and the stillwalk's stack declaration taken out ("The stack"). A scene without units has none of it; hardware traversal'skernel never does.-- Still flattened, as before: meshes that deform (a pose shared by a crowd), every instance of a scene with more+- Still flattened, as before: meshes that deform (a posed skinned model's), every instance of a scene with moreof them than a top tree holds (2^18), and every instance of an offline render (`prepare`; a live session's scenegoes through `prepare_live`), unless `THREERT_UNITS=1`. `THREERT_UNITS=0` flattens everything, as before thisstep (the A/B).diff --git a/renderer/src/gpu.rs b/renderer/src/gpu.rsindex 31502e7..28a474d 100644--- a/renderer/src/gpu.rs+++ b/renderer/src/gpu.rs@@ -228,7 +228,7 @@ pub struct TopBuild {pub instances: bool,/// The dynamic groups' BLASes: their triangles were re-transformed.pub dynamic: bool,- /// Instanced meshes' BLASes: new meshes, a new shared pose.+ /// Instanced meshes' BLASes: new meshes, a skinned model's new pose.pub meshes: Vec<u32>,/// Procedural BLASes an edit made.pub procs: Vec<PendingProc>,@@ -747,7 +747,7 @@ struct SkinJob {palette: u32,}-/// The skinning pass of a scene (shaders/skin.wgsl): the meshes that deform (a job each, `scene::PoseGroup`'s index)+/// The skinning pass of a scene (shaders/skin.wgsl): the meshes that deform (a job each, `scene::Skinned`'s index)/// are skinned from their models' corners and their poses' palettes into the scene's triangles, attributes and BLAS/// input. Hardware RT.pub struct SkinGpu {@@ -2474,7 +2474,7 @@ impl Gpu {.collect()}).collect();- // Deforming meshes (shared poses) are rebuilt every new pose: built fast rather than traced fast, as the dynamic+ // Deforming meshes (posed skinned models') are rebuilt every new pose: built fast rather than traced fast, as the dynamic// groups are.let meshes: Vec<wgpu::Blas> = mesh_sizes.iter()@@ -2705,7 +2705,7 @@ impl Gpu {};// The skinning pass (hardware RT: it writes the BLASes' input), a job each mesh that deforms.let skin = match &accel {- Some(a) if !scene.retained.pose_groups.is_empty() => Some(self.skin_pass(scene, a.pool_first, &b_verts, &b_attrs, &a.verts)),+ Some(a) if !scene.retained.skinned.is_empty() => Some(self.skin_pass(scene, a.pool_first, &b_verts, &b_attrs, &a.verts)),_ => None,};self.queue.submit([]);@@ -3401,7 +3401,7 @@ impl Gpu {}}- /// The skinning pass of `scene`: its pipeline, the models' corners, a job each pose group, and room for a frame's+ /// The skinning pass of `scene`: its pipeline, the models' corners, a job each skinned model, and room for a frame's/// work and every job's palette.fn skin_pass(&self, scene: &Scene, pool_first: usize, verts: &wgpu::Buffer, attrs: &wgpu::Buffer, blas_verts: &wgpu::Buffer) -> SkinGpu {let d = &self.device;@@ -3415,7 +3415,7 @@ impl Gpu {}let corners: Vec<crate::skin::SkinCorner> = scene.skin_sources.iter().flatten().flatten().copied().collect();let (mut jobs, mut matrices, mut blocks) = (vec![], 0u32, 0u32);- for g in &scene.retained.pose_groups {+ for g in &scene.retained.skinned {let m = &scene.meshes[g.mesh as usize];jobs.push((SkinJob { first: pool_first as u32 + m.first, count: m.count, source: source_first[g.source as usize], palette: matrices }, g.palette_len));matrices += g.palette_len;diff --git a/renderer/src/lib.rs b/renderer/src/lib.rsindex ae326b7..eaa4079 100644--- a/renderer/src/lib.rs+++ b/renderer/src/lib.rs@@ -923,7 +923,7 @@ fn unit_trees(sc: &mut scene::Scene) -> Option<Vec<Option<units::MeshTree>>> {Some(trees)}-/// With units: the instances of meshes that deform (a pose a crowd shares) are still written out as world-space+/// With units: the instances of meshes that deform (a posed skinned model's) are still written out as world-space/// triangles, as every instance was. They keep their place among the instances (edits name instances by index) and/// are no unit.fn flatten_deforming(sc: &mut scene::Scene) {diff --git a/renderer/src/live/edits.rs b/renderer/src/live/edits.rsindex 446ec44..73c07cd 100644--- a/renderer/src/live/edits.rs+++ b/renderer/src/live/edits.rs@@ -615,10 +615,10 @@ impl LiveCore {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+ // Movable models placed as instances move their transform (a posed skinned model too); the rest// re-transform triangles.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)),+ Some(i) if !changes.poses.contains(&k) || inst.is_some_and(|i| matches!(i.mesh, scene::MeshKind::Skinned(_))) => placed.push((k, i)),_ => {dynamic.insert(k);}@@ -659,12 +659,12 @@ impl LiveCore {for k in &rigid {dynamic.remove(k);}- // Models in a shared pose re-skin their group's mesh (`repose_groups`, its BLAS only); their moves place instances.- let shared: Vec<u32> = dynamic.iter().copied().filter(|k| self.sc.tables.retained.instance(*k).is_some_and(|i| matches!(i.mesh, scene::MeshKind::Pose(_)))).collect();+ // Posed skinned models: their meshes skinned again (`repose_skinned`, their BLASes only); their moves place instances.+ let shared: Vec<u32> = dynamic.iter().copied().filter(|k| self.sc.tables.retained.instance(*k).is_some_and(|i| matches!(i.mesh, scene::MeshKind::Skinned(_)))).collect();for k in &shared {dynamic.remove(k);}- let shared_ok = shared.is_empty() || (!changes.structural && self.repose_groups(world, &shared, &mut top)?);+ let shared_ok = shared.is_empty() || (!changes.structural && self.repose_skinned(world, &shared, &mut top)?);// Procedural geometry moves its records and TLAS transforms.if !procs_moved.is_empty() && !changes.structural {self.move_procs(world, &procs_moved, &mut top);@@ -1010,7 +1010,8 @@ impl LiveCore {}/// An object shown or hidden by its `visible`, in place: the meshes and models under it (itself, if it is one)- /// each by its instance's mask above the triangles (a posed rigid model's every part's), where no ray sees a+ /// each by its instance's mask above the triangles (a posed rigid model's every part's; a posed skinned model's+ /// own), 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.@@ -1021,8 +1022,12 @@ impl LiveCore {crate::world::Kind::Group | crate::world::Kind::Camera(_) => {}// (One this commit adds is placed as it is, shown or not: `edit_geometry`.)crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { .. } if changes.added.contains(&k) => {}- 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 };+ // A mesh, a still model, or a posed skinned model (an instance of its own mesh): its instance.+ kind @ (crate::world::Kind::Mesh { .. } | crate::world::Kind::Model { .. })+ if !matches!(kind, crate::world::Kind::Model { animation: Some(_), .. }) || self.sc.tables.retained.instance(k).is_some_and(|i| matches!(i.mesh, scene::MeshKind::Skinned(_))) =>+ {+ let skinned = matches!(kind, crate::world::Kind::Model { animation: Some(_), .. });+ let Some(r) = self.sc.tables.retained.instance(k).filter(|i| skinned || 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;@@ -1034,11 +1039,19 @@ impl LiveCore {continue;}let Some(mut top) = gpu::Top::of(&mut self.sc.up.accel, &mut self.sc.up.units) else { return false };+ // (Software traversal has a skinned model's triangles in its still tree: no instance to mask.)+ if !top.has_mesh(inst.mesh) {+ 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);+ // (A skinned model shown is skinned as it is posed now: its mesh kept the pose it was hidden in.)+ if skinned && !unseen {+ changes.poses.insert(k);+ }}// A posed rigid model: every part's instance. Shown, it is placed where it stands and posed as it is// now (`repose_rigid`, this commit: a move while it was hidden placed nothing).@@ -1824,52 +1837,42 @@ impl LiveCore {Ok(true)}- /// Models in a shared pose (`scene::PoseGroup`): each group whose pose changed is skinned once, in model space, by- /// the skinning pass (gpu.rs `skin`: the CPU sends its pose's matrices); the commit builds their BLASes and the- /// TLAS over their new bounds. False when a group's members no longer share one pose, one is hidden or changed,- /// or its new pose mirrors other primitives than the one its mesh was made for: the caller rebuilds, which groups- /// them again. (The CPU keeps no triangles of such a mesh's pose: `LiveCore::mesh_tris` skins it when asked.)- pub(super) fn repose_groups(&mut self, world: &World, members: &[u32], build: &mut gpu::TopBuild) -> Result<bool> {+ /// Posed skinned models (`scene::Skinned`): each whose pose changed is skinned in its own space by the skinning+ /// pass (gpu.rs `skin`: the CPU sends its pose's matrices); the commit builds their BLASes and the TLAS over their+ /// new bounds. One that is hidden keeps the pose its mesh has: it is skinned when it is shown (`show_meshes`).+ /// False when one is another model now, or its new pose mirrors other primitives than the one its mesh was made+ /// for: the caller rebuilds. (The CPU keeps no triangles of such a pose: `LiveCore::mesh_tris` skins it when asked.)+ pub(super) fn repose_skinned(&mut self, world: &World, ids: &[u32], build: &mut gpu::TopBuild) -> Result<bool> {use rayon::prelude::*;if self.sc.up.accel.is_none() || self.sc.up.skin.is_none() {return Ok(false);}let r = &self.sc.tables.retained;- let group = |k: &u32| match r.instance(*k).map(|i| i.mesh) {- Some(scene::MeshKind::Pose(g)) => g,- _ => unreachable!("a pose group's member (`commit`)"),- };- let mut touched: Vec<u32> = members.iter().map(group).collect();- touched.sort_unstable();- touched.dedup();let mut jobs: Vec<(u32, crate::desc::Animation)> = vec![];- for &g in &touched {- let pg = &r.pose_groups[g as usize];- let mut pose: Option<&crate::desc::Animation> = None;- for (id, _) in &pg.members {- let Some(o) = world.objects.get(id) else { return Ok(false) };- let crate::world::Kind::Model { uri, nodes, animation: Some(a), .. } = &o.kind else { return Ok(false) };- if !world.shown(*id) || *uri != pg.uri || *nodes != pg.nodes || pose.is_some_and(|p| p != a) {- return Ok(false);- }- pose = Some(a);+ for id in ids {+ let Some(scene::MeshKind::Skinned(g)) = r.instance(*id).map(|i| i.mesh) else { unreachable!("a posed skinned model (`commit`)") };+ let sk = &r.skinned[g as usize];+ let Some(o) = world.objects.get(id) else { return Ok(false) };+ let crate::world::Kind::Model { uri, nodes, animation: Some(a), .. } = &o.kind else { return Ok(false) };+ if *uri != sk.uri || *nodes != sk.nodes {+ return Ok(false);}- if let Some(a) = pose.filter(|a| **a != pg.animation) {+ if world.shown(*id) && *a != sk.animation {jobs.push((g, a.clone()));}}if jobs.is_empty() {return Ok(true);}- // The poses' matrices (the groups in parallel).+ // The poses' matrices (the models in parallel).let t_skin = Instant::now();let assets = &self.assets;let palettes: Vec<Result<Option<Vec<crate::skin::PaletteRows>>>> = jobs.par_iter().map(|(g, a)| {- let pg = &r.pose_groups[*g as usize];- let model = scene::model_gltf(&pg.uri, assets)?;- if model.mirrored(Some(a))? != pg.mirrors {+ let sk = &r.skinned[*g as usize];+ let model = scene::model_gltf(&sk.uri, assets)?;+ if model.mirrored(Some(a))? != sk.mirrors {return Ok(None);}Ok(Some(model.palette(Some(a))?))@@ -1887,9 +1890,9 @@ impl LiveCore {let df = self.sc.dynamic.0;let (mut lo, mut hi) = (usize::MAX, 0usize);for (g, _) in &jobs {- let pg = &self.sc.tables.retained.pose_groups[*g as usize];- let k = self.sc.gpu_instances[pg.members[0].1 as usize].info[0] as usize - df;- (lo, hi) = (lo.min(k), hi.max(k + pg.order.len()));+ let sk = &self.sc.tables.retained.skinned[*g as usize];+ let k = self.sc.gpu_instances[sk.instance as usize].info[0] as usize - df;+ (lo, hi) = (lo.min(k), hi.max(k + sk.order.len()));}self.keep_prev(self.pose_span.map_or((lo, hi), |(a, b)| (a.min(lo), b.max(hi))));if !self.g.skin(&self.sc.up, &work) {@@ -1898,9 +1901,9 @@ impl LiveCore {self.pose_span = Some((lo, hi));self.pose_reposed = true;for (g, a) in jobs {- let pg = &mut self.sc.tables.retained.pose_groups[g as usize];- pg.animation = a;- build.meshes.push(pg.mesh);+ let sk = &mut self.sc.tables.retained.skinned[g as usize];+ sk.animation = a;+ build.meshes.push(sk.mesh);}self.cpu_upload_ms += t_up.elapsed().as_secs_f32() * 1000.0;Ok(true)diff --git a/renderer/src/live/frame.rs b/renderer/src/live/frame.rsindex b073a47..00aa6fb 100644--- a/renderer/src/live/frame.rs+++ b/renderer/src/live/frame.rs@@ -268,7 +268,7 @@ impl LiveCore {self.update_light_lod();// A camera cut (a jump no camera makes in one frame: 2 m or 30 degrees) is not motion: no blur (UE: bCameraCut).let cut = (self.cam.pos - self.prev_cam.pos).length() > 2.0 || self.cam.fwd.dot(self.prev_cam.fwd) < 0.866;- // (Objects moved this frame: re-posed triangles or moved instances, e.g. walkers in a shared pose.)+ // (Objects moved this frame: re-posed triangles or moved instances, e.g. a crowd's walkers.)let blur = self.blur.0 > 0.0 && (moved || self.reposed || self.pose_reposed || self.inst_moved) && !cut;// Camera motion is reprojected exactly (disocclusions are rejected per pixel), so history survives motion;// the cap only bounds smearing of view-dependent shading (glossy reflections).diff --git a/renderer/src/live/inplace_tests.rs b/renderer/src/live/inplace_tests.rsindex e7adaf7..8b22bdc 100644--- a/renderer/src/live/inplace_tests.rs+++ b/renderer/src/live/inplace_tests.rs@@ -2528,11 +2528,12 @@ fn a_posed_rigid_model_with_flattened_triangles_is_hidden_and_removed_by_a_rebuiassert!(apart(&one, &two) > 0.5, "the second is in the picture ({:.2} steps)", apart(&one, &two));}-/// Models in a shared pose posed again in place (tests/render/data/arm.glb: a skinned strip, a dark half and a light-/// half that a joint swings): their mesh is skinned where it lies, each triangle still in its section. The picture is-/// a build's.+/// Posed skinned models are each a mesh of their own, whatever their poses (tests/render/data/arm.glb: a skinned strip,+/// a dark half and a light half that a joint swings): two in the same pose are two meshes, posed again in place with+/// each triangle still in its section, and one of them given another pose alone is in place too (a pose two shared+/// was one mesh, and that was a rebuild). The picture is a build's.#[test]-fn models_in_a_shared_pose_posed_again_keep_their_sections() {+fn posed_skinned_models_are_meshes_of_their_own() {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 bend = |time| Some(crate::desc::Animation { clip: "bend".into(), time, r#loop: true, nodes: Default::default() });@@ -2546,27 +2547,111 @@ fn models_in_a_shared_pose_posed_again_keep_their_sections() {Err(e) => return eprintln!("skipped: {e}"),};w.take_changes();- let groups = &live.sc.tables.retained.pose_groups;- assert_eq!((groups.len(), live.sc.meshes[groups[0].mesh as usize].sect_count), (1, 2), "the two share a pose's mesh, of two sections");+ if !live.g.hwrt {+ return eprintln!("skipped: no hardware ray tracing");+ }+ let of = |c: &LiveCore, id: u32| c.sc.tables.retained.skinned.iter().find(|s| s.object == id).expect("a posed skinned model").clone();+ let (a, b) = (of(&live, 30), of(&live, 31));+ assert_eq!((live.sc.tables.retained.skinned.len(), a.mesh != b.mesh, a.source == b.source, live.sc.meshes[a.mesh as usize].sect_count), (2, true, true, 2), "two meshes of two sections, skinned from the model's one copy of its corners");+ let against_a_build = |what: &str, live: &mut LiveCore, w: &World| {+ let mut fresh = open(w).unwrap();+ forget(live);+ let (a, b) = (picture(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));+ a+ };+ let loaded = against_a_build("as loaded", &mut live, &w);for id in [30, 31] {w.set_animation(id, bend(0.75)).unwrap();}- let rebuilt = live.commit(&mut w).unwrap();- assert!(!(rebuilt && live.g.hwrt), "the pose changed in place ({:?})", live.fallback);- let mut fresh = open(&w).unwrap();- forget(&mut live);- let (a, b) = (picture(&mut live, 64), picture(&mut fresh, 64));- assert!(apart(&a, &b) < 0.5, "the picture is {:.2} steps from a build's", apart(&a, &b));+ assert!(!live.commit(&mut w).unwrap(), "both posed again: in place ({:?})", live.fallback);+ let both = against_a_build("both posed again", &mut live, &w);+ assert!(apart(&loaded, &both) > 0.5, "the pose is in the picture ({:.2} steps)", apart(&loaded, &both));+ // One alone, and the other's mesh keeps its pose.+ w.set_animation(31, bend(0.2)).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "one of two in the same pose posed alone: in place ({:?})", live.fallback);+ assert_eq!((of(&live, 30).animation.time, of(&live, 31).animation.time), (0.75, 0.2));+ let one = against_a_build("one posed alone", &mut live, &w);+ assert!(apart(&both, &one) > 0.5, "its pose is in the picture ({:.2} steps)", apart(&both, &one));+}++/// A posed skinned model is hidden and shown in place: hidden, no ray sees its instance and a new pose skins+/// nothing; shown, it is skinned as it is posed then, where it stands. The picture is a build's each time. (Under+/// software traversal, by a rebuild.)+#[test]+fn a_posed_skinned_model_is_hidden_and_shown_in_place() {+ 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 bend = |time| Some(crate::desc::Animation { clip: "bend".into(), time, r#loop: true, nodes: Default::default() });+ let mut w = world();+ for (id, x) in [(30, -0.7), (31, 0.7)] {+ w.set_object(id, format!("arm{id}"), None, Kind::Model { uri: "tests/render/data/arm.glb".into(), nodes: None, animation: bend(0.0), functions: vec![] }, true, true).unwrap();+ w.set_transform(id, Vec3::new(x, -1.0, 0.8), glam::Quat::IDENTITY, Vec3::splat(2.0)).unwrap();+ }+ let mut live = match open(&w) {+ Ok(c) => c,+ Err(e) => return eprintln!("skipped: {e}"),+ };+ w.take_changes();+ let of = |c: &LiveCore, id: u32| c.sc.tables.retained.skinned.iter().find(|s| s.object == id).expect("a posed skinned model").clone();+ let against_a_build = |what: &str, live: &mut LiveCore, w: &World| {+ let mut fresh = open(w).unwrap();+ forget(live);+ let (a, b) = (picture(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));+ a+ };+ let loaded = against_a_build("as loaded", &mut live, &w);+ // Software traversal has a skinned model's triangles in its still tree, and no instance to mask: a rebuild's.+ if !live.g.hwrt {+ w.set_visible(31, false).unwrap();+ assert!(live.commit(&mut w).unwrap(), "hidden under software traversal: a rebuild");+ let hidden = against_a_build("hidden under software traversal", &mut live, &w);+ assert!(apart(&loaded, &hidden) > 0.5, "it is out of the picture ({:.2} steps)", apart(&loaded, &hidden));+ w.set_visible(31, true).unwrap();+ assert!(live.commit(&mut w).unwrap(), "shown under software traversal: a rebuild");+ let shown = against_a_build("shown under software traversal", &mut live, &w);+ assert!(apart(&hidden, &shown) > 0.5, "it is in the picture again ({:.2} steps)", apart(&hidden, &shown));+ return;+ }+ let record = of(&live, 31).instance;+ w.set_visible(31, false).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "hidden: in place ({:?})", live.fallback);+ assert!(!seen_by_rays(&live, record) && seen_by_rays(&live, of(&live, 30).instance), "no ray sees the hidden one; the other is seen");+ let hidden = against_a_build("hidden", &mut live, &w);+ assert!(apart(&loaded, &hidden) > 0.5, "it is out of the picture ({:.2} steps)", apart(&loaded, &hidden));+ // Posed and moved while hidden: nothing is skinned; the other is posed as ever.+ w.set_animation(31, bend(0.8)).unwrap();+ w.set_animation(30, bend(0.5)).unwrap();+ w.set_transform(31, Vec3::new(0.5, -0.8, 0.9), glam::Quat::from_rotation_y(0.4), Vec3::splat(2.0)).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "posed and moved while hidden: in place ({:?})", live.fallback);+ assert_eq!((of(&live, 31).animation.time, of(&live, 30).animation.time), (0.0, 0.5), "the hidden one's mesh keeps the pose it had; the other's has the new one");+ against_a_build("posed and moved while hidden", &mut live, &w);+ // Shown: skinned as it is posed now, where it stands now.+ w.set_visible(31, true).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "shown: in place ({:?})", live.fallback);+ assert!(seen_by_rays(&live, record), "the rays see it again");+ assert_eq!(of(&live, 31).animation.time, 0.8, "its mesh has the pose it was given while hidden");+ let shown = against_a_build("shown", &mut live, &w);+ assert!(apart(&hidden, &shown) > 0.5, "it is in the picture again ({:.2} steps)", apart(&hidden, &shown));+ // Hidden and shown again with nothing between: as it was.+ w.set_visible(31, false).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "hidden again: in place ({:?})", live.fallback);+ w.set_visible(31, true).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "shown again: in place ({:?})", live.fallback);+ let again = against_a_build("shown again", &mut live, &w);+ assert!(apart(&shown, &again) < 0.5, "as before it was hidden ({:.2} steps)", apart(&shown, &again));}/// The skinning pass writes what the CPU skin writes. Two models (tests/render/data/skin-blend.glb: 72 triangles,/// vertices two joints hold, weights that do not sum to one, a primitive with tangents and one without normals, a/// mesh on a node beside the skin that mirrors it, a joint turned about an axis that is neither the normals' nor the-/// tangents', its materials in an order a mesh laid out by material does not keep; and arm.glb), two of each in a-/// pose, in a scene with world-space triangles before the meshes': after each new pose the GPU's triangles, shading attributes and-/// BLAS input of each mesh are its model's triangles for the pose, the previous frame's vertices are the pose-/// before, and the CPU has the mesh as it is now when asked. Also after the scene's buffers were made again larger,-/// and a pose that mirrors other primitives than the mesh was made for is a rebuild's.+/// tangents', its materials in an order a mesh laid out by material does not keep; and arm.glb), two of each, each+/// a mesh of its own, in a scene with world-space triangles before the meshes': after each new pose the GPU's+/// triangles, shading attributes and BLAS input of each mesh are its model's triangles for the pose, the previous+/// frame's vertices are the pose before, and the CPU has the mesh as it is now when asked. One posed alone leaves+/// the others' as they were. Also after the scene's buffers were made again larger, and a pose that mirrors other+/// primitives than the mesh was made for is a rebuild's.#[test]fn the_skinning_pass_writes_what_the_cpu_skin_writes() {let presets = crate::default_presets_dir();@@ -2592,12 +2677,12 @@ fn the_skinning_pass_writes_what_the_cpu_skin_writes() {}assert!(live.sc.edit.pool_first > 0, "a mesh's first triangle on the GPU is not its first in the pool");{- let g = live.sc.tables.retained.pose_groups.iter().find(|g| g.uri.ends_with("skin-blend.glb")).expect("the model's mesh");+ let g = live.sc.tables.retained.skinned.iter().find(|g| g.uri.ends_with("skin-blend.glb")).expect("the model's mesh");assert!(g.order.iter().enumerate().any(|(at, &(k, _, _))| at as u32 != k), "the mesh has the model's triangles in another order (by material)");}- // (A mesh, its first instance and its object, for each deforming mesh of the scene.)- let deforming = |c: &LiveCore| c.sc.tables.retained.pose_groups.iter().map(|g| (g.uri.clone(), g.order.clone(), g.members[0].1, g.members[0].0)).collect::<Vec<_>>();- assert_eq!(deforming(&live).len(), 2, "two models, each a pose its two placements share");+ // (A mesh, its instance and its object, for each deforming mesh of the scene.)+ let deforming = |c: &LiveCore| c.sc.tables.retained.skinned.iter().map(|g| (g.uri.clone(), g.order.clone(), g.instance, g.object)).collect::<Vec<_>>();+ assert_eq!(deforming(&live).len(), 4, "four models, each a mesh of its own");let read = |c: &LiveCore, b: &wgpu::Buffer, at: u64, bytes: u64| -> Vec<f32> {let to = c.g.device.create_buffer(&wgpu::BufferDescriptor { label: None, size: bytes, usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false });let mut e = c.g.device.create_command_encoder(&Default::default());@@ -2636,21 +2721,24 @@ fn the_skinning_pass_writes_what_the_cpu_skin_writes() {let up = &c.sc.up;(read(c, &up.verts, k * 48, n * 48), read(c, &up.attrs, k * 96, n * 96), read(c, &up.accel.as_ref().unwrap().verts, k * 36, n * 36), read(c, &up.prev_verts, (k - c.sc.dynamic.0 as u64) * 48, n * 48))};+ let check_one = |what: &str, c: &LiveCore, g: usize, now: &crate::desc::Animation, before: &crate::desc::Animation| {+ let what = format!("{what}, {} (object {})", deforming(c)[g].0, deforming(c)[g].3);+ let ((v, at, b, prev), (cv, cat, cb)) = (gpu(c, g), cpu(c, g, now));+ same(&format!("{what}: the vertices"), &v, &cv, &[3], 12);+ // (An attribute's words: the section in `uv.w` (15), the rank in `x.w` (23), the object and a spare beside.)+ same(&format!("{what}: the attributes"), &at, &cat, &[15, 21, 22, 23], 24);+ same(&format!("{what}: the BLAS input"), &b, &cb, &[], 9);+ same(&format!("{what}: the previous frame's vertices"), &prev, &cpu(c, g, before).0, &[3], 12);+ // The CPU's own: the build's pose in the pool, the pose as it is now when asked.+ let (instance, id) = (deforming(c)[g].2, deforming(c)[g].3);+ let inst = &c.sc.instances[instance as usize];+ let asked: Vec<f32> = c.node_tris(&format!("m{id}")).iter().flatten().flat_map(|p| p.to_array()).collect();+ let placed: Vec<f32> = cb.chunks_exact(3).flat_map(|p| inst.world.transform_point3(Vec3::new(p[0], p[1], p[2])).to_array()).collect();+ same(&format!("{what}: the mesh as the CPU has it when asked"), &asked, &placed, &[], 9);+ };let check = |what: &str, c: &LiveCore, now: &crate::desc::Animation, before: &crate::desc::Animation| {for g in 0..deforming(c).len() {- let what = format!("{what}, {}", deforming(c)[g].0);- let ((v, at, b, prev), (cv, cat, cb)) = (gpu(c, g), cpu(c, g, now));- same(&format!("{what}: the vertices"), &v, &cv, &[3], 12);- // (An attribute's words: the section in `uv.w` (15), the rank in `x.w` (23), the object and a spare beside.)- same(&format!("{what}: the attributes"), &at, &cat, &[15, 21, 22, 23], 24);- same(&format!("{what}: the BLAS input"), &b, &cb, &[], 9);- same(&format!("{what}: the previous frame's vertices"), &prev, &cpu(c, g, before).0, &[3], 12);- // The CPU's own: the build's pose in the pool, the pose as it is now when asked.- let (instance, id) = (deforming(c)[g].2, deforming(c)[g].3);- let inst = &c.sc.instances[instance as usize];- let asked: Vec<f32> = c.node_tris(&format!("m{id}")).iter().flatten().flat_map(|p| p.to_array()).collect();- let placed: Vec<f32> = cb.chunks_exact(3).flat_map(|p| inst.world.transform_point3(Vec3::new(p[0], p[1], p[2])).to_array()).collect();- same(&format!("{what}: the mesh as the CPU has it when asked"), &asked, &placed, &[], 9);+ check_one(what, c, g, now, before);}};let all = |w: &mut World, a: &crate::desc::Animation| {@@ -2659,13 +2747,26 @@ fn the_skinning_pass_writes_what_the_cpu_skin_writes() {}};let (first, second, third) = (bend(0.0), bend(0.75), bend(0.4));- let loaded: Vec<Vec<f32>> = (0..2).map(|g| cpu(&live, g, &first).0).collect();+ let loaded: Vec<Vec<f32>> = (0..4).map(|g| cpu(&live, g, &first).0).collect();for (what, now, before) in [("a new pose", &second, &first), ("the next", &third, &second)] {all(&mut w, now);assert!(!live.commit(&mut w).unwrap(), "{what}: in place ({:?})", live.fallback);check(what, &live, now, before);}- assert!((0..2).all(|g| cpu(&live, g, &third).0.iter().zip(&loaded[g]).any(|(a, b)| (a - b).abs() > 0.05)), "the pose moves both meshes");+ assert!((0..4).all(|g| cpu(&live, g, &third).0.iter().zip(&loaded[g]).any(|(a, b)| (a - b).abs() > 0.05)), "the pose moves every mesh");+ // One posed alone: its mesh, and the others' as they were (their previous frame's vertices their own pose now).+ let alone = bend(0.15);+ w.set_animation(31, Some(alone.clone())).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "one posed alone: in place ({:?})", live.fallback);+ for g in 0..4 {+ if deforming(&live)[g].3 == 31 {+ check_one("one posed alone", &live, g, &alone, &third);+ } else {+ check_one("the others, left alone", &live, g, &third, &third);+ }+ }+ w.set_animation(31, Some(third.clone())).unwrap();+ assert!(!live.commit(&mut w).unwrap(), "and back: in place ({:?})", live.fallback);// The picture is a build's.let pictured = |what: &str, live: &mut LiveCore, w: &World| {let mut fresh = open(w).unwrap();@@ -2735,7 +2836,7 @@ fn models_posed_node_by_node_are_posed_in_place() {if !live.g.hwrt {return eprintln!("skipped: no hardware ray tracing");}- assert_eq!(live.sc.tables.retained.pose_groups.len(), 2, "each its own pose, though the same");+ assert_eq!(live.sc.tables.retained.skinned.len(), 2, "each a mesh of its own, though in the same pose");let before = picture(&mut live, 64);for (id, a) in [(30, 0.9), (31, -1.2)] {w.set_animation(id, turn(a)).unwrap();diff --git a/renderer/src/live/mod.rs b/renderer/src/live/mod.rsindex 3f5d926..034e2b2 100644--- a/renderer/src/live/mod.rs+++ b/renderer/src/live/mod.rs@@ -341,7 +341,7 @@ pub struct LiveCore {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+ /// Likewise for posed skinned models' meshes (`repose_skinned`): the span they took (relative to the dynamic/// tail, past its end) and whether this frame re-skinned any.pose_span: Option<(usize, usize)>,pose_reposed: bool,@@ -927,7 +927,7 @@ impl LiveCore {if !m.deforms || self.sc.up.skin.is_none() {return pool;}- let Some(pg) = self.sc.tables.retained.pose_groups.iter().find(|g| g.mesh == mesh) else { return pool };+ let Some(pg) = self.sc.tables.retained.skinned.iter().find(|g| g.mesh == mesh) else { return pool };if !posed.contains_key(&mesh) {let tris = scene::model_gltf(&pg.uri, &self.assets).and_then(|model| model.triangles(glam::Mat4::IDENTITY, pg.nodes.as_deref(), Some(&pg.animation)));match tris {diff --git a/renderer/src/scene.rs b/renderer/src/scene.rsindex ecd6504..5aa6987 100644--- a/renderer/src/scene.rs+++ b/renderer/src/scene.rs@@ -64,7 +64,7 @@ pub struct InstMesh {/// Model-space bounds (object bounds of its instances, picking).pub lo: Vec3A,pub hi: Vec3A,- /// Its triangles change (a shared pose, `PoseGroup`): its BLAS is rebuilt with them.+ /// Its triangles change (a posed skinned model's, `Skinned`): its BLAS is rebuilt with them.pub deforms: bool,/// Its sections (`Section`), in `Scene::sections`: a geometry of its BLAS each, a row of its instances each.pub sect_first: u32,@@ -672,8 +672,8 @@ pub struct Scene {pub pool_attrs: Vec<GpuTriAttr>,pub meshes: Vec<InstMesh>,pub instances: Vec<Instance>,- /// What the skinning pass reads of the models whose meshes deform (`PoseGroup::source`): a model's triangles as- /// its file has them, in its mesh's order. One a model, whatever its poses.+ /// What the skinning pass reads of the models whose meshes deform (`Skinned::source`): a model's triangles as+ /// its file has them, in its mesh's order. One a model, whatever its placements and poses.pub skin_sources: Vec<Vec<[skin::SkinCorner; 3]>>,/// The meshes' sections (`InstMesh::sect_first`) and the instances' rows (`Instance::rows`): as the kernel reads/// the rows once `prepare` has set where each section's triangles and emitters are.@@ -744,8 +744,8 @@ pub struct Retained {pub light_nodes: Vec<u32>,/// Atmosphere sun: its colour comes from the sky bake.pub sun: Option<u32>,- /// Posed models sharing a pose (`PoseGroup`: its members' proxies name it, `MeshKind::Pose`).- pub pose_groups: Vec<PoseGroup>,+ /// Posed skinned models' meshes (`Skinned`: a model's proxy names its own, `MeshKind::Skinned`).+ pub skinned: Vec<Skinned>,/// Meshes and instanced objects: (geometry, whether by its groups: `by_groups`) -> the shared mesh (objects of the/// same geometry share its BLAS, whatever their materials: those are their instances' rows). live/edits.rs/// `edit_geometry` keeps it.@@ -810,8 +810,8 @@ pub struct InstanceRef {pub enum MeshKind {/// A model's.Model,- /// A shared pose's (`Retained::pose_groups`): the group's mesh is re-skinned, its members move as instances.- Pose(u32),+ /// A posed skinned model's own (`Retained::skinned`): skinned again at a new pose; the model moves as its instance.+ Skinned(u32),/// A geometry's mesh, shared by the objects of the geometry (`Retained::own_mesh`).Own,}@@ -963,11 +963,12 @@ struct RigidPart {rest: Vec<([Vec3; 3], [Vec3; 3], [Vec2; 3], Option<(Vec3, f32)>, u32)>,}-/// Posed skinned models in the same pose (the same model, nodes, clip and time: a crowd whose game shares a few walk-/// phases). One model-space mesh holds the pose, skinned once per new pose and its BLAS rebuilt; each model is an-/// instance of it, moved by its transform (hardware RT). Only meshes without triangles flattened per placement.+/// A posed skinned model's mesh: the model's triangles in its own space, a mesh a model. The skinning pass skins it at+/// each new pose (gpu.rs `skin`: the CPU sends the pose's matrices) and its BLAS is built again; the model moves as+/// its instance (hardware RT). Never shared: two models in one pose are two meshes (a mesh shared came apart when+/// one of them took another pose, and that was a rebuild). Only meshes without triangles flattened per placement.#[derive(Clone, Debug)]-pub struct PoseGroup {+pub struct Skinned {pub mesh: u32,pub uri: String,pub nodes: Option<Vec<String>>,@@ -975,8 +976,9 @@ pub struct PoseGroup {pub animation: desc::Animation,/// Per pool triangle of the mesh, in order: its index in the model's triangles, its section and its index in it.pub order: Vec<(u32, u32, u32)>,- /// (object, instance) of each member.- pub members: Vec<(u32, u32)>,+ /// Its object, and its instance.+ pub object: u32,+ pub instance: u32,/// What the skinning pass skins it from (`Scene::skin_sources`), how many matrices its pose is/// (`skin::Model::palette`), and the primitives the pose its mesh was made for mirrors (`skin::Model::mirrored`:/// a pose that mirrors others has its triangles in another order, a build's to make).@@ -985,10 +987,6 @@ pub struct PoseGroup {pub mirrors: Vec<bool>,}-/// What groups posed models into a `PoseGroup`: model, nodes, clip, time (bits), loop; for a model whose pose names-/// nodes (posed by the game, its own), the object.-type PoseKey = (String, Option<Vec<String>>, String, u32, bool, Option<u32>);-/// pathtrace.wgsl `Medium`: world -> local affine rows (the unit box / sphere's space), (function, shape or/// `MEDIUM_HIDDEN`, homogeneous, animated),/// (majorant 1/m, HG anisotropy, -, -), the node's customData, 32 parameter floats.@@ -1536,35 +1534,7 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&selet mut mesh_of: HashMap<(String, Option<Vec<String>>), Option<u32>> = HashMap::new();// A posed rigid model's parts, by (model, clip): its placements share their meshes.let mut rigid_parts: HashMap<(String, String), std::rc::Rc<Vec<RigidPart>>> = HashMap::new();- // Posed skinned models that share a pose with another share its mesh (`PoseGroup`). THREERT_POSE_SHARE=0 skins- // each model alone (A/B).- let mut pose_key_of: HashMap<u32, PoseKey> = HashMap::new();- if instancing && std::env::var("THREERT_POSE_SHARE").map_or(true, |v| v != "0") {- let mut count: HashMap<PoseKey, usize> = HashMap::new();- for id in &order {- let Kind::Model { uri, nodes, animation: Some(a), functions } = &w.objects[id].kind else { continue };- if !w.shown(*id) || worlds[id].determinant() == 0.0 {- continue;- }- // (Rigid models whose nodes move are `RigidModel`s.)- let glb = model_gltf(uri, assets)?;- if !glb.animated() || (nodes.is_none() && glb.rigid()) {- continue;- }- // (Copies with material functions share a pose only with the same functions: their own materials.)- let file = if functions.is_empty() { uri.clone() } else { format!("{uri}\u{0}{functions:?}") };- // A model the game poses node by node is a group of its own: its mesh (and BLAS) is skinned again when its- // pose changes, and moves as an instance, whatever the other models do (a player's body). It comes apart- // from no other, so no new pose rebuilds the scene.- let own = (!a.nodes.is_empty()).then_some(*id);- let key: PoseKey = (file, nodes.clone(), a.clip.clone(), a.time.to_bits(), a.r#loop, own);- *count.entry(key.clone()).or_default() += 1;- pose_key_of.insert(*id, key);- }- pose_key_of.retain(|_, k| count[k] >= 2 || k.5.is_some());- }- let mut pose_group_of: HashMap<PoseKey, Option<u32>> = HashMap::new();- // What the skinning pass reads, by (model, nodes, the primitives mirrored): shared by the model's pose groups.+ // What the skinning pass reads, by (model, nodes, the primitives mirrored): shared by the model's placements.let mut skin_sources: Vec<Vec<[skin::SkinCorner; 3]>> = vec![];let mut skin_source_of: HashMap<(String, Option<Vec<String>>, Vec<bool>), u32> = HashMap::new();// Flattened instances' triangle ranges.@@ -1880,70 +1850,61 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&se*retained.proxy(*id) = Proxy { object: Some(oi), card: None, draw: Draw::Rigid(rigid) };continue;}- // A model in a shared pose: an instance of the pose's mesh (`PoseGroup`), made by the group's first.- if let Some(key) = pose_key_of.get(id) {- let group = match pose_group_of.get(key) {- Some(g) => *g,- None => {- let a = animation.as_ref().unwrap();- let local = glb.triangles(Mat4::IDENTITY, nodes.as_deref(), Some(a))?;- let mut classed: [Vec<(usize, u32)>; 4] = Default::default();- for (k, t) in local.iter().enumerate() {- // (A mesh that deforms does not keep its emitters: the light list does not follow a- // pose yet.)- let (mat, class, emits) = resolve(t.material.and_then(|i| doc.materials().nth(i)))?;- classed[if emits { FLAT } else { class as usize }].push((k, mat));- }- // Triangles flattened per placement (emissive): each model skinned alone.- let shared = classed[FLAT].is_empty() && !local.is_empty();- let (order, sects, mine) = model_sections(&kept(&classed));- // (The model's corners in the mesh's order: the same for every pose group of the model.)- let mirrors = if shared { glb.mirrored(Some(a))? } else { vec![] };- let skey = (key.0.clone(), nodes.clone(), mirrors.clone());- if shared && !skin_source_of.contains_key(&skey) {+ // A posed skinned model is an instance of a mesh of its own, in its own space, which the skinning pass+ // skins at each new pose (`Skinned`). One with emitting triangles is not yet: skinned alone, below.+ if instancing && posed && m.determinant() != 0.0 && !(nodes.is_none() && glb.rigid()) {+ let a = animation.as_ref().unwrap();+ let local = glb.triangles(Mat4::IDENTITY, nodes.as_deref(), Some(a))?;+ let mut classed: [Vec<(usize, u32)>; 4] = Default::default();+ for (k, t) in local.iter().enumerate() {+ // (A mesh that deforms does not keep its emitters: the light list does not follow a pose yet.)+ let (mat, class, emits) = resolve(t.material.and_then(|i| doc.materials().nth(i)))?;+ classed[if emits { FLAT } else { class as usize }].push((k, mat));+ }+ if classed[FLAT].is_empty() && !local.is_empty() {+ let (order, sects, mine) = model_sections(&kept(&classed));+ // (The model's corners in its mesh's order: one copy for every placement of the model.)+ let mirrors = glb.mirrored(Some(a))?;+ let file = if functions.is_empty() { uri.clone() } else { format!("{uri}\u{0}{functions:?}") };+ let skey = (file, nodes.clone(), mirrors.clone());+ let source = match skin_source_of.get(&skey) {+ Some(k) => *k,+ None => {let corners = glb.skin_source(nodes.as_deref(), Some(a))?;skin_sources.push(order.iter().map(|&(k, _, _)| corners[k]).collect());- skin_source_of.insert(skey.clone(), skin_sources.len() as u32 - 1);+ skin_source_of.insert(skey, skin_sources.len() as u32 - 1);+ skin_sources.len() as u32 - 1}- let g = shared.then(|| {- let first = pool_tris.len() as u32;- let (mut lo, mut hi) = (Vec3A::splat(f32::MAX), Vec3A::splat(f32::MIN));- for &(k, section, rank) in &order {- let t = &local[k];- for v in t.p {- lo = lo.min(v.into());- hi = hi.max(v.into());- }- pool_tris.push([t.p[0].into(), t.p[1].into(), t.p[2].into()]);- pool_attrs.push(section_attr(t.p, t.n, t.uv, t.tangent, section, rank));- }- let tri_order: Vec<(u32, u32, u32)> = order.iter().map(|&(k, section, rank)| (k as u32, section, rank)).collect();- // Other poses reach further (a stride, a swing): object bounds a quarter wider each way;- // one the game poses may take any pose (lie down): as far as its size each way.- let pad = if key.5.is_some() { Vec3A::splat((hi - lo).length()) } else { (hi - lo) * 0.25 };- meshes.push(InstMesh { lo: lo - pad, hi: hi + pad, deforms: true, sect_first: sections.len() as u32, sect_count: sects.len() as u32, ..own_inst_mesh(&pool_tris[first as usize..], first) });- sections.extend(sects);- retained.mesh_rows.insert(meshes.len() as u32 - 1, mine);- retained.pose_groups.push(PoseGroup { mesh: meshes.len() as u32 - 1, uri: uri.clone(), nodes: nodes.clone(), animation: a.clone(), order: tri_order, members: vec![], source: skin_source_of[&skey], palette_len: glb.palette_len() as u32, mirrors });- retained.pose_groups.len() as u32 - 1- });- pose_group_of.insert(key.clone(), g);- g+ };+ let first = pool_tris.len() as u32;+ let (mut lo, mut hi) = (Vec3A::splat(f32::MAX), Vec3A::splat(f32::MIN));+ for &(k, section, rank) in &order {+ let t = &local[k];+ for v in t.p {+ lo = lo.min(v.into());+ hi = hi.max(v.into());+ }+ pool_tris.push([t.p[0].into(), t.p[1].into(), t.p[2].into()]);+ pool_attrs.push(section_attr(t.p, t.n, t.uv, t.tangent, section, rank));}- };- if let Some(g) = group {- let mesh = retained.pose_groups[g as usize].mesh;+ let tri_order: Vec<(u32, u32, u32)> = order.iter().map(|&(k, section, rank)| (k as u32, section, rank)).collect();+ // Other poses reach further (a stride, a swing): object bounds a quarter wider each way; one+ // the game poses may take any pose (lie down): as far as its size each way.+ let pad = if a.nodes.is_empty() { (hi - lo) * 0.25 } else { Vec3A::splat((hi - lo).length()) };+ meshes.push(InstMesh { lo: lo - pad, hi: hi + pad, deforms: true, sect_first: sections.len() as u32, sect_count: sects.len() as u32, ..own_inst_mesh(&pool_tris[first as usize..], first) });+ let mesh = meshes.len() as u32 - 1;+ sections.extend(sects);+ retained.mesh_rows.insert(mesh, mine.clone());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]);let i = instances.len() as u32;- let mine = retained.mesh_rows[&mesh].clone();instances.push(Instance { mesh, world: m, object: oi, cast_shadow: rows_cast(&mine, n.cast_shadow), name: n.name.clone(), sub: None, hidden: false, masked: false, first_emitter: 0, rows: rows.len() as u32, bits: rows_bits(&mine) });rows.extend(mine);- *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));+ retained.skinned.push(Skinned { mesh, uri: uri.clone(), nodes: nodes.clone(), animation: a.clone(), order: tri_order, object: *id, instance: i, source, palette_len: glb.palette_len() as u32, mirrors });+ *retained.proxy(*id) = Proxy { object: Some(oi), card: None, draw: Draw::Instance(InstanceRef { instance: i, mesh: MeshKind::Skinned(retained.skinned.len() as u32 - 1), moves: true }) };continue;}}@@ -2221,7 +2182,7 @@ pub fn build(w: &World, assets: &Path, presets_dir: &Path, overrides: Option<&sestats.insert("triangles", (tris.len() as u64 + instanced) as f64);stats.insert("instances", instances.len() as f64);stats.insert("instanced_triangles", instanced as f64);- // Deforming meshes (shared poses) first in the pool: the previous frame's vertices (`prev_verts`, motion vectors)+ // Deforming meshes (posed skinned models') first in the pool: the previous frame's vertices (`prev_verts`, motion vectors)// cover the dynamic tail and, right after it, them.if meshes.iter().any(|m| m.deforms) {let (mut pt, mut pa) = (Vec::with_capacity(pool_tris.len()), Vec::with_capacity(pool_attrs.len()));diff --git a/tests/render/skinning-shared-pose-live.ts b/tests/render/skinning-shared-pose-live.tsindex 0600f8b..12c8231 100644--- a/tests/render/skinning-shared-pose-live.ts+++ b/tests/render/skinning-shared-pose-live.ts@@ -1,5 +1,5 @@-// Shared poses follow the pose: two mannequins built in one pose (A_TPose) share one skinned mesh (scene::PoseGroup).-// From 0.08 s the frame script poses both Idle_Loop at 0.5 s, so the shared mesh is re-skinned live: the region where+// Models in one pose follow the pose: two mannequins built in one pose (A_TPose), each a skinned mesh of its own.+// From 0.08 s the frame script poses both Idle_Loop at 0.5 s, so each mesh is skinned again live: the region where// the T pose's arm was (screen left, the forearm) shows the 1-nit sky behind it, and the chest is still there. The// ratio of the two: 2.13 in the offline render of this pose (skinning-pose.ts: the chest 0.47 nit under the sky); a// mesh left in its build pose keeps the arm there (about 1.1), a model that is no longer drawn shows sky in both@@ -14,7 +14,7 @@ export const test: TestMeta = {metric: { kind: "ratio", a: [0.33, 0.45, 0.39, 0.48], b: [0.47, 0.5, 0.53, 0.58], expected: 2.13, tolerance: 0.3 },requires: ["assets/quaternius/ual/UAL1_Standard.glb"],live: 30,- note: "both built in A_TPose (one group), both posed Idle_Loop at 0.5 s by the frame script; the other at z = 8",+ note: "both built in A_TPose, both posed Idle_Loop at 0.5 s by the frame script; the other at z = 8",};const URI = "assets/quaternius/ual/UAL1_Standard.glb";diff --git a/tests/render/skinning-shared-pose-split-live.ts b/tests/render/skinning-shared-pose-split-live.tsindex 8ec7ec0..d78b6e6 100644--- a/tests/render/skinning-shared-pose-split-live.ts+++ b/tests/render/skinning-shared-pose-split-live.ts@@ -1,7 +1,7 @@-// A shared pose splits: two mannequins built in one pose (A_TPose) share one skinned mesh (scene::PoseGroup). From-// 0.08 s the frame script poses the first Idle_Loop at 0.5 s and the second Walk_Loop: they no longer share a pose (a-// rebuild regroups them, each skinned alone). The region where the T pose's arm was (screen left, the forearm) shows-// the 1-nit sky; a mesh left in its build pose keeps the arm there. The second mannequin stands behind the camera.+// Two models in one pose come apart: two mannequins built in one pose (A_TPose), each a skinned mesh of its own. From+// 0.08 s the frame script poses the first Idle_Loop at 0.5 s and the second Walk_Loop: each mesh is skinned again in+// place. The region where the T pose's arm was (screen left, the forearm) shows the 1-nit sky; a mesh left in its+// build pose keeps the arm there. The second mannequin stands behind the camera.import { GLTFModel } from "@threert/scene";import { defineGame } from "@threert/gameplay";import { camera, result, sceneWithSky, type TestMeta } from "./lib.ts";@@ -11,7 +11,7 @@ export const test: TestMeta = {metric: { kind: "radiance", region: [0.33, 0.45, 0.39, 0.48], expected: 1, tolerance: 0.02 },requires: ["assets/quaternius/ual/UAL1_Standard.glb"],live: 30,- note: "both built in A_TPose (one group); the frame script poses a Idle_Loop at 0.5 s, b (at z = 8) Walk_Loop",+ note: "both built in A_TPose; the frame script poses a Idle_Loop at 0.5 s, b (at z = 8) Walk_Loop",};const URI = "assets/quaternius/ual/UAL1_Standard.glb";