@luma.gl/engine 9.0.0-beta.3 → 9.0.0-beta.5

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.
Files changed (81) hide show
  1. package/dist/animation/key-frames.js +54 -54
  2. package/dist/animation/timeline.js +95 -100
  3. package/dist/animation-loop/animation-loop-template.js +17 -5
  4. package/dist/animation-loop/animation-loop.js +425 -356
  5. package/dist/animation-loop/animation-props.js +0 -1
  6. package/dist/animation-loop/make-animation-loop.js +27 -25
  7. package/dist/debug/copy-texture-to-image.js +39 -43
  8. package/dist/debug/debug-framebuffer.js +43 -39
  9. package/dist/debug/debug-shader-layout.js +24 -25
  10. package/dist/debug/pixel-data-utils.js +33 -36
  11. package/dist/dist.dev.js +3784 -8642
  12. package/dist/geometries/cone-geometry.js +12 -18
  13. package/dist/geometries/cube-geometry.js +189 -62
  14. package/dist/geometries/cylinder-geometry.js +10 -15
  15. package/dist/geometries/ico-sphere-geometry.js +142 -161
  16. package/dist/geometries/plane-geometry.js +94 -112
  17. package/dist/geometries/sphere-geometry.js +77 -96
  18. package/dist/geometries/truncated-cone-geometry.js +100 -118
  19. package/dist/geometry/geometry-table.js +0 -1
  20. package/dist/geometry/geometry-utils.js +35 -32
  21. package/dist/geometry/geometry.js +77 -71
  22. package/dist/geometry/gpu-geometry.js +80 -99
  23. package/dist/geometry/gpu-table.js +41 -1
  24. package/dist/index.cjs +81 -127
  25. package/dist/index.cjs.map +7 -0
  26. package/dist/index.js +27 -24
  27. package/dist/lib/clip-space.d.ts +1 -1
  28. package/dist/lib/clip-space.d.ts.map +1 -1
  29. package/dist/lib/clip-space.js +26 -30
  30. package/dist/lib/pipeline-factory.d.ts +1 -5
  31. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  32. package/dist/lib/pipeline-factory.js +61 -68
  33. package/dist/model/model.d.ts +2 -2
  34. package/dist/model/model.d.ts.map +1 -1
  35. package/dist/model/model.js +539 -413
  36. package/dist/scenegraph/group-node.js +69 -84
  37. package/dist/scenegraph/model-node.js +32 -25
  38. package/dist/scenegraph/scenegraph-node.js +136 -124
  39. package/dist/shader-inputs.js +96 -58
  40. package/dist/transform/buffer-transform.js +65 -58
  41. package/dist/transform/texture-transform.d.ts.map +1 -1
  42. package/dist/transform/texture-transform.js +108 -115
  43. package/dist.min.js +3 -271
  44. package/package.json +10 -9
  45. package/src/lib/clip-space.ts +2 -1
  46. package/src/lib/pipeline-factory.ts +8 -21
  47. package/src/model/model.ts +5 -5
  48. package/src/transform/buffer-transform.ts +3 -3
  49. package/src/transform/texture-transform.ts +0 -2
  50. package/dist/animation/key-frames.js.map +0 -1
  51. package/dist/animation/timeline.js.map +0 -1
  52. package/dist/animation-loop/animation-loop-template.js.map +0 -1
  53. package/dist/animation-loop/animation-loop.js.map +0 -1
  54. package/dist/animation-loop/animation-props.js.map +0 -1
  55. package/dist/animation-loop/make-animation-loop.js.map +0 -1
  56. package/dist/debug/copy-texture-to-image.js.map +0 -1
  57. package/dist/debug/debug-framebuffer.js.map +0 -1
  58. package/dist/debug/debug-shader-layout.js.map +0 -1
  59. package/dist/debug/pixel-data-utils.js.map +0 -1
  60. package/dist/geometries/cone-geometry.js.map +0 -1
  61. package/dist/geometries/cube-geometry.js.map +0 -1
  62. package/dist/geometries/cylinder-geometry.js.map +0 -1
  63. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  64. package/dist/geometries/plane-geometry.js.map +0 -1
  65. package/dist/geometries/sphere-geometry.js.map +0 -1
  66. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  67. package/dist/geometry/geometry-table.js.map +0 -1
  68. package/dist/geometry/geometry-utils.js.map +0 -1
  69. package/dist/geometry/geometry.js.map +0 -1
  70. package/dist/geometry/gpu-geometry.js.map +0 -1
  71. package/dist/geometry/gpu-table.js.map +0 -1
  72. package/dist/index.js.map +0 -1
  73. package/dist/lib/clip-space.js.map +0 -1
  74. package/dist/lib/pipeline-factory.js.map +0 -1
  75. package/dist/model/model.js.map +0 -1
  76. package/dist/scenegraph/group-node.js.map +0 -1
  77. package/dist/scenegraph/model-node.js.map +0 -1
  78. package/dist/scenegraph/scenegraph-node.js.map +0 -1
  79. package/dist/shader-inputs.js.map +0 -1
  80. package/dist/transform/buffer-transform.js.map +0 -1
  81. package/dist/transform/texture-transform.js.map +0 -1
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=animation-props.js.map
@@ -1,28 +1,30 @@
1
+ // luma.gl, MIT license
1
2
  import { luma } from '@luma.gl/core';
