Blender 2.5 Exporter

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Blender 2.5 Exporter

Post by Tony Richards » Sun Sep 05, 2010 6:22 pm

Hopefully lf3thn4d does not take offense, but I've started a complete rewrite of the exporters, targeting Blender 2.5x.

The main reason for the rewrite is due to the new Blender Python API. The main reason for pushing forward with it now as opposed to waiting for lf3thn4d is because I need it now. I'll roll with the punches as the Blender API changes.

Just a few minutes ago I made my first Mercurial commit to the BlendOGRE project on Google Code.

This first version is not production quality and I've only tested it against the default "cube" mesh. It exports static geometry but not uv maps.

Using Google Code and Mercurial, my hopes is that it can become a community project and others with more experience in the subject (lf3thn4d!) can help when they have time.

Feedback and suggestions are warmly welcome.
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

lucas92
Gnoblar
Posts: 10
Joined: Sat Aug 14, 2010 7:47 pm

Re: Blender 2.5 Exporter

Post by lucas92 » Mon Sep 06, 2010 12:37 am

I'm looking forward it. :)
0 x

User avatar
lf3thn4d
Orc
Posts: 478
Joined: Mon Apr 10, 2006 9:12 pm

Re: Blender 2.5 Exporter

Post by lf3thn4d » Mon Sep 06, 2010 6:21 pm

Awesome. I'm not offended in any means. I think this is a good move in all nature of a community driven project. We could bring it in as an official exporter if it's good or use some of your code when working on the official version. :) Either way, good effort. Will have a look into it when I have the time. My only reason for not starting right now is due to blender's iffy python script API status.
0 x

drr00t
Gnoblar
Posts: 6
Joined: Thu Apr 24, 2008 6:06 pm

Re: Blender 2.5 Exporter

Post by drr00t » Fri Sep 10, 2010 2:13 pm

Hi,

Would be nice have an exporter for Blender 2.5, but i think that start from begin is lot and hard work. What you think use or contribute to add support for Ogre on this exporter: http://code.google.com/p/tubras/ now irrb works very nice for Irrlicht.

Just my opnion.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Blender 2.5 Exporter

Post by jacmoe » Fri Sep 10, 2010 9:53 pm

I would very much prefer an in-house Blender exporter for Ogre.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4293
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: Blender 2.5 Exporter

Post by spacegaier » Sat Sep 11, 2010 12:09 am

jacmoe wrote:I would very much prefer an in-house Blender exporter for Ogre.
+1

Blender is one (if not the) most used tools in conjunction with Ogre. We need to have an own exporter, despite all the work that is connected with that.
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

ecoumans
Kobold
Posts: 39
Joined: Mon Sep 12, 2005 10:07 am
Location: San Francisco
Contact:

Re: Blender 2.5 Exporter

Post by ecoumans » Sat Sep 11, 2010 1:20 am

If you need any data from Blender 2.5, just take the .blend file and extract the data using the small and open source bParse C++ library (under the permissive Zlib license)

You can see its use as part of OgreKit, extracting scenes, lights, cameras, triangle meshes, UV coordinates, textures, skinned animation, physics information, logic bricks and so on.

If you haven't tried it yet, see http://code.google.com/p/gamekit/ or this Forum topic http://www.ogre3d.org/forums/viewtopic.php?f=11&t=54431, there are a few precompiled Windows demos, and complete source code that compiles for Windows, Linux, Mac OSX and iPhone.
Cheers,
Erwin
0 x

Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Re: Blender 2.5 Exporter

Post by Tony Richards » Sat Sep 11, 2010 3:22 pm

@Erwin - I had definitely considered using gamekit code. I played around with it for a bit, but our coding styles are radically different making it difficult for me to follow the code.

Another two factors came to play as well... I recently switched jobs and the new job is going to eventually require me to be a heavy hitter in Python, so I need the practice with Python. The other factor was that I needed to make some custom scripts for Blender to automate some things anyway, so I'm quickly learning a lot about the new bpy API.

Side note, I'm actually quite enjoying the new API.... anyway, I'm digging back into the code in a few minutes. I'll push some more changes sometime this weekend.
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Re: Blender 2.5 Exporter

