I’ve been experimenting with visualizations in python and VTKjs but can’t reproduce some of the features I achieve in python in VTK js.
In python I’m able to get the following super-smooth shading, with the following settings:
# Set the interpolation to Gouraud shading
actor.GetProperty().SetInterpolationToGouraud()
# Set material properties
actor.GetProperty().SetDiffuse(0.9)
actor.GetProperty().SetSpecular(0.05)
actor.GetProperty().SetSpecularPower(5)
actor.GetProperty().SetAmbient(0.2)
actor.GetProperty().SetShading(1)
Are you referring to the second or third photo? In the second photo, it looks like you’re displaying the geometry as a wireframe rather than a surface (actor.getProperty().setRepresentation(Representation.SURFACE)).
As for setShading(true), it appears that we have ts definitions for that method but no actual setters/getters for that property. Looks like vtk.js doesn’t support toggling shading, as it should be on by default.
I’m referring to the third photo, which is the result of the Javascript version while the first two images are Python.
(actor.getProperty().setRepresentation(Representation.SURFACE)). this is set correctly, as it is the default value.
Unfortunatly setShading(true) is indeed in the ts definitions but not in the actual source. I changed this and tried again but even then did it not work as intended.
It is indeed a high resolution model, but I want it to look smooth which is what smooth shading does?
Below you can see the same model from vtk-js in vtk-python, in normal “smooth” shading and wireframe mode to give an understanding to the resolution of the model.
As you can see in the smooth shading, the interpolation ensures that no individual triangles are visible.
Below is an image without shading turned on in python, and you can see the individual triangles in the mesh (flat shading)
That might be because your points are duplicated per cells. hence the polydata normals do not work.
What reader do you use ? OBJReader has the tendancy of duplicating points. You can look at the OBJReader tests in VTK.js to understand the issue with point duplication.
Thanks for this insight, we use multiple readers for multiple file-formats (stl, ply, obj, drc, …)
Is there an easy post-processing step I can take to ensure this duplication is taken care of?
Try to load the file with a vtk (vtp) file format to see if you still have the problem.
If you do, then the problem comes from the OBJ reader. You need to “track duplicates” and merge the points in some way…
Thanks for all the help. There was indeed an issue with duplicated points per cell. We have fixed this by post-processing the incoming meshes.
The shading works perfect now.