[Python-ogre-commit] SF.net SVN: python-ogre:[763] trunk/python-ogre/demos
Brought to you by:
andy_miller,
roman_yakovenko
From: <and...@us...> - 2008-10-20 14:39:48
|
Revision: 763 http://python-ogre.svn.sourceforge.net/python-ogre/?rev=763&view=rev Author: andy_miller Date: 2008-10-20 14:39:41 +0000 (Mon, 20 Oct 2008) Log Message: ----------- cleanup on Hikair demo and pssm Modified Paths: -------------- trunk/python-ogre/demos/hikari/Demo_Hikari_01.py Added Paths: ----------- trunk/python-ogre/demos/PSSM_demo/Demo_pssm.py Removed Paths: ------------- trunk/python-ogre/demos/PSSM_demo/pssm_demo.py Copied: trunk/python-ogre/demos/PSSM_demo/Demo_pssm.py (from rev 759, trunk/python-ogre/demos/PSSM_demo/pssm_demo.py) =================================================================== --- trunk/python-ogre/demos/PSSM_demo/Demo_pssm.py (rev 0) +++ trunk/python-ogre/demos/PSSM_demo/Demo_pssm.py 2008-10-20 14:39:41 UTC (rev 763) @@ -0,0 +1,158 @@ +# This code is in the Public Domain +# ----------------------------------------------------------------------------- +# This source file is part of Python-Ogre +# For the latest info, see http://python-ogre.org/ +# +# It is likely based on original code from OGRE and/or PyOgre +# For the latest info, see http://www.ogre3d.org/ +# +# You may use this sample code for anything you like, it is not covered by the +# LGPL. +# ----------------------------------------------------------------------------- + +# NOTE: +# This demo includes meshes and shaders by lf3thn4d +# see below for more details: +# http://www.ogre3d.org/phpBB2/viewtopic.php?t=41801&highlight=pssm + +# Authors Note: +# This demo seems to perform much better on ATI cards than NVIDIA! + +import sys +sys.path.insert(0,'..') +import PythonOgreConfig + +import ogre.renderer.OGRE as ogre +import ogre.io.OIS as OIS +import SampleFramework as sf + +class PSSMDemoFrameListener(sf.FrameListener): + def __init__(self, rw, cam, light): + sf.FrameListener.__init__(self, rw, cam) + self.light = light + self.angle = ogre.Math.PI / 2 + self.radius = 1000 + + def frameStarted(self, evt): + self.angle += evt.timeSinceLastFrame + xpos = self.radius * ogre.Math.Sin( ogre.Degree( self.angle ) * 5.0 ) + zpos = self.radius * ogre.Math.Cos( ogre.Degree( self.angle ) * 5.0 ) + pos = ogre.Vector3( xpos, 400, zpos ) + self.light.setPosition( pos ) + dirvec = -self.light.getPosition() + dirvec.normalise() + self.light.setDirection( dirvec ) + + return sf.FrameListener.frameStarted(self, evt) + + + +class ApplicationPSSM(sf.Application): + + def __del__(self): + del self.pssmSetup + + def _createScene(self): + self.sceneManager.setShadowTechnique(ogre.SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED) + + # 3 textures per directional light + self.sceneManager.setShadowTextureCountPerLightType(ogre.Light.LT_DIRECTIONAL, 3); + self.sceneManager.setShadowTextureSettings(1024, 3, ogre.PF_FLOAT32_R); + self.sceneManager.setShadowTextureSelfShadow(True); + # Set up caster material - this is just a standard depth/shadow map caster + self.sceneManager.setShadowTextureCasterMaterial("shadow_caster"); + self.camera.setNearClipDistance(1.0) + self.camera.setFarClipDistance(1000.0) + + # shadow camera setup + self.pssmSetup = ogre.PSSMShadowCameraSetup() + self.pssmSetup.calculateSplitPoints(3, self.camera.getNearClipDistance(), self.camera.getFarClipDistance()) + self.pssmSetup.setSplitPadding(5) + self.pssmSetup.setOptimalAdjustFactor(0, 2) + self.pssmSetup.setOptimalAdjustFactor(1, 1); + self.pssmSetup.setOptimalAdjustFactor(2, 0.5) + + self.sceneManager.setShadowCameraSetup(self.pssmSetup) + + + # setup the sun light. + self.sceneManager.setAmbientLight(ogre.ColourValue(0.4, 0.4, 0.5)); + self.mSunLight = self.sceneManager.createLight("_SunLight") + self.mSunLight.setType(ogre.Light.LT_DIRECTIONAL) + self.mSunLight.setDirection(ogre.Vector3(-1, -1, -1)) + self.mSunLight.setDiffuseColour(ogre.ColourValue(1, 1, 1)) + self.mSunLight.setSpecularColour(ogre.ColourValue(1,1,1)) + + # Create the Mesh - + # Note Mesh and Shaders courtesy of lf3thn4d + cityNode = self.sceneManager.getRootSceneNode().createChildSceneNode() + cityEntity = self.sceneManager.createEntity("City", "city.mesh") + cityNode.attachObject(cityEntity) + cityNode.setScale(10,10,10) + + splitPoints = ogre.Vector4(0,0,0,0) + splitPointList = self.pssmSetup.getSplitPoints(); + mat = ogre.MaterialManager.getSingleton().getByName("city") + splitPoints.y = splitPointList[1] + splitPoints.z = splitPointList[2] + mat.getTechnique(0).getPass(1).getFragmentProgramParameters().setNamedConstant("pssmSplitPoints", splitPoints) + self._createDebugShadowOverlays() + + def _createDebugShadowOverlays(self): + baseWhite = ogre.MaterialManager.getSingletonPtr().getByName("BaseWhite") + DepthShadowTexture = baseWhite.clone("DepthShadowTexture0") + textureUnit = DepthShadowTexture.getTechnique(0).getPass(0).createTextureUnitState() + tex = self.sceneManager.getShadowTexture(0) + textureUnit.setTextureName(tex.getName()) + + DepthShadowTexture = baseWhite.clone("DepthShadowTexture1") + textureUnit = DepthShadowTexture.getTechnique(0).getPass(0).createTextureUnitState() + tex = self.sceneManager.getShadowTexture(1) + textureUnit.setTextureName(tex.getName()) + + DepthShadowTexture = baseWhite.clone("DepthShadowTexture2") + textureUnit = DepthShadowTexture.getTechnique(0).getPass(0).createTextureUnitState() + tex = self.sceneManager.getShadowTexture(2) + textureUnit.setTextureName(tex.getName()) + + overlayManager = ogre.OverlayManager.getSingleton() + # Create an overlay + self.mDebugOverlay = overlayManager.create("OverlayName") + + # Create a panel + panel = overlayManager.createOverlayElement("Panel", "PanelName0") + panel.setMetricsMode(ogre.GMM_PIXELS) + panel.setPosition(10, 10) + panel.setDimensions(100, 100) + panel.setMaterialName("DepthShadowTexture0") # Optional background material + self.mDebugOverlay.add2D(panel) + panel = overlayManager.createOverlayElement("Panel", "PanelName1") + panel.setMetricsMode(ogre.GMM_PIXELS) + panel.setPosition(120, 10) + panel.setDimensions(100, 100) + panel.setMaterialName("DepthShadowTexture1") # Optional background material + self.mDebugOverlay.add2D(panel) + panel = overlayManager.createOverlayElement("Panel", "PanelName2") + panel.setMetricsMode(ogre.GMM_PIXELS) + panel.setPosition(230, 10) + panel.setDimensions(100, 100) + panel.setMaterialName("DepthShadowTexture2") # Optional background material + self.mDebugOverlay.add2D(panel) + self.mDebugOverlay.show() + + def _createFrameListener(self): + self.frameListener = PSSMDemoFrameListener(self.renderWindow, self.camera, self.mSunLight) + self.root.addFrameListener(self.frameListener) + + + +if __name__ == '__main__': + import exceptions,sys + try: + application = ApplicationPSSM() + application.go() + except ogre.OgreException, e: + print e + + + Deleted: trunk/python-ogre/demos/PSSM_demo/pssm_demo.py =================================================================== --- trunk/python-ogre/demos/PSSM_demo/pssm_demo.py 2008-10-20 14:27:42 UTC (rev 762) +++ trunk/python-ogre/demos/PSSM_demo/pssm_demo.py 2008-10-20 14:39:41 UTC (rev 763) @@ -1,158 +0,0 @@ -# This code is in the Public Domain -# ----------------------------------------------------------------------------- -# This source file is part of Python-Ogre -# For the latest info, see http://python-ogre.org/ -# -# It is likely based on original code from OGRE and/or PyOgre -# For the latest info, see http://www.ogre3d.org/ -# -# You may use this sample code for anything you like, it is not covered by the -# LGPL. -# ----------------------------------------------------------------------------- - -# NOTE: -# This demo includes meshes and shaders by lf3thn4d -# see below for more details: -# http://www.ogre3d.org/phpBB2/viewtopic.php?t=41801&highlight=pssm - -# Authors Note: -# This demo seems to perform much better on ATI cards than NVIDIA! - -import sys -sys.path.insert(0,'..') -import PythonOgreConfig - -import ogre.renderer.OGRE as ogre -import ogre.io.OIS as OIS -import SampleFramework as sf - -class PSSMDemoFrameListener(sf.FrameListener): - def __init__(self, rw, cam, light): - sf.FrameListener.__init__(self, rw, cam) - self.light = light - self.angle = ogre.Math.PI / 2 - self.radius = 1000 - - def frameStarted(self, evt): - self.angle += evt.timeSinceLastFrame - xpos = self.radius * ogre.Math.Sin( ogre.Degree( self.angle ) * 5.0 ) - zpos = self.radius * ogre.Math.Cos( ogre.Degree( self.angle ) * 5.0 ) - pos = ogre.Vector3( xpos, 400, zpos ) - self.light.setPosition( pos ) - dirvec = -self.light.getPosition() - dirvec.normalise() - self.light.setDirection( dirvec ) - - return sf.FrameListener.frameStarted(self, evt) - - - -class ApplicationPSSM(sf.Application): - - def __del__(self): - del self.pssmSetup - - def _createScene(self): - self.sceneManager.setShadowTechnique(ogre.SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED) - - # 3 textures per directional light - self.sceneManager.setShadowTextureCountPerLightType(ogre.Light.LT_DIRECTIONAL, 3); - self.sceneManager.setShadowTextureSettings(1024, 3, ogre.PF_FLOAT32_R); - self.sceneManager.setShadowTextureSelfShadow(True); - # Set up caster material - this is just a standard depth/shadow map caster - self.sceneManager.setShadowTextureCasterMaterial("shadow_caster"); - self.camera.setNearClipDistance(1.0) - self.camera.setFarClipDistance(1000.0) - - # shadow camera setup - self.pssmSetup = ogre.PSSMShadowCameraSetup() - self.pssmSetup.calculateSplitPoints(3, self.camera.getNearClipDistance(), self.camera.getFarClipDistance()) - self.pssmSetup.setSplitPadding(5) - self.pssmSetup.setOptimalAdjustFactor(0, 2) - self.pssmSetup.setOptimalAdjustFactor(1, 1); - self.pssmSetup.setOptimalAdjustFactor(2, 0.5) - - self.sceneManager.setShadowCameraSetup(self.pssmSetup) - - - # setup the sun light. - self.sceneManager.setAmbientLight(ogre.ColourValue(0.4, 0.4, 0.5)); - self.mSunLight = self.sceneManager.createLight("_SunLight") - self.mSunLight.setType(ogre.Light.LT_DIRECTIONAL) - self.mSunLight.setDirection(ogre.Vector3(-1, -1, -1)) - self.mSunLight.setDiffuseColour(ogre.ColourValue(1, 1, 1)) - self.mSunLight.setSpecularColour(ogre.ColourValue(1,1,1)) - - # Create the Mesh - - # Note Mesh and Shaders courtesy of lf3thn4d - cityNode = self.sceneManager.getRootSceneNode().createChildSceneNode() - cityEntity = self.sceneManager.createEntity("City", "city.mesh") - cityNode.attachObject(cityEntity) - cityNode.setScale(10,10,10) - - splitPoints = ogre.Vector4(0,0,0,0) - splitPointList = self.pssmSetup.getSplitPoints(); - mat = ogre.MaterialManager.getSingleton().getByName("city") - splitPoints.y = splitPointList[1] - splitPoints.z = splitPointList[2] - mat.getTechnique(0).getPass(1).getFragmentProgramParameters().setNamedConstant("pssmSplitPoints", splitPoints) - self._createDebugShadowOverlays() - - def _createDebugShadowOverlays(self): - baseWhite = ogre.MaterialManager.getSingletonPtr().getByName("BaseWhite") - DepthShadowTexture = baseWhite.clone("DepthShadowTexture0") - textureUnit = DepthShadowTexture.getTechnique(0).getPass(0).createTextureUnitState() - tex = self.sceneManager.getShadowTexture(0) - textureUnit.setTextureName(tex.getName()) - - DepthShadowTexture = baseWhite.clone("DepthShadowTexture1") - textureUnit = DepthShadowTexture.getTechnique(0).getPass(0).createTextureUnitState() - tex = self.sceneManager.getShadowTexture(1) - textureUnit.setTextureName(tex.getName()) - - DepthShadowTexture = baseWhite.clone("DepthShadowTexture2") - textureUnit = DepthShadowTexture.getTechnique(0).getPass(0).createTextureUnitState() - tex = self.sceneManager.getShadowTexture(2) - textureUnit.setTextureName(tex.getName()) - - overlayManager = ogre.OverlayManager.getSingleton() - # Create an overlay - self.mDebugOverlay = overlayManager.create("OverlayName") - - # Create a panel - panel = overlayManager.createOverlayElement("Panel", "PanelName0") - panel.setMetricsMode(ogre.GMM_PIXELS) - panel.setPosition(10, 10) - panel.setDimensions(100, 100) - panel.setMaterialName("DepthShadowTexture0") # Optional background material - self.mDebugOverlay.add2D(panel) - panel = overlayManager.createOverlayElement("Panel", "PanelName1") - panel.setMetricsMode(ogre.GMM_PIXELS) - panel.setPosition(120, 10) - panel.setDimensions(100, 100) - panel.setMaterialName("DepthShadowTexture1") # Optional background material - self.mDebugOverlay.add2D(panel) - panel = overlayManager.createOverlayElement("Panel", "PanelName2") - panel.setMetricsMode(ogre.GMM_PIXELS) - panel.setPosition(230, 10) - panel.setDimensions(100, 100) - panel.setMaterialName("DepthShadowTexture2") # Optional background material - self.mDebugOverlay.add2D(panel) - self.mDebugOverlay.show() - - def _createFrameListener(self): - self.frameListener = PSSMDemoFrameListener(self.renderWindow, self.camera, self.mSunLight) - self.root.addFrameListener(self.frameListener) - - - -if __name__ == '__main__': - import exceptions,sys - try: - application = ApplicationPSSM() - application.go() - except ogre.OgreException, e: - print e - - - Modified: trunk/python-ogre/demos/hikari/Demo_Hikari_01.py =================================================================== --- trunk/python-ogre/demos/hikari/Demo_Hikari_01.py 2008-10-20 14:27:42 UTC (rev 762) +++ trunk/python-ogre/demos/hikari/Demo_Hikari_01.py 2008-10-20 14:39:41 UTC (rev 763) @@ -27,9 +27,7 @@ sceneManager = self.sceneManager camera = self.camera - sceneManager.ambientLight = ogre.ColourValue(0.5, 0.5, 0.5) -# sceneManager.ambientLight = ogre.ColourValue(ogre.ColourValue.White) - print ogre.ColourValue.White + sceneManager.ambientLight = ogre.ColourValue().White sceneManager.setShadowTechnique(ogre.SHADOWTYPE_TEXTURE_ADDITIVE) self.setupHikari() @@ -72,7 +70,8 @@ class HikariListener(sf.FrameListener, ois.MouseListener, ois.KeyListener): def __init__(self, app): - sf.FrameListener.__init__(self, app.renderWindow, app.camera, bufferedKeys = False) + print "INIT!!!" + sf.FrameListener.__init__(self, app.renderWindow, app.camera, bufferedMouse=True, bufferedKeys = True) ois.KeyListener.__init__(self) ois.MouseListener.__init__(self) self.app = app @@ -114,14 +113,14 @@ return [("x11_mouse_grab","false"), ("x11_mouse_hide", "false")] ## untested - def frameStarted(self, frameEvent): + def frameRenderingQueued(self, frameEvent): self.app.hikariMgr.update() # root.renderOneFrame() # Ogre::WindowEventUtilities::messagePump() stats = self.renderWindow.getStatistics() self.app.fps.callFunction("setFPS", hikari.Args(hikari.FlashValue(stats.lastFPS) )) - return sf.FrameListener.frameStarted(self, frameEvent) + return sf.FrameListener.frameRenderingQueued(self, frameEvent) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |