@kitware/vtk.js 24.5.6 → 24.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/Common/Core/CellArray.js +14 -3
  2. package/IO/XML/XMLImageDataReader.js +6 -0
  3. package/IO/XML/XMLImageDataWriter.js +2 -1
  4. package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +1 -1
  5. package/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.js +1 -1
  6. package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js +1 -1
  7. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
  8. package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.js +1 -1
  9. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +5 -2
  10. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +3 -1
  11. package/Interaction/Style/InteractorStyleManipulator.js +1 -1
  12. package/Rendering/Core/Mapper.js +1 -1
  13. package/Rendering/Core/RenderWindowInteractor.js +1 -2
  14. package/Rendering/Core/Renderer.d.ts +1 -1
  15. package/Rendering/WebGPU/BindGroup.js +1 -1
  16. package/Rendering/WebGPU/BufferManager/Constants.js +1 -1
  17. package/Rendering/WebGPU/BufferManager.js +92 -275
  18. package/Rendering/WebGPU/CellArrayMapper.js +45 -34
  19. package/Rendering/WebGPU/IndexBuffer.js +397 -0
  20. package/Rendering/WebGPU/RenderEncoder.js +1 -1
  21. package/Rendering/WebGPU/SimpleMapper.js +7 -1
  22. package/Rendering/WebGPU/VertexInput.js +7 -2
  23. package/Rendering/WebGPU/VolumePass.js +15 -5
  24. package/Widgets/Core/WidgetManager.js +11 -2
  25. package/Widgets/Manipulators/TrackballManipulator.js +1 -1
  26. package/Widgets/Representations/ArrowHandleRepresentation.js +12 -3
  27. package/Widgets/Representations/CircleContextRepresentation.js +12 -3
  28. package/Widgets/Representations/CubeHandleRepresentation.js +13 -4
  29. package/Widgets/Representations/SphereContextRepresentation.js +12 -3
  30. package/Widgets/Representations/SphereHandleRepresentation.js +12 -3
  31. package/index.d.ts +1 -1
  32. package/package.json +1 -1
