@kitware/vtk.js 34.8.0 → 34.8.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.
@@ -384,7 +384,7 @@ function addTriangle(layers, a, b, c, verticesArray, uvArray, colorArray, color)
384
384
  uvArray.push(uv[0], uv[1]);
385
385
  });
386
386
  if (colorArray && color) {
387
- for (let i = 0; i < 3; ++i) colorArray.push(color[0], color[1], color[2]);
387
+ for (let i = 0; i < 3; ++i) colorArray.push(color[0] * 255, color[1] * 255, color[2] * 255);
388
388
  }
389
389
  }
390
390
 
@@ -417,7 +417,7 @@ function addQuad(layers, a, b, c, d, verticesArray, uvArray, colorArray, color)
417
417
  uvArray.push(uvs[2][0], uvs[2][1]);
418
418
  uvArray.push(uvs[3][0], uvs[3][1]);
419
419
  if (colorArray && color) {
420
- for (let i = 0; i < 6; ++i) colorArray.push(color[0], color[1], color[2]);
420
+ for (let i = 0; i < 6; ++i) colorArray.push(color[0] * 255, color[1] * 255, color[2] * 255);
421
421
  }
422
422
  }
423
423
 
@@ -258,7 +258,7 @@ function vtkVectorText(publicAPI, model) {
258
258
  let letterIndex = 0;
259
259
  model.shapes.forEach(shape => {
260
260
  let color = null;
261
- if (typeof model.perLetterFaceColors === 'function') {
261
+ if (model.perLetterFaceColors) {
262
262
  color = model.perLetterFaceColors(letterIndex) || [1, 1, 1];
263
263
  }
264
264
  addShape(shape, offsetSize, color);
@@ -285,12 +285,12 @@ function vtkVectorText(publicAPI, model) {
285
285
  polyData.setPolys(cells);
286
286
 
287
287
  // Set points (vertices)
288
- polyData.getPoints().setData(new Float32Array(model.verticesArray), 3);
288
+ polyData.getPoints().setData(Float32Array.from(model.verticesArray), 3);
289
289
 
290
290
  // Set texture coordinates
291
291
  const da = vtkDataArray.newInstance({
292
292
  numberOfComponents: 2,
293
- values: new Float32Array(model.uvArray),
293
+ values: Float32Array.from(model.uvArray),
294
294
  name: 'TEXCOORD_0'
295
295
  });
296
296
  pointData.addArray(da);
@@ -300,7 +300,7 @@ function vtkVectorText(publicAPI, model) {
300
300
  if (model.colorArray && model.colorArray.length) {
301
301
  const ca = vtkDataArray.newInstance({
302
302
  numberOfComponents: 3,
303
- values: new Float32Array(model.colorArray),
303
+ values: Uint8Array.from(model.colorArray),
304
304
  name: 'Colors'
305
305
  });
306
306
  pointData.addArray(ca);
@@ -5,7 +5,9 @@ import vtkHardwareSelector from './HardwareSelector.js';
5
5
  import vtkProperty from '../Core/Property.js';
6
6
  import vtkOpenGLPolyDataMapper from './PolyDataMapper.js';
7
7
  import vtkShaderProgram from './ShaderProgram.js';
8
+ import { computeCoordShiftAndScale } from './CellArrayBufferObject/helpers.js';
8
9
  import { registerOverride } from './ViewNodeFactory.js';
10
+ import { primTypes } from './Helper.js';
9
11
 
10
12
  const {
11
13
  vtkErrorMacro
@@ -25,6 +27,17 @@ const StartEvent = {
25
27
  const EndEvent = {
26
28
  type: 'EndEvent'
27
29
  };
30
+ const MAT4_BYTE_SIZE = 64;
31
+ const MAT4_ELEMENT_COUNT = 16;
32
+ function applyShiftScaleToMat(mat, shift, scale) {
33
+ // the translation component of a 4x4 column-major matrix
34
+ mat[12] = (mat[12] - shift[0]) * scale[0];
35
+ mat[13] = (mat[13] - shift[1]) * scale[1];
36
+ mat[14] = (mat[14] - shift[2]) * scale[2];
37
+ mat[0] *= scale[0];
38
+ mat[5] *= scale[1];
39
+ mat[10] *= scale[2];
40
+ }
28
41
 
29
42
  // ----------------------------------------------------------------------------
30
43
  // vtkOpenGLSphereMapper methods
@@ -389,9 +402,15 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
389
402
  return false;
390
403
  };
391
404
  publicAPI.buildBufferObjects = (ren, actor) => {
405
+ const garray = model.renderable.getMatrixArray();
406
+ const pts = model.renderable.getInputData(0).getPoints();
407
+ const {
408
+ useShiftAndScale,
409
+ coordShift,
410
+ coordScale
411
+ } = computeCoordShiftAndScale(pts);
392
412
  if (model.hardwareSupport) {
393
413
  // update the buffer objects if needed
394
- const garray = model.renderable.getMatrixArray();
395
414
  const narray = model.renderable.getNormalArray();
396
415
  const carray = model.renderable.getColorArray();
397
416
  if (!model.matrixBuffer) {
@@ -404,6 +423,13 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
404
423
  model.pickBuffer = vtkBufferObject.newInstance();
405
424
  model.pickBuffer.setOpenGLRenderWindow(model._openGLRenderWindow);
406
425
  }
426
+ if (useShiftAndScale) {
427
+ const buf = garray.buffer;
428
+ for (let ptIdx = 0; ptIdx < garray.byteLength; ptIdx += MAT4_BYTE_SIZE) {
429
+ const mat = new Float32Array(buf, ptIdx, MAT4_ELEMENT_COUNT);
430
+ applyShiftScaleToMat(mat, coordShift, coordScale);
431
+ }
432
+ }
407
433
  if (model.renderable.getBuildTime().getMTime() > model.glyphBOBuildTime.getMTime()) {
408
434
  model.matrixBuffer.upload(garray, ObjectType.ARRAY_BUFFER);
409
435
  model.normalBuffer.upload(narray, ObjectType.ARRAY_BUFFER);
@@ -430,7 +456,15 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
430
456
  model.glyphBOBuildTime.modified();
431
457
  }
432
458
  }
433
- return superClass.buildBufferObjects(ren, actor);
459
+ superClass.buildBufferObjects(ren, actor);
460
+
461
+ // apply shift + scale to primitives AFTER vtkOpenGLPolyDataMapper.buildBufferObjects
462
+ // so that the Glyph3DMapper gets the last say in the shift + scale
463
+ if (useShiftAndScale) {
464
+ for (let i = primTypes.Start; i < primTypes.End; i++) {
465
+ model.primitives[i].getCABO().setCoordShiftAndScale(coordShift, coordScale);
466
+ }
467
+ }
434
468
  };
435
469
  }
436
470
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.8.0",
3
+ "version": "34.8.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",
@@ -30,7 +30,7 @@
30
30
  "main": "./index.js",
31
31
  "module": "./index.js",
32
32
  "dependencies": {
33
- "@babel/runtime": "7.22.11",
33
+ "@babel/runtime": "^7.28.2",
34
34
  "@types/webxr": "^0.5.5",
35
35
  "commander": "9.2.0",
36
36
  "d3-scale": "4.0.2",
@@ -67,7 +67,7 @@
67
67
  "babel-loader": "8.2.5",
68
68
  "babel-plugin-istanbul": "6.1.1",
69
69
  "buffer": "6.0.3",
70
- "commitizen": "4.2.5",
70
+ "commitizen": "^4.3.1",
71
71
  "concurrently": "7.1.0",
72
72
  "copy-webpack-plugin": "10.2.4",
73
73
  "cross-env": "7.0.3",
@@ -125,7 +125,7 @@
125
125
  "webpack-bundle-analyzer": "4.5.0",
126
126
  "webpack-cli": "4.9.2",
127
127
  "webpack-dashboard": "3.3.7",
128
- "webpack-dev-server": "4.9.0",
128
+ "webpack-dev-server": "^5.2.2",
129
129
  "webpack-merge": "5.8.0",
130
130
  "webpack-notifier": "1.15.0",
131
131
  "wslink": "1.12.4",