On my Pythgon38 Windows10 platform, I am rejigging my solarsystem simulator from OpenGL to VTK. To illuminate the scene from the origin, I have placed a pair of 180deg coned spotlights back to back. With the help of comments in lorensen.github.io/VTKExamples/site/Cxx/Lighting/Light/
the lighting seems correct, but the Sun sphere (also at the origin) has become a black hole, and re-rendering it has no effect. Can anyone enlighten me? Here is the code stripped of animation and other stuff to exhibit my problem
:#!/usr/bin/env python
from random import randint
from math import sqrt, pi, sin, cos
import vtk
colors = vtk.vtkNamedColors() # print(colors)
k = pi / 180 # degrees to radians
ScaleAU = 100 # so 1 AU 100pixels from center, 6 aus is ±600 pixels
ScaleRad = 15 # so 1 earth rad is 15 pixels
class Object:
def init(self, radius, orbit, color,theta = 0):
self.radius = radius * ScaleRad
sphere = vtk.vtkSphereSource() # Create a sphere (from Sphere.py)
sphere.SetRadius(self.radius)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(sphere.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper) # actor is sphere
actor.GetProperty().SetColor(colors.GetColor3d(color))
self.orbit = orbit * ScaleAU
actor.SetPosition(self.orbit * cos(theta), 0, self.orbit * sin(theta))
self.actor = actor
def main():
ren = vtk.vtkRenderer()
ren.SetBackground(colors.GetColor3d(“black”))
renWin = vtk.vtkRenderWindow()
renWin.SetWindowName(‘My Solar Sim’) # doesnt happen
renWin.AddRenderer(ren)
renWin.SetSize(1200, 750)
intren = vtk.vtkRenderWindowInteractor()
intren.SetRenderWindow(renWin)
Planet = []
Planet.append(Object(2.5,0.,"yellow")) # the Sun
Planet.append(Object(.7,.7,"silver", 0)) # Venus
Planet.append(Object(1.,1.,"blue", 180)) # Earth
camera = vtk.vtkCamera()
camera.SetPosition(0.0, 0.0, 500.) # stand well back!
camera.SetFocalPoint(0.0, 0.0, 30.)
camera.SetClippingRange(10., 600.)
camera.SetViewUp(0, 1, 0)
ren.SetActiveCamera(camera)
for planet in Planet[0:]:
ren.AddActor(planet.actor)
Lspot = vtk.vtkLight() # from lorensen.github.io/VTKExamples/site/Cxx/Lighting/Light/
Lspot.SetColor(1.,1.,1.)
Lspot.SetPosition(0., 0., 0.)
Lspot.SetPositional(True)
Lspot.SetFocalPoint(-10., 0., 0.)
Lspot.SetConeAngle(180.)
Lspot.SetLightTypeToSceneLight() # what might this do?
Rspot = vtk.vtkLight()
Rspot.SetColor(1.,1.,1.)
Rspot.SetPosition(0., 0., 0.)
Rspot.SetPositional(True)
Rspot.SetFocalPoint( 10., 0., 0.)
Rspot.SetConeAngle(180.)
Rspot.SetLightTypeToSceneLight()
ren.AddLight(Lspot) # as in lorensen.github.io/VTKExamples/site/Cxx/Lighting/Light/
ren.AddLight(Rspot) # 2 spots but band dividing sun light an dark hemispheres
# lighting is correct but sun is dark so add it again here
ren.AddActor(Planet[0].actor) # - still dark
renWin.Render() # Reset the camera to view all actors added to scene
intren.Initialize() # Render the image of positioned actors onto the scene
renWin.Render()
intren.Start() # start the event loop
if name == ‘main’:
main()