How to color a model in vtk.js

1k Views Asked by At

I am using following code to show a sphere model using vtk.js. This works quite well. However, I want to color the model in red. How can I do this?

// Standard rendering code setup
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();
const resetCamera = renderer.resetCamera;
const render = renderWindow.render;

// read data
const reader = vtkPolyDataReader.newInstance();
reader.setUrl("cube.vtk").then(() => {
  const polydata = reader.getOutputData(0);
  const mapper = vtkMapper.newInstance();
  const actor = vtkActor.newInstance();

  actor.setMapper(mapper);
  mapper.setInputData(polydata);

  // need to color the model

  renderer.addActor(actor);

  resetCamera();
  render();
});

cube.vtk has following data

# vtk DataFile Version 2.0
Cube example
ASCII
DATASET POLYDATA
POINTS 8 float
0.0 0.0 0.0
1.0 0.0 0.0
1.0 1.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
1.0 0.0 1.0
1.0 1.0 1.0
0.0 1.0 1.0
POLYGONS 6 30
4 0 1 2 3
4 4 5 6 7
4 0 1 5 4
4 2 3 7 6
4 0 4 7 3
4 1 2 6 5

How can I make the cube in red color?

1

There are 1 best solutions below

0
On

All you need is:

actor.getProperty().setColor(1.0, 0.0, 0.0)