diff --git a/Sources/Rendering/Core/Picker/index.js b/Sources/Rendering/Core/Picker/index.js index 02592682b61..e1733b5e3b6 100644 --- a/Sources/Rendering/Core/Picker/index.js +++ b/Sources/Rendering/Core/Picker/index.js @@ -116,12 +116,14 @@ function vtkPicker(publicAPI, model) { // Note that only vtkProp3D's can be picked by vtkPicker. props.forEach((prop) => { const mapper = prop.getMapper(); - const propIsNotFullyTranslucent = - prop.getProperty?.()?.getOpacity() > 0.0; + + const propIsFullyTranslucent = + prop.getProperty?.().getOpacity?.() === 0.0; + const pickable = prop.getNestedPickable() && prop.getNestedVisibility() && - propIsNotFullyTranslucent; + !propIsFullyTranslucent; if (!pickable) { // prop cannot be picked diff --git a/Sources/Rendering/Core/Picker/test/testPicker.js b/Sources/Rendering/Core/Picker/test/testPicker.js index d58ab30ce10..df34e08532b 100644 --- a/Sources/Rendering/Core/Picker/test/testPicker.js +++ b/Sources/Rendering/Core/Picker/test/testPicker.js @@ -1,13 +1,17 @@ import test from 'tape'; import testUtils from 'vtk.js/Sources/Testing/testUtils'; -import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs'; -import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow'; -import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer'; -import vtkPicker from 'vtk.js/Sources/Rendering/Core/Picker'; -import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource'; +import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper'; +import vtkPicker from 'vtk.js/Sources/Rendering/Core/Picker'; +import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow'; +import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer'; +import vtkRTAnalyticSource from 'vtk.js/Sources/Filters/Sources/RTAnalyticSource'; +import vtkVolume from 'vtk.js/Sources/Rendering/Core/Volume'; +import vtkVolumeMapper from 'vtk.js/Sources/Rendering/Core/VolumeMapper'; +import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs'; +import 'vtk.js/Sources/Rendering/Profiles/Volume'; function setupRenderingComponents(gc) { const container = document.querySelector('body'); @@ -138,6 +142,36 @@ test.onlyIfWebGL('vtkPicker.pick3DPoint - multiple actors', (t) => { gc.releaseResources(); }); +test.onlyIfWebGL('vtkPicker.pick - volume', (t) => { + const gc = testUtils.createGarbageCollector(t); + const renderer = setupRenderingComponents(gc); + + const source = vtkRTAnalyticSource.newInstance(); + const size = 50; + source.setWholeExtent([0, size, 0, size, 0, size]); + source.update(); + + const volumeMapper = vtkVolumeMapper.newInstance(); + volumeMapper.setInputConnection(source.getOutputPort()); + const volume = vtkVolume.newInstance(); + volume.setMapper(volumeMapper); + renderer.addVolume(volume); + + const picker = vtkPicker.newInstance(); + + picker.setPickFromList(1); + picker.initializePickList(); + picker.addPickList(volume); + + picker.pick([200, 200, 1.0], renderer); + + const pickedActors = picker.getActors(); + t.equal(pickedActors.length, 1); + t.ok(pickedActors[0] === volume); + + gc.releaseResources(); +}); + test('Test vtkPicker instance', (t) => { t.ok(vtkPicker, 'Make sure the class definition exists'); const instance = vtkPicker.newInstance();