@luma.gl/engine 9.4.0 → 10.0.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-loop/animation-loop.d.ts +12 -5
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +22 -7
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.d.ts +3 -1
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/compute/computation.d.ts +12 -0
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +85 -22
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/kernel.d.ts +54 -0
- package/dist/compute/kernel.d.ts.map +1 -0
- package/dist/compute/kernel.js +103 -0
- package/dist/compute/kernel.js.map +1 -0
- package/dist/compute/render-kernel.d.ts +65 -0
- package/dist/compute/render-kernel.d.ts.map +1 -0
- package/dist/compute/render-kernel.js +129 -0
- package/dist/compute/render-kernel.js.map +1 -0
- package/dist/controls/orbit-controls.d.ts +9 -2
- package/dist/controls/orbit-controls.d.ts.map +1 -1
- package/dist/controls/orbit-controls.js +55 -8
- package/dist/controls/orbit-controls.js.map +1 -1
- package/dist/dist.dev.js +502 -134
- package/dist/dist.min.js +23 -23
- package/dist/index.cjs +504 -117
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/model.d.ts +13 -2
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +137 -66
- package/dist/model/model.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +12 -12
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +17 -17
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/package.json +4 -4
- package/src/animation-loop/animation-loop.ts +36 -14
- package/src/animation-loop/animation-props.ts +4 -1
- package/src/animation-loop/make-animation-loop.ts +3 -1
- package/src/compute/computation.ts +83 -30
- package/src/compute/kernel.ts +146 -0
- package/src/compute/render-kernel.ts +192 -0
- package/src/controls/orbit-controls.ts +61 -9
- package/src/index.ts +12 -0
- package/src/model/model.ts +149 -87
- package/src/passes/shader-pass-renderer.ts +28 -25
|
@@ -9,6 +9,7 @@ export type OrbitControlsProps = {
|
|
|
9
9
|
distance?: number;
|
|
10
10
|
yaw?: number;
|
|
11
11
|
pitch?: number;
|
|
12
|
+
roll?: number;
|
|
12
13
|
minDistance?: number;
|
|
13
14
|
maxDistance?: number;
|
|
14
15
|
minPitch?: number;
|
|
@@ -17,6 +18,7 @@ export type OrbitControlsProps = {
|
|
|
17
18
|
pitchSpeed?: number;
|
|
18
19
|
zoomSpeed?: number;
|
|
19
20
|
enabled?: boolean;
|
|
21
|
+
enableRotate?: boolean;
|
|
20
22
|
enableZoom?: boolean;
|
|
21
23
|
enablePan?: boolean;
|
|
22
24
|
panSpeed?: number;
|
|
@@ -35,6 +37,7 @@ const DEFAULT_PROPS: ResolvedOrbitControlsProps = {
|
|
|
35
37
|
distance: 10,
|
|
36
38
|
yaw: 0,
|
|
37
39
|
pitch: 0.25,
|
|
40
|
+
roll: 0,
|
|
38
41
|
minDistance: 1,
|
|
39
42
|
maxDistance: 100,
|
|
40
43
|
minPitch: -Math.PI / 2 + 0.01,
|
|
@@ -42,6 +45,7 @@ const DEFAULT_PROPS: ResolvedOrbitControlsProps = {
|
|
|
42
45
|
rotateSpeed: 0.006,
|
|
43
46
|
zoomSpeed: 0.001,
|
|
44
47
|
enabled: true,
|
|
48
|
+
enableRotate: false,
|
|
45
49
|
enableZoom: true,
|
|
46
50
|
enablePan: false,
|
|
47
51
|
panSpeed: 0.0018,
|
|
@@ -50,7 +54,7 @@ const DEFAULT_PROPS: ResolvedOrbitControlsProps = {
|
|
|
50
54
|
};
|
|
51
55
|
|
|
52
56
|
/**
|
|
53
|
-
* Pointer orbit, wheel and pinch zoom, and
|
|
57
|
+
* Pointer orbit, optional pinch roll, wheel and pinch zoom, and automatic rotation controls.
|
|
54
58
|
*
|
|
55
59
|
* Call {@link update} once per frame with an animation-loop timestamp in milliseconds before
|
|
56
60
|
* reading {@link getEyePosition}. Manual dragging temporarily pauses automatic rotation and
|
|
@@ -61,12 +65,14 @@ export class OrbitControls {
|
|
|
61
65
|
readonly props: ResolvedOrbitControlsProps;
|
|
62
66
|
yaw: number;
|
|
63
67
|
pitch: number;
|
|
68
|
+
roll: number;
|
|
64
69
|
distance: number;
|
|
65
70
|
|
|
66
71
|
private dragging = false;
|
|
67
72
|
private readonly activePointers = new Map<number, [number, number]>();
|
|
68
73
|
private lastPointer: [number, number] = [0, 0];
|
|
69
74
|
private previousPinchDistance: number | null = null;
|
|
75
|
+
private previousPinchAngle: number | null = null;
|
|
70
76
|
private previousTimeMilliseconds: number | null = null;
|
|
71
77
|
private readonly previousCursor: string;
|
|
72
78
|
private readonly previousTouchAction: string;
|
|
@@ -77,6 +83,7 @@ export class OrbitControls {
|
|
|
77
83
|
this.props.target = [...this.props.target];
|
|
78
84
|
this.yaw = this.props.yaw;
|
|
79
85
|
this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
|
|
86
|
+
this.roll = this.props.roll;
|
|
80
87
|
this.distance = clampNumber(
|
|
81
88
|
this.props.distance,
|
|
82
89
|
this.props.minDistance,
|
|
@@ -120,6 +127,34 @@ export class OrbitControls {
|
|
|
120
127
|
];
|
|
121
128
|
}
|
|
122
129
|
|
|
130
|
+
/** Returns the camera up direction after applying pitch and optional two-finger roll. */
|
|
131
|
+
getUpDirection(): OrbitPosition {
|
|
132
|
+
return this.getCameraFrame().up;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private getCameraFrame(): {right: OrbitPosition; up: OrbitPosition} {
|
|
136
|
+
const sineYaw = Math.sin(this.yaw);
|
|
137
|
+
const cosineYaw = Math.cos(this.yaw);
|
|
138
|
+
const sinePitch = Math.sin(this.pitch);
|
|
139
|
+
const cosinePitch = Math.cos(this.pitch);
|
|
140
|
+
const sineRoll = Math.sin(this.roll);
|
|
141
|
+
const cosineRoll = Math.cos(this.roll);
|
|
142
|
+
const right: OrbitPosition = [cosineYaw, 0, -sineYaw];
|
|
143
|
+
const up: OrbitPosition = [-sinePitch * sineYaw, cosinePitch, -sinePitch * cosineYaw];
|
|
144
|
+
return {
|
|
145
|
+
right: [
|
|
146
|
+
right[0] * cosineRoll - up[0] * sineRoll,
|
|
147
|
+
right[1] * cosineRoll - up[1] * sineRoll,
|
|
148
|
+
right[2] * cosineRoll - up[2] * sineRoll
|
|
149
|
+
],
|
|
150
|
+
up: [
|
|
151
|
+
up[0] * cosineRoll + right[0] * sineRoll,
|
|
152
|
+
up[1] * cosineRoll + right[1] * sineRoll,
|
|
153
|
+
up[2] * cosineRoll + right[2] * sineRoll
|
|
154
|
+
]
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
123
158
|
/** Enables or pauses automatic rotation without losing the current manual angle. */
|
|
124
159
|
setAutoRotate(autoRotate: boolean): void {
|
|
125
160
|
this.props.autoRotate = autoRotate;
|
|
@@ -140,6 +175,9 @@ export class OrbitControls {
|
|
|
140
175
|
if (props.pitch !== undefined || props.minPitch !== undefined || props.maxPitch !== undefined) {
|
|
141
176
|
this.pitch = clampNumber(props.pitch ?? this.pitch, this.props.minPitch, this.props.maxPitch);
|
|
142
177
|
}
|
|
178
|
+
if (props.roll !== undefined) {
|
|
179
|
+
this.roll = props.roll;
|
|
180
|
+
}
|
|
143
181
|
if (
|
|
144
182
|
props.distance !== undefined ||
|
|
145
183
|
props.minDistance !== undefined ||
|
|
@@ -153,10 +191,11 @@ export class OrbitControls {
|
|
|
153
191
|
}
|
|
154
192
|
}
|
|
155
193
|
|
|
156
|
-
/** Restores the configured starting
|
|
194
|
+
/** Restores the configured starting orbit, roll, and zoom. */
|
|
157
195
|
reset(): void {
|
|
158
196
|
this.yaw = this.props.yaw;
|
|
159
197
|
this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
|
|
198
|
+
this.roll = this.props.roll;
|
|
160
199
|
this.distance = clampNumber(
|
|
161
200
|
this.props.distance,
|
|
162
201
|
this.props.minDistance,
|
|
@@ -193,9 +232,10 @@ export class OrbitControls {
|
|
|
193
232
|
if (this.activePointers.size === 1) {
|
|
194
233
|
this.lastPointer = [event.clientX, event.clientY];
|
|
195
234
|
} else {
|
|
196
|
-
const {center, distance} = this.getMultiPointerState();
|
|
235
|
+
const {center, distance, angle} = this.getMultiPointerState();
|
|
197
236
|
this.lastPointer = center;
|
|
198
237
|
this.previousPinchDistance = distance;
|
|
238
|
+
this.previousPinchAngle = distance > 0 ? angle : null;
|
|
199
239
|
}
|
|
200
240
|
this.canvas.setPointerCapture(event.pointerId);
|
|
201
241
|
this.canvas.style.cursor = 'grabbing';
|
|
@@ -208,7 +248,7 @@ export class OrbitControls {
|
|
|
208
248
|
|
|
209
249
|
this.activePointers.set(event.pointerId, [event.clientX, event.clientY]);
|
|
210
250
|
if (this.activePointers.size > 1) {
|
|
211
|
-
const {center, distance} = this.getMultiPointerState();
|
|
251
|
+
const {center, distance, angle} = this.getMultiPointerState();
|
|
212
252
|
if (this.props.enablePan) {
|
|
213
253
|
this.panTarget(center[0] - this.lastPointer[0], center[1] - this.lastPointer[1]);
|
|
214
254
|
}
|
|
@@ -219,8 +259,12 @@ export class OrbitControls {
|
|
|
219
259
|
this.props.maxDistance
|
|
220
260
|
);
|
|
221
261
|
}
|
|
262
|
+
if (this.props.enableRotate && this.previousPinchAngle !== null && distance > 0) {
|
|
263
|
+
this.roll += normalizeAngleDelta(angle - this.previousPinchAngle);
|
|
264
|
+
}
|
|
222
265
|
this.lastPointer = center;
|
|
223
266
|
this.previousPinchDistance = distance;
|
|
267
|
+
this.previousPinchAngle = distance > 0 ? angle : null;
|
|
224
268
|
return;
|
|
225
269
|
}
|
|
226
270
|
|
|
@@ -249,6 +293,7 @@ export class OrbitControls {
|
|
|
249
293
|
}
|
|
250
294
|
this.activePointers.delete(event.pointerId);
|
|
251
295
|
this.previousPinchDistance = null;
|
|
296
|
+
this.previousPinchAngle = null;
|
|
252
297
|
|
|
253
298
|
const remainingPointer = this.activePointers.entries().next().value;
|
|
254
299
|
if (remainingPointer) {
|
|
@@ -267,25 +312,28 @@ export class OrbitControls {
|
|
|
267
312
|
}
|
|
268
313
|
this.activePointers.clear();
|
|
269
314
|
this.previousPinchDistance = null;
|
|
315
|
+
this.previousPinchAngle = null;
|
|
270
316
|
this.canvas.style.cursor = 'grab';
|
|
271
317
|
}
|
|
272
318
|
|
|
273
|
-
private getMultiPointerState(): {center: [number, number]; distance: number} {
|
|
319
|
+
private getMultiPointerState(): {center: [number, number]; distance: number; angle: number} {
|
|
274
320
|
const [firstPointer, secondPointer] = this.activePointers.values();
|
|
275
321
|
const deltaX = secondPointer[0] - firstPointer[0];
|
|
276
322
|
const deltaY = secondPointer[1] - firstPointer[1];
|
|
277
323
|
return {
|
|
278
324
|
center: [(firstPointer[0] + secondPointer[0]) / 2, (firstPointer[1] + secondPointer[1]) / 2],
|
|
279
|
-
distance: Math.hypot(deltaX, deltaY)
|
|
325
|
+
distance: Math.hypot(deltaX, deltaY),
|
|
326
|
+
angle: Math.atan2(deltaY, deltaX)
|
|
280
327
|
};
|
|
281
328
|
}
|
|
282
329
|
|
|
283
330
|
private panTarget(deltaX: number, deltaY: number): void {
|
|
284
331
|
const panScale = this.distance * this.props.panSpeed;
|
|
332
|
+
const {right, up} = this.getCameraFrame();
|
|
285
333
|
this.props.target = [
|
|
286
|
-
this.props.target[0]
|
|
287
|
-
this.props.target[1] + deltaY * panScale,
|
|
288
|
-
this.props.target[2] +
|
|
334
|
+
this.props.target[0] + (-right[0] * deltaX + up[0] * deltaY) * panScale,
|
|
335
|
+
this.props.target[1] + (-right[1] * deltaX + up[1] * deltaY) * panScale,
|
|
336
|
+
this.props.target[2] + (-right[2] * deltaX + up[2] * deltaY) * panScale
|
|
289
337
|
];
|
|
290
338
|
}
|
|
291
339
|
|
|
@@ -307,3 +355,7 @@ export class OrbitControls {
|
|
|
307
355
|
function clampNumber(value: number, minimum: number, maximum: number): number {
|
|
308
356
|
return Math.min(Math.max(value, minimum), maximum);
|
|
309
357
|
}
|
|
358
|
+
|
|
359
|
+
function normalizeAngleDelta(angle: number): number {
|
|
360
|
+
return Math.atan2(Math.sin(angle), Math.cos(angle));
|
|
361
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -173,6 +173,18 @@ export {SwapFramebuffers} from './compute/swap';
|
|
|
173
173
|
|
|
174
174
|
export type {ComputationProps} from './compute/computation';
|
|
175
175
|
export {Computation} from './compute/computation';
|
|
176
|
+
export type {
|
|
177
|
+
KernelProps,
|
|
178
|
+
KernelDispatchOptions,
|
|
179
|
+
KernelDispatchIndirectOptions
|
|
180
|
+
} from './compute/kernel';
|
|
181
|
+
export {Kernel} from './compute/kernel';
|
|
182
|
+
export type {
|
|
183
|
+
RenderKernelProps,
|
|
184
|
+
RenderKernelDrawOptions,
|
|
185
|
+
RenderKernelIndirectDrawOptions
|
|
186
|
+
} from './compute/render-kernel';
|
|
187
|
+
export {RenderKernel} from './compute/render-kernel';
|
|
176
188
|
|
|
177
189
|
export type {
|
|
178
190
|
PickInfo,
|
package/src/model/model.ts
CHANGED
|
@@ -134,7 +134,7 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
|
|
|
134
134
|
|
|
135
135
|
/** Optional index buffer. Dynamic buffers are rebound when resized. */
|
|
136
136
|
indexBuffer?: ModelBuffer | null;
|
|
137
|
-
/** Optional indexed draw count. Defaults to the full bound index buffer length. */
|
|
137
|
+
/** Optional indexed draw count. Defaults to vertexCount, then the full bound index buffer length. */
|
|
138
138
|
indexCount?: number;
|
|
139
139
|
/** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
|
|
140
140
|
firstVertex?: number;
|
|
@@ -180,6 +180,31 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
|
|
|
180
180
|
* - Provides detailed debug logging and optional shader source inspection.
|
|
181
181
|
*/
|
|
182
182
|
export class Model {
|
|
183
|
+
/** Creates a model while allowing the backend to compile its render pipeline asynchronously. */
|
|
184
|
+
static async createAsync(device: Device, props: ModelProps): Promise<Model> {
|
|
185
|
+
const ownsCompilation = !PipelineFactory.getAsyncCompilation(device);
|
|
186
|
+
const asyncCompilation = ownsCompilation
|
|
187
|
+
? PipelineFactory.beginAsyncCompilation(device)
|
|
188
|
+
: PipelineFactory.getAsyncCompilation(device)!;
|
|
189
|
+
let model: Model;
|
|
190
|
+
try {
|
|
191
|
+
model = new Model(device, props);
|
|
192
|
+
} finally {
|
|
193
|
+
if (ownsCompilation) PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
if (ownsCompilation) {
|
|
197
|
+
await Promise.all(asyncCompilation);
|
|
198
|
+
} else {
|
|
199
|
+
await model._pipelineInitialization;
|
|
200
|
+
}
|
|
201
|
+
return model;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
model.destroy();
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
183
208
|
static defaultProps: Required<ModelProps> = {
|
|
184
209
|
...RenderPipeline.defaultProps,
|
|
185
210
|
source: undefined!,
|
|
@@ -255,7 +280,7 @@ export class Model {
|
|
|
255
280
|
instanceCount: number = 0;
|
|
256
281
|
/** Vertex count */
|
|
257
282
|
vertexCount: number;
|
|
258
|
-
/** Indexed draw count override. Undefined
|
|
283
|
+
/** Indexed draw count override. Undefined uses vertexCount, then the full bound index buffer. */
|
|
259
284
|
indexCount: number | undefined;
|
|
260
285
|
/** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
|
|
261
286
|
firstVertex: number;
|
|
@@ -276,13 +301,13 @@ export class Model {
|
|
|
276
301
|
* @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
|
|
277
302
|
* @todo - allow application to define multiple vertex arrays?
|
|
278
303
|
* */
|
|
279
|
-
vertexArray
|
|
304
|
+
vertexArray!: VertexArray;
|
|
280
305
|
|
|
281
306
|
/** TransformFeedback, WebGL 2 only. */
|
|
282
307
|
transformFeedback: TransformFeedback | null = null;
|
|
283
308
|
|
|
284
309
|
/** The underlying GPU "program". @note May be recreated if parameters change */
|
|
285
|
-
pipeline
|
|
310
|
+
pipeline!: RenderPipeline;
|
|
286
311
|
|
|
287
312
|
/** ShaderInputs instance */
|
|
288
313
|
// @ts-expect-error Assigned in function called by constructor
|
|
@@ -306,10 +331,12 @@ export class Model {
|
|
|
306
331
|
private _needsRedraw: string | false = 'initializing';
|
|
307
332
|
private _drawBlockedReason: string | false = false;
|
|
308
333
|
private _destroyed = false;
|
|
334
|
+
private _vertexCountSet = false;
|
|
309
335
|
|
|
310
336
|
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
311
337
|
_lastDrawTimestamp: number = -1;
|
|
312
338
|
private _bindingTable: ShaderBindingDebugRow[] = [];
|
|
339
|
+
private _pipelineInitialization?: Promise<void>;
|
|
313
340
|
|
|
314
341
|
get [Symbol.toStringTag](): string {
|
|
315
342
|
return 'Model';
|
|
@@ -321,6 +348,7 @@ export class Model {
|
|
|
321
348
|
|
|
322
349
|
constructor(device: Device, props: ModelProps) {
|
|
323
350
|
const defaultShaderAssembler = Model.defaultProps.shaderAssembler;
|
|
351
|
+
const vertexCountSet = Object.hasOwn(props, 'vertexCount');
|
|
324
352
|
this.props = {
|
|
325
353
|
...Model.defaultProps,
|
|
326
354
|
...props,
|
|
@@ -330,6 +358,7 @@ export class Model {
|
|
|
330
358
|
? defaultShaderAssembler
|
|
331
359
|
: ShaderAssembler.getDefaultShaderAssembler(device.info.shadingLanguage))
|
|
332
360
|
};
|
|
361
|
+
this._vertexCountSet = vertexCountSet;
|
|
333
362
|
props = this.props;
|
|
334
363
|
this.id = props.id || uid('model');
|
|
335
364
|
this.device = device;
|
|
@@ -459,56 +488,47 @@ export class Model {
|
|
|
459
488
|
props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
460
489
|
this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
|
|
461
490
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
491
|
+
const asyncCompilation = PipelineFactory.getAsyncCompilation(this.device);
|
|
492
|
+
if (asyncCompilation) {
|
|
493
|
+
this._pipelineInitialization = this._initializePipelineAsync(props);
|
|
494
|
+
asyncCompilation.push(this._pipelineInitialization);
|
|
495
|
+
} else {
|
|
496
|
+
this.pipeline = this._updatePipeline();
|
|
497
|
+
this._initializePipelineResources(props);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
private async _initializePipelineAsync(props: ModelProps): Promise<void> {
|
|
502
|
+
await this._updatePipelineAsync();
|
|
503
|
+
this._initializePipelineResources(props);
|
|
504
|
+
}
|
|
465
505
|
|
|
466
|
-
|
|
506
|
+
private _initializePipelineResources(props: ModelProps): void {
|
|
507
|
+
this.vertexArray = this.device.createVertexArray({
|
|
467
508
|
shaderLayout: this.pipeline.shaderLayout,
|
|
468
509
|
bufferLayout: this.pipeline.bufferLayout
|
|
469
510
|
});
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (this.
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
if (props.instanceCount) {
|
|
482
|
-
this.setInstanceCount(props.instanceCount);
|
|
483
|
-
}
|
|
484
|
-
if (props.vertexCount) {
|
|
485
|
-
this.setVertexCount(props.vertexCount);
|
|
486
|
-
}
|
|
487
|
-
if (props.indexBuffer) {
|
|
488
|
-
this.setIndexBuffer(props.indexBuffer);
|
|
489
|
-
}
|
|
490
|
-
if (props.attributes) {
|
|
491
|
-
this.setAttributes(props.attributes);
|
|
492
|
-
}
|
|
493
|
-
if (props.constantAttributes) {
|
|
494
|
-
this.setConstantAttributes(props.constantAttributes);
|
|
495
|
-
}
|
|
496
|
-
if (props.bindings) {
|
|
497
|
-
this.setBindings(props.bindings);
|
|
498
|
-
}
|
|
499
|
-
if (props.transformFeedback) {
|
|
500
|
-
this.transformFeedback = props.transformFeedback;
|
|
501
|
-
}
|
|
511
|
+
if (this._gpuGeometry) this._setGeometryAttributes(this._gpuGeometry);
|
|
512
|
+
if ('isInstanced' in props) this.isInstanced = props.isInstanced;
|
|
513
|
+
if (props.instanceCount) this.setInstanceCount(props.instanceCount);
|
|
514
|
+
if (props.vertexCount) this.setVertexCount(props.vertexCount);
|
|
515
|
+
if (props.indexBuffer) this.setIndexBuffer(props.indexBuffer);
|
|
516
|
+
if (props.attributes) this.setAttributes(props.attributes);
|
|
517
|
+
if (props.constantAttributes) this.setConstantAttributes(props.constantAttributes);
|
|
518
|
+
if (props.bindings) this.setBindings(props.bindings);
|
|
519
|
+
if (props.transformFeedback) this.transformFeedback = props.transformFeedback;
|
|
502
520
|
}
|
|
503
521
|
|
|
504
522
|
destroy(): void {
|
|
505
523
|
if (!this._destroyed) {
|
|
506
524
|
// Release pipeline before we destroy the shaders used by the pipeline
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
this.
|
|
525
|
+
if (this.pipeline) {
|
|
526
|
+
this.pipelineFactory.release(this.pipeline);
|
|
527
|
+
// Release the shaders
|
|
528
|
+
this.shaderFactory.release(this.pipeline.vs);
|
|
529
|
+
if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
|
|
530
|
+
this.shaderFactory.release(this.pipeline.fs);
|
|
531
|
+
}
|
|
512
532
|
}
|
|
513
533
|
this._uniformStore.destroy();
|
|
514
534
|
// TODO - mark resource as managed and destroyIfManaged() ?
|
|
@@ -625,7 +645,9 @@ export class Model {
|
|
|
625
645
|
const {indexBuffer} = this.vertexArray;
|
|
626
646
|
const indexCount = indexBuffer
|
|
627
647
|
? (this.indexCount ??
|
|
628
|
-
|
|
648
|
+
(this._vertexCountSet
|
|
649
|
+
? this.vertexCount
|
|
650
|
+
: indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)))
|
|
629
651
|
: undefined;
|
|
630
652
|
|
|
631
653
|
renderPass.setPipeline(this.pipeline);
|
|
@@ -774,6 +796,7 @@ export class Model {
|
|
|
774
796
|
*/
|
|
775
797
|
setVertexCount(vertexCount: number): void {
|
|
776
798
|
this.vertexCount = vertexCount;
|
|
799
|
+
this._vertexCountSet = true;
|
|
777
800
|
this.setNeedsRedraw('vertexCount');
|
|
778
801
|
}
|
|
779
802
|
|
|
@@ -1081,6 +1104,7 @@ export class Model {
|
|
|
1081
1104
|
|
|
1082
1105
|
// TODO - delete previous geometry?
|
|
1083
1106
|
this.vertexCount = gpuGeometry.vertexCount;
|
|
1107
|
+
this._vertexCountSet = true;
|
|
1084
1108
|
this.setIndexBuffer(gpuGeometry.indices || null);
|
|
1085
1109
|
this.setAttributes(gpuGeometry.attributes, {disableWarnings: true});
|
|
1086
1110
|
this.setAttributes(attributes, {disableWarnings: this.props.disableWarnings});
|
|
@@ -1097,40 +1121,64 @@ export class Model {
|
|
|
1097
1121
|
|
|
1098
1122
|
/** Update pipeline if needed */
|
|
1099
1123
|
_updatePipeline(): RenderPipeline {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1124
|
+
const update = this._preparePipelineUpdate();
|
|
1125
|
+
if (update) {
|
|
1126
|
+
this.pipeline = this.pipelineFactory.createRenderPipeline(update.props);
|
|
1127
|
+
this._finishPipelineUpdate(update);
|
|
1128
|
+
}
|
|
1129
|
+
return this.pipeline;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/** Creates or replaces the render pipeline through the backend's asynchronous compilation path. */
|
|
1133
|
+
async _updatePipelineAsync(): Promise<RenderPipeline> {
|
|
1134
|
+
const update = this._preparePipelineUpdate();
|
|
1135
|
+
if (update) {
|
|
1136
|
+
try {
|
|
1137
|
+
this.pipeline = await this.pipelineFactory.createRenderPipelineAsync(update.props);
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
this._releasePipelineShaders(update.vertexShader, update.fragmentShader);
|
|
1140
|
+
this._pipelineNeedsUpdate = 'asynchronous pipeline creation failed';
|
|
1141
|
+
throw error;
|
|
1110
1142
|
}
|
|
1143
|
+
this._finishPipelineUpdate(update);
|
|
1144
|
+
}
|
|
1145
|
+
return this.pipeline;
|
|
1146
|
+
}
|
|
1111
1147
|
|
|
1112
|
-
|
|
1148
|
+
private _preparePipelineUpdate(): {
|
|
1149
|
+
props: RenderPipelineProps;
|
|
1150
|
+
vertexShader: Shader;
|
|
1151
|
+
fragmentShader: Shader | null;
|
|
1152
|
+
previousVertexShader: Shader | null;
|
|
1153
|
+
previousFragmentShader: Shader | null;
|
|
1154
|
+
} | null {
|
|
1155
|
+
if (!this._pipelineNeedsUpdate) return null;
|
|
1156
|
+
const previousVertexShader = this.pipeline?.vs ?? null;
|
|
1157
|
+
const previousFragmentShader = this.pipeline?.fs ?? null;
|
|
1158
|
+
if (this.pipeline) {
|
|
1159
|
+
log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
1160
|
+
}
|
|
1161
|
+
this._pipelineNeedsUpdate = false;
|
|
1113
1162
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1163
|
+
const vertexShader = this.shaderFactory.createShader({
|
|
1164
|
+
id: `${this.id}-vertex`,
|
|
1165
|
+
stage: 'vertex',
|
|
1166
|
+
source: this.source || this.vs,
|
|
1167
|
+
debugShaders: this.props.debugShaders
|
|
1168
|
+
});
|
|
1169
|
+
let fragmentShader: Shader | null = null;
|
|
1170
|
+
if (this.source) {
|
|
1171
|
+
fragmentShader = vertexShader;
|
|
1172
|
+
} else if (this.fs) {
|
|
1173
|
+
fragmentShader = this.shaderFactory.createShader({
|
|
1174
|
+
id: `${this.id}-fragment`,
|
|
1175
|
+
stage: 'fragment',
|
|
1176
|
+
source: this.fs,
|
|
1118
1177
|
debugShaders: this.props.debugShaders
|
|
1119
1178
|
});
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
fs = vs;
|
|
1124
|
-
} else if (this.fs) {
|
|
1125
|
-
fs = this.shaderFactory.createShader({
|
|
1126
|
-
id: `${this.id}-fragment`,
|
|
1127
|
-
stage: 'fragment',
|
|
1128
|
-
source: this.source || this.fs,
|
|
1129
|
-
debugShaders: this.props.debugShaders
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
this.pipeline = this.pipelineFactory.createRenderPipeline({
|
|
1179
|
+
}
|
|
1180
|
+
return {
|
|
1181
|
+
props: {
|
|
1134
1182
|
...this.props,
|
|
1135
1183
|
bindings: undefined,
|
|
1136
1184
|
bufferLayout: this.bufferLayout,
|
|
@@ -1139,21 +1187,35 @@ export class Model {
|
|
|
1139
1187
|
topology: this.topology,
|
|
1140
1188
|
parameters: this.parameters,
|
|
1141
1189
|
bindGroups: undefined,
|
|
1142
|
-
vs,
|
|
1143
|
-
fs
|
|
1144
|
-
}
|
|
1190
|
+
vs: vertexShader,
|
|
1191
|
+
fs: fragmentShader
|
|
1192
|
+
},
|
|
1193
|
+
vertexShader,
|
|
1194
|
+
fragmentShader,
|
|
1195
|
+
previousVertexShader,
|
|
1196
|
+
previousFragmentShader
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1145
1199
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1200
|
+
private _finishPipelineUpdate(update: {
|
|
1201
|
+
previousVertexShader: Shader | null;
|
|
1202
|
+
previousFragmentShader: Shader | null;
|
|
1203
|
+
}): void {
|
|
1204
|
+
this._attributeInfos = getAttributeInfosFromLayouts(
|
|
1205
|
+
this.pipeline.shaderLayout,
|
|
1206
|
+
this.bufferLayout
|
|
1207
|
+
);
|
|
1208
|
+
this._releasePipelineShaders(update.previousVertexShader, update.previousFragmentShader);
|
|
1209
|
+
}
|
|
1150
1210
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1211
|
+
private _releasePipelineShaders(
|
|
1212
|
+
vertexShader: Shader | null,
|
|
1213
|
+
fragmentShader: Shader | null
|
|
1214
|
+
): void {
|
|
1215
|
+
if (vertexShader) this.shaderFactory.release(vertexShader);
|
|
1216
|
+
if (fragmentShader && fragmentShader !== vertexShader) {
|
|
1217
|
+
this.shaderFactory.release(fragmentShader);
|
|
1155
1218
|
}
|
|
1156
|
-
return this.pipeline;
|
|
1157
1219
|
}
|
|
1158
1220
|
|
|
1159
1221
|
/** Throttle draw call logging */
|