@luma.gl/engine 9.0.0-alpha.9 → 9.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -1
- package/dist/animation/key-frames.d.ts +1 -1
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js +6 -27
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +8 -8
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +18 -49
- package/dist/animation/timeline.js.map +1 -1
- package/dist/animation-loop/animation-loop-template.d.ts +23 -0
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +7 -0
- package/dist/animation-loop/animation-loop-template.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -22
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +77 -192
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +2 -3
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/animation-loop/animation-props.js.map +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts +6 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/make-animation-loop.js +28 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/debug/copy-texture-to-image.d.ts +26 -0
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
- package/dist/debug/copy-texture-to-image.js +46 -0
- package/dist/debug/copy-texture-to-image.js.map +1 -0
- package/dist/debug/debug-framebuffer.d.ts +11 -0
- package/dist/debug/debug-framebuffer.d.ts.map +1 -0
- package/dist/debug/debug-framebuffer.js +43 -0
- package/dist/debug/debug-framebuffer.js.map +1 -0
- package/dist/debug/debug-shader-layout.d.ts +9 -0
- package/dist/debug/debug-shader-layout.d.ts.map +1 -0
- package/dist/debug/debug-shader-layout.js +28 -0
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/debug/pixel-data-utils.d.ts +24 -0
- package/dist/debug/pixel-data-utils.d.ts.map +1 -0
- package/dist/debug/pixel-data-utils.js +41 -0
- package/dist/debug/pixel-data-utils.js.map +1 -0
- package/dist/dist.dev.js +10073 -0
- package/dist/geometries/cone-geometry.d.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +6 -5
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.d.ts +2 -2
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +16 -10
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +6 -5
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +10 -19
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts +2 -2
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +14 -23
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts +2 -2
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +9 -13
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +9 -25
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.d.ts +2 -2
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +0 -9
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +43 -43
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +20 -86
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +37 -0
- package/dist/geometry/gpu-geometry.d.ts.map +1 -0
- package/dist/geometry/gpu-geometry.js +110 -0
- package/dist/geometry/gpu-geometry.js.map +1 -0
- package/dist/geometry/gpu-table.d.ts +1 -0
- package/dist/geometry/gpu-table.d.ts.map +1 -0
- package/dist/geometry/gpu-table.js +2 -0
- package/dist/geometry/gpu-table.js.map +1 -0
- package/dist/index.cjs +3120 -0
- package/dist/index.d.ts +24 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/clip-space.d.ts +8 -0
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +47 -0
- package/dist/lib/clip-space.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +12 -46
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +36 -179
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/model/model.d.ts +206 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +440 -0
- package/dist/model/model.js.map +1 -0
- package/dist/scenegraph/group-node.d.ts +21 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -0
- package/dist/scenegraph/group-node.js +94 -0
- package/dist/scenegraph/group-node.js.map +1 -0
- package/dist/scenegraph/model-node.d.ts +18 -0
- package/dist/scenegraph/model-node.d.ts.map +1 -0
- package/dist/scenegraph/model-node.js +28 -0
- package/dist/scenegraph/model-node.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.d.ts +56 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +141 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/shader-inputs.d.ts +63 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +66 -0
- package/dist/shader-inputs.js.map +1 -0
- package/dist/transform/buffer-transform.d.ts +35 -0
- package/dist/transform/buffer-transform.d.ts.map +1 -0
- package/dist/transform/buffer-transform.js +62 -0
- package/dist/transform/buffer-transform.js.map +1 -0
- package/dist/transform/texture-transform.d.ts +57 -0
- package/dist/transform/texture-transform.d.ts.map +1 -0
- package/dist/transform/texture-transform.js +122 -0
- package/dist/transform/texture-transform.js.map +1 -0
- package/dist.min.js +293 -0
- package/package.json +21 -12
- package/src/animation/timeline.ts +15 -14
- package/src/animation-loop/animation-loop-template.ts +23 -0
- package/src/{lib → animation-loop}/animation-loop.ts +99 -88
- package/src/{lib → animation-loop}/animation-props.ts +1 -1
- package/src/animation-loop/make-animation-loop.ts +44 -0
- package/src/debug/copy-texture-to-image.ts +72 -0
- package/src/debug/debug-framebuffer.ts +57 -0
- package/src/debug/debug-shader-layout.ts +38 -0
- package/src/debug/pixel-data-utils.ts +57 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +47 -45
- package/src/geometries/cylinder-geometry.ts +2 -2
- package/src/geometries/ico-sphere-geometry.ts +6 -5
- package/src/geometries/plane-geometry.ts +5 -4
- package/src/geometries/sphere-geometry.ts +4 -3
- package/src/geometries/truncated-cone-geometry.ts +4 -13
- package/src/geometry/geometry-table.ts +1 -1
- package/src/geometry/geometry-utils.ts +19 -3
- package/src/geometry/geometry.ts +65 -110
- package/src/geometry/gpu-geometry.ts +125 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +34 -10
- package/src/lib/clip-space.ts +22 -21
- package/src/lib/pipeline-factory.ts +48 -179
- package/src/model/model.ts +733 -0
- package/src/scenegraph/group-node.ts +103 -0
- package/src/scenegraph/model-node.ts +50 -0
- package/src/scenegraph/scenegraph-node.ts +204 -0
- package/src/shader-inputs.ts +150 -0
- package/src/transform/buffer-transform.ts +94 -0
- package/src/transform/texture-transform.ts +169 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/dist/geometry/primitive-utils.d.ts +0 -1
- package/dist/geometry/primitive-utils.d.ts.map +0 -1
- package/dist/geometry/primitive-utils.js +0 -2
- package/dist/geometry/primitive-utils.js.map +0 -1
- package/dist/lib/animation-loop.d.ts.map +0 -1
- package/dist/lib/animation-loop.js.map +0 -1
- package/dist/lib/animation-props.d.ts.map +0 -1
- package/dist/lib/animation-props.js.map +0 -1
- package/dist/lib/model-utils.d.ts +0 -5
- package/dist/lib/model-utils.d.ts.map +0 -1
- package/dist/lib/model-utils.js +0 -45
- package/dist/lib/model-utils.js.map +0 -1
- package/dist/lib/model.d.ts +0 -41
- package/dist/lib/model.d.ts.map +0 -1
- package/dist/lib/model.js +0 -182
- package/dist/lib/model.js.map +0 -1
- package/dist/lib/render-loop.d.ts +0 -14
- package/dist/lib/render-loop.d.ts.map +0 -1
- package/dist/lib/render-loop.js +0 -49
- package/dist/lib/render-loop.js.map +0 -1
- package/src/bundle.ts +0 -4
- package/src/geometry/primitive-utils.ts +0 -30
- package/src/lib/model-utils.ts +0 -124
- package/src/lib/model.ts +0 -183
- package/src/lib/render-loop.ts +0 -58
- /package/dist/{lib → animation-loop}/animation-props.js +0 -0
|
@@ -1,52 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
_defineProperty(this, "topology", void 0);
|
|
11
|
-
|
|
12
|
-
_defineProperty(this, "drawMode", GL.TRIANGLES);
|
|
13
|
-
|
|
14
|
-
_defineProperty(this, "vertexCount", void 0);
|
|
15
|
-
|
|
16
|
-
_defineProperty(this, "attributes", void 0);
|
|
17
|
-
|
|
18
|
-
_defineProperty(this, "indices", void 0);
|
|
19
|
-
|
|
1
|
+
import { uid, assert } from '@luma.gl/core';
|
|
2
|
+
export class Geometry {
|
|
3
|
+
constructor(props) {
|
|
4
|
+
this.id = void 0;
|
|
5
|
+
this.topology = void 0;
|
|
6
|
+
this.vertexCount = void 0;
|
|
7
|
+
this.indices = void 0;
|
|
8
|
+
this.attributes = void 0;
|
|
9
|
+
this.userData = {};
|
|
20
10
|
const {
|
|
21
|
-
id = uid('geometry'),
|
|
22
|
-
drawMode = GL.TRIANGLES,
|
|
23
11
|
attributes = {},
|
|
24
12
|
indices = null,
|
|
25
13
|
vertexCount = null
|
|
26
14
|
} = props;
|
|
27
|
-
this.id = id;
|
|
28
|
-
this.
|
|
29
|
-
this.topology = props.topology || convertToTopology(drawMode);
|
|
30
|
-
|
|
15
|
+
this.id = props.id || uid('geometry');
|
|
16
|
+
this.topology = props.topology;
|
|
31
17
|
if (indices) {
|
|
32
18
|
this.indices = ArrayBuffer.isView(indices) ? {
|
|
33
19
|
value: indices,
|
|
34
20
|
size: 1
|
|
35
21
|
} : indices;
|
|
36
22
|
}
|
|
37
|
-
|
|
38
23
|
this.attributes = {};
|
|
39
|
-
|
|
40
24
|
for (const [attributeName, attributeValue] of Object.entries(attributes)) {
|
|
41
25
|
const attribute = ArrayBuffer.isView(attributeValue) ? {
|
|
42
26
|
value: attributeValue
|
|
43
27
|
} : attributeValue;
|
|
44
|
-
assert(ArrayBuffer.isView(attribute.value),
|
|
45
|
-
|
|
28
|
+
assert(ArrayBuffer.isView(attribute.value), `${this._print(attributeName)}: must be typed array or object with value as typed array`);
|
|
46
29
|
if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
|
|
47
30
|
attribute.size = 3;
|
|
48
31
|
}
|
|
49
|
-
|
|
50
32
|
if (attributeName === 'indices') {
|
|
51
33
|
assert(!this.indices);
|
|
52
34
|
this.indices = attribute;
|
|
@@ -54,92 +36,44 @@ export default class Geometry {
|
|
|
54
36
|
this.attributes[attributeName] = attribute;
|
|
55
37
|
}
|
|
56
38
|
}
|
|
57
|
-
|
|
58
39
|
if (this.indices && this.indices.isIndexed !== undefined) {
|
|
59
40
|
this.indices = Object.assign({}, this.indices);
|
|
60
41
|
delete this.indices.isIndexed;
|
|
61
42
|
}
|
|
62
|
-
|
|
63
43
|
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
64
44
|
}
|
|
65
|
-
|
|
66
|
-
get mode() {
|
|
67
|
-
return this.drawMode;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
45
|
getVertexCount() {
|
|
71
46
|
return this.vertexCount;
|
|
72
47
|
}
|
|
73
|
-
|
|
48
|
+
getAttributes() {
|
|
49
|
+
return this.indices ? {
|
|
50
|
+
indices: this.indices,
|
|
51
|
+
...this.attributes
|
|
52
|
+
} : this.attributes;
|
|
53
|
+
}
|
|
74
54
|
_print(attributeName) {
|
|
75
|
-
return
|
|
55
|
+
return `Geometry ${this.id} attribute ${attributeName}`;
|
|
76
56
|
}
|
|
77
|
-
|
|
78
57
|
_setAttributes(attributes, indices) {
|
|
79
58
|
return this;
|
|
80
59
|
}
|
|
81
|
-
|
|
82
60
|
_calculateVertexCount(attributes, indices) {
|
|
83
61
|
if (indices) {
|
|
84
62
|
return indices.value.length;
|
|
85
63
|
}
|
|
86
|
-
|
|
87
64
|
let vertexCount = Infinity;
|
|
88
|
-
|
|
89
|
-
for (const attributeName in attributes) {
|
|
90
|
-
const attribute = attributes[attributeName];
|
|
65
|
+
for (const attribute of Object.values(attributes)) {
|
|
91
66
|
const {
|
|
92
67
|
value,
|
|
93
68
|
size,
|
|
94
69
|
constant
|
|
95
70
|
} = attribute;
|
|
96
|
-
|
|
97
71
|
if (!constant && value && size >= 1) {
|
|
98
72
|
vertexCount = Math.min(vertexCount, value.length / size);
|
|
99
73
|
}
|
|
100
74
|
}
|
|
101
|
-
|
|
102
75
|
assert(Number.isFinite(vertexCount));
|
|
103
76
|
return vertexCount;
|
|
104
77
|
}
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
_defineProperty(Geometry, "DRAW_MODE", {
|
|
109
|
-
POINTS: GL.POINTS,
|
|
110
|
-
LINES: GL.LINES,
|
|
111
|
-
LINE_LOOP: GL.LINE_LOOP,
|
|
112
|
-
LINE_STRIP: GL.LINE_STRIP,
|
|
113
|
-
TRIANGLES: GL.TRIANGLES,
|
|
114
|
-
TRIANGLE_STRIP: GL.TRIANGLE_STRIP,
|
|
115
|
-
TRIANGLE_FAN: GL.TRIANGLE_FAN
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
function convertToTopology(drawMode) {
|
|
119
|
-
switch (drawMode) {
|
|
120
|
-
case GL.POINTS:
|
|
121
|
-
return 'point-list';
|
|
122
|
-
|
|
123
|
-
case GL.LINES:
|
|
124
|
-
return 'line-list';
|
|
125
|
-
|
|
126
|
-
case GL.LINE_STRIP:
|
|
127
|
-
return 'line-strip';
|
|
128
|
-
|
|
129
|
-
case GL.TRIANGLES:
|
|
130
|
-
return 'triangle-list';
|
|
131
|
-
|
|
132
|
-
case GL.TRIANGLE_STRIP:
|
|
133
|
-
return 'triangle-strip';
|
|
134
|
-
|
|
135
|
-
case GL.TRIANGLE_FAN:
|
|
136
|
-
return 'triangle-fan';
|
|
137
|
-
|
|
138
|
-
case GL.LINE_LOOP:
|
|
139
|
-
return 'line-loop';
|
|
140
|
-
|
|
141
|
-
default:
|
|
142
|
-
throw new Error(String(drawMode));
|
|
143
|
-
}
|
|
144
78
|
}
|
|
145
79
|
//# sourceMappingURL=geometry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/geometry/geometry.ts"],"names":["uid","assert","GL","Geometry","constructor","props","TRIANGLES","id","drawMode","attributes","indices","vertexCount","topology","convertToTopology","ArrayBuffer","isView","value","size","attributeName","attributeValue","Object","entries","attribute","_print","isIndexed","undefined","assign","_calculateVertexCount","mode","getVertexCount","_setAttributes","length","Infinity","constant","Math","min","Number","isFinite","POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","Error","String"],"mappings":";AAEA,SAAQA,GAAR,EAAaC,MAAb,QAA0B,cAA1B;AACA,OAAOC,EAAP,MAAe,oBAAf;AAyCA,eAAe,MAAMC,QAAN,CAAe;AA6B5BC,EAAAA,WAAW,CAACC,KAAoB,GAAG,EAAxB,EAA4B;AAAA;;AAAA,sCAhBH,EAgBG;;AAAA;;AAAA,sCAXPH,EAAE,CAACI,SAWI;;AAAA;;AAAA;;AAAA;;AACrC,UAAM;AACJC,MAAAA,EAAE,GAAGP,GAAG,CAAC,UAAD,CADJ;AAEJQ,MAAAA,QAAQ,GAAGN,EAAE,CAACI,SAFV;AAGJG,MAAAA,UAAU,GAAG,EAHT;AAIJC,MAAAA,OAAO,GAAG,IAJN;AAKJC,MAAAA,WAAW,GAAG;AALV,QAMFN,KANJ;AAQA,SAAKE,EAAL,GAAUA,EAAV;AACA,SAAKC,QAAL,GAAgBA,QAAhB;AACA,SAAKI,QAAL,GAAgBP,KAAK,CAACO,QAAN,IAAkBC,iBAAiB,CAACL,QAAD,CAAnD;;AAEA,QAAIE,OAAJ,EAAa;AAEX,WAAKA,OAAL,GAAeI,WAAW,CAACC,MAAZ,CAAmBL,OAAnB,IAA8B;AAACM,QAAAA,KAAK,EAAEN,OAAR;AAAiBO,QAAAA,IAAI,EAAE;AAAvB,OAA9B,GAA0DP,OAAzE;AACD;;AAGD,SAAKD,UAAL,GAAkB,EAAlB;;AAEA,SAAK,MAAM,CAACS,aAAD,EAAgBC,cAAhB,CAAX,IAA8CC,MAAM,CAACC,OAAP,CAAeZ,UAAf,CAA9C,EAA0E;AAGxE,YAAMa,SAA4B,GAAGR,WAAW,CAACC,MAAZ,CAAmBI,cAAnB,IAAqC;AAACH,QAAAA,KAAK,EAAEG;AAAR,OAArC,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ExB,SAAKxC,EAAE,CAACyC,YAAR;AAAsB,aAAO,cAAP;;AACtB,SAAKzC,EAAE,CAACsC,SAAR;AAAmB,aAAO,WAAP;;AACnB;AACE,YAAM,IAAII,KAAJ,CAAUC,MAAM,CAACrC,QAAD,CAAhB,CAAN;AAVJ;AAYD","sourcesContent":["// luma.gl, MIT license\nimport type {PrimitiveTopology, TypedArray} from '@luma.gl/api';\nimport {uid, assert} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\n\n/**\n * Rendering primitives - \"topology\" specifies how to extract primitives from vertices.\n * @deprecated - use string constants instead\n */\nexport type GLTopology =\n GL.POINTS | // draw single points.\n GL.LINES | // draw lines. Each vertex connects to the one after it.\n GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.\n GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last\n GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.\n GL.TRIANGLE_STRIP | // draw a connected group of triangles.\n GL.TRIANGLE_FAN // draw a connected group of triangles.\n ;\n\nexport type GeometryAttribute = {\n size?: number;\n value: TypedArray;\n [key: string]: any\n}\n\nexport type GeometryProps = {\n id?: string;\n attributes?: Record<string, GeometryAttribute | TypedArray>,\n indices?: GeometryAttribute | TypedArray;\n vertexCount?: number;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n /** @deprecated */\n drawMode?: GLTopology;\n};\n\ntype GeometryAttributes = {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n indices?: {size?: number, value: Uint32Array | Uint16Array};\n};\n\nexport default class Geometry {\n /** @deprecated */\n static DRAW_MODE = {\n POINTS: GL.POINTS, // draw single points.\n LINES: GL.LINES, // draw lines. Each vertex connects to the one after it.\n LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.\n LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last\n TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.\n TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.\n TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.\n };\n\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: PrimitiveTopology;\n /** @deprecated */\n readonly drawMode: GLTopology = GL.TRIANGLES;\n\n readonly vertexCount: number;\n readonly attributes: {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n };\n readonly indices?: Uint16Array | Uint32Array;\n\n constructor(props: GeometryProps = {}) {\n const {\n id = uid('geometry'),\n drawMode = GL.TRIANGLES,\n attributes = {},\n indices = null,\n vertexCount = null\n } = props;\n\n this.id = id;\n this.drawMode = drawMode;\n this.topology = props.topology || convertToTopology(drawMode);\n\n if (indices) {\n // @ts-expect-error\n this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;\n }\n\n // @ts-expect-error\n this.attributes = {};\n\n for (const [attributeName, attributeValue] of Object.entries(attributes)) {\n\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue) ? {value: attributeValue} : attributeValue;\n\n assert(\n ArrayBuffer.isView(attribute.value),\n `${this._print(attributeName)}: must be typed array or object with value as typed array`\n );\n\n if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {\n attribute.size = 3;\n }\n\n // Move indices to separate field\n if (attributeName === 'indices') {\n assert(!this.indices);\n // @ts-expect-error\n this.indices = attribute;\n } else {\n this.attributes[attributeName] = attribute;\n }\n }\n\n // @ts-expect-error\n if (this.indices && this.indices.isIndexed !== undefined) {\n this.indices = Object.assign({}, this.indices);\n // @ts-expect-error\n delete this.indices.isIndexed;\n }\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n /** @deprecated Use string topology constants instead */\n get mode() {\n return this.drawMode;\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n // Return an object with all attributes plus indices added as a field.\n // getAttributes(): GeometryAttributes {\n // return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;\n // }\n\n // PRIVATE\n\n _print(attributeName: string): string {\n return `Geometry ${this.id} attribute ${attributeName}`;\n }\n\n // GeometryAttribute\n // value: typed array\n // type: indices, vertices, uvs\n // size: elements per vertex\n // target: WebGL buffer type (string or constant)\n _setAttributes(attributes: Record<string, GeometryAttribute>, indices): this {\n\n return this;\n }\n\n _calculateVertexCount(attributes, indices): number {\n if (indices) {\n return indices.value.length;\n }\n let vertexCount = Infinity;\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const {value, size, constant} = attribute;\n if (!constant && value && size >= 1) {\n vertexCount = Math.min(vertexCount, value.length / size);\n }\n }\n\n assert(Number.isFinite(vertexCount));\n return vertexCount;\n }\n}\n\nfunction convertToTopology(drawMode: GLTopology): PrimitiveTopology {\n switch (drawMode) {\n case GL.POINTS: return 'point-list'; // draw single points.\n case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.\n case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last\n case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.\n case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.\n\n case GL.TRIANGLE_FAN: return 'triangle-fan'; // draw a connected group of triangles.\n case GL.LINE_LOOP: return 'line-loop'; // draw lines. Each set of two vertices is treated as a separate line segment.\n default:\n throw new Error(String(drawMode));\n }\n}\n"],"file":"geometry.js"}
|
|
1
|
+
{"version":3,"file":"geometry.js","names":["uid","assert","Geometry","constructor","props","id","topology","vertexCount","indices","attributes","userData","ArrayBuffer","isView","value","size","attributeName","attributeValue","Object","entries","attribute","_print","isIndexed","undefined","assign","_calculateVertexCount","getVertexCount","getAttributes","_setAttributes","length","Infinity","values","constant","Math","min","Number","isFinite"],"sources":["../../src/geometry/geometry.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {PrimitiveTopology, TypedArray} from '@luma.gl/core';\nimport {uid, assert} from '@luma.gl/core';\n\nexport type GeometryProps = {\n id?: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology:\n | 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'line-loop-webgl'\n | 'triangle-list'\n | 'triangle-strip'\n | 'triangle-fan-webgl';\n /** Auto calculated from attributes if not provided */\n vertexCount?: number;\n attributes?: Record<string, GeometryAttribute | TypedArray>;\n indices?: GeometryAttribute | TypedArray;\n};\n\nexport type GeometryAttributes = {\n POSITION: GeometryAttribute;\n NORMAL: GeometryAttribute;\n TEXCOORD_0: GeometryAttribute;\n COLOR_0?: GeometryAttribute;\n indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};\n};\n\nexport type GeometryAttribute = {\n size?: number;\n value: TypedArray;\n [key: string]: any;\n};\n\nexport class Geometry {\n readonly id: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n readonly topology?: PrimitiveTopology;\n readonly vertexCount: number;\n readonly indices?: GeometryAttribute;\n readonly attributes: {\n POSITION: GeometryAttribute;\n NORMAL: GeometryAttribute;\n TEXCOORD_0: GeometryAttribute;\n COLOR_0?: GeometryAttribute;\n [key: string]: GeometryAttribute | undefined;\n };\n\n userData: Record<string, unknown> = {};\n\n constructor(props: GeometryProps) {\n const {attributes = {}, indices = null, vertexCount = null} = props;\n\n this.id = props.id || uid('geometry');\n this.topology = props.topology;\n\n if (indices) {\n this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;\n }\n\n // @ts-expect-error\n this.attributes = {};\n\n for (const [attributeName, attributeValue] of Object.entries(attributes)) {\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)\n ? {value: attributeValue}\n : attributeValue;\n\n assert(\n ArrayBuffer.isView(attribute.value),\n `${this._print(attributeName)}: must be typed array or object with value as typed array`\n );\n\n if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {\n attribute.size = 3;\n }\n\n // Move indices to separate field\n if (attributeName === 'indices') {\n assert(!this.indices);\n this.indices = attribute;\n } else {\n this.attributes[attributeName] = attribute;\n }\n }\n\n if (this.indices && this.indices.isIndexed !== undefined) {\n this.indices = Object.assign({}, this.indices);\n delete this.indices.isIndexed;\n }\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n /** \n * Return an object with all attributes plus indices added as a field.\n * TODO Geometry types are a mess\n */\n getAttributes(): GeometryAttributes {\n return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;\n }\n\n // PRIVATE\n\n _print(attributeName: string): string {\n return `Geometry ${this.id} attribute ${attributeName}`;\n }\n\n /**\n * GeometryAttribute\n * value: typed array\n * type: indices, vertices, uvs\n * size: elements per vertex\n * target: WebGL buffer type (string or constant)\n * \n * @param attributes \n * @param indices \n * @returns \n */\n _setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {\n return this;\n }\n\n _calculateVertexCount(attributes: GeometryAttributes, indices: GeometryAttribute): number {\n if (indices) {\n return indices.value.length;\n }\n let vertexCount = Infinity;\n for (const attribute of Object.values(attributes)) {\n const {value, size, constant} = attribute;\n if (!constant && value && size >= 1) {\n vertexCount = Math.min(vertexCount, value.length / size);\n }\n }\n\n assert(Number.isFinite(vertexCount));\n return vertexCount;\n }\n}\n"],"mappings":"AAEA,SAAQA,GAAG,EAAEC,MAAM,QAAO,eAAe;AAiCzC,OAAO,MAAMC,QAAQ,CAAC;EAgBpBC,WAAWA,CAACC,KAAoB,EAAE;IAAA,KAfzBC,EAAE;IAAA,KAEFC,QAAQ;IAAA,KACRC,WAAW;IAAA,KACXC,OAAO;IAAA,KACPC,UAA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,CAACiC,MAAM,CAACC,QAAQ,CAAC5B,WAAW,CAAC,CAAC;IACpC,OAAOA,WAAW;EACpB;AACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PrimitiveTopology, BufferLayout } from '@luma.gl/core';
|
|
2
|
+
import { Device, Buffer } from '@luma.gl/core';
|
|
3
|
+
import type { Geometry } from '../geometry/geometry';
|
|
4
|
+
export type GPUGeometryProps = {
|
|
5
|
+
id?: string;
|
|
6
|
+
/** Determines how vertices are read from the 'vertex' attributes */
|
|
7
|
+
topology: 'point-list' | 'line-list' | 'line-strip' | 'line-loop-webgl' | 'triangle-list' | 'triangle-strip' | 'triangle-fan-webgl';
|
|
8
|
+
/** Auto calculated from attributes if not provided */
|
|
9
|
+
vertexCount: number;
|
|
10
|
+
bufferLayout: BufferLayout[];
|
|
11
|
+
indices?: Buffer | null;
|
|
12
|
+
attributes: Record<string, Buffer>;
|
|
13
|
+
};
|
|
14
|
+
export declare class GPUGeometry {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
userData: Record<string, unknown>;
|
|
17
|
+
/** Determines how vertices are read from the 'vertex' attributes */
|
|
18
|
+
readonly topology?: PrimitiveTopology;
|
|
19
|
+
readonly bufferLayout: BufferLayout[];
|
|
20
|
+
readonly vertexCount: number;
|
|
21
|
+
readonly indices?: Buffer | null;
|
|
22
|
+
readonly attributes: Record<string, Buffer>;
|
|
23
|
+
constructor(props: GPUGeometryProps);
|
|
24
|
+
destroy(): void;
|
|
25
|
+
getVertexCount(): number;
|
|
26
|
+
getAttributes(): Record<string, Buffer>;
|
|
27
|
+
getIndexes(): Buffer | null;
|
|
28
|
+
_calculateVertexCount(positions: Buffer): number;
|
|
29
|
+
}
|
|
30
|
+
export declare function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry;
|
|
31
|
+
export declare function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined;
|
|
32
|
+
export declare function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): {
|
|
33
|
+
attributes: Record<string, Buffer>;
|
|
34
|
+
bufferLayout: BufferLayout[];
|
|
35
|
+
vertexCount: number;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=gpu-geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-geometry.d.ts","sourceRoot":"","sources":["../../src/geometry/gpu-geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AACnE,OAAO,EAAC,MAAM,EAAE,MAAM,EAA4C,MAAM,eAAe,CAAC;AACxF,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,QAAQ,EACJ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,iBAAiB,GACjB,eAAe,GACf,gBAAgB,GAChB,oBAAoB,CAAC;IACzB,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC,CAAC;AAEF,qBAAa,WAAW;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IAEvC,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,YAAY,EAAE,CAAM;IAE3C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEhC,KAAK,EAAE,gBAAgB;IAenC,OAAO,IAAI,IAAI;IAQf,cAAc,IAAI,MAAM;IAIxB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIvC,UAAU,IAAI,MAAM,GAAG,IAAI;IAI3B,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAKjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,WAAW,CAc7F;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAMjG;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,GACjB;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,YAAY,EAAE,YAAY,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,CAqBzF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Buffer, uid, assert, getVertexFormatFromAttribute } from '@luma.gl/core';
|
|
2
|
+
export class GPUGeometry {
|
|
3
|
+
constructor(props) {
|
|
4
|
+
this.id = void 0;
|
|
5
|
+
this.userData = {};
|
|
6
|
+
this.topology = void 0;
|
|
7
|
+
this.bufferLayout = [];
|
|
8
|
+
this.vertexCount = void 0;
|
|
9
|
+
this.indices = void 0;
|
|
10
|
+
this.attributes = void 0;
|
|
11
|
+
this.id = props.id || uid('geometry');
|
|
12
|
+
this.topology = props.topology;
|
|
13
|
+
this.indices = props.indices || null;
|
|
14
|
+
this.attributes = props.attributes;
|
|
15
|
+
this.vertexCount = props.vertexCount;
|
|
16
|
+
this.bufferLayout = props.bufferLayout || [];
|
|
17
|
+
if (this.indices) {
|
|
18
|
+
assert(this.indices.usage === Buffer.INDEX);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
destroy() {
|
|
22
|
+
var _this$attributes$colo;
|
|
23
|
+
this.indices.destroy();
|
|
24
|
+
this.attributes.positions.destroy();
|
|
25
|
+
this.attributes.normals.destroy();
|
|
26
|
+
this.attributes.texCoords.destroy();
|
|
27
|
+
(_this$attributes$colo = this.attributes.colors) === null || _this$attributes$colo === void 0 ? void 0 : _this$attributes$colo.destroy();
|
|
28
|
+
}
|
|
29
|
+
getVertexCount() {
|
|
30
|
+
return this.vertexCount;
|
|
31
|
+
}
|
|
32
|
+
getAttributes() {
|
|
33
|
+
return this.attributes;
|
|
34
|
+
}
|
|
35
|
+
getIndexes() {
|
|
36
|
+
return this.indices;
|
|
37
|
+
}
|
|
38
|
+
_calculateVertexCount(positions) {
|
|
39
|
+
const vertexCount = positions.byteLength / 12;
|
|
40
|
+
return vertexCount;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function makeGPUGeometry(device, geometry) {
|
|
44
|
+
if (geometry instanceof GPUGeometry) {
|
|
45
|
+
return geometry;
|
|
46
|
+
}
|
|
47
|
+
const indices = getIndexBufferFromGeometry(device, geometry);
|
|
48
|
+
const {
|
|
49
|
+
attributes,
|
|
50
|
+
bufferLayout
|
|
51
|
+
} = getAttributeBuffersFromGeometry(device, geometry);
|
|
52
|
+
return new GPUGeometry({
|
|
53
|
+
topology: geometry.topology || 'triangle-list',
|
|
54
|
+
bufferLayout,
|
|
55
|
+
vertexCount: geometry.vertexCount,
|
|
56
|
+
indices,
|
|
57
|
+
attributes
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function getIndexBufferFromGeometry(device, geometry) {
|
|
61
|
+
if (!geometry.indices) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const data = geometry.indices.value;
|
|
65
|
+
return device.createBuffer({
|
|
66
|
+
usage: Buffer.INDEX,
|
|
67
|
+
data
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export function getAttributeBuffersFromGeometry(device, geometry) {
|
|
71
|
+
const bufferLayout = [];
|
|
72
|
+
const attributes = {};
|
|
73
|
+
for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
|
|
74
|
+
let name = attributeName;
|
|
75
|
+
switch (attributeName) {
|
|
76
|
+
case 'POSITION':
|
|
77
|
+
name = 'positions';
|
|
78
|
+
break;
|
|
79
|
+
case 'NORMAL':
|
|
80
|
+
name = 'normals';
|
|
81
|
+
break;
|
|
82
|
+
case 'TEXCOORD_0':
|
|
83
|
+
name = 'texCoords';
|
|
84
|
+
break;
|
|
85
|
+
case 'COLOR_0':
|
|
86
|
+
name = 'colors';
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
attributes[name] = device.createBuffer({
|
|
90
|
+
data: attribute.value,
|
|
91
|
+
id: `${attributeName}-buffer`
|
|
92
|
+
});
|
|
93
|
+
const {
|
|
94
|
+
value,
|
|
95
|
+
size,
|
|
96
|
+
normalized
|
|
97
|
+
} = attribute;
|
|
98
|
+
bufferLayout.push({
|
|
99
|
+
name,
|
|
100
|
+
format: getVertexFormatFromAttribute(value, size, normalized)
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
|
|
104
|
+
return {
|
|
105
|
+
attributes,
|
|
106
|
+
bufferLayout,
|
|
107
|
+
vertexCount
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=gpu-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-geometry.js","names":["Buffer","uid","assert","getVertexFormatFromAttribute","GPUGeometry","constructor","props","id","userData","topology","bufferLayout","vertexCount","indices","attributes","usage","INDEX","destroy","_this$attributes$colo","positions","normals","texCoords","colors","getVertexCount","getAttributes","getIndexes","_calculateVertexCount","byteLength","makeGPUGeometry","device","geometry","getIndexBufferFromGeometry","getAttributeBuffersFromGeometry","undefined","data","value","createBuffer","attributeName","attribute","Object","entries","name","size","normalized","push","format"],"sources":["../../src/geometry/gpu-geometry.ts"],"sourcesContent":["import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';\nimport {Device, Buffer, uid, assert, getVertexFormatFromAttribute} from '@luma.gl/core';\nimport type {Geometry} from '../geometry/geometry';\n\nexport type GPUGeometryProps = {\n id?: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology:\n | 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'line-loop-webgl'\n | 'triangle-list'\n | 'triangle-strip'\n | 'triangle-fan-webgl';\n /** Auto calculated from attributes if not provided */\n vertexCount: number;\n bufferLayout: BufferLayout[];\n indices?: Buffer | null;\n attributes: Record<string, Buffer>;\n};\n\nexport class GPUGeometry {\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n readonly topology?: PrimitiveTopology;\n readonly bufferLayout: BufferLayout[] = [];\n\n readonly vertexCount: number;\n readonly indices?: Buffer | null;\n readonly attributes: Record<string, Buffer>;\n\n constructor(props: GPUGeometryProps) {\n this.id = props.id || uid('geometry');\n this.topology = props.topology;\n this.indices = props.indices || null;\n this.attributes = props.attributes;\n\n this.vertexCount = props.vertexCount;\n\n this.bufferLayout = props.bufferLayout || [];\n\n if (this.indices) {\n assert(this.indices.usage === Buffer.INDEX);\n }\n }\n\n destroy(): void {\n this.indices.destroy();\n this.attributes.positions.destroy();\n this.attributes.normals.destroy();\n this.attributes.texCoords.destroy();\n this.attributes.colors?.destroy();\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n getAttributes(): Record<string, Buffer> {\n return this.attributes;\n }\n\n getIndexes(): Buffer | null {\n return this.indices;\n }\n\n _calculateVertexCount(positions: Buffer): number {\n // Assume that positions is a fully packed float32x3 buffer\n const vertexCount = positions.byteLength / 12;\n return vertexCount;\n }\n}\n\nexport function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry {\n if (geometry instanceof GPUGeometry) {\n return geometry;\n }\n\n const indices = getIndexBufferFromGeometry(device, geometry);\n const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, geometry);\n return new GPUGeometry({\n topology: geometry.topology || 'triangle-list',\n bufferLayout,\n vertexCount: geometry.vertexCount,\n indices,\n attributes\n });\n}\n\nexport function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {\n if (!geometry.indices) {\n return undefined;\n }\n const data = geometry.indices.value;\n return device.createBuffer({usage: Buffer.INDEX, data});\n}\n\nexport function getAttributeBuffersFromGeometry(\n device: Device,\n geometry: Geometry\n): {attributes: Record<string, Buffer>, bufferLayout: BufferLayout[], vertexCount: number} {\n const bufferLayout: BufferLayout[] = [];\n\n const attributes: Record<string, Buffer> = {};\n for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {\n let name: string = attributeName;\n // TODO Map some GLTF attribute names (is this still needed?)\n switch (attributeName) {\n case 'POSITION': name = 'positions'; break;\n case 'NORMAL': name = 'normals'; break;\n case 'TEXCOORD_0': name = 'texCoords'; break;\n case 'COLOR_0': name = 'colors'; break;\n }\n attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});\n const {value, size, normalized} = attribute;\n bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});\n }\n\n const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)\n\n return {attributes, bufferLayout, vertexCount};\n}\n"],"mappings":"AACA,SAAgBA,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,4BAA4B,QAAO,eAAe;AAqBvF,OAAO,MAAMC,WAAW,CAAC;EAYvBC,WAAWA,CAACC,KAAuB,EAAE;IAAA,KAX5BC,EAAE;IAAA,KACXC,QAAQ,GAA4B,CAAC,CAAC;IAAA,KAG7BC,QAAQ;IAAA,KACRC,YAAY,GAAmB,EAAE;IAAA,KAEjCC,WAAW;IAAA,KACXC,OAAO;IAAA,KACPC,UAAU;IAGjB,IAAI,CAACN,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QAAE;IACnC;IACA3B,UAAU,CAAC2B,IAAI,CAAC,GAAGZ,MAAM,CAACO,YAAY,CAAC;MAACF,IAAI,EAAEI,SAAS,CAACH,KAAK;MAAE3B,EAAE,EAAG,GAAE6B,aAAc;IAAQ,CAAC,CAAC;IAC9F,MAAM;MAACF,KAAK;MAAEO,IAAI;MAAEC;IAAU,CAAC,GAAGL,SAAS;IAC3C3B,YAAY,CAACiC,IAAI,CAAC;MAACH,IAAI;MAAEI,MAAM,EAAEzC,4BAA4B,CAAC+B,KAAK,EAAEO,IAAI,EAAEC,UAAU;IAAC,CAAC,CAAC;EAC1F;EAEA,MAAM/B,WAAW,GAAGkB,QAAQ,CAACJ,qBAAqB,CAACI,QAAQ,CAAChB,UAAU,EAAEgB,QAAQ,CAACjB,OAAO,CAAC;EAEzF,OAAO;IAACC,UAAU;IAAEH,YAAY;IAAEC;EAAW,CAAC;AAChD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=gpu-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-table.d.ts","sourceRoot":"","sources":["../../src/geometry/gpu-table.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-table.js","names":[],"sources":["../../src/geometry/gpu-table.ts"],"sourcesContent":["/*\nexport function getAttributeLayoutsFromGeometry(geometry: Geometry) {\n const layouts: Record<string, {}> = {};\n let indices = geometry.indices;\n\n for (const [name, attribute] of Object.entries(geometry.attributes)) {\n const remappedName = mapAttributeName(name);\n\n if (attribute.constant) {\n throw new Error('constant attributes not supported');\n } else {\n const typedArray = attribute.value;\n // Create accessor by copying the attribute and removing `value``\n const accessor = {...attribute};\n delete accessor.value;\n buffers[remappedName] = [device.createBuffer(typedArray), accessor];\n\n inferAttributeAccessor(name, accessor);\n }\n }\n}\n\nexport class Table {\n length: number;\n // columns: Record<string, TypedArray> = {};\n}\n\nexport class GPUTable {\n length: number;\n columns: Record<string, Buffer> = {};\n}\n\nexport function convertTableToGPUTable(table: Table) {\n // for (const ) {}\n}\n\nexport function renameTableColumns(table: Table, map: (name: string) => string) {\n const newColumns = table.columns.reduce()\n table.clone();\n}\n*/\n"],"mappings":""}
|