Post by Tony Richards » Sat Sep 11, 2010 6:56 pm

Wow, that was a little easier than I expected.

texcoord elements are being exported now.

I've pushed the latest code to the Google Code hg repo.

For the most part, simple static meshes should export. If the mesh has multiple UV maps, all of them are exported.

As with last time, I'm only doing a cursory test, so quite likely there are bugs. Feel free to check it out since it might actually be useful.

Note: If you open / save a .blend with a newer version of Blender, make sure you keep a backup copy just in case you want to use it with an older version... the file format is not backwards compatible.
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
Contact:

Re: Blender 2.5 Exporter

Post by PolyVox » Sun Sep 12, 2010 12:17 am

Great, this looks useful! But how do I use it? I got the source from Mercurial and placed the 'ogreio' folder in 'Blender/2.53/Python/lib'. But this was only a guess. I started Blender and didn't see anything Ogre related in the export menu.

Sorry, I'm not that experienced with Blender...
0 x

Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Re: Blender 2.5 Exporter

Post by Tony Richards » Sun Sep 12, 2010 1:11 am

I'm not sure about Windows... on Linux I put it under blender/2.53/scripts/io/ogreio.
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
Contact:

Re: Blender 2.5 Exporter

Post by PolyVox » Sun Sep 12, 2010 9:24 am

Ah, ok, I think on Windows it doesn't go within 'Program Files' but within the users 'AppData' folder (on Win 7). So I've placed it in 'C:\Users\David\AppData\Roaming\Blender Foundation\Blender\2.53\scripts\io\ogreio', and when I run Blender it generates two additional files compiled Python files with a .pyc extention. So I think Blender is finding it but it's not showing up under File->Export. Is that where it is supposed to be, or is there some other way of acessing the functionality?
0 x

Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Re: Blender 2.5 Exporter

Post by Tony Richards » Sun Sep 12, 2010 3:40 pm

With the files in the correct location, you should get a new File -> Export -> OGRE XML Mesh (.mesh.xml) menu item.

Your setup sounds correct unless you have:

C:\Users\David\AppData\Roaming\Blender Foundation\Blender\2.53\scripts\io\ogreio\ogreio.

I'll setup a Windows VM with Blender and see what I can see.
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
Contact:

Re: Blender 2.5 Exporter

Post by PolyVox » Sun Sep 12, 2010 5:00 pm

Ok, actually I now notice there is some output in the Blender console wondow when I start it up (before I even do anything):

Image

Maybe that provides an insight into what's going wrong?
0 x

Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Re: Blender 2.5 Exporter

Post by Tony Richards » Sun Sep 12, 2010 5:03 pm

Ok, I figured it out...

bpyml isn't in the distribution but it is in Blender SVN.

I'm not using the official 2.53 release during development... in order to keep up with the changes as they happen, I'm using root trunk SVN of Blender.

If you export https://svn.blender.org/svnroot/bf-blen ... s/bpyml.py to Blender\2.53\scripts\modules that would fix it, except there's one other thing that broke between 2.53 and current trunk.

If you'll pull from hg again, I pushed a fix that should do the trick after you've gotten bpyml.py.

This type of problem is probably the reason lf3thn4d hasn't wanted to tackle this yet. :mrgreen:
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Re: Blender 2.5 Exporter

Post by Tony Richards » Sun Sep 12, 2010 6:54 pm

More changes pushed:

Added exception handling that outputs exceptions to the log file. This will help me debug if someone else is having a problem.
Fixed an exception that occurs if the mesh does not have a material assigned.
Added better version checking so that it works in 2.53.0 as well as 2.53.1.

Now, for a bit of programmer-art, here's a castle tower I've been working on in Blender:

Image

And here it is, exported and converted to .mesh and imported into Ogitor:

Image
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
Contact:

Re: Blender 2.5 Exporter

Post by PolyVox » Sun Sep 12, 2010 10:58 pm

Getting close! I now get the following output in the log:

Code: Select all

