Panda3D Light Test

Python : 2007. 4. 5. 16:26
반응형

import direct.directbase.DirectStart
from pandac.PandaModules import *

# Put two pandas in the scene, panda x and panda y.
x= loader.loadModel("panda")
x.reparentTo(render)
x.setPos(10,0,-6)

y= loader.loadModel("panda")
y.reparentTo(render)
y.setPos(-15,0,-6)

# Position the camera to view the two pandas.
base.trackball.node().setPos(0, 100, 10)

# Now create some lights to apply to everything in the scene.

# Create Ambient Light
ambientLight = AmbientLight( 'ambientLight' )
ambientLight.setColor( Vec4( .3, .3, 0.3, 1 ) )
ambientLightNP = render.attachNewNode( ambientLight.upcastToPandaNode() )
render.setLight(ambientLightNP)

# Directional light 01
directionalLight = DirectionalLight( "directionalLight" )
directionalLight.setColor( Vec4( 1.1, 0.1, 0.1, 1 ) )
directionalLightNP = render.attachNewNode( directionalLight.upcastToPandaNode() )
# This light is facing backwards, towards the camera.
directionalLightNP.setHpr(180, -50, 0)
render.setLight(directionalLightNP)

# Directional light 02
directionalLight = DirectionalLight( "directionalLight" )
directionalLight.setColor( Vec4( 0.0, 1.0, 0.0, 1 ) )
directionalLightNP = render.attachNewNode( directionalLight.upcastToPandaNode() )
# This light is facing forwards, away from the camera.
directionalLightNP.setHpr(0, -20, 0)
render.setLight(directionalLightNP)

# Now attach a green light only to object x.
ambient = AmbientLight('ambient')
ambient.setColor(Vec4(0.0,0.0,1.0,1))
ambientNP = x.attachNewNode(ambient.upcastToPandaNode())

# Directional light 03
directionalLight = DirectionalLight( "directionalLight" )
directionalLight.setColor( Vec4( 0.0, 0.6, 0.6, 1 ) )
directionalLightNP = x.attachNewNode( directionalLight.upcastToPandaNode() )
# This light is facing forwards, away from the camera.
directionalLightNP.setHpr(30, 0, -6)
x.setLight(directionalLightNP)


# Directional light 04
directionalLight = DirectionalLight( "directionalLight" )
directionalLight.setColor( Vec4( 1.0, 0.0, 0.0, 1 ) )
directionalLightNP = x.attachNewNode( directionalLight.upcastToPandaNode() )
# This light is facing forwards, away from the camera.
directionalLightNP.setHpr(0, 20, 7)
x.setLight(directionalLightNP)

# Directional light 05 backunder
directionalLight = DirectionalLight( "directionalLight" )
directionalLight.setColor( Vec4( 0.0, 0.0, 1.0, 1 ) )
directionalLightNP = x.attachNewNode( directionalLight.upcastToPandaNode() )
# This light is facing forwards, away from the camera.
directionalLightNP.setHpr(180, -50, 0)
x.setLight(directionalLightNP)

# If we did not call setLightOff() first, the green light would add to
# the total set of lights on this object.  Since we do call
# setLightOff(), we are turning off all the other lights on this
# object first, and then turning on only the green light.
#x.setLightOff()
x.setLight(ambientNP)

#run the example
run()

반응형
Posted by Real_G