@luma.gl/engine 9.0.0-alpha.3 → 9.0.0-alpha.31
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 +2 -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 +0 -20
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +5 -5
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +0 -30
- package/dist/animation/timeline.js.map +1 -1
- package/dist/{lib → animation-loop}/animation-loop.d.ts +28 -29
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +96 -175
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +7 -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 +14977 -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 +9 -18
- 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 +10 -19
- 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 -2
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +9 -14
- 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 +35 -58
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +26 -89
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/primitive-utils.js.map +1 -1
- package/dist/index.cjs +2576 -0
- package/dist/index.d.ts +18 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -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 +36 -1
- package/dist/lib/clip-space.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +19 -14
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +52 -63
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/{lib → model}/model-utils.d.ts +2 -2
- package/dist/model/model-utils.d.ts.map +1 -0
- package/dist/{lib → model}/model-utils.js +3 -8
- package/dist/model/model-utils.js.map +1 -0
- package/dist/model/model.d.ts +67 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/{lib → model}/model.js +59 -76
- 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 +95 -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 +29 -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 +142 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/transform/transform.d.ts +98 -0
- package/dist/transform/transform.d.ts.map +1 -0
- package/dist/transform/transform.js +67 -0
- package/dist/transform/transform.js.map +1 -0
- package/dist.min.js +314 -0
- package/package.json +22 -12
- package/src/animation/timeline.ts +2 -2
- package/src/{lib → animation-loop}/animation-loop.ts +115 -97
- package/src/{lib → animation-loop}/animation-props.ts +6 -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 -3
- package/src/geometry/geometry-table.ts +1 -1
- package/src/geometry/geometry-utils.ts +3 -3
- package/src/geometry/geometry.ts +72 -115
- package/src/index.ts +28 -12
- package/src/lib/clip-space.ts +17 -15
- package/src/lib/pipeline-factory.ts +60 -50
- package/src/{lib → model}/model-utils.ts +5 -4
- package/src/model/model.ts +230 -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/transform/transform.ts +246 -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/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.map +0 -1
- 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.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/lib/model.ts +0 -179
- package/src/lib/render-loop.ts +0 -58
- /package/dist/{lib → animation-loop}/animation-props.js +0 -0
|
@@ -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,5 +1,5 @@
|
|
|
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 {GeometryTable} from '../geometry/geometry-table';
|
|
4
4
|
|
|
5
5
|
const INDEX_OFFSETS = {
|
|
@@ -34,12 +34,13 @@ export function makeTruncatedConeGeometry(props?: TruncatedConeGeometryProps): G
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export class TruncatedConeGeometry extends Geometry {
|
|
37
|
-
constructor(props: TruncatedConeGeometryProps & {id?: string; attributes
|
|
37
|
+
constructor(props: TruncatedConeGeometryProps & {id?: string; attributes?: any} = {}) {
|
|
38
38
|
const {id = uid('truncated-code-geometry')} = props;
|
|
39
39
|
const {indices, attributes} = tesselateTruncatedCone(props);
|
|
40
40
|
super({
|
|
41
41
|
...props,
|
|
42
42
|
id,
|
|
43
|
+
topology: 'triangle-list',
|
|
43
44
|
indices,
|
|
44
45
|
attributes: {
|
|
45
46
|
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,112 +1,60 @@
|
|
|
1
1
|
// luma.gl, MIT license
|
|
2
|
-
import type {TypedArray} from '@luma.gl/
|
|
3
|
-
import {uid, assert} from '@luma.gl/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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';
|
|
4
|
+
|
|
5
|
+
export type GeometryAttribute = {
|
|
6
|
+
size?: number;
|
|
7
|
+
value: TypedArray;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
18
10
|
|
|
19
11
|
export type GeometryProps = {
|
|
20
12
|
id?: string;
|
|
21
|
-
attributes?: {},
|
|
22
|
-
indices?;
|
|
23
|
-
vertexCount?: number;
|
|
24
13
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
25
|
-
topology
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
topology:
|
|
15
|
+
| 'point-list'
|
|
16
|
+
| 'line-list'
|
|
17
|
+
| 'line-strip'
|
|
18
|
+
| 'line-loop-webgl'
|
|
19
|
+
| 'triangle-list'
|
|
20
|
+
| 'triangle-strip'
|
|
21
|
+
| 'triangle-fan-webgl';
|
|
22
|
+
/** Auto calculated from attributes if not provided */
|
|
23
|
+
vertexCount?: number;
|
|
24
|
+
attributes?: Record<string, GeometryAttribute | TypedArray>;
|
|
25
|
+
indices?: GeometryAttribute | TypedArray;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
type GeometryAttributes = {
|
|
31
|
-
POSITION:
|
|
32
|
-
NORMAL:
|
|
33
|
-
TEXCOORD_0:
|
|
34
|
-
COLOR_0?:
|
|
35
|
-
indices?: {size?: number
|
|
29
|
+
POSITION: GeometryAttribute;
|
|
30
|
+
NORMAL: GeometryAttribute;
|
|
31
|
+
TEXCOORD_0: GeometryAttribute;
|
|
32
|
+
COLOR_0?: GeometryAttribute;
|
|
33
|
+
indices?: {size?: number; value: Uint32Array | Uint16Array};
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
export
|
|
39
|
-
/** @deprecated */
|
|
40
|
-
static DRAW_MODE = {
|
|
41
|
-
POINTS: GL.POINTS, // draw single points.
|
|
42
|
-
LINES: GL.LINES, // draw lines. Each vertex connects to the one after it.
|
|
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
|
-
};
|
|
49
|
-
|
|
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?: Uint16Array | Uint32Array;
|
|
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
49
|
|
|
67
|
-
|
|
68
|
-
const {
|
|
69
|
-
id = uid('geometry'),
|
|
70
|
-
drawMode = GL.TRIANGLES,
|
|
71
|
-
attributes = {},
|
|
72
|
-
indices = null,
|
|
73
|
-
vertexCount = null
|
|
74
|
-
} = props;
|
|
50
|
+
userData: Record<string, unknown> = {};
|
|
75
51
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.topology = props.topology || convertToTopology(drawMode);
|
|
52
|
+
constructor(props: GeometryProps) {
|
|
53
|
+
const {attributes = {}, indices = null, vertexCount = null} = props;
|
|
79
54
|
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get mode() {
|
|
86
|
-
return this.drawMode;
|
|
87
|
-
}
|
|
55
|
+
this.id = props.id || uid('geometry');
|
|
56
|
+
this.topology = props.topology;
|
|
88
57
|
|
|
89
|
-
getVertexCount(): number {
|
|
90
|
-
return this.vertexCount;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Return an object with all attributes plus indices added as a field.
|
|
94
|
-
// getAttributes(): GeometryAttributes {
|
|
95
|
-
// return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
|
|
96
|
-
// }
|
|
97
|
-
|
|
98
|
-
// PRIVATE
|
|
99
|
-
|
|
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
59
|
// @ts-expect-error
|
|
112
60
|
this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
|
|
@@ -115,11 +63,11 @@ export default class Geometry {
|
|
|
115
63
|
// @ts-expect-error
|
|
116
64
|
this.attributes = {};
|
|
117
65
|
|
|
118
|
-
for (const attributeName
|
|
119
|
-
let attribute = attributes[attributeName];
|
|
120
|
-
|
|
66
|
+
for (const [attributeName, attributeValue] of Object.entries(attributes)) {
|
|
121
67
|
// Wrap "unwrapped" arrays and try to autodetect their type
|
|
122
|
-
attribute = ArrayBuffer.isView(
|
|
68
|
+
const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
|
|
69
|
+
? {value: attributeValue}
|
|
70
|
+
: attributeValue;
|
|
123
71
|
|
|
124
72
|
assert(
|
|
125
73
|
ArrayBuffer.isView(attribute.value),
|
|
@@ -133,25 +81,49 @@ export default class Geometry {
|
|
|
133
81
|
// Move indices to separate field
|
|
134
82
|
if (attributeName === 'indices') {
|
|
135
83
|
assert(!this.indices);
|
|
136
|
-
|
|
137
|
-
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
this.indices = attribute;
|
|
138
86
|
} else {
|
|
139
87
|
this.attributes[attributeName] = attribute;
|
|
140
88
|
}
|
|
141
89
|
}
|
|
142
90
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// @ts-expect-error
|
|
91
|
+
// @ts-expect-error
|
|
92
|
+
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
146
93
|
this.indices = Object.assign({}, this.indices);
|
|
147
94
|
// @ts-expect-error
|
|
148
95
|
delete this.indices.isIndexed;
|
|
149
96
|
}
|
|
150
97
|
|
|
98
|
+
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getVertexCount(): number {
|
|
102
|
+
return this.vertexCount;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Return an object with all attributes plus indices added as a field.
|
|
106
|
+
getAttributes(): GeometryAttributes {
|
|
107
|
+
// @ts-expect-error Geometry types are a mess
|
|
108
|
+
return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// PRIVATE
|
|
112
|
+
|
|
113
|
+
_print(attributeName: string): string {
|
|
114
|
+
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// GeometryAttribute
|
|
118
|
+
// value: typed array
|
|
119
|
+
// type: indices, vertices, uvs
|
|
120
|
+
// size: elements per vertex
|
|
121
|
+
// target: WebGL buffer type (string or constant)
|
|
122
|
+
_setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
|
|
151
123
|
return this;
|
|
152
124
|
}
|
|
153
125
|
|
|
154
|
-
_calculateVertexCount(attributes, indices): number {
|
|
126
|
+
_calculateVertexCount(attributes: any, indices: any): number {
|
|
155
127
|
if (indices) {
|
|
156
128
|
return indices.value.length;
|
|
157
129
|
}
|
|
@@ -168,18 +140,3 @@ export default class Geometry {
|
|
|
168
140
|
return vertexCount;
|
|
169
141
|
}
|
|
170
142
|
}
|
|
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
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
// luma.gl Engine API
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
// Animation
|
|
4
|
+
export {Timeline} from './animation/timeline';
|
|
5
|
+
export {KeyFrames} from './animation/key-frames';
|
|
6
|
+
export type {AnimationProps} from './animation-loop/animation-props';
|
|
7
|
+
|
|
8
|
+
export {AnimationLoopTemplate} from './animation-loop/render-loop';
|
|
9
|
+
|
|
10
|
+
export type {AnimationLoopProps} from './animation-loop/animation-loop';
|
|
11
|
+
export {AnimationLoop} from './animation-loop/animation-loop';
|
|
12
|
+
|
|
13
|
+
export type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';
|
|
14
|
+
export {makeAnimationLoop} from './animation-loop/make-animation-loop';
|
|
15
|
+
|
|
16
|
+
export type {ModelProps} from './model/model';
|
|
17
|
+
export {Model} from './model/model';
|
|
18
|
+
|
|
19
|
+
export {Transform} from './transform/transform';
|
|
20
|
+
|
|
21
|
+
export {PipelineFactory} from './lib/pipeline-factory';
|
|
8
22
|
|
|
9
23
|
// Utils
|
|
10
|
-
|
|
24
|
+
export {ClipSpace} from './lib/clip-space';
|
|
25
|
+
|
|
26
|
+
// Scenegraph Core nodes
|
|
27
|
+
export {ScenegraphNode} from './scenegraph/scenegraph-node';
|
|
28
|
+
export {GroupNode} from './scenegraph/group-node';
|
|
29
|
+
export {ModelNode} from './scenegraph/model-node';
|
|
11
30
|
|
|
12
31
|
// Geometries
|
|
13
|
-
export {
|
|
32
|
+
export type {GeometryProps} from './geometry/geometry';
|
|
33
|
+
export {Geometry} from './geometry/geometry';
|
|
14
34
|
|
|
15
35
|
// Primitives
|
|
16
36
|
export type {ConeGeometryProps} from './geometries/cone-geometry';
|
|
@@ -28,7 +48,3 @@ export {SphereGeometry} from './geometries/sphere-geometry';
|
|
|
28
48
|
export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';
|
|
29
49
|
export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
|
|
30
50
|
|
|
31
|
-
// Animation
|
|
32
|
-
export {Timeline} from './animation/timeline';
|
|
33
|
-
export {KeyFrames} from './animation/key-frames';
|
|
34
|
-
|
package/src/lib/clip-space.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
// ClipSpace
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import Model,
|
|
6
|
-
import Geometry from '../geometry/geometry';
|
|
3
|
+
import {Device, glsl} from '@luma.gl/core';
|
|
4
|
+
import {WebGLDevice} from '@luma.gl/webgl';
|
|
5
|
+
import {Model, ModelProps} from '../model/model';
|
|
6
|
+
import {Geometry} from '../geometry/geometry';
|
|
7
7
|
|
|
8
|
-
const CLIPSPACE_VERTEX_SHADER = `\
|
|
8
|
+
const CLIPSPACE_VERTEX_SHADER = glsl`\
|
|
9
9
|
attribute vec2 aClipSpacePosition;
|
|
10
10
|
attribute vec2 aTexCoord;
|
|
11
11
|
attribute vec2 aCoordinate;
|
|
@@ -22,20 +22,24 @@ void main(void) {
|
|
|
22
22
|
}
|
|
23
23
|
`;
|
|
24
24
|
|
|
25
|
-
/* eslint-disable indent, no-multi-spaces
|
|
25
|
+
/* eslint-disable indent, no-multi-spaces */
|
|
26
26
|
const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
/**
|
|
29
|
+
* A flat geometry that covers the "visible area" that the GPU renders.
|
|
30
|
+
*/
|
|
31
|
+
export class ClipSpace extends Model {
|
|
32
|
+
constructor(device: Device | WebGLRenderingContext, opts?: ModelProps) {
|
|
31
33
|
const TEX_COORDS = POSITIONS.map((coord) => (coord === -1 ? 0 : coord));
|
|
32
34
|
|
|
33
35
|
super(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
WebGLDevice.attach(device),
|
|
37
|
+
{
|
|
38
|
+
...opts,
|
|
36
39
|
vs: CLIPSPACE_VERTEX_SHADER,
|
|
40
|
+
vertexCount: 4,
|
|
37
41
|
geometry: new Geometry({
|
|
38
|
-
|
|
42
|
+
topology: 'triangle-strip',
|
|
39
43
|
vertexCount: 4,
|
|
40
44
|
attributes: {
|
|
41
45
|
aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},
|
|
@@ -43,9 +47,7 @@ export default class ClipSpace extends Model {
|
|
|
43
47
|
aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)}
|
|
44
48
|
}
|
|
45
49
|
})
|
|
46
|
-
}
|
|
50
|
+
}
|
|
47
51
|
);
|
|
48
|
-
this.setVertexCount(4);
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
|
-
*/
|