Mogre + IronPython = Awesome


22-03-2008 01:26:19

I've created a small demo of using IronPython with Mogre. You can get/browse it from the subversion repository here: Please read at the end of this post for setup instructions.

[The Demo]
The demo I wrote up creates an OgreWindow and a second window with an IronPython console. The IronPython console allows you to inspect/change the state of the application using Python.

For the demo, I've included two python scripts. The first is an example of creating objects and adding a frame listener from within Python called To see it in action, simply go to File->Execute Script and choose You will see a Robot walking over the points (similar to Ogre's Intermediate Tutorial 3).

The second script ( shows you what you can do with the python console to inspect and change the state of your program. For example, execute using File->Execute Script. This drops several inspection-related things into the python namespace. For example, after executing the script (read the source of to see what DumpScene and Objects are doing):
>>> DumpScene()
Node: SceneRoot Vector3(0, 0, 0) Facing: Vector3(0, 0, -1)
Node: Knot1Node Vector3(0, -10, 25) Facing: Vector3(0, 0, -1)
Entity: Knot1
Node: Knot2Node Vector3(550, -10, 50) Facing: Vector3(0, 0, -1)
Entity: Knot2
Node: Knot3Node Vector3(-100, -10, -200) Facing: Vector3(0, 0, -1)
Entity: Knot3
Node: RobotNode Vector3(344.8275, -10, 40.67936) Facing: Vector3(0, 0, -1)
Entity: Robot
>>> for ent in Objects.Entities:
print ent.Name


[Other Projects with this Console]
You can use the PythonWindow/PythonConsole classes as a "Drop in" debugging helper with your programs. You can inspect the entire state of your application using the window. If you want to insert an object into the interpreter, you can do this from your code:

pythonWindow.Console.Scope.SetVariable("foo", obj);

Where obj is an object of any type. You can load things from your applications using this code from within the console window:
# startup script for the PythonConsole plugin
import clr
import Mogre as Ogre

If you replace Mogre with the name of your assembly, you can load any public type out of it, and if that type has any singleton instances, you use that to get at the data in your application. If you do not expose data through public classes or singleton instances, you can just set a local variable (as above). See the functions on PythonWindow.Console.Scope and PythonWindow.Console.Engine for more things you can do with it, as well as the source to to see how I got the root object/SceneManager without needing to call "AddObject".

If there's interest I'll post a short how-to on embedding IronPython in your C# application.

[Setting Up the Demo]
The link above is only the source code to the project. To get it to run, download the source (use SVN->Export to do it). Load up the project and Add a Reference to your local Mogre install. Lastly, download the beta version of IronPython here (you want the 'bin' version). Unzip that somewhere and add a reference to IronPython.dll, Microsoft.Scripting.dll, and IronPython.Modules.dll.

This should be all that's required to get it to run.

Let me know what you think!


22-03-2008 01:58:04

heyy very nice... this would work very well like scripting language for Mogre project... also is a great language.. 2 for our tools