@luma.gl/engine 8.6.0-alpha.5 → 9.0.0-alpha.10
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 +2 -2
- 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 +31 -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 +32 -14
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +57 -34
- 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 +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/animation-loop.d.ts +23 -84
- package/dist/lib/animation-loop.d.ts.map +1 -1
- package/dist/lib/animation-loop.js +106 -193
- 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 +111 -502
- package/dist/lib/model.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +60 -0
- package/dist/lib/pipeline-factory.d.ts.map +1 -0
- package/dist/lib/pipeline-factory.js +219 -0
- package/dist/lib/pipeline-factory.js.map +1 -0
- package/dist/lib/render-loop.d.ts +5 -18
- package/dist/lib/render-loop.d.ts.map +1 -1
- package/dist/lib/render-loop.js +16 -23
- package/dist/lib/render-loop.js.map +1 -1
- package/package.json +6 -6
- package/src/animation/key-frames.ts +1 -0
- package/src/animation/timeline.ts +2 -2
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +160 -8
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +2 -2
- 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 +97 -47
- package/src/geometry/primitive-utils.ts +30 -0
- package/src/index.ts +13 -12
- package/src/lib/animation-loop.ts +136 -314
- 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 +127 -639
- package/src/lib/pipeline-factory.ts +234 -0
- package/src/lib/render-loop.ts +24 -22
- 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,95 +1,51 @@
|
|
|
1
1
|
/// <reference types="offscreencanvas" />
|
|
2
|
-
import { Device } from '@luma.gl/api';
|
|
3
|
-
import type { WebGLDeviceProps } from '@luma.gl/webgl';
|
|
4
|
-
import { Query, Framebuffer } from '@luma.gl/webgl';
|
|
5
|
-
import { Stats, Stat } from '@probe.gl/stats';
|
|
2
|
+
import { Device, DeviceProps } from '@luma.gl/api';
|
|
6
3
|
import { Timeline } from '../animation/timeline';
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { AnimationProps } from '../lib/animation-props';
|
|
5
|
+
import { Stats, Stat } from '@probe.gl/stats';
|
|
9
6
|
/** AnimationLoop properties */
|
|
10
7
|
export declare type AnimationLoopProps = {
|
|
11
|
-
onCreateDevice?: (props: DeviceProps) => Device
|
|
12
|
-
onCreateContext?: (props: ContextProps) => WebGLRenderingContext;
|
|
8
|
+
onCreateDevice?: (props: DeviceProps) => Promise<Device>;
|
|
13
9
|
onAddHTML?: (div: HTMLDivElement) => string;
|
|
14
|
-
onInitialize?: (animationProps: AnimationProps) =>
|
|
10
|
+
onInitialize?: (animationProps: AnimationProps) => void;
|
|
15
11
|
onRender?: (animationProps: AnimationProps) => void;
|
|
16
12
|
onFinalize?: (animationProps: AnimationProps) => void;
|
|
17
|
-
onError?: (reason:
|
|
13
|
+
onError?: (reason: Error) => void;
|
|
14
|
+
device?: Device | null;
|
|
15
|
+
deviceProps?: DeviceProps;
|
|
18
16
|
stats?: Stats;
|
|
19
|
-
device?: Device;
|
|
20
|
-
glOptions?: ContextProps;
|
|
21
17
|
debug?: boolean;
|
|
22
18
|
autoResizeViewport?: boolean;
|
|
23
19
|
autoResizeDrawingBuffer?: boolean;
|
|
24
20
|
useDevicePixels?: number | boolean;
|
|
25
|
-
/** @deprecated Use .device */
|
|
26
|
-
gl?: WebGLRenderingContext;
|
|
27
|
-
/** @deprecated Will be removed */
|
|
28
|
-
createFramebuffer?: boolean;
|
|
29
|
-
};
|
|
30
|
-
export declare type AnimationProps = {
|
|
31
|
-
device: Device;
|
|
32
|
-
stop: () => AnimationLoop;
|
|
33
|
-
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
34
|
-
useDevicePixels: number | boolean;
|
|
35
|
-
needsRedraw?: string;
|
|
36
|
-
startTime: number;
|
|
37
|
-
engineTime: number;
|
|
38
|
-
tick: number;
|
|
39
|
-
tock: number;
|
|
40
|
-
time: number;
|
|
41
|
-
width: number;
|
|
42
|
-
height: number;
|
|
43
|
-
aspect: number;
|
|
44
|
-
timeline: Timeline;
|
|
45
|
-
animationLoop: AnimationLoop;
|
|
46
|
-
_mousePosition?: [number, number];
|
|
47
|
-
/** @deprecated Will be removed, create your own Framebuffer */
|
|
48
|
-
framebuffer: Framebuffer;
|
|
49
|
-
/** @deprecated Use .device */
|
|
50
|
-
gl: WebGLRenderingContext;
|
|
51
|
-
/** @deprecated Use .timeline */
|
|
52
|
-
_timeline: Timeline;
|
|
53
|
-
/** @deprecated Use .animationLoop */
|
|
54
|
-
_loop: AnimationLoop;
|
|
55
|
-
/** @deprecated Use .animationLoop */
|
|
56
|
-
_animationLoop: AnimationLoop;
|
|
57
21
|
};
|
|
58
22
|
/** Convenient animation loop */
|
|
59
|
-
export
|
|
60
|
-
device: Device;
|
|
61
|
-
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
23
|
+
export declare class AnimationLoop {
|
|
24
|
+
device: Device | null;
|
|
25
|
+
canvas: HTMLCanvasElement | OffscreenCanvas | null;
|
|
62
26
|
props: Required<AnimationLoopProps>;
|
|
63
|
-
animationProps: AnimationProps;
|
|
64
|
-
|
|
65
|
-
timeline: Timeline;
|
|
27
|
+
animationProps: AnimationProps | null;
|
|
28
|
+
timeline: Timeline | null;
|
|
66
29
|
stats: Stats;
|
|
67
30
|
cpuTime: Stat;
|
|
68
31
|
gpuTime: Stat;
|
|
69
32
|
frameRate: Stat;
|
|
70
33
|
display: any;
|
|
71
|
-
needsRedraw: string |
|
|
34
|
+
needsRedraw: string | false;
|
|
72
35
|
_initialized: boolean;
|
|
73
36
|
_running: boolean;
|
|
74
37
|
_animationFrameId: any;
|
|
75
|
-
_pageLoadPromise: Promise<{}> | null;
|
|
76
38
|
_nextFramePromise: Promise<AnimationLoop> | null;
|
|
77
39
|
_resolveNextFrame: ((AnimationLoop: any) => void) | null;
|
|
78
40
|
_cpuStartTime: number;
|
|
79
|
-
_gpuTimeQuery: Query | null;
|
|
80
|
-
/** @deprecated */
|
|
81
|
-
gl: WebGLRenderingContext;
|
|
82
41
|
constructor(props?: AnimationLoopProps);
|
|
83
42
|
destroy(): void;
|
|
84
43
|
/** @deprecated Use .destroy() */
|
|
85
44
|
delete(): void;
|
|
86
45
|
setNeedsRedraw(reason: string): this;
|
|
87
46
|
setProps(props: AnimationLoopProps): this;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* @param {Object} context - contains frame specific info (E.g. tick, width, height, etc)
|
|
91
|
-
*/
|
|
92
|
-
_start(opts: any): Promise<this>;
|
|
47
|
+
/** Starts a render loop if not already running */
|
|
48
|
+
start(): Promise<this | null>;
|
|
93
49
|
/** Explicitly draw a frame */
|
|
94
50
|
redraw(): this;
|
|
95
51
|
stop(): this;
|
|
@@ -97,17 +53,7 @@ export default class AnimationLoop {
|
|
|
97
53
|
detachTimeline(): void;
|
|
98
54
|
waitForRender(): Promise<AnimationLoop>;
|
|
99
55
|
toDataURL(): Promise<string>;
|
|
100
|
-
|
|
101
|
-
onCreateDevice(deviceProps: DeviceProps): Device;
|
|
102
|
-
onInitialize(animationProps: AnimationProps): {} | void;
|
|
103
|
-
onRender(animationProps: AnimationProps): void;
|
|
104
|
-
onFinalize(animationProps: AnimationProps): void;
|
|
105
|
-
/** @deprecated Use .onCreateDevice() */
|
|
106
|
-
onCreateContext(props: ContextProps): WebGLRenderingContext;
|
|
107
|
-
/** @deprecated */
|
|
108
|
-
getHTMLControlValue(id: any, defaultValue?: number): number;
|
|
109
|
-
_initialize(props: AnimationLoopProps): void;
|
|
110
|
-
_getPageLoadPromise(): Promise<{}>;
|
|
56
|
+
_initialize(): void;
|
|
111
57
|
_setDisplay(display: any): void;
|
|
112
58
|
_requestAnimationFrame(): void;
|
|
113
59
|
_cancelAnimationFrame(): void;
|
|
@@ -115,13 +61,11 @@ export default class AnimationLoop {
|
|
|
115
61
|
_renderFrame(props: AnimationProps): void;
|
|
116
62
|
_clearNeedsRedraw(): void;
|
|
117
63
|
_setupFrame(): void;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
/** Add application's data to the app context object */
|
|
122
|
-
_addCallbackData(appContext: any): void;
|
|
64
|
+
_initializeAnimationProps(): void;
|
|
65
|
+
_getAnimationProps(): AnimationProps;
|
|
66
|
+
_updateAnimationProps(): void;
|
|
123
67
|
/** Either uses supplied or existing context, or calls provided callback to create one */
|
|
124
|
-
_createDevice(
|
|
68
|
+
_createDevice(): Promise<void>;
|
|
125
69
|
_createInfoDiv(): void;
|
|
126
70
|
_getSizeAndAspect(): {
|
|
127
71
|
width: number;
|
|
@@ -138,12 +82,7 @@ export default class AnimationLoop {
|
|
|
138
82
|
_beginTimers(): void;
|
|
139
83
|
_endTimers(): void;
|
|
140
84
|
_startEventHandling(): void;
|
|
141
|
-
_onMousemove(
|
|
142
|
-
_onMouseleave(
|
|
143
|
-
/** @deprecated */
|
|
144
|
-
_createFramebuffer(): void;
|
|
145
|
-
/** @deprecated */
|
|
146
|
-
_resizeFramebuffer(): void;
|
|
85
|
+
_onMousemove(event: Event): void;
|
|
86
|
+
_onMouseleave(event: Event): void;
|
|
147
87
|
}
|
|
148
|
-
export {};
|
|
149
88
|
//# sourceMappingURL=animation-loop.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animation-loop.d.ts","sourceRoot":"","sources":["../../src/lib/animation-loop.ts"],"names":[],"mappings":";AAAA,OAAO,EAAO,MAAM,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"animation-loop.d.ts","sourceRoot":"","sources":["../../src/lib/animation-loop.ts"],"names":[],"mappings":";AAAA,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,IAAI,CAAC;IACxD,QAAQ,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACpD,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,KAAK,IAAI,CAAC;IAElC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC;IAGd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC,CAAC;AAqBF,gCAAgC;AAChC,qBAAa,aAAa;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC7B,MAAM,EAAE,iBAAiB,GAAG,eAAe,GAAG,IAAI,CAAQ;IAE1D,KAAK,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IACpC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAQ;IAC7C,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAQ;IACjC,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAEhB,OAAO,EAAE,GAAG,CAAC;IAEb,WAAW,EAAE,MAAM,GAAG,KAAK,CAAiB;IAE5C,YAAY,EAAE,OAAO,CAAS;IAC9B,QAAQ,EAAE,OAAO,CAAS;IAC1B,iBAAiB,EAAE,GAAG,CAAQ;IAC9B,iBAAiB,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAQ;IACxD,iBAAiB,EAAE,CAAC,CAAC,aAAa,KAAA,KAAK,IAAI,CAAC,GAAG,IAAI,CAAQ;IAC3D,aAAa,EAAE,MAAM,CAAK;gBAOd,KAAK,GAAE,kBAAuB;IA8B1C,OAAO,IAAI,IAAI;IAKf,iCAAiC;IACjC,MAAM,IAAI,IAAI;IAId,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAMpC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,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,KAAK,EAAE,cAAc;IAYlC,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,40 +1,34 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { luma } from '@luma.gl/api';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { requestAnimationFrame, cancelAnimationFrame, Query, Framebuffer } from '@luma.gl/webgl';
|
|
3
|
+
import { requestAnimationFrame, cancelAnimationFrame } from '@luma.gl/api';
|
|
4
|
+
import { Stats } from '@probe.gl/stats';
|
|
6
5
|
import { isBrowser } from '@probe.gl/env';
|
|
7
6
|
const isPage = isBrowser() && typeof document !== 'undefined';
|
|
8
7
|
let statIdCounter = 0;
|
|
9
8
|
const DEFAULT_ANIMATION_LOOP_PROPS = {
|
|
10
9
|
onCreateDevice: props => luma.createDevice(props),
|
|
11
|
-
|
|
12
|
-
onAddHTML: null,
|
|
10
|
+
onAddHTML: () => '',
|
|
13
11
|
onInitialize: () => ({}),
|
|
14
12
|
onRender: () => {},
|
|
15
13
|
onFinalize: () => {},
|
|
16
14
|
onError: error => console.error(error),
|
|
17
15
|
device: null,
|
|
16
|
+
deviceProps: {},
|
|
18
17
|
debug: false,
|
|
18
|
+
stats: luma.stats.get("animation-loop-".concat(statIdCounter++)),
|
|
19
19
|
useDevicePixels: true,
|
|
20
20
|
autoResizeViewport: true,
|
|
21
|
-
autoResizeDrawingBuffer: true
|
|
22
|
-
stats: lumaStats.get("animation-loop-".concat(statIdCounter++)),
|
|
23
|
-
gl: null,
|
|
24
|
-
glOptions: {},
|
|
25
|
-
createFramebuffer: false
|
|
21
|
+
autoResizeDrawingBuffer: true
|
|
26
22
|
};
|
|
27
|
-
export
|
|
23
|
+
export class AnimationLoop {
|
|
28
24
|
constructor(props = {}) {
|
|
29
|
-
_defineProperty(this, "device",
|
|
25
|
+
_defineProperty(this, "device", null);
|
|
30
26
|
|
|
31
|
-
_defineProperty(this, "canvas",
|
|
27
|
+
_defineProperty(this, "canvas", null);
|
|
32
28
|
|
|
33
29
|
_defineProperty(this, "props", void 0);
|
|
34
30
|
|
|
35
|
-
_defineProperty(this, "animationProps",
|
|
36
|
-
|
|
37
|
-
_defineProperty(this, "framebuffer", null);
|
|
31
|
+
_defineProperty(this, "animationProps", null);
|
|
38
32
|
|
|
39
33
|
_defineProperty(this, "timeline", null);
|
|
40
34
|
|
|
@@ -56,18 +50,12 @@ export default class AnimationLoop {
|
|
|
56
50
|
|
|
57
51
|
_defineProperty(this, "_animationFrameId", null);
|
|
58
52
|
|
|
59
|
-
_defineProperty(this, "_pageLoadPromise", null);
|
|
60
|
-
|
|
61
53
|
_defineProperty(this, "_nextFramePromise", null);
|
|
62
54
|
|
|
63
55
|
_defineProperty(this, "_resolveNextFrame", null);
|
|
64
56
|
|
|
65
57
|
_defineProperty(this, "_cpuStartTime", 0);
|
|
66
58
|
|
|
67
|
-
_defineProperty(this, "_gpuTimeQuery", null);
|
|
68
|
-
|
|
69
|
-
_defineProperty(this, "gl", void 0);
|
|
70
|
-
|
|
71
59
|
this.props = { ...DEFAULT_ANIMATION_LOOP_PROPS,
|
|
72
60
|
...props
|
|
73
61
|
};
|
|
@@ -75,15 +63,11 @@ export default class AnimationLoop {
|
|
|
75
63
|
let {
|
|
76
64
|
useDevicePixels = true
|
|
77
65
|
} = this.props;
|
|
78
|
-
|
|
79
|
-
if ('useDevicePixelRatio' in props) {
|
|
80
|
-
log.deprecated('useDevicePixelRatio', 'useDevicePixels')();
|
|
81
|
-
useDevicePixels = props.useDevicePixelRatio;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this.device = props.device;
|
|
66
|
+
this.device = props.device || null;
|
|
85
67
|
this.gl = this.device && this.device.gl || props.gl;
|
|
86
|
-
this.stats = props.stats
|
|
68
|
+
this.stats = props.stats || new Stats({
|
|
69
|
+
id: 'animation-loop-stats'
|
|
70
|
+
});
|
|
87
71
|
this.cpuTime = this.stats.get('CPU Time');
|
|
88
72
|
this.gpuTime = this.stats.get('GPU Time');
|
|
89
73
|
this.frameRate = this.stats.get('Frame Rate');
|
|
@@ -115,27 +99,21 @@ export default class AnimationLoop {
|
|
|
115
99
|
|
|
116
100
|
setProps(props) {
|
|
117
101
|
if ('autoResizeViewport' in props) {
|
|
118
|
-
this.props.autoResizeViewport = props.autoResizeViewport;
|
|
102
|
+
this.props.autoResizeViewport = props.autoResizeViewport || false;
|
|
119
103
|
}
|
|
120
104
|
|
|
121
105
|
if ('autoResizeDrawingBuffer' in props) {
|
|
122
|
-
this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer;
|
|
106
|
+
this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer || false;
|
|
123
107
|
}
|
|
124
108
|
|
|
125
109
|
if ('useDevicePixels' in props) {
|
|
126
|
-
this.props.useDevicePixels = props.useDevicePixels;
|
|
110
|
+
this.props.useDevicePixels = props.useDevicePixels || false;
|
|
127
111
|
}
|
|
128
112
|
|
|
129
113
|
return this;
|
|
130
114
|
}
|
|
131
115
|
|
|
132
|
-
start(
|
|
133
|
-
this._start(opts);
|
|
134
|
-
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async _start(opts) {
|
|
116
|
+
async start() {
|
|
139
117
|
if (this._running) {
|
|
140
118
|
return this;
|
|
141
119
|
}
|
|
@@ -143,8 +121,6 @@ export default class AnimationLoop {
|
|
|
143
121
|
this._running = true;
|
|
144
122
|
|
|
145
123
|
try {
|
|
146
|
-
await this._getPageLoadPromise();
|
|
147
|
-
|
|
148
124
|
if (!this._running) {
|
|
149
125
|
return null;
|
|
150
126
|
}
|
|
@@ -153,12 +129,11 @@ export default class AnimationLoop {
|
|
|
153
129
|
|
|
154
130
|
if (!this._initialized) {
|
|
155
131
|
this._initialized = true;
|
|
132
|
+
await this._createDevice();
|
|
156
133
|
|
|
157
|
-
this._initialize(
|
|
158
|
-
|
|
159
|
-
appContext = await this.onInitialize(this.animationProps);
|
|
134
|
+
this._initialize();
|
|
160
135
|
|
|
161
|
-
this.
|
|
136
|
+
await this.props.onInitialize(this._getAnimationProps());
|
|
162
137
|
}
|
|
163
138
|
|
|
164
139
|
if (!this._running) {
|
|
@@ -172,14 +147,17 @@ export default class AnimationLoop {
|
|
|
172
147
|
}
|
|
173
148
|
|
|
174
149
|
return this;
|
|
175
|
-
} catch (
|
|
150
|
+
} catch (err) {
|
|
151
|
+
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
176
152
|
this.props.onError(error);
|
|
177
|
-
|
|
153
|
+
throw error;
|
|
178
154
|
}
|
|
179
155
|
}
|
|
180
156
|
|
|
181
157
|
redraw() {
|
|
182
|
-
|
|
158
|
+
var _this$device;
|
|
159
|
+
|
|
160
|
+
if ((_this$device = this.device) !== null && _this$device !== void 0 && _this$device.isLost) {
|
|
183
161
|
return this;
|
|
184
162
|
}
|
|
185
163
|
|
|
@@ -187,9 +165,9 @@ export default class AnimationLoop {
|
|
|
187
165
|
|
|
188
166
|
this._setupFrame();
|
|
189
167
|
|
|
190
|
-
this.
|
|
168
|
+
this._updateAnimationProps();
|
|
191
169
|
|
|
192
|
-
this._renderFrame(this.
|
|
170
|
+
this._renderFrame(this._getAnimationProps());
|
|
193
171
|
|
|
194
172
|
this._clearNeedsRedraw();
|
|
195
173
|
|
|
@@ -207,7 +185,9 @@ export default class AnimationLoop {
|
|
|
207
185
|
|
|
208
186
|
stop() {
|
|
209
187
|
if (this._running) {
|
|
210
|
-
this.
|
|
188
|
+
if (this.animationProps) {
|
|
189
|
+
this.props.onFinalize(this.animationProps);
|
|
190
|
+
}
|
|
211
191
|
|
|
212
192
|
this._cancelAnimationFrame();
|
|
213
193
|
|
|
@@ -243,71 +223,24 @@ export default class AnimationLoop {
|
|
|
243
223
|
async toDataURL() {
|
|
244
224
|
this.setNeedsRedraw('toDataURL');
|
|
245
225
|
await this.waitForRender();
|
|
246
|
-
return this.gl.canvas.toDataURL();
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
isContextLost() {
|
|
250
|
-
return this.gl.isContextLost();
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
onCreateDevice(deviceProps) {
|
|
254
|
-
return this.props.onCreateDevice(deviceProps);
|
|
255
|
-
}
|
|
256
226
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
onRender(animationProps) {
|
|
262
|
-
return this.props.onRender(animationProps);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
onFinalize(animationProps) {
|
|
266
|
-
return this.props.onFinalize(animationProps);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
onCreateContext(props) {
|
|
270
|
-
return this.props.onCreateContext(props);
|
|
271
|
-
}
|
|
227
|
+
if (this.canvas instanceof HTMLCanvasElement) {
|
|
228
|
+
return this.canvas.toDataURL();
|
|
229
|
+
}
|
|
272
230
|
|
|
273
|
-
|
|
274
|
-
const element = document.getElementById(id);
|
|
275
|
-
return element ? Number(element.value) : defaultValue;
|
|
231
|
+
throw new Error('OffscreenCanvas');
|
|
276
232
|
}
|
|
277
233
|
|
|
278
|
-
_initialize(
|
|
279
|
-
this._createDevice(props);
|
|
280
|
-
|
|
281
|
-
this._createFramebuffer();
|
|
282
|
-
|
|
234
|
+
_initialize() {
|
|
283
235
|
this._startEventHandling();
|
|
284
236
|
|
|
285
|
-
this.
|
|
237
|
+
this._initializeAnimationProps();
|
|
286
238
|
|
|
287
|
-
this.
|
|
239
|
+
this._updateAnimationProps();
|
|
288
240
|
|
|
289
241
|
this._resizeCanvasDrawingBuffer();
|
|
290
242
|
|
|
291
243
|
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
244
|
}
|
|
312
245
|
|
|
313
246
|
_setDisplay(display) {
|
|
@@ -357,45 +290,58 @@ export default class AnimationLoop {
|
|
|
357
290
|
return;
|
|
358
291
|
}
|
|
359
292
|
|
|
360
|
-
this.onRender(props);
|
|
293
|
+
this.props.onRender(props);
|
|
361
294
|
}
|
|
362
295
|
|
|
363
296
|
_clearNeedsRedraw() {
|
|
364
|
-
this.needsRedraw =
|
|
297
|
+
this.needsRedraw = false;
|
|
365
298
|
}
|
|
366
299
|
|
|
367
300
|
_setupFrame() {
|
|
368
301
|
this._resizeCanvasDrawingBuffer();
|
|
369
302
|
|
|
370
303
|
this._resizeViewport();
|
|
371
|
-
|
|
372
|
-
this._resizeFramebuffer();
|
|
373
304
|
}
|
|
374
305
|
|
|
375
|
-
|
|
306
|
+
_initializeAnimationProps() {
|
|
307
|
+
var _this$device2, _this$device2$canvasC;
|
|
308
|
+
|
|
309
|
+
if (!this.device) {
|
|
310
|
+
throw new Error('loop');
|
|
311
|
+
}
|
|
312
|
+
|
|
376
313
|
this.animationProps = {
|
|
314
|
+
animationLoop: this,
|
|
377
315
|
device: this.device,
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
canvas: this.gl.canvas,
|
|
316
|
+
canvas: (_this$device2 = this.device) === null || _this$device2 === void 0 ? void 0 : (_this$device2$canvasC = _this$device2.canvasContext) === null || _this$device2$canvasC === void 0 ? void 0 : _this$device2$canvasC.canvas,
|
|
317
|
+
timeline: this.timeline,
|
|
381
318
|
useDevicePixels: this.props.useDevicePixels,
|
|
382
|
-
needsRedraw:
|
|
319
|
+
needsRedraw: false,
|
|
320
|
+
width: 1,
|
|
321
|
+
height: 1,
|
|
322
|
+
aspect: 1,
|
|
323
|
+
time: 0,
|
|
383
324
|
startTime: Date.now(),
|
|
384
325
|
engineTime: 0,
|
|
385
326
|
tick: 0,
|
|
386
327
|
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
|
|
328
|
+
_mousePosition: null
|
|
395
329
|
};
|
|
396
330
|
}
|
|
397
331
|
|
|
398
|
-
|
|
332
|
+
_getAnimationProps() {
|
|
333
|
+
if (!this.animationProps) {
|
|
334
|
+
throw new Error('animationProps');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return this.animationProps;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
_updateAnimationProps() {
|
|
341
|
+
if (!this.animationProps) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
399
345
|
const {
|
|
400
346
|
width,
|
|
401
347
|
height,
|
|
@@ -425,35 +371,20 @@ export default class AnimationLoop {
|
|
|
425
371
|
this.animationProps.time = this.timeline ? this.timeline.getTime() : this.animationProps.engineTime;
|
|
426
372
|
}
|
|
427
373
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
_addCallbackData(appContext) {
|
|
433
|
-
if (typeof appContext === 'object' && appContext !== null) {
|
|
434
|
-
this.animationProps = Object.assign({}, this.animationProps, appContext);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
374
|
+
async _createDevice() {
|
|
375
|
+
var _this$device$canvasCo;
|
|
437
376
|
|
|
438
|
-
_createDevice(props) {
|
|
439
377
|
const deviceProps = { ...this.props,
|
|
440
|
-
...props
|
|
441
|
-
...this.props.glOptions
|
|
378
|
+
...this.props.deviceProps
|
|
442
379
|
};
|
|
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);
|
|
380
|
+
this.device = await this.props.onCreateDevice(deviceProps);
|
|
381
|
+
this.canvas = (_this$device$canvasCo = this.device.canvasContext) === null || _this$device$canvasCo === void 0 ? void 0 : _this$device$canvasCo.canvas;
|
|
451
382
|
|
|
452
383
|
this._createInfoDiv();
|
|
453
384
|
}
|
|
454
385
|
|
|
455
386
|
_createInfoDiv() {
|
|
456
|
-
if (this.
|
|
387
|
+
if (this.canvas && this.props.onAddHTML) {
|
|
457
388
|
const wrapperDiv = document.createElement('div');
|
|
458
389
|
document.body.appendChild(wrapperDiv);
|
|
459
390
|
wrapperDiv.style.position = 'relative';
|
|
@@ -463,7 +394,11 @@ export default class AnimationLoop {
|
|
|
463
394
|
div.style.bottom = '10px';
|
|
464
395
|
div.style.width = '300px';
|
|
465
396
|
div.style.background = 'white';
|
|
466
|
-
|
|
397
|
+
|
|
398
|
+
if (this.canvas instanceof HTMLCanvasElement) {
|
|
399
|
+
wrapperDiv.appendChild(this.canvas);
|
|
400
|
+
}
|
|
401
|
+
|
|
467
402
|
wrapperDiv.appendChild(div);
|
|
468
403
|
const html = this.props.onAddHTML(div);
|
|
469
404
|
|
|
@@ -474,12 +409,19 @@ export default class AnimationLoop {
|
|
|
474
409
|
}
|
|
475
410
|
|
|
476
411
|
_getSizeAndAspect() {
|
|
477
|
-
|
|
478
|
-
|
|
412
|
+
var _this$device3, _this$device3$canvasC, _this$device4, _this$device4$canvasC;
|
|
413
|
+
|
|
414
|
+
if (!this.device) {
|
|
415
|
+
return {
|
|
416
|
+
width: 1,
|
|
417
|
+
height: 1,
|
|
418
|
+
aspect: 1
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const [width, height] = ((_this$device3 = this.device) === null || _this$device3 === void 0 ? void 0 : (_this$device3$canvasC = _this$device3.canvasContext) === null || _this$device3$canvasC === void 0 ? void 0 : _this$device3$canvasC.getPixelSize()) || [1, 1];
|
|
479
423
|
let aspect = 1;
|
|
480
|
-
const
|
|
481
|
-
canvas
|
|
482
|
-
} = this.gl;
|
|
424
|
+
const canvas = (_this$device4 = this.device) === null || _this$device4 === void 0 ? void 0 : (_this$device4$canvasC = _this$device4.canvasContext) === null || _this$device4$canvasC === void 0 ? void 0 : _this$device4$canvasC.canvas;
|
|
483
425
|
|
|
484
426
|
if (canvas && canvas.clientHeight) {
|
|
485
427
|
aspect = canvas.clientWidth / canvas.clientHeight;
|
|
@@ -495,14 +437,16 @@ export default class AnimationLoop {
|
|
|
495
437
|
}
|
|
496
438
|
|
|
497
439
|
_resizeViewport() {
|
|
498
|
-
if (this.props.autoResizeViewport) {
|
|
499
|
-
this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight);
|
|
440
|
+
if (this.props.autoResizeViewport && this.device.gl) {
|
|
441
|
+
this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);
|
|
500
442
|
}
|
|
501
443
|
}
|
|
502
444
|
|
|
503
445
|
_resizeCanvasDrawingBuffer() {
|
|
504
446
|
if (this.props.autoResizeDrawingBuffer) {
|
|
505
|
-
|
|
447
|
+
var _this$device5, _this$device5$canvasC;
|
|
448
|
+
|
|
449
|
+
(_this$device5 = this.device) === null || _this$device5 === void 0 ? void 0 : (_this$device5$canvasC = _this$device5.canvasContext) === null || _this$device5$canvasC === void 0 ? void 0 : _this$device5$canvasC.resize({
|
|
506
450
|
useDevicePixels: this.props.useDevicePixels
|
|
507
451
|
});
|
|
508
452
|
}
|
|
@@ -511,58 +455,27 @@ export default class AnimationLoop {
|
|
|
511
455
|
_beginTimers() {
|
|
512
456
|
this.frameRate.timeEnd();
|
|
513
457
|
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
458
|
}
|
|
525
459
|
|
|
526
460
|
_endTimers() {
|
|
527
461
|
this.cpuTime.timeEnd();
|
|
528
|
-
|
|
529
|
-
if (this._gpuTimeQuery) {
|
|
530
|
-
this._gpuTimeQuery.end();
|
|
531
|
-
}
|
|
532
462
|
}
|
|
533
463
|
|
|
534
464
|
_startEventHandling() {
|
|
535
|
-
|
|
536
|
-
canvas
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (canvas) {
|
|
540
|
-
canvas.addEventListener('mousemove', this._onMousemove);
|
|
541
|
-
canvas.addEventListener('mouseleave', this._onMouseleave);
|
|
465
|
+
if (this.canvas) {
|
|
466
|
+
this.canvas.addEventListener('mousemove', this._onMousemove);
|
|
467
|
+
this.canvas.addEventListener('mouseleave', this._onMouseleave);
|
|
542
468
|
}
|
|
543
469
|
}
|
|
544
470
|
|
|
545
|
-
_onMousemove(
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
_onMouseleave(e) {
|
|
550
|
-
this.animationProps._mousePosition = null;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
_createFramebuffer() {
|
|
554
|
-
if (this.props.createFramebuffer) {
|
|
555
|
-
this.framebuffer = new Framebuffer(this.gl);
|
|
471
|
+
_onMousemove(event) {
|
|
472
|
+
if (event instanceof MouseEvent) {
|
|
473
|
+
this._getAnimationProps()._mousePosition = [event.offsetX, event.offsetY];
|
|
556
474
|
}
|
|
557
475
|
}
|
|
558
476
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
this.framebuffer.resize({
|
|
562
|
-
width: this.gl.drawingBufferWidth,
|
|
563
|
-
height: this.gl.drawingBufferHeight
|
|
564
|
-
});
|
|
565
|
-
}
|
|
477
|
+
_onMouseleave(event) {
|
|
478
|
+
this._getAnimationProps()._mousePosition = null;
|
|
566
479
|
}
|
|
567
480
|
|
|
568
481
|
}
|