@kitware/vtk.js 21.4.1 → 21.6.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/CONTRIBUTING.md CHANGED
@@ -62,7 +62,7 @@ Please follow the coding style:
62
62
  If committing changes to `vtk.js@next` or `vtk.js@next-major`, then set your base branch to be `next`
63
63
  or `next-major`, respectively. For more info see the section on release channels below.
64
64
 
65
- 8. vtk.js uses GitHub for code review and Travis-CI to test proposed patches before they are merged.
65
+ 8. vtk.js uses GitHub for code review and Github Actions to validate proposed patches before they are merged.
66
66
 
67
67
  ## Release Channels
68
68
 
@@ -110,7 +110,7 @@ you are satisfied with the staging branch changes, you can then merge into eithe
110
110
 
111
111
  To create and debug a test:
112
112
  - Create a testFuncNameToTest.js in a "test" folder of the class to test.
113
- - Add the test path into Sources/tests.js and temporarily comment the other tests
113
+ - If you want to run just your test, use `test.only(...)` instead of `test(...)`.
114
114
  - Run `npm run test:debug`
115
115
  - In the opened window, click the Debug button and place breakpoints in browser debugger.
116
116
 
@@ -1,269 +1,318 @@
1
1
  import { vtkObject } from '@kitware/vtk.js/interfaces';
2
2
 
3
3
  export enum ColorSpace {
4
- RGB,
5
- HSV,
6
- LAB,
7
- DIVERGING,
4
+ RGB,
5
+ HSV,
6
+ LAB,
7
+ DIVERGING,
8
8
  }
9
9
 
10
10
  export enum Scale {
11
- LINEAR,
12
- LOG10,
11
+ LINEAR,
12
+ LOG10,
13
13
  }
14
14
 
15
15
  /* TODO: use VtkScalarsToColors instead of VtkObject */
