Blender to Python-ogre Tutorial available ?

BerndWill

05-02-2007 18:00:27

Hello all you fine python-ogre people here,

could anyone please provide me with a Blender example .blend file and a corresponding python-ogre application ?

What I want to learn is, how to create scenes with textured objects and lights and cameras and how to transfer all that stuff into a python-ogre application and how to name/group and access those objects.

Another nice tutorial would be explaining how to create bones and animations and how to move them over from blender to python-ogre.

Any help is very welcome !

Regards
Bernd

bharling

06-02-2007 00:11:50

well, in brief .. :) ..

look around the main ogre site for blender .scene and .mesh exporters (i think they are in the tools section, try googling if not). those utils will export .xml files, you will also need the ogre command line tools to convert the xml into binary .mesh files. Look at the blender mesh export script for details of how to set this up automatically.

the post with a scene importer is here:
scene importer

you need to export the .scene file, and each mesh individually ( personally i prefer to just do the meshes, and do the scene creation through python, which allows more control over when objects are spawned etc.). You'll have to UV-map your blender meshes to get textures to appear, if you do that, the exporter will create material files automatically for you, although you may have to edit by hand a bit (use notepad). The script will also export armature animations to a skeleton file, which also needs converting from xml to binary. you do not need to convert the .scene file from xml, it will work straight after export from blender.

theres a post in this forum with a link to a good .scene import script for pyogre, which will load the locations of your meshes into pyogre from your .scene file.

once all that is done, make sure your resources.cfg is set up correctly to match the folders of meshes / materials / textures you have created (Of course, make sure to copy your texture images into the right folder). Then refer to some of the example files to find out how to load them into your game.

basically, you dont need to do anything special with your models whilst building them in blender, just make sure you export properly. Currently there is no 'one-click' process to export an entire blender scene into ogre. If you want that, wait around for blender-ogre (which is some time off, but looks very promising).

Couple of tips: you will probably have to rotate your entities (in python-ogre) to get them facing the right way when exported from blender. Or alternatively, you could rotate them before exporting if they seem wrong in-game (remember CTRL-A -> apply size and rotation).

you must create a hierarchy in python-ogre to correctly create your game characters ie: mesh -> entity -> sceneNode. the sceneNode is the bit you'll usually be moving around with python. again check the examples or the wiki for this. its easy if you abstract some sort of loading routine, which will load any mesh and return a new sceneNode for it. the scene loader script can also take care of this for you.

also, beware of centering your models, ogre will completely disregard the model's origin point in blender, and just create the model from its geometric centre, so you will quite likely end up with models sunk into the floor. just adjust the entity position in python to fix this, then attach the adjusted entity to a sceneNode to move it around.

It probably will not work out first time, but stay with it. I have sucessfully exported tons of meshes into my pyogre game now, including animations, and it works fine with a little tweaking. The benefits over the blender game engine are too many to count here, but suffice to say, ogre is a lot more powerful than BGE.


hmm.. maybe that wasn't so brief. But you can't really illustrate the process with just a blend file and a python-ogre game, they are two quite different beasts!

A good practice i have found is to divide your project into 'source' and 'release' folders. put all your python scripts, dlls, configs and blender files in the source folder, and all your meshes / textures / sounds in the release folders. if you sort out your .cfg files properly (ie: use ..\release\models etc.), you will have no problems when compiling your project to exe.

hope thats of some help. Its easy when you have done it once. feel free to ask any questions, this is a nice friendly forum. :D

saluk

07-02-2007 09:41:08

Yeah, I couldn't get vertex colors to work with the latest blender exporter, so for my project I'm using a slightly modified version of the older exporter. It works like a charm with textures, alpha textures, vertex colors, lighting, etc. I had to add a few lines to the material export section for it to work right.

Another annoying thing is that the exporter doesn't have any knowledge of paths, so you're either browsing paths endlessly, or you just export everything to one big folder. Well I didn't like the big folder idea, so I made a content folder thats nice and organized. I wrote a simple section of code that runs before the client starts that browses through the blender directories, runs ogrexmlconvert on any xml files it finds, and copies all files to the content (release) folders. Also, I parse all material scripts (which the blender ogre exporter always names export.material) and export new material scripts in the release section with filenames based on the material names. This lets me do things like exporting only one object and not clobbering all the previous exported materials, or change a material in one file and export it to overwrite something specifically.