2
- import { AnimationLoop } from "./animation-loop.js";
3
+ import { AnimationLoop } from './animation-loop';
4
+ /** Instantiates and runs the render loop */
3
5
  export function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
4
- let renderLoop = null;
5
- const device = (props === null || props === void 0 ? void 0 : props.device) || luma.createDevice();
6
- const animationLoop = new AnimationLoop({
7
- ...props,
8
- device,
9
- async onInitialize(animationProps) {
10
- var _renderLoop;
11
- renderLoop = new AnimationLoopTemplateCtor(animationProps);
12
- return await ((_renderLoop = renderLoop) === null || _renderLoop === void 0 ? void 0 : _renderLoop.onInitialize(animationProps));
13
- },
14
- onRender: animationProps => {
15
- var _renderLoop2;
16
- return (_renderLoop2 = renderLoop) === null || _renderLoop2 === void 0 ? void 0 : _renderLoop2.onRender(animationProps);
17
- },
18
- onFinalize: animationProps => {
19
- var _renderLoop3;
20
- return (_renderLoop3 = renderLoop) === null || _renderLoop3 === void 0 ? void 0 : _renderLoop3.onFinalize(animationProps);
21
- }
22
- });
23
- animationLoop.getInfo = () => {
24
- return this.AnimationLoopTemplateCtor.info;
25
- };
26
- return animationLoop;
6
+ let renderLoop = null;
7
+ const device = props?.device || luma.createDevice();
8
+ // Create an animation loop;
9
+ const animationLoop = new AnimationLoop({
10
+ ...props,
11
+ device,
12
+ async onInitialize(animationProps) {
13
+ // @ts-expect-error abstract to prevent instantiation
14
+ renderLoop = new AnimationLoopTemplateCtor(animationProps);
15
+ // Any async loading can be handled here
16
+ return await renderLoop?.onInitialize(animationProps);
17
+ },
18
+ onRender: (animationProps) => renderLoop?.onRender(animationProps),
19
+ onFinalize: (animationProps) => renderLoop?.onFinalize(animationProps)
20
+ });
21
+ // @ts-expect-error Hack: adds info for the website to find
22
+ animationLoop.getInfo = () => {
23
+ // @ts-ignore
24
+ // eslint-disable-next-line no-invalid-this
25
+ return this.AnimationLoopTemplateCtor.info;
26
+ };
27
+ // Start the loop automatically
28
+ // animationLoop.start();
29
+ return animationLoop;
27
30
  }
