@luma.gl/engine 10.0.0-alpha.7 → 10.0.0-alpha.8

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 (129) hide show
  1. package/dist/compute/computation.cjs +3 -0
  2. package/dist/compute/computation.d.ts.map +1 -1
  3. package/dist/compute/computation.js +3 -0
  4. package/dist/compute/computation.js.map +1 -1
  5. package/dist/dist.dev.js +441 -222
  6. package/dist/dist.min.js +59 -59
  7. package/dist/gltf/gltf/gltf-extension-support.cjs +25 -5
  8. package/dist/gltf/gltf/gltf-extension-support.d.ts.map +1 -1
  9. package/dist/gltf/gltf/gltf-extension-support.js +27 -5
  10. package/dist/gltf/gltf/gltf-extension-support.js.map +1 -1
  11. package/dist/gltf/index.cjs.map +1 -1
  12. package/dist/graph/models/index.cjs.map +3 -3
  13. package/dist/graph/physics/index.cjs +3 -0
  14. package/dist/graph/physics/index.cjs.map +3 -3
  15. package/dist/graph/physics/index.d.ts +2 -0
  16. package/dist/graph/physics/index.d.ts.map +1 -1
  17. package/dist/graph/physics/index.js +1 -0
  18. package/dist/graph/physics/index.js.map +1 -1
  19. package/dist/graph/physics/physics-controller-geometry.cjs +203 -0
  20. package/dist/graph/physics/physics-controller-geometry.d.ts +6 -0
  21. package/dist/graph/physics/physics-controller-geometry.d.ts.map +1 -0
  22. package/dist/graph/physics/physics-controller-geometry.js +205 -0
  23. package/dist/graph/physics/physics-controller-geometry.js.map +1 -0
  24. package/dist/graph/physics/physics-controller.cjs +277 -0
  25. package/dist/graph/physics/physics-controller.d.ts +90 -0
  26. package/dist/graph/physics/physics-controller.d.ts.map +1 -0
  27. package/dist/graph/physics/physics-controller.js +266 -0
  28. package/dist/graph/physics/physics-controller.js.map +1 -0
  29. package/dist/graph/physics/scenegraph-instance.cjs +11 -2
  30. package/dist/graph/physics/scenegraph-instance.d.ts +3 -1
  31. package/dist/graph/physics/scenegraph-instance.d.ts.map +1 -1
  32. package/dist/graph/physics/scenegraph-instance.js +11 -0
  33. package/dist/graph/physics/scenegraph-instance.js.map +1 -1
  34. package/dist/graph/physics/scenegraph-motion.cjs +3 -3
  35. package/dist/graph/physics/scenegraph-motion.d.ts +5 -1
  36. package/dist/graph/physics/scenegraph-motion.d.ts.map +1 -1
  37. package/dist/graph/physics/scenegraph-motion.js +3 -3
  38. package/dist/graph/physics/scenegraph-motion.js.map +1 -1
  39. package/dist/graph/physics/scenegraph-publication.cjs +13 -3
  40. package/dist/graph/physics/scenegraph-publication.d.ts +4 -2
  41. package/dist/graph/physics/scenegraph-publication.d.ts.map +1 -1
  42. package/dist/graph/physics/scenegraph-publication.js +14 -3
  43. package/dist/graph/physics/scenegraph-publication.js.map +1 -1
  44. package/dist/graph/physics/scenegraph-session.cjs +11 -1
  45. package/dist/graph/physics/scenegraph-session.d.ts +11 -2
  46. package/dist/graph/physics/scenegraph-session.d.ts.map +1 -1
  47. package/dist/graph/physics/scenegraph-session.js +13 -1
  48. package/dist/graph/physics/scenegraph-session.js.map +1 -1
  49. package/dist/graph/tables/index.cjs.map +3 -3
  50. package/dist/index.cjs +3 -0
  51. package/dist/index.cjs.map +3 -3
  52. package/dist/index.d.ts +2 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +1 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/model/batch-uniform-buffer.cjs +70 -0
  57. package/dist/model/batch-uniform-buffer.d.ts +21 -0
  58. package/dist/model/batch-uniform-buffer.d.ts.map +1 -0
  59. package/dist/model/batch-uniform-buffer.js +48 -0
  60. package/dist/model/batch-uniform-buffer.js.map +1 -0
  61. package/dist/model/gpu-vector-bindings.cjs +57 -16
  62. package/dist/model/gpu-vector-bindings.d.ts.map +1 -1
  63. package/dist/model/gpu-vector-bindings.js +65 -15
  64. package/dist/model/gpu-vector-bindings.js.map +1 -1
  65. package/dist/model/gpu-vector-draw-batches.cjs +4 -2
  66. package/dist/model/gpu-vector-draw-batches.d.ts.map +1 -1
  67. package/dist/model/gpu-vector-draw-batches.js +5 -2
  68. package/dist/model/gpu-vector-draw-batches.js.map +1 -1
  69. package/dist/model/gpu-vector-model-batches.d.ts +5 -0
  70. package/dist/model/gpu-vector-model-batches.d.ts.map +1 -1
  71. package/dist/model/gpu-vector-model-batches.js.map +1 -1
  72. package/dist/model/gpu-vector-model.cjs +41 -3
  73. package/dist/model/gpu-vector-model.d.ts +8 -1
  74. package/dist/model/gpu-vector-model.d.ts.map +1 -1
  75. package/dist/model/gpu-vector-model.js +44 -2
  76. package/dist/model/gpu-vector-model.js.map +1 -1
  77. package/dist/model/model.cjs +8 -0
  78. package/dist/model/model.d.ts +3 -0
  79. package/dist/model/model.d.ts.map +1 -1
  80. package/dist/model/model.js +8 -0
  81. package/dist/model/model.js.map +1 -1
  82. package/dist/scenegraph/geometry-node.cjs +47 -0
  83. package/dist/scenegraph/geometry-node.d.ts +13 -0
  84. package/dist/scenegraph/geometry-node.d.ts.map +1 -0
  85. package/dist/scenegraph/geometry-node.js +26 -0
  86. package/dist/scenegraph/geometry-node.js.map +1 -0
  87. package/dist/scenegraph/group-node.cjs +42 -0
  88. package/dist/scenegraph/group-node.d.ts +8 -0
  89. package/dist/scenegraph/group-node.d.ts.map +1 -1
  90. package/dist/scenegraph/group-node.js +47 -1
  91. package/dist/scenegraph/group-node.js.map +1 -1
  92. package/dist/scenegraph/transform-source.cjs +15 -0
  93. package/dist/scenegraph/transform-source.d.ts +24 -0
  94. package/dist/scenegraph/transform-source.d.ts.map +1 -0
  95. package/dist/scenegraph/transform-source.js +5 -0
  96. package/dist/scenegraph/transform-source.js.map +1 -0
  97. package/dist/splats/gpu-splat-graph-renderer.d.ts +1 -1
  98. package/dist/splats/gpu-splat-graph-renderer.d.ts.map +1 -1
  99. package/dist/splats/index.cjs.map +1 -1
  100. package/dist/splats/splat-renderer.cjs +6 -1
  101. package/dist/splats/splat-renderer.d.ts +3 -0
  102. package/dist/splats/splat-renderer.d.ts.map +1 -1
  103. package/dist/splats/splat-renderer.js +6 -1
  104. package/dist/splats/splat-renderer.js.map +1 -1
  105. package/dist/splats/splat-sort.d.ts +1 -1
  106. package/dist/splats/splat-sort.d.ts.map +1 -1
  107. package/package.json +8 -8
  108. package/src/compute/computation.ts +3 -0
  109. package/src/gltf/gltf/gltf-extension-support.ts +27 -5
  110. package/src/graph/physics/index.ts +10 -0
  111. package/src/graph/physics/physics-controller-geometry.ts +264 -0
  112. package/src/graph/physics/physics-controller.ts +348 -0
  113. package/src/graph/physics/scenegraph-instance.ts +12 -1
  114. package/src/graph/physics/scenegraph-motion.ts +14 -3
  115. package/src/graph/physics/scenegraph-publication.ts +24 -4
  116. package/src/graph/physics/scenegraph-session.ts +35 -3
  117. package/src/index.ts +6 -0
  118. package/src/model/batch-uniform-buffer.ts +51 -0
  119. package/src/model/gpu-vector-bindings.ts +77 -19
  120. package/src/model/gpu-vector-draw-batches.ts +5 -2
  121. package/src/model/gpu-vector-model-batches.ts +5 -0
  122. package/src/model/gpu-vector-model.ts +47 -2
  123. package/src/model/model.ts +10 -0
  124. package/src/scenegraph/geometry-node.ts +31 -0
  125. package/src/scenegraph/group-node.ts +54 -1
  126. package/src/scenegraph/transform-source.ts +30 -0
  127. package/src/splats/gpu-splat-graph-renderer.ts +1 -1
  128. package/src/splats/splat-renderer.ts +9 -1
  129. package/src/splats/splat-sort.ts +1 -1
