@luma.gl/engine 9.0.0-alpha.8 → 9.0.0-beta.1
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 +10081 -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 -82
- 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 +3128 -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 -45
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +42 -168
- 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 +435 -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 +3 -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 +51 -168
- package/src/model/model.ts +726 -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
package/src/geometry/geometry.ts
CHANGED
|
@@ -1,91 +1,61 @@
|
|
|
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
|
-
* @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
|
-
;
|
|
19
|
-
|
|
20
|
-
export type GeometryAttribute = {
|
|
21
|
-
size?: number;
|
|
22
|
-
value: TypedArray;
|
|
23
|
-
[key: string]: any
|
|
24
|
-
}
|
|
2
|
+
import type {PrimitiveTopology, TypedArray} from '@luma.gl/core';
|
|
3
|
+
import {uid, assert} from '@luma.gl/core';
|
|
25
4
|
|
|
26
5
|
export type GeometryProps = {
|
|
27
6
|
id?: string;
|
|
28
|
-
attributes?: Record<string, GeometryAttribute | TypedArray>,
|
|
29
|
-
indices?: GeometryAttribute | TypedArray;
|
|
30
|
-
vertexCount?: number;
|
|
31
7
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
32
|
-
topology
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
35
20
|
};
|
|
36
21
|
|
|
37
|
-
type GeometryAttributes = {
|
|
38
|
-
POSITION: GeometryAttribute
|
|
39
|
-
NORMAL: GeometryAttribute
|
|
40
|
-
TEXCOORD_0: GeometryAttribute
|
|
41
|
-
COLOR_0?: GeometryAttribute
|
|
42
|
-
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};
|
|
43
28
|
};
|
|
44
29
|
|
|
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
|
-
};
|
|
30
|
+
export type GeometryAttribute = {
|
|
31
|
+
size?: number;
|
|
32
|
+
value: TypedArray;
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
};
|
|
56
35
|
|
|
36
|
+
export class Geometry {
|
|
57
37
|
readonly id: string;
|
|
58
|
-
userData: Record<string, unknown> = {};
|
|
59
|
-
|
|
60
38
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
61
|
-
topology?:
|
|
62
|
-
/** @deprecated */
|
|
63
|
-
readonly drawMode: GLTopology = GL.TRIANGLES;
|
|
64
|
-
|
|
39
|
+
readonly topology?: PrimitiveTopology;
|
|
65
40
|
readonly vertexCount: number;
|
|
41
|
+
readonly indices?: GeometryAttribute;
|
|
66
42
|
readonly attributes: {
|
|
67
|
-
POSITION: GeometryAttribute
|
|
68
|
-
NORMAL: GeometryAttribute
|
|
69
|
-
TEXCOORD_0: GeometryAttribute
|
|
70
|
-
COLOR_0?: GeometryAttribute
|
|
43
|
+
POSITION: GeometryAttribute;
|
|
44
|
+
NORMAL: GeometryAttribute;
|
|
45
|
+
TEXCOORD_0: GeometryAttribute;
|
|
46
|
+
COLOR_0?: GeometryAttribute;
|
|
47
|
+
[key: string]: GeometryAttribute | undefined;
|
|
71
48
|
};
|
|
72
|
-
readonly indices?: Uint16Array | Uint32Array;
|
|
73
49
|
|
|
74
|
-
|
|
75
|
-
const {
|
|
76
|
-
id = uid('geometry'),
|
|
77
|
-
drawMode = GL.TRIANGLES,
|
|
78
|
-
attributes = {},
|
|
79
|
-
indices = null,
|
|
80
|
-
vertexCount = null
|
|
81
|
-
} = props;
|
|
50
|
+
userData: Record<string, unknown> = {};
|
|
82
51
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
52
|
+
constructor(props: GeometryProps) {
|
|
53
|
+
const {attributes = {}, indices = null, vertexCount = null} = props;
|
|
54
|
+
|
|
55
|
+
this.id = props.id || uid('geometry');
|
|
56
|
+
this.topology = props.topology;
|
|
86
57
|
|
|
87
58
|
if (indices) {
|
|
88
|
-
// @ts-expect-error
|
|
89
59
|
this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
|
|
90
60
|
}
|
|
91
61
|
|
|
@@ -93,9 +63,10 @@ export default class Geometry {
|
|
|
93
63
|
this.attributes = {};
|
|
94
64
|
|
|
95
65
|
for (const [attributeName, attributeValue] of Object.entries(attributes)) {
|
|
96
|
-
|
|
97
66
|
// Wrap "unwrapped" arrays and try to autodetect their type
|
|
98
|
-
const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
|
|
67
|
+
const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
|
|
68
|
+
? {value: attributeValue}
|
|
69
|
+
: attributeValue;
|
|
99
70
|
|
|
100
71
|
assert(
|
|
101
72
|
ArrayBuffer.isView(attribute.value),
|
|
@@ -109,36 +80,31 @@ export default class Geometry {
|
|
|
109
80
|
// Move indices to separate field
|
|
110
81
|
if (attributeName === 'indices') {
|
|
111
82
|
assert(!this.indices);
|
|
112
|
-
|
|
113
|
-
this.indices = attribute;
|
|
83
|
+
this.indices = attribute;
|
|
114
84
|
} else {
|
|
115
85
|
this.attributes[attributeName] = attribute;
|
|
116
86
|
}
|
|
117
87
|
}
|
|
118
88
|
|
|
119
|
-
|
|
120
|
-
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
89
|
+
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
121
90
|
this.indices = Object.assign({}, this.indices);
|
|
122
|
-
// @ts-expect-error
|
|
123
91
|
delete this.indices.isIndexed;
|
|
124
92
|
}
|
|
125
93
|
|
|
126
94
|
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
127
95
|
}
|
|
128
96
|
|
|
129
|
-
/** @deprecated Use string topology constants instead */
|
|
130
|
-
get mode() {
|
|
131
|
-
return this.drawMode;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
97
|
getVertexCount(): number {
|
|
135
98
|
return this.vertexCount;
|
|
136
99
|
}
|
|
137
100
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
}
|
|
142
108
|
|
|
143
109
|
// PRIVATE
|
|
144
110
|
|
|
@@ -146,23 +112,27 @@ export default class Geometry {
|
|
|
146
112
|
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
147
113
|
}
|
|
148
114
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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 {
|
|
156
127
|
return this;
|
|
157
128
|
}
|
|
158
129
|
|
|
159
|
-
_calculateVertexCount(attributes, indices): number {
|
|
130
|
+
_calculateVertexCount(attributes: GeometryAttributes, indices: GeometryAttribute): number {
|
|
160
131
|
if (indices) {
|
|
161
132
|
return indices.value.length;
|
|
162
133
|
}
|
|
163
134
|
let vertexCount = Infinity;
|
|
164
|
-
for (const
|
|
165
|
-
const attribute = attributes[attributeName];
|
|
135
|
+
for (const attribute of Object.values(attributes)) {
|
|
166
136
|
const {value, size, constant} = attribute;
|
|
167
137
|
if (!constant && value && size >= 1) {
|
|
168
138
|
vertexCount = Math.min(vertexCount, value.length / size);
|
|
@@ -173,18 +143,3 @@ export default class Geometry {
|
|
|
173
143
|
return vertexCount;
|
|
174
144
|
}
|
|
175
145
|
}
|
|
176
|
-
|
|
177
|
-
function convertToTopology(drawMode: GLTopology): 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip' {
|
|
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: // draw a connected group of triangles.
|
|
186
|
-
case GL.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
|
-
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
case 'COLOR_0': name = 'colors'; break;
|
|
116
|
+
}
|
|
117
|
+
attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});
|
|
118
|
+
const {value, size, normalized} = attribute;
|
|
119
|
+
bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)
|
|
123
|
+
|
|
124
|
+
return {attributes, bufferLayout, vertexCount};
|
|
125
|
+
}
|
|
@@ -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
|
+
*/
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
// luma.gl Engine API
|
|
2
|
-
export type {AnimationProps} from './lib/animation-props';
|
|
3
|
-
export type {AnimationLoopProps} from './lib/animation-loop';
|
|
4
|
-
export {AnimationLoop} from './lib/animation-loop';
|
|
5
|
-
export {RenderLoop} from './lib/render-loop';
|
|
6
|
-
export type {ModelProps} from './lib/model';
|
|
7
|
-
export {default as Model} from './lib/model';
|
|
8
|
-
|
|
9
|
-
export {PipelineFactory} from './lib/pipeline-factory';
|
|
10
2
|
|
|
11
3
|
// Animation
|
|
12
4
|
export {Timeline} from './animation/timeline';
|
|
13
5
|
export {KeyFrames} from './animation/key-frames';
|
|
6
|
+
export type {AnimationProps} from './animation-loop/animation-props';
|
|
7
|
+
|
|
8
|
+
export {AnimationLoopTemplate} from './animation-loop/animation-loop-template';
|
|
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
|
+
// Transforms
|
|
20
|
+
export type {BufferTransformProps} from './transform/buffer-transform';
|
|
21
|
+
export {BufferTransform} from './transform/buffer-transform';
|
|
22
|
+
export type {TextureTransformProps} from './transform/texture-transform';
|
|
23
|
+
export {TextureTransform} from './transform/texture-transform';
|
|
24
|
+
|
|
25
|
+
export {PipelineFactory} from './lib/pipeline-factory';
|
|
14
26
|
|
|
15
27
|
// Utils
|
|
16
|
-
|
|
28
|
+
export {ClipSpace} from './lib/clip-space';
|
|
29
|
+
|
|
30
|
+
// Scenegraph Core nodes
|
|
31
|
+
export {ScenegraphNode} from './scenegraph/scenegraph-node';
|
|
32
|
+
export {GroupNode} from './scenegraph/group-node';
|
|
33
|
+
export type {ModelNodeProps} from './scenegraph/model-node';
|
|
34
|
+
export {ModelNode} from './scenegraph/model-node';
|
|
17
35
|
|
|
18
36
|
// Geometries
|
|
19
|
-
export {
|
|
37
|
+
export type {GeometryProps} from './geometry/geometry';
|
|
38
|
+
export {Geometry} from './geometry/geometry';
|
|
39
|
+
export type {GPUGeometryProps} from './geometry/gpu-geometry';
|
|
40
|
+
export {GPUGeometry} from './geometry/gpu-geometry';
|
|
20
41
|
|
|
21
42
|
// Primitives
|
|
22
43
|
export type {ConeGeometryProps} from './geometries/cone-geometry';
|
|
@@ -34,3 +55,6 @@ export {SphereGeometry} from './geometries/sphere-geometry';
|
|
|
34
55
|
export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';
|
|
35
56
|
export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
|
|
36
57
|
|
|
58
|
+
// EXPERIMENTAL
|
|
59
|
+
export type {ShaderModuleInputs} from './shader-inputs';
|
|
60
|
+
export {ShaderInputs as _ShaderInputs} from './shader-inputs';
|
package/src/lib/clip-space.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
|
|
2
2
|
// ClipSpace
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import Geometry from '../geometry/geometry';
|
|
3
|
+
import {Device, glsl} from '@luma.gl/core';
|
|
4
|
+
import {Model, ModelProps} from '../model/model';
|
|
5
|
+
import {Geometry} from '../geometry/geometry';
|
|
7
6
|
|
|
8
|
-
const CLIPSPACE_VERTEX_SHADER = `\
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const CLIPSPACE_VERTEX_SHADER = glsl`\
|
|
8
|
+
in vec2 aClipSpacePosition;
|
|
9
|
+
in vec2 aTexCoord;
|
|
10
|
+
in vec2 aCoordinate;
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
out vec2 position;
|
|
13
|
+
out vec2 coordinate;
|
|
14
|
+
out vec2 uv;
|
|
16
15
|
|
|
17
16
|
void main(void) {
|
|
18
17
|
gl_Position = vec4(aClipSpacePosition, 0., 1.);
|
|
@@ -22,20 +21,24 @@ void main(void) {
|
|
|
22
21
|
}
|
|
23
22
|
`;
|
|
24
23
|
|
|
25
|
-
/* eslint-disable indent, no-multi-spaces
|
|
24
|
+
/* eslint-disable indent, no-multi-spaces */
|
|
26
25
|
const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A flat geometry that covers the "visible area" that the GPU renders.
|
|
29
|
+
*/
|
|
30
|
+
export class ClipSpace extends Model {
|
|
31
|
+
constructor(device: Device, opts?: ModelProps) {
|
|
31
32
|
const TEX_COORDS = POSITIONS.map((coord) => (coord === -1 ? 0 : coord));
|
|
32
33
|
|
|
33
34
|
super(
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
device,
|
|
36
|
+
{
|
|
37
|
+
...opts,
|
|
36
38
|
vs: CLIPSPACE_VERTEX_SHADER,
|
|
39
|
+
vertexCount: 4,
|
|
37
40
|
geometry: new Geometry({
|
|
38
|
-
|
|
41
|
+
topology: 'triangle-strip',
|
|
39
42
|
vertexCount: 4,
|
|
40
43
|
attributes: {
|
|
41
44
|
aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},
|
|
@@ -43,9 +46,7 @@ export default class ClipSpace extends Model {
|
|
|
43
46
|
aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)}
|
|
44
47
|
}
|
|
45
48
|
})
|
|
46
|
-
}
|
|
49
|
+
}
|
|
47
50
|
);
|
|
48
|
-
this.setVertexCount(4);
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
*/
|