28
- //# sourceMappingURL=make-animation-loop.js.map
@@ -1,46 +1,42 @@
1
- import { flipRows, scalePixels } from "./pixel-data-utils.js";
1
+ import { GL } from '@luma.gl/constants';
2
+ import { flipRows, scalePixels } from './pixel-data-utils';
3
+ /**
4
+ * Reads pixels from a Framebuffer or Texture object into an HTML Image
5
+ * @todo - can we move this to @luma.gl/core?
6
+ * @param source
7
+ * @param options options passed to copyToDataUrl
8
+ * @returns
9
+ */
2
10
  export function copyTextureToImage(source, options) {
3
- const dataUrl = copyTextureToDataUrl(source, options);
4
- const targetImage = (options === null || options === void 0 ? void 0 : options.targetImage) || new Image();
5
- targetImage.src = dataUrl;
6
- return targetImage;
11
+ const dataUrl = copyTextureToDataUrl(source, options);
12
+ const targetImage = options?.targetImage || new Image();
13
+ targetImage.src = dataUrl;
14
+ return targetImage;
7
15
  }
8
- export function copyTextureToDataUrl(source) {
9
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10
- const {
11
- sourceAttachment = 36064,
12
- targetMaxHeight = Number.MAX_SAFE_INTEGER
13
- } = options;
14
- let data = source.device.readPixelsToArrayWebGL(source, {
15
- sourceAttachment
16
- });
17
- let {
18
- width,
19
- height
20
- } = source;
21
- while (height > targetMaxHeight) {
22
- ({
23
- data,
24
- width,
25
- height
26
- } = scalePixels({
27
- data,
28
- width,
29
- height
30
- }));
31
- }
32
- flipRows({
33
- data,
34
- width,
35
- height
36
- });
37
- const canvas = document.createElement('canvas');
38
- canvas.width = width;
39
- canvas.height = height;
40
- const context = canvas.getContext('2d');
41
- const imageData = context.createImageData(width, height);
42
- imageData.data.set(data);
43
- context.putImageData(imageData, 0, 0);
44
- return canvas.toDataURL('image/png');
16
+ /**
17
+ * Reads pixels from a Framebuffer or Texture object to a dataUrl
18
+ * @todo - can we move this to @luma.gl/core?
19
+ * @param source texture or framebuffer to read from
20
+ * @param options
21
+ */
22
+ export function copyTextureToDataUrl(source, options = {}) {
23
+ const { sourceAttachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
24
+ targetMaxHeight = Number.MAX_SAFE_INTEGER } = options;
25
+ let data = source.device.readPixelsToArrayWebGL(source, { sourceAttachment });
26
+ // Scale down
27
+ let { width, height } = source;
28
+ while (height > targetMaxHeight) {
29
+ ({ data, width, height } = scalePixels({ data, width, height }));
30
+ }
31
+ // Flip to top down coordinate system
32
+ flipRows({ data, width, height });
33
+ const canvas = document.createElement('canvas');
34
+ canvas.width = width;
35
+ canvas.height = height;
36
+ const context = canvas.getContext('2d');
37
+ // Copy the pixels to a 2D canvas
38
+ const imageData = context.createImageData(width, height);
39
+ imageData.data.set(data);
40
+ context.putImageData(imageData, 0, 0);
41
+ return canvas.toDataURL('image/png');
45
42
  }
46
- //# sourceMappingURL=copy-texture-to-image.js.map
@@ -1,43 +1,47 @@
1
+ // import {copyTextureToImage} from '../debug/copy-texture-to-image';
2
+ /** Only works with 1st device? */
1
3
  let canvas = null;
2
4
  let ctx = null;
3
- export function debugFramebuffer(fbo, _ref) {
4
- let {
5
- id,
6
- minimap,
7
- opaque,
8
- top = '0',
9
- left = '0',
10
- rgbaScale = 1
11
- } = _ref;
12
- if (!canvas) {
13
- canvas = document.createElement('canvas');
14
- canvas.id = id;
15
- canvas.title = id;
16
- canvas.style.zIndex = '100';
17
- canvas.style.position = 'absolute';
18
- canvas.style.top = top;
19
- canvas.style.left = left;
20
- canvas.style.border = 'blue 1px solid';
21
- canvas.style.transform = 'scaleY(-1)';
22
- document.body.appendChild(canvas);
23
- ctx = canvas.getContext('2d');
24
- }
25
- if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
26
- canvas.width = fbo.width / 2;
27
- canvas.height = fbo.height / 2;
28
- canvas.style.width = '400px';
29
- canvas.style.height = '400px';
30
- }
31
- const color = fbo.device.readPixelsToArrayWebGL(fbo);
32
- const imageData = ctx.createImageData(fbo.width, fbo.height);
33
- const offset = 0;
34
- for (let i = 0; i < color.length; i += 4) {
35
- imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
36
- imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
37
- imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
38
- imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
39
- }
40
- ctx.putImageData(imageData, 0, 0);
5
+ // let targetImage: HTMLImageElement | null = null;
6
+ /** Debug utility to draw FBO contents onto screen */
7
+ // eslint-disable-next-line
8
+ export function debugFramebuffer(fbo, { id, minimap, opaque, top = '0', left = '0', rgbaScale = 1 }) {
9
+ if (!canvas) {
10
+ canvas = document.createElement('canvas');
11
+ canvas.id = id;
12
+ canvas.title = id;
13
+ canvas.style.zIndex = '100';
14
+ canvas.style.position = 'absolute';
15
+ canvas.style.top = top; // ⚠️
16
+ canvas.style.left = left; // ⚠️
17
+ canvas.style.border = 'blue 1px solid';
18
+ canvas.style.transform = 'scaleY(-1)';
19
+ document.body.appendChild(canvas);
20
+ ctx = canvas.getContext('2d');
21
+ // targetImage = new Image();
22
+ }
23
+ // const canvasHeight = (minimap ? 2 : 1) * fbo.height;
24
+ if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
25
+ canvas.width = fbo.width / 2;
26
+ canvas.height = fbo.height / 2;
27
+ canvas.style.width = '400px';
28
+ canvas.style.height = '400px';
29
+ }
30
+ // const image = copyTextureToImage(fbo, {targetMaxHeight: 100, targetImage});
31
+ // ctx.drawImage(image, 0, 0);
32
+ const color = fbo.device.readPixelsToArrayWebGL(fbo);
33
+ const imageData = ctx.createImageData(fbo.width, fbo.height);
34
+ // Full map
35
+ const offset = 0;
36
+ // if (color.some((v) => v > 0)) {
37
+ // console.error('THERE IS NON-ZERO DATA IN THE FBO!');
38
+ // }
39
+ for (let i = 0; i < color.length; i += 4) {
40
+ imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
41
+ imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
42
+ imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
43
+ imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
44
+ }
45
+ ctx.putImageData(imageData, 0, 0);
41
46
  }
