@luma.gl/engine 9.0.0-alpha.9 → 9.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -1
- package/dist/animation/key-frames.d.ts +1 -1
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js +6 -27
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +8 -8
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +18 -49
- package/dist/animation/timeline.js.map +1 -1
- package/dist/animation-loop/animation-loop-template.d.ts +23 -0
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +7 -0
- package/dist/animation-loop/animation-loop-template.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -22
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +77 -192
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +2 -3
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/animation-loop/animation-props.js.map +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts +6 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/make-animation-loop.js +28 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/debug/copy-texture-to-image.d.ts +26 -0
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
- package/dist/debug/copy-texture-to-image.js +46 -0
- package/dist/debug/copy-texture-to-image.js.map +1 -0
- package/dist/debug/debug-framebuffer.d.ts +11 -0
- package/dist/debug/debug-framebuffer.d.ts.map +1 -0
- package/dist/debug/debug-framebuffer.js +43 -0
- package/dist/debug/debug-framebuffer.js.map +1 -0
- package/dist/debug/debug-shader-layout.d.ts +9 -0
- package/dist/debug/debug-shader-layout.d.ts.map +1 -0
- package/dist/debug/debug-shader-layout.js +28 -0
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/debug/pixel-data-utils.d.ts +24 -0
- package/dist/debug/pixel-data-utils.d.ts.map +1 -0
- package/dist/debug/pixel-data-utils.js +41 -0
- package/dist/debug/pixel-data-utils.js.map +1 -0
- package/dist/dist.dev.js +10073 -0
- package/dist/geometries/cone-geometry.d.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +6 -5
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.d.ts +2 -2
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +16 -10
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +6 -5
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +10 -19
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts +2 -2
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +14 -23
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts +2 -2
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +9 -13
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +9 -25
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.d.ts +2 -2
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +0 -9
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +43 -43
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +20 -86
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +37 -0
- package/dist/geometry/gpu-geometry.d.ts.map +1 -0
- package/dist/geometry/gpu-geometry.js +110 -0
- package/dist/geometry/gpu-geometry.js.map +1 -0
- package/dist/geometry/gpu-table.d.ts +1 -0
- package/dist/geometry/gpu-table.d.ts.map +1 -0
- package/dist/geometry/gpu-table.js +2 -0
- package/dist/geometry/gpu-table.js.map +1 -0
- package/dist/index.cjs +3120 -0
- package/dist/index.d.ts +24 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/clip-space.d.ts +8 -0
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +47 -0
- package/dist/lib/clip-space.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +12 -46
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +36 -179
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/model/model.d.ts +206 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +440 -0
- package/dist/model/model.js.map +1 -0
- package/dist/scenegraph/group-node.d.ts +21 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -0
- package/dist/scenegraph/group-node.js +94 -0
- package/dist/scenegraph/group-node.js.map +1 -0
- package/dist/scenegraph/model-node.d.ts +18 -0
- package/dist/scenegraph/model-node.d.ts.map +1 -0
- package/dist/scenegraph/model-node.js +28 -0
- package/dist/scenegraph/model-node.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.d.ts +56 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +141 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/shader-inputs.d.ts +63 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +66 -0
- package/dist/shader-inputs.js.map +1 -0
- package/dist/transform/buffer-transform.d.ts +35 -0
- package/dist/transform/buffer-transform.d.ts.map +1 -0
- package/dist/transform/buffer-transform.js +62 -0
- package/dist/transform/buffer-transform.js.map +1 -0
- package/dist/transform/texture-transform.d.ts +57 -0
- package/dist/transform/texture-transform.d.ts.map +1 -0
- package/dist/transform/texture-transform.js +122 -0
- package/dist/transform/texture-transform.js.map +1 -0
- package/dist.min.js +293 -0
- package/package.json +21 -12
- package/src/animation/timeline.ts +15 -14
- package/src/animation-loop/animation-loop-template.ts +23 -0
- package/src/{lib → animation-loop}/animation-loop.ts +99 -88
- package/src/{lib → animation-loop}/animation-props.ts +1 -1
- package/src/animation-loop/make-animation-loop.ts +44 -0
- package/src/debug/copy-texture-to-image.ts +72 -0
- package/src/debug/debug-framebuffer.ts +57 -0
- package/src/debug/debug-shader-layout.ts +38 -0
- package/src/debug/pixel-data-utils.ts +57 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +47 -45
- package/src/geometries/cylinder-geometry.ts +2 -2
- package/src/geometries/ico-sphere-geometry.ts +6 -5
- package/src/geometries/plane-geometry.ts +5 -4
- package/src/geometries/sphere-geometry.ts +4 -3
- package/src/geometries/truncated-cone-geometry.ts +4 -13
- package/src/geometry/geometry-table.ts +1 -1
- package/src/geometry/geometry-utils.ts +19 -3
- package/src/geometry/geometry.ts +65 -110
- package/src/geometry/gpu-geometry.ts +125 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +34 -10
- package/src/lib/clip-space.ts +22 -21
- package/src/lib/pipeline-factory.ts +48 -179
- package/src/model/model.ts +733 -0
- package/src/scenegraph/group-node.ts +103 -0
- package/src/scenegraph/model-node.ts +50 -0
- package/src/scenegraph/scenegraph-node.ts +204 -0
- package/src/shader-inputs.ts +150 -0
- package/src/transform/buffer-transform.ts +94 -0
- package/src/transform/texture-transform.ts +169 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/dist/geometry/primitive-utils.d.ts +0 -1
- package/dist/geometry/primitive-utils.d.ts.map +0 -1
- package/dist/geometry/primitive-utils.js +0 -2
- package/dist/geometry/primitive-utils.js.map +0 -1
- package/dist/lib/animation-loop.d.ts.map +0 -1
- package/dist/lib/animation-loop.js.map +0 -1
- package/dist/lib/animation-props.d.ts.map +0 -1
- package/dist/lib/animation-props.js.map +0 -1
- package/dist/lib/model-utils.d.ts +0 -5
- package/dist/lib/model-utils.d.ts.map +0 -1
- package/dist/lib/model-utils.js +0 -45
- package/dist/lib/model-utils.js.map +0 -1
- package/dist/lib/model.d.ts +0 -41
- package/dist/lib/model.d.ts.map +0 -1
- package/dist/lib/model.js +0 -182
- package/dist/lib/model.js.map +0 -1
- package/dist/lib/render-loop.d.ts +0 -14
- package/dist/lib/render-loop.d.ts.map +0 -1
- package/dist/lib/render-loop.js +0 -49
- package/dist/lib/render-loop.js.map +0 -1
- package/src/bundle.ts +0 -4
- package/src/geometry/primitive-utils.ts +0 -30
- package/src/lib/model-utils.ts +0 -124
- package/src/lib/model.ts +0 -183
- package/src/lib/render-loop.ts +0 -58
- /package/dist/{lib → animation-loop}/animation-props.js +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
import {Texture, Framebuffer} from '@luma.gl/core';
|
|
3
|
+
import {GL} from '@luma.gl/constants';
|
|
4
|
+
import {flipRows, scalePixels} from './pixel-data-utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for copying texture pixels to image
|
|
8
|
+
* @todo - support gl.readBuffer
|
|
9
|
+
*/
|
|
10
|
+
export type CopyTextureToImageOptions = {
|
|
11
|
+
sourceAttachment?: number;
|
|
12
|
+
targetMaxHeight?: number;
|
|
13
|
+
targetImage?: HTMLImageElement;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reads pixels from a Framebuffer or Texture object into an HTML Image
|
|
18
|
+
* @todo - can we move this to @luma.gl/core?
|
|
19
|
+
* @param source
|
|
20
|
+
* @param options options passed to copyToDataUrl
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export function copyTextureToImage(
|
|
24
|
+
source: Texture | Framebuffer,
|
|
25
|
+
options?: CopyTextureToImageOptions
|
|
26
|
+
): HTMLImageElement {
|
|
27
|
+
|
|
28
|
+
const dataUrl = copyTextureToDataUrl(source, options);
|
|
29
|
+
const targetImage: HTMLImageElement = options?.targetImage || new Image();
|
|
30
|
+
targetImage.src = dataUrl;
|
|
31
|
+
|
|
32
|
+
return targetImage;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reads pixels from a Framebuffer or Texture object to a dataUrl
|
|
37
|
+
* @todo - can we move this to @luma.gl/core?
|
|
38
|
+
* @param source texture or framebuffer to read from
|
|
39
|
+
* @param options
|
|
40
|
+
*/
|
|
41
|
+
export function copyTextureToDataUrl(
|
|
42
|
+
source: Texture | Framebuffer,
|
|
43
|
+
options: CopyTextureToImageOptions = {}
|
|
44
|
+
): string {
|
|
45
|
+
const {
|
|
46
|
+
sourceAttachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
|
|
47
|
+
targetMaxHeight = Number.MAX_SAFE_INTEGER
|
|
48
|
+
} = options;
|
|
49
|
+
|
|
50
|
+
let data = source.device.readPixelsToArrayWebGL(source, {sourceAttachment});
|
|
51
|
+
|
|
52
|
+
// Scale down
|
|
53
|
+
let {width, height} = source;
|
|
54
|
+
while (height > targetMaxHeight) {
|
|
55
|
+
({data, width, height} = scalePixels({data, width, height}));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Flip to top down coordinate system
|
|
59
|
+
flipRows({data, width, height});
|
|
60
|
+
|
|
61
|
+
const canvas = document.createElement('canvas');
|
|
62
|
+
canvas.width = width;
|
|
63
|
+
canvas.height = height;
|
|
64
|
+
const context = canvas.getContext('2d');
|
|
65
|
+
|
|
66
|
+
// Copy the pixels to a 2D canvas
|
|
67
|
+
const imageData = context.createImageData(width, height);
|
|
68
|
+
imageData.data.set(data);
|
|
69
|
+
context.putImageData(imageData, 0, 0);
|
|
70
|
+
|
|
71
|
+
return canvas.toDataURL('image/png');
|
|
72
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {Framebuffer, Texture} from '@luma.gl/core';
|
|
2
|
+
// import {copyTextureToImage} from '../debug/copy-texture-to-image';
|
|
3
|
+
|
|
4
|
+
/** Only works with 1st device? */
|
|
5
|
+
let canvas: HTMLCanvasElement | null = null;
|
|
6
|
+
let ctx: CanvasRenderingContext2D | null = null;
|
|
7
|
+
// let targetImage: HTMLImageElement | null = null;
|
|
8
|
+
|
|
9
|
+
/** Debug utility to draw FBO contents onto screen */
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
export function debugFramebuffer(
|
|
12
|
+
fbo: Framebuffer | Texture,
|
|
13
|
+
{id, minimap, opaque, top = '0', left = '0', rgbaScale = 1}: {id: string, minimap?: boolean; opaque?: boolean, top?: string, left?: string, rgbaScale?: number}
|
|
14
|
+
) {
|
|
15
|
+
if (!canvas) {
|
|
16
|
+
canvas = document.createElement('canvas');
|
|
17
|
+
canvas.id = id;
|
|
18
|
+
canvas.title = id;
|
|
19
|
+
canvas.style.zIndex = '100';
|
|
20
|
+
canvas.style.position = 'absolute';
|
|
21
|
+
canvas.style.top = top; // ⚠️
|
|
22
|
+
canvas.style.left = left; // ⚠️
|
|
23
|
+
canvas.style.border = 'blue 1px solid';
|
|
24
|
+
canvas.style.transform = 'scaleY(-1)';
|
|
25
|
+
document.body.appendChild(canvas);
|
|
26
|
+
|
|
27
|
+
ctx = canvas.getContext('2d');
|
|
28
|
+
// targetImage = new Image();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// const canvasHeight = (minimap ? 2 : 1) * fbo.height;
|
|
32
|
+
if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
|
|
33
|
+
canvas.width = fbo.width / 2;
|
|
34
|
+
canvas.height = fbo.height / 2;
|
|
35
|
+
canvas.style.width = '400px';
|
|
36
|
+
canvas.style.height = '400px';
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// const image = copyTextureToImage(fbo, {targetMaxHeight: 100, targetImage});
|
|
41
|
+
// ctx.drawImage(image, 0, 0);
|
|
42
|
+
|
|
43
|
+
const color = fbo.device.readPixelsToArrayWebGL(fbo);
|
|
44
|
+
const imageData = ctx.createImageData(fbo.width, fbo.height);
|
|
45
|
+
// Full map
|
|
46
|
+
const offset = 0;
|
|
47
|
+
// if (color.some((v) => v > 0)) {
|
|
48
|
+
// console.error('THERE IS NON-ZERO DATA IN THE FBO!');
|
|
49
|
+
// }
|
|
50
|
+
for (let i = 0; i < color.length; i += 4) {
|
|
51
|
+
imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
|
|
52
|
+
imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
|
|
53
|
+
imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
|
|
54
|
+
imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
|
|
55
|
+
}
|
|
56
|
+
ctx.putImageData(imageData, 0, 0);
|
|
57
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ShaderLayout} from '@luma.gl/core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extracts a table suitable for `console.table()` from a shader layout to assist in debugging.
|
|
9
|
+
* @param layout shader layout
|
|
10
|
+
* @param name app should provide the most meaningful name, usually the model or pipeline name / id.
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export function getDebugTableForShaderLayout(
|
|
14
|
+
layout: ShaderLayout,
|
|
15
|
+
name: string
|
|
16
|
+
): Record<string, Record<string, string>> {
|
|
17
|
+
const table: Record<string, Record<string, string>> = {};
|
|
18
|
+
|
|
19
|
+
const header = 'Values'; // '`Shader Layout for ${name}`;
|
|
20
|
+
|
|
21
|
+
if (layout.attributes.length === 0 && !layout.varyings?.length) {
|
|
22
|
+
return {'No attributes or varyings': {[header]: 'N/A'}};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (const attributeDeclaration of layout.attributes) {
|
|
26
|
+
if (attributeDeclaration) {
|
|
27
|
+
const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
|
|
28
|
+
table[`in ${glslDeclaration}`] = {[header]: attributeDeclaration.stepMode || 'vertex'};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (const varyingDeclaration of layout.varyings || []) {
|
|
33
|
+
const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;
|
|
34
|
+
table[`out ${glslDeclaration}`] = {[header]: JSON.stringify(varyingDeclaration.accessor)};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return table;
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import {TypedArray} from '@luma.gl/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
|
|
8
|
+
* https: *stackoverflow.com/questions/41969562/
|
|
9
|
+
* how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
|
|
10
|
+
* @param param0
|
|
11
|
+
*/
|
|
12
|
+
export function flipRows(options: {
|
|
13
|
+
data: TypedArray;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
bytesPerPixel?: number;
|
|
17
|
+
temp?: Uint8Array;
|
|
18
|
+
}): void {
|
|
19
|
+
const {data, width, height, bytesPerPixel = 4, temp} = options;
|
|
20
|
+
const bytesPerRow = width * bytesPerPixel;
|
|
21
|
+
|
|
22
|
+
// make a temp buffer to hold one row
|
|
23
|
+
const tempBuffer = temp || new Uint8Array(bytesPerRow);
|
|
24
|
+
for (let y = 0; y < height / 2; ++y) {
|
|
25
|
+
const topOffset = y * bytesPerRow;
|
|
26
|
+
const bottomOffset = (height - y - 1) * bytesPerRow;
|
|
27
|
+
// make copy of a row on the top half
|
|
28
|
+
tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));
|
|
29
|
+
// copy a row from the bottom half to the top
|
|
30
|
+
data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
|
|
31
|
+
// copy the copy of the top half row to the bottom half
|
|
32
|
+
data.set(tempBuffer, bottomOffset);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function scalePixels(options: {
|
|
37
|
+
data: TypedArray;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
}): {
|
|
41
|
+
data: Uint8Array;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
} {
|
|
45
|
+
const {data, width, height} = options;
|
|
46
|
+
const newWidth = Math.round(width / 2);
|
|
47
|
+
const newHeight = Math.round(height / 2);
|
|
48
|
+
const newData = new Uint8Array(newWidth * newHeight * 4);
|
|
49
|
+
for (let y = 0; y < newHeight; y++) {
|
|
50
|
+
for (let x = 0; x < newWidth; x++) {
|
|
51
|
+
for (let c = 0; c < 4; c++) {
|
|
52
|
+
newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {data: newData, width: newWidth, height: newHeight};
|
|
57
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {uid} from '@luma.gl/
|
|
2
|
-
import Geometry from '../geometry/geometry';
|
|
1
|
+
import {uid} from '@luma.gl/core';
|
|
2
|
+
import {Geometry} from '../geometry/geometry';
|
|
3
3
|
// import type {GeometryType} from '../geometry/geometry-type';
|
|
4
4
|
|
|
5
5
|
export type CubeGeometryProps = {
|
|
6
6
|
id?: string;
|
|
7
7
|
indices?: boolean;
|
|
8
|
-
attributes
|
|
8
|
+
attributes?: any;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export class CubeGeometry extends Geometry {
|
|
@@ -14,11 +14,13 @@ export class CubeGeometry extends Geometry {
|
|
|
14
14
|
super(indices ? {
|
|
15
15
|
...props,
|
|
16
16
|
id,
|
|
17
|
+
topology: 'triangle-list',
|
|
17
18
|
indices: {size: 1, value: CUBE_INDICES},
|
|
18
19
|
attributes: {...ATTRIBUTES, ...props.attributes}
|
|
19
20
|
} : {
|
|
20
21
|
...props,
|
|
21
22
|
id,
|
|
23
|
+
topology: 'triangle-list',
|
|
22
24
|
indices: undefined,
|
|
23
25
|
attributes: {...NON_INDEXED_ATTRIBUTES, ...props.attributes}
|
|
24
26
|
});
|
|
@@ -77,47 +79,47 @@ const CUBE_TEX_COORDS = new Float32Array([
|
|
|
77
79
|
// float4 position
|
|
78
80
|
// prettier-ignore
|
|
79
81
|
export const CUBE_NON_INDEXED_POSITIONS = new Float32Array([
|
|
80
|
-
1, -1, 1,
|
|
81
|
-
-1, -1, 1,
|
|
82
|
-
-1, -1, -1,
|
|
83
|
-
1, -1, -1,
|
|
84
|
-
1, -1, 1,
|
|
85
|
-
-1, -1, -1,
|
|
86
|
-
|
|
87
|
-
1, 1, 1,
|
|
88
|
-
1, -1, 1,
|
|
89
|
-
1, -1, -1,
|
|
90
|
-
1, 1, -1,
|
|
91
|
-
1, 1, 1,
|
|
92
|
-
1, -1, -1,
|
|
93
|
-
|
|
94
|
-
-1, 1, 1,
|
|
95
|
-
1, 1, 1,
|
|
96
|
-
1, 1, -1,
|
|
97
|
-
-1, 1, -1,
|
|
98
|
-
-1, 1, 1,
|
|
99
|
-
1, 1, -1,
|
|
100
|
-
|
|
101
|
-
-1, -1, 1,
|
|
102
|
-
-1, 1, 1,
|
|
103
|
-
-1, 1, -1,
|
|
104
|
-
-1, -1, -1,
|
|
105
|
-
-1, -1, 1,
|
|
106
|
-
-1, 1, -1,
|
|
107
|
-
|
|
108
|
-
1, 1, 1,
|
|
109
|
-
-1, 1, 1,
|
|
110
|
-
-1, -1, 1,
|
|
111
|
-
-1, -1, 1,
|
|
112
|
-
1, -1, 1,
|
|
113
|
-
1, 1, 1,
|
|
114
|
-
|
|
115
|
-
1, -1, -1,
|
|
116
|
-
-1, -1, -1,
|
|
117
|
-
-1, 1, -1,
|
|
118
|
-
1, 1, -1,
|
|
119
|
-
1, -1, -1,
|
|
120
|
-
-1, 1, -1,
|
|
82
|
+
1, -1, 1,
|
|
83
|
+
-1, -1, 1,
|
|
84
|
+
-1, -1, -1,
|
|
85
|
+
1, -1, -1,
|
|
86
|
+
1, -1, 1,
|
|
87
|
+
-1, -1, -1,
|
|
88
|
+
|
|
89
|
+
1, 1, 1,
|
|
90
|
+
1, -1, 1,
|
|
91
|
+
1, -1, -1,
|
|
92
|
+
1, 1, -1,
|
|
93
|
+
1, 1, 1,
|
|
94
|
+
1, -1, -1,
|
|
95
|
+
|
|
96
|
+
-1, 1, 1,
|
|
97
|
+
1, 1, 1,
|
|
98
|
+
1, 1, -1,
|
|
99
|
+
-1, 1, -1,
|
|
100
|
+
-1, 1, 1,
|
|
101
|
+
1, 1, -1,
|
|
102
|
+
|
|
103
|
+
-1, -1, 1,
|
|
104
|
+
-1, 1, 1,
|
|
105
|
+
-1, 1, -1,
|
|
106
|
+
-1, -1, -1,
|
|
107
|
+
-1, -1, 1,
|
|
108
|
+
-1, 1, -1,
|
|
109
|
+
|
|
110
|
+
1, 1, 1,
|
|
111
|
+
-1, 1, 1,
|
|
112
|
+
-1, -1, 1,
|
|
113
|
+
-1, -1, 1,
|
|
114
|
+
1, -1, 1,
|
|
115
|
+
1, 1, 1,
|
|
116
|
+
|
|
117
|
+
1, -1, -1,
|
|
118
|
+
-1, -1, -1,
|
|
119
|
+
-1, 1, -1,
|
|
120
|
+
1, 1, -1,
|
|
121
|
+
1, -1, -1,
|
|
122
|
+
-1, 1, -1,
|
|
121
123
|
]);
|
|
122
124
|
|
|
123
125
|
// float2 uv,
|
|
@@ -219,7 +221,7 @@ const ATTRIBUTES = {
|
|
|
219
221
|
};
|
|
220
222
|
|
|
221
223
|
const NON_INDEXED_ATTRIBUTES = {
|
|
222
|
-
POSITION: {size:
|
|
224
|
+
POSITION: {size: 3, value: CUBE_NON_INDEXED_POSITIONS},
|
|
223
225
|
// NORMAL: {size: 3, value: CUBE_NON_INDEXED_NORMALS},
|
|
224
226
|
TEXCOORD_0: {size: 2, value: CUBE_NON_INDEXED_TEX_COORDS},
|
|
225
227
|
COLOR_0: {size: 3, value: CUBE_NON_INDEXED_COLORS}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {uid} from '@luma.gl/
|
|
1
|
+
import {uid} from '@luma.gl/core';
|
|
2
2
|
import {TruncatedConeGeometry} from './truncated-cone-geometry';
|
|
3
3
|
|
|
4
4
|
export type CylinderGeometryProps = {
|
|
5
5
|
id?: string;
|
|
6
6
|
radius?: number;
|
|
7
|
-
attributes
|
|
7
|
+
attributes?: any;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export class CylinderGeometry extends TruncatedConeGeometry {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {uid} from '@luma.gl/
|
|
1
|
+
import {uid} from '@luma.gl/core';
|
|
2
2
|
import {Vector3} from '@math.gl/core';
|
|
3
|
-
import Geometry from '../geometry/geometry';
|
|
3
|
+
import {Geometry} from '../geometry/geometry';
|
|
4
4
|
|
|
5
5
|
/* eslint-disable comma-spacing, max-statements, complexity */
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ export type IcoSphereGeometryProps = {
|
|
|
11
11
|
id?: string;
|
|
12
12
|
radius?: number;
|
|
13
13
|
iterations?: number;
|
|
14
|
-
attributes
|
|
14
|
+
attributes?: any
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export class IcoSphereGeometry extends Geometry {
|
|
@@ -21,6 +21,7 @@ export class IcoSphereGeometry extends Geometry {
|
|
|
21
21
|
super({
|
|
22
22
|
...props,
|
|
23
23
|
id,
|
|
24
|
+
topology: 'triangle-list',
|
|
24
25
|
indices,
|
|
25
26
|
attributes: {...attributes, ...props.attributes}
|
|
26
27
|
});
|
|
@@ -40,9 +41,9 @@ function tesselateIcosaHedron(props: IcoSphereGeometryProps) {
|
|
|
40
41
|
indices.push();
|
|
41
42
|
|
|
42
43
|
const getMiddlePoint = (() => {
|
|
43
|
-
const pointMemo = {};
|
|
44
|
+
const pointMemo: Record<string, number> = {};
|
|
44
45
|
|
|
45
|
-
return (i1, i2) => {
|
|
46
|
+
return (i1: number, i2: number) => {
|
|
46
47
|
i1 *= 3;
|
|
47
48
|
i2 *= 3;
|
|
48
49
|
const mini = i1 < i2 ? i1 : i2;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {uid} from '@luma.gl/
|
|
2
|
-
import Geometry from '../geometry/geometry';
|
|
1
|
+
import {uid} from '@luma.gl/core';
|
|
2
|
+
import {Geometry} from '../geometry/geometry';
|
|
3
3
|
import {unpackIndexedGeometry} from '../geometry/geometry-utils';
|
|
4
4
|
|
|
5
5
|
export type PlaneGeometryProps = {
|
|
6
6
|
id?: string;
|
|
7
7
|
radius?: number;
|
|
8
|
-
attributes
|
|
8
|
+
attributes?: any
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
// Primitives inspired by TDL http://code.google.com/p/webglsamples/,
|
|
@@ -19,6 +19,7 @@ export class PlaneGeometry extends Geometry {
|
|
|
19
19
|
super({
|
|
20
20
|
...props,
|
|
21
21
|
id,
|
|
22
|
+
topology: 'triangle-list',
|
|
22
23
|
indices,
|
|
23
24
|
attributes: {...attributes, ...props.attributes}
|
|
24
25
|
});
|
|
@@ -26,7 +27,7 @@ export class PlaneGeometry extends Geometry {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/* eslint-disable complexity, max-statements */
|
|
29
|
-
function tesselatePlane(props) {
|
|
30
|
+
function tesselatePlane(props: any) {
|
|
30
31
|
const {type = 'x,y', offset = 0, flipCull = false, unpack = false} = props;
|
|
31
32
|
|
|
32
33
|
const coords = type.split(',');
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {uid} from '@luma.gl/
|
|
2
|
-
import Geometry from '../geometry/geometry';
|
|
1
|
+
import {uid} from '@luma.gl/core';
|
|
2
|
+
import {Geometry} from '../geometry/geometry';
|
|
3
3
|
|
|
4
4
|
export type SphereGeometryProps = {
|
|
5
5
|
id?: string;
|
|
6
6
|
radius?: number;
|
|
7
7
|
nlat?: number;
|
|
8
8
|
nlong?: number;
|
|
9
|
-
attributes
|
|
9
|
+
attributes?: any
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// Primitives inspired by TDL http://code.google.com/p/webglsamples/,
|
|
@@ -19,6 +19,7 @@ export class SphereGeometry extends Geometry {
|
|
|
19
19
|
super({
|
|
20
20
|
...props,
|
|
21
21
|
id,
|
|
22
|
+
topology: 'triangle-list',
|
|
22
23
|
indices,
|
|
23
24
|
attributes: {...attributes, ...props.attributes}
|
|
24
25
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {uid} from '@luma.gl/
|
|
2
|
-
import Geometry from '../geometry/geometry';
|
|
3
|
-
import {GeometryTable} from '../geometry/geometry-table';
|
|
1
|
+
import {uid} from '@luma.gl/core';
|
|
2
|
+
import {Geometry} from '../geometry/geometry';
|
|
4
3
|
|
|
5
4
|
const INDEX_OFFSETS = {
|
|
6
5
|
x: [2, 0, 1],
|
|
@@ -24,22 +23,14 @@ export type TruncatedConeGeometryProps = {
|
|
|
24
23
|
* copyright 2011 Google Inc. new BSD License
|
|
25
24
|
* (http://www.opensource.org/licenses/bsd-license.php).
|
|
26
25
|
*/
|
|
27
|
-
export function makeTruncatedConeGeometry(props?: TruncatedConeGeometryProps): GeometryTable {
|
|
28
|
-
const {indices, attributes} = tesselateTruncatedCone(props);
|
|
29
|
-
return {
|
|
30
|
-
length: indices.length,
|
|
31
|
-
indices,
|
|
32
|
-
attributes
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
26
|
export class TruncatedConeGeometry extends Geometry {
|
|
37
|
-
constructor(props: TruncatedConeGeometryProps & {id?: string; attributes
|
|
27
|
+
constructor(props: TruncatedConeGeometryProps & {id?: string; attributes?: any} = {}) {
|
|
38
28
|
const {id = uid('truncated-code-geometry')} = props;
|
|
39
29
|
const {indices, attributes} = tesselateTruncatedCone(props);
|
|
40
30
|
super({
|
|
41
31
|
...props,
|
|
42
32
|
id,
|
|
33
|
+
topology: 'triangle-list',
|
|
43
34
|
indices,
|
|
44
35
|
attributes: {
|
|
45
36
|
POSITION: {size: 3, value: attributes.POSITION},
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// import type Geometry from './geometry';
|
|
1
|
+
// import type {Geometry} from './geometry';
|
|
2
2
|
|
|
3
|
-
export function unpackIndexedGeometry(geometry) {
|
|
3
|
+
export function unpackIndexedGeometry(geometry: any) {
|
|
4
4
|
const {indices, attributes} = geometry;
|
|
5
5
|
if (!indices) {
|
|
6
6
|
return geometry;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const vertexCount = indices.value.length;
|
|
10
|
-
const unpackedAttributes = {};
|
|
10
|
+
const unpackedAttributes: Record<string, any> = {};
|
|
11
11
|
|
|
12
12
|
for (const attributeName in attributes) {
|
|
13
13
|
const attribute = attributes[attributeName];
|
|
@@ -29,3 +29,19 @@ export function unpackIndexedGeometry(geometry) {
|
|
|
29
29
|
attributes: Object.assign({}, attributes, unpackedAttributes)
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
// export function calculateVertexNormals(positions: Float32Array): Uint8Array {
|
|
34
|
+
// let normals = new Uint8Array(positions.length / 3);
|
|
35
|
+
|
|
36
|
+
// for (let i = 0; i < positions.length; i++) {
|
|
37
|
+
// const vec1 = new Vector3(positions.subarray(i * 3, i + 0, i + 3));
|
|
38
|
+
// const vec2 = new Vector3(positions.subarray(i + 3, i + 6));
|
|
39
|
+
// const vec3 = new Vector3(positions.subarray(i + 6, i + 9));
|
|
40
|
+
|
|
41
|
+
// const normal = new Vector3(vec1).cross(vec2).normalize();
|
|
42
|
+
// normals.set(normal[0], i + 4);
|
|
43
|
+
// normals.set(normal[1], i + 4 + 1);
|
|
44
|
+
// normals.set(normal[2], i + 2);
|
|
45
|
+
// }
|
|
46
|
+
// const normal = new Vector3(vec1).cross(vec2).normalize();
|
|
47
|
+
// }
|