@luma.gl/engine 9.0.0-alpha.9 → 9.0.0-beta.10
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 +51 -72
- package/dist/animation/timeline.d.ts +8 -8
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +95 -131
- 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 +21 -0
- package/dist/{lib → animation-loop}/animation-loop.d.ts +31 -23
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop.js +442 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +4 -5
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/animation-loop/animation-props.js +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 +32 -0
- package/dist/computation.d.ts +95 -0
- package/dist/computation.d.ts.map +1 -0
- package/dist/computation.js +248 -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 +43 -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 +46 -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 +27 -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 +39 -0
- package/dist/dist.dev.js +9592 -0
- package/dist/dist.min.js +102 -0
- package/dist/geometries/cone-geometry.d.ts +2 -2
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +13 -18
- 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 +192 -57
- package/dist/geometries/cylinder-geometry.d.ts +2 -2
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +11 -15
- 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 +143 -171
- 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 +95 -122
- 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 +78 -101
- 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 +100 -134
- 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 +3 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +35 -41
- package/dist/geometry/geometry.d.ts +43 -43
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +82 -139
- 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 +90 -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 +42 -0
- package/dist/index.cjs +3444 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +43 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -15
- 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 +43 -2
- package/dist/lib/pipeline-factory.d.ts +17 -51
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +84 -209
- package/dist/lib/shader-factory.d.ts +17 -0
- package/dist/lib/shader-factory.d.ts.map +1 -0
- package/dist/lib/shader-factory.js +46 -0
- package/dist/model/model.d.ts +219 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +659 -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 +84 -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 +35 -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 +153 -0
- package/dist/shader-inputs.d.ts +63 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +107 -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 +70 -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 +117 -0
- package/dist.min.js +25 -0
- package/package.json +24 -14
- package/src/animation/timeline.ts +35 -34
- package/src/animation-loop/animation-loop-template.ts +25 -0
- package/src/{lib → animation-loop}/animation-loop.ts +114 -93
- package/src/{lib → animation-loop}/animation-props.ts +2 -2
- package/src/animation-loop/make-animation-loop.ts +53 -0
- package/src/computation.ts +346 -0
- package/src/debug/copy-texture-to-image.ts +70 -0
- package/src/debug/debug-framebuffer.ts +70 -0
- package/src/debug/debug-shader-layout.ts +38 -0
- package/src/debug/pixel-data-utils.ts +54 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +62 -56
- 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 +6 -14
- package/src/geometry/geometry-table.ts +10 -7
- package/src/geometry/geometry-utils.ts +19 -3
- package/src/geometry/geometry.ts +68 -110
- package/src/geometry/gpu-geometry.ts +132 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +37 -10
- package/src/lib/clip-space.ts +32 -34
- package/src/lib/pipeline-factory.ts +83 -193
- package/src/lib/shader-factory.ts +57 -0
- package/src/model/model.ts +835 -0
- package/src/scenegraph/group-node.ts +107 -0
- package/src/scenegraph/model-node.ts +50 -0
- package/src/scenegraph/scenegraph-node.ts +204 -0
- package/src/shader-inputs.ts +157 -0
- package/src/transform/buffer-transform.ts +102 -0
- package/src/transform/texture-transform.ts +168 -0
- package/dist/animation/key-frames.js.map +0 -1
- package/dist/animation/timeline.js.map +0 -1
- 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/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/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/index.js.map +0 -1
- package/dist/lib/animation-loop.d.ts.map +0 -1
- package/dist/lib/animation-loop.js +0 -480
- 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 +0 -2
- package/dist/lib/animation-props.js.map +0 -1
- package/dist/lib/clip-space.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/pipeline-factory.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
|
@@ -1,27 +1,33 @@
|
|
|
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 {
|
|
12
12
|
constructor(props: CubeGeometryProps = {}) {
|
|
13
13
|
const {id = uid('cube-geometry'), indices = true} = props;
|
|
14
|
-
super(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
super(
|
|
15
|
+
indices
|
|
16
|
+
? {
|
|
17
|
+
...props,
|
|
18
|
+
id,
|
|
19
|
+
topology: 'triangle-list',
|
|
20
|
+
indices: {size: 1, value: CUBE_INDICES},
|
|
21
|
+
attributes: {...ATTRIBUTES, ...props.attributes}
|
|
22
|
+
}
|
|
23
|
+
: {
|
|
24
|
+
...props,
|
|
25
|
+
id,
|
|
26
|
+
topology: 'triangle-list',
|
|
27
|
+
indices: undefined,
|
|
28
|
+
attributes: {...NON_INDEXED_ATTRIBUTES, ...props.attributes}
|
|
29
|
+
}
|
|
30
|
+
);
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -77,47 +83,47 @@ const CUBE_TEX_COORDS = new Float32Array([
|
|
|
77
83
|
// float4 position
|
|
78
84
|
// prettier-ignore
|
|
79
85
|
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,
|
|
86
|
+
1, -1, 1,
|
|
87
|
+
-1, -1, 1,
|
|
88
|
+
-1, -1, -1,
|
|
89
|
+
1, -1, -1,
|
|
90
|
+
1, -1, 1,
|
|
91
|
+
-1, -1, -1,
|
|
92
|
+
|
|
93
|
+
1, 1, 1,
|
|
94
|
+
1, -1, 1,
|
|
95
|
+
1, -1, -1,
|
|
96
|
+
1, 1, -1,
|
|
97
|
+
1, 1, 1,
|
|
98
|
+
1, -1, -1,
|
|
99
|
+
|
|
100
|
+
-1, 1, 1,
|
|
101
|
+
1, 1, 1,
|
|
102
|
+
1, 1, -1,
|
|
103
|
+
-1, 1, -1,
|
|
104
|
+
-1, 1, 1,
|
|
105
|
+
1, 1, -1,
|
|
106
|
+
|
|
107
|
+
-1, -1, 1,
|
|
108
|
+
-1, 1, 1,
|
|
109
|
+
-1, 1, -1,
|
|
110
|
+
-1, -1, -1,
|
|
111
|
+
-1, -1, 1,
|
|
112
|
+
-1, 1, -1,
|
|
113
|
+
|
|
114
|
+
1, 1, 1,
|
|
115
|
+
-1, 1, 1,
|
|
116
|
+
-1, -1, 1,
|
|
117
|
+
-1, -1, 1,
|
|
118
|
+
1, -1, 1,
|
|
119
|
+
1, 1, 1,
|
|
120
|
+
|
|
121
|
+
1, -1, -1,
|
|
122
|
+
-1, -1, -1,
|
|
123
|
+
-1, 1, -1,
|
|
124
|
+
1, 1, -1,
|
|
125
|
+
1, -1, -1,
|
|
126
|
+
-1, 1, -1,
|
|
121
127
|
]);
|
|
122
128
|
|
|
123
129
|
// float2 uv,
|
|
@@ -219,7 +225,7 @@ const ATTRIBUTES = {
|
|
|
219
225
|
};
|
|
220
226
|
|
|
221
227
|
const NON_INDEXED_ATTRIBUTES = {
|
|
222
|
-
POSITION: {size:
|
|
228
|
+
POSITION: {size: 3, value: CUBE_NON_INDEXED_POSITIONS},
|
|
223
229
|
// NORMAL: {size: 3, value: CUBE_NON_INDEXED_NORMALS},
|
|
224
230
|
TEXCOORD_0: {size: 2, value: CUBE_NON_INDEXED_TEX_COORDS},
|
|
225
231
|
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,28 +23,21 @@ 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},
|
|
46
37
|
NORMAL: {size: 3, value: attributes.NORMAL},
|
|
47
38
|
TEXCOORD_0: {size: 2, value: attributes.TEXCOORD_0},
|
|
48
|
-
...props.attributes
|
|
39
|
+
...props.attributes
|
|
40
|
+
}
|
|
49
41
|
});
|
|
50
42
|
}
|
|
51
43
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {TypedArray, VertexFormat} from '@luma.gl/core';
|
|
3
6
|
|
|
4
7
|
/** Holds one geometry */
|
|
5
8
|
export type GeometryTable = {
|
|
6
9
|
length: number;
|
|
7
10
|
schema?: Record<string, VertexFormat>;
|
|
8
11
|
attributes: {
|
|
9
|
-
POSITION: TypedArray
|
|
10
|
-
NORMAL: TypedArray
|
|
11
|
-
TEXCOORD_0: TypedArray
|
|
12
|
-
[key: string]: TypedArray
|
|
12
|
+
POSITION: TypedArray;
|
|
13
|
+
NORMAL: TypedArray;
|
|
14
|
+
TEXCOORD_0: TypedArray;
|
|
15
|
+
[key: string]: TypedArray;
|
|
13
16
|
};
|
|
14
17
|
indices?: Uint16Array | Uint32Array;
|
|
15
18
|
topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
|
|
16
|
-
}
|
|
19
|
+
};
|
|
@@ -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
|
+
// }
|
package/src/geometry/geometry.ts
CHANGED
|
@@ -1,91 +1,64 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import GL from '@luma.gl/constants';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Rendering primitives - "topology" specifies how to extract primitives from vertices.
|
|
8
|
-
* @deprecated - use string constants instead
|
|
9
|
-
*/
|
|
10
|
-
export type GLTopology =
|
|
11
|
-
GL.POINTS | // draw single points.
|
|
12
|
-
GL.LINES | // draw lines. Each vertex connects to the one after it.
|
|
13
|
-
GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.
|
|
14
|
-
GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last
|
|
15
|
-
GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.
|
|
16
|
-
GL.TRIANGLE_STRIP | // draw a connected group of triangles.
|
|
17
|
-
GL.TRIANGLE_FAN // draw a connected group of triangles.
|
|
18
|
-
;
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
19
4
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
value: TypedArray;
|
|
23
|
-
[key: string]: any
|
|
24
|
-
}
|
|
5
|
+
import type {PrimitiveTopology, TypedArray} from '@luma.gl/core';
|
|
6
|
+
import {uid, assert} from '@luma.gl/core';
|
|
25
7
|
|
|
26
8
|
export type GeometryProps = {
|
|
27
9
|
id?: string;
|
|
28
|
-
attributes?: Record<string, GeometryAttribute | TypedArray>,
|
|
29
|
-
indices?: GeometryAttribute | TypedArray;
|
|
30
|
-
vertexCount?: number;
|
|
31
10
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
32
|
-
topology
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
topology:
|
|
12
|
+
| 'point-list'
|
|
13
|
+
| 'line-list'
|
|
14
|
+
| 'line-strip'
|
|
15
|
+
| 'line-loop-webgl'
|
|
16
|
+
| 'triangle-list'
|
|
17
|
+
| 'triangle-strip'
|
|
18
|
+
| 'triangle-fan-webgl';
|
|
19
|
+
/** Auto calculated from attributes if not provided */
|
|
20
|
+
vertexCount?: number;
|
|
21
|
+
attributes?: Record<string, GeometryAttribute | TypedArray>;
|
|
22
|
+
indices?: GeometryAttribute | TypedArray;
|
|
35
23
|
};
|
|
36
24
|
|
|
37
|
-
type GeometryAttributes = {
|
|
38
|
-
POSITION: GeometryAttribute
|
|
39
|
-
NORMAL: GeometryAttribute
|
|
40
|
-
TEXCOORD_0: GeometryAttribute
|
|
41
|
-
COLOR_0?: GeometryAttribute
|
|
42
|
-
indices?: {size
|
|
25
|
+
export type GeometryAttributes = {
|
|
26
|
+
POSITION: GeometryAttribute;
|
|
27
|
+
NORMAL: GeometryAttribute;
|
|
28
|
+
TEXCOORD_0: GeometryAttribute;
|
|
29
|
+
COLOR_0?: GeometryAttribute;
|
|
30
|
+
indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};
|
|
43
31
|
};
|
|
44
32
|
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.
|
|
51
|
-
LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last
|
|
52
|
-
TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.
|
|
53
|
-
TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.
|
|
54
|
-
TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.
|
|
55
|
-
};
|
|
33
|
+
export type GeometryAttribute = {
|
|
34
|
+
size?: number;
|
|
35
|
+
value: TypedArray;
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
};
|
|
56
38
|
|
|
39
|
+
export class Geometry {
|
|
57
40
|
readonly id: string;
|
|
58
|
-
userData: Record<string, unknown> = {};
|
|
59
|
-
|
|
60
41
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
61
|
-
topology?: PrimitiveTopology;
|
|
62
|
-
/** @deprecated */
|
|
63
|
-
readonly drawMode: GLTopology = GL.TRIANGLES;
|
|
64
|
-
|
|
42
|
+
readonly topology?: PrimitiveTopology;
|
|
65
43
|
readonly vertexCount: number;
|
|
44
|
+
readonly indices?: GeometryAttribute;
|
|
66
45
|
readonly attributes: {
|
|
67
|
-
POSITION: GeometryAttribute
|
|
68
|
-
NORMAL: GeometryAttribute
|
|
69
|
-
TEXCOORD_0: GeometryAttribute
|
|
70
|
-
COLOR_0?: GeometryAttribute
|
|
46
|
+
POSITION: GeometryAttribute;
|
|
47
|
+
NORMAL: GeometryAttribute;
|
|
48
|
+
TEXCOORD_0: GeometryAttribute;
|
|
49
|
+
COLOR_0?: GeometryAttribute;
|
|
50
|
+
[key: string]: GeometryAttribute | undefined;
|
|
71
51
|
};
|
|
72
|
-
readonly indices?: Uint16Array | Uint32Array;
|
|
73
52
|
|
|
74
|
-
|
|
75
|
-
const {
|
|
76
|
-
id = uid('geometry'),
|
|
77
|
-
drawMode = GL.TRIANGLES,
|
|
78
|
-
attributes = {},
|
|
79
|
-
indices = null,
|
|
80
|
-
vertexCount = null
|
|
81
|
-
} = props;
|
|
53
|
+
userData: Record<string, unknown> = {};
|
|
82
54
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
55
|
+
constructor(props: GeometryProps) {
|
|
56
|
+
const {attributes = {}, indices = null, vertexCount = null} = props;
|
|
57
|
+
|
|
58
|
+
this.id = props.id || uid('geometry');
|
|
59
|
+
this.topology = props.topology;
|
|
86
60
|
|
|
87
61
|
if (indices) {
|
|
88
|
-
// @ts-expect-error
|
|
89
62
|
this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
|
|
90
63
|
}
|
|
91
64
|
|
|
@@ -93,9 +66,10 @@ export default class Geometry {
|
|
|
93
66
|
this.attributes = {};
|
|
94
67
|
|
|
95
68
|
for (const [attributeName, attributeValue] of Object.entries(attributes)) {
|
|
96
|
-
|
|
97
69
|
// Wrap "unwrapped" arrays and try to autodetect their type
|
|
98
|
-
const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
|
|
70
|
+
const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
|
|
71
|
+
? {value: attributeValue}
|
|
72
|
+
: attributeValue;
|
|
99
73
|
|
|
100
74
|
assert(
|
|
101
75
|
ArrayBuffer.isView(attribute.value),
|
|
@@ -109,36 +83,31 @@ export default class Geometry {
|
|
|
109
83
|
// Move indices to separate field
|
|
110
84
|
if (attributeName === 'indices') {
|
|
111
85
|
assert(!this.indices);
|
|
112
|
-
|
|
113
|
-
this.indices = attribute;
|
|
86
|
+
this.indices = attribute;
|
|
114
87
|
} else {
|
|
115
88
|
this.attributes[attributeName] = attribute;
|
|
116
89
|
}
|
|
117
90
|
}
|
|
118
91
|
|
|
119
|
-
|
|
120
|
-
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
92
|
+
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
121
93
|
this.indices = Object.assign({}, this.indices);
|
|
122
|
-
// @ts-expect-error
|
|
123
94
|
delete this.indices.isIndexed;
|
|
124
95
|
}
|
|
125
96
|
|
|
126
97
|
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
127
98
|
}
|
|
128
99
|
|
|
129
|
-
/** @deprecated Use string topology constants instead */
|
|
130
|
-
get mode() {
|
|
131
|
-
return this.drawMode;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
100
|
getVertexCount(): number {
|
|
135
101
|
return this.vertexCount;
|
|
136
102
|
}
|
|
137
103
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Return an object with all attributes plus indices added as a field.
|
|
106
|
+
* TODO Geometry types are a mess
|
|
107
|
+
*/
|
|
108
|
+
getAttributes(): GeometryAttributes {
|
|
109
|
+
return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
|
|
110
|
+
}
|
|
142
111
|
|
|
143
112
|
// PRIVATE
|
|
144
113
|
|
|
@@ -146,23 +115,27 @@ export default class Geometry {
|
|
|
146
115
|
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
147
116
|
}
|
|
148
117
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
118
|
+
/**
|
|
119
|
+
* GeometryAttribute
|
|
120
|
+
* value: typed array
|
|
121
|
+
* type: indices, vertices, uvs
|
|
122
|
+
* size: elements per vertex
|
|
123
|
+
* target: WebGL buffer type (string or constant)
|
|
124
|
+
*
|
|
125
|
+
* @param attributes
|
|
126
|
+
* @param indices
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
_setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
|
|
156
130
|
return this;
|
|
157
131
|
}
|
|
158
132
|
|
|
159
|
-
_calculateVertexCount(attributes, indices): number {
|
|
133
|
+
_calculateVertexCount(attributes: GeometryAttributes, indices: GeometryAttribute): number {
|
|
160
134
|
if (indices) {
|
|
161
135
|
return indices.value.length;
|
|
162
136
|
}
|
|
163
137
|
let vertexCount = Infinity;
|
|
164
|
-
for (const
|
|
165
|
-
const attribute = attributes[attributeName];
|
|
138
|
+
for (const attribute of Object.values(attributes)) {
|
|
166
139
|
const {value, size, constant} = attribute;
|
|
167
140
|
if (!constant && value && size >= 1) {
|
|
168
141
|
vertexCount = Math.min(vertexCount, value.length / size);
|
|
@@ -173,18 +146,3 @@ export default class Geometry {
|
|
|
173
146
|
return vertexCount;
|
|
174
147
|
}
|
|
175
148
|
}
|
|
176
|
-
|
|
177
|
-
function convertToTopology(drawMode: GLTopology): PrimitiveTopology {
|
|
178
|
-
switch (drawMode) {
|
|
179
|
-
case GL.POINTS: return 'point-list'; // draw single points.
|
|
180
|
-
case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.
|
|
181
|
-
case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last
|
|
182
|
-
case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.
|
|
183
|
-
case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.
|
|
184
|
-
|
|
185
|
-
case GL.TRIANGLE_FAN: return 'triangle-fan'; // draw a connected group of triangles.
|
|
186
|
-
case GL.LINE_LOOP: return 'line-loop'; // draw lines. Each set of two vertices is treated as a separate line segment.
|
|
187
|
-
default:
|
|
188
|
-
throw new Error(String(drawMode));
|
|
189
|
-
}
|
|
190
|
-
}
|