@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.
- package/Common/Core/CellArray.js +14 -3
- package/IO/XML/XMLImageDataReader.js +6 -0
- package/IO/XML/XMLImageDataWriter.js +2 -1
- package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +5 -2
- package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +3 -1
- package/Interaction/Style/InteractorStyleManipulator.js +1 -1
- package/Rendering/Core/Mapper.js +1 -1
- package/Rendering/Core/RenderWindowInteractor.js +1 -2
- package/Rendering/Core/Renderer.d.ts +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/Widgets/Core/WidgetManager.js +11 -2
- package/Widgets/Manipulators/TrackballManipulator.js +1 -1
- package/Widgets/Representations/ArrowHandleRepresentation.js +12 -3
- package/Widgets/Representations/CircleContextRepresentation.js +12 -3
- package/Widgets/Representations/CubeHandleRepresentation.js +13 -4
- package/Widgets/Representations/SphereContextRepresentation.js +12 -3
- package/Widgets/Representations/SphereHandleRepresentation.js +12 -3
- package/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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);
|
|
@@ -37,7 +37,6 @@ function extractRenderingComponents(renderer) {
|
|
|
37
37
|
|
|
38
38
|
function createSvgRoot(id) {
|
|
39
39
|
var svgRoot = createSvgDomElement('svg');
|
|
40
|
-
svgRoot.setAttribute('style', 'position: absolute; top: 0; left: 0; width: 100%; height: 100%;');
|
|
41
40
|
svgRoot.setAttribute('version', '1.1');
|
|
42
41
|
svgRoot.setAttribute('baseProfile', 'full');
|
|
43
42
|
return svgRoot;
|
|
@@ -122,7 +121,7 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
function setSvgSize() {
|
|
125
|
-
var _model$_apiSpecificRe = model._apiSpecificRenderWindow.
|
|
124
|
+
var _model$_apiSpecificRe = model._apiSpecificRenderWindow.getViewportSize(model._renderer),
|
|
126
125
|
_model$_apiSpecificRe2 = _slicedToArray(_model$_apiSpecificRe, 2),
|
|
127
126
|
cwidth = _model$_apiSpecificRe2[0],
|
|
128
127
|
cheight = _model$_apiSpecificRe2[1];
|
|
@@ -148,6 +147,14 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
|
|
150
|
+
function setSvgRootStyle() {
|
|
151
|
+
var viewport = model._renderer.getViewport().map(function (v) {
|
|
152
|
+
return v * 100;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
model.svgRoot.setAttribute('style', "position: absolute; left: ".concat(viewport[0], "%; top: ").concat(100 - viewport[3], "%; width: ").concat(viewport[2] - viewport[0], "%; height: ").concat(viewport[3] - viewport[1], "%;"));
|
|
156
|
+
}
|
|
157
|
+
|
|
151
158
|
function updateSvg() {
|
|
152
159
|
if (model.useSvgLayer) {
|
|
153
160
|
var _loop = function _loop(i) {
|
|
@@ -459,6 +466,8 @@ function vtkWidgetManager(publicAPI, model) {
|
|
|
459
466
|
model._selector.setFieldAssociation(FieldAssociations.FIELD_ASSOCIATION_POINTS);
|
|
460
467
|
|
|
461
468
|
subscriptions.push(model._interactor.onRenderEvent(updateSvg));
|
|
469
|
+
subscriptions.push(renderer.onModified(setSvgRootStyle));
|
|
470
|
+
setSvgRootStyle();
|
|
462
471
|
subscriptions.push(model._apiSpecificRenderWindow.onModified(setSvgSize));
|
|
463
472
|
setSvgSize();
|
|
464
473
|
subscriptions.push(model._apiSpecificRenderWindow.onModified(updateDisplayScaleParams));
|
|
@@ -8,7 +8,7 @@ function trackballRotate(prevX, prevY, curX, curY, origin, direction, renderer,
|
|
|
8
8
|
var camera = renderer.getActiveCamera();
|
|
9
9
|
var viewUp = camera.getViewUp();
|
|
10
10
|
var dop = camera.getDirectionOfProjection();
|
|
11
|
-
var size = renderer.getRenderWindow().getInteractor().getView().
|
|
11
|
+
var size = renderer.getRenderWindow().getInteractor().getView().getViewportSize(renderer);
|
|
12
12
|
var xdeg = 360.0 * dx / size[0];
|
|
13
13
|
var ydeg = 360.0 * dy / size[1];
|
|
14
14
|
var newDirection = new Float64Array([direction[0], direction[1], direction[2]]);
|
|
@@ -255,15 +255,24 @@ function vtkArrowHandleRepresentation(publicAPI, model) {
|
|
|
255
255
|
return orientationRotation;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
var superGetRepresentationStates = publicAPI.getRepresentationStates;
|
|
259
|
+
|
|
260
|
+
publicAPI.getRepresentationStates = function () {
|
|
261
|
+
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : model.inputData[0];
|
|
262
|
+
return superGetRepresentationStates(input).filter(function (state) {
|
|
263
|
+
var _state$getOrigin, _state$isVisible;
|
|
264
|
+
|
|
265
|
+
return ((_state$getOrigin = state.getOrigin) === null || _state$getOrigin === void 0 ? void 0 : _state$getOrigin.call(state)) && ((_state$isVisible = state.isVisible) === null || _state$isVisible === void 0 ? void 0 : _state$isVisible.call(state));
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
|
|
258
269
|
publicAPI.requestDataInternal = function (inData, outData) {
|
|
259
270
|
var _model$internalArrays = model.internalArrays,
|
|
260
271
|
points = _model$internalArrays.points,
|
|
261
272
|
scale = _model$internalArrays.scale,
|
|
262
273
|
color = _model$internalArrays.color,
|
|
263
274
|
direction = _model$internalArrays.direction;
|
|
264
|
-
var list = publicAPI.getRepresentationStates(inData[0])
|
|
265
|
-
return state.getOrigin && state.getOrigin() && state.isVisible && state.isVisible();
|
|
266
|
-
});
|
|
275
|
+
var list = publicAPI.getRepresentationStates(inData[0]);
|
|
267
276
|
var totalCount = list.length;
|
|
268
277
|
|
|
269
278
|
if (color.getNumberOfValues() !== totalCount) {
|
|
@@ -93,6 +93,17 @@ function vtkCircleContextRepresentation(publicAPI, model) {
|
|
|
93
93
|
|
|
94
94
|
publicAPI.setOpacity = function (opacity) {
|
|
95
95
|
model.pipelines.circle.actor.getProperty().setOpacity(opacity);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var superGetRepresentationStates = publicAPI.getRepresentationStates;
|
|
99
|
+
|
|
100
|
+
publicAPI.getRepresentationStates = function () {
|
|
101
|
+
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : model.inputData[0];
|
|
102
|
+
return superGetRepresentationStates(input).filter(function (state) {
|
|
103
|
+
var _state$getOrigin, _state$isVisible;
|
|
104
|
+
|
|
105
|
+
return ((_state$getOrigin = state.getOrigin) === null || _state$getOrigin === void 0 ? void 0 : _state$getOrigin.call(state)) && ((_state$isVisible = state.isVisible) === null || _state$isVisible === void 0 ? void 0 : _state$isVisible.call(state));
|
|
106
|
+
});
|
|
96
107
|
}; // --------------------------------------------------------------------------
|
|
97
108
|
|
|
98
109
|
|
|
@@ -102,9 +113,7 @@ function vtkCircleContextRepresentation(publicAPI, model) {
|
|
|
102
113
|
scale = _model$internalArrays.scale,
|
|
103
114
|
color = _model$internalArrays.color,
|
|
104
115
|
direction = _model$internalArrays.direction;
|
|
105
|
-
var list = publicAPI.getRepresentationStates(inData[0])
|
|
106
|
-
return state.getOrigin && state.getOrigin() && state.isVisible && state.isVisible();
|
|
107
|
-
});
|
|
116
|
+
var list = publicAPI.getRepresentationStates(inData[0]);
|
|
108
117
|
var totalCount = list.length;
|
|
109
118
|
|
|
110
119
|
if (color.getNumberOfValues() !== totalCount) {
|
|
@@ -49,16 +49,25 @@ function vtkCubeHandleRepresentation(publicAPI, model) {
|
|
|
49
49
|
model.mapper.setInputConnection(publicAPI.getOutputPort(), 0);
|
|
50
50
|
model.mapper.setInputConnection(model.glyph.getOutputPort(), 1);
|
|
51
51
|
model.actor.setMapper(model.mapper);
|
|
52
|
-
publicAPI.addActor(model.actor);
|
|
52
|
+
publicAPI.addActor(model.actor);
|
|
53
|
+
var superGetRepresentationStates = publicAPI.getRepresentationStates;
|
|
54
|
+
|
|
55
|
+
publicAPI.getRepresentationStates = function () {
|
|
56
|
+
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : model.inputData[0];
|
|
57
|
+
return superGetRepresentationStates(input).filter(function (state) {
|
|
58
|
+
var _state$getOrigin, _state$isVisible;
|
|
59
|
+
|
|
60
|
+
return ((_state$getOrigin = state.getOrigin) === null || _state$getOrigin === void 0 ? void 0 : _state$getOrigin.call(state)) && ((_state$isVisible = state.isVisible) === null || _state$isVisible === void 0 ? void 0 : _state$isVisible.call(state));
|
|
61
|
+
});
|
|
62
|
+
}; // --------------------------------------------------------------------------
|
|
63
|
+
|
|
53
64
|
|
|
54
65
|
publicAPI.requestData = function (inData, outData) {
|
|
55
66
|
var _model$internalArrays = model.internalArrays,
|
|
56
67
|
points = _model$internalArrays.points,
|
|
57
68
|
scale = _model$internalArrays.scale,
|
|
58
69
|
color = _model$internalArrays.color;
|
|
59
|
-
var list = publicAPI.getRepresentationStates(inData[0])
|
|
60
|
-
return state.getOrigin && state.getOrigin() && state.isVisible && state.isVisible();
|
|
61
|
-
});
|
|
70
|
+
var list = publicAPI.getRepresentationStates(inData[0]);
|
|
62
71
|
var totalCount = list.length;
|
|
63
72
|
|
|
64
73
|
if (color.getNumberOfValues() !== totalCount) {
|
|
@@ -66,14 +66,23 @@ function vtkSphereContextRepresentation(publicAPI, model) {
|
|
|
66
66
|
model.pipelines.circle.actor.getProperty().setOpacity(opacity);
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
var superGetRepresentationStates = publicAPI.getRepresentationStates;
|
|
70
|
+
|
|
71
|
+
publicAPI.getRepresentationStates = function () {
|
|
72
|
+
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : model.inputData[0];
|
|
73
|
+
return superGetRepresentationStates(input).filter(function (state) {
|
|
74
|
+
var _state$getOrigin, _state$isVisible;
|
|
75
|
+
|
|
76
|
+
return ((_state$getOrigin = state.getOrigin) === null || _state$getOrigin === void 0 ? void 0 : _state$getOrigin.call(state)) && ((_state$isVisible = state.isVisible) === null || _state$isVisible === void 0 ? void 0 : _state$isVisible.call(state));
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
69
80
|
publicAPI.requestData = function (inData, outData) {
|
|
70
81
|
var _model$internalArrays = model.internalArrays,
|
|
71
82
|
points = _model$internalArrays.points,
|
|
72
83
|
scale = _model$internalArrays.scale,
|
|
73
84
|
color = _model$internalArrays.color;
|
|
74
|
-
var list = publicAPI.getRepresentationStates(inData[0])
|
|
75
|
-
return state.getOrigin && state.getOrigin() && state.isVisible && state.isVisible();
|
|
76
|
-
});
|
|
85
|
+
var list = publicAPI.getRepresentationStates(inData[0]);
|
|
77
86
|
var totalCount = list.length;
|
|
78
87
|
|
|
79
88
|
if (color.getNumberOfValues() !== totalCount) {
|
|
@@ -96,6 +96,17 @@ function vtkSphereHandleRepresentation(publicAPI, model) {
|
|
|
96
96
|
publicAPI.setDisplayCallback = function (callback) {
|
|
97
97
|
model.displayCallback = callback;
|
|
98
98
|
model.displayMapper.setCallback(callback ? callbackProxy : null);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var superGetRepresentationStates = publicAPI.getRepresentationStates;
|
|
102
|
+
|
|
103
|
+
publicAPI.getRepresentationStates = function () {
|
|
104
|
+
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : model.inputData[0];
|
|
105
|
+
return superGetRepresentationStates(input).filter(function (state) {
|
|
106
|
+
var _state$getOrigin, _state$isVisible;
|
|
107
|
+
|
|
108
|
+
return ((_state$getOrigin = state.getOrigin) === null || _state$getOrigin === void 0 ? void 0 : _state$getOrigin.call(state)) && ((_state$isVisible = state.isVisible) === null || _state$isVisible === void 0 ? void 0 : _state$isVisible.call(state));
|
|
109
|
+
});
|
|
99
110
|
}; // --------------------------------------------------------------------------
|
|
100
111
|
|
|
101
112
|
|
|
@@ -104,9 +115,7 @@ function vtkSphereHandleRepresentation(publicAPI, model) {
|
|
|
104
115
|
points = _model$internalArrays.points,
|
|
105
116
|
scale = _model$internalArrays.scale,
|
|
106
117
|
color = _model$internalArrays.color;
|
|
107
|
-
var list = publicAPI.getRepresentationStates(inData[0])
|
|
108
|
-
return state.getOrigin && state.getOrigin() && state.isVisible && state.isVisible();
|
|
109
|
-
});
|
|
118
|
+
var list = publicAPI.getRepresentationStates(inData[0]);
|
|
110
119
|
var totalCount = list.length;
|
|
111
120
|
|
|
112
121
|
if (color.getNumberOfValues() !== totalCount) {
|