@luma.gl/engine 9.0.0-alpha.7 → 9.0.0-alpha.9
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/geometry/geometry.d.ts +2 -2
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +4 -0
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/lib/animation-loop.js +12 -6
- package/dist/lib/animation-loop.js.map +1 -1
- package/package.json +5 -5
- package/src/geometry/geometry.ts +5 -5
- package/src/lib/animation-loop.ts +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TypedArray } from '@luma.gl/api';
|
|
1
|
+
import type { PrimitiveTopology, TypedArray } from '@luma.gl/api';
|
|
2
2
|
import GL from '@luma.gl/constants';
|
|
3
3
|
/**
|
|
4
4
|
* Rendering primitives - "topology" specifies how to extract primitives from vertices.
|
|
@@ -40,7 +40,7 @@ export default class Geometry {
|
|
|
40
40
|
readonly id: string;
|
|
41
41
|
userData: Record<string, unknown>;
|
|
42
42
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
43
|
-
topology?:
|
|
43
|
+
topology?: PrimitiveTopology;
|
|
44
44
|
/** @deprecated */
|
|
45
45
|
readonly drawMode: GLTopology;
|
|
46
46
|
readonly vertexCount: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/geometry/geometry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/geometry/geometry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEpC;;;GAGG;AACH,oBAAY,UAAU,GACpB,EAAE,CAAC,MAAM,GAA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BAAiB,CAAC;QAC1B,UAAU,EAAE,iBAAiB,CAAC;QAC9B,OAAO,CAAC,EAAE,iBAAiB,CAAC;KAC7B,CAAC;IACF,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;gBAEjC,KAAK,GAAE,aAAkB;IAuDrC,wDAAwD;IACxD,IAAI,IAAI,eAEP;IAED,cAAc,IAAI,MAAM;IAWxB,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IASrC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO,KAAA,GAAG,IAAI;IAK5E,qBAAqB,CAAC,UAAU,KAAA,EAAE,OAAO,KAAA,GAAG,MAAM;CAgBnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/geometry/geometry.ts"],"names":["uid","assert","GL","Geometry","constructor","props","TRIANGLES","id","drawMode","attributes","indices","vertexCount","topology","convertToTopology","ArrayBuffer","isView","value","size","attributeName","attributeValue","Object","entries","attribute","_print","isIndexed","undefined","assign","_calculateVertexCount","mode","getVertexCount","_setAttributes","length","Infinity","constant","Math","min","Number","isFinite","POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","Error","String"],"mappings":";AAEA,SAAQA,GAAR,EAAaC,MAAb,QAA0B,cAA1B;AACA,OAAOC,EAAP,MAAe,oBAAf;AAyCA,eAAe,MAAMC,QAAN,CAAe;AA6B5BC,EAAAA,WAAW,CAACC,KAAoB,GAAG,EAAxB,EAA4B;AAAA;;AAAA,sCAhBH,EAgBG;;AAAA;;AAAA,sCAXPH,EAAE,CAACI,SAWI;;AAAA;;AAAA;;AAAA;;AACrC,UAAM;AACJC,MAAAA,EAAE,GAAGP,GAAG,CAAC,UAAD,CADJ;AAEJQ,MAAAA,QAAQ,GAAGN,EAAE,CAACI,SAFV;AAGJG,MAAAA,UAAU,GAAG,EAHT;AAIJC,MAAAA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AEpC,EAAE,CAACoC,MADM;AAEjBC,EAAAA,KAAK,EAAErC,EAAE,CAACqC,KAFO;AAGjBC,EAAAA,SAAS,EAAEtC,EAAE,CAACsC,SAHG;AAIjBC,EAAAA,UAAU,EAAEvC,EAAE,CAACuC,UAJE;AAKjBnC,EAAAA,SAAS,EAAEJ,EAAE,CAACI,SALG;AAMjBoC,EAAAA,cAAc,EAAExC,EAAE,CAACwC,cANF;AAOjBC,EAAAA,YAAY,EAAEzC,EAAE,CAACyC;AAPA,C;;AAkIrB,SAAS9B,iBAAT,CAA2BL,QAA3B,EAAiI;AAC/H,UAAQA,QAAR;AACE,SAAKN,EAAE,CAACoC,MAAR;AAAgB,aAAO,YAAP;;AAChB,SAAKpC,EAAE,CAACqC,KAAR;AAAe,aAAO,WAAP;;AACf,SAAKrC,EAAE,CAACuC,UAAR;AAAoB,aAAO,YAAP;;AACpB,SAAKvC,EAAE,CAACI,SAAR;AAAmB,aAAO,eAAP;;AACnB,SAAKJ,EAAE,CAACwC,cAAR;AAAwB,aAAO,gBAAP;;AAExB,SAAKxC,EAAE,CAACyC,YAAR;AACA,SAAKzC,EAAE,CAACsC,SAAR;AACA;AACE,YAAM,IAAII,KAAJ,CAAUC,MAAM,CAACrC,QAAD,CAAhB,CAAN;AAVJ;AAYD","sourcesContent":["// luma.gl, MIT license\nimport type {TypedArray} from '@luma.gl/api';\nimport {uid, assert} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\n\n/**\n * Rendering primitives - \"topology\" specifies how to extract primitives from vertices.\n * @deprecated - use string constants instead\n */\nexport type GLTopology =\n GL.POINTS | // draw single points.\n GL.LINES | // draw lines. Each vertex connects to the one after it.\n GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.\n GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last\n GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.\n GL.TRIANGLE_STRIP | // draw a connected group of triangles.\n GL.TRIANGLE_FAN // draw a connected group of triangles.\n ;\n\nexport type GeometryAttribute = {\n size?: number;\n value: TypedArray;\n [key: string]: any\n}\n\nexport type GeometryProps = {\n id?: string;\n attributes?: Record<string, GeometryAttribute | TypedArray>,\n indices?: GeometryAttribute | TypedArray;\n vertexCount?: number;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n /** @deprecated */\n drawMode?: GLTopology;\n};\n\ntype GeometryAttributes = {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n indices?: {size?: number, value: Uint32Array | Uint16Array};\n};\n\nexport default class Geometry {\n /** @deprecated */\n static DRAW_MODE = {\n POINTS: GL.POINTS, // draw single points.\n LINES: GL.LINES, // draw lines. Each vertex connects to the one after it.\n LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.\n LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last\n TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.\n TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.\n TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.\n };\n\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n /** @deprecated */\n readonly drawMode: GLTopology = GL.TRIANGLES;\n\n readonly vertexCount: number;\n readonly attributes: {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n };\n readonly indices?: Uint16Array | Uint32Array;\n\n constructor(props: GeometryProps = {}) {\n const {\n id = uid('geometry'),\n drawMode = GL.TRIANGLES,\n attributes = {},\n indices = null,\n vertexCount = null\n } = props;\n\n this.id = id;\n this.drawMode = drawMode;\n this.topology = props.topology || convertToTopology(drawMode);\n\n if (indices) {\n // @ts-expect-error\n this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;\n }\n\n // @ts-expect-error\n this.attributes = {};\n\n for (const [attributeName, attributeValue] of Object.entries(attributes)) {\n\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue) ? {value: attributeValue} : attributeValue;\n\n assert(\n ArrayBuffer.isView(attribute.value),\n `${this._print(attributeName)}: must be typed array or object with value as typed array`\n );\n\n if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {\n attribute.size = 3;\n }\n\n // Move indices to separate field\n if (attributeName === 'indices') {\n assert(!this.indices);\n // @ts-expect-error\n this.indices = attribute;\n } else {\n this.attributes[attributeName] = attribute;\n }\n }\n\n // @ts-expect-error\n if (this.indices && this.indices.isIndexed !== undefined) {\n this.indices = Object.assign({}, this.indices);\n // @ts-expect-error\n delete this.indices.isIndexed;\n }\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n /** @deprecated Use string topology constants instead */\n get mode() {\n return this.drawMode;\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n // Return an object with all attributes plus indices added as a field.\n // getAttributes(): GeometryAttributes {\n // return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;\n // }\n\n // PRIVATE\n\n _print(attributeName: string): string {\n return `Geometry ${this.id} attribute ${attributeName}`;\n }\n\n // GeometryAttribute\n // value: typed array\n // type: indices, vertices, uvs\n // size: elements per vertex\n // target: WebGL buffer type (string or constant)\n _setAttributes(attributes: Record<string, GeometryAttribute>, indices): this {\n\n return this;\n }\n\n _calculateVertexCount(attributes, indices): number {\n if (indices) {\n return indices.value.length;\n }\n let vertexCount = Infinity;\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const {value, size, constant} = attribute;\n if (!constant && value && size >= 1) {\n vertexCount = Math.min(vertexCount, value.length / size);\n }\n }\n\n assert(Number.isFinite(vertexCount));\n return vertexCount;\n }\n}\n\nfunction convertToTopology(drawMode: GLTopology): 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip' {\n switch (drawMode) {\n case GL.POINTS: return 'point-list'; // draw single points.\n case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.\n case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last\n case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.\n case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.\n\n case GL.TRIANGLE_FAN: // draw a connected group of triangles.\n case GL.LINE_LOOP: // draw lines. Each set of two vertices is treated as a separate line segment.\n default:\n throw new Error(String(drawMode));\n }\n}\n"],"file":"geometry.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/geometry/geometry.ts"],"names":["uid","assert","GL","Geometry","constructor","props","TRIANGLES","id","drawMode","attributes","indices","vertexCount","topology","convertToTopology","ArrayBuffer","isView","value","size","attributeName","attributeValue","Object","entries","attribute","_print","isIndexed","undefined","assign","_calculateVertexCount","mode","getVertexCount","_setAttributes","length","Infinity","constant","Math","min","Number","isFinite","POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","Error","String"],"mappings":";AAEA,SAAQA,GAAR,EAAaC,MAAb,QAA0B,cAA1B;AACA,OAAOC,EAAP,MAAe,oBAAf;AAyCA,eAAe,MAAMC,QAAN,CAAe;AA6B5BC,EAAAA,WAAW,CAACC,KAAoB,GAAG,EAAxB,EAA4B;AAAA;;AAAA,sCAhBH,EAgBG;;AAAA;;AAAA,sCAXPH,EAAE,CAACI,SAWI;;AAAA;;AAAA;;AAAA;;AACrC,UAAM;AACJC,MAAAA,EAAE,GAAGP,GAAG,CAAC,UAAD,CADJ;AAEJQ,MAAAA,QAAQ,GAAGN,EAAE,CAACI,SAFV;AAGJG,MAAAA,UAAU,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;AACjBmC,EAAAA,MAAM,EAAEpC,EAAE,CAACoC,MADM;AAEjBC,EAAAA,KAAK,EAAErC,EAAE,CAACqC,KAFO;AAGjBC,EAAAA,SAAS,EAAEtC,EAAE,CAACsC,SAHG;AAIjBC,EAAAA,UAAU,EAAEvC,EAAE,CAACuC,UAJE;AAKjBnC,EAAAA,SAAS,EAAEJ,EAAE,CAACI,SALG;AAMjBoC,EAAAA,cAAc,EAAExC,EAAE,CAACwC,cANF;AAOjBC,EAAAA,YAAY,EAAEzC,EAAE,CAACyC;AAPA,C;;AAkIrB,SAAS9B,iBAAT,CAA2BL,QAA3B,EAAoE;AAClE,UAAQA,QAAR;AACE,SAAKN,EAAE,CAACoC,MAAR;AAAgB,aAAO,YAAP;;AAChB,SAAKpC,EAAE,CAACqC,KAAR;AAAe,aAAO,WAAP;;AACf,SAAKrC,EAAE,CAACuC,UAAR;AAAoB,aAAO,YAAP;;AACpB,SAAKvC,EAAE,CAACI,SAAR;AAAmB,aAAO,eAAP;;AACnB,SAAKJ,EAAE,CAACwC,cAAR;AAAwB,aAAO,gBAAP;;AAExB,SAAKxC,EAAE,CAACyC,YAAR;AAAsB,aAAO,cAAP;;AACtB,SAAKzC,EAAE,CAACsC,SAAR;AAAmB,aAAO,WAAP;;AACnB;AACE,YAAM,IAAII,KAAJ,CAAUC,MAAM,CAACrC,QAAD,CAAhB,CAAN;AAVJ;AAYD","sourcesContent":["// luma.gl, MIT license\nimport type {PrimitiveTopology, TypedArray} from '@luma.gl/api';\nimport {uid, assert} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\n\n/**\n * Rendering primitives - \"topology\" specifies how to extract primitives from vertices.\n * @deprecated - use string constants instead\n */\nexport type GLTopology =\n GL.POINTS | // draw single points.\n GL.LINES | // draw lines. Each vertex connects to the one after it.\n GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.\n GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last\n GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.\n GL.TRIANGLE_STRIP | // draw a connected group of triangles.\n GL.TRIANGLE_FAN // draw a connected group of triangles.\n ;\n\nexport type GeometryAttribute = {\n size?: number;\n value: TypedArray;\n [key: string]: any\n}\n\nexport type GeometryProps = {\n id?: string;\n attributes?: Record<string, GeometryAttribute | TypedArray>,\n indices?: GeometryAttribute | TypedArray;\n vertexCount?: number;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n /** @deprecated */\n drawMode?: GLTopology;\n};\n\ntype GeometryAttributes = {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n indices?: {size?: number, value: Uint32Array | Uint16Array};\n};\n\nexport default class Geometry {\n /** @deprecated */\n static DRAW_MODE = {\n POINTS: GL.POINTS, // draw single points.\n LINES: GL.LINES, // draw lines. Each vertex connects to the one after it.\n LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.\n LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last\n TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.\n TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.\n TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.\n };\n\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: PrimitiveTopology;\n /** @deprecated */\n readonly drawMode: GLTopology = GL.TRIANGLES;\n\n readonly vertexCount: number;\n readonly attributes: {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n };\n readonly indices?: Uint16Array | Uint32Array;\n\n constructor(props: GeometryProps = {}) {\n const {\n id = uid('geometry'),\n drawMode = GL.TRIANGLES,\n attributes = {},\n indices = null,\n vertexCount = null\n } = props;\n\n this.id = id;\n this.drawMode = drawMode;\n this.topology = props.topology || convertToTopology(drawMode);\n\n if (indices) {\n // @ts-expect-error\n this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;\n }\n\n // @ts-expect-error\n this.attributes = {};\n\n for (const [attributeName, attributeValue] of Object.entries(attributes)) {\n\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue) ? {value: attributeValue} : attributeValue;\n\n assert(\n ArrayBuffer.isView(attribute.value),\n `${this._print(attributeName)}: must be typed array or object with value as typed array`\n );\n\n if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {\n attribute.size = 3;\n }\n\n // Move indices to separate field\n if (attributeName === 'indices') {\n assert(!this.indices);\n // @ts-expect-error\n this.indices = attribute;\n } else {\n this.attributes[attributeName] = attribute;\n }\n }\n\n // @ts-expect-error\n if (this.indices && this.indices.isIndexed !== undefined) {\n this.indices = Object.assign({}, this.indices);\n // @ts-expect-error\n delete this.indices.isIndexed;\n }\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n /** @deprecated Use string topology constants instead */\n get mode() {\n return this.drawMode;\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n // Return an object with all attributes plus indices added as a field.\n // getAttributes(): GeometryAttributes {\n // return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;\n // }\n\n // PRIVATE\n\n _print(attributeName: string): string {\n return `Geometry ${this.id} attribute ${attributeName}`;\n }\n\n // GeometryAttribute\n // value: typed array\n // type: indices, vertices, uvs\n // size: elements per vertex\n // target: WebGL buffer type (string or constant)\n _setAttributes(attributes: Record<string, GeometryAttribute>, indices): this {\n\n return this;\n }\n\n _calculateVertexCount(attributes, indices): number {\n if (indices) {\n return indices.value.length;\n }\n let vertexCount = Infinity;\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const {value, size, constant} = attribute;\n if (!constant && value && size >= 1) {\n vertexCount = Math.min(vertexCount, value.length / size);\n }\n }\n\n assert(Number.isFinite(vertexCount));\n return vertexCount;\n }\n}\n\nfunction convertToTopology(drawMode: GLTopology): PrimitiveTopology {\n switch (drawMode) {\n case GL.POINTS: return 'point-list'; // draw single points.\n case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.\n case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last\n case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.\n case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.\n\n case GL.TRIANGLE_FAN: return 'triangle-fan'; // draw a connected group of triangles.\n case GL.LINE_LOOP: return 'line-loop'; // draw lines. Each set of two vertices is treated as a separate line segment.\n default:\n throw new Error(String(drawMode));\n }\n}\n"],"file":"geometry.js"}
|
|
@@ -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,SAAQ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EAAaiE,aAAb,CAA2BoC,MAA3B,CAAkC;AAAChG,QAAAA,eAAe,EAAE,KAAKd,KAAL,CAAWc;AAA7B,OAAlC;AACD;AACF;;AAEDkC,EAAAA,YAAY,GAAG;AACb,SAAKzB,SAAL,CAAewF,OAAf;AACA,SAAKxF,SAAL,CAAeyF,SAAf;AAmBD;;AAEDzD,EAAAA,UAAU,GAAG;AACX,SAAKlC,OAAL,CAAa0F,OAAb;AAMD;;AAID7C,EAAAA,mBAAmB,GAAG;AACpB,QAAI,KAAKF,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAYiD,gBAAZ,CAA6B,WAA7B,EAA0C,KAAKrF,YAA/C;AACA,WAAKoC,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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a0F,OAAb;AAMD;;AAID7C,EAAAA,mBAAmB,GAAG;AACpB,QAAI,KAAKF,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAYiD,gBAAZ,CAA6B,WAA7B,EAA0C,KAAKrF,YAA/C;AACA,WAAKoC,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() || [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.9",
|
|
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.9",
|
|
35
|
+
"@luma.gl/shadertools": "9.0.0-alpha.9",
|
|
36
|
+
"@luma.gl/webgl": "9.0.0-alpha.9",
|
|
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": "b84aae16edcdee2be84d2861c81cc6584e336b28"
|
|
42
42
|
}
|
package/src/geometry/geometry.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
|
-
import type {TypedArray} from '@luma.gl/api';
|
|
2
|
+
import type {PrimitiveTopology, TypedArray} from '@luma.gl/api';
|
|
3
3
|
import {uid, assert} from '@luma.gl/api';
|
|
4
4
|
import GL from '@luma.gl/constants';
|
|
5
5
|
|
|
@@ -58,7 +58,7 @@ export default class Geometry {
|
|
|
58
58
|
userData: Record<string, unknown> = {};
|
|
59
59
|
|
|
60
60
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
61
|
-
topology?:
|
|
61
|
+
topology?: PrimitiveTopology;
|
|
62
62
|
/** @deprecated */
|
|
63
63
|
readonly drawMode: GLTopology = GL.TRIANGLES;
|
|
64
64
|
|
|
@@ -174,7 +174,7 @@ export default class Geometry {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
function convertToTopology(drawMode: GLTopology):
|
|
177
|
+
function convertToTopology(drawMode: GLTopology): PrimitiveTopology {
|
|
178
178
|
switch (drawMode) {
|
|
179
179
|
case GL.POINTS: return 'point-list'; // draw single points.
|
|
180
180
|
case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.
|
|
@@ -182,8 +182,8 @@ function convertToTopology(drawMode: GLTopology): 'point-list' | 'line-list' | '
|
|
|
182
182
|
case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.
|
|
183
183
|
case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.
|
|
184
184
|
|
|
185
|
-
case GL.TRIANGLE_FAN: // draw a connected group of triangles.
|
|
186
|
-
case GL.LINE_LOOP:
|
|
185
|
+
case GL.TRIANGLE_FAN: return 'triangle-fan'; // draw a connected group of triangles.
|
|
186
|
+
case GL.LINE_LOOP: return 'line-loop'; // draw lines. Each set of two vertices is treated as a separate line segment.
|
|
187
187
|
default:
|
|
188
188
|
throw new Error(String(drawMode));
|
|
189
189
|
}
|
|
@@ -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
|
|