@@ -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, vtkDebugMacro as vtkDebugMacro$1 } from '../../macros.js';
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
- PrimitiveTypes = Constants.PrimitiveTypes;
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 getPrimitiveName(primType) {
128
- switch (primType) {
129
- case PrimitiveTypes.Points:
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 (!cellArray.getData() || !cellArray.getData().length) {
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 numComp = inArray.getNumberOfComponents();
274
- var packedVBO = newTypedArray(outputType, caboCount * (numComp + (packExtra ? 1 : 0))); // pick the right function based on point versus cell data
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 getData = function getData(ptId, cellId) {
277
- return pointData[ptId];
278
- };
118
+ var flatIdMap = indexBuffer.getFlatIdToPointId();
279
119
 
280
120
  if (options.cellData) {
281
- getData = function getData(ptId, cellId) {
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, cellid) {
289
- packedVBO[vboidx++] = scale[0] * getData(i, cellid) + shift[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, cellid) {
293
- packedVBO[vboidx++] = scale[0] * getData(i * 2, cellid * 2) + shift[0];
294
- packedVBO[vboidx++] = scale[1] * getData(i * 2 + 1, cellid * 2 + 1) + shift[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, cellid) {
298
- packedVBO[vboidx++] = scale[0] * getData(i * 3, cellid * 3) + shift[0];
299
- packedVBO[vboidx++] = scale[1] * getData(i * 3 + 1, cellid * 3 + 1) + shift[1];
300
- packedVBO[vboidx++] = scale[2] * getData(i * 3 + 2, cellid * 3 + 2) + shift[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, cellid) {
304
- packedVBO[vboidx++] = scale[0] * getData(i * 3, cellid * 3) + shift[0];
305
- packedVBO[vboidx++] = scale[1] * getData(i * 3 + 1, cellid * 3 + 1) + shift[1];
306
- packedVBO[vboidx++] = scale[2] * getData(i * 3 + 2, cellid * 3 + 2) + shift[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, cellid) {
311
- packedVBO[vboidx++] = scale[0] * getData(i * 4, cellid * 4) + shift[0];
312
- packedVBO[vboidx++] = scale[1] * getData(i * 4 + 1, cellid * 4 + 1) + shift[1];
313
- packedVBO[vboidx++] = scale[2] * getData(i * 4 + 2, cellid * 4 + 2) + shift[2];
314
- packedVBO[vboidx++] = scale[3] * getData(i * 4 + 3, cellid * 4 + 3) + shift[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 < size;) {
321
- func(array[index], array, index + 1, cellId);
322
- index += array[index] + 1;
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, primType, representation, inArray) {
341
- if (!cellArray.getData() || !cellArray.getData().length) {
342
- return null;
343
- }
175
+ function generateNormals(cellArray, pointArray) {
176
+ var pointData = pointArray.getData();
177
+ var cellArrayData = cellArray.getData();
344
178
 
345
- var pointData = inArray.getData();
346
- var addAPoint;
347
- var cellBuilders = {
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 caboCount = getOutputSize(cellArray, representation, primName);
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
- addAPoint = function addAPointFunc(normal) {
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
- } // create one
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.cells, req.primitiveType, req.representation, req.dataArray, arrayType, {
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
- var normals = generateNormals(req.cells, req.primitiveType, req.representation, req.dataArray);
485
- buffer.createAndWrite(normals, gpuUsage);
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, cells, primitiveType, representation) {
340
+ publicAPI.getBufferForPointArray = function (dataArray, indexBuffer) {
522
341
  var format = _getFormatForDataArray(dataArray);
523
342
 
524
343
  var buffRequest = {
525
- hash: "PA".concat(representation, "P").concat(primitiveType, "D").concat(dataArray.getMTime(), "C").concat(cells.getMTime()).concat(format),
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
- cells: cells,
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
- if (vertexInput.hasAttribute('normalMC')) {
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
- if (!vertexInput.hasAttribute('colorVI')) return;
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 hash = "R".concat(representation, "P").concat(primType); // hash = all things that can change the values on the buffer
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
- // - cells mtime - because cells drive how we pack
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 buffRequest = {
297
- hash: "".concat(hash).concat(points.getMTime()).concat(cells.getMTime()).concat(shift.join(), "float32x4"),
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
- cells: cells,
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(buffRequest);
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 _buffRequest = {
332
+ var _buffRequest2 = {
319
333
  format: 'snorm8x4',
320
- cells: cells,
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
- _buffRequest.hash = "".concat(hash).concat(normals.getMTime()).concat(cells.getMTime(), "snorm8x4");
330
- _buffRequest.dataArray = normals;
331
- _buffRequest.usage = BufferUsage.PointArray;
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(_buffRequest);
345
+ var _buff = device.getBufferManager().getBuffer(_buffRequest2);
334
346
 
335
347
  vertexInput.addBuffer(_buff, ['normalMC']);
336
348
  } else if (primType === PrimitiveTypes.Triangles) {
337
- _buffRequest.hash = "".concat(hash).concat(points.getMTime()).concat(cells.getMTime(), "snorm8x4");
338
- _buffRequest.dataArray = points;
339
- _buffRequest.usage = BufferUsage.NormalsFromPoints;
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(_buffRequest);
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 _buffRequest2 = {
378
+ var _buffRequest3 = {
366
379
  usage: BufferUsage.PointArray,
367
380
  format: 'unorm8x4',
368
- hash: "".concat(hash).concat(haveCellScalars).concat(c.getMTime()).concat(cells.getMTime(), "unorm8x4"),
381
+ hash: "".concat(haveCellScalars).concat(c.getMTime(), "I").concat(indexBuffer.getMTime(), "unorm8x4"),
369
382
  dataArray: c,
370
- cells: cells,
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(_buffRequest2);
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, cells, primType, representation);
408
+ var _buff4 = device.getBufferManager().getBufferForPointArray(tcoords, vertexInput.getIndexBuffer());
398
409
 
399
410
  vertexInput.addBuffer(_buff4, ['tcoord']);
400
411
  } else {