Lastly, there is the scene node business. I'm NOT a fan of xml, and I had to have more control over which objects were added where. So I wrote my own scenegraph exporter that only exports top-level scene graphs. Any object that is not parented to anything will be exported to a file along with all of its children. So I can easily export a complex character with various joints etc. If I needed to export an entire scene (which I wont, I do all of my scene creation in-game) I could simply parent the entire scene to an empty. The file cleaner code that I mentioned in the previous paragraph also takes care of these scenegraph files.

So, what I do in the game, is load the scenegraph files, create scenenodes that correspond to each blender object (whether it's an empty or a mesh etc); and load and attach the proper entities where necesary. It's a bit tricky because the order is important, so I sort the scenegraph into a tree first.

Animation and collisions are recent additions to my pipeline.

It all ends up, after quite a bit of hard work, being an extremely smooth pipeline. My artist can open any of our many, organized, blend files, add a new object or modify an old one, press alt-p in the script window, and it's ready to go in the game. Which is where the actual scenes are created (that's a whole different subject entirely)

If you just want to take a blender scene and pop it in real fast, use the dotScene exporter :)

BerndWill

07-02-2007 19:01:53

Thank you very much for your help !

Are there any limits to respect, when transfering models from blender to pyogre ?

I mean, are all texture features supported in pyogre, all boolean intersection functions etc. supported ? Or do you use blender to make point by point meshes and apply textures with OgreStudio or other stuff ? (Just use blender for doing the meshes or do you add textures and animations as well !?)

What about all that "shader" functionality available at Blender and Ogre. Am I right by saying, shaders in blender and ogre are two different things, which means, just do the mesh modeling in blender, export and rearrange shaders and textures using python ? So blender is just a "nice mesh and scene modeler" then !?

Can any mesh model be transfered or does the OgreExporter leave out some blender functionality ?

Regards
Bernd

bharling

07-02-2007 20:17:36

Are there any limits to respect, when transfering models from blender to pyogre ?

I mean, are all texture features supported in pyogre, all boolean intersection functions etc. supported ? Or do you use blender to make point by point meshes and apply textures with OgreStudio or other stuff ? (Just use blender for doing the meshes or do you add textures and animations as well !?)


No, you can texture your models completely in blender, I think the main thing (if you want to have them appear the same in ogre as in blender) is to make sure you have a UV-map applied to your model as well as the texture. Simpler mapping like cubic or spherical may work, but is not as predictable.

Booleans (or any other modifiers) are not supported. You will have to Apply all your modifiers before you export your mesh. I would save your blend file first then apply the modifiers then export, so that you can go back if need be. Always keep backups as well :)

What about all that "shader" functionality available at Blender and Ogre. Am I right by saying, shaders in blender and ogre are two different things, which means, just do the mesh modeling in blender, export and rearrange shaders and textures using python ? So blender is just a "nice mesh and scene modeler" then !?

I am not 100% sure about this yet. I have tried exporting models with blender materials rather than textures applied, and the exporter does make a material file for it, which contains things like the colour, specularity, transparency etc.. but things like 'noise' textures will not export into ogre. If you are talking about shader scripts (such as HLSL, GLSL etc.), then yes, Ogre will support these scripts, the same as blender does (shaders are independant of which program is rendering them .. most of the time).

Can any mesh model be transfered or does the OgreExporter leave out some blender functionality ?

yes, any mesh model can be transferred, which includes bones and some animations. However, it will not transfer things like logic bricks or physics settings, you will have to re-create all that in ogre. To put it simply, Blender can create the content (models and textures) for your game, but you must create the game itself in Ogre.

BerndWill

07-02-2007 22:17:05

I have been playing around with the BlenderGameEngine a while ago and IMHO it is an embedded "interactive animation add on", but no game engine. Though it is a very nice prototyping tool, the borders of the BGE functionality are showing up real soon.

