@luma.gl/engine 9.0.0-alpha.5 → 9.0.0-alpha.51
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 +9 -9
- 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/{lib → animation-loop}/animation-loop.d.ts +30 -31
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +115 -199
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +6 -7
- 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/animation-loop/render-loop.d.ts +23 -0
- package/dist/animation-loop/render-loop.d.ts.map +1 -0
- package/dist/animation-loop/render-loop.js +7 -0
- package/dist/animation-loop/render-loop.js.map +1 -0
- package/dist/dist.dev.js +7064 -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 +15 -8
- 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 +50 -59
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +32 -97
- 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 +107 -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 +2959 -0
- package/dist/index.d.ts +26 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -13
- 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 -40
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +50 -148
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/model/model.d.ts +192 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +312 -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 +62 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +49 -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 +286 -0
- package/package.json +21 -12
- package/src/animation/timeline.ts +16 -15
- package/src/{lib → animation-loop}/animation-loop.ts +120 -107
- package/src/{lib → animation-loop}/animation-props.ts +5 -5
- package/src/animation-loop/make-animation-loop.ts +44 -0
- package/src/animation-loop/render-loop.ts +23 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +6 -3
- package/src/geometries/cylinder-geometry.ts +2 -2
- package/src/geometries/ico-sphere-geometry.ts +7 -6
- 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 +3 -3
- package/src/geometry/geometry.ts +79 -119
- package/src/geometry/gpu-geometry.ts +124 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +38 -12
- package/src/lib/clip-space.ts +22 -21
- package/src/lib/pipeline-factory.ts +60 -168
- package/src/model/model.ts +549 -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 +132 -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 -176
- 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 -179
- package/src/lib/render-loop.ts +0 -58
- /package/dist/{lib → animation-loop}/animation-props.js +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {AnimationProps} from './animation-props';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal class that represents a "componentized" rendering life cycle
|
|
5
|
+
* (resource construction, repeated rendering, resource destruction)
|
|
6
|
+
*
|
|
7
|
+
* @note A motivation for this class compared to the raw animation loop is
|
|
8
|
+
* that it simplifies TypeScript code by allowing resources to be typed unconditionally
|
|
9
|
+
* since they are allocated in the constructor rather than in onInitialized
|
|
10
|
+
*
|
|
11
|
+
* @note Introduced in luma.gl v9
|
|
12
|
+
*
|
|
13
|
+
* @example AnimationLoopTemplate is intended to be subclassed,
|
|
14
|
+
* but the subclass should not be instantiated directly. Instead the subclass
|
|
15
|
+
* (i.e. the constructor of the subclass) should be used
|
|
16
|
+
* as an argument to create an AnimationLoop.
|
|
17
|
+
*/
|
|
18
|
+
export abstract class AnimationLoopTemplate {
|
|
19
|
+
constructor(animationProps?: AnimationProps) {}
|
|
20
|
+
async onInitialize(animationProps: AnimationProps): Promise<unknown> { return null; }
|
|
21
|
+
abstract onRender(animationProps: AnimationProps): unknown;
|
|
22
|
+
abstract onFinalize(animationProps: AnimationProps): void;
|
|
23
|
+
}
|
|
@@ -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,14 @@ 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',
|
|
24
|
+
indices: undefined,
|
|
22
25
|
attributes: {...NON_INDEXED_ATTRIBUTES, ...props.attributes}
|
|
23
26
|
});
|
|
24
27
|
}
|
|
@@ -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;
|
|
@@ -75,7 +76,7 @@ function tesselateIcosaHedron(props: IcoSphereGeometryProps) {
|
|
|
75
76
|
})();
|
|
76
77
|
|
|
77
78
|
for (let i = 0; i < iterations; i++) {
|
|
78
|
-
const indices2 = [];
|
|
79
|
+
const indices2: number[] = [];
|
|
79
80
|
for (let j = 0; j < indices.length; j += 3) {
|
|
80
81
|
const a = getMiddlePoint(indices[j + 0], indices[j + 1]);
|
|
81
82
|
const b = getMiddlePoint(indices[j + 1], indices[j + 2]);
|
|
@@ -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];
|
package/src/geometry/geometry.ts
CHANGED
|
@@ -1,125 +1,72 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
|
-
import type {TypedArray} from '@luma.gl/
|
|
3
|
-
import {uid, assert} from '@luma.gl/
|
|
4
|
-
import GL from '@luma.gl/constants';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Rendering primitives - "topology" specifies how to extract primitives from vertices.
|
|
8
|
-
*/
|
|
9
|
-
export type Topology =
|
|
10
|
-
GL.POINTS | // draw single points.
|
|
11
|
-
GL.LINES | // draw lines. Each vertex connects to the one after it.
|
|
12
|
-
GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.
|
|
13
|
-
GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last
|
|
14
|
-
GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.
|
|
15
|
-
GL.TRIANGLE_STRIP | // draw a connected group of triangles.
|
|
16
|
-
GL.TRIANGLE_FAN // draw a connected group of triangles.
|
|
17
|
-
;
|
|
2
|
+
import type {PrimitiveTopology, TypedArray} from '@luma.gl/core';
|
|
3
|
+
import {uid, assert} from '@luma.gl/core';
|
|
18
4
|
|
|
19
5
|
export type GeometryProps = {
|
|
20
6
|
id?: string;
|
|
21
|
-
attributes?: {},
|
|
22
|
-
indices?;
|
|
23
|
-
vertexCount?: number;
|
|
24
7
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
25
|
-
topology
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
topology:
|
|
9
|
+
| 'point-list'
|
|
10
|
+
| 'line-list'
|
|
11
|
+
| 'line-strip'
|
|
12
|
+
| 'line-loop-webgl'
|
|
13
|
+
| 'triangle-list'
|
|
14
|
+
| 'triangle-strip'
|
|
15
|
+
| 'triangle-fan-webgl';
|
|
16
|
+
/** Auto calculated from attributes if not provided */
|
|
17
|
+
vertexCount?: number;
|
|
18
|
+
attributes?: Record<string, GeometryAttribute | TypedArray>;
|
|
19
|
+
indices?: GeometryAttribute | TypedArray;
|
|
28
20
|
};
|
|
29
21
|
|
|
30
|
-
type GeometryAttributes = {
|
|
31
|
-
POSITION:
|
|
32
|
-
NORMAL:
|
|
33
|
-
TEXCOORD_0:
|
|
34
|
-
COLOR_0?:
|
|
35
|
-
indices?: {size
|
|
22
|
+
export type GeometryAttributes = {
|
|
23
|
+
POSITION: GeometryAttribute;
|
|
24
|
+
NORMAL: GeometryAttribute;
|
|
25
|
+
TEXCOORD_0: GeometryAttribute;
|
|
26
|
+
COLOR_0?: GeometryAttribute;
|
|
27
|
+
indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};
|
|
36
28
|
};
|
|
37
29
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.
|
|
44
|
-
LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last
|
|
45
|
-
TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.
|
|
46
|
-
TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.
|
|
47
|
-
TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.
|
|
48
|
-
};
|
|
30
|
+
export type GeometryAttribute = {
|
|
31
|
+
size?: number;
|
|
32
|
+
value: TypedArray;
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
};
|
|
49
35
|
|
|
36
|
+
export class Geometry {
|
|
50
37
|
readonly id: string;
|
|
51
|
-
userData: Record<string, any> = {};
|
|
52
|
-
|
|
53
38
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
54
|
-
topology?:
|
|
55
|
-
/** @deprecated */
|
|
56
|
-
readonly drawMode: Topology = GL.TRIANGLES;
|
|
57
|
-
|
|
39
|
+
readonly topology?: PrimitiveTopology;
|
|
58
40
|
readonly vertexCount: number;
|
|
41
|
+
readonly indices?: GeometryAttribute;
|
|
59
42
|
readonly attributes: {
|
|
60
|
-
POSITION:
|
|
61
|
-
NORMAL:
|
|
62
|
-
TEXCOORD_0:
|
|
63
|
-
COLOR_0?:
|
|
43
|
+
POSITION: GeometryAttribute;
|
|
44
|
+
NORMAL: GeometryAttribute;
|
|
45
|
+
TEXCOORD_0: GeometryAttribute;
|
|
46
|
+
COLOR_0?: GeometryAttribute;
|
|
47
|
+
[key: string]: GeometryAttribute | undefined;
|
|
64
48
|
};
|
|
65
|
-
readonly indices?: Uint16Array | Uint32Array;
|
|
66
|
-
|
|
67
|
-
constructor(props: GeometryProps = {}) {
|
|
68
|
-
const {
|
|
69
|
-
id = uid('geometry'),
|
|
70
|
-
drawMode = GL.TRIANGLES,
|
|
71
|
-
attributes = {},
|
|
72
|
-
indices = null,
|
|
73
|
-
vertexCount = null
|
|
74
|
-
} = props;
|
|
75
|
-
|
|
76
|
-
this.id = id;
|
|
77
|
-
this.drawMode = drawMode;
|
|
78
|
-
this.topology = props.topology || convertToTopology(drawMode);
|
|
79
|
-
|
|
80
|
-
this._setAttributes(attributes, indices);
|
|
81
|
-
|
|
82
|
-
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
83
|
-
}
|
|
84
49
|
|
|
85
|
-
|
|
86
|
-
return this.drawMode;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getVertexCount(): number {
|
|
90
|
-
return this.vertexCount;
|
|
91
|
-
}
|
|
50
|
+
userData: Record<string, unknown> = {};
|
|
92
51
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
|
|
96
|
-
// }
|
|
52
|
+
constructor(props: GeometryProps) {
|
|
53
|
+
const {attributes = {}, indices = null, vertexCount = null} = props;
|
|
97
54
|
|
|
98
|
-
|
|
55
|
+
this.id = props.id || uid('geometry');
|
|
56
|
+
this.topology = props.topology;
|
|
99
57
|
|
|
100
|
-
_print(attributeName): string {
|
|
101
|
-
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Attribute
|
|
105
|
-
// value: typed array
|
|
106
|
-
// type: indices, vertices, uvs
|
|
107
|
-
// size: elements per vertex
|
|
108
|
-
// target: WebGL buffer type (string or constant)
|
|
109
|
-
_setAttributes(attributes, indices): this {
|
|
110
58
|
if (indices) {
|
|
111
|
-
// @ts-expect-error
|
|
112
59
|
this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
|
|
113
60
|
}
|
|
114
61
|
|
|
115
62
|
// @ts-expect-error
|
|
116
63
|
this.attributes = {};
|
|
117
64
|
|
|
118
|
-
for (const attributeName
|
|
119
|
-
let attribute = attributes[attributeName];
|
|
120
|
-
|
|
65
|
+
for (const [attributeName, attributeValue] of Object.entries(attributes)) {
|
|
121
66
|
// Wrap "unwrapped" arrays and try to autodetect their type
|
|
122
|
-
attribute = ArrayBuffer.isView(
|
|
67
|
+
const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
|
|
68
|
+
? {value: attributeValue}
|
|
69
|
+
: attributeValue;
|
|
123
70
|
|
|
124
71
|
assert(
|
|
125
72
|
ArrayBuffer.isView(attribute.value),
|
|
@@ -133,31 +80,59 @@ export default class Geometry {
|
|
|
133
80
|
// Move indices to separate field
|
|
134
81
|
if (attributeName === 'indices') {
|
|
135
82
|
assert(!this.indices);
|
|
136
|
-
|
|
137
|
-
this.indices = attribute;
|
|
83
|
+
this.indices = attribute;
|
|
138
84
|
} else {
|
|
139
85
|
this.attributes[attributeName] = attribute;
|
|
140
86
|
}
|
|
141
87
|
}
|
|
142
88
|
|
|
143
|
-
|
|
144
|
-
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
145
|
-
// @ts-expect-error
|
|
89
|
+
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
146
90
|
this.indices = Object.assign({}, this.indices);
|
|
147
|
-
// @ts-expect-error
|
|
148
91
|
delete this.indices.isIndexed;
|
|
149
92
|
}
|
|
150
93
|
|
|
94
|
+
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getVertexCount(): number {
|
|
98
|
+
return this.vertexCount;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Return an object with all attributes plus indices added as a field.
|
|
103
|
+
* TODO Geometry types are a mess
|
|
104
|
+
*/
|
|
105
|
+
getAttributes(): GeometryAttributes {
|
|
106
|
+
return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// PRIVATE
|
|
110
|
+
|
|
111
|
+
_print(attributeName: string): string {
|
|
112
|
+
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* GeometryAttribute
|
|
117
|
+
* value: typed array
|
|
118
|
+
* type: indices, vertices, uvs
|
|
119
|
+
* size: elements per vertex
|
|
120
|
+
* target: WebGL buffer type (string or constant)
|
|
121
|
+
*
|
|
122
|
+
* @param attributes
|
|
123
|
+
* @param indices
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
_setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
|
|
151
127
|
return this;
|
|
152
128
|
}
|
|
153
129
|
|
|
154
|
-
_calculateVertexCount(attributes, indices): number {
|
|
130
|
+
_calculateVertexCount(attributes: GeometryAttributes, indices: GeometryAttribute): number {
|
|
155
131
|
if (indices) {
|
|
156
132
|
return indices.value.length;
|
|
157
133
|
}
|
|
158
134
|
let vertexCount = Infinity;
|
|
159
|
-
for (const
|
|
160
|
-
const attribute = attributes[attributeName];
|
|
135
|
+
for (const attribute of Object.values(attributes)) {
|
|
161
136
|
const {value, size, constant} = attribute;
|
|
162
137
|
if (!constant && value && size >= 1) {
|
|
163
138
|
vertexCount = Math.min(vertexCount, value.length / size);
|
|
@@ -168,18 +143,3 @@ export default class Geometry {
|
|
|
168
143
|
return vertexCount;
|
|
169
144
|
}
|
|
170
145
|
}
|
|
171
|
-
|
|
172
|
-
function convertToTopology(drawMode: GL): 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip' {
|
|
173
|
-
switch (drawMode) {
|
|
174
|
-
case GL.POINTS: return 'point-list'; // draw single points.
|
|
175
|
-
case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.
|
|
176
|
-
case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last
|
|
177
|
-
case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.
|
|
178
|
-
case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.
|
|
179
|
-
|
|
180
|
-
case GL.TRIANGLE_FAN: // draw a connected group of triangles.
|
|
181
|
-
case GL.LINE_LOOP: // draw lines. Each set of two vertices is treated as a separate line segment.
|
|
182
|
-
default:
|
|
183
|
-
throw new Error(String(drawMode));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';
|
|
2
|
+
import {Device, Buffer, uid, assert, getVertexFormatFromAttribute} from '@luma.gl/core';
|
|
3
|
+
import type {Geometry} from '../geometry/geometry';
|
|
4
|
+
|
|
5
|
+
export type GPUGeometryProps = {
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Determines how vertices are read from the 'vertex' attributes */
|
|
8
|
+
topology:
|
|
9
|
+
| 'point-list'
|
|
10
|
+
| 'line-list'
|
|
11
|
+
| 'line-strip'
|
|
12
|
+
| 'line-loop-webgl'
|
|
13
|
+
| 'triangle-list'
|
|
14
|
+
| 'triangle-strip'
|
|
15
|
+
| 'triangle-fan-webgl';
|
|
16
|
+
/** Auto calculated from attributes if not provided */
|
|
17
|
+
vertexCount: number;
|
|
18
|
+
bufferLayout: BufferLayout[];
|
|
19
|
+
indices?: Buffer | null;
|
|
20
|
+
attributes: Record<string, Buffer>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class GPUGeometry {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
userData: Record<string, unknown> = {};
|
|
26
|
+
|
|
27
|
+
/** Determines how vertices are read from the 'vertex' attributes */
|
|
28
|
+
readonly topology?: PrimitiveTopology;
|
|
29
|
+
readonly bufferLayout: BufferLayout[] = [];
|
|
30
|
+
|
|
31
|
+
readonly vertexCount: number;
|
|
32
|
+
readonly indices?: Buffer | null;
|
|
33
|
+
readonly attributes: Record<string, Buffer>;
|
|
34
|
+
|
|
35
|
+
constructor(props: GPUGeometryProps) {
|
|
36
|
+
this.id = props.id || uid('geometry');
|
|
37
|
+
this.topology = props.topology;
|
|
38
|
+
this.indices = props.indices || null;
|
|
39
|
+
this.attributes = props.attributes;
|
|
40
|
+
|
|
41
|
+
this.vertexCount = props.vertexCount;
|
|
42
|
+
|
|
43
|
+
this.bufferLayout = props.bufferLayout || [];
|
|
44
|
+
|
|
45
|
+
if (this.indices) {
|
|
46
|
+
assert(this.indices.usage === Buffer.INDEX);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
destroy(): void {
|
|
51
|
+
this.indices.destroy();
|
|
52
|
+
this.attributes.positions.destroy();
|
|
53
|
+
this.attributes.normals.destroy();
|
|
54
|
+
this.attributes.texCoords.destroy();
|
|
55
|
+
this.attributes.colors?.destroy();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getVertexCount(): number {
|
|
59
|
+
return this.vertexCount;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getAttributes(): Record<string, Buffer> {
|
|
63
|
+
return this.attributes;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getIndexes(): Buffer | null {
|
|
67
|
+
return this.indices;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_calculateVertexCount(positions: Buffer): number {
|
|
71
|
+
// Assume that positions is a fully packed float32x3 buffer
|
|
72
|
+
const vertexCount = positions.byteLength / 12;
|
|
73
|
+
return vertexCount;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry {
|
|
78
|
+
if (geometry instanceof GPUGeometry) {
|
|
79
|
+
return geometry;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const indices = getIndexBufferFromGeometry(device, geometry);
|
|
83
|
+
const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, geometry);
|
|
84
|
+
return new GPUGeometry({
|
|
85
|
+
topology: geometry.topology || 'triangle-list',
|
|
86
|
+
bufferLayout,
|
|
87
|
+
vertexCount: geometry.vertexCount,
|
|
88
|
+
indices,
|
|
89
|
+
attributes
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {
|
|
94
|
+
if (!geometry.indices) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
const data = geometry.indices.value;
|
|
98
|
+
return device.createBuffer({usage: Buffer.INDEX, data});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function getAttributeBuffersFromGeometry(
|
|
102
|
+
device: Device,
|
|
103
|
+
geometry: Geometry
|
|
104
|
+
): {attributes: Record<string, Buffer>, bufferLayout: BufferLayout[], vertexCount: number} {
|
|
105
|
+
const bufferLayout: BufferLayout[] = [];
|
|
106
|
+
|
|
107
|
+
const attributes: Record<string, Buffer> = {};
|
|
108
|
+
for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
|
|
109
|
+
let name: string = attributeName;
|
|
110
|
+
// TODO Map some GLTF attribute names (is this still needed?)
|
|
111
|
+
switch (attributeName) {
|
|
112
|
+
case 'POSITION': name = 'positions'; break;
|
|
113
|
+
case 'NORMAL': name = 'normals'; break;
|
|
114
|
+
case 'TEXCOORD_0': name = 'texCoords'; break;
|
|
115
|
+
}
|
|
116
|
+
attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});
|
|
117
|
+
const {value, size, normalized} = attribute;
|
|
118
|
+
bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)
|
|
122
|
+
|
|
123
|
+
return {attributes, bufferLayout, vertexCount};
|
|
124
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
export function getAttributeLayoutsFromGeometry(geometry: Geometry) {
|
|
3
|
+
const layouts: Record<string, {}> = {};
|
|
4
|
+
let indices = geometry.indices;
|
|
5
|
+
|
|
6
|
+
for (const [name, attribute] of Object.entries(geometry.attributes)) {
|
|
7
|
+
const remappedName = mapAttributeName(name);
|
|
8
|
+
|
|
9
|
+
if (attribute.constant) {
|
|
10
|
+
throw new Error('constant attributes not supported');
|
|
11
|
+
} else {
|
|
12
|
+
const typedArray = attribute.value;
|
|
13
|
+
// Create accessor by copying the attribute and removing `value``
|
|
14
|
+
const accessor = {...attribute};
|
|
15
|
+
delete accessor.value;
|
|
16
|
+
buffers[remappedName] = [device.createBuffer(typedArray), accessor];
|
|
17
|
+
|
|
18
|
+
inferAttributeAccessor(name, accessor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Table {
|
|
24
|
+
length: number;
|
|
25
|
+
// columns: Record<string, TypedArray> = {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class GPUTable {
|
|
29
|
+
length: number;
|
|
30
|
+
columns: Record<string, Buffer> = {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function convertTableToGPUTable(table: Table) {
|
|
34
|
+
// for (const ) {}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function renameTableColumns(table: Table, map: (name: string) => string) {
|
|
38
|
+
const newColumns = table.columns.reduce()
|
|
39
|
+
table.clone();
|
|
40
|
+
}
|
|
41
|
+
*/
|