16
16
  export interface vtkColorTransferFunction extends vtkObject {
17
-
18
- /**
19
- * Add a point defined in RGB
20
- * @param {Number} x The index of the point.
21
- * @param {Number} r Defines the red component (between 0 and 1).
22
- * @param {Number} g Defines the green component (between 0 and 1).
23
- * @param {Number} b Defines the blue component (between 0 and 1).
24
- */
25
- addRGBPoint(x: number, r: number, g: number, b: number): number;
26
-
27
- /**
28
- * Add a point defined in RGB
29
- * @param {Number} x The index of the point.
30
- * @param {Number} r Defines the red component (between 0 and 1).
31
- * @param {Number} g Defines the green component (between 0 and 1).
32
- * @param {Number} b Defines the blue component (between 0 and 1).
33
- * @param {Number} [midpoint]
34
- * @param {Number} [sharpness]
35
- */
36
- addRGBPointLong(x: number, r: number, g: number, b: number, midpoint?: number, sharpness?: number): number;
37
-
38
- /**
39
- * Add a point defined in HSV
40
- * @param {Number} x The index of the point.
41
- * @param {Number} h Defines the hue of the color (between 0 and 1).
42
- * @param {Number} s Defines the saturation of the color (between 0 and 1).
43
- * @param {Number} v Defines the value of the color (between 0 and 1).
44
- */
45
- addHSVPoint(x: number, h: number, s: number, v: number): number;
46
-
47
- /**
48
- * Add a line defined in RGB
49
- * @param {Number} x1 The index of the first point.
50
- * @param {Number} r1 Defines the red component of the first point(between 0 and 1).
51
- * @param {Number} g1 Defines the green component of the first point(between 0 and 1).
52
- * @param {Number} b1 Defines the red component of the first point (between 0 and 1).
53
- * @param {Number} x2 The index of the second point.
54
- * @param {Number} r2 Defines the red component of the second point (between 0 and 1).
55
- * @param {Number} g2 Defines the green component of the second point (between 0 and 1).
56
- * @param {Number} b2 Defines the blue component of the second point (between 0 and 1).
57
- */
58
- addRGBSegment(x1: number, r1: number, g1: number, b1: number, x2: number, r2: number, g2: number, b2: number): void;
59
-
60
- /**
61
- * Add a line defined in HSV
62
- * @param {Number} x1 The index of the first point.
63
- * @param {Number} h1 Defines the hue of the color of the first point (between 0 and 1).
64
- * @param {Number} s1 Defines the saturation of the color of the first point (between 0 and 1).
65
- * @param {Number} v1 Defines the value of the color of the first point (between 0 and 1).
66
- * @param {Number} x2 The index of the second point.
67
- * @param {Number} h2 Defines the hue of the colorof the second point (between 0 and 1).
68
- * @param {Number} s2 Defines the saturation of the color of the second point (between 0 and 1).
69
- * @param {Number} v2 Defines the value of the color of the second point (between 0 and 1).
70
- */
71
- addHSVSegment(x1: number, h1: number, s1: number, v1: number, x2: number, h2: number, s2: number, v2: number): void;
72
-
73
-
74
- /**
75
- * Add a point defined in HSV
76
- * @param {Number} x The index of the point.
77
- * @param {Number} h Defines the hue of the color (between 0 and 1).
78
- * @param {Number} s Defines the saturation of the color (between 0 and 1).
79
- * @param {Number} v Defines the value of the color (between 0 and 1).
80
- * @param {Number} [midpoint]
81
- * @param {Number} [sharpness]
82
- */
83
- addHSVPointLong(x: number, h: number, s: number, v: number, midpoint?: number, sharpness?: number): number;
84
-
85
- /**
86
- * Get the number of points which specify this function
87
- */
88
- getSize(): number;
89
-
90
- /**
91
- * Set nodes directly
92
- * @param nodes
93
- */
94
- setNodes(nodes: any): void;
95
-
96
- /**
97
- * Sort the vector in increasing order, then fill in
98
- * the Range
99
- */
100
- sortAndUpdateRange(): void;
101
-
102
- /**
103
- *
104
- */
105
- updateRange(): boolean;
106
-
107
- /**
108
- * Remove a point
109
- * @param {Number} x The index of the point.
110
- */
111
- removePoint(x: number): number;
112
-
113
- /**
114
- * Moves point from oldX to newX.
115
- *
116
- * It removed the point from oldX. If any point existed at newX, it will also be removed.
117
- * @param {Number} oldX The old index of the point.
118
- * @param {Number} newX The new index of the point.
119
- */
120
- movePoint(oldX: number, newX: number): void;
121
-
122
- /**
123
- * Remove all points
124
- */
125
- removeAllPoints(): void;
126
-
127
- /**
128
- * Get the RGBA color evaluated at the specified location
129
- * @param {Number} x The index of the point.
130
- */
131
- mapValue(x: number): any;
132
-
133
- /**
134
- * Get the RGB color evaluated at the specified location
135
- * @param {Number} x The index of the point.
136
- * @param {Number[]} rgb The Array of the RGB color to fill.
137
- */
138
- getColor(x: number, rgb: number[]): void;
139
-
140
- /**
141
- * Get the red color evaluated at the specified location
142
- * @param {Number} x The index of the point.
143
- */
144
- getRedValue(x: number): number;
145
-
146
- /**
147
- * Get the green color evaluated at the specified location
148
- * @param {Number} x The index of the point.
149
- */
150
- getGreenValue(x: number): number;
151
-
152
- /**
153
- * Get the blue color evaluated at the specified location
154
- * @param {Number} x The index of the point.
155
- */
156
- getBlueValue(x: number): number;
157
-
158
- /**
159
- * Get a table of RGB colors at regular intervals along the function
160
- * @param {Number} xStart The index of the first point.
161
- * @param {Number} xEnd The index of the second point.
162
- * @param {Number} size
163
- * @param {Number[]} table
164
- */
165
- getTable(xStart: number, xEnd: number, size: number, table: number[]): void;
166
-
167
- /**
168
- * @param {Number} xStart The index of the first point.
169
- * @param {Number} xEnd The index of the first point.
170
- * @param {Number} size
171
- * @param {Boolean} withAlpha
172
- */
173
- getUint8Table(xStart: number, xEnd: number, size: number, withAlpha: boolean): Float32Array;
174
-
175
- /**
176
- * Construct a color transfer function from a table.
177
- * @param {Number} xStart The index of the first point.
178
- * @param {Number} xEnd The index of the first point.
179
- * @param {Number} size
180
- * @param {Number[]} table
181
- */
182
- buildFunctionFromTable(xStart: number, xEnd: number, size: number, table: number[]): void;
183
-
184
- /**
185
- * For the node specified by index, set/get the location (X), R, G, and B
186
- * values, midpoint, and sharpness values at the node.
187
- * @param {Number} index
188
- * @param {Number[]} val
189
- */
190
- getNodeValue(index: number, val: number[]): number;
191
-
192
- /**
193
- * For a specified index value, set the node parameters
194
- * @param {Number} index
195
- * @param {Number[]} val
196
- */
197
- setNodeValue(index: number, val: number[]): number;
198
-
199
- /**
200
- * Get the number of available colors for mapping to.
201
- */
202
- getNumberOfAvailableColors(): number;
203
-
204
- /**
205
- * Get the color given an integer index.
206
- * @param {Number} idx The index of the point.
207
- * @param {Number[]} rgba An Array of the RGBA color.
208
- */
209
- getIndexedColor(idx: number, rgba: number[]): void;
210
-
211
- /**
212
- * Defines the nodes from an array ptr with the layout [X1, R1, G1, B1, X2,
213
- * R2, G2, B2, ..., Xn, Rn, Gn, Bn] where n is the number of nodes.
214
- * @param {Number} nb
215
- * @param ptr
216
- */
217
- fillFromDataPointer(nb: number, ptr: any): void;
218
-
219
- /**
220
- * Set the range of scalars being mapped.
221
- * @param {Number} min
222
- * @param {Number} max
223
- */
224
- setMappingRange(min: number, max: number): void;
225
-
226
- /**
227
- * Remove all points out of the new range, and make sure there is a point at
228
- * each end of that range.
229
- * @param {Number[]} range
230
- */
231
- adjustRange(range: number[]): number;
232
-
233
- /**
234
- * Estimates the minimum size of a table such that it would correctly sample this function.
235
- * @param {Number} x1
236
- * @param {Number} x2
237
- */
238
- estimateMinNumberOfSamples(x1: number, x2: number): number;
239
-
240
- /**
241
- * Traverses the nodes to find the minimum distance.
242
- */
243
- findMinimumXDistance(): number;
244
-
245
- /**
246
- *
247
- * @param input
248
- * @param output
249
- * @param outFormat
250
- * @param inputOffset
251
- */
252
- mapScalarsThroughTable(input: any, output: any, outFormat: any, inputOffset: any): void;
253
-
254
- /**
255
- * Map a set of scalars through the lookup table.
256
- * @param input
257
- * @param output
258
- * @param outFormat
259
- * @param inputOffset
260
- */
261
- mapData(input: any, output: any, outFormat: any, inputOffset: any): void;
262
-
263
- /**
264
- * @param colorMap
265
- */
266
- applyColorMap(colorMap: any): void;
17
+ /**
18
+ * Add a point defined in RGB
19
+ * @param {Number} x The index of the point.
20
+ * @param {Number} r Defines the red component (between 0 and 1).
21
+ * @param {Number} g Defines the green component (between 0 and 1).
22
+ * @param {Number} b Defines the blue component (between 0 and 1).
23
+ */
24
+ addRGBPoint(x: number, r: number, g: number, b: number): number;
25
+
26
+ /**
27
+ * Add a point defined in RGB
28
+ * @param {Number} x The index of the point.
29
+ * @param {Number} r Defines the red component (between 0 and 1).
30
+ * @param {Number} g Defines the green component (between 0 and 1).
31
+ * @param {Number} b Defines the blue component (between 0 and 1).
32
+ * @param {Number} [midpoint]
33
+ * @param {Number} [sharpness]
34
+ */
35
+ addRGBPointLong(
36
+ x: number,
37
+ r: number,
38
+ g: number,
39
+ b: number,
40
+ midpoint?: number,
41
+ sharpness?: number
42
+ ): number;
43
+
44
+ /**
45
+ * Add a point defined in HSV
46
+ * @param {Number} x The index of the point.
47
+ * @param {Number} h Defines the hue of the color (between 0 and 1).
48
+ * @param {Number} s Defines the saturation of the color (between 0 and 1).
49
+ * @param {Number} v Defines the value of the color (between 0 and 1).
50
+ */
51
+ addHSVPoint(x: number, h: number, s: number, v: number): number;
52
+
53
+ /**
54
+ * Add a line defined in RGB
55
+ * @param {Number} x1 The index of the first point.
56
+ * @param {Number} r1 Defines the red component of the first point(between 0 and 1).
57
+ * @param {Number} g1 Defines the green component of the first point(between 0 and 1).
58
+ * @param {Number} b1 Defines the red component of the first point (between 0 and 1).
59
+ * @param {Number} x2 The index of the second point.
60
+ * @param {Number} r2 Defines the red component of the second point (between 0 and 1).
61
+ * @param {Number} g2 Defines the green component of the second point (between 0 and 1).
62
+ * @param {Number} b2 Defines the blue component of the second point (between 0 and 1).
63
+ */
64
+ addRGBSegment(
65
+ x1: number,
66
+ r1: number,
67
+ g1: number,
68
+ b1: number,
69
+ x2: number,
70
+ r2: number,
71
+ g2: number,
72
+ b2: number
73
+ ): void;
74
+
75
+ /**
76
+ * Add a line defined in HSV
77
+ * @param {Number} x1 The index of the first point.
78
+ * @param {Number} h1 Defines the hue of the color of the first point (between 0 and 1).
79
+ * @param {Number} s1 Defines the saturation of the color of the first point (between 0 and 1).
80
+ * @param {Number} v1 Defines the value of the color of the first point (between 0 and 1).
81
+ * @param {Number} x2 The index of the second point.
82
+ * @param {Number} h2 Defines the hue of the colorof the second point (between 0 and 1).
83
+ * @param {Number} s2 Defines the saturation of the color of the second point (between 0 and 1).
84
+ * @param {Number} v2 Defines the value of the color of the second point (between 0 and 1).
85
+ */
86
+ addHSVSegment(
87
+ x1: number,
88
+ h1: number,
89
+ s1: number,
90
+ v1: number,
91
+ x2: number,
92
+ h2: number,
93
+ s2: number,
94
+ v2: number
95
+ ): void;
96
+
97
+ /**
98
+ * Add a point defined in HSV
99
+ * @param {Number} x The index of the point.
100
+ * @param {Number} h Defines the hue of the color (between 0 and 1).
101
+ * @param {Number} s Defines the saturation of the color (between 0 and 1).
102
+ * @param {Number} v Defines the value of the color (between 0 and 1).
103
+ * @param {Number} [midpoint]
104
+ * @param {Number} [sharpness]
105
+ */
106
+ addHSVPointLong(
107
+ x: number,
108
+ h: number,
109
+ s: number,
110
+ v: number,
111
+ midpoint?: number,
112
+ sharpness?: number
113
+ ): number;
114
+
115
+ /**
116
+ * Get the number of points which specify this function
117
+ */
118
+ getSize(): number;
119
+
120
+ /**
121
+ * Set nodes directly
122
+ * @param nodes
123
+ *
124
+ * @returns true if a change happen
125
+ */
126
+ setNodes(nodes: any): boolean;
127
+
128
+ /**
129
+ * Sort the vector in increasing order, then fill in
130
+ * the Range
131
+ *
132
+ * @returns true if a change happen
133
+ */
134
+ sortAndUpdateRange(): boolean;
135
+
136
+ /**
137
+ * @returns true if a change happen
138
+ */
139
+ updateRange(): boolean;
140
+
141
+ /**
142
+ * Remove a point
143
+ * @param {Number} x The index of the point.
144
+ */
145
+ removePoint(x: number): number;
146
+
147
+ /**
148
+ * Moves point from oldX to newX.
149
+ *
150
+ * It removed the point from oldX. If any point existed at newX, it will also be removed.
151
+ * @param {Number} oldX The old index of the point.
152
+ * @param {Number} newX The new index of the point.
153
+ */
154
+ movePoint(oldX: number, newX: number): void;
155
+
156
+ /**
157
+ * Remove all points
158
+ */
159
+ removeAllPoints(): void;
160
+
161
+ /**
162
+ * Get the RGBA color evaluated at the specified location
163
+ * @param {Number} x The index of the point.
164
+ */
165
+ mapValue(x: number): any;
166
+
167
+ /**
168
+ * Get the RGB color evaluated at the specified location
169
+ * @param {Number} x The index of the point.
170
+ * @param {Number[]} rgb The Array of the RGB color to fill.
171
+ */
172
+ getColor(x: number, rgb: number[]): void;
173
+
174
+ /**
175
+ * Get the red color evaluated at the specified location
176
+ * @param {Number} x The index of the point.
177
+ */
178
+ getRedValue(x: number): number;
179
+
180
+ /**
181
+ * Get the green color evaluated at the specified location
182
+ * @param {Number} x The index of the point.
183
+ */
184
+ getGreenValue(x: number): number;
185
+
186
+ /**
187
+ * Get the blue color evaluated at the specified location
188
+ * @param {Number} x The index of the point.
189
+ */
190
+ getBlueValue(x: number): number;
191
+
192
+ /**
193
+ * Get a table of RGB colors at regular intervals along the function
194
+ * @param {Number} xStart The index of the first point.
195
+ * @param {Number} xEnd The index of the second point.
196
+ * @param {Number} size
197
+ * @param {Number[]} table
198
+ */
199
+ getTable(xStart: number, xEnd: number, size: number, table: number[]): void;
200
+
201
+ /**
202
+ * @param {Number} xStart The index of the first point.
203
+ * @param {Number} xEnd The index of the first point.
204
+ * @param {Number} size
205
+ * @param {Boolean} withAlpha
206
+ */
207
+ getUint8Table(
208
+ xStart: number,
209
+ xEnd: number,
210
+ size: number,
211
+ withAlpha: boolean
212
+ ): Float32Array;
213
+
214
+ /**
215
+ * Construct a color transfer function from a table.
216
+ * @param {Number} xStart The index of the first point.
217
+ * @param {Number} xEnd The index of the first point.
218
+ * @param {Number} size
219
+ * @param {Number[]} table
220
+ */
221
+ buildFunctionFromTable(
222
+ xStart: number,
223
+ xEnd: number,
224
+ size: number,
225
+ table: number[]
226
+ ): void;
227
+
228
+ /**
229
+ * For the node specified by index, set/get the location (X), R, G, and B
230
+ * values, midpoint, and sharpness values at the node.
231
+ * @param {Number} index
232
+ * @param {Number[]} val
233
+ */
234
+ getNodeValue(index: number, val: number[]): number;
235
+
236
+ /**
237
+ * For a specified index value, set the node parameters
238
+ * @param {Number} index
239
+ * @param {Number[]} val
240
+ */
241
+ setNodeValue(index: number, val: number[]): number;
242
+
243
+ /**
244
+ * Get the number of available colors for mapping to.
245
+ */
246
+ getNumberOfAvailableColors(): number;
247
+
248
+ /**
249
+ * Get the color given an integer index.
250
+ * @param {Number} idx The index of the point.
251
+ * @param {Number[]} rgba An Array of the RGBA color.
252
+ */
253
+ getIndexedColor(idx: number, rgba: number[]): void;
254
+
255
+ /**
256
+ * Defines the nodes from an array ptr with the layout [X1, R1, G1, B1, X2,
257
+ * R2, G2, B2, ..., Xn, Rn, Gn, Bn] where n is the number of nodes.
258
+ * @param {Number} nb
259
+ * @param ptr
260
+ */
261
+ fillFromDataPointer(nb: number, ptr: any): void;
262
+
263
+ /**
264
+ * Set the range of scalars being mapped.
265
+ * @param {Number} min
266
+ * @param {Number} max
267
+ */
268
+ setMappingRange(min: number, max: number): void;
269
+
270
+ /**
271
+ * Remove all points out of the new range, and make sure there is a point at
272
+ * each end of that range.
273
+ * @param {Number[]} range
274
+ */
275
+ adjustRange(range: number[]): number;
276
+
277
+ /**
278
+ * Estimates the minimum size of a table such that it would correctly sample this function.
279
+ * @param {Number} x1
280
+ * @param {Number} x2
281
+ */
282
+ estimateMinNumberOfSamples(x1: number, x2: number): number;
283
+
284
+ /**
285
+ * Traverses the nodes to find the minimum distance.
286
+ */
287
+ findMinimumXDistance(): number;
288
+
289
+ /**
290
+ *
291
+ * @param input
292
+ * @param output
293
+ * @param outFormat
294
+ * @param inputOffset
295
+ */
296
+ mapScalarsThroughTable(
297
+ input: any,
298
+ output: any,
299
+ outFormat: any,
300
+ inputOffset: any
301
+ ): void;
302
+
303
+ /**
304
+ * Map a set of scalars through the lookup table.
305
+ * @param input
306
+ * @param output
307
+ * @param outFormat
308
+ * @param inputOffset
309
+ */
310
+ mapData(input: any, output: any, outFormat: any, inputOffset: any): void;
311
+
312
+ /**
313
+ * @param colorMap
314
+ */
315
+ applyColorMap(colorMap: any): void;
267
316
  }
