Hello,
I need some help with setting up a custom scene with PSSM. I just found this better roaming ralph script which has a perfect camera look for my demo. Now I’m trying to add PSSM shadows with another example I found here.
Somehow I get some clipping and not get the correct effect.
Here’s the Better Roaming Ralph code:
### Original Header
#iModels: Jeff Styers, Reagan Heller
# Last Updated: 6/13/2005
#
# This tutorial provides an example of creating a character
# and having it walk around on uneven terrain, as well
# as implementing a fully rotatable camera.
### Better Ralph: modifications by Stephen Lujan
# This is a modification of the roaming ralph demo to provide improved controls
# and camera angles, imitating those of modern commercial games
import direct.directbase.DirectStart
from panda3d.core import WindowProperties
from panda3d.core import CollisionTraverser,CollisionNode
from panda3d.core import CollisionHandlerQueue,CollisionRay
from panda3d.core import CollisionTube,CollisionSegment
from panda3d.core import Filename,AmbientLight,DirectionalLight
from panda3d.core import PandaNode,NodePath,Camera,TextNode
from panda3d.core import Point3,Vec3,Vec4,BitMask32
from panda3d.core import LightRampAttrib
from direct.gui.OnscreenText import OnscreenText
from direct.actor.Actor import Actor
from direct.showbase.DirectObject import DirectObject
import random, sys, os, math
SPEED = 0.5
# Function to put instructions on the screen.
def addInstructions(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)
# Function to put title on the screen.
def addTitle(text):
return OnscreenText(text=text, style=1, fg=(1,1,1,1),
pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
class World(DirectObject):
def __init__(self):
self.controlMap = {"left":0, "right":0, "forward":0, "backward":0,
"zoom-in":0, "zoom-out":0, "wheel-in":0, "wheel-out":0}
self.mousebtn = [0,0,0]
base.win.setClearColor(Vec4(0,0,0,1))
# Post the instructions
self.title = addTitle("Panda3D Tutorial: Better Ralph (Walking on Uneven Terrain)")
self.inst1 = addInstructions(0.95, "[ESC]: Quit")
self.inst2 = addInstructions(0.90, "W A S D keys move Ralph forward, left, back, and right, respectively.")
self.inst3 = addInstructions(0.85, "Use the mouse to look around and steer Ralph.")
self.inst4 = addInstructions(0.80, "Zoom in and out using the mouse wheel, or page up and page down keys.")
# Set up the environment
#
# This environment model contains collision meshes. If you look
# in the egg file, you will see the following:
#
# <Collide> { Polyset keep descend }
#
# This tag causes the following mesh to be converted to a collision
# mesh -- a mesh which is optimized for collision, not rendering.
# It also keeps the original mesh, so there are now two copies ---
# one optimized for rendering, one for collisions.
self.environ = loader.loadModel("models/world")
self.environ.reparentTo(render)
self.environ.setPos(0,0,0)
# Create the main character, Ralph
ralphStartPos = self.environ.find("**/start_point").getPos()
self.ralph = Actor("models/ralph",
{"run":"models/ralph-run",
"walk":"models/ralph-walk"})
self.ralph.reparentTo(render)
self.ralph.setScale(.2)
self.ralph.setPos(ralphStartPos)
# Accept the control keys for movement and rotation
self.accept("escape", sys.exit)
self.accept("w", self.setControl, ["forward",1])
self.accept("a", self.setControl, ["left",1])
self.accept("s", self.setControl, ["backward",1])
self.accept("d", self.setControl, ["right",1])
self.accept("w-up", self.setControl, ["forward",0])
self.accept("a-up", self.setControl, ["left",0])
self.accept("s-up", self.setControl, ["backward",0])
self.accept("d-up", self.setControl, ["right",0])
# self.accept("mouse1", self.setControl, ["zoom-in", 1])
# self.accept("mouse1-up", self.setControl, ["zoom-in", 0])
# self.accept("mouse3", self.setControl, ["zoom-out", 1])
# self.accept("mouse3-up", self.setControl, ["zoom-out", 0])
self.accept("wheel_up", self.setControl, ["wheel-in", 1])
self.accept("wheel_down", self.setControl, ["wheel-out", 1])
self.accept("page_up", self.setControl, ["zoom-in", 1])
self.accept("page_up-up", self.setControl, ["zoom-in", 0])
self.accept("page_down", self.setControl, ["zoom-out", 1])
self.accept("page_down-up", self.setControl, ["zoom-out", 0])
taskMgr.add(self.move,"moveTask")
# Game state variables
self.isMoving = False
# Set up the camera
# Adding the camera to Ralph is a simple way to keep the camera locked
# in behind Ralph regardless of ralph's movement.
base.camera.reparentTo(self.ralph)
# We don't actually want to point the camera at Ralph's feet.
# This value will serve as a vertical offset so we can look over Ralph
self.cameraTargetHeight = 6.0
# How far should the camera be from Ralph
self.cameraDistance = 30
# Initialize the pitch of the camera
self.cameraPitch = 10
# This just disables the built in camera controls; we're using our own.
base.disableMouse()
# The mouse moves rotates the camera so lets get rid of the cursor
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
# We will detect the height of the terrain by creating a collision
# ray and casting it downward toward the terrain. One ray will
# start above ralph's head.
# A ray may hit the terrain, or it may hit a rock or a tree. If it
# hits the terrain, we can detect the height. If it hits anything
# else, we rule that the move is illegal.
self.cTrav = CollisionTraverser()
self.ralphGroundRay = CollisionRay()
self.ralphGroundRay.setOrigin(0,0,1000)
self.ralphGroundRay.setDirection(0,0,-1)
self.ralphGroundCol = CollisionNode('ralphRay')
self.ralphGroundCol.addSolid(self.ralphGroundRay)
self.ralphGroundCol.setFromCollideMask(BitMask32.bit(0))
self.ralphGroundCol.setIntoCollideMask(BitMask32.allOff())
self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol)
self.ralphGroundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
# We will detect anything obstructing the camera's view of the player
self.cameraRay = CollisionSegment((0,0,self.cameraTargetHeight),(0,5,5))
self.cameraCol = CollisionNode('cameraRay')
self.cameraCol.addSolid(self.cameraRay)
self.cameraCol.setFromCollideMask(BitMask32.bit(0))
self.cameraCol.setIntoCollideMask(BitMask32.allOff())
self.cameraColNp = self.ralph.attachNewNode(self.cameraCol)
self.cameraColHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.cameraColNp, self.cameraColHandler)
############## CollisionTube doesn't seem to be working
# self.cameraRay = CollisionTube( (0,0,self.cameraTargetHeight),
# (0,25,25),
# (self.cameraTargetHeight/2))
# self.cameraCol = CollisionNode('cameraRay')
# self.cameraCol.addSolid(self.cameraRay)
# self.cameraCol.setFromCollideMask(BitMask32.bit(0))
# self.cameraCol.setIntoCollideMask(BitMask32.allOff())
# self.cameraColNp = self.ralph.attachNewNode(self.cameraCol)
# self.cameraColHandler = CollisionHandlerQueue()
# self.cTrav.addCollider(self.cameraColNp, self.cameraColHandler)
############
# Uncomment this line to see the collision rays
#self.ralphGroundColNp.show()
#self.camGroundColNp.show()
#self.cameraColNp.show()
# Uncomment this line to show a visual representation of the
# collisions occuring
#self.cTrav.showCollisions(render)
# Create some lighting
# lets add hdr lighting for fun
render.setShaderAuto()
render.setAttrib(LightRampAttrib.makeHdr1())
ambientLight = AmbientLight("ambientLight")
# existing lighting is effectively darkened so boost ambient a bit
ambientLight.setColor(Vec4(.4, .4, .4, 1))
directionalLight = DirectionalLight("directionalLight")
directionalLight.setDirection(Vec3(-5, -5, -5))
# hdr can handle any amount of lighting
# lets make things nice and sunny
directionalLight.setColor(Vec4(2.0, 2.0, 2.0, 1.0))
directionalLight.setSpecularColor(Vec4(2.0, 2.0, 2.0, 1))
render.setLight(render.attachNewNode(ambientLight))
render.setLight(render.attachNewNode(directionalLight))
#Records the state of the arrow keys
def setControl(self, key, value):
self.controlMap[key] = value
# Accepts arrow keys to move either the player or the menu cursor,
# Also deals with grid checking and collision detection
def move(self, task):
# save ralph's initial position so that we can restore it,
# in case he falls off the map or runs into something.
startpos = self.ralph.getPos()
# If a move-key is pressed, move ralph in the specified direction.
if (self.controlMap["forward"]!=0):
self.ralph.setY(self.ralph, -25 * globalClock.getDt())
if (self.controlMap["backward"]!=0):
self.ralph.setY(self.ralph, 25 * globalClock.getDt())
if (self.controlMap["left"]!=0):
self.ralph.setX(self.ralph, 25 * globalClock.getDt())
if (self.controlMap["right"]!=0):
self.ralph.setX(self.ralph, -25 * globalClock.getDt())
# If a zoom button is pressed, zoom in or out
if (self.controlMap["wheel-in"]!=0):
self.cameraDistance -= 0.1 * self.cameraDistance;
if (self.cameraDistance < 5):
self.cameraDistance = 5
self.controlMap["wheel-in"] = 0
elif (self.controlMap["wheel-out"]!=0):
self.cameraDistance += 0.1 * self.cameraDistance;
if (self.cameraDistance > 250):
self.cameraDistance = 250
self.controlMap["wheel-out"] = 0
if (self.controlMap["zoom-in"]!=0):
self.cameraDistance -= globalClock.getDt() * self.cameraDistance;
if (self.cameraDistance < 5):
self.cameraDistance = 5
elif (self.controlMap["zoom-out"]!=0):
self.cameraDistance += globalClock.getDt() * self.cameraDistance;
if (self.cameraDistance > 250):
self.cameraDistance = 250
# Use mouse input to turn both Ralph and the Camera
if base.mouseWatcherNode.hasMouse():
# get changes in mouse position
md = base.win.getPointer(0)
x = md.getX()
y = md.getY()
deltaX = md.getX() - 200
deltaY = md.getY() - 200
# reset mouse cursor position
base.win.movePointer(0, 200, 200)
# alter ralph's yaw by an amount proportionate to deltaX
self.ralph.setH(self.ralph.getH() - 0.3* deltaX)
# find the new camera pitch and clamp it to a reasonable range
self.cameraPitch = self.cameraPitch + 0.1 * deltaY
if (self.cameraPitch < -60): self.cameraPitch = -60
if (self.cameraPitch > 80): self.cameraPitch = 80
base.camera.setHpr(0,self.cameraPitch,0)
# set the camera at around ralph's middle
# We should pivot around here instead of the view target which is noticebly higher
base.camera.setPos(0,0,self.cameraTargetHeight/2)
# back the camera out to its proper distance
base.camera.setY(base.camera,self.cameraDistance)
# point the camera at the view target
viewTarget = Point3(0,0,self.cameraTargetHeight)
base.camera.lookAt(viewTarget)
# reposition the end of the camera's obstruction ray trace
self.cameraRay.setPointB(base.camera.getPos())
# If ralph is moving, loop the run animation.
# If he is standing still, stop the animation.
if (self.controlMap["forward"]!=0) or (self.controlMap["left"]!=0) or (self.controlMap["right"]!=0) or (self.controlMap["backward"]!=0):
if self.isMoving is False:
self.ralph.loop("run")
self.isMoving = True
else:
if self.isMoving:
self.ralph.stop()
self.ralph.pose("walk",5)
self.isMoving = False
# Now check for collisions.
self.cTrav.traverse(render)
# Adjust ralph's Z coordinate. If ralph's ray hit terrain,
# update his Z. If it hit anything else, or didn't hit anything, put
# him back where he was last frame.
entries = []
for i in range(self.ralphGroundHandler.getNumEntries()):
entry = self.ralphGroundHandler.getEntry(i)
entries.append(entry)
entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
x.getSurfacePoint(render).getZ()))
if (len(entries)>0) and (entries[0].getIntoNode().getName() == "terrain"):
self.ralph.setZ(entries[0].getSurfacePoint(render).getZ())
else:
self.ralph.setPos(startpos)
# We will detect anything obstructing the camera via a ray trace
# from the view target around the avatar's head, to the desired camera
# podition. If the ray intersects anything, we move the camera to the
# the first intersection point, This brings the camera in between its
# ideal position, and any present obstructions.
entries = []
for i in range(self.cameraColHandler.getNumEntries()):
entry = self.cameraColHandler.getEntry(i)
entries.append(entry)
entries.sort(lambda x,y: cmp(-y.getSurfacePoint(self.ralph).getY(),
-x.getSurfacePoint(self.ralph).getY()))
if (len(entries)>0):
collisionPoint = entries[0].getSurfacePoint(self.ralph)
collisionVec = ( viewTarget - collisionPoint)
if ( collisionVec.lengthSquared() < self.cameraDistance * self.cameraDistance ):
base.camera.setPos(collisionPoint)
if (entries[0].getIntoNode().getName() == "terrain"):
base.camera.setZ(base.camera, 0.2)
base.camera.setY(base.camera, 0.3)
return task.cont
w = World()
run()
and the Ralph PSSM Shadows:
# Author: Ryan Myers
# Models: Jeff Styers, Reagan Heller
# Last Updated: 6/13/2005
#
# This tutorial provides an example of creating a character
# and having it walk around on uneven terrain, as well
# as implementing a fully rotatable camera.
import direct.directbase.DirectStart
from panda3d.core import CollisionTraverser,CollisionNode
from panda3d.core import CollisionHandlerQueue,CollisionRay
from panda3d.core import Filename,AmbientLight,DirectionalLight
from panda3d.core import PandaNode,NodePath,Camera,TextNode
from panda3d.core import Vec3,Vec4,BitMask32
from direct.gui.OnscreenText import OnscreenText
from direct.actor.Actor import Actor
from direct.showbase.DirectObject import DirectObject
import random, sys, os, math
SPEED = 0.5
# Function to put instructions on the screen.
def addInstructions(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)
# Function to put title on the screen.
def addTitle(text):
return OnscreenText(text=text, style=1, fg=(1,1,1,1),
pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
class World(DirectObject):
def __init__(self):
self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}
base.win.setClearColor(Vec4(0,0,0,1))
# Post the instructions
self.title = addTitle("Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)")
self.inst1 = addInstructions(0.95, "[ESC]: Quit")
self.inst2 = addInstructions(0.90, "[Left Arrow]: Rotate Ralph Left")
self.inst3 = addInstructions(0.85, "[Right Arrow]: Rotate Ralph Right")
self.inst4 = addInstructions(0.80, "[Up Arrow]: Run Ralph Forward")
self.inst6 = addInstructions(0.70, "[A]: Rotate Camera Left")
self.inst7 = addInstructions(0.65, "[S]: Rotate Camera Right")
# Set up the environment
#
# This environment model contains collision meshes. If you look
# in the egg file, you will see the following:
#
# <Collide> { Polyset keep descend }
#
# This tag causes the following mesh to be converted to a collision
# mesh -- a mesh which is optimized for collision, not rendering.
# It also keeps the original mesh, so there are now two copies ---
# one optimized for rendering, one for collisions.
self.environ = loader.loadModel("models/world")
self.environ.reparentTo(render)
self.environ.setPos(0,0,0)
# Create the main character, Ralph
ralphStartPos = self.environ.find("**/start_point").getPos()
self.ralph = Actor("models/ralph",
{"run":"models/ralph-run",
"walk":"models/ralph-walk"})
self.ralph.reparentTo(render)
self.ralph.setScale(.2)
self.ralph.setPos(ralphStartPos)
# Create a floater object. We use the "floater" as a temporary
# variable in a variety of calculations.
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
# Accept the control keys for movement and rotation
self.accept("escape", sys.exit)
self.accept("arrow_left", self.setKey, ["left",1])
self.accept("arrow_right", self.setKey, ["right",1])
self.accept("arrow_up", self.setKey, ["forward",1])
self.accept("a", self.setKey, ["cam-left",1])
self.accept("s", self.setKey, ["cam-right",1])
self.accept("arrow_left-up", self.setKey, ["left",0])
self.accept("arrow_right-up", self.setKey, ["right",0])
self.accept("arrow_up-up", self.setKey, ["forward",0])
self.accept("a-up", self.setKey, ["cam-left",0])
self.accept("s-up", self.setKey, ["cam-right",0])
taskMgr.add(self.move,"moveTask")
# Game state variables
self.isMoving = False
# Set up the camera
base.disableMouse()
base.cam.setPos(self.ralph.getX(),self.ralph.getY()+10,2)
# We will detect the height of the terrain by creating a collision
# ray and casting it downward toward the terrain. One ray will
# start above ralph's head, and the other will start above the camera.
# A ray may hit the terrain, or it may hit a rock or a tree. If it
# hits the terrain, we can detect the height. If it hits anything
# else, we rule that the move is illegal.
self.cTrav = CollisionTraverser()
self.ralphGroundRay = CollisionRay()
self.ralphGroundRay.setOrigin(0,0,1000)
self.ralphGroundRay.setDirection(0,0,-1)
self.ralphGroundCol = CollisionNode('ralphRay')
self.ralphGroundCol.addSolid(self.ralphGroundRay)
self.ralphGroundCol.setFromCollideMask(BitMask32.bit(0))
self.ralphGroundCol.setIntoCollideMask(BitMask32.allOff())
self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol)
self.ralphGroundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
self.camGroundRay = CollisionRay()
self.camGroundRay.setOrigin(0,0,1000)
self.camGroundRay.setDirection(0,0,-1)
self.camGroundCol = CollisionNode('camRay')
self.camGroundCol.addSolid(self.camGroundRay)
self.camGroundCol.setFromCollideMask(BitMask32.bit(0))
self.camGroundCol.setIntoCollideMask(BitMask32.allOff())
self.camGroundColNp = base.cam.attachNewNode(self.camGroundCol)
self.camGroundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler)
# Uncomment this line to see the collision rays
#self.ralphGroundColNp.show()
#self.camGroundColNp.show()
# Uncomment this line to show a visual representation of the
# collisions occuring
#self.cTrav.showCollisions(render)
# Create some lighting
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor(Vec4(.3, .3, .3, 1))
directionalLight = DirectionalLight("directionalLight")
directionalLight.setDirection(Vec3(-5, -5, -5))
directionalLight.setColor(Vec4(1, 1, 1, 1))
directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
render.setLight(render.attachNewNode(ambientLight))
render.setLight(render.attachNewNode(directionalLight))
#Records the state of the arrow keys
def setKey(self, key, value):
self.keyMap[key] = value
# Accepts arrow keys to move either the player or the menu cursor,
# Also deals with grid checking and collision detection
def move(self, task):
# If the camera-left key is pressed, move camera left.
# If the camera-right key is pressed, move camera right.
base.cam.lookAt(self.ralph)
if (self.keyMap["cam-left"]!=0):
base.cam.setX(base.cam, -20 * globalClock.getDt())
if (self.keyMap["cam-right"]!=0):
base.cam.setX(base.cam, +20 * globalClock.getDt())
# save ralph's initial position so that we can restore it,
# in case he falls off the map or runs into something.
startpos = self.ralph.getPos()
# If a move-key is pressed, move ralph in the specified direction.
if (self.keyMap["left"]!=0):
self.ralph.setH(self.ralph.getH() + 300 * globalClock.getDt())
if (self.keyMap["right"]!=0):
self.ralph.setH(self.ralph.getH() - 300 * globalClock.getDt())
if (self.keyMap["forward"]!=0):
self.ralph.setY(self.ralph, -25 * globalClock.getDt())
# If ralph is moving, loop the run animation.
# If he is standing still, stop the animation.
if (self.keyMap["forward"]!=0) or (self.keyMap["left"]!=0) or (self.keyMap["right"]!=0):
if self.isMoving is False:
self.ralph.loop("run")
self.isMoving = True
else:
if self.isMoving:
self.ralph.stop()
self.ralph.pose("walk",5)
self.isMoving = False
# If the camera is too far from ralph, move it closer.
# If the camera is too close to ralph, move it farther.
camvec = self.ralph.getPos() - base.cam.getPos()
camvec.setZ(0)
camdist = camvec.length()
camvec.normalize()
if (camdist > 10.0):
base.cam.setPos(base.cam.getPos() + camvec*(camdist-10))
camdist = 10.0
if (camdist < 5.0):
base.cam.setPos(base.cam.getPos() - camvec*(5-camdist))
camdist = 5.0
# Now check for collisions.
self.cTrav.traverse(render)
# Adjust ralph's Z coordinate. If ralph's ray hit terrain,
# update his Z. If it hit anything else, or didn't hit anything, put
# him back where he was last frame.
entries = []
for i in range(self.ralphGroundHandler.getNumEntries()):
entry = self.ralphGroundHandler.getEntry(i)
entries.append(entry)
entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
x.getSurfacePoint(render).getZ()))
if (len(entries)>0) and (entries[0].getIntoNode().getName() == "terrain"):
self.ralph.setZ(entries[0].getSurfacePoint(render).getZ())
else:
self.ralph.setPos(startpos)
# Keep the camera at one foot above the terrain,
# or two feet above ralph, whichever is greater.
entries = []
for i in range(self.camGroundHandler.getNumEntries()):
entry = self.camGroundHandler.getEntry(i)
entries.append(entry)
entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
x.getSurfacePoint(render).getZ()))
if (len(entries)>0) and (entries[0].getIntoNode().getName() == "terrain"):
base.cam.setZ(entries[0].getSurfacePoint(render).getZ()+1.0)
if (base.cam.getZ() < self.ralph.getZ() + 2.0):
base.cam.setZ(self.ralph.getZ() + 2.0)
# The camera should look in ralph's direction,
# but it should also try to stay horizontal, so look at
# a floater which hovers above ralph's head.
self.floater.setPos(self.ralph.getPos())
self.floater.setZ(self.ralph.getZ() + 2.0)
base.cam.lookAt(self.floater)
return task.cont
global w
w = World()
### ------------------------ Guis####-------------------
from ShadowManager import *
from panda3d.core import PerspectiveLens
global objShadManager
global tdict
tdict = {}
tdict[ 'DebugLabelIntensity' ] = 1.0
global camEagle
global booEagle
global booShadCam1
global booShadCam2
global booShadCam3
booShadCam1 = False
booShadCam2 = False
booShadCam3 = False
booEagle = False
camEagle = base.makeCamera( base.win, sort = 4, camName = 'Eagle One' )
camEagle.setPos( 0, 0, 300)
camEagle.lookAt( 0, 0, 0)
camEagle.node().setActive(0)
def ToggleColorSection():
global tdict
tdict[ 'DebugLabelIntensity'] = 1 - tdict[ 'DebugLabelIntensity']
npRoot.setShaderInput('DebugLabelIntensity', Vec4( tdict[ 'DebugLabelIntensity'], 0, 0, 0 ) )
def LookAtRalph(task):
global w
camEagle.lookAt( w.ralph )
return task.cont
def EagleView():
global objShadManager
global booEagle
booEagle = not booEagle
if booEagle:
base.cam.node().setActive(0)
camEagle.node().setActive(1)
taskMgr.add( LookAtRalph, 'LookAtRalph' )
else:
base.cam.node().setActive(0)
camEagle.node().setActive(1)
taskMgr.remove( 'LookAtRalph' )
def ToggleShadCam1():
global booShadCam1
booShadCam1 = not booShadCam1
if booShadCam1:
objShadManager.listShadowCams[0].node().showFrustum()
base.cam.node().showFrustum()
else:
base.cam.node().hideFrustum()
objShadManager.listShadowCams[0].node().hideFrustum()
def ToggleShadCam2():
global booShadCam2
booShadCam2 = not booShadCam2
if booShadCam2:
objShadManager.listShadowCams[1].node().showFrustum()
base.cam.node().showFrustum()
else:
base.cam.node().hideFrustum()
objShadManager.listShadowCams[1].node().hideFrustum()
def ToggleShadCam3():
global booShadCam3
booShadCam3 = not booShadCam3
if booShadCam3:
objShadManager.listShadowCams[2].node().showFrustum()
base.cam.node().showFrustum()
else:
objShadManager.listShadowCams[2].node().hideFrustum()
base.cam.node().hideFrustum()
base.accept('c', ToggleColorSection )
base.accept('e', EagleView )
base.accept('1', ToggleShadCam1 )
base.accept('2', ToggleShadCam2 )
base.accept('3', ToggleShadCam3 )
lens = base.cam.node().getLens()
lens.setNear( 5 )
lens.setFar( 120 )
tdir = Vec3( 1, 1, 1)
tdir.normalize()
objShadManager = clShadowManager( npViewCam = base.cam, vec3LightDir = tdir, objSpace = None, tupMapSizes = (2048,2048,2048), booOptimize = True,
booGhostBuffers = False )
objShadManager.DebugAutoFrustumRecalc()
npRoot = render
shader = loader.loadShader( 'zshadow.c' )
npRoot.setShader( shader )
npRoot.setShaderInput('MainCamera', base.cam )
npRoot.setShaderInput('KeyLightDir', objShadManager.GetLightDirAsVB4() )
tlist = objShadManager.GetListSplitDepths()
print tlist
npRoot.setShaderInput('SplitDepth', Vec4( tlist[1], tlist[2], tlist[3], 0 ) )
npRoot.setShaderInput('ShadowCam0', objShadManager.GetNpShadowCam( 0 ) )
npRoot.setShaderInput('ShadowCam1', objShadManager.GetNpShadowCam( 1 ) )
npRoot.setShaderInput('ShadowCam2', objShadManager.GetNpShadowCam( 2 ) )
npRoot.setShaderInput('texShadDepth0', objShadManager.GetDepthTexture( 0 ) )
npRoot.setShaderInput('texShadDepth1', objShadManager.GetDepthTexture( 1 ) )
npRoot.setShaderInput('texShadDepth2', objShadManager.GetDepthTexture( 2 ) )
npRoot.setShaderInput('smapkernal', Vec4( 1./objShadManager.GetTupMapSizes()[0],0 ,0,0 ) )
npRoot.setShaderInput('DebugLabelIntensity', Vec4( tdict[ 'DebugLabelIntensity'], 0, 0,0 ) )
t = addInstructions(0.50, "[c] Toggle Frustum labeling")
t = addInstructions(0.45, "[e] Eagle's View of the camera")
t = addInstructions(0.40, "[1][2][3] Toggle Debug Shadow Cam")
run()
Thanks.