@threenative/core 0.3.12 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +1 -1
  2. package/capabilities.json +1047 -44
  3. package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
  4. package/dist/{canvas-layer-CWuFRT7G.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
  5. package/dist/{chunk-7UUT3TY5.js → chunk-2GPHICV6.js} +1 -1
  6. package/dist/{chunk-GMHATRPW.js → chunk-GEMQJBY4.js} +1650 -383
  7. package/dist/{chunk-VAZM36TV.js → chunk-H4J6IAJE.js} +17 -10
  8. package/dist/{chunk-5O73CDMR.js → chunk-QAMSM3Z5.js} +415 -27
  9. package/dist/{chunk-2Z44XSI2.js → chunk-QAQHYOWY.js} +3 -7
  10. package/dist/{chunk-DBELTTTM.js → chunk-U4YHUKKL.js} +1 -1
  11. package/dist/{chunk-OKXUCASC.js → chunk-VBBYWGAT.js} +3 -4
  12. package/dist/chunk-VP43GIWW.js +18 -0
  13. package/dist/{chunk-N5LRP4BR.js → chunk-VQRPEOKY.js} +66 -3
  14. package/dist/{chunk-6KLNISRJ.js → chunk-XDTZ4QMO.js} +11 -4
  15. package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
  16. package/dist/{game-D7pAzZUY.d.ts → game-k8K3hZai.d.ts} +72 -8
  17. package/dist/hot.d.ts +5 -4
  18. package/dist/hot.js +5 -8
  19. package/dist/index.d.ts +871 -1018
  20. package/dist/index.js +4786 -1631
  21. package/dist/{model-lod-B6BMqS1r.d.ts → model-lod-DPTzeCcD.d.ts} +4 -2
  22. package/dist/playtest.d.ts +5 -4
  23. package/dist/playtest.js +6 -5
  24. package/dist/quality-BADStsTn.d.ts +868 -0
  25. package/dist/react.d.ts +3 -2
  26. package/dist/render-environment.d.ts +170 -0
  27. package/dist/render-environment.js +352 -0
  28. package/dist/{renderer-DvFVoAgj.d.ts → renderer-BtOSseYf.d.ts} +29 -31
  29. package/dist/spells/index.js +1 -1
  30. package/dist/ui-layer.js +3 -2
  31. package/dist/worker.js +12 -5
  32. package/dist/world.d.ts +280 -16
  33. package/dist/world.js +1529 -642
  34. package/mcp/animation-server.mjs +1 -1
  35. package/mcp/engine-server.mjs +135 -11
  36. package/mcp/servers.mjs +4 -4
  37. package/package.json +10 -6
  38. package/scripts/ensure-mcp.mjs +6 -1
  39. package/src/animation-batch.ts +193 -0
  40. package/src/animation-layers.ts +7 -3
  41. package/src/animation.ts +209 -29
  42. package/src/asset-cache.ts +3 -3
  43. package/src/asset-memo.ts +202 -0
  44. package/src/assets.ts +436 -131
  45. package/src/auto-batch.ts +190 -44
  46. package/src/clustered-batch.ts +146 -3
  47. package/src/clustered-mesh.ts +548 -20
  48. package/src/compute-driven.ts +1 -1
  49. package/src/config.ts +8 -0
  50. package/src/debug.ts +119 -22
  51. package/src/dev-global.ts +54 -0
  52. package/src/displaced-surface.ts +428 -0
  53. package/src/engine-hooks.ts +37 -0
  54. package/src/frame-budget.ts +35 -3
  55. package/src/game-boot-phase.ts +269 -0
  56. package/src/game-dev-tools.ts +7 -14
  57. package/src/game-frame-loop.ts +45 -82
  58. package/src/game-startup.ts +145 -70
  59. package/src/game-ui.ts +84 -0
  60. package/src/game.ts +168 -552
  61. package/src/gamepad-mappings.ts +269 -0
  62. package/src/generated/console-markers.ts +14 -0
  63. package/src/geometry-capture.ts +28 -4
  64. package/src/gpu-readings.ts +98 -0
  65. package/src/gpu-scene-bvh.ts +149 -36
  66. package/src/grass-field.ts +628 -0
  67. package/src/hot.ts +4 -7
  68. package/src/index.ts +227 -8
  69. package/src/input.ts +237 -25
  70. package/src/instanced-batch-lod.ts +3 -8
  71. package/src/interpolation.ts +171 -40
  72. package/src/look/ao-admission.ts +4 -3
  73. package/src/look/auto-exposure.ts +5 -16
  74. package/src/look/default-tone-mapping.ts +41 -5
  75. package/src/look/local-exposure.ts +2 -7
  76. package/src/look/quad-pass.ts +21 -0
  77. package/src/look/quality.ts +4 -0
  78. package/src/look/unreal-bloom.ts +4 -13
  79. package/src/look/world-environment.ts +58 -115
  80. package/src/merge-parts.ts +20 -24
  81. package/src/model-lod.ts +97 -14
  82. package/src/particle-significance.ts +12 -0
  83. package/src/particles.ts +19 -10
  84. package/src/platform.ts +23 -4
  85. package/src/profiling/FrameStages.ts +5 -6
  86. package/src/profiling/Spans.ts +3 -17
  87. package/src/profiling/debug-telemetry.ts +2 -6
  88. package/src/profiling/render-list-validate.ts +6 -15
  89. package/src/projection-marker.ts +2 -1
  90. package/src/quiet-markers.ts +3 -10
  91. package/src/render/cpu-bvh.ts +100 -0
  92. package/src/render/depth-pyramid.ts +6 -14
  93. package/src/render/environment/environmentContribution.ts +202 -0
  94. package/src/render/environment/environmentRadiance.ts +44 -0
  95. package/src/render/environment/environmentSampleCache.ts +56 -0
  96. package/src/render/environment/environmentSampling.ts +201 -0
  97. package/src/render/environment/environmentSnapshot.ts +71 -0
  98. package/src/render/environment/gate.ts +57 -0
  99. package/src/render/material-key.ts +21 -1
  100. package/src/render/mesh-pool.ts +3 -19
  101. package/src/render/probe-trace.ts +872 -0
  102. package/src/render/probe-volume.ts +780 -34
  103. package/src/render/radiance-cache.ts +17 -0
  104. package/src/render/screen-probe-gather.ts +303 -0
  105. package/src/render/short-range-ao.ts +274 -0
  106. package/src/render/virtual-shadow-partial.ts +13 -0
  107. package/src/render/virtual-shadow.ts +18 -16
  108. package/src/render/world-impostor-surface.ts +207 -9
  109. package/src/render/world-impostor.ts +5 -2
  110. package/src/render-camera-cull.ts +105 -4
  111. package/src/render-environment.ts +41 -0
  112. package/src/renderer-config.ts +36 -0
  113. package/src/renderer-facts.ts +37 -0
  114. package/src/renderer.ts +78 -32
  115. package/src/resolution-scaler.ts +3 -2
  116. package/src/scatter-field.ts +496 -0
  117. package/src/scene-entry-inspectors.ts +61 -0
  118. package/src/snow-field.ts +1 -0
  119. package/src/startup-offscreen-bytes.ts +84 -0
  120. package/src/state.ts +16 -3
  121. package/src/static-transform.ts +100 -25
  122. package/src/streamed-textures.ts +112 -0
  123. package/src/streaming.ts +68 -4
  124. package/src/texture-streaming.ts +331 -0
  125. package/src/tile-ring.ts +294 -0
  126. package/src/version.ts +1 -1
  127. package/src/warmup.ts +15 -2
  128. package/src/worker.ts +12 -2
  129. package/src/world-bundle-safety.ts +55 -10
  130. package/src/world-cell-batches.ts +166 -200
  131. package/src/world-cell-chunks.ts +3 -7
  132. package/src/world-cell-data.ts +7 -0
  133. package/src/world-cell-impostors.ts +20 -8
  134. package/src/world-cell-models.ts +36 -8
  135. package/src/world-cell-options.ts +2 -14
  136. package/src/world-cell-placements.ts +194 -90
  137. package/src/world-cell-prewarm.ts +39 -4
  138. package/src/world-cell-records.ts +401 -0
  139. package/src/world-cell-render-bundles.ts +2 -2
  140. package/src/world-cell-render-gpu-dress.ts +17 -19
  141. package/src/world-cell-render-main-cull.ts +73 -17
  142. package/src/world-cell-render-util.ts +18 -5
  143. package/src/world-cell-render.ts +13 -5
  144. package/src/world-cell-residency.ts +15 -6
  145. package/src/world-cell-stale.ts +238 -0
  146. package/src/world-cells.ts +23 -6
  147. package/src/world-gpu-flags.ts +18 -50
  148. package/src/world-gpu-reference.ts +22 -8
  149. package/src/world-gpu-scene.ts +44 -24
  150. package/src/world-gpu-shadow.ts +21 -8
  151. package/src/world-gpu-types.ts +41 -13
  152. package/src/world-load-limiter.ts +5 -0
  153. package/src/world-model-sections.ts +80 -0
  154. package/src/world-river-ribbon.ts +273 -0
  155. package/src/world-root-frame.ts +39 -0
  156. package/src/world-shore-field.ts +91 -0
  157. package/src/world-static-pose.ts +163 -0
  158. package/src/world-surface-sampler.ts +48 -0
  159. package/src/world-terrain-splat.ts +10 -18
  160. package/src/world-tile-budget.ts +4 -11
  161. package/src/world-tiles.ts +79 -12
  162. package/src/world-validate.ts +6 -14
  163. package/src/world-warm.ts +51 -0
  164. package/src/world-water-bodies.ts +113 -3
  165. package/src/world.ts +13 -0
@@ -3,6 +3,7 @@ import {
3
3
  BufferGeometry,
4
4
  Group,
5
5
  InstancedMesh,
6
+ type Material,
6
7
  Matrix3,
7
8
  Matrix4,
8
9
  Mesh,
@@ -14,6 +15,8 @@ import * as upstreamWebGPU from "three-mesh-bvh/webgpu";
14
15
  import { storage } from "three/tsl";
15
16
  import { StorageBufferAttribute, type StorageBufferNode, type StructTypeNode } from "three/webgpu";
16
17
  import type { IComputeDriven } from "./compute-driven.js";
18
+ import { buildCpuBvh } from "./render/cpu-bvh.js";
19
+ import type { IProbeTraceScene } from "./render/probe-trace.js";
17
20
  import type { IRendererLike } from "./renderer.js";
18
21
 
19
22
  /** Selects the meshes that become part of a GPU trace set. */
@@ -50,21 +53,26 @@ interface IPackedScene {
50
53
  readonly geometry: BufferGeometry;
51
54
  readonly indices: Uint32Array;
52
55
  readonly materialGroups: readonly IGPUSceneBVHMaterialGroup[];
56
+ readonly materials: readonly Material[];
53
57
  readonly nodes: Uint32Array;
54
58
  readonly normals: Float32Array;
55
59
  readonly objectCount: number;
56
60
  readonly positions: Float32Array;
57
61
  readonly triangleCount: number;
62
+ readonly triangleMaterials: Uint32Array;
58
63
  readonly vertexCount: number;
59
64
  }
60
65
 
61
66
  interface IBuildState {
62
67
  indices: number[];
68
+ /** One slot per distinct Material, in first-seen order: the trace's material table. */
69
+ materialSlots: Map<Material, number>;
63
70
  normals: number[];
64
71
  objectCount: number;
65
72
  positions: number[];
66
73
  triangleCount: number;
67
74
  triangleMaterials: number[];
75
+ triangleSlots: number[];
68
76
  }
69
77
 
70
78
  interface IRange {
@@ -207,7 +215,19 @@ function padVec3(array: Float32Array): Float32Array {
207
215
  return padded;
208
216
  }
209
217
 
218
+ function materialSlot(mesh: Mesh, materialIndex: number, state: IBuildState): number {
219
+ const material = Array.isArray(mesh.material) ? mesh.material[materialIndex] : mesh.material;
220
+ if (material === undefined) return 0;
221
+ let slot = state.materialSlots.get(material);
222
+ if (slot === undefined) {
223
+ slot = state.materialSlots.size;
224
+ state.materialSlots.set(material, slot);
225
+ }
226
+ return slot;
227
+ }
228
+
210
229
  function appendTriangles(
230
+ mesh: Mesh,
211
231
  index: ReturnType<BufferGeometry["getIndex"]>,
212
232
  ranges: readonly IRange[],
213
233
  vertexOffset: number,
@@ -219,8 +239,10 @@ function appendTriangles(
219
239
  state.indices.push(vertexOffset + sourceIndex);
220
240
  }
221
241
  const triangles = range.count / 3;
242
+ const slot = materialSlot(mesh, range.materialIndex, state);
222
243
  for (let triangle = 0; triangle < triangles; triangle += 1) {
223
244
  state.triangleMaterials.push(range.materialIndex);
245
+ state.triangleSlots.push(slot);
224
246
  }
225
247
  state.triangleCount += triangles;
226
248
  }
@@ -242,7 +264,7 @@ function appendMesh(mesh: Mesh, state: IBuildState): void {
242
264
  matrixFor(mesh, instance, matrix);
243
265
  normalMatrix.getNormalMatrix(matrix);
244
266
  appendVertices(mesh, position, normal, matrix, normalMatrix, state);
245
- appendTriangles(index, ranges, vertexOffset, state);
267
+ appendTriangles(mesh, index, ranges, vertexOffset, state);
246
268
  }
247
269
  }
248
270
 
@@ -267,32 +289,66 @@ function materialGroupsFor(materials: Uint32Array): IGPUSceneBVHMaterialGroup[]
267
289
  * it, so a leaf's triangle offset and the material ranges address the same layout.
268
290
  */
269
291
  function permuteToLeafOrder(
270
- bvh: MeshBVH,
292
+ resolveTriangleIndex: (slot: number) => number,
271
293
  sourceIndices: Uint32Array,
272
294
  sourceMaterials: readonly number[],
273
- ): { indices: Uint32Array; materialGroups: IGPUSceneBVHMaterialGroup[] } {
295
+ sourceSlots: readonly number[],
296
+ ): { indices: Uint32Array; materialGroups: IGPUSceneBVHMaterialGroup[]; slots: Uint32Array } {
274
297
  const triangleCount = sourceIndices.length / 3;
275
298
  const indices = new Uint32Array(sourceIndices.length);
276
299
  const materials = new Uint32Array(triangleCount);
300
+ const slots = new Uint32Array(triangleCount);
277
301
  for (let slot = 0; slot < triangleCount; slot += 1) {
278
- const triangle = bvh.resolveTriangleIndex(slot);
302
+ const triangle = resolveTriangleIndex(slot);
279
303
  indices[slot * 3] = sourceIndices[triangle * 3] ?? 0;
280
304
  indices[slot * 3 + 1] = sourceIndices[triangle * 3 + 1] ?? 0;
281
305
  indices[slot * 3 + 2] = sourceIndices[triangle * 3 + 2] ?? 0;
282
306
  materials[slot] = sourceMaterials[triangle] ?? 0;
307
+ slots[slot] = sourceSlots[triangle] ?? 0;
308
+ }
309
+ return { indices, materialGroups: materialGroupsFor(materials), slots };
310
+ }
311
+
312
+ /**
313
+ * The BVH nodes and leaf order. Upstream `MeshBVH` builds them where it builds a tree; the owned engine's
314
+ * `MeshBVH` refuses the build options and holds no tree, so a CPU build (`render/cpu-bvh.ts`) stands in.
315
+ */
316
+ function buildNodes(
317
+ geometry: BufferGeometry,
318
+ positions: Float32Array,
319
+ indices: Uint32Array,
320
+ ): { nodes: Uint32Array; resolveTriangleIndex: (slot: number) => number } {
321
+ try {
322
+ const bvh = new MeshBVH(geometry, {
323
+ indirect: true,
324
+ strategy: SAH,
325
+ targetLeafSize: 10,
326
+ verbose: false,
327
+ });
328
+ const root = MeshBVH.serialize(bvh, { cloneBuffers: false }).roots[0];
329
+ if (root === undefined) throw new Error("GPUSceneBVH could not serialize its root node.");
330
+ return {
331
+ nodes: new Uint32Array(root),
332
+ resolveTriangleIndex: (slot) => bvh.resolveTriangleIndex(slot),
333
+ };
334
+ } catch (error) {
335
+ if (!String((error as Error).message).includes("TN_NATIVE_MESH_BVH")) throw error;
336
+ const built = buildCpuBvh(positions, indices);
337
+ return { nodes: built.nodes, resolveTriangleIndex: (slot) => built.order[slot] as number };
283
338
  }
284
- return { indices, materialGroups: materialGroupsFor(materials) };
285
339
  }
286
340
 
287
341
  function packScene(scene: Object3D, include: (object: Mesh) => boolean): IPackedScene {
288
342
  scene.updateMatrixWorld(true);
289
343
  const state: IBuildState = {
290
344
  indices: [],
345
+ materialSlots: new Map(),
291
346
  normals: [],
292
347
  objectCount: 0,
293
348
  positions: [],
294
349
  triangleCount: 0,
295
350
  triangleMaterials: [],
351
+ triangleSlots: [],
296
352
  };
297
353
  scene.traverse((candidate) => {
298
354
  if (!(candidate instanceof Mesh) || candidate.visible === false || !include(candidate)) return;
@@ -313,32 +369,33 @@ function packScene(scene: Object3D, include: (object: Mesh) => boolean): IPacked
313
369
  let nodes = emptyNodes();
314
370
  let indices: Uint32Array = sourceIndices;
315
371
  let materialGroups: readonly IGPUSceneBVHMaterialGroup[] = [];
372
+ let triangleMaterials: Uint32Array = new Uint32Array(state.triangleSlots);
316
373
  if (state.indices.length > 0) {
317
374
  // Indirect keeps `geometry.index` in source order, so the material assignment collected above
318
375
  // still lines up with it; the leaf order is then applied to both at once below.
319
- const bvh = new MeshBVH(geometry, {
320
- indirect: true,
321
- strategy: SAH,
322
- targetLeafSize: 10,
323
- verbose: false,
324
- });
325
- const serialized = MeshBVH.serialize(bvh, { cloneBuffers: false });
326
- const root = serialized.roots[0];
327
- if (root === undefined) throw new Error("GPUSceneBVH could not serialize its root node.");
328
- nodes = new Uint32Array(root);
329
- const permuted = permuteToLeafOrder(bvh, sourceIndices, state.triangleMaterials);
376
+ const built = buildNodes(geometry, tightPositions, sourceIndices);
377
+ nodes = built.nodes;
378
+ const permuted = permuteToLeafOrder(
379
+ built.resolveTriangleIndex,
380
+ sourceIndices,
381
+ state.triangleMaterials,
382
+ state.triangleSlots,
383
+ );
330
384
  indices = permuted.indices;
331
385
  materialGroups = permuted.materialGroups;
386
+ triangleMaterials = permuted.slots;
332
387
  }
333
388
  return {
334
389
  geometry,
335
390
  indices,
336
391
  materialGroups,
392
+ materials: [...state.materialSlots.keys()],
337
393
  nodes,
338
394
  normals,
339
395
  objectCount: state.objectCount,
340
396
  positions,
341
397
  triangleCount: state.triangleCount,
398
+ triangleMaterials,
342
399
  vertexCount: tightPositions.length / 3,
343
400
  };
344
401
  }
@@ -353,17 +410,23 @@ function packScene(scene: Object3D, include: (object: Mesh) => boolean): IPacked
353
410
  */
354
411
  export class GPUSceneBVH extends Group implements IComputeDriven {
355
412
  #backings: INodeBackings = {
356
- indices: readStorage(new Uint32Array([0, 0, 0]), "uvec3", 3),
357
- nodes: readNodeStorage(emptyNodes()),
358
- normals: readStorage(new Float32Array([0, 1, 0, 0]), "vec3", 4),
359
- positions: readStorage(new Float32Array([0, 0, 0, 0]), "vec3", 4),
413
+ // Each backing is built on first read: the owned engine refuses the upstream node struct and
414
+ // freezes storage nodes, and the probe trace (`traceScene`) needs none of them.
415
+ indices: null,
416
+ nodes: null,
417
+ normals: null,
418
+ positions: null,
419
+ };
420
+ #packedStorage: { indices: Uint32Array; normals: Float32Array; positions: Float32Array } = {
421
+ indices: new Uint32Array([0, 0, 0]),
422
+ normals: new Float32Array([0, 1, 0, 0]),
423
+ positions: new Float32Array([0, 0, 0, 0]),
360
424
  };
361
- readonly indices: StorageBufferNode<"uvec3">;
362
- readonly nodes: StorageBufferNode<"struct">;
363
- readonly normals: StorageBufferNode<"vec3">;
364
- readonly positions: StorageBufferNode<"vec3">;
365
425
  readonly warmupNodes: readonly unknown[] = [];
366
426
  #buildMs = 0;
427
+ #packedNodes: Uint32Array = emptyNodes();
428
+ #traceScene: IProbeTraceScene | undefined;
429
+ #version = 0;
367
430
  #include: (object: Mesh) => boolean;
368
431
  #materialGroups: readonly IGPUSceneBVHMaterialGroup[] = [];
369
432
  #objectCount = 0;
@@ -381,14 +444,50 @@ export class GPUSceneBVH extends Group implements IComputeDriven {
381
444
  }
382
445
  this.#scene = scene;
383
446
  this.#include = options.include ?? (() => true);
384
- this.nodes = this.#backings.nodes as StorageBufferNode<"struct">;
385
- this.positions = this.#backings.positions as StorageBufferNode<"vec3">;
386
- this.indices = this.#backings.indices as StorageBufferNode<"uvec3">;
387
- this.normals = this.#backings.normals as StorageBufferNode<"vec3">;
388
447
  this.addEventListener("removed", this.#onRemoved);
389
448
  this.rebuild();
390
449
  }
391
450
 
451
+ /** Packed triangle indices as a storage node, built on first read. */
452
+ get indices(): StorageBufferNode<"uvec3"> {
453
+ if (this.#released) throw new Error("GPUSceneBVH indices were read after release.");
454
+ this.#backings.indices ??= readStorage(this.#packedStorage.indices, "uvec3", 3);
455
+ return this.#backings.indices;
456
+ }
457
+
458
+ /** Packed vertex normals as a storage node, built on first read. */
459
+ get normals(): StorageBufferNode<"vec3"> {
460
+ if (this.#released) throw new Error("GPUSceneBVH normals were read after release.");
461
+ this.#backings.normals ??= readStorage(this.#packedStorage.normals, "vec3", 4);
462
+ return this.#backings.normals;
463
+ }
464
+
465
+ /** Packed world-space vertex positions as a storage node, built on first read. */
466
+ get positions(): StorageBufferNode<"vec3"> {
467
+ if (this.#released) throw new Error("GPUSceneBVH positions were read after release.");
468
+ this.#backings.positions ??= readStorage(this.#packedStorage.positions, "vec3", 4);
469
+ return this.#backings.positions;
470
+ }
471
+
472
+ /** The upstream TSL query's node table, built on first read. */
473
+ get nodes(): StorageBufferNode<"struct"> {
474
+ if (this.#released) throw new Error("GPUSceneBVH nodes were read after release.");
475
+ this.#backings.nodes ??= readNodeStorage(this.#packedNodes);
476
+ return this.#backings.nodes;
477
+ }
478
+
479
+ /** The CPU snapshot in leaf order, with one material slot per triangle: what `RadianceCache` traces. */
480
+ get traceScene(): IProbeTraceScene {
481
+ if (this.#traceScene === undefined)
482
+ throw new Error("GPUSceneBVH has no snapshot after release.");
483
+ return this.#traceScene;
484
+ }
485
+
486
+ /** Increments on every rebuild, so a consumer of `traceScene` knows to re-upload. */
487
+ get version(): number {
488
+ return this.#version;
489
+ }
490
+
392
491
  get buildMs(): number {
393
492
  return this.#buildMs;
394
493
  }
@@ -426,14 +525,27 @@ export class GPUSceneBVH extends Group implements IComputeDriven {
426
525
  if (this.#released) throw new Error("GPUSceneBVH cannot rebuild after release.");
427
526
  const started = now();
428
527
  const packed = packScene(this.#scene, this.#include);
429
- const nextNodes = readNodeStorage(packed.nodes);
430
- const nextPositions = readStorage(packed.positions, "vec3", 4);
431
- const nextIndices = readStorage(packed.indices, "uvec3", 3);
432
- const nextNormals = readStorage(packed.normals, "vec3", 4);
433
- replaceStorage(this.#backings.nodes as StorageBufferNode<"struct">, nextNodes);
434
- replaceStorage(this.#backings.positions as StorageBufferNode<"vec3">, nextPositions);
435
- replaceStorage(this.#backings.indices as StorageBufferNode<"uvec3">, nextIndices);
436
- replaceStorage(this.#backings.normals as StorageBufferNode<"vec3">, nextNormals);
528
+ this.#packedNodes = packed.nodes;
529
+ if (this.#backings.nodes !== null) {
530
+ replaceStorage(this.#backings.nodes, readNodeStorage(packed.nodes));
531
+ }
532
+ this.#traceScene = {
533
+ indices: packed.indices,
534
+ materials: packed.materials,
535
+ nodes: packed.nodes,
536
+ positions: packed.positions,
537
+ triangleMaterials: packed.triangleMaterials,
538
+ };
539
+ this.#version += 1;
540
+ this.#packedStorage = {
541
+ indices: packed.indices,
542
+ normals: packed.normals,
543
+ positions: packed.positions,
544
+ };
545
+ const { positions, indices, normals } = this.#backings;
546
+ if (positions !== null) replaceStorage(positions, readStorage(packed.positions, "vec3", 4));
547
+ if (indices !== null) replaceStorage(indices, readStorage(packed.indices, "uvec3", 3));
548
+ if (normals !== null) replaceStorage(normals, readStorage(packed.normals, "vec3", 4));
437
549
  this.#packedGeometry?.dispose();
438
550
  this.#packedGeometry = packed.geometry;
439
551
  this.#materialGroups = packed.materialGroups;
@@ -457,6 +569,7 @@ export class GPUSceneBVH extends Group implements IComputeDriven {
457
569
  this.#backings.normals = null;
458
570
  this.#packedGeometry?.dispose();
459
571
  this.#packedGeometry = undefined;
572
+ this.#traceScene = undefined;
460
573
  this.#released = true;
461
574
  }
462
575