@kitware/vtk.js 24.5.6 → 24.6.0
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/Common/Core/CellArray.js +14 -3
- package/Rendering/Core/Mapper.js +1 -1
- package/Rendering/WebGPU/BindGroup.js +1 -1
- package/Rendering/WebGPU/BufferManager/Constants.js +1 -1
- package/Rendering/WebGPU/BufferManager.js +92 -275
- package/Rendering/WebGPU/CellArrayMapper.js +45 -34
- package/Rendering/WebGPU/IndexBuffer.js +397 -0
- package/Rendering/WebGPU/RenderEncoder.js +1 -1
- package/Rendering/WebGPU/SimpleMapper.js +7 -1
- package/Rendering/WebGPU/VertexInput.js +7 -2
- package/Rendering/WebGPU/VolumePass.js +15 -5
- package/package.json +1 -1
package/Common/Core/CellArray.js
CHANGED
|
@@ -22,7 +22,14 @@ function extractCellSizes(cellArray) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function getNumberOfCells(cellArray) {
|
|
25
|
-
|
|
25
|
+
var cellId = 0;
|
|
26
|
+
|
|
27
|
+
for (var cellArrayIndex = 0; cellArrayIndex < cellArray.length;) {
|
|
28
|
+
cellArrayIndex += cellArray[cellArrayIndex] + 1;
|
|
29
|
+
cellId++;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return cellId;
|
|
26
33
|
} // ----------------------------------------------------------------------------
|
|
27
34
|
// Static API
|
|
28
35
|
// ----------------------------------------------------------------------------
|
|
@@ -44,8 +51,12 @@ function vtkCellArray(publicAPI, model) {
|
|
|
44
51
|
return model.numberOfCells;
|
|
45
52
|
}
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
if (model.cellSizes) {
|
|
55
|
+
model.numberOfCells = model.cellSizes.length;
|
|
56
|
+
} else {
|
|
57
|
+
model.numberOfCells = getNumberOfCells(model.values);
|
|
58
|
+
}
|
|
59
|
+
|
|
49
60
|
return model.numberOfCells;
|
|
50
61
|
};
|
|
51
62
|
|
package/Rendering/Core/Mapper.js
CHANGED
|
@@ -445,7 +445,7 @@ function vtkMapper(publicAPI, model) {
|
|
|
445
445
|
points: input.getPoints().getNumberOfValues() / 3,
|
|
446
446
|
verts: input.getVerts().getNumberOfValues() - input.getVerts().getNumberOfCells(),
|
|
447
447
|
lines: input.getLines().getNumberOfValues() - 2 * input.getLines().getNumberOfCells(),
|
|
448
|
-
triangles: input.getPolys().getNumberOfValues() - 3 * input.
|
|
448
|
+
triangles: input.getPolys().getNumberOfValues() - 3 * input.getPolys().getNumberOfCells()
|
|
449
449
|
};
|
|
450
450
|
return pcount;
|
|
451
451
|
};
|
|
@@ -105,7 +105,7 @@ function extend(publicAPI, model) {
|
|
|
105
105
|
mtime: 0
|
|
106
106
|
});
|
|
107
107
|
macro.get(publicAPI, model, ['bindGroupTime', 'handle', 'sizeInBytes', 'usage']);
|
|
108
|
-
macro.setGet(publicAPI, model, ['label', 'device', 'arrayInformation'
|
|
108
|
+
macro.setGet(publicAPI, model, ['label', 'device', 'arrayInformation']);
|
|
109
109
|
vtkWebGPUBindGroup(publicAPI, model);
|
|
110
110
|
} // ----------------------------------------------------------------------------
|
|
111
111
|
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { newInstance as newInstance$1, obj, setGet, vtkErrorMacro as vtkErrorMacro$1, newTypedArray
|
|
2
|
+
import { newInstance as newInstance$1, obj, setGet, vtkErrorMacro as vtkErrorMacro$1, newTypedArray } from '../../macros.js';
|
|
3
3
|
import { j as cross, l as normalize } from '../../Common/Core/Math/index.js';
|
|
4
4
|
import vtkDataArray from '../../Common/Core/DataArray.js';
|
|
5
5
|
import vtkWebGPUBuffer from './Buffer.js';
|
|
6
|
+
import vtkWebGPUIndexBuffer from './IndexBuffer.js';
|
|
6
7
|
import vtkWebGPUTypes from './Types.js';
|
|
7
|
-
import vtkProperty from '../Core/Property.js';
|
|
8
8
|
import Constants from './BufferManager/Constants.js';
|
|
9
9
|
|
|
10
10
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
11
|
|
|
12
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
var BufferUsage = Constants.BufferUsage
|
|
14
|
-
|
|
15
|
-
var Representation = vtkProperty.Representation;
|
|
16
|
-
var vtkDebugMacro = vtkDebugMacro$1,
|
|
17
|
-
vtkErrorMacro = vtkErrorMacro$1;
|
|
13
|
+
var BufferUsage = Constants.BufferUsage;
|
|
14
|
+
var vtkErrorMacro = vtkErrorMacro$1;
|
|
18
15
|
var VtkDataTypes = vtkDataArray.VtkDataTypes; // the webgpu constants all show up as undefined
|
|
19
16
|
|
|
20
17
|
/* eslint-disable no-undef */
|
|
@@ -23,47 +20,6 @@ var VtkDataTypes = vtkDataArray.VtkDataTypes; // the webgpu constants all show u
|
|
|
23
20
|
// ----------------------------------------------------------------------------
|
|
24
21
|
|
|
25
22
|
var STATIC = {};
|
|
26
|
-
var cellCounters = {
|
|
27
|
-
// easy, every input point becomes an output point
|
|
28
|
-
anythingToPoints: function anythingToPoints(numPoints, cellPts) {
|
|
29
|
-
return numPoints;
|
|
30
|
-
},
|
|
31
|
-
linesToWireframe: function linesToWireframe(numPoints, cellPts) {
|
|
32
|
-
if (numPoints > 1) {
|
|
33
|
-
return (numPoints - 1) * 2;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return 0;
|
|
37
|
-
},
|
|
38
|
-
polysToWireframe: function polysToWireframe(numPoints, cellPts) {
|
|
39
|
-
if (numPoints > 2) {
|
|
40
|
-
return numPoints * 2;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return 0;
|
|
44
|
-
},
|
|
45
|
-
stripsToWireframe: function stripsToWireframe(numPoints, cellPts) {
|
|
46
|
-
if (numPoints > 2) {
|
|
47
|
-
return numPoints * 4 - 6;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return 0;
|
|
51
|
-
},
|
|
52
|
-
polysToSurface: function polysToSurface(npts, cellPts) {
|
|
53
|
-
if (npts > 2) {
|
|
54
|
-
return (npts - 2) * 3;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return 0;
|
|
58
|
-
},
|
|
59
|
-
stripsToSurface: function stripsToSurface(npts, cellPts, offset) {
|
|
60
|
-
if (numPoints > 2) {
|
|
61
|
-
return (npts - 2) * 3;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return 0;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
23
|
|
|
68
24
|
function _getFormatForDataArray(dataArray) {
|
|
69
25
|
var format;
|
|
@@ -124,58 +80,11 @@ function _getFormatForDataArray(dataArray) {
|
|
|
124
80
|
return format;
|
|
125
81
|
}
|
|
126
82
|
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return 'points';
|
|
131
|
-
|
|
132
|
-
case PrimitiveTypes.Lines:
|
|
133
|
-
return 'lines';
|
|
134
|
-
|
|
135
|
-
case PrimitiveTypes.Triangles:
|
|
136
|
-
case PrimitiveTypes.TriangleEdges:
|
|
137
|
-
return 'polys';
|
|
138
|
-
|
|
139
|
-
case PrimitiveTypes.TriangleStripEdges:
|
|
140
|
-
case PrimitiveTypes.TriangleStrips:
|
|
141
|
-
return 'strips';
|
|
142
|
-
|
|
143
|
-
default:
|
|
144
|
-
return '';
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function getOutputSize(cellArray, representation, inRepName) {
|
|
149
|
-
var countFunc = null;
|
|
150
|
-
|
|
151
|
-
if (representation === Representation.POINTS || inRepName === 'points') {
|
|
152
|
-
countFunc = cellCounters.anythingToPoints;
|
|
153
|
-
} else if (representation === Representation.WIREFRAME || inRepName === 'lines') {
|
|
154
|
-
countFunc = cellCounters["".concat(inRepName, "ToWireframe")];
|
|
155
|
-
} else {
|
|
156
|
-
countFunc = cellCounters["".concat(inRepName, "ToSurface")];
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
var array = cellArray.getData();
|
|
160
|
-
var size = array.length;
|
|
161
|
-
var caboCount = 0;
|
|
162
|
-
|
|
163
|
-
for (var index = 0; index < size;) {
|
|
164
|
-
caboCount += countFunc(array[index], array);
|
|
165
|
-
index += array[index] + 1;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return caboCount;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function packArray(cellArray, primType, representation, inArray, outputType, options) {
|
|
172
|
-
var result = {
|
|
173
|
-
elementCount: 0,
|
|
174
|
-
blockSize: 0,
|
|
175
|
-
stride: 0
|
|
176
|
-
};
|
|
83
|
+
function packArray(indexBuffer, inArrayData, numComp, outputType, options) {
|
|
84
|
+
var result = {};
|
|
85
|
+
var flatSize = indexBuffer.getFlatSize();
|
|
177
86
|
|
|
178
|
-
if (!
|
|
87
|
+
if (!flatSize) {
|
|
179
88
|
return result;
|
|
180
89
|
} // setup shift and scale
|
|
181
90
|
|
|
@@ -201,130 +110,56 @@ function packArray(cellArray, primType, representation, inArray, outputType, opt
|
|
|
201
110
|
}
|
|
202
111
|
|
|
203
112
|
var packExtra = Object.prototype.hasOwnProperty.call(options, 'packExtra') ? options.packExtra : false;
|
|
204
|
-
var pointData = inArray.getData();
|
|
205
113
|
var addAPoint;
|
|
206
|
-
var cellBuilders = {
|
|
207
|
-
// easy, every input point becomes an output point
|
|
208
|
-
anythingToPoints: function anythingToPoints(numPoints, cellPts, offset, cellId) {
|
|
209
|
-
for (var i = 0; i < numPoints; ++i) {
|
|
210
|
-
addAPoint(cellPts[offset + i], cellId);
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
linesToWireframe: function linesToWireframe(numPoints, cellPts, offset, cellId) {
|
|
214
|
-
// for lines we add a bunch of segments
|
|
215
|
-
for (var i = 0; i < numPoints - 1; ++i) {
|
|
216
|
-
addAPoint(cellPts[offset + i], cellId);
|
|
217
|
-
addAPoint(cellPts[offset + i + 1], cellId);
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
polysToWireframe: function polysToWireframe(numPoints, cellPts, offset, cellId) {
|
|
221
|
-
// for polys we add a bunch of segments and close it
|
|
222
|
-
if (numPoints > 2) {
|
|
223
|
-
for (var i = 0; i < numPoints; ++i) {
|
|
224
|
-
addAPoint(cellPts[offset + i], cellId);
|
|
225
|
-
addAPoint(cellPts[offset + (i + 1) % numPoints], cellId);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
stripsToWireframe: function stripsToWireframe(numPoints, cellPts, offset, cellId) {
|
|
230
|
-
if (numPoints > 2) {
|
|
231
|
-
// for strips we add a bunch of segments and close it
|
|
232
|
-
for (var i = 0; i < numPoints - 1; ++i) {
|
|
233
|
-
addAPoint(cellPts[offset + i], cellId);
|
|
234
|
-
addAPoint(cellPts[offset + i + 1], cellId);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
for (var _i = 0; _i < numPoints - 2; _i++) {
|
|
238
|
-
addAPoint(cellPts[offset + _i], cellId);
|
|
239
|
-
addAPoint(cellPts[offset + _i + 2], cellId);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
polysToSurface: function polysToSurface(npts, cellPts, offset, cellId) {
|
|
244
|
-
for (var i = 0; i < npts - 2; i++) {
|
|
245
|
-
addAPoint(cellPts[offset + 0], cellId);
|
|
246
|
-
addAPoint(cellPts[offset + i + 1], cellId);
|
|
247
|
-
addAPoint(cellPts[offset + i + 2], cellId);
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
stripsToSurface: function stripsToSurface(npts, cellPts, offset, cellId) {
|
|
251
|
-
for (var i = 0; i < npts - 2; i++) {
|
|
252
|
-
addAPoint(cellPts[offset + i], cellId);
|
|
253
|
-
addAPoint(cellPts[offset + i + 1 + i % 2], cellId);
|
|
254
|
-
addAPoint(cellPts[offset + i + 1 + (i + 1) % 2], cellId);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
var inRepName = getPrimitiveName(primType);
|
|
259
|
-
var func = null;
|
|
260
|
-
|
|
261
|
-
if (representation === Representation.POINTS || primType === PrimitiveTypes.Points) {
|
|
262
|
-
func = cellBuilders.anythingToPoints;
|
|
263
|
-
} else if (representation === Representation.WIREFRAME || primType === PrimitiveTypes.Lines) {
|
|
264
|
-
func = cellBuilders["".concat(inRepName, "ToWireframe")];
|
|
265
|
-
} else {
|
|
266
|
-
func = cellBuilders["".concat(inRepName, "ToSurface")];
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
var array = cellArray.getData();
|
|
270
|
-
var size = array.length;
|
|
271
|
-
var caboCount = getOutputSize(cellArray, representation, inRepName);
|
|
272
114
|
var vboidx = 0;
|
|
273
|
-
var
|
|
274
|
-
var packedVBO = newTypedArray(outputType,
|
|
115
|
+
var stride = numComp + (packExtra ? 1 : 0);
|
|
116
|
+
var packedVBO = newTypedArray(outputType, flatSize * stride); // pick the right function based on point versus cell data
|
|
275
117
|
|
|
276
|
-
var
|
|
277
|
-
return pointData[ptId];
|
|
278
|
-
};
|
|
118
|
+
var flatIdMap = indexBuffer.getFlatIdToPointId();
|
|
279
119
|
|
|
280
120
|
if (options.cellData) {
|
|
281
|
-
|
|
282
|
-
return pointData[cellId];
|
|
283
|
-
};
|
|
121
|
+
flatIdMap = indexBuffer.getFlatIdToCellId();
|
|
284
122
|
} // add data based on number of components
|
|
285
123
|
|
|
286
124
|
|
|
287
125
|
if (numComp === 1) {
|
|
288
|
-
addAPoint = function addAPointFunc(i
|
|
289
|
-
packedVBO[vboidx++] = scale[0] *
|
|
126
|
+
addAPoint = function addAPointFunc(i) {
|
|
127
|
+
packedVBO[vboidx++] = scale[0] * inArrayData[i] + shift[0];
|
|
290
128
|
};
|
|
291
129
|
} else if (numComp === 2) {
|
|
292
|
-
addAPoint = function addAPointFunc(i
|
|
293
|
-
packedVBO[vboidx++] = scale[0] *
|
|
294
|
-
packedVBO[vboidx++] = scale[1] *
|
|
130
|
+
addAPoint = function addAPointFunc(i) {
|
|
131
|
+
packedVBO[vboidx++] = scale[0] * inArrayData[i] + shift[0];
|
|
132
|
+
packedVBO[vboidx++] = scale[1] * inArrayData[i + 1] + shift[1];
|
|
295
133
|
};
|
|
296
134
|
} else if (numComp === 3 && !packExtra) {
|
|
297
|
-
addAPoint = function addAPointFunc(i
|
|
298
|
-
packedVBO[vboidx++] = scale[0] *
|
|
299
|
-
packedVBO[vboidx++] = scale[1] *
|
|
300
|
-
packedVBO[vboidx++] = scale[2] *
|
|
135
|
+
addAPoint = function addAPointFunc(i) {
|
|
136
|
+
packedVBO[vboidx++] = scale[0] * inArrayData[i] + shift[0];
|
|
137
|
+
packedVBO[vboidx++] = scale[1] * inArrayData[i + 1] + shift[1];
|
|
138
|
+
packedVBO[vboidx++] = scale[2] * inArrayData[i + 2] + shift[2];
|
|
301
139
|
};
|
|
302
140
|
} else if (numComp === 3 && packExtra) {
|
|
303
|
-
addAPoint = function addAPointFunc(i
|
|
304
|
-
packedVBO[vboidx++] = scale[0] *
|
|
305
|
-
packedVBO[vboidx++] = scale[1] *
|
|
306
|
-
packedVBO[vboidx++] = scale[2] *
|
|
141
|
+
addAPoint = function addAPointFunc(i) {
|
|
142
|
+
packedVBO[vboidx++] = scale[0] * inArrayData[i] + shift[0];
|
|
143
|
+
packedVBO[vboidx++] = scale[1] * inArrayData[i + 1] + shift[1];
|
|
144
|
+
packedVBO[vboidx++] = scale[2] * inArrayData[i + 2] + shift[2];
|
|
307
145
|
packedVBO[vboidx++] = scale[3] * 1.0 + shift[3];
|
|
308
146
|
};
|
|
309
147
|
} else if (numComp === 4) {
|
|
310
|
-
addAPoint = function addAPointFunc(i
|
|
311
|
-
packedVBO[vboidx++] = scale[0] *
|
|
312
|
-
packedVBO[vboidx++] = scale[1] *
|
|
313
|
-
packedVBO[vboidx++] = scale[2] *
|
|
314
|
-
packedVBO[vboidx++] = scale[3] *
|
|
148
|
+
addAPoint = function addAPointFunc(i) {
|
|
149
|
+
packedVBO[vboidx++] = scale[0] * inArrayData[i] + shift[0];
|
|
150
|
+
packedVBO[vboidx++] = scale[1] * inArrayData[i + 1] + shift[1];
|
|
151
|
+
packedVBO[vboidx++] = scale[2] * inArrayData[i + 2] + shift[2];
|
|
152
|
+
packedVBO[vboidx++] = scale[3] * inArrayData[i + 3] + shift[3];
|
|
315
153
|
};
|
|
316
|
-
}
|
|
154
|
+
} // for each entry in the flat array process it
|
|
317
155
|
|
|
318
|
-
var cellId = options.cellOffset;
|
|
319
156
|
|
|
320
|
-
for (var index = 0; index <
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
cellId++;
|
|
157
|
+
for (var index = 0; index < flatSize; index++) {
|
|
158
|
+
var inArrayId = numComp * flatIdMap[index];
|
|
159
|
+
addAPoint(inArrayId);
|
|
324
160
|
}
|
|
325
161
|
|
|
326
162
|
result.nativeArray = packedVBO;
|
|
327
|
-
result.elementCount = caboCount;
|
|
328
163
|
return result;
|
|
329
164
|
}
|
|
330
165
|
|
|
@@ -337,75 +172,26 @@ function getNormal(pointData, i0, i1, i2) {
|
|
|
337
172
|
return result;
|
|
338
173
|
}
|
|
339
174
|
|
|
340
|
-
function generateNormals(cellArray,
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
175
|
+
function generateNormals(cellArray, pointArray) {
|
|
176
|
+
var pointData = pointArray.getData();
|
|
177
|
+
var cellArrayData = cellArray.getData();
|
|
344
178
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
polysToPoints: function polysToPoints(numPoints, cellPts, offset) {
|
|
349
|
-
var normal = getNormal(pointData, cellPts[offset], cellPts[offset + 1], cellPts[offset + 2]);
|
|
179
|
+
if (!cellArrayData || !pointData) {
|
|
180
|
+
return null;
|
|
181
|
+
} // return a cellArray of normals
|
|
350
182
|
|
|
351
|
-
for (var i = 0; i < numPoints; ++i) {
|
|
352
|
-
addAPoint(normal);
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
polysToWireframe: function polysToWireframe(numPoints, cellPts, offset) {
|
|
356
|
-
// for polys we add a bunch of segments and close it
|
|
357
|
-
// compute the normal
|
|
358
|
-
var normal = getNormal(pointData, cellPts[offset], cellPts[offset + 1], cellPts[offset + 2]);
|
|
359
|
-
|
|
360
|
-
for (var i = 0; i < numPoints; ++i) {
|
|
361
|
-
addAPoint(normal);
|
|
362
|
-
addAPoint(normal);
|
|
363
|
-
}
|
|
364
|
-
},
|
|
365
|
-
polysToSurface: function polysToSurface(npts, cellPts, offset) {
|
|
366
|
-
if (npts < 3) {
|
|
367
|
-
// ignore degenerate triangles
|
|
368
|
-
vtkDebugMacro('skipping degenerate triangle');
|
|
369
|
-
} else {
|
|
370
|
-
// compute the normal
|
|
371
|
-
var normal = getNormal(pointData, cellPts[offset], cellPts[offset + 1], cellPts[offset + 2]);
|
|
372
|
-
|
|
373
|
-
for (var i = 0; i < npts - 2; i++) {
|
|
374
|
-
addAPoint(normal);
|
|
375
|
-
addAPoint(normal);
|
|
376
|
-
addAPoint(normal);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
var primName = getPrimitiveName(primType);
|
|
382
|
-
var func = null;
|
|
383
|
-
|
|
384
|
-
if (representation === Representation.POINTS) {
|
|
385
|
-
func = cellBuilders["".concat(primName, "ToPoints")];
|
|
386
|
-
} else if (representation === Representation.WIREFRAME) {
|
|
387
|
-
func = cellBuilders["".concat(primName, "ToWireframe")];
|
|
388
|
-
} else {
|
|
389
|
-
func = cellBuilders["".concat(primName, "ToSurface")];
|
|
390
|
-
}
|
|
391
183
|
|
|
392
|
-
var
|
|
184
|
+
var packedVBO = new Int8Array(cellArray.getNumberOfCells() * 4);
|
|
185
|
+
var size = cellArrayData.length;
|
|
393
186
|
var vboidx = 0;
|
|
394
|
-
var packedVBO = new Int8Array(caboCount * 4);
|
|
395
187
|
|
|
396
|
-
|
|
188
|
+
for (var index = 0; index < size;) {
|
|
189
|
+
var normal = getNormal(pointData, cellArrayData[index + 1], cellArrayData[index + 2], cellArrayData[index + 3]);
|
|
397
190
|
packedVBO[vboidx++] = 127 * normal[0];
|
|
398
191
|
packedVBO[vboidx++] = 127 * normal[1];
|
|
399
192
|
packedVBO[vboidx++] = 127 * normal[2];
|
|
400
193
|
packedVBO[vboidx++] = 127;
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
var array = cellArray.getData();
|
|
404
|
-
var size = array.length;
|
|
405
|
-
|
|
406
|
-
for (var index = 0; index < size;) {
|
|
407
|
-
func(array[index], array, index + 1);
|
|
408
|
-
index += array[index] + 1;
|
|
194
|
+
index += cellArrayData[index] + 1;
|
|
409
195
|
}
|
|
410
196
|
|
|
411
197
|
return packedVBO;
|
|
@@ -422,14 +208,37 @@ function vtkWebGPUBufferManager(publicAPI, model) {
|
|
|
422
208
|
// if a dataArray is provided set the nativeArray
|
|
423
209
|
if (req.dataArray && !req.nativeArray) {
|
|
424
210
|
req.nativeArray = req.dataArray.getData();
|
|
425
|
-
}
|
|
211
|
+
}
|
|
426
212
|
|
|
213
|
+
var buffer;
|
|
214
|
+
var gpuUsage; // handle index buffers
|
|
215
|
+
|
|
216
|
+
if (req.usage === BufferUsage.Index) {
|
|
217
|
+
// todo change to FlattenedIndex to be more clear
|
|
218
|
+
buffer = vtkWebGPUIndexBuffer.newInstance({
|
|
219
|
+
label: req.label
|
|
220
|
+
});
|
|
221
|
+
buffer.setDevice(model.device);
|
|
222
|
+
/* eslint-disable no-bitwise */
|
|
223
|
+
|
|
224
|
+
gpuUsage = GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST;
|
|
225
|
+
/* eslint-enable no-bitwise */
|
|
226
|
+
|
|
227
|
+
buffer.buildIndexBuffer(req);
|
|
228
|
+
buffer.createAndWrite(req.nativeArray, gpuUsage);
|
|
229
|
+
buffer.setArrayInformation([{
|
|
230
|
+
format: req.format
|
|
231
|
+
}]);
|
|
232
|
+
} // create one if not done already
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
if (!buffer) {
|
|
236
|
+
buffer = vtkWebGPUBuffer.newInstance({
|
|
237
|
+
label: req.label
|
|
238
|
+
});
|
|
239
|
+
buffer.setDevice(model.device);
|
|
240
|
+
} // handle uniform buffers
|
|
427
241
|
|
|
428
|
-
var buffer = vtkWebGPUBuffer.newInstance({
|
|
429
|
-
label: req.label
|
|
430
|
-
});
|
|
431
|
-
buffer.setDevice(model.device);
|
|
432
|
-
var gpuUsage = null; // handle uniform buffers
|
|
433
242
|
|
|
434
243
|
if (req.usage === BufferUsage.UniformArray) {
|
|
435
244
|
/* eslint-disable no-bitwise */
|
|
@@ -463,7 +272,7 @@ function vtkWebGPUBufferManager(publicAPI, model) {
|
|
|
463
272
|
if (req.usage === BufferUsage.PointArray) {
|
|
464
273
|
gpuUsage = GPUBufferUsage.VERTEX;
|
|
465
274
|
var arrayType = vtkWebGPUTypes.getNativeTypeFromBufferFormat(req.format);
|
|
466
|
-
var result = packArray(req.
|
|
275
|
+
var result = packArray(req.indexBuffer, req.dataArray.getData(), req.dataArray.getNumberOfComponents(), arrayType, {
|
|
467
276
|
packExtra: req.packExtra,
|
|
468
277
|
shift: req.shift,
|
|
469
278
|
scale: req.scale,
|
|
@@ -474,19 +283,29 @@ function vtkWebGPUBufferManager(publicAPI, model) {
|
|
|
474
283
|
buffer.setStrideInBytes(vtkWebGPUTypes.getByteStrideFromBufferFormat(req.format));
|
|
475
284
|
buffer.setArrayInformation([{
|
|
476
285
|
offset: 0,
|
|
477
|
-
format: req.format
|
|
286
|
+
format: req.format,
|
|
287
|
+
interpolation: req.cellData ? 'flat' : 'perspective'
|
|
478
288
|
}]);
|
|
479
289
|
} // handle normals from points, snorm8x4
|
|
480
290
|
|
|
481
291
|
|
|
482
292
|
if (req.usage === BufferUsage.NormalsFromPoints) {
|
|
483
293
|
gpuUsage = GPUBufferUsage.VERTEX;
|
|
484
|
-
|
|
485
|
-
|
|
294
|
+
|
|
295
|
+
var _arrayType = vtkWebGPUTypes.getNativeTypeFromBufferFormat(req.format);
|
|
296
|
+
|
|
297
|
+
var normals = generateNormals(req.cells, req.dataArray);
|
|
298
|
+
|
|
299
|
+
var _result = packArray(req.indexBuffer, normals, 4, _arrayType, {
|
|
300
|
+
cellData: true
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
buffer.createAndWrite(_result.nativeArray, gpuUsage);
|
|
486
304
|
buffer.setStrideInBytes(vtkWebGPUTypes.getByteStrideFromBufferFormat(req.format));
|
|
487
305
|
buffer.setArrayInformation([{
|
|
488
306
|
offset: 0,
|
|
489
|
-
format: req.format
|
|
307
|
+
format: req.format,
|
|
308
|
+
interpolation: 'flat'
|
|
490
309
|
}]);
|
|
491
310
|
}
|
|
492
311
|
|
|
@@ -518,17 +337,15 @@ function vtkWebGPUBufferManager(publicAPI, model) {
|
|
|
518
337
|
return _createBuffer(req);
|
|
519
338
|
};
|
|
520
339
|
|
|
521
|
-
publicAPI.getBufferForPointArray = function (dataArray,
|
|
340
|
+
publicAPI.getBufferForPointArray = function (dataArray, indexBuffer) {
|
|
522
341
|
var format = _getFormatForDataArray(dataArray);
|
|
523
342
|
|
|
524
343
|
var buffRequest = {
|
|
525
|
-
hash: "
|
|
344
|
+
hash: "".concat(dataArray.getMTime(), "I").concat(indexBuffer.getMTime()).concat(format),
|
|
526
345
|
usage: BufferUsage.PointArray,
|
|
527
346
|
format: format,
|
|
528
347
|
dataArray: dataArray,
|
|
529
|
-
|
|
530
|
-
primitiveType: primitiveType,
|
|
531
|
-
representation: representation
|
|
348
|
+
indexBuffer: indexBuffer
|
|
532
349
|
};
|
|
533
350
|
return publicAPI.getBuffer(buffRequest);
|
|
534
351
|
};
|
|
@@ -121,9 +121,11 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
121
121
|
model.shaderReplacements.set('replaceShaderPosition', publicAPI.replaceShaderPosition);
|
|
122
122
|
|
|
123
123
|
publicAPI.replaceShaderNormal = function (hash, pipeline, vertexInput) {
|
|
124
|
-
|
|
124
|
+
var normalBuffer = vertexInput.getBuffer('normalMC');
|
|
125
|
+
|
|
126
|
+
if (normalBuffer) {
|
|
125
127
|
var vDesc = pipeline.getShaderDescription('vertex');
|
|
126
|
-
vDesc.addOutput('vec3<f32>', 'normalVC');
|
|
128
|
+
vDesc.addOutput('vec3<f32>', 'normalVC', normalBuffer.getArrayInformation()[0].interpolation);
|
|
127
129
|
var code = vDesc.getCode();
|
|
128
130
|
code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [' output.normalVC = normalize((rendererUBO.WCVCNormals * mapperUBO.MCWCNormals * normalMC).xyz);']).result;
|
|
129
131
|
vDesc.setCode(code);
|
|
@@ -165,9 +167,10 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
165
167
|
return;
|
|
166
168
|
}
|
|
167
169
|
|
|
168
|
-
|
|
170
|
+
var colorBuffer = vertexInput.getBuffer('colorVI');
|
|
171
|
+
if (!colorBuffer) return;
|
|
169
172
|
var vDesc = pipeline.getShaderDescription('vertex');
|
|
170
|
-
vDesc.addOutput('vec4<f32>', 'color');
|
|
173
|
+
vDesc.addOutput('vec4<f32>', 'color', colorBuffer.getArrayInformation()[0].interpolation);
|
|
171
174
|
var code = vDesc.getCode();
|
|
172
175
|
code = vtkWebGPUShaderCache.substitute(code, '//VTK::Color::Impl', [' output.color = colorVI;']).result;
|
|
173
176
|
vDesc.setCode(code);
|
|
@@ -276,35 +279,46 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
276
279
|
}
|
|
277
280
|
|
|
278
281
|
var vertexInput = model.vertexInput;
|
|
279
|
-
var
|
|
282
|
+
var points = pd.getPoints();
|
|
283
|
+
var indexBuffer; // get the flat mapping indexBuffer for the cells
|
|
284
|
+
|
|
285
|
+
if (cells) {
|
|
286
|
+
var buffRequest = {
|
|
287
|
+
hash: "R".concat(representation, "P").concat(primType).concat(cells.getMTime()),
|
|
288
|
+
usage: BufferUsage.Index,
|
|
289
|
+
cells: cells,
|
|
290
|
+
numberOfPoints: points.getNumberOfPoints(),
|
|
291
|
+
primitiveType: primType,
|
|
292
|
+
representation: representation
|
|
293
|
+
};
|
|
294
|
+
indexBuffer = device.getBufferManager().getBuffer(buffRequest);
|
|
295
|
+
vertexInput.setIndexBuffer(indexBuffer);
|
|
296
|
+
} else {
|
|
297
|
+
vertexInput.setIndexBuffer(null);
|
|
298
|
+
} // hash = all things that can change the values on the buffer
|
|
280
299
|
// since mtimes are unique we can use
|
|
281
|
-
// -
|
|
282
|
-
// - rep (point/wireframe/surface) - again because of packing
|
|
300
|
+
// - indexBuffer mtime - because cells drive how we pack
|
|
283
301
|
// - relevant dataArray mtime - the source data
|
|
284
302
|
// - shift - not currently captured
|
|
285
303
|
// - scale - not currently captured
|
|
286
304
|
// - format
|
|
287
305
|
// - usage
|
|
288
306
|
// - packExtra - covered by format
|
|
289
|
-
// - prim type (vert/lines/polys/strips) - covered by cells mtime
|
|
290
307
|
// points
|
|
291
308
|
|
|
292
|
-
var points = pd.getPoints();
|
|
293
309
|
|
|
294
310
|
if (points) {
|
|
295
311
|
var shift = model.WebGPUActor.getBufferShift(model.WebGPURenderer);
|
|
296
|
-
var
|
|
297
|
-
hash: "".concat(
|
|
312
|
+
var _buffRequest = {
|
|
313
|
+
hash: "".concat(points.getMTime(), "I").concat(indexBuffer.getMTime()).concat(shift.join(), "float32x4"),
|
|
298
314
|
usage: BufferUsage.PointArray,
|
|
299
315
|
format: 'float32x4',
|
|
300
316
|
dataArray: points,
|
|
301
|
-
|
|
302
|
-
primitiveType: primType,
|
|
303
|
-
representation: representation,
|
|
317
|
+
indexBuffer: indexBuffer,
|
|
304
318
|
shift: shift,
|
|
305
319
|
packExtra: true
|
|
306
320
|
};
|
|
307
|
-
var buff = device.getBufferManager().getBuffer(
|
|
321
|
+
var buff = device.getBufferManager().getBuffer(_buffRequest);
|
|
308
322
|
vertexInput.addBuffer(buff, ['vertexBC']);
|
|
309
323
|
} else {
|
|
310
324
|
vertexInput.removeBufferIfPresent('vertexBC');
|
|
@@ -315,30 +329,29 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
315
329
|
|
|
316
330
|
if (usage === BufferUsage.Triangles || usage === BufferUsage.Strips) {
|
|
317
331
|
var normals = pd.getPointData().getNormals();
|
|
318
|
-
var
|
|
332
|
+
var _buffRequest2 = {
|
|
319
333
|
format: 'snorm8x4',
|
|
320
|
-
|
|
321
|
-
representation: representation,
|
|
322
|
-
primitiveType: primType,
|
|
334
|
+
indexBuffer: indexBuffer,
|
|
323
335
|
packExtra: true,
|
|
324
336
|
shift: 0,
|
|
325
337
|
scale: 127
|
|
326
338
|
};
|
|
327
339
|
|
|
328
340
|
if (normals) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
341
|
+
_buffRequest2.hash = "".concat(normals.getMTime(), "I").concat(indexBuffer.getMTime(), "snorm8x4");
|
|
342
|
+
_buffRequest2.dataArray = normals;
|
|
343
|
+
_buffRequest2.usage = BufferUsage.PointArray;
|
|
332
344
|
|
|
333
|
-
var _buff = device.getBufferManager().getBuffer(
|
|
345
|
+
var _buff = device.getBufferManager().getBuffer(_buffRequest2);
|
|
334
346
|
|
|
335
347
|
vertexInput.addBuffer(_buff, ['normalMC']);
|
|
336
348
|
} else if (primType === PrimitiveTypes.Triangles) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
349
|
+
_buffRequest2.hash = "PFN".concat(points.getMTime(), "I").concat(indexBuffer.getMTime(), "snorm8x4");
|
|
350
|
+
_buffRequest2.dataArray = points;
|
|
351
|
+
_buffRequest2.cells = cells;
|
|
352
|
+
_buffRequest2.usage = BufferUsage.NormalsFromPoints;
|
|
340
353
|
|
|
341
|
-
var _buff2 = device.getBufferManager().getBuffer(
|
|
354
|
+
var _buff2 = device.getBufferManager().getBuffer(_buffRequest2);
|
|
342
355
|
|
|
343
356
|
vertexInput.addBuffer(_buff2, ['normalMC']);
|
|
344
357
|
} else {
|
|
@@ -362,19 +375,17 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
362
375
|
haveCellScalars = true;
|
|
363
376
|
}
|
|
364
377
|
|
|
365
|
-
var
|
|
378
|
+
var _buffRequest3 = {
|
|
366
379
|
usage: BufferUsage.PointArray,
|
|
367
380
|
format: 'unorm8x4',
|
|
368
|
-
hash: "".concat(
|
|
381
|
+
hash: "".concat(haveCellScalars).concat(c.getMTime(), "I").concat(indexBuffer.getMTime(), "unorm8x4"),
|
|
369
382
|
dataArray: c,
|
|
370
|
-
|
|
371
|
-
primitiveType: primType,
|
|
372
|
-
representation: representation,
|
|
383
|
+
indexBuffer: indexBuffer,
|
|
373
384
|
cellData: haveCellScalars,
|
|
374
385
|
cellOffset: 0
|
|
375
386
|
};
|
|
376
387
|
|
|
377
|
-
var _buff3 = device.getBufferManager().getBuffer(
|
|
388
|
+
var _buff3 = device.getBufferManager().getBuffer(_buffRequest3);
|
|
378
389
|
|
|
379
390
|
vertexInput.addBuffer(_buff3, ['colorVI']);
|
|
380
391
|
haveColors = true;
|
|
@@ -394,7 +405,7 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
394
405
|
}
|
|
395
406
|
|
|
396
407
|
if (tcoords && !edges) {
|
|
397
|
-
var _buff4 = device.getBufferManager().getBufferForPointArray(tcoords,
|
|
408
|
+
var _buff4 = device.getBufferManager().getBufferForPointArray(tcoords, vertexInput.getIndexBuffer());
|
|
398
409
|
|
|
399
410
|
vertexInput.addBuffer(_buff4, ['tcoord']);
|
|
400
411
|
} else {
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
3
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
+
import macro from '../../macros.js';
|
|
5
|
+
import Constants from './BufferManager/Constants.js';
|
|
6
|
+
import vtkProperty from '../Core/Property.js';
|
|
7
|
+
import vtkWebGPUBuffer from './Buffer.js';
|
|
8
|
+
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
+
var Representation = vtkProperty.Representation;
|
|
13
|
+
var PrimitiveTypes = Constants.PrimitiveTypes; // Simulate a small map of pointId to flatId for a cell. The original code
|
|
14
|
+
// used a map and was 2.6x slower (4.7 to 1.9 seconds). Using two fixed
|
|
15
|
+
// length arrays with a count is so much faster even with the required for
|
|
16
|
+
// loops and if statements. This only works as we know the usage is
|
|
17
|
+
// restricted to clear(), set() get() and has() so the count is always
|
|
18
|
+
// incrmenting except for clear where it goes back to 0. Performance
|
|
19
|
+
// improvement is probably due to this appoach not hitting the heap but wow
|
|
20
|
+
// it is so much faster. Code that adds to these vectors checks against 9 to
|
|
21
|
+
// make sure there is room. Switching to test against vec.length -1 results
|
|
22
|
+
// in a small performance hit, so if you change 10, search for 9 in this
|
|
23
|
+
// small class and change those as well.
|
|
24
|
+
|
|
25
|
+
var _LimitedMap = /*#__PURE__*/function () {
|
|
26
|
+
function _LimitedMap() {
|
|
27
|
+
_classCallCheck(this, _LimitedMap);
|
|
28
|
+
|
|
29
|
+
this.keys = new Uint32Array(10);
|
|
30
|
+
this.values = new Uint32Array(10);
|
|
31
|
+
this.count = 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_createClass(_LimitedMap, [{
|
|
35
|
+
key: "clear",
|
|
36
|
+
value: function clear() {
|
|
37
|
+
this.count = 0;
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "has",
|
|
41
|
+
value: function has(key) {
|
|
42
|
+
for (var i = 0; i < this.count; i++) {
|
|
43
|
+
if (this.keys[i] === key) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "get",
|
|
52
|
+
value: function get(key) {
|
|
53
|
+
for (var i = 0; i < this.count; i++) {
|
|
54
|
+
if (this.keys[i] === key) {
|
|
55
|
+
return this.values[i];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "set",
|
|
63
|
+
value: function set(key, value) {
|
|
64
|
+
if (this.count < 9) {
|
|
65
|
+
this.keys[this.count] = key;
|
|
66
|
+
this.values[this.count++] = value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}]);
|
|
70
|
+
|
|
71
|
+
return _LimitedMap;
|
|
72
|
+
}();
|
|
73
|
+
|
|
74
|
+
function getPrimitiveName(primType) {
|
|
75
|
+
switch (primType) {
|
|
76
|
+
case PrimitiveTypes.Points:
|
|
77
|
+
return 'points';
|
|
78
|
+
|
|
79
|
+
case PrimitiveTypes.Lines:
|
|
80
|
+
return 'lines';
|
|
81
|
+
|
|
82
|
+
case PrimitiveTypes.Triangles:
|
|
83
|
+
case PrimitiveTypes.TriangleEdges:
|
|
84
|
+
return 'polys';
|
|
85
|
+
|
|
86
|
+
case PrimitiveTypes.TriangleStripEdges:
|
|
87
|
+
case PrimitiveTypes.TriangleStrips:
|
|
88
|
+
return 'strips';
|
|
89
|
+
|
|
90
|
+
default:
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function _getOrAddFlatId(state, ptId, cellId) {
|
|
96
|
+
var flatId = state.pointIdToFlatId[ptId];
|
|
97
|
+
|
|
98
|
+
if (flatId < 0) {
|
|
99
|
+
flatId = state.flatId;
|
|
100
|
+
state.pointIdToFlatId[ptId] = flatId;
|
|
101
|
+
state.flatIdToPointId[state.flatId] = ptId;
|
|
102
|
+
state.flatIdToCellId[state.flatId] = cellId;
|
|
103
|
+
state.flatId++;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return flatId;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function fillCell(ptIds, cellId, state) {
|
|
110
|
+
var numPtIds = ptIds.length; // are any points already marked for this cell? If so use that as the provoking point
|
|
111
|
+
|
|
112
|
+
for (var ptIdx = 0; ptIdx < numPtIds; ptIdx++) {
|
|
113
|
+
var _ptId = ptIds[ptIdx];
|
|
114
|
+
|
|
115
|
+
if (state.cellProvokedMap.has(_ptId)) {
|
|
116
|
+
state.ibo[state.iboId++] = state.cellProvokedMap.get(_ptId); // insert remaining ptIds (they do not need to provoke)
|
|
117
|
+
|
|
118
|
+
for (var ptIdx2 = ptIdx + 1; ptIdx2 < ptIdx + numPtIds; ptIdx2++) {
|
|
119
|
+
_ptId = ptIds[ptIdx2 % numPtIds];
|
|
120
|
+
|
|
121
|
+
var _flatId = _getOrAddFlatId(state, _ptId, cellId); // add to ibo
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
state.ibo[state.iboId++] = _flatId;
|
|
125
|
+
} // all done now
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
} // else have any of the points not been used yet? (not in provokedPointIds)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
for (var _ptIdx = 0; _ptIdx < numPtIds; _ptIdx++) {
|
|
134
|
+
var _ptId2 = ptIds[_ptIdx];
|
|
135
|
+
|
|
136
|
+
if (!state.provokedPointIds[_ptId2]) {
|
|
137
|
+
var _flatId2 = _getOrAddFlatId(state, _ptId2, cellId); // mark provoking and add to ibo
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
state.provokedPointIds[_ptId2] = 1;
|
|
141
|
+
state.cellProvokedMap.set(_ptId2, _flatId2); // when provoking always set the cellId as an original non-provoking value
|
|
142
|
+
// will have been stored and we need to overwrite that
|
|
143
|
+
|
|
144
|
+
state.flatIdToCellId[_flatId2] = cellId;
|
|
145
|
+
state.ibo[state.iboId++] = _flatId2; // insert remaining ptIds (they do not need to provoke)
|
|
146
|
+
|
|
147
|
+
for (var _ptIdx2 = _ptIdx + 1; _ptIdx2 < _ptIdx + numPtIds; _ptIdx2++) {
|
|
148
|
+
_ptId2 = ptIds[_ptIdx2 % numPtIds];
|
|
149
|
+
_flatId2 = _getOrAddFlatId(state, _ptId2, cellId); // add to ibo
|
|
150
|
+
|
|
151
|
+
state.ibo[state.iboId++] = _flatId2;
|
|
152
|
+
} // all done now
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
} // if we got here then none of the ptIds could be used to provoke
|
|
158
|
+
// so just duplicate the first one
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
var ptId = ptIds[0];
|
|
162
|
+
var flatId = state.flatId;
|
|
163
|
+
state.cellProvokedMap.set(ptId, flatId);
|
|
164
|
+
state.flatIdToPointId[state.flatId] = ptId;
|
|
165
|
+
state.flatIdToCellId[state.flatId] = cellId;
|
|
166
|
+
state.flatId++; // add to ibo
|
|
167
|
+
|
|
168
|
+
state.ibo[state.iboId++] = flatId; // insert remaining ptIds (they do not need to provoke)
|
|
169
|
+
|
|
170
|
+
for (var _ptIdx3 = 1; _ptIdx3 < numPtIds; _ptIdx3++) {
|
|
171
|
+
ptId = ptIds[_ptIdx3];
|
|
172
|
+
flatId = _getOrAddFlatId(state, ptId, cellId); // add to ibo
|
|
173
|
+
|
|
174
|
+
state.ibo[state.iboId++] = flatId;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function countCell(ptIds, cellId, state) {
|
|
179
|
+
var numPtIds = ptIds.length;
|
|
180
|
+
state.iboSize += numPtIds; // are any points already marked for this cell? If so use that as the provoking point
|
|
181
|
+
|
|
182
|
+
for (var ptIdx = 0; ptIdx < numPtIds; ptIdx++) {
|
|
183
|
+
var ptId = ptIds[ptIdx];
|
|
184
|
+
|
|
185
|
+
if (state.cellProvokedMap.has(ptId)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
} // else have any of the points not been used yet? (not in provokedPointIds)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
for (var _ptIdx4 = 0; _ptIdx4 < numPtIds; _ptIdx4++) {
|
|
192
|
+
var _ptId3 = ptIds[_ptIdx4];
|
|
193
|
+
|
|
194
|
+
if (!state.provokedPointIds[_ptId3]) {
|
|
195
|
+
state.provokedPointIds[_ptId3] = 1;
|
|
196
|
+
state.cellProvokedMap.set(_ptId3, 1);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
} // if we got here then none of the ptIds could be used to provoke
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
state.cellProvokedMap.set(ptIds[0], 1);
|
|
203
|
+
state.extraPoints++;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
var processCell;
|
|
207
|
+
|
|
208
|
+
var _single = new Uint32Array(1);
|
|
209
|
+
|
|
210
|
+
var _double = new Uint32Array(2);
|
|
211
|
+
|
|
212
|
+
var _triple = new Uint32Array(3);
|
|
213
|
+
|
|
214
|
+
var _indexCellBuilders = {
|
|
215
|
+
// easy, every input point becomes an output point
|
|
216
|
+
anythingToPoints: function anythingToPoints(numPoints, cellPts, offset, cellId, state) {
|
|
217
|
+
for (var i = 0; i < numPoints; ++i) {
|
|
218
|
+
_single[0] = cellPts[offset + i];
|
|
219
|
+
processCell(_single, cellId, state);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
linesToWireframe: function linesToWireframe(numPoints, cellPts, offset, cellId, state) {
|
|
223
|
+
// for lines we add a bunch of segments
|
|
224
|
+
for (var i = 0; i < numPoints - 1; ++i) {
|
|
225
|
+
_double[0] = cellPts[offset + i];
|
|
226
|
+
_double[1] = cellPts[offset + i + 1];
|
|
227
|
+
processCell(_double, cellId, state);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
polysToWireframe: function polysToWireframe(numPoints, cellPts, offset, cellId, state) {
|
|
231
|
+
// for polys we add a bunch of segments and close it
|
|
232
|
+
if (numPoints > 2) {
|
|
233
|
+
for (var i = 0; i < numPoints; ++i) {
|
|
234
|
+
_double[0] = cellPts[offset + i];
|
|
235
|
+
_double[1] = cellPts[offset + (i + 1) % numPoints];
|
|
236
|
+
processCell(_double, cellId, state);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
stripsToWireframe: function stripsToWireframe(numPoints, cellPts, offset, cellId, state) {
|
|
241
|
+
if (numPoints > 2) {
|
|
242
|
+
// for strips we add a bunch of segments and close it
|
|
243
|
+
for (var i = 0; i < numPoints - 1; ++i) {
|
|
244
|
+
_double[0] = cellPts[offset + i];
|
|
245
|
+
_double[1] = cellPts[offset + i + 1];
|
|
246
|
+
processCell(_double, cellId, state);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for (var _i = 0; _i < numPoints - 2; _i++) {
|
|
250
|
+
_double[0] = cellPts[offset + _i];
|
|
251
|
+
_double[1] = cellPts[offset + _i + 2];
|
|
252
|
+
processCell(_double, cellId, state);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
polysToSurface: function polysToSurface(npts, cellPts, offset, cellId, state) {
|
|
257
|
+
for (var i = 0; i < npts - 2; i++) {
|
|
258
|
+
_triple[0] = cellPts[offset];
|
|
259
|
+
_triple[1] = cellPts[offset + i + 1];
|
|
260
|
+
_triple[2] = cellPts[offset + i + 2];
|
|
261
|
+
processCell(_triple, cellId, state);
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
stripsToSurface: function stripsToSurface(npts, cellPts, offset, cellId, state) {
|
|
265
|
+
for (var i = 0; i < npts - 2; i++) {
|
|
266
|
+
_triple[0] = cellPts[offset + i];
|
|
267
|
+
_triple[1] = cellPts[offset + i + 1 + i % 2];
|
|
268
|
+
_triple[2] = cellPts[offset + i + 1 + (i + 1) % 2];
|
|
269
|
+
processCell(_triple, cellId, state);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}; // ----------------------------------------------------------------------------
|
|
273
|
+
// vtkWebGPUIndexBufferManager methods
|
|
274
|
+
// ----------------------------------------------------------------------------
|
|
275
|
+
|
|
276
|
+
function vtkWebGPUIndexBuffer(publicAPI, model) {
|
|
277
|
+
// Set our className
|
|
278
|
+
model.classHierarchy.push('vtkWebGPUIndexBuffer');
|
|
279
|
+
|
|
280
|
+
publicAPI.buildIndexBuffer = function (req) {
|
|
281
|
+
var cellArray = req.cells;
|
|
282
|
+
var primitiveType = req.primitiveType;
|
|
283
|
+
var representation = req.representation;
|
|
284
|
+
var cellOffset = req.cellOffset;
|
|
285
|
+
var array = cellArray.getData();
|
|
286
|
+
var cellArraySize = array.length;
|
|
287
|
+
var inRepName = getPrimitiveName(primitiveType);
|
|
288
|
+
var numPts = req.numberOfPoints;
|
|
289
|
+
var state = {
|
|
290
|
+
provokedPointIds: new Uint8Array(numPts),
|
|
291
|
+
// size is good
|
|
292
|
+
extraPoints: 0,
|
|
293
|
+
iboSize: 0,
|
|
294
|
+
flatId: 0,
|
|
295
|
+
iboId: 0,
|
|
296
|
+
cellProvokedMap: new _LimitedMap()
|
|
297
|
+
};
|
|
298
|
+
var func = null;
|
|
299
|
+
|
|
300
|
+
if (representation === Representation.POINTS || primitiveType === PrimitiveTypes.Points) {
|
|
301
|
+
func = _indexCellBuilders.anythingToPoints;
|
|
302
|
+
} else if (representation === Representation.WIREFRAME || primitiveType === PrimitiveTypes.Lines) {
|
|
303
|
+
func = _indexCellBuilders["".concat(inRepName, "ToWireframe")];
|
|
304
|
+
} else {
|
|
305
|
+
func = _indexCellBuilders["".concat(inRepName, "ToSurface")];
|
|
306
|
+
} // first we count how many extra provoking points we need
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
processCell = countCell;
|
|
310
|
+
var cellId = cellOffset || 0;
|
|
311
|
+
|
|
312
|
+
for (var cellArrayIndex = 0; cellArrayIndex < cellArraySize;) {
|
|
313
|
+
state.cellProvokedMap.clear();
|
|
314
|
+
func(array[cellArrayIndex], array, cellArrayIndex + 1, cellId, state);
|
|
315
|
+
cellArrayIndex += array[cellArrayIndex] + 1;
|
|
316
|
+
cellId++;
|
|
317
|
+
} // then we allocate the remaining structures
|
|
318
|
+
// (we pick the best size to save space and transfer costs)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
if (numPts <= 0xffff) {
|
|
322
|
+
state.flatIdToPointId = new Uint16Array(numPts + state.extraPoints);
|
|
323
|
+
} else {
|
|
324
|
+
state.flatIdToPointId = new Uint32Array(numPts + state.extraPoints);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (numPts + state.extraPoints < 0x8fff) {
|
|
328
|
+
state.pointIdToFlatId = new Int16Array(numPts);
|
|
329
|
+
} else {
|
|
330
|
+
state.pointIdToFlatId = new Int32Array(numPts);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (numPts + state.extraPoints <= 0xffff) {
|
|
334
|
+
state.ibo = new Uint16Array(state.iboSize);
|
|
335
|
+
req.format = 'uint16';
|
|
336
|
+
} else {
|
|
337
|
+
state.ibo = new Uint32Array(state.iboSize);
|
|
338
|
+
req.format = 'uint32';
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (cellId <= 0xffff) {
|
|
342
|
+
state.flatIdToCellId = new Uint16Array(numPts + state.extraPoints);
|
|
343
|
+
} else {
|
|
344
|
+
state.flatIdToCellId = new Uint32Array(numPts + state.extraPoints);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
state.pointIdToFlatId.fill(-1);
|
|
348
|
+
state.provokedPointIds.fill(0); // and fill them in
|
|
349
|
+
|
|
350
|
+
processCell = fillCell;
|
|
351
|
+
cellId = cellOffset || 0;
|
|
352
|
+
|
|
353
|
+
for (var _cellArrayIndex = 0; _cellArrayIndex < cellArraySize;) {
|
|
354
|
+
state.cellProvokedMap.clear();
|
|
355
|
+
func(array[_cellArrayIndex], array, _cellArrayIndex + 1, cellId, state);
|
|
356
|
+
_cellArrayIndex += array[_cellArrayIndex] + 1;
|
|
357
|
+
cellId++;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
delete state.provokedPointIds;
|
|
361
|
+
delete state.pointIdToFlatId; // store the results we need
|
|
362
|
+
|
|
363
|
+
req.nativeArray = state.ibo;
|
|
364
|
+
model.flatIdToPointId = state.flatIdToPointId;
|
|
365
|
+
model.flatIdToCellId = state.flatIdToCellId;
|
|
366
|
+
model.flatSize = state.flatId;
|
|
367
|
+
model.indexCount = state.iboId;
|
|
368
|
+
};
|
|
369
|
+
} // ----------------------------------------------------------------------------
|
|
370
|
+
// Object factory
|
|
371
|
+
// ----------------------------------------------------------------------------
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
var DEFAULT_VALUES = {
|
|
375
|
+
flatIdToPointId: null,
|
|
376
|
+
flatIdToCellId: null,
|
|
377
|
+
flatSize: 0,
|
|
378
|
+
indexCount: 0
|
|
379
|
+
}; // ----------------------------------------------------------------------------
|
|
380
|
+
|
|
381
|
+
function extend(publicAPI, model) {
|
|
382
|
+
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
383
|
+
Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
|
|
384
|
+
|
|
385
|
+
vtkWebGPUBuffer.extend(publicAPI, model, initialValues);
|
|
386
|
+
macro.setGet(publicAPI, model, ['flatIdToPointId', 'flatIdToCellId', 'flatSize', 'indexCount']);
|
|
387
|
+
vtkWebGPUIndexBuffer(publicAPI, model);
|
|
388
|
+
} // ----------------------------------------------------------------------------
|
|
389
|
+
|
|
390
|
+
var newInstance = macro.newInstance(extend); // ----------------------------------------------------------------------------
|
|
391
|
+
|
|
392
|
+
var vtkWebGPUIndexBuffer$1 = _objectSpread({
|
|
393
|
+
newInstance: newInstance,
|
|
394
|
+
extend: extend
|
|
395
|
+
}, Constants);
|
|
396
|
+
|
|
397
|
+
export { vtkWebGPUIndexBuffer$1 as default, extend, newInstance };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { newInstance as newInstance$1, obj, get, setGet } from '../../macros.js';
|
|
2
2
|
import vtkWebGPUShaderCache from './ShaderCache.js';
|
|
3
3
|
|
|
4
|
-
var forwarded = ['setBindGroup', 'setVertexBuffer', 'draw']; // ----------------------------------------------------------------------------
|
|
4
|
+
var forwarded = ['setBindGroup', 'setIndexBuffer', 'setVertexBuffer', 'draw', 'drawIndexed']; // ----------------------------------------------------------------------------
|
|
5
5
|
// vtkWebGPURenderEncoder methods
|
|
6
6
|
// ----------------------------------------------------------------------------
|
|
7
7
|
|
|
@@ -179,7 +179,13 @@ function vtkWebGPUSimpleMapper(publicAPI, model) {
|
|
|
179
179
|
renderEncoder.activateBindGroup(model.bindGroup); // bind the vertex input
|
|
180
180
|
|
|
181
181
|
pipeline.bindVertexInput(renderEncoder, model.vertexInput);
|
|
182
|
-
|
|
182
|
+
var indexBuffer = model.vertexInput.getIndexBuffer();
|
|
183
|
+
|
|
184
|
+
if (indexBuffer) {
|
|
185
|
+
renderEncoder.drawIndexed(indexBuffer.getIndexCount(), model.numberOfInstances, 0, 0, 0);
|
|
186
|
+
} else {
|
|
187
|
+
renderEncoder.draw(model.numberOfVertices, model.numberOfInstances, 0, 0);
|
|
188
|
+
}
|
|
183
189
|
};
|
|
184
190
|
|
|
185
191
|
publicAPI.getBindables = function () {
|
|
@@ -158,6 +158,10 @@ function vtkWebGPUVertexInput(publicAPI, model) {
|
|
|
158
158
|
for (var i = 0; i < model.inputs.length; i++) {
|
|
159
159
|
renderEncoder.setVertexBuffer(i, model.inputs[i].buffer.getHandle());
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
if (model.indexBuffer) {
|
|
163
|
+
renderEncoder.setIndexBuffer(model.indexBuffer.getHandle(), model.indexBuffer.getArrayInformation()[0].format);
|
|
164
|
+
}
|
|
161
165
|
};
|
|
162
166
|
|
|
163
167
|
publicAPI.getReady = function () {};
|
|
@@ -177,7 +181,8 @@ function vtkWebGPUVertexInput(publicAPI, model) {
|
|
|
177
181
|
var DEFAULT_VALUES = {
|
|
178
182
|
inputs: null,
|
|
179
183
|
bindingDescriptions: false,
|
|
180
|
-
attributeDescriptions: null
|
|
184
|
+
attributeDescriptions: null,
|
|
185
|
+
indexBuffer: null
|
|
181
186
|
}; // ----------------------------------------------------------------------------
|
|
182
187
|
|
|
183
188
|
function extend(publicAPI, model) {
|
|
@@ -188,7 +193,7 @@ function extend(publicAPI, model) {
|
|
|
188
193
|
model.bindingDescriptions = [];
|
|
189
194
|
model.attributeDescriptions = [];
|
|
190
195
|
model.inputs = [];
|
|
191
|
-
setGet(publicAPI, model, ['created', 'device', 'handle']); // For more macro methods, see "Sources/macros.js"
|
|
196
|
+
setGet(publicAPI, model, ['created', 'device', 'handle', 'indexBuffer']); // For more macro methods, see "Sources/macros.js"
|
|
192
197
|
// Object specific methods
|
|
193
198
|
|
|
194
199
|
vtkWebGPUVertexInput(publicAPI, model);
|
|
@@ -256,17 +256,27 @@ function vtkWebGPUVolumePass(publicAPI, model) {
|
|
|
256
256
|
publicAPI.renderDepthBounds = function (renNode, viewNode) {
|
|
257
257
|
publicAPI.updateDepthPolyData(renNode);
|
|
258
258
|
var pd = model._boundsPoly;
|
|
259
|
-
var cells = pd.getPolys(); // points
|
|
260
|
-
|
|
261
259
|
var points = pd.getPoints();
|
|
260
|
+
var cells = pd.getPolys();
|
|
262
261
|
var buffRequest = {
|
|
262
|
+
hash: "vp".concat(cells.getMTime()),
|
|
263
|
+
usage: BufferUsage.Index,
|
|
264
|
+
cells: cells,
|
|
265
|
+
numberOfPoints: points.getNumberOfPoints(),
|
|
266
|
+
primitiveType: PrimitiveTypes.Triangles,
|
|
267
|
+
representation: Representation.SURFACE
|
|
268
|
+
};
|
|
269
|
+
var indexBuffer = viewNode.getDevice().getBufferManager().getBuffer(buffRequest);
|
|
270
|
+
|
|
271
|
+
model._mapper.getVertexInput().setIndexBuffer(indexBuffer); // points
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
buffRequest = {
|
|
263
275
|
usage: BufferUsage.PointArray,
|
|
264
276
|
format: 'float32x4',
|
|
265
277
|
hash: "vp".concat(points.getMTime()).concat(cells.getMTime()),
|
|
266
278
|
dataArray: points,
|
|
267
|
-
|
|
268
|
-
primitiveType: PrimitiveTypes.Triangles,
|
|
269
|
-
representation: Representation.SURFACE,
|
|
279
|
+
indexBuffer: indexBuffer,
|
|
270
280
|
packExtra: true
|
|
271
281
|
};
|
|
272
282
|
var buff = viewNode.getDevice().getBufferManager().getBuffer(buffRequest);
|