[Python-ogre-commit] SF.net SVN: python-ogre: [406] trunk/python-ogre
Brought to you by:
andy_miller,
roman_yakovenko
From: <and...@us...> - 2007-10-03 04:10:33
|
Revision: 406 http://python-ogre.svn.sourceforge.net/python-ogre/?rev=406&view=rev Author: andy_miller Date: 2007-10-02 21:10:32 -0700 (Tue, 02 Oct 2007) Log Message: ----------- Missing files -- Navi Demo.. Added Paths: ----------- trunk/python-ogre/README trunk/python-ogre/convert.sed trunk/python-ogre/demos/media_extra/fish.ogg trunk/python-ogre/demos/media_extra/test.tst trunk/python-ogre/demos/navi/ trunk/python-ogre/demos/navi/Demo1_navi.py trunk/python-ogre/demos/navi/Demo_navi.py trunk/python-ogre/demos/navi/SampleFramework.py trunk/python-ogre/demos/navi/media.cfg trunk/python-ogre/demos/navi/ogre.cfg trunk/python-ogre/demos/navi/plugins.cfg trunk/python-ogre/demos/navi/resources.cfg trunk/python-ogre/demos/ogre/tests/Test_ManualMeshes.py trunk/python-ogre/demos/ogre/tests/Test_RenderOneFrame.py trunk/python-ogre/demos/ogre/tests/Test_WriteToTexture.py Added: trunk/python-ogre/README =================================================================== --- trunk/python-ogre/README (rev 0) +++ trunk/python-ogre/README 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,23 @@ +Please see http://python-ogre.python.hosting.com for info + +----- + +Copyright 2006-2007 The Python-Ogre Team. + +This file is part of Python-Ogre + +Python-Ogre is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Python-Ogre is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Python-Ogre; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + Added: trunk/python-ogre/convert.sed =================================================================== --- trunk/python-ogre/convert.sed (rev 0) +++ trunk/python-ogre/convert.sed 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,25 @@ +# sedscript to convert C++ Ogre programs t0 python +# simple stuff - comments, -> and :: to ., true/false spelling, remove ;, remove trailing 'f' on floats +s/\-\>/\./ +s/\/\//##/ +s/\-\>/\./ +s/\:\:/\./ +s/true/True/ +s/false/False/ +s/NULL/None/ +s/this/self/ +s/;/ / +s/const// +#s/\(^W*\)Ogre::^w+\(^W*\)/\1/ +s/\([0-9]\)f/\1/ +# put trailing : after if and else +s/\(^\W*if.*$\)/\1:/ +s/\(^\W*else.*$\)/\1:/ +# open and closing braces on their own lines get removed +s/^\W*{\W*$// +s/^\W*}\W*$// + +# (r'^[\W]*{[\W]*$\n',''), +# (r'^[\W]*}[\W]*$\n',''), + #(r'void \W*(\w+)\(','def $1('), +## (r'^/\*.*\*/', 'special3') Added: trunk/python-ogre/demos/media_extra/fish.ogg =================================================================== (Binary files differ) Property changes on: trunk/python-ogre/demos/media_extra/fish.ogg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/python-ogre/demos/media_extra/test.tst =================================================================== (Binary files differ) Property changes on: trunk/python-ogre/demos/media_extra/test.tst ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/python-ogre/demos/navi/Demo1_navi.py =================================================================== --- trunk/python-ogre/demos/navi/Demo1_navi.py (rev 0) +++ trunk/python-ogre/demos/navi/Demo1_navi.py 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,407 @@ +# For the latest inf +# +# You may use this sample code for anything you like, it is not covered by the +# LGPL. +# ----------------------------------------------------------------------------- +import ogre.renderer.OGRE as ogre +import ogre.gui.navi as navi +import ogre.io.OIS as OIS +import SampleFramework as sf + + +naviMgr = navi.NaviManager.Get() + +class NaviDemo(): + def __init__(self): + self.shouldQuit = False + self.renderWin = 0 + self.sceneMgr = 0 + + + def Startup( self ): + root = ogre.Root("./plugins.cfg", "./ogre.cfg", "./ogre.log") + if not root.restoreConfig(): + self.shouldQuit = not root.showConfigDialog() + if self.shouldQuit: + return + root.saveConfig() + self.root = root + self.renderWin = root.initialise(True, "NaviDemo") + + self.sceneMgr = root.createSceneManager("TerrainSceneManager", "NaviDemoSceneMgr") + self.sceneMgr.setAmbientLight(ogre.ColourValue(1, 1, 1)) + self.sceneMgr.setShadowTechnique(ogre.SHADOWTYPE_TEXTURE_ADDITIVE) + self.sceneMgr.setFog( ogre.FOG_LINEAR, ogre.ColourValue(0.9, 0.9, 1), 0.0, 0, 1550 ) + + camera = self.sceneMgr.createCamera("MainCam") + camera.setPosition(0,10,-15) + camera.lookAt(0, 0, 30) + viewport = self.renderWin.addViewport(camera) + viewport.setBackgroundColour(ogre.ColourValue(0.5, 0.5, 0.5)) + camera.setAspectRatio(viewport.getActualWidth() / viewport.getActualHeight()) + camera.setFarClipDistance( 1000 ) + camera.setNearClipDistance( 1 ) + camNode = self.sceneMgr.getRootSceneNode().createChildSceneNode("camNode") + camNode.attachObject(camera) + + if (root.getRenderSystem().getCapabilities().hasCapability(ogre.RSC_INFINITE_FAR_PLANE)): + camera.setFarClipDistance(0) + + light = self.sceneMgr.createLight( "Sun" ) + light.setType( ogre.Light.LT_DIRECTIONAL ) + light.setDiffuseColour( ogre.ColourValue( .82, .81, .7 ) ) + light.setSpecularColour( ogre.ColourValue( .82, .81, .7 ) ) + light.setDirection( ogre.Vector3( 0, -1, 1 ) ) + + self.parseResources() + + self.sceneMgr.setSkyDome( True, "CloudySky", 5, 6, 8 ) + + + ## Startup, create, and manage Navis + naviMgr.Startup(self.renderWin) + + naviMgr.createNavi("menubar", "local://menubar.html", navi.NaviPosition(navi.BottomCenter), 1024, 128, False) + naviMgr.setNaviMask("menubar", "navimenu_bg.png") +# # naviMgr.bind("menubar", "turnOn", NaviDelegate(this, &NaviDemo.turnOn), Strings("name")) +# # naviMgr.bind("menubar", "turnOff", NaviDelegate(this, &NaviDemo.turnOff), Strings("name")) +# # naviMgr.bind("menubar", "hpChange", NaviDelegate(this, &NaviDemo.hpChange), Strings("direction")) +# +# naviMgr.createNavi("status", "local:##status.html", navi.NaviPosition(0, 0), 512, 256, True, False) +# naviMgr.setNaviMask("status", "status_bg.png") +# # naviMgr.bind("status", "levelChanged", NaviDelegate(this, &NaviDemo.levelChanged), Strings("#level")) +# +# naviMgr.createNavi("chat", "http:##navi.agelessanime.com/chat", navi.NaviPosition(navi.BottomLeft, 40, -150), 512, 256, True, False) +# naviMgr.setNaviMask("chat", "navichat_bg.png") +# naviMgr.setNaviColorKey("chat", "#19001a", 0.7) +# # naviMgr.bind("chat", "messageSent", NaviDelegate(this, &NaviDemo.messageSent), Strings("nick")("message")) +# +# naviMgr.createNavi("equip", "local:##equip.html", navi.NaviPosition(navi.Right), 256, 512, True, False) +# naviMgr.setNaviMask("equip", "naviequip_bg.png") +# # naviMgr.bind("equip", "itemEquipped", NaviDelegate(this, &NaviDemo.itemEquipped), Strings("name")) +# +# ## Startup NaviMouse and create the cursors +# mouse = naviMgr.StartupMouse() +# mouse.createCursor("defaultCursor", 3, 2).addFrame(0, "cursor1.png") +# mouse.setDefaultCursor("defaultCursor") +# +# ## If you define a "move" cursor, NaviMouse will automatically use that when you move a Navi +# moveCursor = mouse.createCursor("move", 19, 19) +# moveCursor.addFrame(0, "cursorMove.png") +# + ## Create the ground + plane = ogre.Plane ( ogre.Vector3.UNIT_Y, 0) + ogre.MeshManager.getSingleton().createPlane("ground", + ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, + 1500,1500,1,1,True,1,9,9,ogre.Vector3.UNIT_Z) + ent = self.sceneMgr.createEntity( "GroundEntity", "ground" ) + self.sceneMgr.getRootSceneNode().createChildSceneNode("GroundNode").attachObject(ent) + ent.setMaterialName("Terrain") + ent.setCastShadows(False) + + ## Create the Blue Knot + ent = self.sceneMgr.createEntity( "BlueMetalKnot", "knot.mesh" ) + ent.setMaterialName("Knot") + ent.setCastShadows( True ) + + ## Position and scale the Blue Knot + node = self.sceneMgr.getRootSceneNode().createChildSceneNode("KnotNode", ogre.Vector3(0, 12, 45)) + node.attachObject( ent ) + node.scale=(.07, .07, .07) + print "Done Startup" + + ##loadInputSystem() + + ##Ogre.WindowEventUtilities.addWindowEventListener(self.renderWin, this) + + def turnOn(naviData): + naviName = naviData["name"].str() + + if(naviName == "quit"): + self.shouldQuit = True + else: + naviMgr.resetNaviPosition(naviName) + naviMgr.showNavi(naviName, True) + + def turnOff(naviData): + naviMgr.hideNavi(naviData["name"].str(), True) + +# # # def hpChange(const NaviData &naviData) +# # # { +# # # static short curHP = 100 +# # # +# # # if(naviData["direction"].str() == "up") +# # # { +# # # curHP += (rand() % 30) + 1 +# # # if(curHP > 100) curHP = 100 +# # # std.stringstream setHP +# # # setHP << "setHP(" << curHP << ")" +# # # naviMgr.naviEvaluateJS("status", setHP.str()) +# # # } +# # # else +# # # { +# # # curHP -= (rand() % 30) + 1 +# # # if(curHP < 0) curHP = 0 +# # # std.stringstream setHP +# # # setHP << "setHP(" << curHP << ")" +# # # naviMgr.naviEvaluateJS("status", setHP.str()) +# # # } +# # # +# # # std.stringstream hpMsg +# # # hpMsg << "Navi Menubar: Current HP is now " << curHP << "%" +# # # +# # # LogManager.getSingleton().logMessage(hpMsg.str()) +# # # } +# # # +# # # void NaviDemo.messageSent(const NaviData &naviData) +# # # { +# # # naviMgr.naviEvaluateJS("status", "$('playerName').innerHTML = '" + naviData["nick"].str() + "'") +# # # LogManager.getSingleton().logMessage("Navi Chat: " + naviData["message"].str()) +# # # } +# # # +# # # void NaviDemo.itemEquipped(const NaviData &naviData) +# # # { +# # # LogManager.getSingleton().logMessage("Navi Equip: Item '" + naviData["name"].str() + "' equipped!") +# # # } +# # # +# # # void NaviDemo.levelChanged(const NaviData &naviData) +# # # { +# # # int level = naviData["level"].toInt() +# # # +# # # std.stringstream levelMsg +# # # levelMsg << "Navi Status: Level has been changed to: " << level << ", double that is: " << level * 2 +# # # +# # # LogManager.getSingleton().logMessage(levelMsg.str()) +# # # } + + def Update(self): + navi.NaviManager.Get().Update() + self.root.renderOneFrame() + self.updateStats() + ogre.WindowEventUtilities.messagePump() + ##InputManager.getSingletonPtr().capture() + + + + def Shutdown(self): + navi.NaviManager.Get().Shutdown() + ogre.Root.getSingleton().shutdown() + + def parseResources(self): + config = ogre.ConfigFile() + config.load('resources.cfg' ) + seci = config.getSectionIterator() + while seci.hasMoreElements(): + SectionName = seci.peekNextKey() + Section = seci.getNext() + for item in Section: + ogre.ResourceGroupManager.getSingleton().\ + addResourceLocation(item.value, item.key, SectionName) + ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups() + + +# /* void NaviDemo.loadInputSystem() +# { +# inputMgr = InputManager.getSingletonPtr() +# inputMgr.initialise(self.renderWin) +# inputMgr.addMouseListener(this, "NaviDemoMouseListener") +# inputMgr.addKeyListener(this, "NaviDemoKeyListener") +# }*/ + + def updateStats(self): + return + +if __name__ == '__main__': + try: + demo = NaviDemo() + demo.Startup() + + while not demo.shouldQuit: + demo.Update() + except ogre.OgreException, e: + print e + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: trunk/python-ogre/demos/navi/Demo_navi.py =================================================================== --- trunk/python-ogre/demos/navi/Demo_navi.py (rev 0) +++ trunk/python-ogre/demos/navi/Demo_navi.py 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,150 @@ +# 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. +# ----------------------------------------------------------------------------- +import ogre.renderer.OGRE as ogre +import ogre.gui.navi as navi +import ogre.io.OIS as OIS +import SampleFramework as sf +import random + +class NaviApplication(sf.Application, ogre.WindowEventListener): + def _createScene(self): + sceneManager = self.sceneManager + camera = self.camera + self.naviMgr = navi.NaviManager.Get() + self.shouldQuit = False # flag to allow the app to do a shutdown + + sceneManager.ambientLight = ogre.ColourValue(0.5, 0.5, 0.5) + sceneManager.setSkyDome(True, 'CloudySky', 5.0, 6, 8,) + light = sceneManager.createLight( "Sun" ) + light.setType( ogre.Light.LT_DIRECTIONAL ) + light.setDiffuseColour( ogre.ColourValue( .82, .81, .7 ) ) + light.setSpecularColour( ogre.ColourValue( .82, .81, .7 ) ) + light.setDirection( ogre.Vector3( 0, -1, -1 ) ) + + ## Create the Blue Knot + ent = sceneManager.createEntity( "BlueMetalKnot", "knot.mesh" ) + ent.setMaterialName("Knot") + ent.setCastShadows( True ) + + ## Position and scale the Blue Knot + node = sceneManager.getRootSceneNode().createChildSceneNode("KnotNode", ogre.Vector3(0, 0, 400)) + node.attachObject( ent ) + node.scale=(.2, .2, .2) + + ## Startup, create, and manage Navis + self.naviMgr.Startup(self.renderWindow) + + self.naviMgr.createNavi("menubar", "local://menubar.html", navi.NaviPosition(navi.BottomCenter), 1024, 128, False) + self.naviMgr.setNaviMask("menubar", "navimenu_bg.png") + self.naviMgr.bind("menubar", "turnOn", self, "turnOn", ["name"] ) + self.naviMgr.bind("menubar", "turnOff", self, "turnOff", ["name"] ) + self.naviMgr.bind("menubar", "hpChange", self,"hpChange", ["direction"] ) + + self.naviMgr.createNavi("status", "local://status.html", navi.NaviPosition(0, 0), 512, 256, True, False) + self.naviMgr.setNaviMask("status", "status_bg.png") + self.naviMgr.bind("status", "levelChanged", self,"levelChanged", ["#level"]) + + self.naviMgr.createNavi("chat", "http://navi.agelessanime.com/chat", navi.NaviPosition(navi.BottomLeft, 40, -150), 512, 256, True, False) + self.naviMgr.setNaviMask("chat", "navichat_bg.png") + self.naviMgr.setNaviColorKey("chat", "#19001a", 0.7) + self.naviMgr.bind("chat", "messageSent", self, "messageSent", ["nick","message"]) + + self.naviMgr.createNavi("equip", "local://equip.html", navi.NaviPosition(navi.Right), 256, 512, True, False) + self.naviMgr.setNaviMask("equip", "naviequip_bg.png") + self.naviMgr.bind("equip", "itemEquipped", self, "itemEquipped", ["name"]) + + ## Startup NaviMouse and create the cursors + mouse = self.naviMgr.StartupMouse() + mouse.createCursor("defaultCursor", 3, 2).addFrame(0, "cursor1.png") + mouse.setDefaultCursor("defaultCursor") + + ## If you define a "move" cursor, NaviMouse will automatically use that when you move a Navi + moveCursor = mouse.createCursor("move", 19, 19) + moveCursor.addFrame(0, "cursorMove.png") + self.curHP = 100 + + def turnOn(self, naviData): + naviName = naviData["name"].str() + if(naviName == "quit"): + self.shouldQuit = True + else: + self.naviMgr.resetNaviPosition(naviName) + self.naviMgr.showNavi(naviName, True) + + def turnOff(self, naviData): + self.naviMgr.hideNavi(naviData["name"].str(), True) + + def hpChange(self,naviData): + print "HPCHANGE" + if naviData["direction"].str() == "up": + self.curHP += (random.random() % 30) + 1 + if self.curHP > 100: self.curHP = 100 + self.naviMgr.naviEvaluateJS("status", "setHP(" + str(self.curHP)+")" ) + else: + self.curHP -= (random.random() % 30) + 1 + if self.curHP < 0: self.curHP = 0 + self.naviMgr.naviEvaluateJS("status", "setHP(" + str(self.curHP)+")" ) + + ogre.LogManager.getSingleton().logMessage("Navi Menubar: Current HP is now " + str(self.curHP)+"%") + + def messageSent(self, naviData): + self.naviMgr.naviEvaluateJS("status", "$('playerName').innerHTML = '" + naviData["nick"].str() + "'") + ogre.LogManager.getSingleton().logMessage("Navi Chat: " + naviData["message"].str()) + + def itemEquipped(self, naviData): + ogre.LogManager.getSingleton().logMessage("Navi Equip: Item '" + naviData["name"].str() + "' equipped!") + + def levelChanged(seld, naviData): + level = naviData["level"].toInt() +# levelMsg << "Navi Status: Level has been changed to: " << level << ", double that is: " << level * 2 +# LogManager.getSingleton().logMessage(levelMsg.str()) + + def _createFrameListener(self): + self.frameListener = frameListener(self.renderWindow, self.camera, self) + self.root.addFrameListener(self.frameListener) + +class frameListener(sf.FrameListener, OIS.MouseListener, OIS.KeyListener): + def __init__(self, renderWindow, camera,app): + sf.FrameListener.__init__(self, renderWindow, camera) + self.showDebugOverlay(False) # don't show the overlay + OIS.KeyListener.__init__(self) + OIS.MouseListener.__init__(self) + self.app = app + self.Mouse.setEventCallback(self) + self.MenuMode = True # stops the mouse moving the background + self.Keyboard.setEventCallback(self) + + def mouseMoved(self,arg): + if(arg.get_state().Z.rel != 0): + navi.NaviManager.Get().injectMouseWheel(arg.get_state().Z.rel) + return navi.NaviManager.Get().injectMouseMove(arg.get_state().X.abs, arg.get_state().Y.abs) + + def mousePressed(self, arg, id): + return navi.NaviManager.Get().injectMouseDown(id) + + def mouseReleased(self, arg, id): + return navi.NaviManager.Get().injectMouseUp(id) + + def frameStarted(self, frameEvent): + navi.NaviManager.Get().Update() + ret = sf.FrameListener.frameStarted(self, frameEvent) + if self.app.shouldQuit == True: ret = False # force the exit + if not ret: # we've been asked to exit + navi.NaviManager.Get().Shutdown() + return ret + +if __name__ == '__main__': + try: + application = NaviApplication() + application.go() + except ogre.OgreException, e: + print e Added: trunk/python-ogre/demos/navi/SampleFramework.py =================================================================== --- trunk/python-ogre/demos/navi/SampleFramework.py (rev 0) +++ trunk/python-ogre/demos/navi/SampleFramework.py 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,14 @@ +# This code is in the Public Domain +# + +import ogre.renderer.OGRE as ogre + +# We don't use the verisons but it's nice to set them up... +ogre.OgreVersion = ogre.GetOgreVersion() +ogre.OgreVersionString = ogre.OgreVersion[0] + ogre.OgreVersion[1] + ogre.OgreVersion[2] +ogre.PythonOgreVersion = ogre.GetPythonOgreVersion() + +from ogre.renderer.OGRE.sf_OIS import * + + + Added: trunk/python-ogre/demos/navi/media.cfg =================================================================== --- trunk/python-ogre/demos/navi/media.cfg (rev 0) +++ trunk/python-ogre/demos/navi/media.cfg 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1 @@ + Added: trunk/python-ogre/demos/navi/ogre.cfg =================================================================== --- trunk/python-ogre/demos/navi/ogre.cfg (rev 0) +++ trunk/python-ogre/demos/navi/ogre.cfg 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,19 @@ +Render System=Direct3D9 Rendering Subsystem + +[Direct3D9 Rendering Subsystem] +Allow NVPerfHUD=No +Anti aliasing=None +Floating-point mode=Fastest +Full Screen=No +Rendering Device=ATI MOBILITY RADEON +VSync=No +Video Mode=800 x 600 @ 32-bit colour + +[OpenGL Rendering Subsystem] +Colour Depth=32 +Display Frequency=N/A +FSAA=0 +Full Screen=No +RTT Preferred Mode=FBO +VSync=No +Video Mode=640 x 480 Added: trunk/python-ogre/demos/navi/plugins.cfg =================================================================== --- trunk/python-ogre/demos/navi/plugins.cfg (rev 0) +++ trunk/python-ogre/demos/navi/plugins.cfg 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,14 @@ +# Defines plugins to load + +# Define plugin folder +PluginFolder=../../plugins + +# Define plugins +Plugin=RenderSystem_Direct3D9 +Plugin=RenderSystem_GL +Plugin=Plugin_ParticleFX +Plugin=Plugin_BSPSceneManager +Plugin=Plugin_OctreeSceneManager +Plugin=Plugin_CgProgramManager + + Added: trunk/python-ogre/demos/navi/resources.cfg =================================================================== --- trunk/python-ogre/demos/navi/resources.cfg (rev 0) +++ trunk/python-ogre/demos/navi/resources.cfg 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,9 @@ +# Resource locations to be added to the 'boostrap' path +# This also contains the minimum you need to use the Ogre example framework +[Bootstrap] +Zip=../media/packs/OgreCore.zip + +# Resource locations to be added to the default path +[General] +FileSystem=Media +FileSystem=NaviLocal Added: trunk/python-ogre/demos/ogre/tests/Test_ManualMeshes.py =================================================================== --- trunk/python-ogre/demos/ogre/tests/Test_ManualMeshes.py (rev 0) +++ trunk/python-ogre/demos/ogre/tests/Test_ManualMeshes.py 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,209 @@ +import ogre.renderer.OGRE as ogre +import sys +import SampleFramework +import math + +class ManuallyDefinedMesh: + def __init__(self,Name, Vertices_Pos, Vertices_Norm, Faces, Vertices_Colour=None, CreateImediately=True): + """ An experimental class to define meshes programatically + 'Name' is the name by which the mesh will be referenced + Vertices_Pos, Vertices_Norm are botj lists of triplets + Faces is a simple list of vertex indices + Vertices_Colour is an optional list of ogre.ColourValue's + You can delay the mesh loading by setting 'CreateImediately' to False + Even if you assign colors to your vertexes, you will have to assign a + material to each entity created based on this mesh.""" + + assert len(Vertices_Pos)==len(Vertices_Norm) + assert (len(Faces)%3)==0 #Each face is defined by 3 consecutive vertex indices + + if Vertices_Colour is not None : + assert len(Vertices_Pos)==len(Vertices_Colour) + + meshMgr = ogre.MeshManager.getSingleton() + self.mesh = mesh = meshMgr.createManual(Name, ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME) + self.subMesh = subMesh = mesh.createSubMesh() + + POSITION_ELEMENT = 0 + NORMAL_ELEMENT = 1 + UV_ELEMENT = 2 + COLOUR_ELEMENT = 0 + + self.Vertices_Pos = Vertices_Pos + self.Vertices_Norm = Vertices_Norm + self.Vertices_Colour = Vertices_Colour + + # ?????????????? / Not sure about this, without the get crash + mesh.sharedVertexData = ogre.VertexData() + mesh.sharedVertexData.vertexCount = len(Vertices_Pos) + + #work-around to prevent destruction + self.sharedVertexData = mesh.sharedVertexData + + declaration = mesh.sharedVertexData.vertexDeclaration + offset = 0 + offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3) + declaration.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_POSITION) + offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3) + + declaration.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_NORMAL) + offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3) + + hBuffMgr = ogre.HardwareBufferManager.getSingleton() + vbuf = hBuffMgr.createVertexBuffer(offset, mesh.sharedVertexData.vertexCount, + ogre.HardwareBuffer.HBU_STATIC_WRITE_ONLY) + + +# # pVertex = vbuf.lock(declaration, ogre.HardwareBuffer.HBL_DISCARD) + pVertex = vbuf.lock(ogre.HardwareBuffer.HBL_DISCARD) + + + #loop through the position array + for i in range(len(Vertices_Pos)): + vx, vy, vz = Vertices_Pos[i] + nx, ny, nz = Vertices_Norm[i] + + pVertex.setFloat(i, POSITION_ELEMENT, vx, vy, vz) + pVertex.setFloat(i, NORMAL_ELEMENT, nx, ny, nz) + bind = mesh.sharedVertexData.vertexBufferBinding + bind.setBinding(0,vbuf) #Set vertex buffer binding so buffer 0 is bound to positional data + + subMesh.indexData.indexCount = len(Faces) + subMesh.indexData.indexBuffer = hBuffMgr.createIndexBuffer(ogre.HardwareIndexBuffer.IT_16BIT, + len(Faces), ogre.HardwareBuffer.HBU_STATIC_WRITE_ONLY) + + ibuf = subMesh.indexData.indexBuffer + subMesh.indexData.indexBuffer.writeIndexes(0, Faces) + + vbuf.unlock() + + + #2nd buffer , colours + if Vertices_Colour is not None : + offset = 0 + declaration.addElement(1, offset, ogre.VET_COLOUR, ogre.VES_DIFFUSE) + offset += ogre.VertexElement.getTypeSize(ogre.VET_COLOUR) + vbuf = ogre.HardwareBufferManager.getSingleton().createVertexBuffer( + offset, mesh.sharedVertexData.vertexCount, ogre.HardwareBuffer.HBU_STATIC_WRITE_ONLY) +# # pVertex = vbuf.lock(declaration, ogre.HardwareBuffer.HBL_DISCARD) + pVertex = vbuf.lock(ogre.HardwareBuffer.HBL_DISCARD) + + for i in range(len(Vertices_Colour)): + pVertex.setColour(i, COLOUR_ELEMENT, Vertices_Colour[i]) + vbuf.unlock() + + #Set vertex buffer binding so buffer 1 is bound to our colour buffer + bind.setBinding(1, vbuf) + + subMesh.useSharedVertices = True + subMesh.indexData.indexBuffer = ibuf + subMesh.indexData.indexCount = len(Faces) + subMesh.indexData.indexStart = 0 + self.indexData = subMesh.indexData + + if CreateImediately: + self.MakeAvailable() + + def MakeAvailable(self,BoundBox=(None,None,None,None,None,None), BoundSphereRadius=None): + + if None in BoundBox: #Simple guess of the bounding box + xcoord = [i[0] for i in self.Vertices_Pos] + ycoord = [i[1] for i in self.Vertices_Pos] + zcoord = [i[2] for i in self.Vertices_Pos] + BoundBox = (min(xcoord),min(ycoord),min(zcoord),max(xcoord),max(ycoord),max(zcoord)) + + if BoundSphereRadius is None : #Very naive guess of the bounding sphere radius + BoundSphereRadius = max([abs(BoundBox[i+3]-BoundBox[i]) for i in range(3)]) + + mesh=self.mesh + + mesh._setBounds(ogre.AxisAlignedBox(*BoundBox)) + mesh._setBoundingSphereRadius(BoundSphereRadius) + + mesh.load() + + def Print(self): + mesh = self.mesh + print "Number SubMeshes",mesh.numSubMeshes + for i in range(mesh.numSubMeshes): + for f in (mesh.getSubMesh(i).indices): + print f + for v in ( mesh.getSubMesh(i).getVertices(ogre.Vector3(0.0,0.0,0.0), + ogre.Quaternion.IDENTITY, ogre.Vector3(1.0,1.0,1.0))): + print v + + +class TutorialApplication(SampleFramework.Application): + def _createScene(self): + sm = self.sceneManager + + self.headNode = sm.getRootSceneNode().createChildSceneNode('head1') + self.headNode.position=-70,0,0 + self.entity = sm.createEntity('head', 'ogrehead.mesh') + self.headNode.attachObject(self.entity) + + self.TestManual() + + def TestManual ( self ): + sqrt13 = 0.577350269 # sqrt(1/3) + x = 30.0 + y = 30.0 + z = 30.0 + vert_pos = [ + (-x,y,-z), #0 position + (x,y,-z), #1 position + (x,-y,-z), #2 position + (-x,-y,-z), #3 position + (-x,y,z), #4 position + (x,y,z), #5 position + (x,-y,z), #6 position + (-x,-y,z) #7 position + ] + vert_norm = [ + (-sqrt13,sqrt13,-sqrt13), #0 normal + (sqrt13,sqrt13,-sqrt13), #1 normal + (sqrt13,-sqrt13,-sqrt13), #2 normal + (-sqrt13,-sqrt13,-sqrt13), #3 normal + (-sqrt13,sqrt13,sqrt13), #4 normal + (sqrt13,sqrt13,sqrt13), #5 normal + (sqrt13,-sqrt13,sqrt13), #6 normal + (-sqrt13,-sqrt13,sqrt13) #7 normal + ] + faces = [ + 0,2,3, + 0,1,2, + 1,6,2, + 1,5,6, + 4,6,5, + 4,7,6, + 0,7,4, + 0,3,7, + 0,5,1, + 0,4,5, + 2,7,3, + 2,6,7] + + rs = self.root.getRenderSystem() +# colours=[] +# colours.append(rs.convertColourValue(ogre.ColourValue(1.0,0.0,0.0))) #0 colour +# colours.append(rs.convertColourValue(ogre.ColourValue(1.0,1.0,0.0))) #1 colour +# colours.append(rs.convertColourValue(ogre.ColourValue(0.0,1.0,0.0))) #2 colour +# colours.append(rs.convertColourValue(ogre.ColourValue(0.0,0.0,0.0))) #3 colour +# colours.append(rs.convertColourValue(ogre.ColourValue(1.0,0.0,1.0))) #4 colour +# colours.append(rs.convertColourValue(ogre.ColourValue(1.0,1.0,1.0))) #5 colour +# colours.append(rs.convertColourValue(ogre.ColourValue(0.0,1.0,1.0))) #6 colour +# colours.append(rs.convertColourValue(ogre.ColourValue(0.0,0.0,1.0))) #7 colour + + ManuallyDefinedMesh("cubeMesh",vert_pos,vert_norm,faces ) #,colours) + + self.cubeEntity = sceneManager.createEntity("myCubeEntity", "cubeMesh") + self.cubeEntity.setMaterialName("Test/SimpleVertexColor") + self.nd=sceneManager.rootSceneNode.createChildSceneNode() + self.nd.attachObject(self.cubeEntity) + + +if __name__ == '__main__': + ta = TutorialApplication() + ta.go() + + \ No newline at end of file Added: trunk/python-ogre/demos/ogre/tests/Test_RenderOneFrame.py =================================================================== --- trunk/python-ogre/demos/ogre/tests/Test_RenderOneFrame.py (rev 0) +++ trunk/python-ogre/demos/ogre/tests/Test_RenderOneFrame.py 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,9 @@ +import ogre.renderer.OGRE as ogre +class program: + def __init__(self): + self.root = ogre.Root("plugins.cfg","ogre.cfg","ogre.txt") + self.root.showConfigDialog() + self.root.initialise(True) +main = program() +while True: + main.root.renderOneFrame() \ No newline at end of file Added: trunk/python-ogre/demos/ogre/tests/Test_WriteToTexture.py =================================================================== --- trunk/python-ogre/demos/ogre/tests/Test_WriteToTexture.py (rev 0) +++ trunk/python-ogre/demos/ogre/tests/Test_WriteToTexture.py 2007-10-03 04:10:32 UTC (rev 406) @@ -0,0 +1,214 @@ +# 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. +# ----------------------------------------------------------------------------- +import ogre.renderer.OGRE as ogre +import SampleFramework as sf +import ctypes + + + +def WriteToTexture(in_string, destTexture, destRectangle, font, color, justify = 'l', wordwrap = True): + if destTexture.getHeight() < destRectangle.bottom: + destRectangle.bottom = destTexture.getHeight() + if destTexture.getWidth() < destRectangle.right: + destRectangle.right = destTexture.getWidth() + + if not font.isLoaded(): + font.load() + + fontTexture = ogre.TextureManager.getSingleton().getByName\ + (font.getMaterial().getTechnique(0).getPass(0).getTextureUnitState(0).getTextureName()) + + fontBuffer = fontTexture.getBuffer() + destBuffer = destTexture.getBuffer() + + destPb = destBuffer.lock(destRectangle,ogre.HardwareBuffer.HBL_NORMAL) + + ## The font texture buffer was created write only...so we cannot read it back :o). + ## One solution is to copy the buffer instead of locking it. + ## (Maybe there is a way to create a font texture which is not write_only ?) + + ## create a buffer + nBuffSize = fontBuffer.getSizeInBytes() + ## Here we show the difference in C++ and Python + ## uint8* buff = (uint8*)calloc(nBuffSize, sizeof(uint8)) + storageclass = ctypes.c_uint8 * (nBuffSize) # allocate a buffer class + buff=storageclass() + + ## the PixelBox call needs a pointer to the buffer and here's how we do this in Python-Ogre + VoidPointer = ogre.CastVoidPtr(ctypes.addressof(buff)) + + ## create pixel box using the copy of the buffer + fontPb = ogre.PixelBox(fontBuffer.getWidth(), fontBuffer.getHeight(),fontBuffer.getDepth(), + fontBuffer.getFormat(), VoidPointer) + fontBuffer.blitToMemory(fontPb) + +# fontData = static_cast<uint8*>( fontPb.data ) +# destData = static_cast<uint8*>( destPb.data ) + + fontData = buff + + # we nede to know the size of the dest buffer so hopefully this is right + destSize = destPb.getConsecutiveSize() + destData = (ctypes.c_uint8 * (destSize)).from_address( ogre.CastInt(destPb.getData()) ) + + fontPixelSize = ogre.PixelUtil.getNumElemBytes(fontPb.format) + destPixelSize = ogre.PixelUtil.getNumElemBytes(destPb.format) + + fontRowPitchBytes = fontPb.rowPitch * fontPixelSize + destRowPitchBytes = destPb.rowPitch * destPixelSize + + GlyphTexCoords =[] + for i in range (len (in_string)): + GlyphTexCoords.append(ogre.Box()) # need a fixed size array in Python + + charheight = 0 + charwidth = 0 + + for i in range ( len(in_string) ): + if ((in_string[i] != '\t') and (in_string[i] != '\n') and (in_string[i] != ' ')): + glypheTexRect = font.getGlyphTexCoords(ord(in_string[i]) ) + GlyphTexCoords[i].left = int(glypheTexRect.left * fontTexture.getSrcWidth()) + GlyphTexCoords[i].top = int(glypheTexRect.top * fontTexture.getSrcHeight()) + GlyphTexCoords[i].right = int(glypheTexRect.right * fontTexture.getSrcWidth()) + GlyphTexCoords[i].bottom = int(glypheTexRect.bottom * fontTexture.getSrcHeight()) + + if (GlyphTexCoords[i].getHeight() > charheight): + charheight = GlyphTexCoords[i].getHeight() + if (GlyphTexCoords[i].getWidth() > charwidth): + charwidth = GlyphTexCoords[i].getWidth() + + cursorX = 0 + cursorY = 0 + lineend = destRectangle.getWidth() + carriagreturn = True + for strindex in range (len(in_string) ): + tchar = in_string[strindex] + if tchar == ' ': cursorX += charwidth + elif tchar == '\t':cursorX += charwidth * 3 + elif tchar == '\n': + cursorY += charheight + carriagreturn = True + else: + ##wrapping + if (cursorX + GlyphTexCoords[strindex].getWidth()> lineend) and not carriagreturn: + cursorY += charheight + carriagreturn = True + + ##justify + if (carriagreturn): + l = strindex + textwidth = 0 + wordwidth = 0 + while (l < len(in_string) ) and (in_string[l] != '\n)'): + wordwidth = 0 + if in_string[l] == ' ': + wordwidth = charwidth + l+=1 + elif in_string[l] == '\t': + wordwidth = charwidth *3 + l+=1 + elif in_string[l] == '\n': l = len(in_string) + + if wordwrap: + while((l < len(in_string)) and (in_string[l] != ' ') and (in_string[l] != '\t') and (in_string[l] != '\n')): + wordwidth += GlyphTexCoords[l].getWidth() + l+=1 + else: + wordwidth += GlyphTexCoords[l].getWidth() + l+=1 + + if ((textwidth + wordwidth) <= destRectangle.getWidth()): + textwidth += (wordwidth) + else: + break + + if ((textwidth == 0) and (wordwidth > destRectangle.getWidth())): + textwidth = destRectangle.getWidth() + + if justify == 'c': + cursorX = (destRectangle.getWidth() - textwidth)/2 + lineend = destRectangle.getWidth() - cursorX + + elif justify == 'r': + cursorX = (destRectangle.getWidth() - textwidth) + lineend = destRectangle.getWidth() + + else: + cursorX = 0 + lineend = textwidth + + carriagreturn = False + + ##abort - net enough space to draw + if ((cursorY + charheight) > destRectangle.getHeight()): + ## need to bail here + print "ERROR" + + ##draw pixel by pixel + for i in range ( GlyphTexCoords[strindex].getHeight() ): + for j in range (GlyphTexCoords[strindex].getWidth() ): + + index =(i + GlyphTexCoords[strindex].top) * fontRowPitchBytes + (j + GlyphTexCoords[strindex].left) * fontPixelSize +1 + fd = fontData[ index ] + alpha = color.a * (fd / 255.0) + invalpha = 1.0 - alpha + offset = (i + cursorY) * destRowPitchBytes + (j + cursorX) * destPixelSize + pix = ogre.ColourValue() + address = ctypes.addressof(destData) + offset + ogre.PixelUtil.unpackColour(pix,destPb.format,address) + pix = (pix * invalpha) + (color * alpha) + ogre.PixelUtil.packColour(pix,destPb.format,address) + + cursorX += GlyphTexCoords[strindex].getWidth() + + destBuffer.unlock() + + +class TestApplication(sf.Application): + def _createScene(self): + sceneManager = self.sceneManager + camera = self.camera + + sceneManager.ambientLight = ogre.ColourValue(0.5, 0.5, 0.5) + + background = ogre.TextureManager.getSingleton().getByName("ogretext.png") + + font = ogre.FontManager.getSingleton().getByName("BlueHighway") + + ## Make sure the texture is not WRITE_ONLY, we need to read the buffer to do the blending with the font (get the alpha for example) + texture = ogre.TextureManager.getSingleton().createManual("Write Texture","General", + ogre.TEX_TYPE_2D, 512, 512, ogre.MIP_UNLIMITED , + ogre.PF_X8R8G8B8, ogre.TU_STATIC|ogre.TU_AUTOMIPMAP) + + ## Draw the background to the new texture + texture.getBuffer().blit(background.getBuffer()) + + WriteToTexture("Andy was here!",texture,ogre.Box(25,275,370,500),font,ogre.ColourValue(1.0,1.0,1.0,1.0),'c') + + c = sceneManager.createEntity("cubo", "cube.mesh") + n = sceneManager.getRootSceneNode().createChildSceneNode() + n.attachObject(c) + n.setPosition(ogre.Vector3(0, 0, 350)) + + c.setMaterialName('Examples/Rockwall') + + mat=ogre.MaterialManager.getSingleton().getByName('Examples/Rockwall') + tex=mat.getTechnique(0).getPass(0).getTextureUnitState(0) + tex.setTextureName("Write Texture") + + +if __name__ == '__main__': + try: + application = TestApplication() + application.go() + except ogre.OgreException, e: + print e This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |