@luma.gl/engine 9.0.0-alpha.11 → 9.0.0-alpha.12
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/{lib → animation-loop}/animation-loop.d.ts +14 -11
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +17 -18
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +0 -0
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.js +0 -0
- package/dist/{lib → animation-loop}/animation-props.js.map +0 -0
- package/dist/animation-loop/make-animation-loop.d.ts +6 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/make-animation-loop.js +34 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/animation-loop/render-loop.d.ts +23 -0
- package/dist/animation-loop/render-loop.d.ts.map +1 -0
- package/dist/animation-loop/render-loop.js +9 -0
- package/dist/animation-loop/render-loop.js.map +1 -0
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts.map +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.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +13 -0
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +7 -0
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/model-utils.js +2 -2
- package/dist/lib/model-utils.js.map +1 -1
- package/dist/lib/model.d.ts +2 -2
- package/dist/lib/model.d.ts.map +1 -1
- package/dist/lib/model.js +1 -1
- package/dist/lib/model.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/package.json +5 -5
- package/src/{lib → animation-loop}/animation-loop.ts +34 -31
- package/src/{lib → animation-loop}/animation-props.ts +0 -0
- package/src/animation-loop/make-animation-loop.ts +43 -0
- package/src/animation-loop/render-loop.ts +23 -0
- package/src/geometries/cube-geometry.ts +1 -1
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +3 -3
- package/src/geometries/plane-geometry.ts +2 -2
- package/src/geometries/sphere-geometry.ts +1 -1
- package/src/geometries/truncated-cone-geometry.ts +1 -1
- package/src/geometry/geometry-utils.ts +2 -2
- package/src/geometry/geometry.ts +9 -7
- package/src/index.ts +14 -8
- package/src/lib/model-utils.ts +3 -2
- package/src/lib/model.ts +2 -2
- package/src/lib/pipeline-factory.ts +3 -3
- package/dist/lib/animation-loop.d.ts.map +0 -1
- package/dist/lib/animation-loop.js.map +0 -1
- package/dist/lib/animation-props.d.ts.map +0 -1
- package/dist/lib/render-loop.d.ts +0 -19
- package/dist/lib/render-loop.d.ts.map +0 -1
- package/dist/lib/render-loop.js +0 -53
- package/dist/lib/render-loop.js.map +0 -1
- package/src/lib/render-loop.ts +0 -60
|
@@ -1,53 +1,54 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
2
|
|
|
3
|
-
import {luma, Device
|
|
3
|
+
import {luma, Device} from '@luma.gl/api';
|
|
4
4
|
import {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';
|
|
5
5
|
import {Timeline} from '../animation/timeline';
|
|
6
|
-
import {AnimationProps} from '
|
|
6
|
+
import {AnimationProps} from './animation-props';
|
|
7
7
|
import {Stats, Stat} from '@probe.gl/stats';
|
|
8
|
-
import {isBrowser} from '@probe.gl/env';
|
|
9
|
-
|
|
10
|
-
const isPage = isBrowser() && typeof document !== 'undefined';
|
|
11
8
|
|
|
12
9
|
let statIdCounter = 0;
|
|
13
10
|
|
|
14
|
-
type ContextProps = DeviceProps;
|
|
15
|
-
|
|
16
11
|
/** AnimationLoop properties */
|
|
17
12
|
export type AnimationLoopProps = {
|
|
18
|
-
|
|
13
|
+
device: Device | Promise<Device>;
|
|
14
|
+
|
|
19
15
|
onAddHTML?: (div: HTMLDivElement) => string; // innerHTML
|
|
20
16
|
onInitialize?: (animationProps: AnimationProps) => Promise<unknown>;
|
|
21
17
|
onRender?: (animationProps: AnimationProps) => unknown;
|
|
22
18
|
onFinalize?: (animationProps: AnimationProps) => void;
|
|
23
19
|
onError?: (reason: Error) => void;
|
|
24
20
|
|
|
25
|
-
device?: Device | null;
|
|
26
|
-
deviceProps?: DeviceProps;
|
|
27
21
|
stats?: Stats;
|
|
28
22
|
|
|
29
|
-
// view parameters
|
|
23
|
+
// view parameters - TODO move to CanvasContext?
|
|
30
24
|
autoResizeViewport?: boolean;
|
|
31
25
|
autoResizeDrawingBuffer?: boolean;
|
|
32
26
|
useDevicePixels?: number | boolean;
|
|
33
27
|
};
|
|
34
28
|
|
|
29
|
+
export type MutableAnimationLoopProps = {
|
|
30
|
+
// view parameters
|
|
31
|
+
autoResizeViewport?: boolean;
|
|
32
|
+
autoResizeDrawingBuffer?: boolean;
|
|
33
|
+
useDevicePixels?: number | boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
35
37
|
const DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {
|
|
36
|
-
|
|
38
|
+
device: null!,
|
|
39
|
+
|
|
37
40
|
onAddHTML: () => '',
|
|
38
41
|
onInitialize: async () => { return null; },
|
|
39
42
|
onRender: () => {},
|
|
40
43
|
onFinalize: () => {},
|
|
41
44
|
onError: (error) => console.error(error), // eslint-disable-line no-console
|
|
42
45
|
|
|
43
|
-
device: null,
|
|
44
|
-
deviceProps: {},
|
|
45
46
|
stats: luma.stats.get(`animation-loop-${statIdCounter++}`),
|
|
46
47
|
|
|
47
48
|
// view parameters
|
|
48
49
|
useDevicePixels: true,
|
|
49
|
-
autoResizeViewport:
|
|
50
|
-
autoResizeDrawingBuffer:
|
|
50
|
+
autoResizeViewport: false,
|
|
51
|
+
autoResizeDrawingBuffer: false,
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
/** Convenient animation loop */
|
|
@@ -71,7 +72,7 @@ export class AnimationLoop {
|
|
|
71
72
|
_running: boolean = false;
|
|
72
73
|
_animationFrameId: any = null;
|
|
73
74
|
_nextFramePromise: Promise<AnimationLoop> | null = null;
|
|
74
|
-
_resolveNextFrame: ((AnimationLoop) => void) | null = null;
|
|
75
|
+
_resolveNextFrame: ((animationLoop: AnimationLoop) => void) | null = null;
|
|
75
76
|
_cpuStartTime: number = 0;
|
|
76
77
|
|
|
77
78
|
// _gpuTimeQuery: Query | null = null;
|
|
@@ -79,17 +80,17 @@ export class AnimationLoop {
|
|
|
79
80
|
/*
|
|
80
81
|
* @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context
|
|
81
82
|
*/
|
|
82
|
-
constructor(props: AnimationLoopProps
|
|
83
|
+
constructor(props: AnimationLoopProps) {
|
|
83
84
|
this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};
|
|
84
85
|
props = this.props;
|
|
85
86
|
|
|
87
|
+
if (!props.device) {
|
|
88
|
+
throw new Error('No device provided');
|
|
89
|
+
}
|
|
90
|
+
|
|
86
91
|
let {useDevicePixels = true} = this.props;
|
|
87
92
|
|
|
88
93
|
// state
|
|
89
|
-
this.device = props.device || null;
|
|
90
|
-
// @ts-expect-error
|
|
91
|
-
this.gl = (this.device && this.device.gl) || props.gl;
|
|
92
|
-
|
|
93
94
|
this.stats = props.stats || new Stats({id: 'animation-loop-stats'});
|
|
94
95
|
this.cpuTime = this.stats.get('CPU Time');
|
|
95
96
|
this.gpuTime = this.stats.get('GPU Time');
|
|
@@ -125,7 +126,7 @@ export class AnimationLoop {
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
// TODO - move to CanvasContext
|
|
128
|
-
setProps(props:
|
|
129
|
+
setProps(props: MutableAnimationLoopProps): this {
|
|
129
130
|
if ('autoResizeViewport' in props) {
|
|
130
131
|
this.props.autoResizeViewport = props.autoResizeViewport || false;
|
|
131
132
|
}
|
|
@@ -155,7 +156,7 @@ export class AnimationLoop {
|
|
|
155
156
|
if (!this._initialized) {
|
|
156
157
|
this._initialized = true;
|
|
157
158
|
// Create the WebGL context
|
|
158
|
-
await this.
|
|
159
|
+
await this._initDevice();
|
|
159
160
|
this._initialize();
|
|
160
161
|
|
|
161
162
|
// Note: onIntialize can return a promise (e.g. in case app needs to load resources)
|
|
@@ -273,7 +274,7 @@ export class AnimationLoop {
|
|
|
273
274
|
// this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;
|
|
274
275
|
}
|
|
275
276
|
|
|
276
|
-
_setDisplay(display) {
|
|
277
|
+
_setDisplay(display: any) {
|
|
277
278
|
if (this.display) {
|
|
278
279
|
this.display.delete();
|
|
279
280
|
this.display.animationLoop = null;
|
|
@@ -422,12 +423,14 @@ export class AnimationLoop {
|
|
|
422
423
|
: this.animationProps.engineTime;
|
|
423
424
|
}
|
|
424
425
|
|
|
425
|
-
/**
|
|
426
|
-
async
|
|
427
|
-
|
|
428
|
-
this.device
|
|
429
|
-
|
|
430
|
-
|
|
426
|
+
/** Wait for supplied device */
|
|
427
|
+
async _initDevice() {
|
|
428
|
+
this.device = await this.props.device;
|
|
429
|
+
if (!this.device) {
|
|
430
|
+
throw new Error('No device provided');
|
|
431
|
+
}
|
|
432
|
+
this.canvas = this.device.canvasContext?.canvas || null;
|
|
433
|
+
// this._createInfoDiv();
|
|
431
434
|
}
|
|
432
435
|
|
|
433
436
|
_createInfoDiv() {
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
import {luma} from '@luma.gl/api';
|
|
3
|
+
import {AnimationLoopTemplate} from './render-loop'
|
|
4
|
+
import {AnimationLoop, AnimationLoopProps} from './animation-loop'
|
|
5
|
+
import type {AnimationProps} from './animation-props';
|
|
6
|
+
|
|
7
|
+
export type MakeAnimationLoopProps = Omit<AnimationLoopProps, 'onCreateDevice' | 'onInitialize' | 'onRedraw' | 'onFinalize'>;
|
|
8
|
+
|
|
9
|
+
/** Instantiates and runs the render loop */
|
|
10
|
+
export function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoopTemplate, props?: MakeAnimationLoopProps): AnimationLoop {
|
|
11
|
+
let renderLoop: AnimationLoopTemplate | null = null;
|
|
12
|
+
|
|
13
|
+
const device = props?.device || luma.createDevice();
|
|
14
|
+
|
|
15
|
+
// Create an animation loop;
|
|
16
|
+
const animationLoop = new AnimationLoop({
|
|
17
|
+
... props,
|
|
18
|
+
|
|
19
|
+
device,
|
|
20
|
+
|
|
21
|
+
async onInitialize(animationProps: AnimationProps): Promise<unknown> {
|
|
22
|
+
// @ts-expect-error abstract to prevent instantiation
|
|
23
|
+
renderLoop = new AnimationLoopTemplateCtor(animationProps);
|
|
24
|
+
// Any async loading can be handled here
|
|
25
|
+
return await renderLoop?.onInitialize(animationProps);
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
onRender: (animationProps: AnimationProps) => renderLoop?.onRender(animationProps),
|
|
29
|
+
|
|
30
|
+
onFinalize: (animationProps: AnimationProps) => renderLoop?.onFinalize(animationProps)
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// @ts-expect-error Hack: adds info for the website to find
|
|
34
|
+
animationLoop.getInfo = () => {
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
return this.AnimationLoopTemplateCtor.info;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Start the loop automatically
|
|
40
|
+
// animationLoop.start();
|
|
41
|
+
|
|
42
|
+
return animationLoop;
|
|
43
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {AnimationProps} from './animation-props';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal class that represents a "componentized" rendering life cycle
|
|
5
|
+
* (resource construction, repeated rendering, resource destruction)
|
|
6
|
+
*
|
|
7
|
+
* @note A motivation for this class compared to the raw animation loop is
|
|
8
|
+
* that it simplifies TypeScript code by allowing resources to be typed unconditionally
|
|
9
|
+
* since they are allocated in the constructor rather than in onInitialized
|
|
10
|
+
*
|
|
11
|
+
* @note Introduced in luma.gl v9
|
|
12
|
+
*
|
|
13
|
+
* @example AnimationLoopTemplate is intended to be subclassed,
|
|
14
|
+
* but the subclass should not be instantiated directly. Instead the subclass
|
|
15
|
+
* (i.e. the constructor of the subclass) should be used
|
|
16
|
+
* as an argument to create an AnimationLoop.
|
|
17
|
+
*/
|
|
18
|
+
export abstract class AnimationLoopTemplate {
|
|
19
|
+
constructor(animationProps?: AnimationProps) {}
|
|
20
|
+
async onInitialize(animationProps: AnimationProps): Promise<unknown> { return null; }
|
|
21
|
+
abstract onRender(animationProps: AnimationProps): unknown;
|
|
22
|
+
abstract onFinalize(animationProps: AnimationProps): void;
|
|
23
|
+
}
|
|
@@ -11,7 +11,7 @@ export type IcoSphereGeometryProps = {
|
|
|
11
11
|
id?: string;
|
|
12
12
|
radius?: number;
|
|
13
13
|
iterations?: number;
|
|
14
|
-
attributes
|
|
14
|
+
attributes?: any
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export class IcoSphereGeometry extends Geometry {
|
|
@@ -40,9 +40,9 @@ function tesselateIcosaHedron(props: IcoSphereGeometryProps) {
|
|
|
40
40
|
indices.push();
|
|
41
41
|
|
|
42
42
|
const getMiddlePoint = (() => {
|
|
43
|
-
const pointMemo = {};
|
|
43
|
+
const pointMemo: Record<string, number> = {};
|
|
44
44
|
|
|
45
|
-
return (i1, i2) => {
|
|
45
|
+
return (i1: number, i2: number) => {
|
|
46
46
|
i1 *= 3;
|
|
47
47
|
i2 *= 3;
|
|
48
48
|
const mini = i1 < i2 ? i1 : i2;
|
|
@@ -5,7 +5,7 @@ import {unpackIndexedGeometry} from '../geometry/geometry-utils';
|
|
|
5
5
|
export type PlaneGeometryProps = {
|
|
6
6
|
id?: string;
|
|
7
7
|
radius?: number;
|
|
8
|
-
attributes
|
|
8
|
+
attributes?: any
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
// Primitives inspired by TDL http://code.google.com/p/webglsamples/,
|
|
@@ -26,7 +26,7 @@ export class PlaneGeometry extends Geometry {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/* eslint-disable complexity, max-statements */
|
|
29
|
-
function tesselatePlane(props) {
|
|
29
|
+
function tesselatePlane(props: any) {
|
|
30
30
|
const {type = 'x,y', offset = 0, flipCull = false, unpack = false} = props;
|
|
31
31
|
|
|
32
32
|
const coords = type.split(',');
|
|
@@ -34,7 +34,7 @@ export function makeTruncatedConeGeometry(props?: TruncatedConeGeometryProps): G
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export class TruncatedConeGeometry extends Geometry {
|
|
37
|
-
constructor(props: TruncatedConeGeometryProps & {id?: string; attributes
|
|
37
|
+
constructor(props: TruncatedConeGeometryProps & {id?: string; attributes?: any} = {}) {
|
|
38
38
|
const {id = uid('truncated-code-geometry')} = props;
|
|
39
39
|
const {indices, attributes} = tesselateTruncatedCone(props);
|
|
40
40
|
super({
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// import type Geometry from './geometry';
|
|
2
2
|
|
|
3
|
-
export function unpackIndexedGeometry(geometry) {
|
|
3
|
+
export function unpackIndexedGeometry(geometry: any) {
|
|
4
4
|
const {indices, attributes} = geometry;
|
|
5
5
|
if (!indices) {
|
|
6
6
|
return geometry;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const vertexCount = indices.value.length;
|
|
10
|
-
const unpackedAttributes = {};
|
|
10
|
+
const unpackedAttributes: Record<string, any> = {};
|
|
11
11
|
|
|
12
12
|
for (const attributeName in attributes) {
|
|
13
13
|
const attribute = attributes[attributeName];
|
package/src/geometry/geometry.ts
CHANGED
|
@@ -68,6 +68,7 @@ export default class Geometry {
|
|
|
68
68
|
NORMAL: GeometryAttribute,
|
|
69
69
|
TEXCOORD_0: GeometryAttribute,
|
|
70
70
|
COLOR_0?: GeometryAttribute,
|
|
71
|
+
[key: string]: GeometryAttribute | undefined
|
|
71
72
|
};
|
|
72
73
|
readonly indices?: Uint16Array | Uint32Array;
|
|
73
74
|
|
|
@@ -109,8 +110,8 @@ export default class Geometry {
|
|
|
109
110
|
// Move indices to separate field
|
|
110
111
|
if (attributeName === 'indices') {
|
|
111
112
|
assert(!this.indices);
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
// @ts-expect-error
|
|
114
|
+
this.indices = attribute;
|
|
114
115
|
} else {
|
|
115
116
|
this.attributes[attributeName] = attribute;
|
|
116
117
|
}
|
|
@@ -136,9 +137,10 @@ export default class Geometry {
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
// Return an object with all attributes plus indices added as a field.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
getAttributes(): GeometryAttributes {
|
|
141
|
+
// @ts-expect-error Geometry types are a mess
|
|
142
|
+
return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
|
|
143
|
+
}
|
|
142
144
|
|
|
143
145
|
// PRIVATE
|
|
144
146
|
|
|
@@ -151,12 +153,12 @@ export default class Geometry {
|
|
|
151
153
|
// type: indices, vertices, uvs
|
|
152
154
|
// size: elements per vertex
|
|
153
155
|
// target: WebGL buffer type (string or constant)
|
|
154
|
-
_setAttributes(attributes: Record<string, GeometryAttribute>, indices): this {
|
|
156
|
+
_setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
|
|
155
157
|
|
|
156
158
|
return this;
|
|
157
159
|
}
|
|
158
160
|
|
|
159
|
-
_calculateVertexCount(attributes, indices): number {
|
|
161
|
+
_calculateVertexCount(attributes: any, indices: any): number {
|
|
160
162
|
if (indices) {
|
|
161
163
|
return indices.value.length;
|
|
162
164
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
// luma.gl Engine API
|
|
2
|
-
export type {AnimationProps} from './lib/animation-props';
|
|
3
|
-
export type {AnimationLoopProps} from './lib/animation-loop';
|
|
4
|
-
export {AnimationLoop} from './lib/animation-loop';
|
|
5
|
-
export {RenderLoop} from './lib/render-loop';
|
|
6
|
-
export type {ModelProps} from './lib/model';
|
|
7
|
-
export {default as Model} from './lib/model';
|
|
8
|
-
|
|
9
|
-
export {PipelineFactory} from './lib/pipeline-factory';
|
|
10
2
|
|
|
11
3
|
// Animation
|
|
12
4
|
export {Timeline} from './animation/timeline';
|
|
13
5
|
export {KeyFrames} from './animation/key-frames';
|
|
6
|
+
export type {AnimationProps} from './animation-loop/animation-props';
|
|
7
|
+
|
|
8
|
+
export {AnimationLoopTemplate} from './animation-loop/render-loop';
|
|
9
|
+
|
|
10
|
+
export type {AnimationLoopProps} from './animation-loop/animation-loop';
|
|
11
|
+
export {AnimationLoop} from './animation-loop/animation-loop';
|
|
12
|
+
|
|
13
|
+
export type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';
|
|
14
|
+
export {makeAnimationLoop} from './animation-loop/make-animation-loop';
|
|
15
|
+
|
|
16
|
+
export type {ModelProps} from './lib/model';
|
|
17
|
+
export {Model} from './lib/model';
|
|
18
|
+
|
|
19
|
+
export {PipelineFactory} from './lib/pipeline-factory';
|
|
14
20
|
|
|
15
21
|
// Utils
|
|
16
22
|
// export {default as ClipSpace} from './lib/clip-space';
|
package/src/lib/model-utils.ts
CHANGED
|
@@ -72,10 +72,10 @@ export function getAttributeBuffersFromGeometry(device: Device, geometry: Geomet
|
|
|
72
72
|
|
|
73
73
|
for (const [name, attribute] of Object.entries(geometry.attributes)) {
|
|
74
74
|
const remappedName = mapAttributeName(name);
|
|
75
|
-
if (attribute
|
|
75
|
+
if (attribute?.constant) {
|
|
76
76
|
throw new Error('constant attributes not supported');
|
|
77
77
|
} else {
|
|
78
|
-
const typedArray = attribute
|
|
78
|
+
const typedArray = attribute?.value;
|
|
79
79
|
buffers[remappedName] = device.createBuffer({data: typedArray, id: `${remappedName}-buffer`});
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -84,6 +84,7 @@ export function getAttributeBuffersFromGeometry(device: Device, geometry: Geomet
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function mapAttributeName(name: string): string {
|
|
87
|
+
// @ts-ignore-error
|
|
87
88
|
return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;
|
|
88
89
|
}
|
|
89
90
|
|
package/src/lib/model.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
2
|
|
|
3
3
|
import type {Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology} from '@luma.gl/api';
|
|
4
|
-
import {RenderPipeline
|
|
4
|
+
import {RenderPipeline} from '@luma.gl/api';
|
|
5
5
|
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
6
6
|
import type Geometry from '../geometry/geometry';
|
|
7
7
|
import {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';
|
|
@@ -29,7 +29,7 @@ const DEFAULT_MODEL_PROPS: Required<ModelProps> = {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
/** v9 API */
|
|
32
|
-
export
|
|
32
|
+
export class Model {
|
|
33
33
|
readonly device: Device;
|
|
34
34
|
readonly pipeline: RenderPipeline;
|
|
35
35
|
readonly id: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {Device, RenderPipeline
|
|
1
|
+
import type {RenderPipelineParameters, PrimitiveTopology, ShaderLayout} from '@luma.gl/api';
|
|
2
|
+
import {Device, RenderPipeline} from '@luma.gl/api/';
|
|
3
3
|
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
4
4
|
import {assembleShaders} from '@luma.gl/shadertools';
|
|
5
5
|
|
|
@@ -89,7 +89,7 @@ export class PipelineFactory {
|
|
|
89
89
|
this.stateHash++;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
addShaderHook(hook: string, opts
|
|
92
|
+
addShaderHook(hook: string, opts?: any): void {
|
|
93
93
|
if (opts) {
|
|
94
94
|
hook = Object.assign(opts, {hook});
|
|
95
95
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"animation-loop.d.ts","sourceRoot":"","sources":["../../src/lib/animation-loop.ts"],"names":[],"mappings":";AAEA,OAAO,EAAO,MAAM,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAS5C,+BAA+B;AAC/B,oBAAY,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACpE,QAAQ,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,OAAO,CAAC;IACvD,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACtD,OAAO,CAAC,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AkB,GAAG,IAAI;IAazC,kDAAkD;IAC5C,KAAK;IA4CX,8BAA8B;IAC9B,MAAM,IAAI,IAAI;IA2Bd,IAAI;IAiBJ,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IAK5C,cAAc,IAAI,IAAI;IAItB,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAWjC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAWlC,WAAW;IAcX,WAAW,CAAC,OAAO,KAAA;IAcnB,sBAAsB;IActB,qBAAqB;IAerB,eAAe;IAUf,YAAY,CAAC,cAAc,EAAE,cAAc;IAY3C,iBAAiB;IAIjB,WAAW;IAMX,yBAAyB;IA+BzB,kBAAkB,IAAI,cAAc;IAQpC,qBAAqB,IAAI,IAAI;IAmC7B,yFAAyF;IACnF,aAAa;IAOnB,cAAc;IAsBd,iBAAiB,IAAI;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC;IAsBpE,6BAA6B;IAC7B,eAAe;IAQf;;;OAGG;IACH,0BAA0B;IAM1B,YAAY;IAuBZ,UAAU;IAWV,mBAAmB;IAOnB,YAAY,CAAC,KAAK,EAAE,KAAK;IAMzB,aAAa,CAAC,KAAK,EAAE,KAAK;CAG3B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","requestAnimationFrame","cancelAnimationFrame","Stats","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onAddHTML","onInitialize","onRender","onFinalize","onError","error","console","device","deviceProps","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","gl","id","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","_running","appContext","_initialized","_createDevice","_initialize","_getAnimationProps","_cancelAnimationFrame","_requestAnimationFrame","err","Error","redraw","isLost","_beginTimers","_setupFrame","_updateAnimationProps","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","animationProps","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","HTMLCanvasElement","_startEventHandling","_initializeAnimationProps","_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","event","MouseEvent","offsetX","offsetY"],"mappings":";AAEA,SAAQA,IAAR,QAAwC,cAAxC;AACA,SAAQC,qBAAR,EAA+BC,oBAA/B,QAA0D,cAA1D;AAGA,SAAQC,KAAR,QAA0B,iBAA1B;AACA,SAAQC,SAAR,QAAwB,eAAxB;AAEA,MAAMC,MAAM,GAAGD,SAAS,MAAM,OAAOE,QAAP,KAAoB,WAAlD;AAEA,IAAIC,aAAa,GAAG,CAApB;AAuBA,MAAMC,4BAA0D,GAAG;AACjEC,EAAAA,cAAc,EAAGC,KAAD,IAAyCV,IAAI,CAACW,YAAL,CAAkBD,KAAlB,CADQ;AAEjEE,EAAAA,SAAS,EAAE,MAAM,EAFgD;AAGjEC,EAAAA,YAAY,EAAE,YAAY;AAAE,WAAO,IAAP;AAAc,GAHuB;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,EAAE,IARyD;AASjEC,EAAAA,WA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AAiC;AAC/B,WAAK1E,kBAAL,GAA0B4C,cAA1B,GAA2C,CAAC6B,KAAK,CAACE,OAAP,EAAgBF,KAAK,CAACG,OAAtB,CAA3C;AACD;AACF;;AAEDxF,EAAAA,aAAa,CAACqF,KAAD,EAAe;AAC1B,SAAKzE,kBAAL,GAA0B4C,cAA1B,GAA2C,IAA3C;AACD;;AA3ewB","sourcesContent":["// luma.gl, MIT license\n\nimport {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) => Promise<unknown>;\n onRender?: (animationProps: AnimationProps) => unknown;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device | null;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\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: () => '',\n onInitialize: async () => { return null; },\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: null,\n deviceProps: {},\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 class AnimationLoop {\n device: Device | null = null;\n canvas: HTMLCanvasElement | OffscreenCanvas | null = null;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps | null = null;\n timeline: Timeline | null = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | false = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId: any = 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 || null;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats || new Stats({id: 'animation-loop-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 || false;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer || false;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels || false;\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.props.onInitialize(this._getAnimationProps());\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._updateAnimationProps();\n\n this._renderFrame(this._getAnimationProps());\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 // If stop is called immediately, we can end up in a state where props haven't been initialized...\n if (this.animationProps) {\n this.props.onFinalize(this.animationProps);\n }\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(): Promise<string> {\n this.setNeedsRedraw('toDataURL');\n await this.waitForRender();\n if (this.canvas instanceof HTMLCanvasElement) {\n return this.canvas.toDataURL();\n }\n throw new Error('OffscreenCanvas');\n }\n\n // PRIVATE METHODS\n\n _initialize() {\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeAnimationProps();\n this._updateAnimationProps();\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(animationProps: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(animationProps);\n return;\n }\n\n // call callback\n this.props.onRender(this._getAnimationProps());\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = false;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeAnimationProps() {\n if (!this.device) {\n throw new Error('loop');\n }\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: false,\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 _getAnimationProps(): AnimationProps {\n if (!this.animationProps) {\n throw new Error('animationProps');\n }\n return this.animationProps;\n }\n\n // Update the context object that will be passed to app callbacks\n _updateAnimationProps(): void {\n if (!this.animationProps) {\n return;\n }\n\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.props.onCreateDevice(deviceProps);\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 if (this.canvas instanceof HTMLCanvasElement) {\n wrapperDiv.appendChild(this.canvas);\n }\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect(): {width: number; height: number; aspect: number} {\n if (!this.device) {\n return {width: 1, height: 1, aspect: 1};\n }\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const [width, height] = this.device?.canvasContext?.getPixelSize() || [1, 1];\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(event: Event) {\n if (event instanceof MouseEvent) {\n this._getAnimationProps()._mousePosition = [event.offsetX, event.offsetY];\n }\n }\n\n _onMouseleave(event: Event) {\n this._getAnimationProps()._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAEpD,+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,GAAG,KAAK,CAAC;IAE7B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAG1B,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC1C,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { DeviceProps } from '@luma.gl/api';
|
|
2
|
-
import type { AnimationProps } from '../lib/animation-props';
|
|
3
|
-
import { AnimationLoop } from './animation-loop';
|
|
4
|
-
/**
|
|
5
|
-
* Minimal animation loop that initializes models in constructor
|
|
6
|
-
* Simplifying type management
|
|
7
|
-
* v9 API
|
|
8
|
-
*/
|
|
9
|
-
export declare abstract class RenderLoop {
|
|
10
|
-
animationLoop?: AnimationLoop;
|
|
11
|
-
constructor(animationProps?: AnimationProps);
|
|
12
|
-
destroy(): void;
|
|
13
|
-
onInitialize(animationProps: AnimationProps): Promise<unknown>;
|
|
14
|
-
abstract onRender(animationProps: AnimationProps): unknown;
|
|
15
|
-
abstract onFinalize(animationProps: AnimationProps): void;
|
|
16
|
-
/** Instantiates and runs the render loop */
|
|
17
|
-
static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=render-loop.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-loop.d.ts","sourceRoot":"","sources":["../../src/lib/render-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,8BAAsB,UAAU;IAE9B,aAAa,CAAC,EAAE,aAAa,CAAC;gBAElB,cAAc,CAAC,EAAE,cAAc;IAE3C,OAAO,IAAI,IAAI;IAIT,YAAY,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IACpE,QAAQ,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO;IAC1D,QAAQ,CAAC,UAAU,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI;IAEzD,4CAA4C;IAC5C,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,OAAO,UAAU,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa;CAmC/F"}
|
package/dist/lib/render-loop.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { AnimationLoop } from './animation-loop';
|
|
3
|
-
export class RenderLoop {
|
|
4
|
-
constructor(animationProps) {
|
|
5
|
-
_defineProperty(this, "animationLoop", void 0);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
destroy() {
|
|
9
|
-
var _this$animationLoop;
|
|
10
|
-
|
|
11
|
-
(_this$animationLoop = this.animationLoop) === null || _this$animationLoop === void 0 ? void 0 : _this$animationLoop.destroy();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async onInitialize(animationProps) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static run(RenderLoopConstructor, deviceProps) {
|
|
19
|
-
let renderLoop = null;
|
|
20
|
-
const animationLoop = new AnimationLoop({
|
|
21
|
-
deviceProps,
|
|
22
|
-
|
|
23
|
-
async onInitialize(animationProps) {
|
|
24
|
-
var _renderLoop;
|
|
25
|
-
|
|
26
|
-
renderLoop = new RenderLoopConstructor(animationProps);
|
|
27
|
-
renderLoop.animationLoop = animationLoop;
|
|
28
|
-
return await ((_renderLoop = renderLoop) === null || _renderLoop === void 0 ? void 0 : _renderLoop.onInitialize(animationProps));
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
onRender(animationProps) {
|
|
32
|
-
var _renderLoop2;
|
|
33
|
-
|
|
34
|
-
(_renderLoop2 = renderLoop) === null || _renderLoop2 === void 0 ? void 0 : _renderLoop2.onRender(animationProps);
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
onFinalize(animationProps) {
|
|
38
|
-
var _renderLoop3;
|
|
39
|
-
|
|
40
|
-
(_renderLoop3 = renderLoop) === null || _renderLoop3 === void 0 ? void 0 : _renderLoop3.onFinalize(animationProps);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
animationLoop.getInfo = () => {
|
|
46
|
-
return this.RenderLoopConstructor.info;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return animationLoop;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=render-loop.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/render-loop.ts"],"names":["AnimationLoop","RenderLoop","constructor","animationProps","destroy","animationLoop","onInitialize","run","RenderLoopConstructor","deviceProps","renderLoop","onRender","onFinalize","getInfo","info"],"mappings":";AAEA,SAAQA,aAAR,QAA4B,kBAA5B;AAOA,OAAO,MAAeC,UAAf,CAA0B;AAI/BC,EAAAA,WAAW,CAACC,cAAD,EAAkC;AAAA;AAAE;;AAE/CC,EAAAA,OAAO,GAAS;AAAA;;AACd,gCAAKC,aAAL,4EAAoBD,OAApB;AACD;;AAEiB,QAAZE,YAAY,CAACH,cAAD,EAAmD;AAAE,WAAO,IAAP;AAAc;;AAK3E,SAAHI,GAAG,CAACC,qBAAD,EAA2CC,WAA3C,EAAqF;AAC7F,QAAIC,UAA6B,GAAG,IAApC;AAGA,UAAML,aAAa,GAAG,IAAIL,aAAJ,CAAkB;AACtCS,MAAAA,WADsC;;AAGtC,YAAMH,YAAN,CAAmBH,cAAnB,EAAqE;AAAA;;AAEnEO,QAAAA,UAAU,GAAG,IAAIF,qBAAJ,CAA0BL,cAA1B,CAAb;AACAO,QAAAA,UAAU,CAAEL,aAAZ,GAA4BA,aAA5B;AAEA,eAAO,sBAAMK,UAAN,gDAAM,YAAYJ,YAAZ,CAAyBH,cAAzB,CAAN,CAAP;AACD,OATqC;;AAWtCQ,MAAAA,QAAQ,CAACR,cAAD,EAAiC;AAAA;;AACvC,wBAAAO,UAAU,UAAV,oDAAYC,QAAZ,CAAqBR,cAArB;AACD,OAbqC;;AAetCS,MAAAA,UAAU,CAACT,cAAD,EAAiC;AAAA;;AACzC,wBAAAO,UAAU,UAAV,oDAAYE,UAAZ,CAAuBT,cAAvB;AACD;;AAjBqC,KAAlB,CAAtB;;AAqBAE,IAAAA,aAAa,CAACQ,OAAd,GAAwB,MAAM;AAE5B,aAAO,KAAKL,qBAAL,CAA2BM,IAAlC;AACD,KAHD;;AAQA,WAAOT,aAAP;AACD;;AAjD8B","sourcesContent":["import type {DeviceProps} from '@luma.gl/api';\nimport type {AnimationProps} from '../lib/animation-props';\nimport {AnimationLoop} from './animation-loop';\n\n/**\n * Minimal animation loop that initializes models in constructor\n * Simplifying type management\n * v9 API\n */\nexport abstract class RenderLoop {\n\n animationLoop?: AnimationLoop;\n\n constructor(animationProps?: AnimationProps) {}\n\n destroy(): void {\n this.animationLoop?.destroy();\n }\n\n async onInitialize(animationProps: AnimationProps): Promise<unknown> { return null; }\n abstract onRender(animationProps: AnimationProps): unknown;\n abstract onFinalize(animationProps: AnimationProps): void;\n\n /** Instantiates and runs the render loop */\n static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop {\n let renderLoop: RenderLoop | null = null;\n\n // Create an animation loop;\n const animationLoop = new AnimationLoop({\n deviceProps,\n\n async onInitialize(animationProps: AnimationProps): Promise<unknown> {\n // @ts-expect-error abstract to prevent instantiation\n renderLoop = new RenderLoopConstructor(animationProps);\n renderLoop!.animationLoop = animationLoop;\n // Any async loading can be handled here\n return await renderLoop?.onInitialize(animationProps);\n },\n \n onRender(animationProps: AnimationProps) {\n renderLoop?.onRender(animationProps);\n },\n \n onFinalize(animationProps: AnimationProps) {\n renderLoop?.onFinalize(animationProps);\n }\n });\n\n // @ts-expect-error Hack: adds info for the website to find\n animationLoop.getInfo = () => {\n // @ts-ignore\n return this.RenderLoopConstructor.info;\n }\n\n // Start the loop automatically\n // animationLoop.start();\n\n return animationLoop;\n }\n}\n"],"file":"render-loop.js"}
|