@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.
- package/dist/animation/key-frames.js +54 -54
- package/dist/animation/timeline.js +95 -100
- package/dist/animation-loop/animation-loop-template.js +17 -5
- package/dist/animation-loop/animation-loop.js +425 -356
- package/dist/animation-loop/animation-props.js +0 -1
- package/dist/animation-loop/make-animation-loop.js +27 -25
- package/dist/debug/copy-texture-to-image.js +39 -43
- package/dist/debug/debug-framebuffer.js +43 -39
- package/dist/debug/debug-shader-layout.js +24 -25
- package/dist/debug/pixel-data-utils.js +33 -36
- package/dist/dist.dev.js +3784 -8642
- package/dist/geometries/cone-geometry.js +12 -18
- package/dist/geometries/cube-geometry.js +189 -62
- package/dist/geometries/cylinder-geometry.js +10 -15
- package/dist/geometries/ico-sphere-geometry.js +142 -161
- package/dist/geometries/plane-geometry.js +94 -112
- package/dist/geometries/sphere-geometry.js +77 -96
- package/dist/geometries/truncated-cone-geometry.js +100 -118
- package/dist/geometry/geometry-table.js +0 -1
- package/dist/geometry/geometry-utils.js +35 -32
- package/dist/geometry/geometry.js +77 -71
- package/dist/geometry/gpu-geometry.js +80 -99
- package/dist/geometry/gpu-table.js +41 -1
- package/dist/index.cjs +81 -127
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +27 -24
- package/dist/lib/clip-space.d.ts +1 -1
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +26 -30
- package/dist/lib/pipeline-factory.d.ts +1 -5
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +61 -68
- package/dist/model/model.d.ts +2 -2
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +539 -413
- package/dist/scenegraph/group-node.js +69 -84
- package/dist/scenegraph/model-node.js +32 -25
- package/dist/scenegraph/scenegraph-node.js +136 -124
- package/dist/shader-inputs.js +96 -58
- package/dist/transform/buffer-transform.js +65 -58
- package/dist/transform/texture-transform.d.ts.map +1 -1
- package/dist/transform/texture-transform.js +108 -115
- package/dist.min.js +3 -271
- package/package.json +10 -9
- package/src/lib/clip-space.ts +2 -1
- package/src/lib/pipeline-factory.ts +8 -21
- package/src/model/model.ts +5 -5
- package/src/transform/buffer-transform.ts +3 -3
- package/src/transform/texture-transform.ts +0 -2
- package/dist/animation/key-frames.js.map +0 -1
- package/dist/animation/timeline.js.map +0 -1
- package/dist/animation-loop/animation-loop-template.js.map +0 -1
- package/dist/animation-loop/animation-loop.js.map +0 -1
- package/dist/animation-loop/animation-props.js.map +0 -1
- package/dist/animation-loop/make-animation-loop.js.map +0 -1
- package/dist/debug/copy-texture-to-image.js.map +0 -1
- package/dist/debug/debug-framebuffer.js.map +0 -1
- package/dist/debug/debug-shader-layout.js.map +0 -1
- package/dist/debug/pixel-data-utils.js.map +0 -1
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/dist/geometry/geometry-table.js.map +0 -1
- package/dist/geometry/geometry-utils.js.map +0 -1
- package/dist/geometry/geometry.js.map +0 -1
- package/dist/geometry/gpu-geometry.js.map +0 -1
- package/dist/geometry/gpu-table.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/clip-space.js.map +0 -1
- package/dist/lib/pipeline-factory.js.map +0 -1
- package/dist/model/model.js.map +0 -1
- package/dist/scenegraph/group-node.js.map +0 -1
- package/dist/scenegraph/model-node.js.map +0 -1
- package/dist/scenegraph/scenegraph-node.js.map +0 -1
- package/dist/shader-inputs.js.map +0 -1
- package/dist/transform/buffer-transform.js.map +0 -1
- package/dist/transform/texture-transform.js.map +0 -1
|
@@ -1,28 +1,30 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
1
2
|
import { luma } from '@luma.gl/core';
|
|
2
|
-
import { AnimationLoop } from
|
|
3
|
+
import { AnimationLoop } from './animation-loop';
|
|
4
|
+
/** Instantiates and runs the render loop */
|
|
3
5
|
export function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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 {
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
const dataUrl = copyTextureToDataUrl(source, options);
|
|
12
|
+
const targetImage = options?.targetImage || new Image();
|
|
13
|
+
targetImage.src = dataUrl;
|
|
14
|
+
return targetImage;
|
|
7
15
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
sourceAttachment
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
height
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|