268
317
 
269
318
  /**
@@ -273,7 +322,11 @@ export interface vtkColorTransferFunction extends vtkObject {
273
322
  * @param model object on which data structure will be bounds (protected)
274
323
  * @param {object} [initialValues] (default: {})
275
324
  */
276
- export function extend(publicAPI: object, model: object, initialValues?: object): void;
325
+ export function extend(
326
+ publicAPI: object,
327
+ model: object,
328
+ initialValues?: object
329
+ ): void;
277
330
 
278
331
  /**
279
332
  * Method use to create a new instance of vtkColorTransferFunction
@@ -303,7 +356,7 @@ export function newInstance(initialValues?: object): vtkColorTransferFunction;
303
356
  */
304
357
 
305
358
  export declare const vtkColorTransferFunction: {
306
- newInstance: typeof newInstance,
307
- extend: typeof extend,
359
+ newInstance: typeof newInstance;
360
+ extend: typeof extend;
308
361
  };
309
362
  export default vtkColorTransferFunction;
@@ -221,23 +221,32 @@ function vtkColorTransferFunction(publicAPI, model) {
221
221
 
222
222
  publicAPI.setNodes = function (nodes) {
223
223
  if (model.nodes !== nodes) {
224
+ var before = JSON.stringify(model.nodes);
224
225
  model.nodes = nodes;
225
- publicAPI.sortAndUpdateRange();
226
+ var after = JSON.stringify(model.nodes);
227
+ return publicAPI.sortAndUpdateRange() || before !== after;
226
228
  }
229
+
230
+ return false;
227
231
  }; //----------------------------------------------------------------------------
228
232
  // Sort the vector in increasing order, then fill in
229
233
  // the Range
230
234
 
231
235
 
232
236
  publicAPI.sortAndUpdateRange = function () {
237
+ var before = JSON.stringify(model.nodes);
233
238
  model.nodes.sort(function (a, b) {
234
239
  return a.x - b.x;
235
240
  });
241
+ var after = JSON.stringify(model.nodes);
236
242
  var modifiedInvoked = publicAPI.updateRange(); // If range is updated, Modified() has been called, don't call it again.
237
243
 
238
- if (!modifiedInvoked) {
244
+ if (!modifiedInvoked && before !== after) {
239
245
  publicAPI.modified();
246
+ return true;
240
247
  }
248
+
249
+ return modifiedInvoked;
241
250
  }; //----------------------------------------------------------------------------
242
251
 
243
252
 
@@ -102,12 +102,29 @@ function bindArrays(arraysToBind) {
102
102
 
103
103
  function createNewArrayHandler(instance, arrayMetadata, arraysToBind) {
104
104
  return function (values) {
105
+ var regMethod = arrayMetadata.registration ? arrayMetadata.registration : 'addArray';
106
+ var location = arrayMetadata.location ? instance.getReferenceByName(arrayMetadata.location) : instance; // Try to prevent unncessary modified
107
+
108
+ var previousArray = null;
109
+
110
+ if (arrayMetadata.location) {
111
+ previousArray = instance.getReferenceByName(arrayMetadata.location).getArray(arrayMetadata.name);
112
+ } else {
113
+ previousArray = instance["get".concat(regMethod.substring(3))]();
114
+ }
115
+
116
+ if (previousArray) {
117
+ if (previousArray.getData() !== values) {
118
+ arraysToBind.push([previousArray.setData, [values, arrayMetadata.numberOfComponents]]);
119
+ }
120
+
121
+ return previousArray;
122
+ }
123
+
105
124
  var vtkClass = arrayMetadata.vtkClass ? arrayMetadata.vtkClass : 'vtkDataArray';
106
125
  var array = DATA_ARRAY_MAPPER[vtkClass].newInstance(_objectSpread(_objectSpread({}, arrayMetadata), {}, {
107
126
  values: values
108
127
  }));
109
- var regMethod = arrayMetadata.registration ? arrayMetadata.registration : 'addArray';
110
- var location = arrayMetadata.location ? instance.getReferenceByName(arrayMetadata.location) : instance;
111
128
  arraysToBind.push([location[regMethod], [array]]);
112
129
  return array;
113
130
  };
@@ -273,6 +290,11 @@ function genericUpdater(instance, state, context) {
273
290
  context.start(); // -> start(arraysToBind)
274
291
 
275
292
  dependencies.push(Promise.all(promises).then(function () {
293
+ // Since some arrays are getting updated, we should modify our dataset
294
+ if (arraysToBind.length) {
295
+ instance.modified();
296
+ }
297
+
276
298
  bindArrays(arraysToBind);
277
299
  return true;
278
300
  }).catch(function (error) {
@@ -429,8 +451,6 @@ function colorTransferFunctionUpdater(instance, state, context) {
429
451
  instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
430
452
  nodes: nodes
431
453
  }), true);
432
- instance.sortAndUpdateRange();
433
- instance.modified();
434
454
  context.end(); // -> end(colorTransferFunctionUpdater)
435
455
  }
436
456
 
@@ -454,12 +474,30 @@ function piecewiseFunctionUpdater(instance, state, context) {
454
474
  instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
455
475
  nodes: nodes
456
476
  }), true);
457
- instance.sortAndUpdateRange();
458
- instance.modified();
477
+ instance.sortAndUpdateRange(); // instance.modified();
478
+
459
479
  context.end(); // -> end(piecewiseFunctionUpdater)
460
480
  } // ----------------------------------------------------------------------------
461
481
 
462
482
 
483
+ function removeUnavailableArrays(fields, availableNames) {
484
+ var namesToDelete = [];
485
+ var size = fields.getNumberOfArrays();
486
+
487
+ for (var i = 0; i < size; i++) {
488
+ var array = fields.getArray(i);
489
+ var name = array.getName();
490
+
491
+ if (!availableNames.has(name)) {
492
+ namesToDelete.push(name);
493
+ }
494
+ }
495
+
496
+ for (var _i = 0; _i < namesToDelete.length; _i++) {
497
+ fields.removeArray(namesToDelete[_i]);
498
+ }
499
+ }
500
+
463
501
  function createDataSetUpdate() {
464
502
  var piecesToFetch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
465
503
  return function (instance, state, context) {
@@ -489,8 +527,18 @@ function createDataSetUpdate() {
489
527
 
490
528
  delete state.properties.fields; // Reset any pre-existing fields array
491
529
 
492
- instance.getPointData().removeAllArrays();
493
- instance.getCellData().removeAllArrays(); // Generic handling
530
+ var arrayToKeep = {
531
+ pointData: new Set(),
532
+ cellData: new Set(),
533
+ fieldData: new Set()
534
+ };
535
+ fieldsArrays.forEach(function (_ref5) {
536
+ var location = _ref5.location,
537
+ name = _ref5.name;
538
+ arrayToKeep[location].add(name);
539
+ });
540
+ removeUnavailableArrays(instance.getPointData(), arrayToKeep.pointData);
541
+ removeUnavailableArrays(instance.getCellData(), arrayToKeep.cellData); // Generic handling
494
542
 
495
543
  var res = genericUpdater(instance, state, context); // Finish what we started
496
544
 
@@ -22,6 +22,19 @@ var SCREENSHOT_PLACEHOLDER = {
22
22
  width: '100%',
23
23
  height: '100%'
24
24
  };
25
+ var DEFAULT_RESET_FACTORS = {
26
+ vr: {
27
+ rescaleFactor: 1.0,
28
+ translateZ: -0.7 // 0.7 m forward from the camera
29
+
30
+ },
31
+ ar: {
32
+ rescaleFactor: 0.25,
33
+ // scale down AR for viewing comfort by default
34
+ translateZ: -0.5 // 0.5 m forward from the camera
35
+
36
+ }
37
+ };
25
38
 
26
39
  function checkRenderTargetSupport(gl, format, type) {
27
40
  // create temporary frame buffer and texture
@@ -245,21 +258,28 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
245
258
  // typically in response to a user request such as a button press
246
259
 
247
260
 
248
- publicAPI.startXR = function () {
261
+ publicAPI.startXR = function (isAR) {
249
262
  if (navigator.xr === undefined) {
250
263
  throw new Error('WebXR is not available');
251
264
  }
252
265
 
253
- if (!navigator.xr.isSessionSupported('immersive-vr')) {
254
- throw new Error('VR display is not available');
266
+ model.xrSessionIsAR = isAR;
267
+ var sessionType = isAR ? 'immersive-ar' : 'immersive-vr';
268
+
269
+ if (!navigator.xr.isSessionSupported(sessionType)) {
270
+ if (isAR) {
271
+ throw new Error('Device does not support AR session');
272
+ } else {
273
+ throw new Error('VR display is not available');
274
+ }
255
275
  }
256
276
 
257
277
  if (model.xrSession === null) {
258
- navigator.xr.requestSession('immersive-vr').then(publicAPI.enterXR, function () {
259
- throw new Error('Failed to create VR session!');
278
+ navigator.xr.requestSession(sessionType).then(publicAPI.enterXR, function () {
279
+ throw new Error('Failed to create XR session!');
260
280
  });
261
281
  } else {
262
- throw new Error('VR Session already exists!');
282
+ throw new Error('XR Session already exists!');
263
283
  }
264
284
  }; // When an XR session is available, set up the XRWebGLLayer
265
285
  // and request the first animation frame for the device
@@ -276,7 +296,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
276
296
  model.oldCanvasSize = model.size.slice();
277
297
 
278
298
  if (!(model.xrSession !== null)) {
279
- _context.next = 14;
299
+ _context.next = 15;
280
300
  break;
281
301
  }
282
302
 
@@ -293,15 +313,16 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
293
313
  model.xrSession.requestReferenceSpace('local').then(function (refSpace) {
294
314
  model.xrReferenceSpace = refSpace;
295
315
  });
316
+ publicAPI.resetXRScene();
296
317
  model.renderable.getInteractor().switchToXRAnimation();
297
318
  model.xrSceneFrame = model.xrSession.requestAnimationFrame(publicAPI.xrRender);
298
- _context.next = 15;
319
+ _context.next = 16;
299
320
  break;
300
321
 
301
- case 14:
322
+ case 15:
302
323
  throw new Error('Failed to enter VR with a null xrSession.');
303
324
 
304
- case 15:
325
+ case 16:
305
326
  case "end":
306
327
  return _context.stop();
307
328
  }
@@ -314,6 +335,36 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
314
335
  };
315
336
  }();
316
337
 
338
+ publicAPI.resetXRScene = function () {
339
+ var inputRescaleFactor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_RESET_FACTORS.vr.rescaleFactor;
340
+ var inputTranslateZ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_RESET_FACTORS.vr.translateZ;
341
+ // Adjust world-to-physical parameters for different modalities
342
+ // Default parameter values are for VR (model.xrSessionIsAR == false)
343
+ var rescaleFactor = inputRescaleFactor;
344
+ var translateZ = inputTranslateZ;
345
+
346
+ if (model.xrSessionIsAR && rescaleFactor === DEFAULT_RESET_FACTORS.vr.rescaleFactor) {
347
+ // Scale down by default in AR
348
+ rescaleFactor = DEFAULT_RESET_FACTORS.ar.rescaleFactor;
349
+ }
350
+
351
+ if (model.xrSessionIsAR && translateZ === DEFAULT_RESET_FACTORS.vr.translateZ) {
352
+ // Default closer to the camera in AR
353
+ translateZ = DEFAULT_RESET_FACTORS.ar.translateZ;
354
+ }
355
+
356
+ var ren = model.renderable.getRenderers()[0];
357
+ ren.resetCamera();
358
+ var camera = ren.getActiveCamera();
359
+ var physicalScale = camera.getPhysicalScale();
360
+ var physicalTranslation = camera.getPhysicalTranslation();
361
+ physicalScale /= rescaleFactor;
362
+ translateZ *= physicalScale;
363
+ physicalTranslation[2] += translateZ;
364
+ camera.setPhysicalScale(physicalScale);
365
+ camera.setPhysicalTranslation(physicalTranslation);
366
+ };
367
+
317
368
  publicAPI.stopXR = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
318
369
  var gl, ren;
319
370
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
@@ -348,7 +399,10 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
348
399
  model.xrSession = null;
349
400
 
350
401
  case 10:
351
- publicAPI.setSize.apply(publicAPI, _toConsumableArray(model.oldCanvasSize)); // Reset to default canvas
402
+ if (model.oldCanvasSize !== undefined) {
403
+ publicAPI.setSize.apply(publicAPI, _toConsumableArray(model.oldCanvasSize));
404
+ } // Reset to default canvas
405
+
352
406
 
353
407
  ren = model.renderable.getRenderers()[0];
354
408
  ren.getActiveCamera().setProjectionMatrix(null);
@@ -378,6 +432,12 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
378
432
 
379
433
  if (xrPose) {
380
434
  gl = publicAPI.get3DContext();
435
+
436
+ if (model.xrSessionIsAR && model.oldCanvasSize !== undefined) {
437
+ gl.canvas.width = model.oldCanvasSize[0];
438
+ gl.canvas.height = model.oldCanvasSize[1];
439
+ }
440
+
381
441
  glLayer = xrSession.renderState.baseLayer;
382
442
  gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
383
443
  gl.clear(gl.COLOR_BUFFER_BIT);
@@ -387,15 +447,18 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
387
447
 
388
448
  xrPose.views.forEach(function (view) {
389
449
  var viewport = glLayer.getViewport(view);
390
- gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
391
-
392
- if (view.eye === 'left') {
393
- ren.setViewport(0, 0, 0.5, 1.0);
394
- } else if (view.eye === 'right') {
395
- ren.setViewport(0.5, 0, 1.0, 1.0);
396
- } else {
397
- // No handling for non-eye viewport
398
- return;
450
+ gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); // TODO: Appropriate handling for AR passthrough on HMDs
451
+ // with two eyes will require further investigation.
452
+
453
+ if (!model.xrSessionIsAR) {
454
+ if (view.eye === 'left') {
455
+ ren.setViewport(0, 0, 0.5, 1.0);
456
+ } else if (view.eye === 'right') {
457
+ ren.setViewport(0.5, 0, 1.0, 1.0);
458
+ } else {
459
+ // No handling for non-eye viewport
460
+ return;
461
+ }
399
462
  }
400
463
 
401
464
  ren.getActiveCamera().computeViewParametersFromPhysicalMatrix(view.transform.inverse.matrix);
@@ -777,7 +840,9 @@ var DEFAULT_VALUES = {
777
840
  // attempt webgl2 on by default
778
841
  activeFramebuffer: null,
779
842
  xrSession: null,
843
+ xrSessionIsAR: false,
780
844
  xrReferenceSpace: null,
845
+ xrSupported: true,
781
846
  imageFormat: 'image/png',
782
847
  useOffScreen: false,
783
848
  useBackgroundImage: false
@@ -820,7 +885,7 @@ function extend(publicAPI, model) {
820
885
  macro.event(publicAPI, model, 'imageReady');
821
886
  macro.event(publicAPI, model, 'haveVRDisplay'); // Build VTK API
822
887
 
823
- macro.get(publicAPI, model, ['shaderCache', 'textureUnitManager', 'webgl2', 'vrDisplay', 'useBackgroundImage']);
888
+ macro.get(publicAPI, model, ['shaderCache', 'textureUnitManager', 'webgl2', 'vrDisplay', 'useBackgroundImage', 'xrSupported']);
824
889
  macro.setGet(publicAPI, model, ['initialized', 'context', 'canvas', 'renderPasses', 'notifyStartCaptureImage', 'defaultToWebgl2', 'cursor', 'useOffScreen', // might want to make this not call modified as
825
890
  // we change the active framebuffer a lot. Or maybe
826
891
  // only mark modified if the size or depth
@@ -616,7 +616,8 @@ var DEFAULT_VALUES = {
616
616
  imageFormat: 'image/png',
617
617
  useOffScreen: false,
618
618
  useBackgroundImage: false,
619
- nextPropID: 1
619
+ nextPropID: 1,
620
+ xrSupported: false
620
621
  }; // ----------------------------------------------------------------------------
621
622
 
622
623
  function extend(publicAPI, model) {
@@ -652,7 +653,7 @@ function extend(publicAPI, model) {
652
653
  macro.event(publicAPI, model, 'imageReady');
653
654
  macro.event(publicAPI, model, 'initialized'); // Build VTK API
654
655
 
655
- macro.get(publicAPI, model, ['commandEncoder', 'device', 'useBackgroundImage']);
656
+ macro.get(publicAPI, model, ['commandEncoder', 'device', 'useBackgroundImage', 'xrSupported']);
656
657
  macro.setGet(publicAPI, model, ['initialized', 'context', 'canvas', 'device', 'renderPasses', 'notifyStartCaptureImage', 'cursor', 'useOffScreen']);
657
658
  macro.setGetArray(publicAPI, model, ['size'], 2); // Object methods
658
659
 
@@ -178,7 +178,7 @@ function vtkWebGPUStorageBuffer(publicAPI, model) {
178
178
  lines.push(" ".concat(entry.name, ": ").concat(entry.type, ";"));
179
179
  }
180
180
 
181
- lines.push("\n};\n[[block]] struct ".concat(model.name, "Struct\n{\n values: array<").concat(model.name, "StructEntry>;\n};\n[[binding(").concat(binding, "), group(").concat(group, ")]] var<storage, read> ").concat(model.name, ": ").concat(model.name, "Struct;\n"));
181
+ lines.push("\n};\nstruct ".concat(model.name, "Struct\n{\n values: array<").concat(model.name, "StructEntry>;\n};\n[[binding(").concat(binding, "), group(").concat(group, ")]] var<storage, read> ").concat(model.name, ": ").concat(model.name, "Struct;\n"));
182
182
  return lines.join('\n');
183
183
  };
184
184
 
@@ -45,18 +45,34 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
45
45
  }
46
46
 
47
47
  var currOffset = 0;
48
- var newEntries = []; // pack anything whose size is a multiple of 16 bytes first
49
- // this includes a couple types that don't require 16 byte alignment
50
- // such as mat2x2<f32> but that is OK
48
+ var newEntries = []; // compute the max alignment, this is required as WebGPU defines a UBO to have
49
+ // a size that is a multiple of the maxAlignment
50
+
51
+ var maxAlignment = 4;
51
52
 
52
53
  for (var i = 0; i < model.bufferEntries.length; i++) {
53
54
  var entry = model.bufferEntries[i];
54
55
 
55
- if (entry.packed === false && entry.sizeInBytes % 16 === 0) {
56
- entry.packed = true;
57
- entry.offset = currOffset;
58
- newEntries.push(entry);
59
- currOffset += entry.sizeInBytes;
56
+ if (entry.sizeInBytes % 16 === 0) {
57
+ maxAlignment = Math.max(16, maxAlignment);
58
+ }
59
+
60
+ if (entry.sizeInBytes % 8 === 0) {
61
+ maxAlignment = Math.max(8, maxAlignment);
62
+ }
63
+ } // pack anything whose size is a multiple of 16 bytes first
64
+ // this includes a couple types that don't require 16 byte alignment
65
+ // such as mat2x2<f32> but that is OK
66
+
67
+
68
+ for (var _i = 0; _i < model.bufferEntries.length; _i++) {
69
+ var _entry = model.bufferEntries[_i];
70
+
71
+ if (_entry.packed === false && _entry.sizeInBytes % 16 === 0) {
72
+ _entry.packed = true;
73
+ _entry.offset = currOffset;
74
+ newEntries.push(_entry);
75
+ currOffset += _entry.sizeInBytes;
60
76
  }
61
77
  } // now it gets tough, we have the following common types (f32, i32, u32)
62
78
  // - vec2<f32> 8 byte size, 8 byte alignment
@@ -65,18 +81,18 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
65
81
  // try adding 12 byte, 4 byte pairs
66
82
 
67
83
 
68
- for (var _i = 0; _i < model.bufferEntries.length; _i++) {
69
- var _entry = model.bufferEntries[_i];
84
+ for (var _i2 = 0; _i2 < model.bufferEntries.length; _i2++) {
85
+ var _entry2 = model.bufferEntries[_i2];
70
86
 
71
- if (_entry.packed === false && _entry.sizeInBytes === 12) {
87
+ if (_entry2.packed === false && _entry2.sizeInBytes === 12) {
72
88
  for (var i2 = 0; i2 < model.bufferEntries.length; i2++) {
73
89
  var entry2 = model.bufferEntries[i2];
74
90
 
75
91
  if (entry2.packed === false && entry2.sizeInBytes === 4) {
76
- _entry.packed = true;
77
- _entry.offset = currOffset;
78
- newEntries.push(_entry);
79
- currOffset += _entry.sizeInBytes;
92
+ _entry2.packed = true;
93
+ _entry2.offset = currOffset;
94
+ newEntries.push(_entry2);
95
+ currOffset += _entry2.sizeInBytes;
80
96
  entry2.packed = true;
81
97
  entry2.offset = currOffset;
82
98
  newEntries.push(entry2);
@@ -88,22 +104,22 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
88
104
  } // try adding 8 byte, 8 byte pairs
89
105
 
90
106
 
91
- for (var _i2 = 0; _i2 < model.bufferEntries.length; _i2++) {
92
- var _entry2 = model.bufferEntries[_i2];
107
+ for (var _i3 = 0; _i3 < model.bufferEntries.length; _i3++) {
108
+ var _entry3 = model.bufferEntries[_i3];
93
109
 
94
- if (!_entry2.packed && _entry2.sizeInBytes % 8 === 0) {
95
- for (var _i3 = _i2 + 1; _i3 < model.bufferEntries.length; _i3++) {
96
- var _entry3 = model.bufferEntries[_i3];
110
+ if (!_entry3.packed && _entry3.sizeInBytes % 8 === 0) {
111
+ for (var _i4 = _i3 + 1; _i4 < model.bufferEntries.length; _i4++) {
112
+ var _entry4 = model.bufferEntries[_i4];
97
113
 
98
- if (!_entry3.packed && _entry3.sizeInBytes % 8 === 0) {
99
- _entry2.packed = true;
100
- _entry2.offset = currOffset;
101
- newEntries.push(_entry2);
102
- currOffset += _entry2.sizeInBytes;
114
+ if (!_entry4.packed && _entry4.sizeInBytes % 8 === 0) {
103
115
  _entry3.packed = true;
104
116
  _entry3.offset = currOffset;
105
117
  newEntries.push(_entry3);
106
118
  currOffset += _entry3.sizeInBytes;
119
+ _entry4.packed = true;
120
+ _entry4.offset = currOffset;
121
+ newEntries.push(_entry4);
122
+ currOffset += _entry4.sizeInBytes;
107
123
  break;
108
124
  }
109
125
  }
@@ -111,28 +127,28 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
111
127
  } // try adding 8 byte, 4 byte 4 byte triplets
112
128
 
113
129
 
114
- for (var _i4 = 0; _i4 < model.bufferEntries.length; _i4++) {
115
- var _entry4 = model.bufferEntries[_i4];
130
+ for (var _i5 = 0; _i5 < model.bufferEntries.length; _i5++) {
131
+ var _entry5 = model.bufferEntries[_i5];
116
132
 
117
- if (!_entry4.packed && _entry4.sizeInBytes % 8 === 0) {
133
+ if (!_entry5.packed && _entry5.sizeInBytes % 8 === 0) {
118
134
  var found = false;
119
135
 
120
- for (var _i5 = 0; !found && _i5 < model.bufferEntries.length; _i5++) {
121
- var _entry5 = model.bufferEntries[_i5];
136
+ for (var _i6 = 0; !found && _i6 < model.bufferEntries.length; _i6++) {
137
+ var _entry6 = model.bufferEntries[_i6];
122
138
 
123
- if (!_entry5.packed && _entry5.sizeInBytes === 4) {
124
- for (var i3 = _i5 + 1; i3 < model.bufferEntries.length; i3++) {
139
+ if (!_entry6.packed && _entry6.sizeInBytes === 4) {
140
+ for (var i3 = _i6 + 1; i3 < model.bufferEntries.length; i3++) {
125
141
  var entry3 = model.bufferEntries[i3];
126
142
 
127
143
  if (!entry3.packed && entry3.sizeInBytes === 4) {
128
- _entry4.packed = true;
129
- _entry4.offset = currOffset;
130
- newEntries.push(_entry4);
131
- currOffset += _entry4.sizeInBytes;
132
144
  _entry5.packed = true;
133
145
  _entry5.offset = currOffset;
134
146
  newEntries.push(_entry5);
135
147
  currOffset += _entry5.sizeInBytes;
148
+ _entry6.packed = true;
149
+ _entry6.offset = currOffset;
150
+ newEntries.push(_entry6);
151
+ currOffset += _entry6.sizeInBytes;
136
152
  entry3.packed = true;
137
153
  entry3.offset = currOffset;
138
154
  newEntries.push(entry3);
@@ -149,27 +165,27 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
149
165
  // in a failed UBO
150
166
 
151
167
 
152
- for (var _i6 = 0; _i6 < model.bufferEntries.length; _i6++) {
153
- var _entry6 = model.bufferEntries[_i6];
154
-
155
- if (!_entry6.packed && _entry6.sizeInBytes > 4) {
156
- _entry6.packed = true;
157
- _entry6.offset = currOffset;
158
- newEntries.push(_entry6);
159
- currOffset += _entry6.sizeInBytes;
160
- }
161
- } // finally add remaining 4 byte items
162
-
163
-
164
168
  for (var _i7 = 0; _i7 < model.bufferEntries.length; _i7++) {
165
169
  var _entry7 = model.bufferEntries[_i7];
166
170
 
167
- if (!_entry7.packed) {
171
+ if (!_entry7.packed && _entry7.sizeInBytes > 4) {
168
172
  _entry7.packed = true;
169
173
  _entry7.offset = currOffset;
170
174
  newEntries.push(_entry7);
171
175
  currOffset += _entry7.sizeInBytes;
172
176
  }
177
+ } // finally add remaining 4 byte items
178
+
179
+
180
+ for (var _i8 = 0; _i8 < model.bufferEntries.length; _i8++) {
181
+ var _entry8 = model.bufferEntries[_i8];
182
+
183
+ if (!_entry8.packed) {
184
+ _entry8.packed = true;
185
+ _entry8.offset = currOffset;
186
+ newEntries.push(_entry8);
187
+ currOffset += _entry8.sizeInBytes;
188
+ }
173
189
  } // update entries and entryNames
174
190
 
175
191
 
@@ -177,11 +193,12 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
177
193
 
178
194
  model._bufferEntryNames.clear();
179
195
 
180
- for (var _i8 = 0; _i8 < model.bufferEntries.length; _i8++) {
181
- model._bufferEntryNames.set(model.bufferEntries[_i8].name, _i8);
196
+ for (var _i9 = 0; _i9 < model.bufferEntries.length; _i9++) {
197
+ model._bufferEntryNames.set(model.bufferEntries[_i9].name, _i9);
182
198
  }
183
199
 
184
200
  model.sizeInBytes = currOffset;
201
+ model.sizeInBytes = maxAlignment * Math.ceil(model.sizeInBytes / maxAlignment);
185
202
  model.sortDirty = false;
186
203
  };
187
204
 
@@ -284,7 +301,7 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
284
301
  publicAPI.getShaderCode = function (binding, group) {
285
302
  // sort the entries
286
303
  publicAPI.sortBufferEntries();
287
- var lines = ["[[block]] struct ".concat(model.name, "Struct\n{")];
304
+ var lines = ["struct ".concat(model.name, "Struct\n{")];
288
305
 
289
306
  for (var i = 0; i < model.bufferEntries.length; i++) {
290
307
  var entry = model.bufferEntries[i];
@@ -218,7 +218,7 @@ function vtkWebGPUVolumePass(publicAPI, model) {
218
218
  fDesc.addOutput('vec4<f32>', 'outColor1');
219
219
  fDesc.addOutput('vec4<f32>', 'outColor2');
220
220
  var code = fDesc.getCode();
221
- code = vtkWebGPUShaderCache.substitute(code, '//VTK::RenderEncoder::Impl', ['output.outColor1 = vec4<f32>(stopval, 0.0, 0.0, 0.0);', 'output.outColor2 = vec4<f32>(input.fragPos.z, 0.0, 0.0, 0.0);']).result;
221
+ code = vtkWebGPUShaderCache.substitute(code, '//VTK::RenderEncoder::Impl', ['output.outColor1 = vec4<f32>(input.fragPos.z, 0.0, 0.0, 0.0);', 'output.outColor2 = vec4<f32>(stopval, 0.0, 0.0, 0.0);']).result;
222
222
  fDesc.setCode(code);
223
223
  });
224
224
  model.depthRangeEncoder.setDescription({
package/macros.js CHANGED
@@ -304,8 +304,8 @@ function obj() {
304
304
  vtkWarningMacro("Warning: Set value to model directly ".concat(name, ", ").concat(map[name]));
305
305
  }
306
306
 
307
+ ret = model[name] !== map[name] || ret;
307
308
  model[name] = map[name];
308
- ret = true;
309
309
  }
310
310
  });
311
311
  return ret;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "21.4.1",
3
+ "version": "21.6.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",