@luma.gl/engine 9.3.5 → 9.4.0-alpha.1
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.
- package/dist/animation/animator.d.ts +42 -0
- package/dist/animation/animator.d.ts.map +1 -0
- package/dist/animation/animator.js +53 -0
- package/dist/animation/animator.js.map +1 -0
- package/dist/animation-loop/animation-loop.d.ts +14 -2
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +40 -22
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.d.ts +2 -0
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/application-utils/load-file.d.ts +2 -0
- package/dist/application-utils/load-file.d.ts.map +1 -1
- package/dist/application-utils/load-file.js +31 -5
- package/dist/application-utils/load-file.js.map +1 -1
- package/dist/compute/buffer-transform.d.ts +5 -1
- package/dist/compute/buffer-transform.d.ts.map +1 -1
- package/dist/compute/buffer-transform.js +7 -3
- package/dist/compute/buffer-transform.js.map +1 -1
- package/dist/compute/computation.d.ts +20 -8
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +34 -13
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.d.ts.map +1 -1
- package/dist/compute/swap.js +17 -0
- package/dist/compute/swap.js.map +1 -1
- package/dist/dist.dev.js +4100 -1979
- package/dist/dist.min.js +288 -42
- package/dist/dynamic-buffer/dynamic-buffer.d.ts +171 -0
- package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -0
- package/dist/dynamic-buffer/dynamic-buffer.js +316 -0
- package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts +14 -1
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +31 -2
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.d.ts +55 -0
- package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -0
- package/dist/dynamic-texture/texture-binding-source.js +55 -0
- package/dist/dynamic-texture/texture-binding-source.js.map +1 -0
- package/dist/dynamic-texture/texture-data.d.ts +5 -3
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +5 -0
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/dynamic-texture/video-texture.d.ts +101 -0
- package/dist/dynamic-texture/video-texture.d.ts.map +1 -0
- package/dist/dynamic-texture/video-texture.js +272 -0
- package/dist/dynamic-texture/video-texture.js.map +1 -0
- package/dist/geometries/cube-geometry.d.ts +1 -0
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +22 -2
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts +10 -0
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts +36 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +137 -2
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +52 -33
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +70 -19
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +37 -4
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +44 -36
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +3990 -1961
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +20 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.d.ts +2 -1
- package/dist/material/material-factory.d.ts.map +1 -1
- package/dist/material/material-factory.js.map +1 -1
- package/dist/material/material.d.ts +29 -10
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +84 -21
- package/dist/material/material.js.map +1 -1
- package/dist/model/model.d.ts +81 -23
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +312 -78
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts +5 -2
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts +5 -2
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +28 -10
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/modules/picking/index-color-picking.d.ts +24 -0
- package/dist/modules/picking/index-color-picking.d.ts.map +1 -0
- package/dist/modules/picking/index-color-picking.js +205 -0
- package/dist/modules/picking/index-color-picking.js.map +1 -0
- package/dist/modules/picking/index-picking.d.ts +3 -3
- package/dist/modules/picking/index-picking.d.ts.map +1 -1
- package/dist/modules/picking/index-picking.js +23 -6
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/picking-manager.d.ts +21 -0
- package/dist/modules/picking/picking-manager.d.ts.map +1 -1
- package/dist/modules/picking/picking-manager.js +100 -0
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts +4 -4
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +3 -0
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.d.ts +5 -1
- package/dist/modules/picking/picking.d.ts.map +1 -1
- package/dist/modules/picking/picking.js +6 -0
- package/dist/modules/picking/picking.js.map +1 -1
- package/dist/passes/get-fragment-shader.js +4 -4
- package/dist/passes/shader-pass-renderer.d.ts +92 -25
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +466 -72
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/passes/texture-transform-module.d.ts +10 -0
- package/dist/passes/texture-transform-module.d.ts.map +1 -0
- package/dist/passes/texture-transform-module.js +50 -0
- package/dist/passes/texture-transform-module.js.map +1 -0
- package/dist/shader-inputs.d.ts +33 -16
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +42 -12
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/buffer-layout-helper.d.ts +0 -1
- package/dist/utils/buffer-layout-helper.d.ts.map +1 -1
- package/dist/utils/buffer-layout-helper.js +2 -11
- package/dist/utils/buffer-layout-helper.js.map +1 -1
- package/dist/utils/buffer-layout-order.d.ts.map +1 -1
- package/dist/utils/buffer-layout-order.js +4 -15
- package/dist/utils/buffer-layout-order.js.map +1 -1
- package/dist/utils/shader-module-utils.d.ts +2 -0
- package/dist/utils/shader-module-utils.d.ts.map +1 -1
- package/dist/utils/shader-module-utils.js +64 -3
- package/dist/utils/shader-module-utils.js.map +1 -1
- package/package.json +2 -2
- package/src/animation/animator.ts +79 -0
- package/src/animation-loop/animation-loop.ts +56 -22
- package/src/animation-loop/animation-props.ts +2 -0
- package/src/animation-loop/make-animation-loop.ts +4 -0
- package/src/application-utils/load-file.ts +38 -5
- package/src/compute/buffer-transform.ts +14 -5
- package/src/compute/computation.ts +53 -21
- package/src/compute/swap.ts +19 -0
- package/src/dynamic-buffer/dynamic-buffer.ts +453 -0
- package/src/dynamic-texture/dynamic-texture.ts +36 -3
- package/src/dynamic-texture/texture-binding-source.ts +94 -0
- package/src/dynamic-texture/texture-data.ts +12 -4
- package/src/dynamic-texture/video-texture.ts +334 -0
- package/src/geometries/cube-geometry.ts +24 -2
- package/src/geometries/plane-geometry.ts +10 -0
- package/src/geometry/geometry-utils.ts +209 -4
- package/src/geometry/geometry.ts +113 -36
- package/src/geometry/gpu-geometry.ts +61 -41
- package/src/index.ts +50 -14
- package/src/material/material-factory.ts +5 -1
- package/src/material/material.ts +123 -27
- package/src/model/model.ts +441 -102
- package/src/model/split-uniforms-and-bindings.ts +7 -3
- package/src/models/billboard-texture-model.ts +33 -12
- package/src/modules/picking/index-color-picking.ts +212 -0
- package/src/modules/picking/index-picking.ts +23 -6
- package/src/modules/picking/picking-manager.ts +141 -0
- package/src/modules/picking/picking-uniforms.ts +7 -4
- package/src/modules/picking/picking.ts +8 -0
- package/src/passes/get-fragment-shader.ts +4 -4
- package/src/passes/shader-pass-renderer.ts +691 -89
- package/src/passes/texture-transform-module.ts +52 -0
- package/src/shader-inputs.ts +65 -17
- package/src/utils/buffer-layout-helper.ts +2 -14
- package/src/utils/buffer-layout-order.ts +14 -24
- package/src/utils/shader-module-utils.ts +109 -3
- package/dist/geometry/gpu-table.d.ts +0 -1
- package/dist/geometry/gpu-table.d.ts.map +0 -1
- package/dist/geometry/gpu-table.js +0 -46
- package/dist/geometry/gpu-table.js.map +0 -1
- package/src/dynamic-texture/texture-data.ts.disabled +0 -296
- package/src/geometry/gpu-table.ts +0 -45
package/src/geometry/geometry.ts
CHANGED
|
@@ -3,49 +3,81 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {TypedArray} from '@math.gl/core';
|
|
6
|
-
import type {PrimitiveTopology} from '@luma.gl/core';
|
|
6
|
+
import type {BufferLayout, PrimitiveTopology} from '@luma.gl/core';
|
|
7
|
+
import {vertexFormatDecoder} from '@luma.gl/core';
|
|
7
8
|
import {uid} from '../utils/uid';
|
|
8
9
|
|
|
10
|
+
/** CPU-side attribute data accepted by {@link Geometry}. */
|
|
11
|
+
export type GeometryAttributeInput = GeometryAttribute | TypedArray;
|
|
12
|
+
|
|
13
|
+
/** Properties used to create a {@link Geometry}. */
|
|
9
14
|
export type GeometryProps = {
|
|
15
|
+
/** Application-provided identifier. */
|
|
10
16
|
id?: string;
|
|
11
|
-
/** Determines how vertices are
|
|
17
|
+
/** Determines how vertices are assembled into primitives. */
|
|
12
18
|
topology: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
|
|
13
|
-
/** Auto
|
|
19
|
+
/** Draw vertex count. Auto-calculated from attributes or indices when omitted. */
|
|
14
20
|
vertexCount?: number;
|
|
15
|
-
attributes
|
|
21
|
+
/** CPU attributes, keyed by caller-provided names such as glTF mesh attribute semantics. */
|
|
22
|
+
attributes: Record<string, GeometryAttributeInput>;
|
|
23
|
+
/**
|
|
24
|
+
* Maps geometry buffers to shader attributes.
|
|
25
|
+
*
|
|
26
|
+
* If omitted, the constructor creates one shader-facing buffer layout entry for each attribute.
|
|
27
|
+
* Explicit buffer layouts are preserved unchanged.
|
|
28
|
+
*/
|
|
29
|
+
bufferLayout?: BufferLayout[];
|
|
30
|
+
/** Optional index data. Indices are always stored separately from vertex attributes. */
|
|
16
31
|
indices?: GeometryAttribute | TypedArray;
|
|
17
32
|
};
|
|
18
33
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
TEXCOORD_0: GeometryAttribute;
|
|
23
|
-
COLOR_0?: GeometryAttribute;
|
|
34
|
+
/** Attributes returned by {@link Geometry.getAttributes}. */
|
|
35
|
+
export type GeometryAttributes = Record<string, GeometryAttribute | undefined> & {
|
|
36
|
+
/** Optional index attribute, included when the geometry is indexed. */
|
|
24
37
|
indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};
|
|
25
38
|
};
|
|
26
39
|
|
|
40
|
+
/** Typed-array backed CPU geometry attribute. */
|
|
27
41
|
export type GeometryAttribute = {
|
|
42
|
+
/** Number of typed-array elements per vertex. */
|
|
28
43
|
size?: number;
|
|
44
|
+
/** Attribute data. */
|
|
29
45
|
value: TypedArray;
|
|
46
|
+
/** Additional attribute metadata consumed by geometry utilities. */
|
|
30
47
|
[key: string]: any;
|
|
31
48
|
};
|
|
32
49
|
|
|
50
|
+
/**
|
|
51
|
+
* CPU-side geometry container.
|
|
52
|
+
*
|
|
53
|
+
* `Geometry` stores typed-array vertex data, optional index data, and an always-populated
|
|
54
|
+
* `bufferLayout` that describes how its attributes map to shader inputs. CPU attribute names are
|
|
55
|
+
* preserved as supplied; synthesized buffer layouts map supported glTF-style names such as
|
|
56
|
+
* `POSITION` and `TEXCOORD_0` to default shader names such as `positions` and `texCoords`.
|
|
57
|
+
*/
|
|
33
58
|
export class Geometry {
|
|
59
|
+
/** Application-provided or generated identifier. */
|
|
34
60
|
readonly id: string;
|
|
35
|
-
|
|
61
|
+
|
|
62
|
+
/** Determines how vertices are assembled into primitives. */
|
|
36
63
|
readonly topology?: PrimitiveTopology;
|
|
64
|
+
|
|
65
|
+
/** Resolved draw vertex count. */
|
|
37
66
|
readonly vertexCount: number;
|
|
67
|
+
|
|
68
|
+
/** Optional index attribute. */
|
|
38
69
|
readonly indices?: GeometryAttribute;
|
|
39
|
-
readonly attributes: {
|
|
40
|
-
POSITION: GeometryAttribute;
|
|
41
|
-
NORMAL: GeometryAttribute;
|
|
42
|
-
TEXCOORD_0: GeometryAttribute;
|
|
43
|
-
COLOR_0?: GeometryAttribute;
|
|
44
|
-
[key: string]: GeometryAttribute | undefined;
|
|
45
|
-
};
|
|
46
70
|
|
|
71
|
+
/** CPU attributes, keyed by caller-provided source attribute name. */
|
|
72
|
+
readonly attributes: Record<string, GeometryAttribute | undefined>;
|
|
73
|
+
|
|
74
|
+
/** Buffer layout matching the geometry attributes. Always populated. */
|
|
75
|
+
readonly bufferLayout: BufferLayout[];
|
|
76
|
+
|
|
77
|
+
/** Application-owned metadata. */
|
|
47
78
|
userData: Record<string, unknown> = {};
|
|
48
79
|
|
|
80
|
+
/** Creates a CPU geometry and wraps raw typed arrays into attribute records. */
|
|
49
81
|
constructor(props: GeometryProps) {
|
|
50
82
|
const {attributes = {}, indices = null, vertexCount = null} = props;
|
|
51
83
|
|
|
@@ -56,7 +88,6 @@ export class Geometry {
|
|
|
56
88
|
this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
|
|
57
89
|
}
|
|
58
90
|
|
|
59
|
-
// @ts-expect-error
|
|
60
91
|
this.attributes = {};
|
|
61
92
|
|
|
62
93
|
for (const [attributeName, attributeValue] of Object.entries(attributes)) {
|
|
@@ -82,6 +113,13 @@ export class Geometry {
|
|
|
82
113
|
}
|
|
83
114
|
this.indices = attribute;
|
|
84
115
|
} else {
|
|
116
|
+
const shaderAttributeName = getGeometryShaderAttributeName(attributeName);
|
|
117
|
+
const storedAttributeName = Object.keys(this.attributes).find(
|
|
118
|
+
name => getGeometryShaderAttributeName(name) === shaderAttributeName
|
|
119
|
+
);
|
|
120
|
+
if (storedAttributeName) {
|
|
121
|
+
delete this.attributes[storedAttributeName];
|
|
122
|
+
}
|
|
85
123
|
this.attributes[attributeName] = attribute;
|
|
86
124
|
}
|
|
87
125
|
}
|
|
@@ -92,19 +130,20 @@ export class Geometry {
|
|
|
92
130
|
}
|
|
93
131
|
|
|
94
132
|
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
133
|
+
this.bufferLayout =
|
|
134
|
+
props.bufferLayout || getBufferLayoutFromGeometryAttributes(this.attributes);
|
|
95
135
|
}
|
|
96
136
|
|
|
137
|
+
/** Returns the resolved draw vertex count. */
|
|
97
138
|
getVertexCount(): number {
|
|
98
139
|
return this.vertexCount;
|
|
99
140
|
}
|
|
100
141
|
|
|
101
|
-
/**
|
|
102
|
-
* Return an object with all attributes plus indices added as a field.
|
|
103
|
-
* TODO Geometry types are a mess
|
|
104
|
-
*/
|
|
142
|
+
/** Returns all attributes, including `indices` when index data is present. */
|
|
105
143
|
getAttributes(): GeometryAttributes {
|
|
106
|
-
|
|
107
|
-
|
|
144
|
+
return (
|
|
145
|
+
this.indices ? {indices: this.indices, ...this.attributes} : this.attributes
|
|
146
|
+
) as GeometryAttributes;
|
|
108
147
|
}
|
|
109
148
|
|
|
110
149
|
// PRIVATE
|
|
@@ -113,27 +152,22 @@ export class Geometry {
|
|
|
113
152
|
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
114
153
|
}
|
|
115
154
|
|
|
116
|
-
/**
|
|
117
|
-
* GeometryAttribute
|
|
118
|
-
* value: typed array
|
|
119
|
-
* type: indices, vertices, uvs
|
|
120
|
-
* size: elements per vertex
|
|
121
|
-
* target: WebGL buffer type (string or constant)
|
|
122
|
-
*
|
|
123
|
-
* @param attributes
|
|
124
|
-
* @param indices
|
|
125
|
-
* @returns
|
|
126
|
-
*/
|
|
127
155
|
_setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
|
|
128
156
|
return this;
|
|
129
157
|
}
|
|
130
158
|
|
|
131
|
-
_calculateVertexCount(
|
|
159
|
+
_calculateVertexCount(
|
|
160
|
+
attributes: Record<string, GeometryAttribute | undefined>,
|
|
161
|
+
indices?: GeometryAttribute
|
|
162
|
+
): number {
|
|
132
163
|
if (indices) {
|
|
133
164
|
return indices.value.length;
|
|
134
165
|
}
|
|
135
166
|
let vertexCount = Infinity;
|
|
136
167
|
for (const attribute of Object.values(attributes)) {
|
|
168
|
+
if (!attribute) {
|
|
169
|
+
continue; // eslint-disable-line no-continue
|
|
170
|
+
}
|
|
137
171
|
const {value, size, constant} = attribute;
|
|
138
172
|
if (!constant && value && size !== undefined && size >= 1) {
|
|
139
173
|
vertexCount = Math.min(vertexCount, value.length / size);
|
|
@@ -144,3 +178,46 @@ export class Geometry {
|
|
|
144
178
|
return vertexCount;
|
|
145
179
|
}
|
|
146
180
|
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Converts supported geometry semantic names to default shader attribute names.
|
|
184
|
+
*
|
|
185
|
+
* Use this only at render-layout boundaries. CPU `Geometry.attributes` preserves source names.
|
|
186
|
+
* Names that do not have a built-in mapping are returned unchanged.
|
|
187
|
+
*/
|
|
188
|
+
export function getGeometryShaderAttributeName(attributeName: string): string {
|
|
189
|
+
switch (attributeName) {
|
|
190
|
+
case 'POSITION':
|
|
191
|
+
return 'positions';
|
|
192
|
+
case 'NORMAL':
|
|
193
|
+
return 'normals';
|
|
194
|
+
case 'TEXCOORD_0':
|
|
195
|
+
return 'texCoords';
|
|
196
|
+
case 'TEXCOORD_1':
|
|
197
|
+
return 'texCoords1';
|
|
198
|
+
case 'COLOR_0':
|
|
199
|
+
return 'colors';
|
|
200
|
+
default:
|
|
201
|
+
return attributeName;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function getBufferLayoutFromGeometryAttributes(
|
|
206
|
+
attributes: Record<string, GeometryAttribute | undefined>
|
|
207
|
+
): BufferLayout[] {
|
|
208
|
+
const bufferLayout: BufferLayout[] = [];
|
|
209
|
+
for (const [attributeName, attribute] of Object.entries(attributes)) {
|
|
210
|
+
if (!attribute) {
|
|
211
|
+
continue; // eslint-disable-line no-continue
|
|
212
|
+
}
|
|
213
|
+
const {value, size, normalized} = attribute;
|
|
214
|
+
if (size === undefined) {
|
|
215
|
+
throw new Error(`Attribute ${attributeName} is missing a size`);
|
|
216
|
+
}
|
|
217
|
+
bufferLayout.push({
|
|
218
|
+
name: getGeometryShaderAttributeName(attributeName),
|
|
219
|
+
format: vertexFormatDecoder.getVertexFormatFromAttribute(value, size, normalized)
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return bufferLayout;
|
|
223
|
+
}
|
|
@@ -3,33 +3,61 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';
|
|
6
|
-
import {Device, Buffer
|
|
7
|
-
import type
|
|
6
|
+
import {Device, Buffer} from '@luma.gl/core';
|
|
7
|
+
import {type Geometry, getGeometryShaderAttributeName} from '../geometry/geometry';
|
|
8
|
+
import {makeInterleavedGeometry} from './geometry-utils';
|
|
8
9
|
import {uid} from '../utils/uid';
|
|
9
10
|
|
|
11
|
+
/** Properties used to create a {@link GPUGeometry}. */
|
|
10
12
|
export type GPUGeometryProps = {
|
|
13
|
+
/** Application-provided identifier. */
|
|
11
14
|
id?: string;
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
/** Determines how vertices are assembled into primitives. */
|
|
13
17
|
topology: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
|
|
14
|
-
|
|
18
|
+
|
|
19
|
+
/** Draw vertex count. */
|
|
15
20
|
vertexCount: number;
|
|
21
|
+
|
|
22
|
+
/** Buffer layout matching the supplied GPU vertex buffers. */
|
|
16
23
|
bufferLayout: BufferLayout[];
|
|
24
|
+
|
|
25
|
+
/** Optional GPU index buffer. */
|
|
17
26
|
indices?: Buffer | null;
|
|
27
|
+
|
|
28
|
+
/** GPU vertex buffers, keyed by buffer layout name. */
|
|
18
29
|
attributes: Record<string, Buffer>;
|
|
19
30
|
};
|
|
20
31
|
|
|
32
|
+
/**
|
|
33
|
+
* GPU-backed geometry container.
|
|
34
|
+
*
|
|
35
|
+
* `GPUGeometry` owns already-created vertex and index buffers plus the `bufferLayout` metadata
|
|
36
|
+
* needed to bind those buffers to shader attributes.
|
|
37
|
+
*/
|
|
21
38
|
export class GPUGeometry {
|
|
39
|
+
/** Application-provided or generated identifier. */
|
|
22
40
|
readonly id: string;
|
|
41
|
+
|
|
42
|
+
/** Application-owned metadata. */
|
|
23
43
|
userData: Record<string, unknown> = {};
|
|
24
44
|
|
|
25
|
-
/** Determines how vertices are
|
|
45
|
+
/** Determines how vertices are assembled into primitives. */
|
|
26
46
|
readonly topology?: PrimitiveTopology;
|
|
47
|
+
|
|
48
|
+
/** Buffer layout matching {@link GPUGeometry.attributes}. */
|
|
27
49
|
readonly bufferLayout: BufferLayout[] = [];
|
|
28
50
|
|
|
51
|
+
/** Resolved draw vertex count. */
|
|
29
52
|
readonly vertexCount: number;
|
|
53
|
+
|
|
54
|
+
/** Optional GPU index buffer. */
|
|
30
55
|
readonly indices?: Buffer | null;
|
|
56
|
+
|
|
57
|
+
/** GPU vertex buffers, keyed by buffer layout name. */
|
|
31
58
|
readonly attributes: Record<string, Buffer>;
|
|
32
59
|
|
|
60
|
+
/** Creates GPU-backed geometry from existing buffers. */
|
|
33
61
|
constructor(props: GPUGeometryProps) {
|
|
34
62
|
this.id = props.id || uid('geometry');
|
|
35
63
|
this.topology = props.topology;
|
|
@@ -47,6 +75,7 @@ export class GPUGeometry {
|
|
|
47
75
|
}
|
|
48
76
|
}
|
|
49
77
|
|
|
78
|
+
/** Destroys the owned index and vertex buffers. */
|
|
50
79
|
destroy(): void {
|
|
51
80
|
this.indices?.destroy();
|
|
52
81
|
for (const attribute of Object.values(this.attributes)) {
|
|
@@ -54,14 +83,17 @@ export class GPUGeometry {
|
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
85
|
|
|
86
|
+
/** Returns the draw vertex count. */
|
|
57
87
|
getVertexCount(): number {
|
|
58
88
|
return this.vertexCount;
|
|
59
89
|
}
|
|
60
90
|
|
|
91
|
+
/** Returns the GPU vertex buffers. */
|
|
61
92
|
getAttributes(): Record<string, Buffer> {
|
|
62
93
|
return this.attributes;
|
|
63
94
|
}
|
|
64
95
|
|
|
96
|
+
/** Returns the GPU index buffer, or `null` for non-indexed geometry. */
|
|
65
97
|
getIndexes(): Buffer | null {
|
|
66
98
|
return this.indices || null;
|
|
67
99
|
}
|
|
@@ -73,22 +105,30 @@ export class GPUGeometry {
|
|
|
73
105
|
}
|
|
74
106
|
}
|
|
75
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Converts CPU geometry into GPU geometry.
|
|
110
|
+
*
|
|
111
|
+
* CPU `Geometry` input is interleaved before upload so the resulting `GPUGeometry` has one vertex
|
|
112
|
+
* buffer plus an optional index buffer. Passing a `GPUGeometry` returns the original instance.
|
|
113
|
+
*/
|
|
76
114
|
export function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry {
|
|
77
115
|
if (geometry instanceof GPUGeometry) {
|
|
78
116
|
return geometry;
|
|
79
117
|
}
|
|
80
118
|
|
|
81
|
-
const
|
|
82
|
-
const
|
|
119
|
+
const sourceGeometry = makeInterleavedGeometry(geometry);
|
|
120
|
+
const indices = getIndexBufferFromGeometry(device, sourceGeometry);
|
|
121
|
+
const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, sourceGeometry);
|
|
83
122
|
return new GPUGeometry({
|
|
84
|
-
topology:
|
|
123
|
+
topology: sourceGeometry.topology || 'triangle-list',
|
|
85
124
|
bufferLayout,
|
|
86
|
-
vertexCount:
|
|
125
|
+
vertexCount: sourceGeometry.vertexCount,
|
|
87
126
|
indices,
|
|
88
127
|
attributes
|
|
89
128
|
});
|
|
90
129
|
}
|
|
91
130
|
|
|
131
|
+
/** Creates a GPU index buffer from CPU geometry index data, when present. */
|
|
92
132
|
export function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {
|
|
93
133
|
if (!geometry.indices) {
|
|
94
134
|
return undefined;
|
|
@@ -97,50 +137,30 @@ export function getIndexBufferFromGeometry(device: Device, geometry: Geometry):
|
|
|
97
137
|
return device.createBuffer({usage: Buffer.INDEX, data});
|
|
98
138
|
}
|
|
99
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Uploads one GPU vertex buffer for each CPU geometry attribute key and preserves its buffer
|
|
142
|
+
* layout metadata.
|
|
143
|
+
*/
|
|
100
144
|
export function getAttributeBuffersFromGeometry(
|
|
101
145
|
device: Device,
|
|
102
146
|
geometry: Geometry
|
|
103
147
|
): {attributes: Record<string, Buffer>; bufferLayout: BufferLayout[]; vertexCount: number} {
|
|
104
|
-
const bufferLayout: BufferLayout[] = [];
|
|
105
|
-
|
|
106
148
|
const attributes: Record<string, Buffer> = {};
|
|
107
149
|
for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
case 'POSITION':
|
|
112
|
-
name = 'positions';
|
|
113
|
-
break;
|
|
114
|
-
case 'NORMAL':
|
|
115
|
-
name = 'normals';
|
|
116
|
-
break;
|
|
117
|
-
case 'TEXCOORD_0':
|
|
118
|
-
name = 'texCoords';
|
|
119
|
-
break;
|
|
120
|
-
case 'TEXCOORD_1':
|
|
121
|
-
name = 'texCoords1';
|
|
122
|
-
break;
|
|
123
|
-
case 'COLOR_0':
|
|
124
|
-
name = 'colors';
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
150
|
+
const name =
|
|
151
|
+
geometry.bufferLayout.find(bufferLayout => bufferLayout.name === attributeName)?.name ||
|
|
152
|
+
getGeometryShaderAttributeName(attributeName);
|
|
127
153
|
if (attribute) {
|
|
128
154
|
attributes[name] = device.createBuffer({
|
|
129
155
|
data: attribute.value,
|
|
130
156
|
id: `${attributeName}-buffer`
|
|
131
157
|
});
|
|
132
|
-
const {value, size, normalized} = attribute;
|
|
133
|
-
if (size === undefined) {
|
|
134
|
-
throw new Error(`Attribute ${attributeName} is missing a size`);
|
|
135
|
-
}
|
|
136
|
-
bufferLayout.push({
|
|
137
|
-
name,
|
|
138
|
-
format: vertexFormatDecoder.getVertexFormatFromAttribute(value, size, normalized)
|
|
139
|
-
});
|
|
140
158
|
}
|
|
141
159
|
}
|
|
142
160
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
161
|
+
return {
|
|
162
|
+
attributes,
|
|
163
|
+
bufferLayout: geometry.bufferLayout,
|
|
164
|
+
vertexCount: geometry.vertexCount
|
|
165
|
+
};
|
|
146
166
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,13 +5,19 @@
|
|
|
5
5
|
// luma.gl Engine API
|
|
6
6
|
|
|
7
7
|
// Animation
|
|
8
|
+
export type {AnimationClipControllerProps} from './animation/animator';
|
|
9
|
+
export {AnimationClipController, Animator} from './animation/animator';
|
|
8
10
|
export {Timeline} from './animation/timeline';
|
|
9
11
|
export {KeyFrames} from './animation/key-frames';
|
|
10
12
|
export type {AnimationProps} from './animation-loop/animation-props';
|
|
11
13
|
|
|
12
14
|
export {AnimationLoopTemplate} from './animation-loop/animation-loop-template';
|
|
13
15
|
|
|
14
|
-
export type {
|
|
16
|
+
export type {
|
|
17
|
+
AnimationFrameCallback,
|
|
18
|
+
AnimationFrameProvider,
|
|
19
|
+
AnimationLoopProps
|
|
20
|
+
} from './animation-loop/animation-loop';
|
|
15
21
|
export {AnimationLoop} from './animation-loop/animation-loop';
|
|
16
22
|
|
|
17
23
|
export type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';
|
|
@@ -52,8 +58,10 @@ export type {ModelNodeProps} from './scenegraph/model-node';
|
|
|
52
58
|
export {ModelNode} from './scenegraph/model-node';
|
|
53
59
|
|
|
54
60
|
// Geometries
|
|
55
|
-
export type {GeometryProps, GeometryAttribute} from './geometry/geometry';
|
|
61
|
+
export type {GeometryProps, GeometryAttribute, GeometryAttributeInput} from './geometry/geometry';
|
|
56
62
|
export {Geometry} from './geometry/geometry';
|
|
63
|
+
export type {MakeInterleavedGeometryOptions} from './geometry/geometry-utils';
|
|
64
|
+
export {makeInterleavedGeometry} from './geometry/geometry-utils';
|
|
57
65
|
export type {GPUGeometryProps} from './geometry/gpu-geometry';
|
|
58
66
|
export {GPUGeometry} from './geometry/gpu-geometry';
|
|
59
67
|
|
|
@@ -74,21 +82,18 @@ export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geome
|
|
|
74
82
|
export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
|
|
75
83
|
|
|
76
84
|
export {ShaderInputs} from './shader-inputs';
|
|
85
|
+
export type {ShaderInputBinding, ShaderInputsProps} from './shader-inputs';
|
|
77
86
|
|
|
78
87
|
// Application Utilities
|
|
79
88
|
export {makeRandomGenerator} from './application-utils/random';
|
|
80
|
-
export {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export {Swap} from './compute/swap';
|
|
87
|
-
export {SwapBuffers} from './compute/swap';
|
|
88
|
-
export {SwapFramebuffers} from './compute/swap';
|
|
89
|
+
export {
|
|
90
|
+
setPathPrefix,
|
|
91
|
+
loadImage,
|
|
92
|
+
loadImageBitmap,
|
|
93
|
+
_resolveLoadFileUrl
|
|
94
|
+
} from './application-utils/load-file';
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
export {Computation} from './compute/computation';
|
|
96
|
+
// Dynamic Resources
|
|
92
97
|
|
|
93
98
|
export type {
|
|
94
99
|
TextureCubeFace,
|
|
@@ -103,11 +108,41 @@ export type {
|
|
|
103
108
|
|
|
104
109
|
export type {DynamicTextureProps} from './dynamic-texture/dynamic-texture';
|
|
105
110
|
export {DynamicTexture} from './dynamic-texture/dynamic-texture';
|
|
111
|
+
export type {
|
|
112
|
+
TextureBindingLayout,
|
|
113
|
+
TextureBindingSource
|
|
114
|
+
} from './dynamic-texture/texture-binding-source';
|
|
115
|
+
export type {VideoTextureProps} from './dynamic-texture/video-texture';
|
|
116
|
+
export {VideoTexture} from './dynamic-texture/video-texture';
|
|
117
|
+
export type {
|
|
118
|
+
BufferBindingSource,
|
|
119
|
+
DynamicBufferProps,
|
|
120
|
+
DynamicBufferRange
|
|
121
|
+
} from './dynamic-buffer/dynamic-buffer';
|
|
122
|
+
export {DynamicBuffer} from './dynamic-buffer/dynamic-buffer';
|
|
123
|
+
|
|
124
|
+
// EXPERIMENTAL
|
|
125
|
+
export type {
|
|
126
|
+
ShaderPassBinding,
|
|
127
|
+
ShaderPassRendererProps,
|
|
128
|
+
ShaderPassRendererRenderOptions,
|
|
129
|
+
ShaderPassSourceTexture
|
|
130
|
+
} from './passes/shader-pass-renderer';
|
|
131
|
+
export {ShaderPassRenderer} from './passes/shader-pass-renderer';
|
|
132
|
+
|
|
133
|
+
export {Swap} from './compute/swap';
|
|
134
|
+
export {SwapBuffers} from './compute/swap';
|
|
135
|
+
export {SwapFramebuffers} from './compute/swap';
|
|
136
|
+
|
|
137
|
+
export type {ComputationProps} from './compute/computation';
|
|
138
|
+
export {Computation} from './compute/computation';
|
|
106
139
|
|
|
107
140
|
export type {
|
|
108
141
|
PickInfo,
|
|
142
|
+
PickingTooltip,
|
|
109
143
|
PickingMode,
|
|
110
144
|
ResolvedPickingMode,
|
|
145
|
+
PickingShouldPickOptions,
|
|
111
146
|
PickingBackend,
|
|
112
147
|
PickingManagerProps,
|
|
113
148
|
ResolvedPickingBackend
|
|
@@ -118,8 +153,9 @@ export {
|
|
|
118
153
|
resolvePickingMode,
|
|
119
154
|
resolvePickingBackend
|
|
120
155
|
} from './modules/picking/picking-manager';
|
|
121
|
-
export {picking} from './modules/picking/picking';
|
|
156
|
+
export {getIndexPickingModule, picking} from './modules/picking/picking';
|
|
122
157
|
export {picking as indexPicking} from './modules/picking/index-picking';
|
|
158
|
+
export {picking as indexColorPicking} from './modules/picking/index-color-picking';
|
|
123
159
|
export {picking as colorPicking} from './modules/picking/color-picking';
|
|
124
160
|
|
|
125
161
|
export {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type {Binding, BindingsByGroup, Device} from '@luma.gl/core';
|
|
6
6
|
import type {ShaderModule} from '@luma.gl/shadertools';
|
|
7
|
+
import type {TextureBindingSource} from '../dynamic-texture/texture-binding-source';
|
|
7
8
|
import {ShaderInputs} from '../shader-inputs';
|
|
8
9
|
import type {Material, MaterialProps} from './material';
|
|
9
10
|
import {Material as MaterialClass} from './material';
|
|
@@ -11,7 +12,10 @@ import {Material as MaterialClass} from './material';
|
|
|
11
12
|
type MaterialModuleProps = Partial<Record<string, Record<string, unknown>>>;
|
|
12
13
|
type MaterialBindings = Record<
|
|
13
14
|
string,
|
|
14
|
-
|
|
15
|
+
| Binding
|
|
16
|
+
| TextureBindingSource
|
|
17
|
+
| import('../dynamic-buffer/dynamic-buffer').DynamicBuffer
|
|
18
|
+
| import('../dynamic-buffer/dynamic-buffer').DynamicBufferRange
|
|
15
19
|
>;
|
|
16
20
|
|
|
17
21
|
/** Logical bind-group slot reserved for material-owned bindings. */
|