42
47
  ;
43
- //# sourceMappingURL=debug-framebuffer.js.map
@@ -1,28 +1,27 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /**
5
+ * Extracts a table suitable for `console.table()` from a shader layout to assist in debugging.
6
+ * @param layout shader layout
7
+ * @param name app should provide the most meaningful name, usually the model or pipeline name / id.
8
+ * @returns
9
+ */
1
10
  export function getDebugTableForShaderLayout(layout, name) {
2
- var _layout$varyings;
3
- const table = {};
4
- const header = 'Values';
5
- if (layout.attributes.length === 0 && !((_layout$varyings = layout.varyings) !== null && _layout$varyings !== void 0 && _layout$varyings.length)) {
6
- return {
7
- 'No attributes or varyings': {
8
- [header]: 'N/A'
9
- }
10
- };
11
- }
12
- for (const attributeDeclaration of layout.attributes) {
13
- if (attributeDeclaration) {
14
- const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
15
- table[`in ${glslDeclaration}`] = {
16
- [header]: attributeDeclaration.stepMode || 'vertex'
17
- };
11
+ const table = {};
12
+ const header = 'Values'; // '`Shader Layout for ${name}`;
13
+ if (layout.attributes.length === 0 && !layout.varyings?.length) {
14
+ return { 'No attributes or varyings': { [header]: 'N/A' } };
18
15
  }
19
- }
20
- for (const varyingDeclaration of layout.varyings || []) {
21
- const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;
22
- table[`out ${glslDeclaration}`] = {
23
- [header]: JSON.stringify(varyingDeclaration.accessor)
24
- };
25
- }
26
- return table;
16
+ for (const attributeDeclaration of layout.attributes) {
17
+ if (attributeDeclaration) {
18
+ const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
19
+ table[`in ${glslDeclaration}`] = { [header]: attributeDeclaration.stepMode || 'vertex' };
20
+ }
21
+ }
22
+ for (const varyingDeclaration of layout.varyings || []) {
23
+ const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;
24
+ table[`out ${glslDeclaration}`] = { [header]: JSON.stringify(varyingDeclaration.accessor) };
25
+ }
26
+ return table;
27
27
  }
28
- //# sourceMappingURL=debug-shader-layout.js.map
@@ -1,41 +1,38 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+ /**
4
+ * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
5
+ * https: *stackoverflow.com/questions/41969562/
6
+ * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
7
+ * @param param0
8
+ */
1
9
  export function flipRows(options) {
2
- const {
3
- data,
4
- width,
5
- height,
6
- bytesPerPixel = 4,
7
- temp
8
- } = options;
9
- const bytesPerRow = width * bytesPerPixel;
10
- const tempBuffer = temp || new Uint8Array(bytesPerRow);
11
- for (let y = 0; y < height / 2; ++y) {
12
- const topOffset = y * bytesPerRow;
13
- const bottomOffset = (height - y - 1) * bytesPerRow;
14
- tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));
15
- data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
16
- data.set(tempBuffer, bottomOffset);
17
- }
10
+ const { data, width, height, bytesPerPixel = 4, temp } = options;
11
+ const bytesPerRow = width * bytesPerPixel;
12
+ // make a temp buffer to hold one row
13
+ const tempBuffer = temp || new Uint8Array(bytesPerRow);
14
+ for (let y = 0; y < height / 2; ++y) {
15
+ const topOffset = y * bytesPerRow;
16
+ const bottomOffset = (height - y - 1) * bytesPerRow;
17
+ // make copy of a row on the top half
18
+ tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));
19
+ // copy a row from the bottom half to the top
20
+ data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
21
+ // copy the copy of the top half row to the bottom half
22
+ data.set(tempBuffer, bottomOffset);
23
+ }
18
24
  }
19
25
  export function scalePixels(options) {
20
- const {
21
- data,
22
- width,
23
- height
24
- } = options;
25
- const newWidth = Math.round(width / 2);
26
- const newHeight = Math.round(height / 2);
27
- const newData = new Uint8Array(newWidth * newHeight * 4);
28
- for (let y = 0; y < newHeight; y++) {
29
- for (let x = 0; x < newWidth; x++) {
30
- for (let c = 0; c < 4; c++) {
31
- newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
32
- }
26
+ const { data, width, height } = options;
27
+ const newWidth = Math.round(width / 2);
28
+ const newHeight = Math.round(height / 2);
29
+ const newData = new Uint8Array(newWidth * newHeight * 4);
30
+ for (let y = 0; y < newHeight; y++) {
31
+ for (let x = 0; x < newWidth; x++) {
32
+ for (let c = 0; c < 4; c++) {
33
+ newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
34
+ }
35
+ }
33
36
  }
34
- }
35
- return {
36
- data: newData,
37
- width: newWidth,
38
- height: newHeight
39
- };
37
+ return { data: newData, width: newWidth, height: newHeight };
40
38
  }
41
- //# sourceMappingURL=pixel-data-utils.js.map