open-standards/wai/wai-web/src/splat4d.rs
Transaction Science df20c392d8 wai: interactive + temporal cargo classes, provenance, telepresence
Adds the "carries whatever it can reconstruct, verifies whatever it
carries" surface on top of the existing neural/codec WAI. All builds
green against this base (wai-rs all-features tests + clippy, wai-web
wasm, wai-spz-gen, wai-relay).

Reconstruct half — each a spec + conformance corpus + in-tab browser
sink that re-derives the corpus hash, over one wai.det.fixed64 floor:
  - interactive worlds      replay-equivalence   (3 sim registrants,
    relay multiplayer, session receipts, glTF + real-SPZ assets)
  - spatial audio           mixdown-equivalence
  - haptics                 sample-equivalence
  - state-feeds             replay-equivalence  (non-physics sim)
  - avatars / digital humans  pose-equivalence  (+ telepresence)
  - volumetric / 4D splats  frame-state-equivalence (WebGPU EWA render)

Verify half (lever 4):
  - asset provenance — signed, energy-accounted lineage for opaque
    captured content WAI does not reconstruct; tamper-evident in-tab.

Cross-cutting: per-class JWP receipt profiles; a native energy meter
(IOReport via macmon, no sudo) emitting receipts with real measured
joules. Codecs gated behind a `codecs` feature (default on) so the
world/wasm sinks build without the C codec chain.

Excludes the separately-evolving neural subsystem (semantic path, GLC
rANS, ONNX tooling) to avoid reverting newer origin work.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-13 23:16:42 -04:00

75 lines
2.5 KiB
Rust

//! Browser sink for `wai.splat.4d` — the volumetric extension.
//!
//! Not a port: it binds the same `wai` engine native sinks run. The sink
//! reconstructs the Gaussian cloud at a frame in the deterministic floor
//! and checks its hash against the corpus (frame-state-equivalence); the
//! page renders the reconstructed set. `frame()` returns a flat f32
//! buffer (14 per Gaussian: position, scale, rotation quaternion, color,
//! opacity) — the cloud the EWA renderer draws. The pose is exact `Fx`;
//! only this display projection is float.
use wasm_bindgen::prelude::*;
use wai::splat4d::Splat4dClipData;
#[wasm_bindgen]
pub struct Splat4dSink {
clip: Splat4dClipData,
}
fn hex(b: &[u8]) -> String {
b.iter().map(|x| format!("{x:02x}")).collect()
}
#[wasm_bindgen]
impl Splat4dSink {
#[wasm_bindgen(constructor)]
pub fn new(w4ds: &[u8]) -> Result<Splat4dSink, JsError> {
Ok(Splat4dSink {
clip: Splat4dClipData::from_bytes(w4ds).map_err(|e| JsError::new(&e.to_string()))?,
})
}
pub fn n_gaussians(&self) -> u32 {
self.clip.contract.n_gaussians
}
pub fn n_frames(&self) -> u64 {
self.clip.contract.n_frames
}
pub fn frame_rate(&self) -> u32 {
self.clip.contract.frame_rate
}
pub fn clip_hash_hex(&self) -> String {
hex(&self.clip.clip_hash())
}
/// Frame-state-equivalence quantity at `frame` — the BLAKE3 of the
/// reconstructed Gaussian set, computed by the corpus-generating code.
pub fn frame_hash_hex(&self, frame: u64) -> String {
hex(&self.clip.frame_hash(frame))
}
/// The reconstructed cloud at `frame`: 14 f32 per Gaussian —
/// `[x,y,z, sx,sy,sz, qx,qy,qz,qw, r,g,b,a]`. The render's job is the
/// sink's; this is the verified state, projected to f32 for the GPU.
pub fn frame(&self, frame: u64) -> Box<[f32]> {
let states = self.clip.reconstruct_frame(frame);
let mut out = Vec::with_capacity(states.len() * 14);
for s in &states {
for v in s.pos {
out.push(v.approx_f64() as f32);
}
for v in s.scale {
out.push(v.approx_f64() as f32);
}
for v in s.rot {
out.push(v.approx_f64() as f32);
}
for v in s.color {
out.push(v.approx_f64() as f32);
}
out.push(s.opacity.approx_f64() as f32);
}
out.into_boxed_slice()
}
}