@luma.gl/engine 9.0.0-alpha.9 → 9.0.0-beta.2
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/LICENSE +3 -1
- package/dist/animation/key-frames.d.ts +1 -1
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js +6 -27
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +8 -8
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +18 -49
- package/dist/animation/timeline.js.map +1 -1
- package/dist/animation-loop/animation-loop-template.d.ts +23 -0
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +7 -0
- package/dist/animation-loop/animation-loop-template.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -22
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +77 -192
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +2 -3
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/animation-loop/animation-props.js.map +1 -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 +28 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/debug/copy-texture-to-image.d.ts +26 -0
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
- package/dist/debug/copy-texture-to-image.js +46 -0
- package/dist/debug/copy-texture-to-image.js.map +1 -0
- package/dist/debug/debug-framebuffer.d.ts +11 -0
- package/dist/debug/debug-framebuffer.d.ts.map +1 -0
- package/dist/debug/debug-framebuffer.js +43 -0
- package/dist/debug/debug-framebuffer.js.map +1 -0
- package/dist/debug/debug-shader-layout.d.ts +9 -0
- package/dist/debug/debug-shader-layout.d.ts.map +1 -0
- package/dist/debug/debug-shader-layout.js +28 -0
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/debug/pixel-data-utils.d.ts +24 -0
- package/dist/debug/pixel-data-utils.d.ts.map +1 -0
- package/dist/debug/pixel-data-utils.js +41 -0
- package/dist/debug/pixel-data-utils.js.map +1 -0
- package/dist/dist.dev.js +10073 -0
- package/dist/geometries/cone-geometry.d.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +6 -5
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.d.ts +2 -2
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +16 -10
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +6 -5
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +10 -19
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts +2 -2
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +14 -23
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts +2 -2
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +9 -13
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +9 -25
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.d.ts +2 -2
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +0 -9
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +43 -43
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +20 -86
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +37 -0
- package/dist/geometry/gpu-geometry.d.ts.map +1 -0
- package/dist/geometry/gpu-geometry.js +110 -0
- package/dist/geometry/gpu-geometry.js.map +1 -0
- package/dist/geometry/gpu-table.d.ts +1 -0
- package/dist/geometry/gpu-table.d.ts.map +1 -0
- package/dist/geometry/gpu-table.js +2 -0
- package/dist/geometry/gpu-table.js.map +1 -0
- package/dist/index.cjs +3120 -0
- package/dist/index.d.ts +24 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/clip-space.d.ts +8 -0
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +47 -0
- package/dist/lib/clip-space.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +12 -46
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +36 -179
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/model/model.d.ts +206 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +440 -0
- package/dist/model/model.js.map +1 -0
- package/dist/scenegraph/group-node.d.ts +21 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -0
- package/dist/scenegraph/group-node.js +94 -0
- package/dist/scenegraph/group-node.js.map +1 -0
- package/dist/scenegraph/model-node.d.ts +18 -0
- package/dist/scenegraph/model-node.d.ts.map +1 -0
- package/dist/scenegraph/model-node.js +28 -0
- package/dist/scenegraph/model-node.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.d.ts +56 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +141 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/shader-inputs.d.ts +63 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +66 -0
- package/dist/shader-inputs.js.map +1 -0
- package/dist/transform/buffer-transform.d.ts +35 -0
- package/dist/transform/buffer-transform.d.ts.map +1 -0
- package/dist/transform/buffer-transform.js +62 -0
- package/dist/transform/buffer-transform.js.map +1 -0
- package/dist/transform/texture-transform.d.ts +57 -0
- package/dist/transform/texture-transform.d.ts.map +1 -0
- package/dist/transform/texture-transform.js +122 -0
- package/dist/transform/texture-transform.js.map +1 -0
- package/dist.min.js +293 -0
- package/package.json +21 -12
- package/src/animation/timeline.ts +15 -14
- package/src/animation-loop/animation-loop-template.ts +23 -0
- package/src/{lib → animation-loop}/animation-loop.ts +99 -88
- package/src/{lib → animation-loop}/animation-props.ts +1 -1
- package/src/animation-loop/make-animation-loop.ts +44 -0
- package/src/debug/copy-texture-to-image.ts +72 -0
- package/src/debug/debug-framebuffer.ts +57 -0
- package/src/debug/debug-shader-layout.ts +38 -0
- package/src/debug/pixel-data-utils.ts +57 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +47 -45
- package/src/geometries/cylinder-geometry.ts +2 -2
- package/src/geometries/ico-sphere-geometry.ts +6 -5
- package/src/geometries/plane-geometry.ts +5 -4
- package/src/geometries/sphere-geometry.ts +4 -3
- package/src/geometries/truncated-cone-geometry.ts +4 -13
- package/src/geometry/geometry-table.ts +1 -1
- package/src/geometry/geometry-utils.ts +19 -3
- package/src/geometry/geometry.ts +65 -110
- package/src/geometry/gpu-geometry.ts +125 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +34 -10
- package/src/lib/clip-space.ts +22 -21
- package/src/lib/pipeline-factory.ts +48 -179
- package/src/model/model.ts +733 -0
- package/src/scenegraph/group-node.ts +103 -0
- package/src/scenegraph/model-node.ts +50 -0
- package/src/scenegraph/scenegraph-node.ts +204 -0
- package/src/shader-inputs.ts +150 -0
- package/src/transform/buffer-transform.ts +94 -0
- package/src/transform/texture-transform.ts +169 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/dist/geometry/primitive-utils.d.ts +0 -1
- package/dist/geometry/primitive-utils.d.ts.map +0 -1
- package/dist/geometry/primitive-utils.js +0 -2
- package/dist/geometry/primitive-utils.js.map +0 -1
- 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/animation-props.js.map +0 -1
- package/dist/lib/model-utils.d.ts +0 -5
- package/dist/lib/model-utils.d.ts.map +0 -1
- package/dist/lib/model-utils.js +0 -45
- package/dist/lib/model-utils.js.map +0 -1
- package/dist/lib/model.d.ts +0 -41
- package/dist/lib/model.d.ts.map +0 -1
- package/dist/lib/model.js +0 -182
- package/dist/lib/model.js.map +0 -1
- package/dist/lib/render-loop.d.ts +0 -14
- package/dist/lib/render-loop.d.ts.map +0 -1
- package/dist/lib/render-loop.js +0 -49
- package/dist/lib/render-loop.js.map +0 -1
- package/src/bundle.ts +0 -4
- package/src/geometry/primitive-utils.ts +0 -30
- package/src/lib/model-utils.ts +0 -124
- package/src/lib/model.ts +0 -183
- package/src/lib/render-loop.ts +0 -58
- /package/dist/{lib → animation-loop}/animation-props.js +0 -0
|
@@ -1,70 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { requestAnimationFrame, cancelAnimationFrame } from '@luma.gl/api';
|
|
1
|
+
import { luma } from '@luma.gl/core';
|
|
2
|
+
import { requestAnimationFrame, cancelAnimationFrame } from '@luma.gl/core';
|
|
4
3
|
import { Stats } from '@probe.gl/stats';
|
|
5
|
-
import { isBrowser } from '@probe.gl/env';
|
|
6
|
-
const isPage = isBrowser() && typeof document !== 'undefined';
|
|
7
4
|
let statIdCounter = 0;
|
|
8
5
|
const DEFAULT_ANIMATION_LOOP_PROPS = {
|
|
9
|
-
|
|
6
|
+
device: null,
|
|
10
7
|
onAddHTML: () => '',
|
|
11
|
-
onInitialize: () =>
|
|
8
|
+
onInitialize: async () => {
|
|
9
|
+
return null;
|
|
10
|
+
},
|
|
12
11
|
onRender: () => {},
|
|
13
12
|
onFinalize: () => {},
|
|
14
13
|
onError: error => console.error(error),
|
|
15
|
-
|
|
16
|
-
deviceProps: {},
|
|
17
|
-
debug: false,
|
|
18
|
-
stats: luma.stats.get("animation-loop-".concat(statIdCounter++)),
|
|
14
|
+
stats: luma.stats.get(`animation-loop-${statIdCounter++}`),
|
|
19
15
|
useDevicePixels: true,
|
|
20
|
-
autoResizeViewport:
|
|
21
|
-
autoResizeDrawingBuffer:
|
|
16
|
+
autoResizeViewport: false,
|
|
17
|
+
autoResizeDrawingBuffer: false
|
|
22
18
|
};
|
|
23
19
|
export class AnimationLoop {
|
|
24
|
-
constructor(props
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_defineProperty(this, "needsRedraw", 'initialized');
|
|
46
|
-
|
|
47
|
-
_defineProperty(this, "_initialized", false);
|
|
48
|
-
|
|
49
|
-
_defineProperty(this, "_running", false);
|
|
50
|
-
|
|
51
|
-
_defineProperty(this, "_animationFrameId", null);
|
|
52
|
-
|
|
53
|
-
_defineProperty(this, "_nextFramePromise", null);
|
|
54
|
-
|
|
55
|
-
_defineProperty(this, "_resolveNextFrame", null);
|
|
56
|
-
|
|
57
|
-
_defineProperty(this, "_cpuStartTime", 0);
|
|
58
|
-
|
|
59
|
-
this.props = { ...DEFAULT_ANIMATION_LOOP_PROPS,
|
|
20
|
+
constructor(props) {
|
|
21
|
+
this.device = null;
|
|
22
|
+
this.canvas = null;
|
|
23
|
+
this.props = void 0;
|
|
24
|
+
this.animationProps = null;
|
|
25
|
+
this.timeline = null;
|
|
26
|
+
this.stats = void 0;
|
|
27
|
+
this.cpuTime = void 0;
|
|
28
|
+
this.gpuTime = void 0;
|
|
29
|
+
this.frameRate = void 0;
|
|
30
|
+
this.display = void 0;
|
|
31
|
+
this.needsRedraw = 'initialized';
|
|
32
|
+
this._initialized = false;
|
|
33
|
+
this._running = false;
|
|
34
|
+
this._animationFrameId = null;
|
|
35
|
+
this._nextFramePromise = null;
|
|
36
|
+
this._resolveNextFrame = null;
|
|
37
|
+
this._cpuStartTime = 0;
|
|
38
|
+
this.props = {
|
|
39
|
+
...DEFAULT_ANIMATION_LOOP_PROPS,
|
|
60
40
|
...props
|
|
61
41
|
};
|
|
62
42
|
props = this.props;
|
|
63
|
-
|
|
43
|
+
if (!props.device) {
|
|
44
|
+
throw new Error('No device provided');
|
|
45
|
+
}
|
|
46
|
+
const {
|
|
64
47
|
useDevicePixels = true
|
|
65
48
|
} = this.props;
|
|
66
|
-
this.device = props.device || null;
|
|
67
|
-
this.gl = this.device && this.device.gl || props.gl;
|
|
68
49
|
this.stats = props.stats || new Stats({
|
|
69
50
|
id: 'animation-loop-stats'
|
|
70
51
|
});
|
|
@@ -81,71 +62,49 @@ export class AnimationLoop {
|
|
|
81
62
|
this._onMousemove = this._onMousemove.bind(this);
|
|
82
63
|
this._onMouseleave = this._onMouseleave.bind(this);
|
|
83
64
|
}
|
|
84
|
-
|
|
85
65
|
destroy() {
|
|
86
66
|
this.stop();
|
|
87
|
-
|
|
88
67
|
this._setDisplay(null);
|
|
89
68
|
}
|
|
90
|
-
|
|
91
69
|
delete() {
|
|
92
70
|
this.destroy();
|
|
93
71
|
}
|
|
94
|
-
|
|
95
72
|
setNeedsRedraw(reason) {
|
|
96
73
|
this.needsRedraw = this.needsRedraw || reason;
|
|
97
74
|
return this;
|
|
98
75
|
}
|
|
99
|
-
|
|
100
76
|
setProps(props) {
|
|
101
77
|
if ('autoResizeViewport' in props) {
|
|
102
78
|
this.props.autoResizeViewport = props.autoResizeViewport || false;
|
|
103
79
|
}
|
|
104
|
-
|
|
105
80
|
if ('autoResizeDrawingBuffer' in props) {
|
|
106
81
|
this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer || false;
|
|
107
82
|
}
|
|
108
|
-
|
|
109
83
|
if ('useDevicePixels' in props) {
|
|
110
84
|
this.props.useDevicePixels = props.useDevicePixels || false;
|
|
111
85
|
}
|
|
112
|
-
|
|
113
86
|
return this;
|
|
114
87
|
}
|
|
115
|
-
|
|
116
88
|
async start() {
|
|
117
89
|
if (this._running) {
|
|
118
90
|
return this;
|
|
119
91
|
}
|
|
120
|
-
|
|
121
92
|
this._running = true;
|
|
122
|
-
|
|
123
93
|
try {
|
|
124
|
-
if (!this._running) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
94
|
let appContext;
|
|
129
|
-
|
|
130
95
|
if (!this._initialized) {
|
|
131
96
|
this._initialized = true;
|
|
132
|
-
await this.
|
|
133
|
-
|
|
97
|
+
await this._initDevice();
|
|
134
98
|
this._initialize();
|
|
135
|
-
|
|
136
99
|
await this.props.onInitialize(this._getAnimationProps());
|
|
137
100
|
}
|
|
138
|
-
|
|
139
101
|
if (!this._running) {
|
|
140
102
|
return null;
|
|
141
103
|
}
|
|
142
|
-
|
|
143
104
|
if (appContext !== false) {
|
|
144
105
|
this._cancelAnimationFrame();
|
|
145
|
-
|
|
146
106
|
this._requestAnimationFrame();
|
|
147
107
|
}
|
|
148
|
-
|
|
149
108
|
return this;
|
|
150
109
|
} catch (err) {
|
|
151
110
|
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
@@ -153,167 +112,121 @@ export class AnimationLoop {
|
|
|
153
112
|
throw error;
|
|
154
113
|
}
|
|
155
114
|
}
|
|
156
|
-
|
|
115
|
+
stop() {
|
|
116
|
+
if (this._running) {
|
|
117
|
+
if (this.animationProps) {
|
|
118
|
+
this.props.onFinalize(this.animationProps);
|
|
119
|
+
}
|
|
120
|
+
this._cancelAnimationFrame();
|
|
121
|
+
this._nextFramePromise = null;
|
|
122
|
+
this._resolveNextFrame = null;
|
|
123
|
+
this._running = false;
|
|
124
|
+
}
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
157
127
|
redraw() {
|
|
158
128
|
var _this$device;
|
|
159
|
-
|
|
160
129
|
if ((_this$device = this.device) !== null && _this$device !== void 0 && _this$device.isLost) {
|
|
161
130
|
return this;
|
|
162
131
|
}
|
|
163
|
-
|
|
164
|
-
this._beginTimers();
|
|
165
|
-
|
|
132
|
+
this._beginFrameTimers();
|
|
166
133
|
this._setupFrame();
|
|
167
|
-
|
|
168
134
|
this._updateAnimationProps();
|
|
169
|
-
|
|
170
135
|
this._renderFrame(this._getAnimationProps());
|
|
171
|
-
|
|
172
136
|
this._clearNeedsRedraw();
|
|
173
|
-
|
|
174
137
|
if (this._resolveNextFrame) {
|
|
175
138
|
this._resolveNextFrame(this);
|
|
176
|
-
|
|
177
|
-
this._nextFramePromise = null;
|
|
178
|
-
this._resolveNextFrame = null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
this._endTimers();
|
|
182
|
-
|
|
183
|
-
return this;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
stop() {
|
|
187
|
-
if (this._running) {
|
|
188
|
-
if (this.animationProps) {
|
|
189
|
-
this.props.onFinalize(this.animationProps);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
this._cancelAnimationFrame();
|
|
193
|
-
|
|
194
139
|
this._nextFramePromise = null;
|
|
195
140
|
this._resolveNextFrame = null;
|
|
196
|
-
this._running = false;
|
|
197
141
|
}
|
|
198
|
-
|
|
142
|
+
this._endFrameTimers();
|
|
199
143
|
return this;
|
|
200
144
|
}
|
|
201
|
-
|
|
202
145
|
attachTimeline(timeline) {
|
|
203
146
|
this.timeline = timeline;
|
|
204
147
|
return this.timeline;
|
|
205
148
|
}
|
|
206
|
-
|
|
207
149
|
detachTimeline() {
|
|
208
150
|
this.timeline = null;
|
|
209
151
|
}
|
|
210
|
-
|
|
211
152
|
waitForRender() {
|
|
212
153
|
this.setNeedsRedraw('waitForRender');
|
|
213
|
-
|
|
214
154
|
if (!this._nextFramePromise) {
|
|
215
155
|
this._nextFramePromise = new Promise(resolve => {
|
|
216
156
|
this._resolveNextFrame = resolve;
|
|
217
157
|
});
|
|
218
158
|
}
|
|
219
|
-
|
|
220
159
|
return this._nextFramePromise;
|
|
221
160
|
}
|
|
222
|
-
|
|
223
161
|
async toDataURL() {
|
|
224
162
|
this.setNeedsRedraw('toDataURL');
|
|
225
163
|
await this.waitForRender();
|
|
226
|
-
|
|
227
164
|
if (this.canvas instanceof HTMLCanvasElement) {
|
|
228
165
|
return this.canvas.toDataURL();
|
|
229
166
|
}
|
|
230
|
-
|
|
231
167
|
throw new Error('OffscreenCanvas');
|
|
232
168
|
}
|
|
233
|
-
|
|
234
169
|
_initialize() {
|
|
235
170
|
this._startEventHandling();
|
|
236
|
-
|
|
237
171
|
this._initializeAnimationProps();
|
|
238
|
-
|
|
239
172
|
this._updateAnimationProps();
|
|
240
|
-
|
|
241
173
|
this._resizeCanvasDrawingBuffer();
|
|
242
|
-
|
|
243
174
|
this._resizeViewport();
|
|
244
175
|
}
|
|
245
|
-
|
|
246
176
|
_setDisplay(display) {
|
|
247
177
|
if (this.display) {
|
|
248
|
-
this.display.
|
|
178
|
+
this.display.destroy();
|
|
249
179
|
this.display.animationLoop = null;
|
|
250
180
|
}
|
|
251
|
-
|
|
252
181
|
if (display) {
|
|
253
182
|
display.animationLoop = this;
|
|
254
183
|
}
|
|
255
|
-
|
|
256
184
|
this.display = display;
|
|
257
185
|
}
|
|
258
|
-
|
|
259
186
|
_requestAnimationFrame() {
|
|
260
187
|
if (!this._running) {
|
|
261
188
|
return;
|
|
262
189
|
}
|
|
263
|
-
|
|
264
190
|
this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));
|
|
265
191
|
}
|
|
266
|
-
|
|
267
192
|
_cancelAnimationFrame() {
|
|
268
|
-
if (this._animationFrameId
|
|
193
|
+
if (this._animationFrameId === null) {
|
|
269
194
|
return;
|
|
270
195
|
}
|
|
271
|
-
|
|
272
196
|
cancelAnimationFrame(this._animationFrameId);
|
|
273
197
|
this._animationFrameId = null;
|
|
274
198
|
}
|
|
275
|
-
|
|
276
199
|
_animationFrame() {
|
|
277
200
|
if (!this._running) {
|
|
278
201
|
return;
|
|
279
202
|
}
|
|
280
|
-
|
|
281
203
|
this.redraw();
|
|
282
|
-
|
|
283
204
|
this._requestAnimationFrame();
|
|
284
205
|
}
|
|
285
|
-
|
|
286
|
-
_renderFrame(props) {
|
|
206
|
+
_renderFrame(animationProps) {
|
|
287
207
|
if (this.display) {
|
|
288
|
-
this.display._renderFrame(
|
|
289
|
-
|
|
208
|
+
this.display._renderFrame(animationProps);
|
|
290
209
|
return;
|
|
291
210
|
}
|
|
292
|
-
|
|
293
|
-
this.
|
|
211
|
+
this.props.onRender(this._getAnimationProps());
|
|
212
|
+
this.device.submit();
|
|
294
213
|
}
|
|
295
|
-
|
|
296
214
|
_clearNeedsRedraw() {
|
|
297
215
|
this.needsRedraw = false;
|
|
298
216
|
}
|
|
299
|
-
|
|
300
217
|
_setupFrame() {
|
|
301
218
|
this._resizeCanvasDrawingBuffer();
|
|
302
|
-
|
|
303
219
|
this._resizeViewport();
|
|
304
220
|
}
|
|
305
|
-
|
|
306
221
|
_initializeAnimationProps() {
|
|
307
|
-
var _this$device2
|
|
308
|
-
|
|
222
|
+
var _this$device2;
|
|
309
223
|
if (!this.device) {
|
|
310
224
|
throw new Error('loop');
|
|
311
225
|
}
|
|
312
|
-
|
|
313
226
|
this.animationProps = {
|
|
314
227
|
animationLoop: this,
|
|
315
228
|
device: this.device,
|
|
316
|
-
canvas: (_this$device2 = this.device) === null || _this$device2 === void 0
|
|
229
|
+
canvas: (_this$device2 = this.device) === null || _this$device2 === void 0 || (_this$device2 = _this$device2.canvasContext) === null || _this$device2 === void 0 ? void 0 : _this$device2.canvas,
|
|
317
230
|
timeline: this.timeline,
|
|
318
231
|
useDevicePixels: this.props.useDevicePixels,
|
|
319
232
|
needsRedraw: false,
|
|
@@ -328,61 +241,47 @@ export class AnimationLoop {
|
|
|
328
241
|
_mousePosition: null
|
|
329
242
|
};
|
|
330
243
|
}
|
|
331
|
-
|
|
332
244
|
_getAnimationProps() {
|
|
333
245
|
if (!this.animationProps) {
|
|
334
246
|
throw new Error('animationProps');
|
|
335
247
|
}
|
|
336
|
-
|
|
337
248
|
return this.animationProps;
|
|
338
249
|
}
|
|
339
|
-
|
|
340
250
|
_updateAnimationProps() {
|
|
341
251
|
if (!this.animationProps) {
|
|
342
252
|
return;
|
|
343
253
|
}
|
|
344
|
-
|
|
345
254
|
const {
|
|
346
255
|
width,
|
|
347
256
|
height,
|
|
348
257
|
aspect
|
|
349
258
|
} = this._getSizeAndAspect();
|
|
350
|
-
|
|
351
259
|
if (width !== this.animationProps.width || height !== this.animationProps.height) {
|
|
352
260
|
this.setNeedsRedraw('drawing buffer resized');
|
|
353
261
|
}
|
|
354
|
-
|
|
355
262
|
if (aspect !== this.animationProps.aspect) {
|
|
356
263
|
this.setNeedsRedraw('drawing buffer aspect changed');
|
|
357
264
|
}
|
|
358
|
-
|
|
359
265
|
this.animationProps.width = width;
|
|
360
266
|
this.animationProps.height = height;
|
|
361
267
|
this.animationProps.aspect = aspect;
|
|
362
268
|
this.animationProps.needsRedraw = this.needsRedraw;
|
|
363
269
|
this.animationProps.engineTime = Date.now() - this.animationProps.startTime;
|
|
364
|
-
|
|
365
270
|
if (this.timeline) {
|
|
366
271
|
this.timeline.update(this.animationProps.engineTime);
|
|
367
272
|
}
|
|
368
|
-
|
|
369
273
|
this.animationProps.tick = Math.floor(this.animationProps.time / 1000 * 60);
|
|
370
274
|
this.animationProps.tock++;
|
|
371
275
|
this.animationProps.time = this.timeline ? this.timeline.getTime() : this.animationProps.engineTime;
|
|
372
276
|
}
|
|
373
|
-
|
|
374
|
-
async _createDevice() {
|
|
277
|
+
async _initDevice() {
|
|
375
278
|
var _this$device$canvasCo;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
this.device =
|
|
381
|
-
this.canvas = (_this$device$canvasCo = this.device.canvasContext) === null || _this$device$canvasCo === void 0 ? void 0 : _this$device$canvasCo.canvas;
|
|
382
|
-
|
|
383
|
-
this._createInfoDiv();
|
|
279
|
+
this.device = await this.props.device;
|
|
280
|
+
if (!this.device) {
|
|
281
|
+
throw new Error('No device provided');
|
|
282
|
+
}
|
|
283
|
+
this.canvas = ((_this$device$canvasCo = this.device.canvasContext) === null || _this$device$canvasCo === void 0 ? void 0 : _this$device$canvasCo.canvas) || null;
|
|
384
284
|
}
|
|
385
|
-
|
|
386
285
|
_createInfoDiv() {
|
|
387
286
|
if (this.canvas && this.props.onAddHTML) {
|
|
388
287
|
const wrapperDiv = document.createElement('div');
|
|
@@ -394,23 +293,18 @@ export class AnimationLoop {
|
|
|
394
293
|
div.style.bottom = '10px';
|
|
395
294
|
div.style.width = '300px';
|
|
396
295
|
div.style.background = 'white';
|
|
397
|
-
|
|
398
296
|
if (this.canvas instanceof HTMLCanvasElement) {
|
|
399
297
|
wrapperDiv.appendChild(this.canvas);
|
|
400
298
|
}
|
|
401
|
-
|
|
402
299
|
wrapperDiv.appendChild(div);
|
|
403
300
|
const html = this.props.onAddHTML(div);
|
|
404
|
-
|
|
405
301
|
if (html) {
|
|
406
302
|
div.innerHTML = html;
|
|
407
303
|
}
|
|
408
304
|
}
|
|
409
305
|
}
|
|
410
|
-
|
|
411
306
|
_getSizeAndAspect() {
|
|
412
|
-
var _this$device3, _this$
|
|
413
|
-
|
|
307
|
+
var _this$device3, _this$device4;
|
|
414
308
|
if (!this.device) {
|
|
415
309
|
return {
|
|
416
310
|
width: 1,
|
|
@@ -418,63 +312,54 @@ export class AnimationLoop {
|
|
|
418
312
|
aspect: 1
|
|
419
313
|
};
|
|
420
314
|
}
|
|
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];
|
|
315
|
+
const [width, height] = ((_this$device3 = this.device) === null || _this$device3 === void 0 || (_this$device3 = _this$device3.canvasContext) === null || _this$device3 === void 0 ? void 0 : _this$device3.getPixelSize()) || [1, 1];
|
|
423
316
|
let aspect = 1;
|
|
424
|
-
const canvas = (_this$device4 = this.device) === null || _this$device4 === void 0
|
|
425
|
-
|
|
317
|
+
const canvas = (_this$device4 = this.device) === null || _this$device4 === void 0 || (_this$device4 = _this$device4.canvasContext) === null || _this$device4 === void 0 ? void 0 : _this$device4.canvas;
|
|
426
318
|
if (canvas && canvas.clientHeight) {
|
|
427
319
|
aspect = canvas.clientWidth / canvas.clientHeight;
|
|
428
320
|
} else if (width > 0 && height > 0) {
|
|
429
321
|
aspect = width / height;
|
|
430
322
|
}
|
|
431
|
-
|
|
432
323
|
return {
|
|
433
324
|
width,
|
|
434
325
|
height,
|
|
435
326
|
aspect
|
|
436
327
|
};
|
|
437
328
|
}
|
|
438
|
-
|
|
439
329
|
_resizeViewport() {
|
|
440
330
|
if (this.props.autoResizeViewport && this.device.gl) {
|
|
441
331
|
this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);
|
|
442
332
|
}
|
|
443
333
|
}
|
|
444
|
-
|
|
445
334
|
_resizeCanvasDrawingBuffer() {
|
|
446
335
|
if (this.props.autoResizeDrawingBuffer) {
|
|
447
|
-
var _this$device5
|
|
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({
|
|
336
|
+
var _this$device5;
|
|
337
|
+
(_this$device5 = this.device) === null || _this$device5 === void 0 || (_this$device5 = _this$device5.canvasContext) === null || _this$device5 === void 0 ? void 0 : _this$device5.resize({
|
|
450
338
|
useDevicePixels: this.props.useDevicePixels
|
|
451
339
|
});
|
|
452
340
|
}
|
|
453
341
|
}
|
|
454
|
-
|
|
455
|
-
_beginTimers() {
|
|
342
|
+
_beginFrameTimers() {
|
|
456
343
|
this.frameRate.timeEnd();
|
|
457
344
|
this.frameRate.timeStart();
|
|
345
|
+
this.cpuTime.timeStart();
|
|
458
346
|
}
|
|
459
|
-
|
|
460
|
-
_endTimers() {
|
|
347
|
+
_endFrameTimers() {
|
|
461
348
|
this.cpuTime.timeEnd();
|
|
462
349
|
}
|
|
463
|
-
|
|
464
350
|
_startEventHandling() {
|
|
465
351
|
if (this.canvas) {
|
|
466
|
-
this.canvas.addEventListener('mousemove', this._onMousemove);
|
|
467
|
-
this.canvas.addEventListener('mouseleave', this._onMouseleave);
|
|
352
|
+
this.canvas.addEventListener('mousemove', this._onMousemove.bind(this));
|
|
353
|
+
this.canvas.addEventListener('mouseleave', this._onMouseleave.bind(this));
|
|
468
354
|
}
|
|
469
355
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
356
|
+
_onMousemove(event) {
|
|
357
|
+
if (event instanceof MouseEvent) {
|
|
358
|
+
this._getAnimationProps()._mousePosition = [event.offsetX, event.offsetY];
|
|
359
|
+
}
|
|
473
360
|
}
|
|
474
|
-
|
|
475
|
-
_onMouseleave(e) {
|
|
361
|
+
_onMouseleave(event) {
|
|
476
362
|
this._getAnimationProps()._mousePosition = null;
|
|
477
363
|
}
|
|
478
|
-
|
|
479
364
|
}
|
|
480
365
|
//# sourceMappingURL=animation-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animation-loop.js","names":["luma","requestAnimationFrame","cancelAnimationFrame","Stats","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","device","onAddHTML","onInitialize","onRender","onFinalize","onError","error","console","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","props","canvas","animationProps","timeline","cpuTime","gpuTime","frameRate","display","needsRedraw","_initialized","_running","_animationFrameId","_nextFramePromise","_resolveNextFrame","_cpuStartTime","Error","id","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","appContext","_initDevice","_initialize","_getAnimationProps","_cancelAnimationFrame","_requestAnimationFrame","err","redraw","_this$device","isLost","_beginFrameTimers","_setupFrame","_updateAnimationProps","_renderFrame","_clearNeedsRedraw","_endFrameTimers","attachTimeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","HTMLCanvasElement","_startEventHandling","_initializeAnimationProps","_resizeCanvasDrawingBuffer","_resizeViewport","animationLoop","_animationFrame","submit","_this$device2","canvasContext","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_this$device$canvasCo","_createInfoDiv","wrapperDiv","document","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","_this$device3","_this$device4","getPixelSize","clientHeight","clientWidth","gl","viewport","drawingBufferWidth","drawingBufferHeight","_this$device5","resize","timeEnd","timeStart","addEventListener","event","MouseEvent","offsetX","offsetY"],"sources":["../../src/animation-loop/animation-loop.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {luma, Device} from '@luma.gl/core';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/core';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from './animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\n\nlet statIdCounter = 0;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n device: Device | Promise<Device>;\n\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 stats?: Stats;\n\n // view parameters - TODO move to CanvasContext?\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nexport type MutableAnimationLoopProps = {\n // view parameters\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n}\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n device: null!,\n\n onAddHTML: () => '',\n onInitialize: async () => { return null; },\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: false,\n autoResizeDrawingBuffer: false,\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: 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 if (!props.device) {\n throw new Error('No device provided');\n }\n\n const {useDevicePixels = true} = this.props;\n\n // state\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 /** Flags this animation loop as needing redraw */\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n /** TODO - move these props to CanvasContext? */\n setProps(props: MutableAnimationLoopProps): 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\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n // Create the WebGL context\n await this._initDevice();\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 /** 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 /** Explicitly draw a frame */\n redraw(): this {\n if (this.device?.isLost) {\n return this;\n }\n\n this._beginFrameTimers();\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._endFrameTimers();\n\n return this;\n }\n\n /** Add a timeline, it will be automatically updated by the animation loop. */\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n /** Remove a timeline */\n detachTimeline(): void {\n this.timeline = null;\n }\n\n /** Wait until a render completes */\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 /** TODO - should use device.deviceContext */\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(): void {\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: any): void {\n if (this.display) {\n this.display.destroy();\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(): void {\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(): void {\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(): void {\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): void {\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 // Submit commands (necessary on WebGPU)\n this.device.submit();\n }\n\n _clearNeedsRedraw(): void {\n this.needsRedraw = false;\n }\n\n _setupFrame(): void {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeAnimationProps(): void {\n if (!this.device) {\n throw new Error('loop');\n }\n this.animationProps = {\n animationLoop: this,\n\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 // Can this be replaced with canvas context?\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 /** Wait for supplied device */\n async _initDevice() {\n this.device = await this.props.device;\n if (!this.device) {\n throw new Error('No device provided');\n }\n this.canvas = this.device.canvasContext?.canvas || null;\n // this._createInfoDiv();\n }\n\n _createInfoDiv(): void {\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(): void {\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(): void {\n if (this.props.autoResizeDrawingBuffer) {\n this.device?.canvasContext?.resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginFrameTimers() {\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 _endFrameTimers() {\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.bind(this));\n this.canvas.addEventListener('mouseleave', this._onMouseleave.bind(this));\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"],"mappings":"AAGA,SAAQA,IAAI,QAAe,eAAe;AAC1C,SAAQC,qBAAqB,EAAEC,oBAAoB,QAAO,eAAe;AAGzE,SAAQC,KAAK,QAAa,iBAAiB;AAE3C,IAAIC,aAAa,GAAG,CAAC;AA2BrB,MAAMC,4BAA0D,GAAG;EACjEC,MAAM,EAAE,IAAK;EAEbC,SAAS,EAAEA,CAAA,KAAM,EAAE;EACnBC,YAAY,EAAE,MAAAA,CAAA,KAAY;IAAE,OAAO,IAAI;EAAE,CAAC;EAC1CC,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;EAClBC,UAAU,EAAEA,CAAA,KAAM,CAAC,CAAC;EACpBC,OAAO,EAAGC,KAAK,IAAKC,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC;EAExCE,KAAK,EAAEd,IAAI,CAACc,KAAK,CAACC,GAAG,CAAE,kBAAiBX,aAAa,EAAG,EAAC,CAAC;EAG1DY,eAAe,EAAE,IAAI;EACrBC,kBAAkB,EAAE,KAAK;EACzBC,uBAAuB,EAAE;AAC3B,CAAC;AAGD,OAAO,MAAMC,aAAa,CAAC;EA4BzBC,WAAWA,CAACC,KAAyB,EAAE;IAAA,KA3BvCf,MAAM,GAAkB,IAAI;IAAA,KAC5BgB,MAAM,GAA+C,IAAI;IAAA,KAEzDD,KAAK;IAAA,KACLE,cAAc,GAA0B,IAAI;IAAA,KAC5CC,QAAQ,GAAoB,IAAI;IAAA,KAChCV,KAAK;IAAA,KACLW,OAAO;IAAA,KACPC,OAAO;IAAA,KACPC,SAAS;IAAA,KAETC,OAAO;IAAA,KAEPC,WAAW,G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nH,MAAM,cAAAmH,aAAA,gBAAAA,aAAA,GAAXA,aAAA,CAAazC,aAAa,cAAAyC,aAAA,uBAA1BA,aAAA,CAA4BC,MAAM,CAAC;QAAC1G,eAAe,EAAE,IAAI,CAACK,KAAK,CAACL;MAAe,CAAC,CAAC;IACnF;EACF;EAEA2C,iBAAiBA,CAAA,EAAG;IAClB,IAAI,CAAChC,SAAS,CAACgG,OAAO,CAAC,CAAC;IACxB,IAAI,CAAChG,SAAS,CAACiG,SAAS,CAAC,CAAC;IAkB1B,IAAI,CAACnG,OAAO,CAACmG,SAAS,CAAC,CAAC;EAC1B;EAEA5D,eAAeA,CAAA,EAAG;IAChB,IAAI,CAACvC,OAAO,CAACkG,OAAO,CAAC,CAAC;EAMxB;EAIAnD,mBAAmBA,CAAA,EAAG;IACpB,IAAI,IAAI,CAAClD,MAAM,EAAE;MACf,IAAI,CAACA,MAAM,CAACuG,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAACnF,YAAY,CAACF,IAAI,CAAC,IAAI,CAAC,CAAC;MACvE,IAAI,CAAClB,MAAM,CAACuG,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAClF,aAAa,CAACH,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E;EACF;EAEAE,YAAYA,CAACoF,KAAY,EAAE;IACzB,IAAIA,KAAK,YAAYC,UAAU,EAAE;MAC/B,IAAI,CAAC3E,kBAAkB,CAAC,CAAC,CAACuC,cAAc,GAAG,CAACmC,KAAK,CAACE,OAAO,EAAEF,KAAK,CAACG,OAAO,CAAC;IAC3E;EACF;EAEAtF,aAAaA,CAACmF,KAAY,EAAE;IAC1B,IAAI,CAAC1E,kBAAkB,CAAC,CAAC,CAACuC,cAAc,GAAG,IAAI;EACjD;AACF"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { Device } from '@luma.gl/api';
|
|
1
|
+
import { Device } from '@luma.gl/core';
|
|
3
2
|
import { Timeline } from '../animation/timeline';
|
|
4
3
|
import type { AnimationLoop } from './animation-loop';
|
|
5
4
|
/** Properties passed to every render frame */
|
|
6
|
-
export
|
|
5
|
+
export type AnimationProps = {
|
|
7
6
|
device: Device;
|
|
8
7
|
animationLoop: AnimationLoop;
|
|
9
8
|
/** @todo Should be canvasContext */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/animation-loop/animation-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAC9C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAEpD,+CAA+C;AAC/C,MAAM,MAAM,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animation-props.js","names":[],"sources":["../../src/animation-loop/animation-props.ts"],"sourcesContent":["import {Device} from '@luma.gl/core';\nimport {Timeline} from '../animation/timeline'\nimport type {AnimationLoop} from './animation-loop';\n\n/** Properties passed to every render frame */\nexport type AnimationProps = {\n device: Device;\n animationLoop: AnimationLoop;\n\n /** @todo Should be canvasContext */\n canvas: HTMLCanvasElement | OffscreenCanvas;\n useDevicePixels: number | boolean;\n width: number;\n height: number;\n aspect: number;\n\n // Animation props\n time: number;\n startTime: number;\n engineTime: number;\n tick: number;\n tock: number;\n\n // Initial values\n needsRedraw?: string | false;\n\n timeline: Timeline | null;\n\n // Experimental\n _mousePosition?: [number, number] | null; // [offsetX, offsetY],\n};\n"],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AnimationLoopTemplate } from './animation-loop-template';
|
|
2
|
+
import { AnimationLoop, AnimationLoopProps } from './animation-loop';
|
|
3
|
+
export type MakeAnimationLoopProps = Omit<AnimationLoopProps, 'onCreateDevice' | 'onInitialize' | 'onRedraw' | 'onFinalize'>;
|
|
4
|
+
/** Instantiates and runs the render loop */
|
|
5
|
+
export declare function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoopTemplate, props?: MakeAnimationLoopProps): AnimationLoop;
|
|
6
|
+
//# sourceMappingURL=make-animation-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-animation-loop.d.ts","sourceRoot":"","sources":["../../src/animation-loop/make-animation-loop.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,MAAM,kBAAkB,CAAA;AAGlE,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,kBAAkB,EAAE,gBAAgB,GAAG,cAAc,GAAG,UAAU,GAAG,YAAY,CAAC,CAAC;AAE7H,4CAA4C;AAC5C,wBAAgB,iBAAiB,CAAC,yBAAyB,EAAE,OAAO,qBAAqB,EAAE,KAAK,CAAC,EAAE,sBAAsB,GAAG,aAAa,CAkCxI"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { luma } from '@luma.gl/core';
|
|
2
|
+
import { AnimationLoop } from "./animation-loop.js";
|
|
3
|
+
export function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
|
|
4
|
+
let renderLoop = null;
|
|
5
|
+
const device = (props === null || props === void 0 ? void 0 : props.device) || luma.createDevice();
|
|
6
|
+
const animationLoop = new AnimationLoop({
|
|
7
|
+
...props,
|
|
8
|
+
device,
|
|
9
|
+
async onInitialize(animationProps) {
|
|
10
|
+
var _renderLoop;
|
|
11
|
+
renderLoop = new AnimationLoopTemplateCtor(animationProps);
|
|
12
|
+
return await ((_renderLoop = renderLoop) === null || _renderLoop === void 0 ? void 0 : _renderLoop.onInitialize(animationProps));
|
|
13
|
+
},
|
|
14
|
+
onRender: animationProps => {
|
|
15
|
+
var _renderLoop2;
|
|
16
|
+
return (_renderLoop2 = renderLoop) === null || _renderLoop2 === void 0 ? void 0 : _renderLoop2.onRender(animationProps);
|
|
17
|
+
},
|
|
18
|
+
onFinalize: animationProps => {
|
|
19
|
+
var _renderLoop3;
|
|
20
|
+
return (_renderLoop3 = renderLoop) === null || _renderLoop3 === void 0 ? void 0 : _renderLoop3.onFinalize(animationProps);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
animationLoop.getInfo = () => {
|
|
24
|
+
return this.AnimationLoopTemplateCtor.info;
|
|
25
|
+
};
|
|
26
|
+
return animationLoop;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=make-animation-loop.js.map
|