def setupLights(self): # Add a directional light dPos = Vec3(40, 40, 40) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(2048) dirLight.setPssmTarget(self.cam, self.camLens) # dirLight.setAmbientColor(Vec3(0.1,0.1,0.1)) dirLight.setCastsShadows(True) dirLight.setPos(dPos) dirLight.setColor(Vec3(6)) self.renderPipeline.addLight(dirLight) self.renderPipeline.globalIllum.setTargetLight(dirLight)
def __init__(self): DebugObject.__init__(self, "Main") self.debug("Bit System =", 8 * struct.calcsize("P")) # Load engine configuration self.debug("Loading panda3d configuration from configuration.prc ..") loadPrcFile("../../Config/configuration.prc") # Init the showbase ShowBase.__init__(self) # Create the render pipeline self.debug("Creating pipeline") self.renderPipeline = RenderingPipeline(self) # Set a write directory, where the shader cache and so on is stored # self.renderPipeline.getMountManager().setWritePath(writeDirectory) self.renderPipeline.getMountManager().setBasePath("../../") self.renderPipeline.loadSettings("../../Config/pipeline.ini") # Create the pipeline, and enable scattering self.renderPipeline.create() self.renderPipeline.enableDefaultEarthScattering() # Load some demo source self.sceneSource = "Models/SmoothCube/Cube.bam" # Load scene from disk self.debug("Loading Scene '" + self.sceneSource + "'") self.model = self.loader.loadModel(self.sceneSource) self.scene = render.attachNewNode("Scene") self.model.reparentTo(self.scene) self.model.setZ(1.0) # Wheter to use a ground floor self.usePlane = True self.sceneWireframe = False # Flatten scene self.scene.flattenStrong() # Load ground plane if configured if self.usePlane: self.groundPlane = self.loader.loadModel( "Models/Plane/Model.egg.bam") self.groundPlane.setPos(0, 0, 0) self.groundPlane.setScale(2.0) self.groundPlane.setTwoSided(True) self.groundPlane.flattenStrong() self.groundPlane.reparentTo(self.scene) # Prepare textures with SRGB format self.prepareSRGB(self.scene) # Create movement controller (Freecam) self.controller = MovementController(self) self.controller.setInitialPosition(Vec3(0, -5, 5.0), Vec3(0, 0, 5)) self.controller.setup() # Hotkey for wireframe self.accept("f3", self.toggleSceneWireframe) # Hotkey to reload all shaders self.accept("r", self.setShaders) # Create a sun light dPos = Vec3(60, 30, 100) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(2048) dirLight.setAmbientColor(Vec3(0.0, 0.0, 0.0)) dirLight.setPos(dPos) dirLight.setColor(Vec3(3)) dirLight.setPssmTarget(base.cam, base.camLens) dirLight.setPssmDistance(50.0) dirLight.setCastsShadows(True) self.renderPipeline.addLight(dirLight) self.dirLight = dirLight sunPos = Vec3(56.7587, -31.3601, 189.196) self.dirLight.setPos(sunPos) self.dirLight.setDirection(sunPos) # Tell the GI which light casts the GI self.renderPipeline.setGILightSource(dirLight) # Slider to move the sun if self.renderPipeline.settings.displayOnscreenDebugger: self.renderPipeline.guiManager.demoSlider.node[ "command"] = self.setSunPos self.renderPipeline.guiManager.demoSlider.node["value"] = 20 self.lastSliderValue = 0.0 # Load skyboxn self.skybox = None self.loadSkybox() # Set default object shaders self.setShaders(refreshPipeline=False) self.createGUI()
def __init__(self): # Load the default configuration.prc. This is recommended, as it # contains some important panda options loadPrcFile("../../Config/configuration.prc") ShowBase.__init__(self) # Create a new pipeline instance self.renderPipeline = RenderingPipeline(self) # Set the base path for the pipeline. This is required as we are in # a subdirectory self.renderPipeline.getMountManager().setBasePath("../../") # Also set the write path self.renderPipeline.getMountManager().setWritePath("../../Temp/") # Load the default settings self.renderPipeline.loadSettings("../../Config/pipeline.ini") # Now create the pipeline self.renderPipeline.create() # Add a directional light dPos = Vec3(40, 40, 40) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(2048) dirLight.setPssmTarget(self.cam, self.camLens) # dirLight.setAmbientColor(Vec3(0.1,0.1,0.1)) dirLight.setCastsShadows(True) dirLight.setPos(dPos) dirLight.setColor(Vec3(6)) self.renderPipeline.addLight(dirLight) self.renderPipeline.globalIllum.setTargetLight(dirLight) 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) self.environ.find("**/wall").removeNode() # 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]) # NOTICE: It is important that your update tasks have a lower priority # than -10000 taskMgr.add(self.move, "moveTask", priority=-20000) self.accept("r", self.reloadShader) # Game state variables self.isMoving = False # Set up the camera base.disableMouse() base.camera.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.camera.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) # Add earth scattering self.renderPipeline.enableDefaultEarthScattering() self.prepareSRGB(render) self.loadSkybox() self.reloadShader()
def __init__(self): # Load the default configuration.prc. This is recommended, as it # contains some important panda options loadPrcFile("../../Config/configuration.prc") ShowBase.__init__(self) # Create a new pipeline instance self.renderPipeline = RenderingPipeline(self) # Set the base path for the pipeline. This is required as we are in # a subdirectory self.renderPipeline.getMountManager().setBasePath("../../") # Also set the write path self.renderPipeline.getMountManager().setWritePath("../../Temp/") # Load the default settings self.renderPipeline.loadSettings("../../Config/pipeline.ini") # Now create the pipeline self.renderPipeline.create() # Add a directional light dPos = Vec3(40, 40, 40) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(4096) # dirLight.setAmbientColor(Vec3(0.1,0.1,0.1)) dirLight.setCastsShadows(True) dirLight.setPos(dPos) dirLight.setColor(Vec3(6)) self.renderPipeline.addLight(dirLight) 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) self.environ.ls() self.environ.find("**/wall").removeNode() # 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]) # NOTICE: It is important that your update tasks have a lower priority # than -10000 taskMgr.add(self.move, "moveTask", priority=-20000) self.accept("r", self.reloadShader) # Game state variables self.isMoving = False # Set up the camera base.disableMouse() base.camera.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.camera.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) # Add earth scattering self.renderPipeline.enableDefaultEarthScattering() self.prepareSRGB(render) self.loadSkybox() self.reloadShader()
from Code.RenderingPipeline import RenderingPipeline from Code.DirectionalLight import DirectionalLight #from Code.GlobalIllumination import GlobalIllumination from direct.showbase.ShowBaseWide import ShowBase base = ShowBase() rp = RenderingPipeline(base) #rp.getMountManager().setBasePath(".") rp.loadSettings("Config/pipeline.ini") rp.create() dLight = DirectionalLight() dLight.setDirection(Vec3(60, 30, 100)) dLight.setShadowMapResolution(2048) dLight.setAmbientColor(Vec3(0.0, 0.0, 0.0)) dLight.setPos(Vec3(60, 30, 100)) dLight.setColor(Vec3(3)) dLight.setPssmTarget(base.cam, base.camLens) dLight.setCastsShadows(True) rp.addLight(dLight) rp.setGILightSource(dLight) scene = loader.loadModel("../phase_3/models/gui/quit_button.bam") scene.reparentTo(render) scene.setScale(5) scene.setShader(rp.getDefaultObjectShader(False))
def __init__(self): DebugObject.__init__(self, "Main") self.debug("Bit System =", 8 * struct.calcsize("P")) # Load engine configuration self.debug("Loading panda3d configuration from configuration.prc ..") loadPrcFile("Config/configuration.prc") # Init the showbase ShowBase.__init__(self) # Create the render pipeline self.debug("Creating pipeline") self.renderPipeline = RenderingPipeline(self) self.renderPipeline.loadSettings("Config/pipeline.ini") # Uncomment to use temp directory # writeDirectory = tempfile.mkdtemp(prefix='Shader-tmp') # writeDirectory = "Temp/" # Clear write directory when app exits # atexit.register(os.remove, writeDirectory) # Set a write directory, where the shader cache and so on is stored # self.renderPipeline.getMountManager().setWritePath(writeDirectory) self.renderPipeline.getMountManager().setBasePath(".") ####### END OF RENDER PIPELINE SETUP ####### # Load some demo source # self.sceneSource = "Demoscene.ignore/sponza.egg.bam" # self.sceneSource = "Demoscene.ignore/occlusionTest/Model.egg" # self.sceneSource = "Demoscene.ignore/lost-empire/Model.egg" # self.sceneSource = "Models/PSSMTest/Model.egg.bam" # self.sceneSource = "Scene.ignore/Car.bam" # self.sceneSource = "Demoscene.ignore/GITest/Model.egg" # self.sceneSource = "Demoscene.ignore/PSSMTest/Model.egg.bam" # self.sceneSource = "Models/Raventon/Model.egg" # self.sceneSource = "Demoscene.ignore/Room/LivingRoom.egg.bam" self.sceneSource = "Toolkit/Blender Material Library/MaterialLibrary.egg" # If global illumination is enabled, load the voxel grid GlobalIllumination.setSceneRoot( "Toolkit/Blender Material Library/voxelized/") # Create the pipeline, and enable scattering self.renderPipeline.create() self.renderPipeline.enableDefaultEarthScattering() # Load scene from disk self.debug("Loading Scene '" + self.sceneSource + "'") self.scene = self.loader.loadModel(self.sceneSource) # Wheter to use a ground floor self.usePlane = False self.sceneWireframe = False # Flatten scene? self.scene.flattenStrong() # Load ground plane if configured if self.usePlane: self.groundPlane = self.loader.loadModel( "Models/Plane/Model.egg.bam") self.groundPlane.setPos(0, 0, -0.01) self.groundPlane.setScale(2.0) self.groundPlane.setTwoSided(True) self.groundPlane.flattenStrong() self.groundPlane.reparentTo(self.scene) # Some artists really don't know about backface culling # self.scene.setTwoSided(True) # Required for tesselation # self.convertToPatches(self.scene) self.scene.reparentTo(self.render) # Prepare textures with SRGB format self.prepareSRGB(self.scene) # Create movement controller (Freecam) self.controller = MovementController(self) self.controller.setInitialPosition( Vec3(0.422895, -6.49557, 4.72692), Vec3(0, 0, 3)) self.controller.setup() # Hotkey for wireframe self.accept("f3", self.toggleSceneWireframe) # Hotkey to reload all shaders self.accept("r", self.setShaders) # Create a sun light dPos = Vec3(60, 30, 100) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(4096) dirLight.setAmbientColor(Vec3(0.5, 0.5, 0.5)) dirLight.setCastsShadows(True) dirLight.setPos(dPos) dirLight.setColor(Vec3(4)) self.renderPipeline.addLight(dirLight) self.dirLight = dirLight sunPos = Vec3(56.7587, -31.3601, 189.196) self.dirLight.setPos(sunPos) self.dirLight.setDirection(sunPos) # Slider to move the sun if self.renderPipeline.settings.displayOnscreenDebugger: self.renderPipeline.guiManager.demoSlider.node[ "command"] = self.setSunPos self.lastSliderValue = 0.0 # Load skybox self.skybox = None self.loadSkybox() # Set default object shaders self.setShaders(refreshPipeline=False)
def __init__(self): DebugObject.__init__(self, "Main") self.debug("Bit System =", 8 * struct.calcsize("P")) # Load engine configuration self.debug("Loading panda3d configuration from configuration.prc ..") loadPrcFile("Config/configuration.prc") # Init the showbase ShowBase.__init__(self) # Create the render pipeline self.debug("Creating pipeline") self.renderPipeline = RenderingPipeline(self) # Uncomment to use temp directory # writeDirectory = tempfile.mkdtemp(prefix='Shader-tmp') # writeDirectory = "Temp/" # Clear write directory when app exits # atexit.register(os.remove, writeDirectory) # Set a write directory, where the shader cache and so on is stored # self.renderPipeline.getMountManager().setWritePath(writeDirectory) self.renderPipeline.getMountManager().setBasePath(".") ####### END OF RENDER PIPELINE SETUP ####### # Load some demo source # self.sceneSource = "Demoscene.ignore/sponza.egg.bam" # self.sceneSource = "Demoscene.ignore/occlusionTest/Model.egg" # self.sceneSource = "Demoscene.ignore/lost-empire/Model.egg" # self.sceneSource = "Models/PSSMTest/Model.egg.bam" # self.sceneSource = "Demoscene.ignore/GITest/Model.egg" # self.sceneSource = "Demoscene.ignore/PSSMTest/Model.egg.bam" # self.sceneSource = "Demoscene.ignore/Room/LivingRoom.egg" # self.sceneSource = "Models/CornelBox/Model.egg" # self.sceneSource = "Models/HouseSet/Model.egg" self.sceneSource = "Toolkit/Blender Material Library/MaterialLibrary.egg" self.renderPipeline.loadSettings("Config/pipeline.ini") # Create the pipeline, and enable scattering self.renderPipeline.create() self.renderPipeline.enableDefaultEarthScattering() # Load scene from disk self.debug("Loading Scene '" + self.sceneSource + "'") self.scene = self.loader.loadModel(self.sceneSource) # Wheter to use a ground floor self.usePlane = False self.sceneWireframe = False # Flatten scene? self.scene.flattenStrong() self.scene.analyze() # Load ground plane if configured if self.usePlane: self.groundPlane = self.loader.loadModel( "Models/Plane/Model.egg.bam") self.groundPlane.setPos(0, 0, -0.01) self.groundPlane.setScale(2.0) self.groundPlane.setTwoSided(True) self.groundPlane.flattenStrong() self.groundPlane.reparentTo(self.scene) # Some artists really don't know about backface culling # self.scene.setTwoSided(True) # Required for tesselation # self.convertToPatches(self.scene) self.scene.reparentTo(self.render) # Prepare textures with SRGB format self.prepareSRGB(self.scene) # Create movement controller (Freecam)wwww self.controller = MovementController(self) self.controller.setInitialPosition(Vec3(0, -5, 5.0), Vec3(0, 0, 5)) self.controller.setup() # Hotkey for wireframe self.accept("f3", self.toggleSceneWireframe) # Hotkey to reload all shaders self.accept("r", self.setShaders) # for i in xrange(1): # pointLight = PointLight() # pointLight.setPos(Vec3( (i-1)*3, 0, 7)) # pointLight.setColor(Vec3(0.1)) # pointLight.setShadowMapResolution(1024) # pointLight.setRadius(50) # pointLight.setCastsShadows(True) # # pointLight.attachDebugNode(render) # self.renderPipeline.addLight(pointLight) # Create a sun light dPos = Vec3(60, 30, 100) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(2048) dirLight.setAmbientColor(Vec3(0.0, 0.0, 0.0)) dirLight.setPos(dPos) dirLight.setColor(Vec3(3)) dirLight.setPssmTarget(base.cam, base.camLens) dirLight.setCastsShadows(True) self.renderPipeline.addLight(dirLight) self.dirLight = dirLight sunPos = Vec3(56.7587, -31.3601, 189.196) self.dirLight.setPos(sunPos) self.dirLight.setDirection(sunPos) # Tell the GI which light casts the GI self.renderPipeline.setGILightSource(dirLight) # Slider to move the sun if self.renderPipeline.settings.displayOnscreenDebugger: self.renderPipeline.guiManager.demoSlider.node[ "command"] = self.setSunPos self.renderPipeline.guiManager.demoSlider.node["value"] = 20 self.lastSliderValue = 0.0 # Load skyboxn self.skybox = None self.loadSkybox() # Set default object shaders self.setShaders(refreshPipeline=False)
def __init__(self): DebugObject.__init__(self, "Main") self.debug("Bit System =", 8 * struct.calcsize("P")) # Load engine configuration self.debug("Loading panda3d configuration from configuration.prc ..") loadPrcFile("Config/configuration.prc") # Init the showbase ShowBase.__init__(self) # Show loading screen self.loadingScreen = PipelineLoadingScreen(self) self.loadingScreen.render() self.loadingScreen.setStatus("Creating pipeline") # Create the render pipeline self.debug("Creating pipeline") self.renderPipeline = RenderingPipeline(self) # Uncomment to use temp directory # writeDirectory = tempfile.mkdtemp(prefix='Shader-tmp') writeDirectory = "Temp/" # Set the pipeline base path self.renderPipeline.getMountManager().setBasePath(".") # Load pipeline settings self.renderPipeline.loadSettings("Config/pipeline.ini") self.loadingScreen.setStatus("Compiling shaders") # Create the pipeline, and enable scattering self.renderPipeline.create() ####### END OF RENDER PIPELINE SETUP ####### # Select demo scene here: # This sources are not included in the repo, for size reasons # self.sceneSource = "Demoscene.ignore/MasterSword/Scene.egg" # self.sceneSource = "Demoscene.ignore/MasterSword/Scene2.egg.bam" # self.sceneSource = "Demoscene.ignore/Couch2/Scene.egg" # self.sceneSource = "Demoscene.ignore/Couch/couch.egg.bam" # self.sceneSource = "Demoscene.ignore/LivingRoom/LivingRoom.egg" # self.sceneSource = "Demoscene.ignore/LivingRoom2/LivingRoom.egg" # self.sceneSource = "Demoscene.ignore/LostEmpire/Model.egg" # self.sceneSource = "Demoscene.ignore/SSLRTest/scene.egg" # self.sceneSource = "Demoscene.ignore/BMW/Bmw.egg" # self.sceneSource = "Demoscene.ignore/OldHouse/Scene.egg" # self.sceneSource = "Demoscene.ignore/DemoTerrain/Scene.egg" # self.sceneSource = "Demoscene.ignore/TransparencyTest/Scene.egg" # self.sceneSource = "Demoscene.ignore/SanMiguel/Scene.bam" # This sources are included in the repo # self.sceneSource = "Models/CornelBox/Model.egg" # self.sceneSource = "Models/HouseSet/Model.egg" # self.sceneSource = "Models/PSSMTest/Model.egg.bam" # self.sceneSource = "Models/PBSTest/Scene.egg.bam" # self.sceneSource = "Models/HDRTest/Scene.egg" # self.sceneSource = "Models/GITestScene/Scene.egg" # self.sceneSource = "Models/VertexPerformanceTest/Scene.egg" self.sceneSource = "Models/Buddha/Buddha.bam" # self.sceneSource = "Toolkit/Blender Material Library/Buddha.bam" # Select surrounding scene here self.sceneSourceSurround = None # self.sceneSourceSurround = "Demoscene.ignore/Couch/Surrounding.egg" # self.sceneSourceSurround = "Demoscene.ignore/LivingRoom/LivingRoom.egg" # Store a list of transparent objects self.transparentObjects = [] # Create a sun light dPos = Vec3(60, 30, 100) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(1024) dirLight.setPos(dPos) dirLight.setColor(Vec3(1, 1, 0.8)) # dirLight.setColor(Vec3(0.3)) dirLight.setPssmTarget(base.cam, base.camLens) dirLight.setCastsShadows(True) self.renderPipeline.addLight(dirLight) self.dirLight = dirLight sunPos = Vec3(56.7587, -31.3601, 189.196) self.dirLight.setPos(sunPos) self.dirLight.setDirection(sunPos) # Tell the GI which light casts the GI self.renderPipeline.setGILightSource(dirLight) # Slider to move the sun if self.renderPipeline.settings.displayOnscreenDebugger: self.renderPipeline.guiManager.demoSlider.node[ "command"] = self.setSunPos self.renderPipeline.guiManager.demoSlider.node[ "value"] = 80 self.lastSliderValue = 0.0 self.movingLights = [] self.demoLights = [] # Create some lights for i in xrange(0): pointLight = PointLight() radius = float(i) / 5.0 * 6.28 + 1.52 xoffs = math.sin(radius) * 12.0 yoffs = math.cos(radius) * 12.0 pointLight.setPos(Vec3( xoffs, yoffs - 9, 12)) pointLight.setColor(Vec3( 0.3, 0.75, 1.0)) pointLight.setShadowMapResolution(512) pointLight.setRadius(35) pointLight.setCastsShadows(True) self.renderPipeline.addLight(pointLight) pointLight.attachDebugNode(render) self.movingLights.append(pointLight) # Create more lights for i in xrange(0): pointLight = PointLight() radius = float(i) / 5.0 * 6.28 + 5.22 xoffs = math.sin(radius) * 30.0 yoffs = math.cos(radius) * 30.0 pointLight.setPos(Vec3( xoffs, yoffs, 12)) pointLight.setColor(Vec3(0.2,0.6,1.0) * 0.1) pointLight.setRadius(60) self.renderPipeline.addLight(pointLight) # pointLight.attachDebugNode(render) for x in xrange(0): spotLight = SpotLight() spotLight.setColor(Vec3(0.5, 0.8, 1.0) * 0.2) lightPos = Vec3(x * 3.0 - 7.0, 0, 6) lightPos = Vec3(math.sin(x/19.0 * 6.28) * 7.0, math.cos(x/19.0 * 6.28) * 7.0, 10.0) spotLight.setPos(lightPos) spotLight.lookAt(lightPos - Vec3(0, 0, 1)) spotLight.setFov(90) spotLight.setShadowMapResolution(512) spotLight.setCastsShadows(True) spotLight.setNearFar(2.0, 15.0) spotLight.setIESProfile("AreaLight") self.renderPipeline.addLight(spotLight) # spotLight.attachDebugNode(render) # self.movingLights.append(spotLight) # Attach update task self.addTask(self.update, "update") # Update loading screen status self.loadingScreen.setStatus("Loading scene") # Show loading screen a bit if True: self.doMethodLater(0.5, self.loadScene, "Load Scene") else: self.loadScene()
def __init__(self): DebugObject.__init__(self, "Main") self.debug("Bit System =", 8 * struct.calcsize("P")) # Load engine configuration self.debug("Loading panda3d configuration from configuration.prc ..") loadPrcFile("../../Config/configuration.prc") # Init the showbase ShowBase.__init__(self) # Create the render pipeline self.debug("Creating pipeline") self.renderPipeline = RenderingPipeline(self) # Set a write directory, where the shader cache and so on is stored # self.renderPipeline.getMountManager().setWritePath(writeDirectory) self.renderPipeline.getMountManager().setBasePath("../../") self.renderPipeline.loadSettings("../../Config/pipeline.ini") # Create the pipeline, and enable scattering self.renderPipeline.create() self.renderPipeline.enableDefaultEarthScattering() # Load some demo source self.sceneSource = "Models/SmoothCube/Cube.bam" # Load scene from disk self.debug("Loading Scene '" + self.sceneSource + "'") self.model = self.loader.loadModel(self.sceneSource) self.scene = render.attachNewNode("Scene") self.model.reparentTo(self.scene) self.model.setZ(1.0) # Wheter to use a ground floor self.usePlane = True self.sceneWireframe = False # Flatten scene self.scene.flattenStrong() # Load ground plane if configured if self.usePlane: self.groundPlane = self.loader.loadModel( "Models/Plane/Model.egg.bam") self.groundPlane.setPos(0, 0, 0) self.groundPlane.setScale(2.0) self.groundPlane.setTwoSided(True) self.groundPlane.flattenStrong() self.groundPlane.reparentTo(self.scene) # Prepare textures with SRGB format self.prepareSRGB(self.scene) # Create movement controller (Freecam) self.controller = MovementController(self) self.controller.setInitialPosition( Vec3(0, -5, 5.0), Vec3(0, 0, 5)) self.controller.setup() # Hotkey for wireframe self.accept("f3", self.toggleSceneWireframe) # Hotkey to reload all shaders self.accept("r", self.setShaders) # Create a sun light dPos = Vec3(60, 30, 100) dirLight = DirectionalLight() dirLight.setDirection(dPos) dirLight.setShadowMapResolution(2048) dirLight.setAmbientColor(Vec3(0.0, 0.0, 0.0)) dirLight.setPos(dPos) dirLight.setColor(Vec3(3)) dirLight.setPssmTarget(base.cam, base.camLens) dirLight.setPssmDistance(50.0) dirLight.setCastsShadows(True) self.renderPipeline.addLight(dirLight) self.dirLight = dirLight sunPos = Vec3(56.7587, -31.3601, 189.196) self.dirLight.setPos(sunPos) self.dirLight.setDirection(sunPos) # Tell the GI which light casts the GI self.renderPipeline.setGILightSource(dirLight) # Slider to move the sun if self.renderPipeline.settings.displayOnscreenDebugger: self.renderPipeline.guiManager.demoSlider.node[ "command"] = self.setSunPos self.renderPipeline.guiManager.demoSlider.node[ "value"] = 20 self.lastSliderValue = 0.0 # Load skyboxn self.skybox = self.renderPipeline.getDefaultSkybox() self.skybox.reparentTo(render) # Set default object shaders self.setShaders(refreshPipeline=False) self.createGUI()