Exporting to C:\Users\David\Documents\startup.mesh.xml
Traceback (most recent call last):
  File "C:\Users\David\AppData\Roaming\Blender Foundation\Blender\2.53\scripts\io\ogreio\export_mesh.py", line 65, in execute
    self.writeMesh(filepath)
  File "C:\Users\David\AppData\Roaming\Blender Foundation\Blender\2.53\scripts\io\ogreio\export_mesh.py", line 242, in writeMesh
    faces_node, vertex_face_index = self.generateFacesNode(submesh)
  File "C:\Users\David\AppData\Roaming\Blender Foundation\Blender\2.53\scripts\io\ogreio\export_mesh.py", line 145, in generateFacesNode
    if len(face.vertices) == 3: #tri
AttributeError: 'MeshFace' object has no attribute 'vertices'
This is with the default startup scene (the cube) that Blender creates.
0 x

zaph34r
Gnoblar
Posts: 24
Joined: Mon Feb 22, 2010 4:56 pm
Location: Germany

Re: Blender 2.5 Exporter

Post by zaph34r » Mon Sep 13, 2010 12:55 pm

I wrote a mesh exporter myself yesterday for 2.5.3 (as i didn't see that one was already available in this thread, should look a bit more next time :lol: of course i find it right after i finished a few hours of coding and debugging ..)

I'll post the code, if someone wants to use it, or just take it apart and use it for the one in this thread, or whatever.

Things to note:
- This version only works by pasting it in the editor in blender, and use Run Script, i just couldn't get it to be recognized as an Addon, even if i directly copypasted the relevant parts from the API reference, or other (working) addons :?
- Exports as .mesh.xml (have to convert for yourself to .mesh, haven't integrated that yet because i use a batch script to do that anyways)
- material names are exported as-is from blender (so if a face has material "foo" assigned, it will look for a material named "foo" in ogre, had some weird stuff with /SOLID/TEX/Untitled being appended with the 2.49 exporter, didn't play nice with my dynamically generated materials. probably something with the textures, im no blender expert, and i abhor the 2.49 interface so i corrected that with my batch converter script :? )

Code: Select all

# Preliminary Blender2.5.3 Ogre .mesh.xml export script v0.1 by zaph34r
# licensed under the YCDWYWWI license (You Can Do Whatever You Want With It)

# usage: paste to blender text editor, select some object, Run Script

# exports mesh data of currently selected object to OUTPUT_PATH/objectname.mesh.xml
# exports assigned materials as named in blender to separate submeshes
# exports first uv set
# should correct scale issues if scale is not applied to object in blender, but better use Apply Visual Transform in blender to make sure
# maps coordinates to ogre coordinate system (blender > ogre: x > x, y > -z, z > y)

import bpy

SHADING = "flat" # "smooth" uses vertex normals instead of face normals, still duplicates verts for corners though
OUTPUT_PATH = "yourpath"

class OgreVector(object):
    def __init__(self, bVector):
        self.x = bVector.x
        self.y = bVector.z
        self.z = -bVector.y

    def scale(self,scale):
        self.x *= scale.x
        self.y *= scale.z
        self.z *= scale.y

    def __eq__(self,other):
        return self.x == other.x and self.y == other.y and self.z == other.z

    def __neq__(self,other):
        return not self.__eq__(other)
    def __repr__(self):
        return "Vector({0.x},{0.y},{0.z}".format(self)

class OgreFace(object):
    def __init__(self, verts,normal,uvFace):
        self.verts = [v for v in verts]
        self.normal = normal
        self.uvs = uvFace
        if not type(normal) == OgreVector:
            self.normal = OgreVector(normal)
    def triangulate(self):
        v1,v2,v3,v4 = self.verts
        uv1,uv2,uv3,uv4 = self.uvs
        return [OgreFace([v1,v2,v3],self.normal,[uv1,uv2,uv3]),OgreFace([v1,v3,v4],self.normal,[uv1,uv3,uv4])]
    def __repr__(self):
        return repr(self.verts)

class OgreVertex(object):
    def __init__(self,bVertex, uvs, scale):
        self.pos = OgreVector(bVertex.co)
        self.normal = OgreVector(bVertex.normal)
        self.pos.scale(scale)
        self.u = uvs[0]
        self.v = uvs[1]

    def __eq__(self, other):
        if type(other) == OgreVertex:
            return self.pos == other.pos and self.normal == other.normal and self.u == other.u and self.v == other.v
        else:
            raise TypeError

    def __neq__(self,other):
        return not self.__eq__(other)

    def __repr__(self):
        return "Vertex > "+self.pos.__repr__()

def exportMeshData():
    filepath = OUTPUT_PATH
    xml = MeshXMLWriter()

    obj = bpy.context.active_object
    vertices = obj.data.verts
    faces = obj.data.faces
    uvs = obj.data.active_uv_texture.data

    subMeshData = {}
    for face,uvFace in zip(faces,uvs):
        mat = obj.material_slots[face.material_index].name
        uvFace = [uvFace.uv1,uvFace.uv2,uvFace.uv3,uvFace.uv4]
        if mat not in subMeshData:
            subMeshData[mat] = []
        if len(face.verts) == 3:
            subMeshData[mat].append(OgreFace(face.verts,face.normal,uvFace))
        elif len(face.verts) == 4:
            subMeshData[mat].extend(OgreFace(face.verts,face.normal,uvFace).triangulate())

    submeshes = {}
    for material,submesh in subMeshData.items():
        vertexIndex = 0
        submeshes[material] = {"vertices":[],"faces":submesh}
        for face in submesh:
            newFaceVerts = []
            for index in face.verts:
                vertex = OgreVertex(vertices[index],face.uvs[face.verts.index(index)],obj.scale)
                if SHADING != "smooth":
                    vertex.normal = OgreVector(face.normal)
                if vertex in submeshes[material]["vertices"]:
                    newFaceVerts.append(submeshes[material]["vertices"].index(vertex))
                else:
                    submeshes[material]["vertices"].append(vertex)
                    newFaceVerts.append(vertexIndex)
                    vertexIndex += 1
            face.verts = newFaceVerts

    xml.buffer("<mesh>")
    xml.buffer("<submeshes>",1)
    for material,submesh in submeshes.items():
        xml.buffer('<submesh material="{0}" usesharedvertices="false">'.format(material), 2)
        xml.buffer('<faces count="{0}">'.format(len(submesh["faces"])),3)
        for face in submesh["faces"]:
            xml.buffer('<face v1="{0.verts[0]}" v2="{0.verts[1]}" v3="{0.verts[2]}"/>'.format(face),4)
        xml.buffer('</faces>',3)
        xml.buffer('<geometry vertexcount="{0}">'.format(len(submesh["vertices"])),3)
        xml.buffer('<vertexbuffer positions="true" normals="true" texture_coords="1">',4)
        for vertex in submesh["vertices"]:
            xml.buffer('<vertex>',5)
            xml.buffer('<position x="{0.pos.x:.6f}" y="{0.pos.y:.6f}" z="{0.pos.z:.6f}"/>'.format(vertex),6)
            xml.buffer('<normal x="{0.normal.x:.6f}" y="{0.normal.y:.6f}" z="{0.normal.z:.6f}"/>'.format(vertex),6)
            xml.buffer('<texcoord u="{0.u}" v="{0.v}"/>'.format(vertex),6)
            xml.buffer('</vertex>',5)
        xml.buffer("</vertexbuffer>",4)
        xml.buffer('</geometry>',3)
        xml.buffer('</submesh>',2)
    xml.buffer("</submeshes>",1)
    xml.buffer("</mesh>")
    filepath.rstrip(".mesh.xml")
    filepath = filepath+obj.name
    filepath += ".mesh.xml"
    xml.write(filepath)

class MeshXMLWriter(object):
    def __init__(self):
        self.textbuffer = []
        self.indendations = []
    def buffer(self, text, indendationLevel = 0):
        self.textbuffer.append(str(text))
        self.indendations.append(indendationLevel)
    def write(self, filename):
        f = open(filename,"w")
        for i in range(len(self.textbuffer)):
            f.write(self.indendations[i]*"\t"+self.textbuffer[i]+"\n")
        f.close()

exportMeshData()
I just want to add that in no way i want to usurp the thread, or say my exporter is teh shiznit, haven't looked at the one from here yet (due to being fatigued by making my own atm).
Just thought if i made it, i might as well share it, for the chance that someone has some use for it

PS: here, have some of what i did with it too:
Image
yay for random dungeons :)
0 x

User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
Contact:

Re: Blender 2.5 Exporter

Post by PolyVox » Mon Sep 13, 2010 10:49 pm

zaph34r wrote:I wrote a mesh exporter myself yesterday for 2.5.3 (as i didn't see that one was already available in this thread, should look a bit more next time :lol: of course i find it right after i finished a few hours of coding and debugging ..)
Hi, thanks for your efforts but actually I didn't get this one to work either...

Image

Any ideas?
0 x

User avatar
Kentamanos
Minaton
Posts: 980
Joined: Sat Aug 07, 2004 12:08 am
Location: Dallas, TX

Re: Blender 2.5 Exporter

Post by Kentamanos » Mon Sep 13, 2010 11:33 pm

I just copied his code from the above code block into notepad and for some reason, all of it is indented (which indicates scope change in Python). I recommend pasting it into something like Notepad++, selecting all of it and unindenting it.
0 x

zaph34r
Gnoblar
Posts: 24
Joined: Mon Feb 22, 2010 4:56 pm
Location: Germany

Re: Blender 2.5 Exporter

Post by zaph34r » Tue Sep 14, 2010 9:25 am

i had that problem sometimes too with codeblocks in phpBB based forums.
the above mentioned "unindent all" often fucks things up even more, especially from some python boards (handy isn't it?), because after unindenting everything the stuff that should be indented is indented too little (python needs 4 spaces per indendation level, some code tags in some boards often indent everything just one to three spaces when you copypaste)

EDIT: just checked, in this case it should work, at least for me when i click SELECT ALL at the code block it indents everything 4 spaces, so if you unindent 4 spaces it should work just fine

just a second, ill upload it in a txt file

http://www.behindthemirrors.com/files/g ... export.txt
0 x

Tony Richards
Halfling
Posts: 86
Joined: Mon Nov 10, 2008 9:32 pm
Location: New York, NY, USA
Contact:

Re: Blender 2.5 Exporter

Post by Tony Richards » Sat Sep 18, 2010 3:24 pm

Blender 2.54 Beta was released Sept 11. Since this is finally "Beta" and the Python API is starting to settle down, I'm going to target that as my officially supported release.

I've not tested it on Windows yet. I'll do that now and once I'm sure it's working with 2.54 I'll push the updates and make a post here.
0 x
Image IndieZen.org - Open source game development tools, game engine, and MMO frameworks

SRombauts
Kobold
Posts: 39
Joined: Mon Feb 28, 2011 6:58 pm
Location: Paris, France
Contact:

Re: Blender 2.5 Exporter

Post by SRombauts » Fri Mar 11, 2011 6:46 pm

Hi,

I am a newcomer to OGRE : I've only played a while with some (great) tutorials from the wiki.

So now I would like to learn to use Blender with OGRE :
but it seams that learning Blender 2.49 is not a good idea anymore, as Blender 2.5 is now officially recommended for beginners (at least in Blender Video Tutorials).

So my question is :
Is the this new script blendogre (https://code.google.com/p/blendogre/) is stable enough ?

Are you guys planing to maintain it ? And what for animations in mesh ? Any timeline ?

Regards,
SRombauts

ps: I think I will try it anyway, and give you some feedback... but I do not have much time before a while !
0 x
http://www.srombauts.fr, comments from an Android developer

SRombauts
Kobold
Posts: 39
Joined: Mon Feb 28, 2011 6:58 pm
Location: Paris, France
Contact:

Re: Blender 2.5 Exporter

Post by SRombauts » Fri Mar 18, 2011 12:55 pm

Hi,

In fact there is another quite good Blender 2.5 Plugin exporter for Ogre in development mentioned in this topic :
http://www.ogre3d.org/forums/viewtopic.php?f=4&t=61485

I will follow it closely and try to help !

Regards,
SRombauts
0 x
http://www.srombauts.fr, comments from an Android developer

User avatar
LiMuBei
Goblin
Posts: 297
Joined: Mon Jun 09, 2008 3:56 pm
Location: Karlsruhe, Germany

Re: Blender 2.5 Exporter

Post by LiMuBei » Thu Oct 13, 2011 8:59 pm

Check out the one SRombauts pointed out. Works for animations!
0 x

Post Reply