Regards
Bernd

saluk

08-02-2007 04:06:47

Yep, this is true. I was able to get very far with my project in BGE, but I don't regret switching to Ogre!

BerndWill

08-02-2007 07:53:05

How do you guys staff your scenes ?

A) entities, scenes, blend files
----------------------------------
Am I right by saying, that every entity which you want to control seperately inside the game, will get its own scene in blender ?
So you come up with a blender file containing several scenes each having its discret entity ?

B) Cameras and Lights
----------------------------------
Another question is: Are you positioning cameras and lights inside the scene or do you design and position them seperately within the python game source ?

C) Particle effects
----------------------------------
Are you using any effects from blender or do you use one of the ogre particle generators instead ?

D) Overlays
----------------------------------
How do you get your GUI overlay assets (pictures) into the game source ? Do you create "helper" objects (cubes etc.) and use those overlay pics as textures for them ... or do you have another technique ?
Is it possible to put a flash movie as an overlay over the ogre 3d view ?

Thanks again for your interesting posts !

Regards
Bernd

saluk

08-02-2007 18:56:19

My scene exporter exports all top-level (unparented) objects along with their children as a seperate .sg file which only contains the mesh names and their relationships. So if there is a Blender scene with two characters and a room, the scenegraph files will look something like this:

#character1.sg

baseempty mesh=None
body mesh=char1body parent_to=baseempty position=...
head mesh=char1head parent_to=body position=...

#character2.sg

baseempty mesh=None
body mesh=char2body parent_to=baseempty position=...
head mesh=char2head parent_to=body position=...

#room1.sg

walls mesh=room1walls
staticfurniture mesh=room1static parent_to=walls position=...


So the SceneNodes get a name based on the object name, and they load an entity from a mesh file based on the mesh name. And all the scene nodes are parented accordint to their parenting relationships which were defined in blender.

This gives us flexibility in how and where we define our scenes. We have a furniture.blend that contains all of our furniture objects, a characters.blend that contains all of our characters, etc. We could also store things in seperate scenes within a .blend, but we like version control and it's much better to seperate in files. However for exporting, it's easiest if we can export many objects at once. But we could have everything in a single blend in a single scene in a single layer if we wanted to, and it would still split it up that way.

And this method also is able to handle both levels and game objects, as a level can just be all of the static geometry parented to an empty so it gets exported together. (Or if it can be static, joined into a single mesh as that will likely be more framerate efficient)

--------------------------
So far I have defined lighting and cameras in the python-ogre source, as it's kind of a set up once and forget sort of thing, rather than something that will be tweaked long into the project. An exporter for them would not be difficult to write, oand I think the dotScene exporter does support them. This would be a case where I might opt to use dotScene instead of my own, because it actually is setting up the initial scene, and I don't need to worry about dynamic objects.

I'm also not using particle effects or overlays, so I can't help you there. For all of the interface things I use CEGUI and the cegui layout editor to define my gui's. CEGUI is a pain to work with by the way, especially if you want to modify the look.
--------------------------------

Good luck with your explorations, if anyone is interested, I might clean up some of my export scripts and put them up, although there are probably some issues with them.

BerndWill

08-02-2007 20:57:05

Hi saluk,

what is the difference between your export script and the standard ogreExporter ? How do you export the meshes ? Do you export each of those meshes manually using ogreMeshExporter ?

By the way: Does anyone export camera and light positions with the dotScene exporter or do you all set this up in the python game source afterwards ?

( To learn from your experiences, it would be superb, if you could post your scripts somewhere ... e.g. wiki !? )

Regards
Bernd

saluk

08-02-2007 21:06:40

I'll put up some of my code sometime this weekend for you to look at. I am using a modified version of the older blender mesh exporter, the newer one confused me too much to modify it and I wasn't getting vertex colors. The only modifications I've done is to make it bypass the gui and just do the export on all selected objects, and some tweaks to the generated materials.

It basically simplifies it so instead of exporting the mesh, and then exporting the scenes, it does them both in one run. But the downside of course is it doesn't give you any access to the mesh exporters options, they're hard coded.