@luma.gl/engine 9.0.0-alpha.7 → 9.0.0-alpha.8
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.
|
@@ -304,6 +304,8 @@ export class AnimationLoop {
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
_initializeAnimationProps() {
|
|
307
|
+
var _this$device2, _this$device2$canvasC;
|
|
308
|
+
|
|
307
309
|
if (!this.device) {
|
|
308
310
|
throw new Error('loop');
|
|
309
311
|
}
|
|
@@ -311,7 +313,7 @@ export class AnimationLoop {
|
|
|
311
313
|
this.animationProps = {
|
|
312
314
|
animationLoop: this,
|
|
313
315
|
device: this.device,
|
|
314
|
-
canvas: this.device.canvasContext.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,
|
|
315
317
|
timeline: this.timeline,
|
|
316
318
|
useDevicePixels: this.props.useDevicePixels,
|
|
317
319
|
needsRedraw: false,
|
|
@@ -370,11 +372,13 @@ export class AnimationLoop {
|
|
|
370
372
|
}
|
|
371
373
|
|
|
372
374
|
async _createDevice() {
|
|
375
|
+
var _this$device$canvasCo;
|
|
376
|
+
|
|
373
377
|
const deviceProps = { ...this.props,
|
|
374
378
|
...this.props.deviceProps
|
|
375
379
|
};
|
|
376
380
|
this.device = await this.props.onCreateDevice(deviceProps);
|
|
377
|
-
this.canvas = this.device.canvasContext.canvas;
|
|
381
|
+
this.canvas = (_this$device$canvasCo = this.device.canvasContext) === null || _this$device$canvasCo === void 0 ? void 0 : _this$device$canvasCo.canvas;
|
|
378
382
|
|
|
379
383
|
this._createInfoDiv();
|
|
380
384
|
}
|
|
@@ -405,6 +409,8 @@ export class AnimationLoop {
|
|
|
405
409
|
}
|
|
406
410
|
|
|
407
411
|
_getSizeAndAspect() {
|
|
412
|
+
var _this$device3, _this$device3$canvasC, _this$device4, _this$device4$canvasC;
|
|
413
|
+
|
|
408
414
|
if (!this.device) {
|
|
409
415
|
return {
|
|
410
416
|
width: 1,
|
|
@@ -413,9 +419,9 @@ export class AnimationLoop {
|
|
|
413
419
|
};
|
|
414
420
|
}
|
|
415
421
|
|
|
416
|
-
const [width, height] = this.device.canvasContext.getPixelSize();
|
|
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];
|
|
417
423
|
let aspect = 1;
|
|
418
|
-
const canvas = this.device.canvasContext.canvas;
|
|
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;
|
|
419
425
|
|
|
420
426
|
if (canvas && canvas.clientHeight) {
|
|
421
427
|
aspect = canvas.clientWidth / canvas.clientHeight;
|
|
@@ -438,9 +444,9 @@ export class AnimationLoop {
|
|
|
438
444
|
|
|
439
445
|
_resizeCanvasDrawingBuffer() {
|
|
440
446
|
if (this.props.autoResizeDrawingBuffer) {
|
|
441
|
-
var _this$
|
|
447
|
+
var _this$device5, _this$device5$canvasC;
|
|
442
448
|
|
|
443
|
-
(_this$
|
|
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({
|
|
444
450
|
useDevicePixels: this.props.useDevicePixels
|
|
445
451
|
});
|
|
446
452
|
}
|
|
@@ -1 +1 @@
|
|
|
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","debug","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","e","offsetX","offsetY"],"mappings":";AAAA,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;AAwBA,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,OAAO,EAAP,CAHmD;AAIjEC,EAAAA,QAAQ,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,MAAL,CAAYiD,gBAAZ,CAA6B,YAA7B,EAA2C,KAAKpF,aAAhD;AACD;AACF;;AAEDD,EAAAA,YAAY,CAACsF,CAAD,EAAI;AACd,SAAKzE,kBAAL,GAA0B4C,cAA1B,GAA2C,CAAC6B,CAAC,CAACC,OAAH,EAAYD,CAAC,CAACE,OAAd,CAA3C;AACD;;AAEDvF,EAAAA,aAAa,CAACqF,CAAD,EAAI;AACf,SAAKzE,kBAAL,GAA0B4C,cAA1B,GAA2C,IAA3C;AACD;;AAzewB","sourcesContent":["import {luma, Device, DeviceProps} from '@luma.gl/api';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from '../lib/animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\nimport {isBrowser} from '@probe.gl/env';\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\ntype ContextProps = DeviceProps;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Promise<Device>;\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device | null;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\n debug?: boolean;\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),\n onAddHTML: () => '',\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: null,\n deviceProps: {},\n debug: false,\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n};\n\n/** Convenient animation loop */\nexport 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(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.props.onRender(props);\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();\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const canvas = this.device.canvasContext.canvas;\n\n // @ts-expect-error\n if (canvas && canvas.clientHeight) {\n // @ts-expect-error\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n // @ts-expect-error Expose on canvasContext\n if (this.props.autoResizeViewport && this.device.gl) {\n // @ts-expect-error Expose canvasContext\n this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);\n }\n }\n\n /**\n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n this.device?.canvasContext.resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n // if (\n // this._gpuTimeQuery &&\n // this._gpuTimeQuery.isResultAvailable() &&\n // !this._gpuTimeQuery.isTimerDisjoint()\n // ) {\n // this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n // }\n\n // if (this._gpuTimeQuery) {\n // // GPU time query start\n // this._gpuTimeQuery.beginTimeElapsedQuery();\n // }\n\n // this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n // if (this._gpuTimeQuery) {\n // // GPU time query end. Results will be available on next frame.\n // this._gpuTimeQuery.end();\n // }\n }\n\n // Event handling\n\n _startEventHandling() {\n if (this.canvas) {\n this.canvas.addEventListener('mousemove', this._onMousemove);\n this.canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(e) {\n this._getAnimationProps()._mousePosition = [e.offsetX, e.offsetY];\n }\n\n _onMouseleave(e) {\n this._getAnimationProps()._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
|
|
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","debug","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","e","offsetX","offsetY"],"mappings":";AAAA,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;AAwBA,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,OAAO,EAAP,CAHmD;AAIjEC,EAAAA,QAAQ,EAAE,MAAM,CAAE,CAJ+C;AAKjEC,EAAAA,UAAU,EAAE,MAAM,CAAE,CAL6C;AAMjEC,EAAAA,OAAO,EAAGC,KAAD,IAAWC,OAAO,CAACD,KAAR,CAAcA,KAAd,CAN6C;AAQjEE,EAAAA,MAAM,EAAE,IARyD;AASjEC,EAAAA,WAAW,EAAE,EAToD;AAUjEC,EAAAA,KAAK,EAAE,KAV0D;AAWjEC,EAAAA,KAAK,EAAEtB,IAAI,CAACsB,KAAL,CAAWC,GAAX,0BAAiChB,aAAa,EAA9C,EAX0D;AAcjEiB,EAAAA,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ACf,SAAKzE,kBAAL,GAA0B4C,cAA1B,GAA2C,IAA3C;AACD;;AAzewB","sourcesContent":["import {luma, Device, DeviceProps} from '@luma.gl/api';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from '../lib/animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\nimport {isBrowser} from '@probe.gl/env';\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\ntype ContextProps = DeviceProps;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Promise<Device>;\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device | null;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\n debug?: boolean;\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),\n onAddHTML: () => '',\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: null,\n deviceProps: {},\n debug: false,\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n};\n\n/** Convenient animation loop */\nexport 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(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.props.onRender(props);\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(e) {\n this._getAnimationProps()._mousePosition = [e.offsetX, e.offsetY];\n }\n\n _onMouseleave(e) {\n this._getAnimationProps()._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/engine",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.8",
|
|
4
4
|
"description": "WebGL2 Components for High Performance Rendering and Computation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.0.0",
|
|
34
|
-
"@luma.gl/constants": "9.0.0-alpha.
|
|
35
|
-
"@luma.gl/shadertools": "9.0.0-alpha.
|
|
36
|
-
"@luma.gl/webgl": "9.0.0-alpha.
|
|
34
|
+
"@luma.gl/constants": "9.0.0-alpha.8",
|
|
35
|
+
"@luma.gl/shadertools": "9.0.0-alpha.8",
|
|
36
|
+
"@luma.gl/webgl": "9.0.0-alpha.8",
|
|
37
37
|
"@math.gl/core": "^3.5.0",
|
|
38
38
|
"@probe.gl/log": "^3.5.0",
|
|
39
39
|
"@probe.gl/stats": "^3.5.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "9f5c5cca812c45ccf35e03b0491fd7243c5f2a6d"
|
|
42
42
|
}
|
|
@@ -355,7 +355,7 @@ export class AnimationLoop {
|
|
|
355
355
|
this.animationProps = {
|
|
356
356
|
animationLoop: this,
|
|
357
357
|
device: this.device,
|
|
358
|
-
canvas: this.device
|
|
358
|
+
canvas: this.device?.canvasContext?.canvas!,
|
|
359
359
|
timeline: this.timeline,
|
|
360
360
|
|
|
361
361
|
// Initial values
|
|
@@ -426,7 +426,7 @@ export class AnimationLoop {
|
|
|
426
426
|
async _createDevice() {
|
|
427
427
|
const deviceProps = {...this.props, ...this.props.deviceProps};
|
|
428
428
|
this.device = await this.props.onCreateDevice(deviceProps);
|
|
429
|
-
this.canvas = this.device.canvasContext
|
|
429
|
+
this.canvas = this.device.canvasContext?.canvas!;
|
|
430
430
|
this._createInfoDiv();
|
|
431
431
|
}
|
|
432
432
|
|
|
@@ -457,11 +457,11 @@ export class AnimationLoop {
|
|
|
457
457
|
return {width: 1, height: 1, aspect: 1};
|
|
458
458
|
}
|
|
459
459
|
// https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
|
|
460
|
-
const [width, height] = this.device
|
|
460
|
+
const [width, height] = this.device?.canvasContext?.getPixelSize() || [1, 1];
|
|
461
461
|
|
|
462
462
|
// https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html
|
|
463
463
|
let aspect = 1;
|
|
464
|
-
const canvas = this.device
|
|
464
|
+
const canvas = this.device?.canvasContext?.canvas;
|
|
465
465
|
|
|
466
466
|
// @ts-expect-error
|
|
467
467
|
if (canvas && canvas.clientHeight) {
|
|
@@ -489,7 +489,7 @@ export class AnimationLoop {
|
|
|
489
489
|
*/
|
|
490
490
|
_resizeCanvasDrawingBuffer() {
|
|
491
491
|
if (this.props.autoResizeDrawingBuffer) {
|
|
492
|
-
this.device?.canvasContext
|
|
492
|
+
this.device?.canvasContext?.resize({useDevicePixels: this.props.useDevicePixels});
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
|