Fortuna
12-07-2007 22:47:39
I am currently learning the basics of Python-Ogre by studying the various demos and tutorials avaible for Python ogre.
I have however encountered a problem. When I try to create a scene using the ST_EXTERIOR_CLOSE scenemannager it seems not to want to load it.
To load it I use:
self.sm = self.root.createSceneManager(ogre.ST_EXTERIOR_CLOSE)
But when I try to apply the hightmap:
self.sm.setWorldGeometry("terrain.cfg")
I get the following error:
ogre.renderer.OGRE._ogre_exceptions_.OgreInvalidParametersException: OGRE EXCEPTION(2:): World geometry is not supported by the generic SceneManager. in SceneManager::setWorldGeometry at ..\src\OgreSceneManager.cpp (line 1312)
This makes it seem to me it loads the generic rather than the one I specified??? Is this really the case, and in that case. How does one fix it?
I have tried using the same two commands, when using the Sampleframework.py example from the demo folder. And here no problem occured.
If more information is needed. Please ask away
I suspect you are calling things in a strange order (perhaps??) -- could you post you complete source for us to look at. I did go back to Demo_Terrain and it works 'both' ways
class TerrainApplication(sf.Application):
def _chooseSceneManager(self):
# self.sceneManager = self.root.createSceneManager("TerrainSceneManager")
self.sceneManager = self.root.createSceneManager(ogre.ST_EXTERIOR_CLOSE)
Cheers
Andy
Fortuna
13-07-2007 06:06:43
Sure.. It is probably pretty messy though.
When learning how to use something like PyOgre I piece together bits and pieces from as many places as possible and then rewrite it. Makes the learning easier for me.
But I am pretty sure the order is correct. though my application class might be the problem?
iimport sys
import time
import ogre.renderer.OGRE as ogre
import ogre.io.OIS as OIS
class InputManager(OIS.KeyListener, OIS.MouseListener):
def __init__(self, app, hnd):
OIS.KeyListener.__init__(self)
OIS.MouseListener.__init__(self)
self.app = app
self.input_mgr = OIS.createPythonInputSystem([("WINDOW", str(hnd)),("w32_mouse", "DISCL_NONEXCLUSIVE"), ("w32_mouse", "DISCL_FOREGROUND")])
# Setup Unbuffered Keyboard and Buffered Mouse Input
self.keyboard = \
self.input_mgr.createInputObjectKeyboard(OIS.OISKeyboard,True)
self.keyboard.setEventCallback(self)
self.mouse = \
self.input_mgr.createInputObjectMouse(OIS.OISMouse, True)
self.mouse.setEventCallback(self)
def capture(self):
self.keyboard.capture()
self.mouse.capture()
def keyPressed(self, evt):
# evt.device is a reference to the device that emitted this signal
# evt.key is an OIS.KeyCode object (e.g. KC_SPACE)
# evt.text appears to be a decimal keycode (e.g. 115)
print "DOWN: %s" % evt.key
self.app.key_down(evt.key)
def keyReleased(self, evt):
print "UP: %s" % evt.key
self.app.key_up(evt.key)
def mouseMoved(self, evt):
return True
def mousePressed(self, evt, button):
print evt, button
return True
def mouseReleased(self, evt, button):
print evt, button
return True
def shutdown(self):
#self.input_mgr.destroyInputObjectMouse(self.mouse)
self.input_mgr.destroyInputObjectKeyboard(self.keyboard)
OIS.InputManager.destroyInputSystem(self.input_mgr)
class Application(object):
def _load_resources(self, resource_path):
config = ogre.ConfigFile()
config.load(resource_path)
section_iter = config.getSectionIterator()
while section_iter.hasMoreElements():
section_name = section_iter.peekNextKey()
settings = section_iter.getNext()
for item in settings:
self.rgm.addResourceLocation(item.value, item.key, section_name)
def _choose_render_engine(self):
rend_list = self.root.getAvailableRenderers()
self.root.setRenderSystem(rend_list[-1])
def __init__(self, plugins_path='plugins.cfg', resource_path='resources.cfg'):
self.plugins_path = plugins_path
self.resource_path = resource_path
self.root = ogre.Root(plugins_path)
self._choose_render_engine()
self.root.initialise(False)
# Create Light and setup window
self.sm = self.root.createSceneManager(ogre.ST_GENERIC)
self.sm = self.root.createSceneManager(ogre.ST_EXTERIOR_CLOSE)
self.sm.setAmbientLight(ogre.ColourValue(0.1, 0.1, 0.1))
l = self.sm.createLight("MainLight")
l.setType(ogre.Light.LT_DIRECTIONAL)
l.setDirection(-0.5, -0.5, 0)
self.sm.shadowTechnique = ogre.SHADOWTYPE_STENCIL_ADDITIVE
self.window = self.root.createRenderWindow("The World", 1280, 1024,True)
# keep track of the resource manager
self.rgm = ogre.ResourceGroupManager.getSingleton()
self._load_resources(self.resource_path)
## initalize resource here
self.rgm.initialiseAllResourceGroups()
self._build_scene()
window_hnd = self.window.getCustomAttributeInt("WINDOW")
self.input_manager = InputManager(self, window_hnd)
def _build_scene(self):
s_root = self.sm.getRootSceneNode()
#self.GroundPlane = GroundPlane(self, s_root, ogre.Vector3(0,0,0))
self.sm.setWorldGeometry("terrain.cfg")
self.camnode = Camera(self, s_root, ogre.Vector3(0,0,0))
self.sm.setSkyDome(True, 'CloudySky', 5, 8)
def key_down(self, key):
if key == OIS.KC_S:
self.transVector.z += self.move
elif key == OIS.KC_W:
self.transVector.z -= self.move
elif key == OIS.KC_D:
self.transVector.x += self.move
elif key == OIS.KC_A:
self.transVector.x -= self.move
def key_up(self, key):
if key == OIS.KC_ESCAPE:
self.window.destroy()
if key == OIS.KC_S:
self.transVector.z = 0
elif key == OIS.KC_W:
self.transVector.z = 0
elif key == OIS.KC_D:
self.transVector.x = 0
elif key == OIS.KC_A:
self.transVector.x = 0
def render_one(self):
self.root.renderOneFrame()
self.input_manager.capture()
currMouse = self.input_manager.mouse.getMouseState()
if currMouse.buttonDown(OIS.MB_Right):
self.camNode.yaw(ogre.Degree(-self.rotate * currMouse.X.rel).valueRadians())
self.camNode.pitch(ogre.Degree(-self.rotate * currMouse.Y.rel).valueRadians())
self.camNode.translate(self.camNode.Orientation * self.transVector)
def shutdown(self):
self.input_manager.shutdown()
self.root.shutdown()
class GroundPlane(object):
"""Creates the GroundPlane"""
def __init__(self, app, node, start_coords):
self.entity = app.sm.createEntity('GroundPlane', 'GroundPlane.mesh')
self.node = node.createChildSceneNode("GroundPlane_node", start_coords)
self.node.attachObject(self.entity)
src = self.node.Orientation * (ogre.Vector3.UNIT_Z)
directionToGo = ogre.Vector3(0,0,-1)
quat = src.getRotationTo(directionToGo)
self.node.Orientation=quat
class Camera(object):
"""Creates the camera and the viewport"""
def __init__(self, app, node, start_coords):
self.entity = app.sm.createCamera("camera")
self.entity.setNearClipDistance(0.1)
app.camNode = node.createChildSceneNode("Camera_node", start_coords)
app.camNode.attachObject(self.entity)
src = app.camNode.Orientation * (ogre.Vector3.UNIT_Z)
orientation = ogre.Vector3(0,0,0)
quat = src.getRotationTo(orientation)
app.camNode.Orientation=quat
app.transVector = ogre.Vector3(0, 0, 0)
app.move = 0.1
app.rotate = 0.2
app.viewport = app.window.addViewport(self.entity)
app.viewport.setBackgroundColour(ogre.ColourValue(0, 0, 0))
def main():
app = Application()
while not app.window.isClosed():
ogre.WindowEventUtilities().messagePump()
if app.window.isActive():
app.render_one()
time.sleep(.0001)
else:
time.sleep(1)
app.shutdown()
if __name__ == "__main__":
main()
You need to initialise the plugins before creating the SceneManager. ie if you change your createSceneManager line to:
self.sm = self.root.createSceneManager("TerrainSceneManager")
you will get a more interesting (and valid) error message. Using ogre.ST_EXTERIOR_CLOSE is misleading because it tells Ogre to do the best it can but to fail back (in this case to a generic sceneManager) - using a specific name forces Ogre to only try and load that one.
The problem is probably best fixed by specifically initialising the plugins such as:
self._choose_render_engine()
self.root.initialise(False)
self.root.initialisePlugins()
or you can create the renderWindow BEFORE you create the sceneManager which will do this for you.
Cheers
Andy
Fortuna
13-07-2007 11:26:11
Ah.. I see :D Creating the window before the scenemannager was exactly what I needed to do. I already initialized the plugins before... It works now!
Many thanks to you for taking the time to help a beginner! :D