@@ -3,7 +3,12 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Matrix4} from '@math.gl/core';
6
- import {GroupNode, decomposePhysicsTransform, type ScenegraphNode} from '../../index';
6
+ import {
7
+ GroupNode,
8
+ decomposePhysicsTransform,
9
+ type ScenegraphNode,
10
+ type ScenegraphBounds
11
+ } from '../../index';
7
12
  import type {GPURigidBodyWorld} from '@luma.gl/graph/gpu-physics';
8
13
  import type {GPURigidBodyBounds} from '@luma.gl/graph/gpu-physics';
9
14
 
@@ -17,11 +22,16 @@ export type ScenegraphPhysicsRenderBinding = {
17
22
  /** Authoring transforms feed GPU publication metadata; simulated poses never come back. */
18
23
  export class ScenegraphPhysicsPublication {
19
24
  readonly bindings = new Map<ScenegraphNode, ScenegraphPhysicsRenderBinding>();
25
+ readonly transformBindings = new Map<
26
+ ScenegraphNode,
27
+ import('../../scenegraph/transform-source').ScenegraphTransformBinding
28
+ >();
20
29
  private boundsKey = '';
21
30
  constructor(
22
31
  readonly world: GPURigidBodyWorld,
23
32
  readonly roots: readonly ScenegraphNode[],
24
- readonly bodies: ReadonlyMap<ScenegraphNode, number>
33
+ readonly bodies: ReadonlyMap<ScenegraphNode, number>,
34
+ readonly localBounds?: ReadonlyMap<ScenegraphNode, ScenegraphBounds>
25
35
  ) {
26
36
  if (!world.poseMatrices || !world.poseBounds)
27
37
  throw new Error('Scene publication requires pose and bounds buffers');
@@ -69,7 +79,10 @@ export class ScenegraphPhysicsPublication {
69
79
  throw new Error('Invalid publication body');
70
80
  bindings.set(node, {body, localMatrix, visible: displayed});
71
81
  // Group bounds include descendants, which may belong to independent child bodies.
72
- const localBounds = node instanceof GroupNode ? null : node.getBounds();
82
+ const localBounds =
83
+ node instanceof GroupNode
84
+ ? null
85
+ : (node.getBounds() ?? this.localBounds?.get(node) ?? null);
73
86
  if (
74
87
  localBounds &&
75
88
  (localBounds.length !== 2 ||
@@ -111,6 +124,13 @@ export class ScenegraphPhysicsPublication {
111
124
  this.boundsKey = key;
112
125
  }
113
126
  this.bindings.clear();
114
- for (const [node, binding] of bindings) this.bindings.set(node, binding);
127
+ this.transformBindings.clear();
128
+ for (const [node, binding] of bindings) {
129
+ this.bindings.set(node, binding);
130
+ this.transformBindings.set(node, {
131
+ matrixIndex: binding.body,
132
+ localMatrix: binding.localMatrix
133
+ });
134
+ }
115
135
  }
116
136
  }
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import type {Device} from '@luma.gl/core';
6
- import {GroupNode, type ScenegraphNode} from '../../index';
5
+ import {assert, type Device, type CommandEncoder} from '@luma.gl/core';
6
+ import {GroupNode, type ScenegraphNode, type ScenegraphBounds} from '../../index';
7
7
  import {
8
8
  ScenegraphPhysicsInstance,
9
9
  type ScenegraphPhysicsDefinition,
@@ -22,6 +22,8 @@ export type ScenegraphPhysicsScene = {
22
22
  roots: readonly ScenegraphNode[];
23
23
  definition: ScenegraphPhysicsDefinition;
24
24
  colliders?: readonly ScenegraphPhysicsColliderTarget[];
25
+ /** Prepared local visual bounds for geometry nodes that do not expose getBounds(). */
26
+ localBounds?: ReadonlyMap<ScenegraphNode, ScenegraphBounds>;
25
27
  properties?: (world: GPURigidBodyWorld) => ScenegraphPhysicsProperties;
26
28
  behaviors?: ScenegraphPhysicsBehaviorProps;
27
29
  };
@@ -102,7 +104,12 @@ export class ScenegraphPhysicsSession {
102
104
  scene.definition.bodies,
103
105
  scene.colliders
104
106
  ),
105
- publication: new ScenegraphPhysicsPublication(world, scene.roots, scene.definition.bodies),
107
+ publication: new ScenegraphPhysicsPublication(
108
+ world,
109
+ scene.roots,
110
+ scene.definition.bodies,
111
+ scene.localBounds
112
+ ),
106
113
  properties: scene.properties?.(world) ?? new ScenegraphPhysicsProperties(world, new Map()),
107
114
  behaviors: scene.behaviors
108
115
  ? new ScenegraphPhysicsBehaviors(world, scene.behaviors)
@@ -127,6 +134,31 @@ export class ScenegraphPhysicsSession {
127
134
  }
128
135
  }
129
136
 
137
+ /** Encode a fixed-step batch after sampling animation; the caller owns submission. */
138
+ encode(
139
+ encoder: CommandEncoder,
140
+ {
141
+ steps = 1,
142
+ animatedNodes = new Set<ScenegraphNode>(),
143
+ excludedNodes,
144
+ targetNodes
145
+ }: {
146
+ steps?: number;
147
+ animatedNodes?: ReadonlySet<ScenegraphNode>;
148
+ excludedNodes?: ReadonlySet<ScenegraphNode>;
149
+ targetNodes?: ReadonlySet<ScenegraphNode>;
150
+ } = {}
151
+ ): void {
152
+ // Synchronous frame encoding must not overlap readback, reset, rebuild or destruction.
153
+ assert(!this.pending && !this.closing);
154
+ // Validate the batch before mutating animation ownership or targets.
155
+ assert(Number.isSafeInteger(steps) && steps > 0);
156
+ this.motion.setAnimatedNodes(animatedNodes, {excludedNodes, targetNodes});
157
+ this.motion.update();
158
+ this.publication.update();
159
+ this.instance.encode(encoder, steps);
160
+ }
161
+
130
162
  /** Sample/blend first; declare active transform tracks, including paused tracks, explicitly. */
131
163
  async step(
132
164
  animatedNodes: ReadonlySet<ScenegraphNode> = new Set(),
package/src/index.ts CHANGED
@@ -85,6 +85,12 @@ export type {
85
85
  GroupNodeProps
86
86
  } from './scenegraph/group-node';
87
87
  export {GroupNode} from './scenegraph/group-node';
88
+ export {GeometryNode, type GeometryNodeProps} from './scenegraph/geometry-node';
89
+ export type {
90
+ ScenegraphTransformSource,
91
+ ScenegraphTransformFrame,
92
+ ScenegraphTransformBinding
93
+ } from './scenegraph/transform-source';
88
94
  export type {ModelNodeProps} from './scenegraph/model-node';
89
95
  export {ModelNode} from './scenegraph/model-node';
90
96
 
@@ -0,0 +1,51 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Buffer, assert, type Device} from '@luma.gl/core';
6
+
7
+ /** Engine-owned aligned uniform slots, reused between submitted batch draws. */
8
+ export class BatchUniformBuffer {
9
+ private buffer?: Buffer;
10
+ private byteOffset = 0;
11
+
12
+ constructor(private readonly device: Device) {}
13
+
14
+ /** Reserves the entire call before drawing, so growth cannot invalidate an earlier batch. */
15
+ prepare(byteLength: number): void {
16
+ if (!this.buffer || this.buffer.byteLength < byteLength) {
17
+ const capacity = Math.max(1024, (this.buffer?.byteLength ?? 0) * 2, byteLength);
18
+ const buffer = this.device.createBuffer({
19
+ id: 'batch-uniforms',
20
+ byteLength: capacity,
21
+ usage: Buffer.UNIFORM | Buffer.COPY_DST
22
+ });
23
+ this.buffer?.destroy();
24
+ this.buffer = buffer;
25
+ }
26
+ this.byteOffset = 0;
27
+ }
28
+
29
+ /** Returns the aligned slot size required for a uniform block. */
30
+ getAlignedByteLength(byteLength: number): number {
31
+ const alignment = this.device.limits.minUniformBufferOffsetAlignment || 1;
32
+ return Math.ceil(byteLength / alignment) * alignment;
33
+ }
34
+
35
+ /** Writes one slot without overwriting earlier batches in this call. */
36
+ write(data: Uint8Array): {buffer: Buffer; offset: number; size: number} {
37
+ // prepare() must reserve enough space for all blocks in all batches before drawing.
38
+ assert(this.buffer && this.byteOffset + data.byteLength <= this.buffer.byteLength);
39
+ const binding = {buffer: this.buffer, offset: this.byteOffset, size: data.byteLength};
40
+ this.buffer.write(data, binding.offset);
41
+ this.byteOffset += this.getAlignedByteLength(data.byteLength);
42
+ return binding;
43
+ }
44
+
45
+ /** Releases the model-owned allocation. */
46
+ destroy(): void {
47
+ this.buffer?.destroy();
48
+ this.buffer = undefined;
49
+ this.byteOffset = 0;
50
+ }
51
+ }
@@ -66,26 +66,22 @@ export class GPUVectorBindings {
66
66
  Object.entries(columns).flatMap<BufferLayout>(([name, column]) =>
67
67
  column && !isConstant(column) && column.bufferLayout ? [{...column.bufferLayout, name}] : []
68
68
  );
69
- const layouts: BufferLayout[] = [
70
- ...providedLayouts,
71
- ...Object.entries(columns).flatMap<BufferLayout>(([name, column]) => {
72
- if (
73
- !column ||
74
- providedLayouts.some(
75
- layout =>
76
- layout.name === name ||
77
- layout.attributes?.some(attribute => attribute.attribute === name)
78
- )
69
+ const inferredLayouts = Object.entries(columns).flatMap<BufferLayout>(([name, column]) => {
70
+ if (
71
+ !column ||
72
+ providedLayouts.some(
73
+ layout =>
74
+ layout.name === name ||
75
+ layout.attributes?.some(attribute => attribute.attribute === name)
79
76
  )
80
- return [];
81
- assert(column.format);
82
- const format = column.format as VertexFormat;
83
- const byteStride = isConstant(column) ? 0 : column.byteStride;
84
- return [
85
- {name, stepMode, byteStride, attributes: [{attribute: name, format, byteOffset: 0}]}
86
- ];
87
- })
88
- ];
77
+ )
78
+ return [];
79
+ assert(column.format);
80
+ const format = column.format as VertexFormat;
81
+ const byteStride = isConstant(column) ? 0 : column.byteStride;
82
+ return [{name, stepMode, byteStride, attributes: [{attribute: name, format, byteOffset: 0}]}];
83
+ });
84
+ const layouts = [...providedLayouts, ...consolidateInferredLayouts(columns, inferredLayouts)];
89
85
  for (const [name, column] of Object.entries(columns)) {
90
86
  if (!column) continue;
91
87
  // Inputs must describe a typed vector or a typed constant, never raw buffers or arrays.
@@ -274,3 +270,65 @@ function getShaderConstant(column: GPUVectorModelConstant): TypedArray {
274
270
  return information.signed ? new Int32Array(values) : new Uint32Array(values);
275
271
  return new Float32Array(values);
276
272
  }
273
+
274
+ /** Consolidates inferred views without changing stored bytes or caller-owned layouts. */
275
+ function consolidateInferredLayouts(
276
+ columns: GPUVectorModelAttributes,
277
+ layouts: BufferLayout[]
278
+ ): BufferLayout[] {
279
+ const result: BufferLayout[] = [];
280
+ let constantLayout: BufferLayout | undefined;
281
+ let constantByteLength = 0;
282
+ // Start with the lowest offset so shared views have nonnegative attribute offsets.
283
+ const sortedLayouts = [...layouts].sort((left, right) => {
284
+ const leftColumn = columns[left.name];
285
+ const rightColumn = columns[right.name];
286
+ return (
287
+ (leftColumn && !isConstant(leftColumn) ? (leftColumn.data[0]?.byteOffset ?? 0) : 0) -
288
+ (rightColumn && !isConstant(rightColumn) ? (rightColumn.data[0]?.byteOffset ?? 0) : 0)
289
+ );
290
+ });
291
+ for (const layout of sortedLayouts) {
292
+ const column = columns[layout.name]!;
293
+ const attribute = layout.attributes![0];
294
+ if (isConstant(column)) {
295
+ if (!constantLayout) {
296
+ constantLayout = {...layout, attributes: []};
297
+ result.push(constantLayout);
298
+ }
299
+ const alignment = Math.min(4, column.byteLength);
300
+ constantByteLength = Math.ceil(constantByteLength / alignment) * alignment;
301
+ constantLayout.attributes!.push({...attribute, byteOffset: constantByteLength});
302
+ constantByteLength += column.byteLength;
303
+ continue;
304
+ }
305
+ const sharedLayout = result.find(candidate => {
306
+ const primary = columns[candidate.name];
307
+ if (!primary || isConstant(primary) || !primary.data.length || !column.data.length)
308
+ return false;
309
+ const offset = column.data[0].byteOffset - primary.data[0].byteOffset;
310
+ return (
311
+ candidate.stepMode === layout.stepMode &&
312
+ candidate.byteStride === layout.byteStride &&
313
+ offset >= 0 &&
314
+ offset + column.rowByteLength <= column.byteStride &&
315
+ column.data.every((chunk, index) => {
316
+ const primaryChunk = primary.data[index];
317
+ return (
318
+ chunk.buffer === primaryChunk.buffer &&
319
+ chunk.byteStride === primaryChunk.byteStride &&
320
+ chunk.byteOffset - primaryChunk.byteOffset === offset
321
+ );
322
+ })
323
+ );
324
+ });
325
+ if (sharedLayout) {
326
+ const primary = columns[sharedLayout.name] as GPUVectorModelInput;
327
+ sharedLayout.attributes!.push({
328
+ ...attribute,
329
+ byteOffset: column.data[0].byteOffset - primary.data[0].byteOffset
330
+ });
331
+ } else result.push({...layout, attributes: [...layout.attributes!]});
332
+ }
333
+ return result;
334
+ }
@@ -25,6 +25,9 @@ export function drawGPUVectorGroups(
25
25
  const attributeInputs = attributes.inputs;
26
26
  const geometryLayouts = geometry.sourceLayouts;
27
27
  const attributeLayouts = attributes.sourceLayouts;
28
+ // Keep the full group's inference stable when selecting individual chunks.
29
+ const geometryBatchLayouts = geometry.layouts;
30
+ const attributeBatchLayouts = attributes.layouts;
28
31
  const attributeStepMode = attributes.stepMode;
29
32
  const geometryBatchCount = geometry.batchCount;
30
33
  const attributeBatchCount = attributes.batchCount;
@@ -52,10 +55,10 @@ export function drawGPUVectorGroups(
52
55
  const attributeBatchIndex = independentInstances
53
56
  ? batchIndex % attributeBatchCount
54
57
  : Math.min(batchIndex, attributeBatchCount - 1);
55
- geometry.setInputs(geometryBatches[geometryBatchIndex], geometryLayouts, 'vertex');
58
+ geometry.setInputs(geometryBatches[geometryBatchIndex], geometryBatchLayouts, 'vertex');
56
59
  attributes.setInputs(
57
60
  attributeBatches[attributeBatchIndex],
58
- attributeLayouts,
61
+ attributeBatchLayouts,
59
62
  attributeStepMode
60
63
  );
61
64
  syncBindings();
@@ -50,6 +50,11 @@ export type GPUVectorModelDrawBatchesOptions<
50
50
  Inputs extends GPUVectorModelInputs = GPUVectorModelInputs
51
51
  > = {
52
52
  vectors: Inputs;
53
+ /**
54
+ * Runs synchronously before each chunk draw. Managed uniforms use distinct aligned slots
55
+ * within this call; submit before reusing slots with different values in another call.
56
+ * External buffers remain caller-managed. Row offsets are cumulative.
57
+ */
53
58
  onBatch?: (batch: GPUVectorModelBatch<NonNullable<Inputs[keyof Inputs]>['data'][number]>) => void;
54
59
  };
55
60
 
@@ -42,6 +42,7 @@ import {mergeShaderPluginModules, resolveShaderPlugins, ShaderAssembler} from '@
42
42
  import {GLSLShaderAssembler} from '@luma.gl/shaders/glsl';
43
43
  import {WGSLShaderAssembler} from '@luma.gl/shaders/wgsl';
44
44
 
45
+ import {BatchUniformBuffer} from './batch-uniform-buffer';
45
46
  import {getDebugTableForShaderLayout} from '../debug/debug-shader-layout';
46
47
  import {debugFramebuffer} from '../debug/debug-framebuffer';
47
48
  import {deepEqual} from '../utils/deep-equal';
@@ -339,6 +340,7 @@ export class GPUVectorModel {
339
340
 
340
341
  _attributeInfos: Record<string, AttributeInfo> = {};
341
342
  protected props: Required<GPUVectorModelProps>;
343
+ private batchUniformBuffer?: BatchUniformBuffer;
342
344
  private geometryVectorBindings!: GPUVectorBindings;
343
345
  private attributeVectorBindings!: GPUVectorBindings;
344
346
  private explicitBufferLayout: BufferLayout[] = [];
@@ -476,6 +478,7 @@ export class GPUVectorModel {
476
478
  ...this.props,
477
479
  modules,
478
480
  defines,
481
+ pluginHooks: resolvedPlugins.hooks,
479
482
  pluginInjections: resolvedPlugins.injections,
480
483
  pluginVertexInputs: resolvedPlugins.vertexInputs,
481
484
  pluginInterStageVariables: resolvedPlugins.interStageVariables
@@ -513,6 +516,7 @@ export class GPUVectorModel {
513
516
  ...this.props,
514
517
  modules,
515
518
  defines,
519
+ pluginHooks: resolvedPlugins.hooks,
516
520
  pluginInjections: resolvedPlugins.injections,
517
521
  pluginVertexInputs: resolvedPlugins.vertexInputs,
518
522
  pluginInterStageVariables: resolvedPlugins.interStageVariables
@@ -610,6 +614,7 @@ export class GPUVectorModel {
610
614
  this.geometryVectorBindings.destroy();
611
615
  this.attributeVectorBindings.destroy();
612
616
  this._uniformStore?.destroy();
617
+ this.batchUniformBuffer?.destroy();
613
618
  this._destroyed = true;
614
619
  }
615
620
  }
@@ -1007,7 +1012,13 @@ export class GPUVectorModel {
1007
1012
  }
1008
1013
  }
1009
1014
 
1010
- /** Draws each aligned physical chunk without retaining or taking ownership of input vectors. */
1015
+ /**
1016
+ * Draws each aligned physical chunk without taking ownership of input vectors.
1017
+ * Each batch uses a separate aligned slot for managed shader-input uniforms set by
1018
+ * `onBatch`. Slots are reused on each call: submit previous draws before changing their
1019
+ * values or growing the allocation. Explicit buffers remain caller-managed. Vector
1020
+ * lengths and physical chunk boundaries must match.
1021
+ */
1011
1022
  drawBatches<Inputs extends GPUVectorModelInputs = GPUVectorModelInputs>(
1012
1023
  renderPass: RenderPass,
1013
1024
  {vectors, onBatch}: GPUVectorModelDrawBatchesOptions<Inputs>
@@ -1026,6 +1037,20 @@ export class GPUVectorModel {
1026
1037
  const previousIsInstanced = this.isInstanced;
1027
1038
  const previousVertexCountSet = this._vertexCountSet;
1028
1039
  const drawingVectorBatches = this.drawingVectorBatches;
1040
+ const batchUniformStore =
1041
+ this.device.type === 'webgpu' && batches.length
1042
+ ? new UniformStore(this.device, this.shaderInputs.modules)
1043
+ : undefined;
1044
+ if (batchUniformStore && this._uniformStore.uniformBuffers.size) {
1045
+ this.batchUniformBuffer ??= new BatchUniformBuffer(this.device);
1046
+ let batchByteLength = 0;
1047
+ for (const moduleName of this._uniformStore.uniformBuffers.keys()) {
1048
+ batchByteLength += this.batchUniformBuffer.getAlignedByteLength(
1049
+ batchUniformStore.getUniformBufferData(moduleName).byteLength
1050
+ );
1051
+ }
1052
+ this.batchUniformBuffer.prepare(batchByteLength * batches.length);
1053
+ }
1029
1054
  this.drawingVectorBatches = true;
1030
1055
  let drawSuccess = true;
1031
1056
  try {
@@ -1033,9 +1058,29 @@ export class GPUVectorModel {
1033
1058
  this.setGPUData(batch.data);
1034
1059
  this.setBatchDrawCount(batch.rowCount);
1035
1060
  onBatch?.(batch);
1036
- drawSuccess = GPUVectorModel.prototype.draw.call(this, renderPass) && drawSuccess;
1061
+ const managedBindings: Record<string, ModelBinding> = {};
1062
+ try {
1063
+ if (batchUniformStore) {
1064
+ batchUniformStore.setUniforms(this.shaderInputs.getUniformValues());
1065
+ for (const [moduleName, buffer] of this._uniformStore.uniformBuffers) {
1066
+ const bindingName = `${moduleName}Uniforms`;
1067
+ // Explicit bindings are caller-owned and must not be replaced.
1068
+ if (this.bindings[bindingName] !== buffer) continue;
1069
+ managedBindings[bindingName] = buffer;
1070
+ this.setBindings({
1071
+ [bindingName]: this.batchUniformBuffer!.write(
1072
+ batchUniformStore.getUniformBufferData(moduleName)
1073
+ )
1074
+ });
1075
+ }
1076
+ }
1077
+ drawSuccess = GPUVectorModel.prototype.draw.call(this, renderPass) && drawSuccess;
1078
+ } finally {
1079
+ this.setBindings(managedBindings);
1080
+ }
1037
1081
  }
1038
1082
  } finally {
1083
+ batchUniformStore?.destroy();
1039
1084
  this.setAttributes(previousAttributes, {byteOffsets: previousAttributeByteOffsets});
1040
1085
  for (const name of Object.keys(this.bindings)) {
1041
1086
  if (!(name in previousBindings)) delete this.bindings[name];
@@ -34,6 +34,12 @@ export class Model extends GPUVectorModel {
34
34
  declare material: Material | null;
35
35
  declare _gpuGeometry: GPUGeometry | null;
36
36
  private declare indexCountOverride: number | undefined;
37
+ private declare sourceGeometryValue: ModelProps['geometry'];
38
+
39
+ /** Borrowed source geometry, retained for scene adapters such as physics cooking. */
40
+ get sourceGeometry(): ModelProps['geometry'] {
41
+ return this.sourceGeometryValue;
42
+ }
37
43
 
38
44
  constructor(device: Device, props: ModelProps) {
39
45
  const sourceGeometry =
@@ -56,12 +62,14 @@ export class Model extends GPUVectorModel {
56
62
  throw error;
57
63
  }
58
64
  this._gpuGeometry = gpuGeometry;
65
+ this.sourceGeometryValue = sourceGeometry;
59
66
  if (gpuGeometry) this.setIndexCount(this.props.indexCount);
60
67
  }
61
68
 
62
69
  protected override _initializeProps(props: GPUVectorModelProps & {material?: Material}): void {
63
70
  this.material = props.material || null;
64
71
  this._gpuGeometry = null;
72
+ this.sourceGeometryValue = null;
65
73
  super._initializeProps(props);
66
74
  }
67
75
 
@@ -75,6 +83,7 @@ export class Model extends GPUVectorModel {
75
83
  super.destroy();
76
84
  this._gpuGeometry?.destroy();
77
85
  this._gpuGeometry = null;
86
+ this.sourceGeometryValue = null;
78
87
  }
79
88
 
80
89
  /** Adapts CPU and legacy buffer geometry into the GPU vector geometry API. */
@@ -89,6 +98,7 @@ export class Model extends GPUVectorModel {
89
98
  : geometry;
90
99
  super.setGeometry(vectorGeometry instanceof GPUVectorGeometry ? vectorGeometry : null);
91
100
  if (!(geometry instanceof GPUVectorGeometry)) super.setIndexCount(this.indexCountOverride);
101
+ this.sourceGeometryValue = geometry;
92
102
  }
93
103
 
94
104
  override setIndexCount(indexCount: number | undefined): void {
@@ -0,0 +1,31 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {Geometry} from '../geometry/geometry';
6
+ import {ScenegraphNode, type ScenegraphNodeProps} from './scenegraph-node';
7
+ import type {ScenegraphBounds} from './scenegraph-bounds';
8
+
9
+ export type GeometryNodeProps = ScenegraphNodeProps & {geometry: Geometry};
10
+
11
+ /** Retained CPU geometry shared by render adapters and collider cooking. */
12
+ export class GeometryNode extends ScenegraphNode {
13
+ readonly geometry: Geometry;
14
+ constructor(props: GeometryNodeProps) {
15
+ super(props);
16
+ this.geometry = props.geometry;
17
+ }
18
+
19
+ override getBounds(): ScenegraphBounds | null {
20
+ const positions = this.geometry.attributes['POSITION'];
21
+ if (!positions || positions.size !== 3 || !positions.value.length) return null;
22
+ const minimum: [number, number, number] = [Infinity, Infinity, Infinity];
23
+ const maximum: [number, number, number] = [-Infinity, -Infinity, -Infinity];
24
+ for (let index = 0; index < positions.value.length; index++) {
25
+ const axis = index % 3;
26
+ minimum[axis] = Math.min(minimum[axis], positions.value[index]);
27
+ maximum[axis] = Math.max(maximum[axis], positions.value[index]);
28
+ }
29
+ return [minimum, maximum];
30
+ }
31
+ }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import {Matrix4, Vector3} from '@math.gl/core';
6
6
  import type {NumericArray} from '@math.gl/core';
7
- import {log} from '@luma.gl/core';
7
+ import {assert, log} from '@luma.gl/core';
8
8
  import {ScenegraphNode, ScenegraphNodeProps} from './scenegraph-node';
9
9
  import {
10
10
  areScenegraphBoundsDefined,
@@ -12,9 +12,11 @@ import {
12
12
  makeEmptyScenegraphBounds
13
13
  } from './scenegraph-bounds';
14
14
  import type {ScenegraphBounds} from './scenegraph-bounds';
15
+ import type {ScenegraphTransformSource} from './transform-source';
15
16
 
16
17
  export type GroupNodeProps = ScenegraphNodeProps & {
17
18
  children?: ScenegraphNode[];
19
+ transformSource?: ScenegraphTransformSource;
18
20
  };
19
21
 
20
22
  /** Camera-relative ordering options for a flattened scenegraph traversal. */
@@ -33,6 +35,8 @@ export type DepthSortedTraversalContext = {
33
35
 
34
36
  export class GroupNode extends ScenegraphNode {
35
37
  children: ScenegraphNode[];
38
+ /** Optional evaluated GPU poses; authored matrices remain unchanged. */
39
+ transformSource: ScenegraphTransformSource | null;
36
40
 
37
41
  constructor(children: ScenegraphNode[]);
38
42
  constructor(props?: GroupNodeProps);
@@ -46,6 +50,7 @@ export class GroupNode extends ScenegraphNode {
46
50
  );
47
51
  super(props);
48
52
  this.children = children;
53
+ this.transformSource = props.transformSource ?? null;
49
54
  }
50
55
 
51
56
  override getBounds(): ScenegraphBounds | null {
@@ -94,6 +99,54 @@ export class GroupNode extends ScenegraphNode {
94
99
  return this;
95
100
  }
96
101
 
102
+ /** Resolve one exact ID or path. Missing nodes return undefined; ambiguous paths throw. */
103
+ findNode(path: string): ScenegraphNode | undefined {
104
+ const matches = this.findNodes(path);
105
+ if (matches.length > 1) {
106
+ throw new Error(`Ambiguous scenegraph path: ${path} (${matches.length} matches)`);
107
+ }
108
+ return matches[0];
109
+ }
110
+
111
+ /** Find structural matches in preorder, including hidden nodes and the search root. */
112
+ findNodes(path: string): ScenegraphNode[] {
113
+ const anchored = path.startsWith('/');
114
+ const segments =
115
+ path === '/'
116
+ ? []
117
+ : (anchored ? path.slice(1) : path).split('/').map(segment => {
118
+ if (!segment || /~(?![01])/.test(segment)) {
119
+ throw new Error(`Invalid scenegraph path: ${path}`);
120
+ }
121
+ return segment.replace(/~1/g, '/').replace(/~0/g, '~');
122
+ });
123
+ const matches: ScenegraphNode[] = [];
124
+ const ancestors: string[] = [];
125
+ const visited = new Set<ScenegraphNode>();
126
+ const pending: {node: ScenegraphNode; depth: number}[] = [{node: this, depth: 0}];
127
+ while (pending.length) {
128
+ const {node, depth} = pending.pop()!;
129
+ // Structural lookup requires a tree: cycles and shared node objects are invalid.
130
+ assert(!visited.has(node));
131
+ visited.add(node);
132
+ ancestors.length = depth;
133
+ ancestors.push(node.id);
134
+ const offset = ancestors.length - segments.length;
135
+ if (
136
+ (anchored ? offset === 1 : offset >= 0) &&
137
+ segments.every((segment, index) => segment === ancestors[offset + index])
138
+ ) {
139
+ matches.push(node);
140
+ }
141
+ if (node instanceof GroupNode) {
142
+ for (let index = node.children.length - 1; index >= 0; index--) {
143
+ pending.push({node: node.children[index], depth: depth + 1});
144
+ }
145
+ }
146
+ }
147
+ return matches;
148
+ }
149
+
97
150
  traverse(
98
151
  visitor: (node: ScenegraphNode, context: {worldMatrix: Matrix4}) => void,
99
152
  {worldMatrix = new Matrix4()} = {}
@@ -0,0 +1,30 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {Buffer} from '@luma.gl/core';
6
+ import type {NumericArray} from '@math.gl/core';
7
+ import type {ScenegraphNode} from './scenegraph-node';
8
+
9
+ /** One visual node relative to a producer-owned world matrix. */
10
+ export type ScenegraphTransformBinding = {
11
+ matrixIndex: number;
12
+ localMatrix: Readonly<NumericArray>;
13
+ /** Optional producer visibility mask; authored display is evaluated live by traversal. */
14
+ visible?: boolean;
15
+ };
16
+
17
+ /** An accepted GPU publication. Buffers are borrowed, never owned by a renderer. */
18
+ export type ScenegraphTransformFrame = {
19
+ /** Column-major float32 mat4 array, with STORAGE usage. */
20
+ matrices: Buffer;
21
+ matrixCount: number;
22
+ /** Changes when the producer replaces its buffers or index mapping. */
23
+ revision: number;
24
+ bindings: ReadonlyMap<ScenegraphNode, ScenegraphTransformBinding>;
25
+ };
26
+
27
+ /** Generic GPU transform producer. Returning null selects authored scene transforms. */
28
+ export interface ScenegraphTransformSource {
29
+ getFrame(): ScenegraphTransformFrame | null;
30
+ }
@@ -39,7 +39,7 @@ import type {SplatSortMode} from './splat-sort';
39
39
  /** Camera, styling, borrowed data, and canvas clearing for graph-native Gaussian rendering. */
40
40
  export type GPUSplatGraphRendererProps = Omit<
41
41
  SplatRendererProps,
42
- 'depthCompare' | 'depthWriteEnabled'
42
+ 'depthCompare' | 'depthWriteEnabled' | 'depthConvention'
43
43
  > & {
44
44
  /** Color used when the graph opens its single default-framebuffer render pass. */
45
45
  clearColor?: [number, number, number, number];