@luma.gl/engine 8.6.0-alpha.3 → 9.0.0-alpha.3
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/key-frames.d.ts +1 -0
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +1 -1
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js.map +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.d.ts +4 -0
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +30 -7
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +15 -3
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +29 -15
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.d.ts +15 -0
- package/dist/geometry/geometry-table.d.ts.map +1 -0
- package/dist/geometry/geometry-table.js +2 -0
- package/dist/{transform/transform-types.js.map → geometry/geometry-table.js.map} +1 -1
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +34 -7
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +33 -11
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/primitive-utils.d.ts +1 -0
- package/dist/geometry/primitive-utils.d.ts.map +1 -0
- package/dist/geometry/primitive-utils.js +2 -0
- package/dist/geometry/primitive-utils.js.map +1 -0
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/animation-loop.d.ts +14 -73
- package/dist/lib/animation-loop.d.ts.map +1 -1
- package/dist/lib/animation-loop.js +39 -160
- package/dist/lib/animation-loop.js.map +1 -1
- package/dist/lib/animation-props.d.ts +24 -0
- package/dist/lib/animation-props.d.ts.map +1 -0
- package/dist/lib/animation-props.js +2 -0
- package/dist/lib/animation-props.js.map +1 -0
- package/dist/lib/clip-space.d.ts +1 -0
- package/dist/lib/clip-space.d.ts.map +1 -0
- package/dist/lib/clip-space.js +2 -0
- package/dist/lib/clip-space.js.map +1 -0
- package/dist/lib/model-utils.d.ts +4 -3
- package/dist/lib/model-utils.d.ts.map +1 -1
- package/dist/lib/model-utils.js +24 -70
- package/dist/lib/model-utils.js.map +1 -1
- package/dist/lib/model.d.ts +34 -104
- package/dist/lib/model.d.ts.map +1 -1
- package/dist/lib/model.js +108 -505
- package/dist/lib/model.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +55 -0
- package/dist/lib/pipeline-factory.d.ts.map +1 -0
- package/dist/lib/pipeline-factory.js +191 -0
- package/dist/lib/pipeline-factory.js.map +1 -0
- package/dist/lib/render-loop.d.ts +4 -17
- package/dist/lib/render-loop.d.ts.map +1 -1
- package/dist/lib/render-loop.js +14 -21
- package/dist/lib/render-loop.js.map +1 -1
- package/package.json +5 -5
- package/src/animation/key-frames.ts +1 -0
- package/src/animation/timeline.ts +1 -1
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +159 -8
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/sphere-geometry.ts +2 -2
- package/src/geometries/truncated-cone-geometry.ts +30 -12
- package/src/geometry/geometry-table.ts +16 -0
- package/src/geometry/geometry-utils.ts +1 -1
- package/src/geometry/geometry.ts +58 -13
- package/src/geometry/primitive-utils.ts +30 -0
- package/src/index.ts +7 -8
- package/src/lib/animation-loop.ts +85 -274
- package/src/lib/animation-props.ts +31 -0
- package/src/{utils → lib}/clip-space.ts +5 -2
- package/src/lib/model-utils.ts +60 -32
- package/src/lib/model.ts +126 -642
- package/src/lib/pipeline-factory.ts +225 -0
- package/src/lib/render-loop.ts +21 -19
- package/dist/lib/program-manager.d.ts +0 -39
- package/dist/lib/program-manager.d.ts.map +0 -1
- package/dist/lib/program-manager.js +0 -175
- package/dist/lib/program-manager.js.map +0 -1
- package/dist/transform/buffer-transform.d.ts +0 -36
- package/dist/transform/buffer-transform.d.ts.map +0 -1
- package/dist/transform/buffer-transform.js +0 -255
- package/dist/transform/buffer-transform.js.map +0 -1
- package/dist/transform/texture-transform.d.ts +0 -57
- package/dist/transform/texture-transform.d.ts.map +0 -1
- package/dist/transform/texture-transform.js +0 -412
- package/dist/transform/texture-transform.js.map +0 -1
- package/dist/transform/transform-shader-utils.d.ts +0 -26
- package/dist/transform/transform-shader-utils.d.ts.map +0 -1
- package/dist/transform/transform-shader-utils.js +0 -149
- package/dist/transform/transform-shader-utils.js.map +0 -1
- package/dist/transform/transform-types.d.ts +0 -44
- package/dist/transform/transform-types.d.ts.map +0 -1
- package/dist/transform/transform-types.js +0 -2
- package/dist/transform/transform.d.ts +0 -47
- package/dist/transform/transform.d.ts.map +0 -1
- package/dist/transform/transform.js +0 -198
- package/dist/transform/transform.js.map +0 -1
- package/dist/utils/clip-space.d.ts +0 -5
- package/dist/utils/clip-space.d.ts.map +0 -1
- package/dist/utils/clip-space.js +0 -34
- package/dist/utils/clip-space.js.map +0 -1
- package/src/lib/program-manager.ts +0 -187
- package/src/transform/buffer-transform.ts +0 -214
- package/src/transform/texture-transform.ts +0 -344
- package/src/transform/transform-shader-utils.ts +0 -169
- package/src/transform/transform-types.ts +0 -42
- package/src/transform/transform.ts +0 -189
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { luma } from '@luma.gl/api';
|
|
3
|
-
import {
|
|
4
|
-
import { isWebGL, resetParameters } from '@luma.gl/webgl';
|
|
5
|
-
import { requestAnimationFrame, cancelAnimationFrame, Query, Framebuffer } from '@luma.gl/webgl';
|
|
3
|
+
import { requestAnimationFrame, cancelAnimationFrame } from '@luma.gl/api';
|
|
6
4
|
import { isBrowser } from '@probe.gl/env';
|
|
7
5
|
const isPage = isBrowser() && typeof document !== 'undefined';
|
|
8
6
|
let statIdCounter = 0;
|
|
9
7
|
const DEFAULT_ANIMATION_LOOP_PROPS = {
|
|
10
8
|
onCreateDevice: props => luma.createDevice(props),
|
|
11
|
-
|
|
12
|
-
onAddHTML: null,
|
|
9
|
+
onAddHTML: undefined,
|
|
13
10
|
onInitialize: () => ({}),
|
|
14
11
|
onRender: () => {},
|
|
15
12
|
onFinalize: () => {},
|
|
16
13
|
onError: error => console.error(error),
|
|
17
|
-
device:
|
|
14
|
+
device: undefined,
|
|
15
|
+
deviceProps: {},
|
|
18
16
|
debug: false,
|
|
17
|
+
stats: luma.stats.get("animation-loop-".concat(statIdCounter++)),
|
|
19
18
|
useDevicePixels: true,
|
|
20
19
|
autoResizeViewport: true,
|
|
21
|
-
autoResizeDrawingBuffer: true
|
|
22
|
-
stats: lumaStats.get("animation-loop-".concat(statIdCounter++)),
|
|
23
|
-
gl: null,
|
|
24
|
-
glOptions: {},
|
|
25
|
-
createFramebuffer: false
|
|
20
|
+
autoResizeDrawingBuffer: true
|
|
26
21
|
};
|
|
27
22
|
export default class AnimationLoop {
|
|
28
23
|
constructor(props = {}) {
|
|
@@ -34,8 +29,6 @@ export default class AnimationLoop {
|
|
|
34
29
|
|
|
35
30
|
_defineProperty(this, "animationProps", void 0);
|
|
36
31
|
|
|
37
|
-
_defineProperty(this, "framebuffer", null);
|
|
38
|
-
|
|
39
32
|
_defineProperty(this, "timeline", null);
|
|
40
33
|
|
|
41
34
|
_defineProperty(this, "stats", void 0);
|
|
@@ -56,18 +49,12 @@ export default class AnimationLoop {
|
|
|
56
49
|
|
|
57
50
|
_defineProperty(this, "_animationFrameId", null);
|
|
58
51
|
|
|
59
|
-
_defineProperty(this, "_pageLoadPromise", null);
|
|
60
|
-
|
|
61
52
|
_defineProperty(this, "_nextFramePromise", null);
|
|
62
53
|
|
|
63
54
|
_defineProperty(this, "_resolveNextFrame", null);
|
|
64
55
|
|
|
65
56
|
_defineProperty(this, "_cpuStartTime", 0);
|
|
66
57
|
|
|
67
|
-
_defineProperty(this, "_gpuTimeQuery", null);
|
|
68
|
-
|
|
69
|
-
_defineProperty(this, "gl", void 0);
|
|
70
|
-
|
|
71
58
|
this.props = { ...DEFAULT_ANIMATION_LOOP_PROPS,
|
|
72
59
|
...props
|
|
73
60
|
};
|
|
@@ -75,12 +62,6 @@ export default class AnimationLoop {
|
|
|
75
62
|
let {
|
|
76
63
|
useDevicePixels = true
|
|
77
64
|
} = this.props;
|
|
78
|
-
|
|
79
|
-
if ('useDevicePixelRatio' in props) {
|
|
80
|
-
log.deprecated('useDevicePixelRatio', 'useDevicePixels')();
|
|
81
|
-
useDevicePixels = props.useDevicePixelRatio;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
65
|
this.device = props.device;
|
|
85
66
|
this.gl = this.device && this.device.gl || props.gl;
|
|
86
67
|
this.stats = props.stats;
|
|
@@ -129,13 +110,7 @@ export default class AnimationLoop {
|
|
|
129
110
|
return this;
|
|
130
111
|
}
|
|
131
112
|
|
|
132
|
-
start(
|
|
133
|
-
this._start(opts);
|
|
134
|
-
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async _start(opts) {
|
|
113
|
+
async start() {
|
|
139
114
|
if (this._running) {
|
|
140
115
|
return this;
|
|
141
116
|
}
|
|
@@ -143,8 +118,6 @@ export default class AnimationLoop {
|
|
|
143
118
|
this._running = true;
|
|
144
119
|
|
|
145
120
|
try {
|
|
146
|
-
await this._getPageLoadPromise();
|
|
147
|
-
|
|
148
121
|
if (!this._running) {
|
|
149
122
|
return null;
|
|
150
123
|
}
|
|
@@ -153,12 +126,11 @@ export default class AnimationLoop {
|
|
|
153
126
|
|
|
154
127
|
if (!this._initialized) {
|
|
155
128
|
this._initialized = true;
|
|
129
|
+
await this._createDevice();
|
|
156
130
|
|
|
157
|
-
this._initialize(
|
|
131
|
+
this._initialize();
|
|
158
132
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this._addCallbackData(appContext || {});
|
|
133
|
+
await this.onInitialize(this.animationProps);
|
|
162
134
|
}
|
|
163
135
|
|
|
164
136
|
if (!this._running) {
|
|
@@ -172,14 +144,15 @@ export default class AnimationLoop {
|
|
|
172
144
|
}
|
|
173
145
|
|
|
174
146
|
return this;
|
|
175
|
-
} catch (
|
|
147
|
+
} catch (err) {
|
|
148
|
+
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
176
149
|
this.props.onError(error);
|
|
177
|
-
|
|
150
|
+
throw error;
|
|
178
151
|
}
|
|
179
152
|
}
|
|
180
153
|
|
|
181
154
|
redraw() {
|
|
182
|
-
if (this.
|
|
155
|
+
if (this.device.isLost) {
|
|
183
156
|
return this;
|
|
184
157
|
}
|
|
185
158
|
|
|
@@ -207,7 +180,7 @@ export default class AnimationLoop {
|
|
|
207
180
|
|
|
208
181
|
stop() {
|
|
209
182
|
if (this._running) {
|
|
210
|
-
this.
|
|
183
|
+
this.onFinalize(this.animationProps);
|
|
211
184
|
|
|
212
185
|
this._cancelAnimationFrame();
|
|
213
186
|
|
|
@@ -243,11 +216,7 @@ export default class AnimationLoop {
|
|
|
243
216
|
async toDataURL() {
|
|
244
217
|
this.setNeedsRedraw('toDataURL');
|
|
245
218
|
await this.waitForRender();
|
|
246
|
-
return this.
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
isContextLost() {
|
|
250
|
-
return this.gl.isContextLost();
|
|
219
|
+
return this.canvas.toDataURL();
|
|
251
220
|
}
|
|
252
221
|
|
|
253
222
|
onCreateDevice(deviceProps) {
|
|
@@ -266,20 +235,7 @@ export default class AnimationLoop {
|
|
|
266
235
|
return this.props.onFinalize(animationProps);
|
|
267
236
|
}
|
|
268
237
|
|
|
269
|
-
|
|
270
|
-
return this.props.onCreateContext(props);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
getHTMLControlValue(id, defaultValue = 1) {
|
|
274
|
-
const element = document.getElementById(id);
|
|
275
|
-
return element ? Number(element.value) : defaultValue;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
_initialize(props) {
|
|
279
|
-
this._createDevice(props);
|
|
280
|
-
|
|
281
|
-
this._createFramebuffer();
|
|
282
|
-
|
|
238
|
+
_initialize() {
|
|
283
239
|
this._startEventHandling();
|
|
284
240
|
|
|
285
241
|
this._initializeCallbackData();
|
|
@@ -289,25 +245,6 @@ export default class AnimationLoop {
|
|
|
289
245
|
this._resizeCanvasDrawingBuffer();
|
|
290
246
|
|
|
291
247
|
this._resizeViewport();
|
|
292
|
-
|
|
293
|
-
this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
_getPageLoadPromise() {
|
|
297
|
-
if (!this._pageLoadPromise) {
|
|
298
|
-
this._pageLoadPromise = isPage ? new Promise((resolve, reject) => {
|
|
299
|
-
if (isPage && document.readyState === 'complete') {
|
|
300
|
-
resolve(document);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
window.addEventListener('load', () => {
|
|
305
|
-
resolve(document);
|
|
306
|
-
});
|
|
307
|
-
}) : Promise.resolve({});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return this._pageLoadPromise;
|
|
311
248
|
}
|
|
312
249
|
|
|
313
250
|
_setDisplay(display) {
|
|
@@ -368,30 +305,25 @@ export default class AnimationLoop {
|
|
|
368
305
|
this._resizeCanvasDrawingBuffer();
|
|
369
306
|
|
|
370
307
|
this._resizeViewport();
|
|
371
|
-
|
|
372
|
-
this._resizeFramebuffer();
|
|
373
308
|
}
|
|
374
309
|
|
|
375
310
|
_initializeCallbackData() {
|
|
376
311
|
this.animationProps = {
|
|
312
|
+
animationLoop: this,
|
|
377
313
|
device: this.device,
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
canvas: this.gl.canvas,
|
|
314
|
+
canvas: this.device.canvasContext.canvas,
|
|
315
|
+
timeline: this.timeline,
|
|
381
316
|
useDevicePixels: this.props.useDevicePixels,
|
|
382
317
|
needsRedraw: null,
|
|
318
|
+
width: 1,
|
|
319
|
+
height: 1,
|
|
320
|
+
aspect: 1,
|
|
321
|
+
time: 0,
|
|
383
322
|
startTime: Date.now(),
|
|
384
323
|
engineTime: 0,
|
|
385
324
|
tick: 0,
|
|
386
325
|
tock: 0,
|
|
387
|
-
|
|
388
|
-
animationLoop: this,
|
|
389
|
-
time: 0,
|
|
390
|
-
_mousePosition: null,
|
|
391
|
-
framebuffer: this.framebuffer,
|
|
392
|
-
_timeline: this.timeline,
|
|
393
|
-
_loop: this,
|
|
394
|
-
_animationLoop: this
|
|
326
|
+
_mousePosition: null
|
|
395
327
|
};
|
|
396
328
|
}
|
|
397
329
|
|
|
@@ -425,35 +357,18 @@ export default class AnimationLoop {
|
|
|
425
357
|
this.animationProps.time = this.timeline ? this.timeline.getTime() : this.animationProps.engineTime;
|
|
426
358
|
}
|
|
427
359
|
|
|
428
|
-
|
|
429
|
-
this.onFinalize(this.animationProps);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
_addCallbackData(appContext) {
|
|
433
|
-
if (typeof appContext === 'object' && appContext !== null) {
|
|
434
|
-
this.animationProps = Object.assign({}, this.animationProps, appContext);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
_createDevice(props) {
|
|
360
|
+
async _createDevice() {
|
|
439
361
|
const deviceProps = { ...this.props,
|
|
440
|
-
...props
|
|
441
|
-
...this.props.glOptions
|
|
362
|
+
...this.props.deviceProps
|
|
442
363
|
};
|
|
443
|
-
this.device = this.onCreateDevice(deviceProps);
|
|
444
|
-
this.
|
|
445
|
-
|
|
446
|
-
if (!isWebGL(this.gl)) {
|
|
447
|
-
throw new Error('AnimationLoop.onCreateContext - illegal context returned');
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
resetParameters(this.gl);
|
|
364
|
+
this.device = await this.onCreateDevice(deviceProps);
|
|
365
|
+
this.canvas = this.device.canvasContext.canvas;
|
|
451
366
|
|
|
452
367
|
this._createInfoDiv();
|
|
453
368
|
}
|
|
454
369
|
|
|
455
370
|
_createInfoDiv() {
|
|
456
|
-
if (this.
|
|
371
|
+
if (this.canvas && this.props.onAddHTML) {
|
|
457
372
|
const wrapperDiv = document.createElement('div');
|
|
458
373
|
document.body.appendChild(wrapperDiv);
|
|
459
374
|
wrapperDiv.style.position = 'relative';
|
|
@@ -463,7 +378,7 @@ export default class AnimationLoop {
|
|
|
463
378
|
div.style.bottom = '10px';
|
|
464
379
|
div.style.width = '300px';
|
|
465
380
|
div.style.background = 'white';
|
|
466
|
-
wrapperDiv.appendChild(this.
|
|
381
|
+
wrapperDiv.appendChild(this.canvas);
|
|
467
382
|
wrapperDiv.appendChild(div);
|
|
468
383
|
const html = this.props.onAddHTML(div);
|
|
469
384
|
|
|
@@ -474,12 +389,9 @@ export default class AnimationLoop {
|
|
|
474
389
|
}
|
|
475
390
|
|
|
476
391
|
_getSizeAndAspect() {
|
|
477
|
-
const width = this.
|
|
478
|
-
const height = this.gl.drawingBufferHeight;
|
|
392
|
+
const [width, height] = this.device.canvasContext.getPixelSize();
|
|
479
393
|
let aspect = 1;
|
|
480
|
-
const
|
|
481
|
-
canvas
|
|
482
|
-
} = this.gl;
|
|
394
|
+
const canvas = this.device.canvasContext.canvas;
|
|
483
395
|
|
|
484
396
|
if (canvas && canvas.clientHeight) {
|
|
485
397
|
aspect = canvas.clientWidth / canvas.clientHeight;
|
|
@@ -495,14 +407,14 @@ export default class AnimationLoop {
|
|
|
495
407
|
}
|
|
496
408
|
|
|
497
409
|
_resizeViewport() {
|
|
498
|
-
if (this.props.autoResizeViewport) {
|
|
499
|
-
this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight);
|
|
410
|
+
if (this.props.autoResizeViewport && this.device.gl) {
|
|
411
|
+
this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);
|
|
500
412
|
}
|
|
501
413
|
}
|
|
502
414
|
|
|
503
415
|
_resizeCanvasDrawingBuffer() {
|
|
504
416
|
if (this.props.autoResizeDrawingBuffer) {
|
|
505
|
-
this.device.resize({
|
|
417
|
+
this.device.canvasContext.resize({
|
|
506
418
|
useDevicePixels: this.props.useDevicePixels
|
|
507
419
|
});
|
|
508
420
|
}
|
|
@@ -511,34 +423,16 @@ export default class AnimationLoop {
|
|
|
511
423
|
_beginTimers() {
|
|
512
424
|
this.frameRate.timeEnd();
|
|
513
425
|
this.frameRate.timeStart();
|
|
514
|
-
|
|
515
|
-
if (this._gpuTimeQuery && this._gpuTimeQuery.isResultAvailable() && !this._gpuTimeQuery.isTimerDisjoint()) {
|
|
516
|
-
this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
if (this._gpuTimeQuery) {
|
|
520
|
-
this._gpuTimeQuery.beginTimeElapsedQuery();
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
this.cpuTime.timeStart();
|
|
524
426
|
}
|
|
525
427
|
|
|
526
428
|
_endTimers() {
|
|
527
429
|
this.cpuTime.timeEnd();
|
|
528
|
-
|
|
529
|
-
if (this._gpuTimeQuery) {
|
|
530
|
-
this._gpuTimeQuery.end();
|
|
531
|
-
}
|
|
532
430
|
}
|
|
533
431
|
|
|
534
432
|
_startEventHandling() {
|
|
535
|
-
|
|
536
|
-
canvas
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (canvas) {
|
|
540
|
-
canvas.addEventListener('mousemove', this._onMousemove);
|
|
541
|
-
canvas.addEventListener('mouseleave', this._onMouseleave);
|
|
433
|
+
if (this.canvas) {
|
|
434
|
+
this.canvas.addEventListener('mousemove', this._onMousemove);
|
|
435
|
+
this.canvas.addEventListener('mouseleave', this._onMouseleave);
|
|
542
436
|
}
|
|
543
437
|
}
|
|
544
438
|
|
|
@@ -550,20 +444,5 @@ export default class AnimationLoop {
|
|
|
550
444
|
this.animationProps._mousePosition = null;
|
|
551
445
|
}
|
|
552
446
|
|
|
553
|
-
_createFramebuffer() {
|
|
554
|
-
if (this.props.createFramebuffer) {
|
|
555
|
-
this.framebuffer = new Framebuffer(this.gl);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
_resizeFramebuffer() {
|
|
560
|
-
if (this.framebuffer) {
|
|
561
|
-
this.framebuffer.resize({
|
|
562
|
-
width: this.gl.drawingBufferWidth,
|
|
563
|
-
height: this.gl.drawingBufferHeight
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
447
|
}
|
|
569
448
|
//# sourceMappingURL=animation-loop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","lumaStats","log","isWebGL","resetParameters","requestAnimationFrame","cancelAnimationFrame","Query","Framebuffer","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onCreateContext","onAddHTML","onInitialize","onRender","onFinalize","onError","error","console","device","debug","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","stats","get","gl","glOptions","createFramebuffer","AnimationLoop","constructor","deprecated","useDevicePixelRatio","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","opts","_start","_running","_getPageLoadPromise","appContext","_initialized","_initialize","animationProps","_addCallbackData","_cancelAnimationFrame","_requestAnimationFrame","redraw","isContextLost","_beginTimers","_setupFrame","_updateCallbackData","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","_finalizeCallbackData","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","deviceProps","getHTMLControlValue","id","defaultValue","element","getElementById","Number","value","_createDevice","_createFramebuffer","_startEventHandling","_initializeCallbackData","_resizeCanvasDrawingBuffer","_resizeViewport","_gpuTimeQuery","isSupported","_pageLoadPromise","reject","readyState","window","addEventListener","display","animationLoop","_animationFrameId","_animationFrame","_resizeFramebuffer","startTime","Date","now","engineTime","tick","tock","time","_mousePosition","framebuffer","_timeline","_loop","_animationLoop","width","height","aspect","_getSizeAndAspect","update","Math","floor","getTime","Object","assign","Error","_createInfoDiv","wrapperDiv","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","drawingBufferWidth","drawingBufferHeight","clientHeight","clientWidth","viewport","resize","timeEnd","timeStart","isResultAvailable","isTimerDisjoint","addTime","getTimerMilliseconds","beginTimeElapsedQuery","end","e","offsetX","offsetY"],"mappings":";AAAA,SAAQA,IAAR,QAA2B,cAA3B;AACA,SACEC,SADF,EAGEC,GAHF,QAKO,cALP;AAQA,SACEC,OADF,EAKEC,eALF,QAMO,gBANP;AASA,SACEC,qBADF,EAEEC,oBAFF,EAGEC,KAHF,EAKEC,WALF,QAMO,gBANP;AASA,SAAQC,SAAR,QAAwB,eAAxB;AAQA,MAAMC,MAAM,GAAGD,SAAS,MAAM,OAAOE,QAAP,KAAoB,WAAlD;AAEA,IAA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CAACkH,CAAD,EAAI;AACd,SAAKnG,cAAL,CAAoBwD,cAApB,GAAqC,CAAC2C,CAAC,CAACC,OAAH,EAAYD,CAAC,CAACE,OAAd,CAArC;AACD;;AACDnH,EAAAA,aAAa,CAACiH,CAAD,EAAI;AACf,SAAKnG,cAAL,CAAoBwD,cAApB,GAAqC,IAArC;AACD;;AAKDxB,EAAAA,kBAAkB,GAAG;AAEnB,QAAI,KAAK9E,KAAL,CAAWmB,iBAAf,EAAkC;AAChC,WAAKoF,WAAL,GAAmB,IAAI9G,WAAJ,CAAgB,KAAKwB,EAArB,CAAnB;AACD;AACF;;AAGD6E,EAAAA,kBAAkB,GAAG;AACnB,QAAI,KAAKS,WAAT,EAAsB;AACpB,WAAKA,WAAL,CAAiBiC,MAAjB,CAAwB;AACtB7B,QAAAA,KAAK,EAAE,KAAK1F,EAAL,CAAQkH,kBADO;AAEtBvB,QAAAA,MAAM,EAAE,KAAK3F,EAAL,CAAQmH;AAFM,OAAxB;AAID;AACF;;AA9kBgC","sourcesContent":["import {luma, Device} from '@luma.gl/api';\nimport {\n lumaStats,\n // TODO - remove dependency on framebuffer (bundle size impact)\n log,\n assert\n} from '@luma.gl/api';\nimport type {WebGLDeviceProps} from '@luma.gl/webgl'\nimport {WebGLDevice} from '@luma.gl/webgl';\nimport {\n isWebGL,\n // createGLContext,\n // instrumentGLContext,\n // resizeGLContext,\n resetParameters\n} from '@luma.gl/webgl';\n\n\nimport {\n requestAnimationFrame,\n cancelAnimationFrame,\n Query,\n // TODO - remove dependency on framebuffer (bundle size impact)\n Framebuffer\n} from '@luma.gl/webgl';\n\nimport { Stats, Stat } from '@probe.gl/stats'\nimport {isBrowser} from '@probe.gl/env';\n\nimport { Timeline } from '../animation/timeline'\n\n\ntype DeviceProps = WebGLDeviceProps;\ntype ContextProps = WebGLDeviceProps;\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Device;\n onCreateContext?: (props: ContextProps) => WebGLRenderingContext; // TODO: signature from createGLContext\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => {} | void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: any) => void;\n\n stats?: Stats;\n\n device?: Device;\n glOptions?: ContextProps; // createGLContext options\n debug?: boolean;\n\n // view parameters\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n\n /** @deprecated Use .device */\n gl?: WebGLRenderingContext\n /** @deprecated Will be removed */\n createFramebuffer?: boolean;\n};\n\nexport type AnimationProps = {\n device: Device;\n\n stop: () => AnimationLoop\n canvas: HTMLCanvasElement | OffscreenCanvas\n // Initial values\n useDevicePixels: number | boolean\n needsRedraw?: string\n // Animation props\n startTime: number\n engineTime: number\n tick: number\n tock: number\n\n // Timeline time for back compatibility\n time: number\n\n width: number\n height: number\n aspect: number\n\n timeline: Timeline\n animationLoop: AnimationLoop\n\n // Experimental\n _mousePosition?: [number, number] // [offsetX, offsetY],\n\n /** @deprecated Will be removed, create your own Framebuffer */\n framebuffer: Framebuffer\n /** @deprecated Use .device */\n gl: WebGLRenderingContext\n\n /** @deprecated Use .timeline */\n _timeline: Timeline\n /** @deprecated Use .animationLoop */\n _loop: AnimationLoop\n /** @deprecated Use .animationLoop */\n _animationLoop: AnimationLoop\n}\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps) => luma.createDevice(props),\n onCreateContext: null,\n onAddHTML: null,\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: null,\n debug: false,\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n stats: lumaStats.get(`animation-loop-${statIdCounter++}`),\n\n // deprecated\n // onCreateContext: (opts) => createGLContext(opts),\n gl: null,\n glOptions: {},\n createFramebuffer: false\n};\n\n/** Convenient animation loop */\nexport default class AnimationLoop {\n device: Device;\n canvas: HTMLCanvasElement | OffscreenCanvas;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps;\n framebuffer: Framebuffer = null;\n timeline: Timeline = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | null = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId = null;\n _pageLoadPromise: Promise<{}> | null = null;\n _nextFramePromise: Promise<AnimationLoop> | null = null;\n _resolveNextFrame: ((AnimationLoop) => void) | null = null;\n _cpuStartTime: number = 0;\n\n _gpuTimeQuery: Query | null = null;\n\n /** @deprecated */\n gl: WebGLRenderingContext;\n\n /*\n * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context\n */\n constructor(props: AnimationLoopProps = {}) {\n this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};\n props = this.props;\n\n let {useDevicePixels = true} = this.props;\n\n if ('useDevicePixelRatio' in props) {\n log.deprecated('useDevicePixelRatio', 'useDevicePixels')();\n // @ts-expect-error\n useDevicePixels = props.useDevicePixelRatio;\n }\n\n // state\n this.device = props.device;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats;\n this.cpuTime = this.stats.get('CPU Time');\n this.gpuTime = this.stats.get('GPU Time');\n this.frameRate = this.stats.get('Frame Rate');\n\n this.setProps({\n autoResizeViewport: props.autoResizeViewport,\n autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,\n useDevicePixels\n });\n\n // Bind methods\n this.start = this.start.bind(this);\n this.stop = this.stop.bind(this);\n\n this._onMousemove = this._onMousemove.bind(this);\n this._onMouseleave = this._onMouseleave.bind(this);\n }\n\n destroy(): void {\n this.stop();\n this._setDisplay(null);\n }\n\n /** @deprecated Use .destroy() */\n delete(): void {\n this.destroy();\n }\n\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n setProps(props: AnimationLoopProps): this {\n if ('autoResizeViewport' in props) {\n this.props.autoResizeViewport = props.autoResizeViewport;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels;\n }\n return this;\n }\n\n start(opts = {}) {\n this._start(opts);\n return this;\n }\n\n /** Starts a render loop if not already running\n * @param {Object} context - contains frame specific info (E.g. tick, width, height, etc)\n */\n async _start(opts) {\n if (this._running) {\n return this;\n }\n this._running = true;\n\n // console.debug(`Starting ${this.constructor.name}`);\n // Wait for start promise before rendering frame\n try {\n await this._getPageLoadPromise();\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n this._initialize(opts);\n\n // Note: onIntialize can return a promise (in case app needs to load resources)\n appContext = await this.onInitialize(this.animationProps);\n this._addCallbackData(appContext || {});\n }\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n // Start the loop\n if (appContext !== false) {\n // cancel any pending renders to ensure only one loop can ever run\n this._cancelAnimationFrame();\n this._requestAnimationFrame();\n }\n\n return this;\n } catch (error) {\n this.props.onError(error);\n // this._running = false; // TODO\n return null;\n }\n }\n\n /** Explicitly draw a frame */\n redraw(): this {\n if (this.isContextLost()) {\n return this;\n }\n\n this._beginTimers();\n\n this._setupFrame();\n this._updateCallbackData();\n\n this._renderFrame(this.animationProps);\n\n // clear needsRedraw flag\n this._clearNeedsRedraw();\n\n if (this._resolveNextFrame) {\n this._resolveNextFrame(this);\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n }\n\n this._endTimers();\n\n return this;\n }\n\n // Stops a render loop if already running, finalizing\n stop() {\n // console.debug(`Stopping ${this.constructor.name}`);\n if (this._running) {\n this._finalizeCallbackData();\n this._cancelAnimationFrame();\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n this._running = false;\n }\n return this;\n }\n\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n detachTimeline(): void {\n this.timeline = null;\n }\n\n waitForRender(): Promise<AnimationLoop> {\n this.setNeedsRedraw('waitForRender');\n\n if (!this._nextFramePromise) {\n this._nextFramePromise = new Promise((resolve) => {\n this._resolveNextFrame = resolve;\n });\n }\n return this._nextFramePromise;\n }\n\n async toDataURL() {\n this.setNeedsRedraw('toDataURL');\n\n await this.waitForRender();\n\n return this.gl.canvas.toDataURL();\n }\n\n isContextLost(): boolean {\n return this.gl.isContextLost();\n }\n\n onCreateDevice(deviceProps: DeviceProps) {\n return this.props.onCreateDevice(deviceProps);\n }\n\n onInitialize(animationProps: AnimationProps): {} | void {\n return this.props.onInitialize(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n return this.props.onRender(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n return this.props.onFinalize(animationProps);\n }\n\n // DEPRECATED/REMOVED METHODS\n\n /** @deprecated Use .onCreateDevice() */\n onCreateContext(props: ContextProps) {\n return this.props.onCreateContext(props);\n }\n\n /** @deprecated */\n getHTMLControlValue(id, defaultValue = 1) {\n const element = document.getElementById(id);\n // @ts-expect-error Not all html elements have value\n return element ? Number(element.value) : defaultValue;\n }\n\n // PRIVATE METHODS\n\n _initialize(props: AnimationLoopProps) {\n // Create the WebGL context\n this._createDevice(props);\n this._createFramebuffer();\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeCallbackData();\n this._updateCallbackData();\n\n // Default viewport setup, in case onInitialize wants to render\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n\n this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;\n }\n\n _getPageLoadPromise() {\n if (!this._pageLoadPromise) {\n this._pageLoadPromise = isPage\n ? new Promise((resolve, reject) => {\n if (isPage && document.readyState === 'complete') {\n resolve(document);\n return;\n }\n window.addEventListener('load', () => {\n resolve(document);\n });\n })\n : Promise.resolve({});\n }\n return this._pageLoadPromise;\n }\n\n _setDisplay(display) {\n if (this.display) {\n this.display.delete();\n this.display.animationLoop = null;\n }\n\n // store animation loop on the display\n if (display) {\n display.animationLoop = this;\n }\n\n this.display = display;\n }\n\n _requestAnimationFrame() {\n if (!this._running) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.requestAnimationFrame) {\n // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));\n // }\n this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));\n }\n\n _cancelAnimationFrame() {\n if (this._animationFrameId !== null) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.cancelAnimationFrame) {\n // this.display.cancelAnimationFrame(this._animationFrameId);\n // }\n cancelAnimationFrame(this._animationFrameId);\n this._animationFrameId = null;\n }\n\n _animationFrame() {\n if (!this._running) {\n return;\n }\n this.redraw();\n this._requestAnimationFrame();\n }\n\n // Called on each frame, can be overridden to call onRender multiple times\n // to support e.g. stereoscopic rendering\n _renderFrame(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.onRender(props);\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = null;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n this._resizeFramebuffer();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeCallbackData() {\n // @ts-expect-error\n this.animationProps = {\n device: this.device,\n gl: this.gl,\n\n stop: this.stop,\n canvas: this.gl.canvas,\n\n // Initial values\n useDevicePixels: this.props.useDevicePixels,\n needsRedraw: null,\n\n // Animation props\n startTime: Date.now(),\n engineTime: 0,\n tick: 0,\n tock: 0,\n\n timeline: this.timeline,\n animationLoop: this,\n\n // Timeline time for back compatibility\n time: 0,\n\n // Experimental\n _mousePosition: null, // Event props\n\n // Deprecated\n framebuffer: this.framebuffer,\n _timeline: this.timeline,\n _loop: this,\n _animationLoop: this\n };\n }\n\n // Update the context object that will be passed to app callbacks\n _updateCallbackData() {\n const {width, height, aspect} = this._getSizeAndAspect();\n if (width !== this.animationProps.width || height !== this.animationProps.height) {\n this.setNeedsRedraw('drawing buffer resized');\n }\n if (aspect !== this.animationProps.aspect) {\n this.setNeedsRedraw('drawing buffer aspect changed');\n }\n\n this.animationProps.width = width;\n this.animationProps.height = height;\n this.animationProps.aspect = aspect;\n\n this.animationProps.needsRedraw = this.needsRedraw;\n\n // Update time properties\n this.animationProps.engineTime = Date.now() - this.animationProps.startTime;\n\n if (this.timeline) {\n this.timeline.update(this.animationProps.engineTime);\n }\n\n this.animationProps.tick = Math.floor((this.animationProps.time / 1000) * 60);\n this.animationProps.tock++;\n\n // For back compatibility\n this.animationProps.time = this.timeline\n ? this.timeline.getTime()\n : this.animationProps.engineTime;\n }\n\n _finalizeCallbackData() {\n // call callback\n this.onFinalize(this.animationProps);\n // end callback\n }\n\n /** Add application's data to the app context object */\n _addCallbackData(appContext) {\n if (typeof appContext === 'object' && appContext !== null) {\n this.animationProps = Object.assign({}, this.animationProps, appContext);\n }\n }\n\n /** Either uses supplied or existing context, or calls provided callback to create one */\n _createDevice(props: DeviceProps) {\n const deviceProps = {...this.props, ...props, ...this.props.glOptions};\n\n // TODO - support this.onCreateContext\n // Create the WebGL context if necessary\n // this.gl = this.props.gl ? instrumentGLContext(this.props.gl, deviceProps) : this.onCreateContext(deviceProps);\n\n this.device = this.onCreateDevice(deviceProps);\n // @ts-expect-error\n this.gl = this.device.gl;\n\n if (!isWebGL(this.gl)) {\n throw new Error('AnimationLoop.onCreateContext - illegal context returned');\n }\n\n // Reset the WebGL context.\n resetParameters(this.gl);\n\n this._createInfoDiv();\n }\n\n _createInfoDiv() {\n if (this.gl.canvas && this.props.onAddHTML) {\n const wrapperDiv = document.createElement('div');\n document.body.appendChild(wrapperDiv);\n wrapperDiv.style.position = 'relative';\n const div = document.createElement('div');\n div.style.position = 'absolute';\n div.style.left = '10px';\n div.style.bottom = '10px';\n div.style.width = '300px';\n div.style.background = 'white';\n wrapperDiv.appendChild(this.gl.canvas);\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect() {\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const width = this.gl.drawingBufferWidth;\n const height = this.gl.drawingBufferHeight;\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const {canvas} = this.gl;\n\n if (canvas && canvas.clientHeight) {\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n if (this.props.autoResizeViewport) {\n this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight);\n }\n }\n\n /** \n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n (this.device as WebGLDevice).resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n if (\n this._gpuTimeQuery &&\n this._gpuTimeQuery.isResultAvailable() &&\n !this._gpuTimeQuery.isTimerDisjoint()\n ) {\n this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n }\n\n if (this._gpuTimeQuery) {\n // GPU time query start\n this._gpuTimeQuery.beginTimeElapsedQuery();\n }\n\n this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n if (this._gpuTimeQuery) {\n // GPU time query end. Results will be available on next frame.\n this._gpuTimeQuery.end();\n }\n }\n\n // Event handling\n\n _startEventHandling() {\n const {canvas} = this.gl;\n if (canvas) {\n canvas.addEventListener('mousemove', this._onMousemove);\n canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(e) {\n this.animationProps._mousePosition = [e.offsetX, e.offsetY];\n }\n _onMouseleave(e) {\n this.animationProps._mousePosition = null;\n }\n\n // Deprecated\n\n /** @deprecated */\n _createFramebuffer() {\n // Setup default framebuffer\n if (this.props.createFramebuffer) {\n this.framebuffer = new Framebuffer(this.gl);\n }\n }\n\n /** @deprecated */\n _resizeFramebuffer() {\n if (this.framebuffer) {\n this.framebuffer.resize({\n width: this.gl.drawingBufferWidth,\n height: this.gl.drawingBufferHeight\n });\n }\n } \n}\n"],"file":"animation-loop.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","requestAnimationFrame","cancelAnimationFrame","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onAddHTML","undefined","onInitialize","onRender","onFinalize","onError","error","console","device","deviceProps","debug","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","gl","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","_running","appContext","_initialized","_createDevice","_initialize","animationProps","_cancelAnimationFrame","_requestAnimationFrame","err","Error","redraw","isLost","_beginTimers","_setupFrame","_updateCallbackData","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","_startEventHandling","_initializeCallbackData","_resizeCanvasDrawingBuffer","_resizeViewport","display","animationLoop","_animationFrameId","_animationFrame","canvasContext","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_createInfoDiv","wrapperDiv","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","getPixelSize","clientHeight","clientWidth","viewport","drawingBufferWidth","drawingBufferHeight","resize","timeEnd","timeStart","addEventListener","e","offsetX","offsetY"],"mappings":";AAAA,SAAQA,IAAR,QAAwC,cAAxC;AACA,SAAQC,qBAAR,EAA+BC,oBAA/B,QAA0D,cAA1D;AAIA,SAAQC,SAAR,QAAwB,eAAxB;AAEA,MAAMC,MAAM,GAAGD,SAAS,MAAM,OAAOE,QAAP,KAAoB,WAAlD;AAEA,IAAIC,aAAa,GAAG,CAApB;AAwBA,MAAMC,4BAA0D,GAAG;AACjEC,EAAAA,cAAc,EAAGC,KAAD,IAAyCT,IAAI,CAACU,YAAL,CAAkBD,KAAlB,CADQ;AAEjEE,EAAAA,SAAS,EAAEC,SAFsD;AAGjEC,EAAAA,YAAY,EAAE,OAAO,EAAP,CAHmD;AAIjEC,EAAAA,QAAQ,EAAE,MAAM,CAAE,CAJ+C;AAKjEC,EAAAA,UAAU,EAAE,MAAM,CAAE,CAL6C;AAMjEC,EAAAA,OAAO,EAAGC,KAAD,IAAWC,OAAO,CAACD,KAAR,CAAcA,KAAd,CAN6C;AAQjEE,EAAAA,MAAM,EAAEP,SARyD;AASjEQ,EAAAA,WAAW,EAAE,EAToD;AAUjEC,EAAAA,KAAK,EAAE,KAV0D;AAWjEC,EAAAA,KAAK,EAAEtB,IAAI,CAACsB,KAAL,CAAWC,GAAX,0BAAiCjB,aAAa,EAA9C,EAX0D;AAcjEkB,EAAAA,eAAe,EAAE,IAdgD;AAejEC,EAAAA,kBAAkB,EAAE,IAf6C;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jC;AACD;AACF;;AAEDiC,EAAAA,YAAY,GAAG;AACb,SAAKzB,SAAL,CAAesF,OAAf;AACA,SAAKtF,SAAL,CAAeuF,SAAf;AAmBD;;AAEDvD,EAAAA,UAAU,GAAG;AACX,SAAKlC,OAAL,CAAawF,OAAb;AAMD;;AAID7C,EAAAA,mBAAmB,GAAG;AACpB,QAAI,KAAKD,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAYgD,gBAAZ,CAA6B,WAA7B,EAA0C,KAAKnF,YAA/C;AACA,WAAKmC,MAAL,CAAYgD,gBAAZ,CAA6B,YAA7B,EAA2C,KAAKlF,aAAhD;AACD;AACF;;AAEDD,EAAAA,YAAY,CAACoF,CAAD,EAAI;AACd,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,CAAC6B,CAAC,CAACC,OAAH,EAAYD,CAAC,CAACE,OAAd,CAArC;AACD;;AACDrF,EAAAA,aAAa,CAACmF,CAAD,EAAI;AACf,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,IAArC;AACD;;AAhegC","sourcesContent":["import {luma, Device, DeviceProps} from '@luma.gl/api';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from '../lib/animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\nimport {isBrowser} from '@probe.gl/env';\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\ntype ContextProps = DeviceProps;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Promise<Device>;\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\n debug?: boolean;\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),\n onAddHTML: undefined,\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: undefined,\n deviceProps: {},\n debug: false,\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n};\n\n/** Convenient animation loop */\nexport default class AnimationLoop {\n device: Device;\n canvas: HTMLCanvasElement; // | OffscreenCanvas;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps;\n timeline: Timeline = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | null = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId = null;\n _nextFramePromise: Promise<AnimationLoop> | null = null;\n _resolveNextFrame: ((AnimationLoop) => void) | null = null;\n _cpuStartTime: number = 0;\n\n // _gpuTimeQuery: Query | null = null;\n\n /*\n * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context\n */\n constructor(props: AnimationLoopProps = {}) {\n this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};\n props = this.props;\n\n let {useDevicePixels = true} = this.props;\n\n // state\n this.device = props.device;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats;\n this.cpuTime = this.stats.get('CPU Time');\n this.gpuTime = this.stats.get('GPU Time');\n this.frameRate = this.stats.get('Frame Rate');\n\n this.setProps({\n autoResizeViewport: props.autoResizeViewport,\n autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,\n useDevicePixels\n });\n\n // Bind methods\n this.start = this.start.bind(this);\n this.stop = this.stop.bind(this);\n\n this._onMousemove = this._onMousemove.bind(this);\n this._onMouseleave = this._onMouseleave.bind(this);\n }\n\n destroy(): void {\n this.stop();\n this._setDisplay(null);\n }\n\n /** @deprecated Use .destroy() */\n delete(): void {\n this.destroy();\n }\n\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n // TODO - move to CanvasContext\n setProps(props: AnimationLoopProps): this {\n if ('autoResizeViewport' in props) {\n this.props.autoResizeViewport = props.autoResizeViewport;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels;\n }\n return this;\n }\n\n /** Starts a render loop if not already running */\n async start() {\n if (this._running) {\n return this;\n }\n this._running = true;\n\n try {\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n // Create the WebGL context\n await this._createDevice();\n this._initialize();\n\n // Note: onIntialize can return a promise (e.g. in case app needs to load resources)\n await this.onInitialize(this.animationProps);\n }\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n // Start the loop\n if (appContext !== false) {\n // cancel any pending renders to ensure only one loop can ever run\n this._cancelAnimationFrame();\n this._requestAnimationFrame();\n }\n\n return this;\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error('Unknown error')\n this.props.onError(error);\n // this._running = false; // TODO\n throw error;\n }\n }\n\n /** Explicitly draw a frame */\n redraw(): this {\n if (this.device.isLost) {\n return this;\n }\n\n this._beginTimers();\n\n this._setupFrame();\n this._updateCallbackData();\n\n this._renderFrame(this.animationProps);\n\n // clear needsRedraw flag\n this._clearNeedsRedraw();\n\n if (this._resolveNextFrame) {\n this._resolveNextFrame(this);\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n }\n\n this._endTimers();\n\n return this;\n }\n\n // Stops a render loop if already running, finalizing\n stop() {\n // console.debug(`Stopping ${this.constructor.name}`);\n if (this._running) {\n // call callback\n this.onFinalize(this.animationProps);\n\n this._cancelAnimationFrame();\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n this._running = false;\n }\n return this;\n }\n\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n detachTimeline(): void {\n this.timeline = null;\n }\n\n waitForRender(): Promise<AnimationLoop> {\n this.setNeedsRedraw('waitForRender');\n\n if (!this._nextFramePromise) {\n this._nextFramePromise = new Promise((resolve) => {\n this._resolveNextFrame = resolve;\n });\n }\n return this._nextFramePromise;\n }\n\n async toDataURL() {\n this.setNeedsRedraw('toDataURL');\n await this.waitForRender();\n return this.canvas.toDataURL();\n }\n\n onCreateDevice(deviceProps: DeviceProps): Promise<Device> {\n return this.props.onCreateDevice(deviceProps);\n }\n\n onInitialize(animationProps: AnimationProps): {} | void {\n return this.props.onInitialize(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n return this.props.onRender(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n return this.props.onFinalize(animationProps);\n }\n\n // PRIVATE METHODS\n\n _initialize() {\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeCallbackData();\n this._updateCallbackData();\n\n // Default viewport setup, in case onInitialize wants to render\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n\n // this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;\n }\n\n _setDisplay(display) {\n if (this.display) {\n this.display.delete();\n this.display.animationLoop = null;\n }\n\n // store animation loop on the display\n if (display) {\n display.animationLoop = this;\n }\n\n this.display = display;\n }\n\n _requestAnimationFrame() {\n if (!this._running) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.requestAnimationFrame) {\n // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));\n // }\n this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));\n }\n\n _cancelAnimationFrame() {\n if (this._animationFrameId !== null) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.cancelAnimationFrame) {\n // this.display.cancelAnimationFrame(this._animationFrameId);\n // }\n cancelAnimationFrame(this._animationFrameId);\n this._animationFrameId = null;\n }\n\n _animationFrame() {\n if (!this._running) {\n return;\n }\n this.redraw();\n this._requestAnimationFrame();\n }\n\n // Called on each frame, can be overridden to call onRender multiple times\n // to support e.g. stereoscopic rendering\n _renderFrame(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.onRender(props);\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = null;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeCallbackData() {\n this.animationProps = {\n animationLoop: this,\n device: this.device,\n canvas: this.device.canvasContext.canvas,\n timeline: this.timeline,\n\n // Initial values\n useDevicePixels: this.props.useDevicePixels,\n needsRedraw: null,\n\n // Placeholders\n width: 1,\n height: 1,\n aspect: 1,\n\n // Animation props\n time: 0,\n startTime: Date.now(),\n engineTime: 0,\n tick: 0,\n tock: 0,\n\n // Experimental\n _mousePosition: null // Event props\n };\n }\n\n // Update the context object that will be passed to app callbacks\n _updateCallbackData() {\n const {width, height, aspect} = this._getSizeAndAspect();\n if (width !== this.animationProps.width || height !== this.animationProps.height) {\n this.setNeedsRedraw('drawing buffer resized');\n }\n if (aspect !== this.animationProps.aspect) {\n this.setNeedsRedraw('drawing buffer aspect changed');\n }\n\n this.animationProps.width = width;\n this.animationProps.height = height;\n this.animationProps.aspect = aspect;\n\n this.animationProps.needsRedraw = this.needsRedraw;\n\n // Update time properties\n this.animationProps.engineTime = Date.now() - this.animationProps.startTime;\n\n if (this.timeline) {\n this.timeline.update(this.animationProps.engineTime);\n }\n\n this.animationProps.tick = Math.floor((this.animationProps.time / 1000) * 60);\n this.animationProps.tock++;\n\n // For back compatibility\n this.animationProps.time = this.timeline\n ? this.timeline.getTime()\n : this.animationProps.engineTime;\n }\n\n /** Either uses supplied or existing context, or calls provided callback to create one */\n async _createDevice() {\n const deviceProps = {...this.props, ...this.props.deviceProps};\n this.device = await this.onCreateDevice(deviceProps);\n // @ts-expect-error\n this.canvas = this.device.canvasContext.canvas;\n this._createInfoDiv();\n }\n\n _createInfoDiv() {\n if (this.canvas && this.props.onAddHTML) {\n const wrapperDiv = document.createElement('div');\n document.body.appendChild(wrapperDiv);\n wrapperDiv.style.position = 'relative';\n const div = document.createElement('div');\n div.style.position = 'absolute';\n div.style.left = '10px';\n div.style.bottom = '10px';\n div.style.width = '300px';\n div.style.background = 'white';\n wrapperDiv.appendChild(this.canvas);\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect() {\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const [width, height] = this.device.canvasContext.getPixelSize();\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const canvas = this.device.canvasContext.canvas;\n\n // @ts-expect-error\n if (canvas && canvas.clientHeight) {\n // @ts-expect-error\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n // @ts-expect-error Expose on canvasContext\n if (this.props.autoResizeViewport && this.device.gl) {\n // @ts-expect-error Expose canvasContext\n this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);\n }\n }\n\n /**\n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n this.device.canvasContext.resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n // if (\n // this._gpuTimeQuery &&\n // this._gpuTimeQuery.isResultAvailable() &&\n // !this._gpuTimeQuery.isTimerDisjoint()\n // ) {\n // this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n // }\n\n // if (this._gpuTimeQuery) {\n // // GPU time query start\n // this._gpuTimeQuery.beginTimeElapsedQuery();\n // }\n\n // this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n // if (this._gpuTimeQuery) {\n // // GPU time query end. Results will be available on next frame.\n // this._gpuTimeQuery.end();\n // }\n }\n\n // Event handling\n\n _startEventHandling() {\n if (this.canvas) {\n this.canvas.addEventListener('mousemove', this._onMousemove);\n this.canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(e) {\n this.animationProps._mousePosition = [e.offsetX, e.offsetY];\n }\n _onMouseleave(e) {\n this.animationProps._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="offscreencanvas" />
|
|
2
|
+
import { Device } from '@luma.gl/api';
|
|
3
|
+
import { Timeline } from '../animation/timeline';
|
|
4
|
+
import type AnimationLoop from './animation-loop';
|
|
5
|
+
/** Properties passed to every render frame */
|
|
6
|
+
export declare type AnimationProps = {
|
|
7
|
+
device: Device;
|
|
8
|
+
animationLoop: AnimationLoop;
|
|
9
|
+
/** @todo Should be canvasContext */
|
|
10
|
+
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
11
|
+
useDevicePixels: number | boolean;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
aspect: number;
|
|
15
|
+
time: number;
|
|
16
|
+
startTime: number;
|
|
17
|
+
engineTime: number;
|
|
18
|
+
tick: number;
|
|
19
|
+
tock: number;
|
|
20
|
+
needsRedraw?: string;
|
|
21
|
+
timeline: Timeline;
|
|
22
|
+
_mousePosition?: [number, number];
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=animation-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/lib/animation-props.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAC9C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAElD,+CAA+C;AAC/C,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAE7B,oCAAoC;IACpC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAC;IAC5C,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAGb,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,QAAQ,EAAE,QAAQ,CAAC;IAGnB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"animation-props.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=clip-space.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clip-space.d.ts","sourceRoot":"","sources":["../../src/lib/clip-space.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"clip-space.js"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Buffer } from '@luma.gl/
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { Device, Buffer } from '@luma.gl/api';
|
|
2
|
+
import type Geometry from '../geometry/geometry';
|
|
3
|
+
export declare function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined;
|
|
4
|
+
export declare function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): Record<string, Buffer>;
|
|
4
5
|
//# sourceMappingURL=model-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/lib/model-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/lib/model-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAS,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAsDjD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAYjG;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1G"}
|