vtk.js mapper for polydata

Hello!

I am trying to map colors based on scalars of a polydata using vtk.js - but I can’t get it to work.

        polydata = reader.getOutputData();
            
        arrayName = polydata.getPointData().getArrayName(0);
        activeArray = polydata.getPointData().getArrays()[0];
        dataRange = activeArray.getRange()

        lookupTable = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
        lookupTable.setVectorModeToMagnitude();
        lookupTable.applyColorMap(preset);
        lookupTable.setMappingRange(dataRange[0],dataRange[1]);
        lookupTable.updateRange();

        mapper = vtk.Rendering.Core.vtkMapper.newInstance({});
        mapper.setInputData(polydata);
        mapper.setLookupTable(lookupTable);
        mapper.setColorByArrayName(arrayName);
        mapper.setColorModeToMapScalars();
        mapper.setInterpolateScalarsBeforeMapping();
        mapper.setScalarModeToUsePointData();
        mapper.setScalarVisibility(true);
        mapper.setScalarRange(dataRange[0],dataRange[1]);

        actor.setMapper(mapper);
    
        renderer.addActor(actor);
        renderer.resetCamera();
        renderWindow.render();

The polydata loads but no colors are assigned. What do I need to add?

Thank you so much!

It works now with

mapper.setScalarModeToUsePointFieldData();

:slight_smile:

Glad to hear that you figured it out.