vtk lights in Mayavi

204 views
Skip to first unread message

Williams, Darren

unread,
Jul 27, 2021, 10:15:21 AM7/27/21
to Enthought Tool Suite users
Hi Everyone. 

I have learned that vtk has both headlights located at
infinity and source lights located at some position. 
mylight = vtk.vtkLight()

It is apparent that Mayavi includes the "headlight"
option. But I'd like to also insert a "source" light
emanating from an x,y,z position in the scene.

This should in principle be possible by adding a vtk light 
and converting it to an "actor" for insertion.

I'm looking for help with the procedure for doing this. 

Thanks (Anyone).

Darren Williams

Prabhu Ramachandran

unread,
Oct 16, 2021, 8:21:04 AM10/16/21
to Williams, Darren, Enthought Tool Suite users
Just to keep the answer public,  here are a few possibly useful pointers.

1. You can access the lights used in a scene like so::

from mayavi import mlab
s = mlab.test_plot3d()
print(s.scene.light_manager.lights)

You can then set the properties of the lights as you see fit.  You can also add/remove new lights:

from tvtk.pyface.light_manager import CameraLight
c = CameraLight(s.scene)
s.scene.light_manager.lights.append(c)

By default the lights are at infinity (they are not positional lights) and this can be changed like so::

from mayavi import mlab
g = mlab.test_plot3d()
g.scene.light_manager.lights[0].source.positional = True

Hope this helps.  The VTK Lights documentation is worth reading:


cheers,
Prabhu

--
You received this message because you are subscribed to the Google Groups "Enthought Tool Suite users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ets-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ets-users/CH2PR02MB70132DDE5B1E38CCD734350698E99%40CH2PR02MB7013.namprd02.prod.outlook.com.

Williams, Darren

unread,
Oct 16, 2021, 8:20:30 PM10/16/21
to Prabhu Ramachandran, Enthought Tool Suite users
Ok, thanks, but the following commands:

myscene = Instance(MlabSceneModel, ())
camera_light0 = self.myscene.scene_editor.light_manager.lights[0]
camera_light0.color = (1,0,0)
camera_light0.source.positional = True
camera_light0.position=(10,0,10)
   
yields a red light shining on a spherical surface, but the position/direction of the 
light is always the same, no matter what I change the coordinates in last statement to. 

What am I doing wrong?



From: ets-...@googlegroups.com <ets-...@googlegroups.com> on behalf of Prabhu Ramachandran <pra...@enthought.com>
Sent: Saturday, October 16, 2021 8:20 AM
To: Williams, Darren <dmw...@psu.edu>
Cc: Enthought Tool Suite users <ets-...@googlegroups.com>
Subject: Re: [ets-users] vtk lights in Mayavi
 

Prabhu Ramachandran

unread,
Oct 17, 2021, 10:42:23 PM10/17/21
to Williams, Darren, Enthought Tool Suite users
Hi Darren,

Here is an example, without a reproducible example I cannot quite tell.  By default mayavi uses the "raymond" mode which has 4 active lights.  The vtk mode is simpler.  

from mayavi import mlab
g = mlab.test_plot3d()
g.scene.light_manager.light_mode = 'vtk'
l0 = g.scene.light_manager.lights[0]
l0.source.positional = True
l0.source.position = 1, 0, 1
g.scene.render()

Did you see the documentation link I shared, there are many methods that you can try like setting the cone angle, focal point, attenuation, and also switch the light between a camera light and a scene light.

cheers,
Prabhu

Reply all
Reply to author
Forward
0 new messages