1

I am trying to add ambient light to vispy mesh. Here is the code that I am using to render a triangulated mesh.

meshdata = vispy.geometry.MeshData(vertices=r.vertices, faces=r.faces, vertex_colors=r.vColor)
canvas = scene.SceneCanvas(keys='interactive', size=(800, 600), show=True)
mesh = scene.visuals.Mesh(meshdata=meshdata, shading='smooth')
view = canvas.central_widget.add_view()
view.add(mesh)
view.bgcolor = '#efefef'    
view.camera = TurntableCamera(azimuth=azimuth, elevation=elevation)
color = Color("#3f51b5")
axis = scene.visuals.XYZAxis(parent=view.scene)
if __name__ == '__main__' and sys.flags.interactive == 0:
    canvas.app.run()

Somehow the mesh appears very dark and I want to add ambient lights to this. How can I do this? I searched online and it seems to be not easy. I want to start using python 3 and so trying to use vispy instead of mayavi. Any help would be greatly appreciated.

AnandJ
  • 346
  • 4
  • 15

1 Answers1

0

For a white ambient light:

mesh.ambient_light_color = vispy.color.Color('white')

For a custom color (orange, half transparent):

mesh.ambient_light_color = vispy.color.Color(color=(1.0, 0.5, 0.0), alpha=0.5)

See: http://vispy.org/visuals.html#vispy.visuals.MeshVisual.ambient_light_color

ice
  • 77
  • 3