Question

I am using Mayavi for a 3D visualization with TraitsUI. The scene is a trait of the type MlabSceneModel. I want to change the lighting and trying to access scene.light_manager in a function called on the activated event. However, scene.light_manager is always None.

Using mlab.figure() to creates a scene which has a light manager, but as I want the scene to be integrated in the UI and not in an additional window this is no option for me.

Was it helpful?

Solution

Good question which threw me for a loop at first.

Looking at the tvtk source, the light manager is added to the scene when the interactor is generated, which occurs after scene activation. Furthermore, the first thing I tried, which was to listen to 'scene:light_manager' doesn't work because the light manager is a Property trait that doesn't directly change. That said, if you listen to the object itself, which is referred to by the property, it will trigger a notification on creation. In other words, do this:

class Application(HasTraits):
  scene=Instance(MlabSceneModel,())

  ...

  @on_trait_change('scene:scene_editor:light_manager')
  def muck_with_the_lights(self):
    print self.scene.light_manager
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top