@kitware/vtk.js 32.0.0 → 32.0.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.
@@ -595,11 +595,11 @@ function vtkMapper(publicAPI, model) {
595
595
  let inValue = 0;
596
596
  inValue += rawHighData[pos];
597
597
  inValue *= 256;
598
- inValue += rawLowData[pos];
598
+ inValue += rawLowData[pos + 2];
599
599
  inValue *= 256;
600
600
  inValue += rawLowData[pos + 1];
601
601
  inValue *= 256;
602
- inValue += rawLowData[pos + 2];
602
+ inValue += rawLowData[pos];
603
603
  const outValue = idMap[inValue];
604
604
  const highData = selector.getPixelBuffer(PassTypes.ID_HIGH24);
605
605
  highData[pos] = (outValue & 0xff000000) >> 24;
@@ -331,6 +331,23 @@ export function extend(
331
331
  initialValues?: IOpenGLHardwareSelectorInitialValues
332
332
  ): void;
333
333
 
334
+ /**
335
+ * The WebGL implementation of the hardware selector renders the id of the VBO
336
+ * vertices (gl_VertexID) with an offset to a RGBA texture.
337
+ * Only the RGB channels of the RGBA texture are used. This means that a single
338
+ * render can only draw 24 bits of information. To reach 32 bits, the hardware
339
+ * selector renders a second pass which only writes in the R channel of the
340
+ * texture.
341
+ *
342
+ * Note:
343
+ * - With Webgl 2, it is now possible to render directly to a R32 texture and
344
+ * even render to multiple render targets.
345
+ * - The raw pixel buffers fetched from WebGL are processed in the core mapper
346
+ * (see `processSelectorPixelBuffers`) instead of the PolydataMapper.
347
+ * - The processing of the raw pixel buffers does not output an UInt32Array as
348
+ * we could expect, but one or two textures with the same layout as the RGBA
349
+ * textures as input.
350
+ */
334
351
  export const vtkOpenGLHardwareSelector: {
335
352
  newInstance: typeof newInstance;
336
353
  extend: typeof extend;
@@ -358,6 +358,7 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
358
358
  model._renderer.setBackground(0.0, 0.0, 0.0, 0.0);
359
359
  const rpasses = model._openGLRenderWindow.getRenderPasses();
360
360
  publicAPI.beginSelection();
361
+ const pixelBufferSavedPasses = [];
361
362
  for (model.currentPass = PassTypes.MIN_KNOWN_PASS; model.currentPass <= PassTypes.MAX_KNOWN_PASS; model.currentPass++) {
362
363
  if (publicAPI.passRequired(model.currentPass)) {
363
364
  publicAPI.preCapturePass(model.currentPass);
@@ -369,9 +370,16 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
369
370
  }
370
371
  publicAPI.postCapturePass(model.currentPass);
371
372
  publicAPI.savePixelBuffer(model.currentPass);
372
- publicAPI.processPixelBuffers();
373
+ pixelBufferSavedPasses.push(model.currentPass);
373
374
  }
374
375
  }
376
+
377
+ // Process pixel buffers
378
+ pixelBufferSavedPasses.forEach(pass => {
379
+ model.currentPass = pass;
380
+ publicAPI.processPixelBuffers();
381
+ });
382
+ model.currentPass = PassTypes.MAX_KNOWN_PASS;
375
383
  publicAPI.endSelection();
376
384
 
377
385
  // restore original background
@@ -631,9 +639,9 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
631
639
 
632
640
  //----------------------------------------------------------------------------
633
641
 
634
- publicAPI.attach = (w, r) => {
635
- model._openGLRenderWindow = w;
636
- model._renderer = r;
642
+ publicAPI.attach = (openGLRenderWindow, renderer) => {
643
+ model._openGLRenderWindow = openGLRenderWindow;
644
+ model._renderer = renderer;
637
645
  };
638
646
 
639
647
  // override
@@ -438,7 +438,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
438
438
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = vec4(float(idx%256)/255.0, float((idx/256)%256)/255.0, float((idx/65536)%256)/255.0, 1.0);').result;
439
439
  break;
440
440
  case PassTypes.ID_HIGH24:
441
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = vec4(float(idx)/255.0, 0.0, 0.0, 1.0);').result;
441
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = vec4(float((idx/16777216)%256)/255.0, 0.0, 0.0, 1.0);').result;
442
442
  break;
443
443
  default:
444
444
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Dec', 'uniform vec3 mapperIndex;').result;
@@ -953,6 +953,8 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
953
953
  if (publicAPI.getNeedToRebuildBufferObjects(ren, actor)) {
954
954
  publicAPI.buildBufferObjects(ren, actor);
955
955
  }
956
+ // Always call this function as the selector can change
957
+ publicAPI.updateMaximumPointCellIds();
956
958
  };
957
959
  publicAPI.getNeedToRebuildBufferObjects = (ren, actor) => {
958
960
  // first do a coarse check
@@ -1092,7 +1094,6 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
1092
1094
  }
1093
1095
  if (model.renderable.getPopulateSelectionSettings()) {
1094
1096
  model.renderable.setSelectionWebGLIdsToVTKIds(model.selectionWebGLIdsToVTKIds);
1095
- publicAPI.updateMaximumPointCellIds();
1096
1097
  }
1097
1098
  model.VBOBuildString = toString;
1098
1099
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "32.0.0",
3
+ "version": "32.0.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",