Page 1 of 5

Blender importer [WIP]

Posted: Sun Apr 03, 2005 5:01 pm
by haffax
Yesterday I started to work on a blender importer for mesh files.
Mesh import for a single submesh and UVs are working.

the imported robot.mesh:
Image

Edit: Permanent download address: http://cvs.sourceforge.net/viewcvs.py/* ... _import.py
or ogreaddons/blenderimporter in the ogre cvs.

Posted: Sun Apr 03, 2005 6:08 pm
by Clay
Awesome work. =)

Posted: Sun Apr 03, 2005 10:58 pm
by bana
Wow, I was unaware that this was even feasible but looks like its working great :) Can't wait to see/use it myself.

Posted: Sun Apr 03, 2005 11:19 pm
by haffax
Thanks. :)
I have a busy week ahead now, so I don't know if I have time for the importer. But next weekend I will have time and fix some minor things and then publish it.

Posted: Tue Apr 05, 2005 8:56 am
by spline
that looks great, nice work
:lol:

Posted: Sun Apr 10, 2005 1:35 am
by haffax
Ok. Got the first public release ready.

Image
Now working:
* multiple submeshes (triangle list)
* uvs
* materials (textures only)
* vertex colours

Meshes that I know to not work:
* Meshes having multiple texture coordinate sets
* Meshes using a shared vertex buffer
* Meshes with submeshes given as triangle strip or triangle fan

Neither of these points is any difficult, but I just didn't have time to add them and I don't have test meshes for these.
So if anyone is interested in these features being implemented, I'd be happy to receive test meshes. :D

Anyway here is the script [EDIT]Use the download link in the first post.[/EDIT]

Note there are two options inside the script:
* IMPORT_SCALE_FACTOR: this scales the mesh with the given factor, default is 0.1
* IMPORT_OGREXMLCONVERTER: this is the path to your copy of the OgreXMLConverter, if given and valid, you can import meshes directly instead of converting them beforehand to mesh.xml files

Just copy the script into your .blender/scripts directory and restart blender. You should now have the option to import ogre meshes under File->Import. The importer expects the material script(s) and all used textures to be in the same directory as your mesh.

This is still a very early version, so your mesh might not work. If it doesn't I'd like to receive error reports, best with your meshes, or hints on what your meshes include (like multiple submeshes, with some of them containing vertex colours others not and such). And make sure to copy the error messages in the blender console window.
Another point: I didn't test the script with linux/mac, so it might fail. Error reports or patches are very welcome. :)

Anyway just try it out and report back.

Edit: Forgot to mention, that you need Python 2.3.x for it to work. After installing python create an environment variable called PYTHON that contains the full path to your python.exe ("C:\python23\python.exe" for the default installation destination).

Posted: Sun Apr 10, 2005 2:49 am
by RoundSparrow
Three cheers! keep it up!

Having Blender as a free option for people to tweak Ogre meshes is a very important thing!

Posted: Sun Apr 10, 2005 6:55 pm
by spline
this is great any chance you can explane how to set up a environment variable,thanx, keep up the great work :lol:

Posted: Sun Apr 10, 2005 7:03 pm
by haffax
To set up an environment variable on WindowsXP right click on the "My Computer" icon on the desktop, choose Properties. In the dialog choose the tab "Extended" and here the button "environment". Under "system variables" click the "new" button and type PYTHON for the name and the path to and including the python.exe as value. Leave all the dialogs with the ok buttons. You have to restart Belnder for that to take effect.

I don't have an english Windows, so I don't know if the names are correct, they are just guesses.

Posted: Mon Apr 11, 2005 4:40 pm
by haffax
Small update: some bugfixes and graceful handling of missing textures or materials.

with the bugfixes even my biggest testmesh with over 50 distinct textures loaded just fine: http://team-pantheon.de/~haffax/ruchin.jpg :)

download URL see first post.

Posted: Wed Apr 13, 2005 11:42 am
by StaticVoid
Using blender 2.36, linux, latest importer & robot.mesh.xml. PC locks up when rendering imported model. I know the answer is probably don't render (as I don't really need to), but I thought it may be some indication of a problem with the imported model.

Posted: Wed Apr 13, 2005 11:52 am
by haffax
Rendering is indeed not supported right now, because I don't create any render materials right now. Last time I tested rendering was before I made the imported mesh a scene object. At that time the model was rendered, but without proper material. I'll have look at it this evening, because a lock-up should never happen here. That said, I can only test on Windows right now.

Posted: Wed Apr 13, 2005 7:05 pm
by haffax
StaticVoid, I cannot reproduce your problem. I was able to render models just fine with the build-in renderer and with yafray. But as said without texture atm, because the script doesn't create a render material.

Posted: Fri May 06, 2005 5:26 pm
by P
Nice work Tanis !

Did you plan to work on importing shared vertex buffer ? I need it so if you are not working on it I ll try :)

Thank you for this nice tool !

Posted: Fri May 06, 2005 8:35 pm
by haffax
Thanks :)
P, give me a mesh with shared vertices to test, and I'll gladly do it. (Preferably with texture(s))

Posted: Sat May 07, 2005 2:53 am
by P
I'll make and texture a quick mesh using several submeshes (probably 2) and several uv for them

I ll send you that tomorrow

Thank you :)

Posted: Sat May 07, 2005 1:47 pm
by alphageek
Blender rules. Nice one.

Posted: Mon May 09, 2005 9:45 am
by P
@ Tanis : sorry i m 2 days later but here is the mesh i had promised to model :

lost fountain

*textures, .mesh, .xml & .material included

I made it quickly but i tried to use all that can make the importer fail
:lol:

It s a FFEEFMG model (Free For Everybody Except For Microsoft Guys) so feel free to do what you want with, althought i doubt something can be done with it..

Good luck on the importer ( luck ? )

Posted: Mon May 09, 2005 10:35 am
by haffax
Thank you, P. This will proove very helpful. I will do it later this week. Maybe Thursday.

I don't know if this is a question of luck, though. Good speed! is the phrase, iirc. :)
Edit:(But LEO probably botched the translation, as good speed sounds stupid)

Posted: Mon May 09, 2005 10:57 am
by P
i only meant luck is almost not involved into coding, i tried luck with cooking too but it s not working such as expected

Good coding ? maybe just simple as that !

Posted: Wed May 11, 2005 11:59 pm
by haffax
I just released a new version. The download link is shown in the first post of this thread. Tomorrow I will upload the script to ogreaddons/blenderimport in the Ogre CVS.

This new version now imports shared vertices and can handle meshes with multiple texture coordinate sets, but only the first set will be used, since Blender only supports one uv set.

I decided to gradually implement import of all features Blender and Ogre support. Namely skeleton and animations. It will take time though, since I cannot invest too much time in this project right now.

As always please report bugs/problems/suggestion about the importer in this thread.

Posted: Fri May 13, 2005 12:03 am
by haffax
The script is now part of the ogreaddons. It can be found under ogreaddons/blenderimport

Or directly using the sf checkout script from here: http://cvs.sourceforge.net/viewcvs.py/* ... _import.py

Posted: Sun May 29, 2005 5:05 am
by discipline
Haffax, I think it's great that you created this. I would definitely like to see it import animation as well.

I'm having trouble importing materials. I'm running under linux, with blender 2.36.

I copied ninja.*, Example.material, nskingr.jpg, robot.* and r2skin.jpg to a single directory.
Next, I import the mesh which loads just fine, minus the texture.
Browsing through your script, I added in some print lines and here's what I found out:
- The '\\' character doesn't work for linux as a path separator. You use it twice on lines 323 and 336. Changing this to '/' allows the following to happen.
- After doing the above, and inserting some print lines in collect_materials, I see it processes each material file and does find the "Example/Ninja" material.
- In CreateBlenderMesh in the transfer faces section material.getTexture() is successful.
- getTexture successfully loads nskingr.jpg on the first call, and does not on the second call (having already loaded it).

After this point, it gets into blender specific code that I didn't trace. After changing the path character it looks like the texture is loaded. However browsing through my blender interface, I don't see any textures in there, nothing was put on the ninja and only a grey untextured figure is rendered. Same thing with the robot, texture loads, but doesn't appear in blender. I get no errors from the script or interface.

Code: Select all

...
Material: /home/cory/devl/3d/blender/Example.material: Material #9
Texture: LEGS.jpg
Material: /home/cory/devl/3d/blender/Example.material: Examples/Fish
Texture: steelhead.png
Material: /home/cory/devl/3d/blender/Example.material: Examples/Ninja
Texture: nskingr.jpg
Material: /home/cory/devl/3d/blender/Example.material: Examples/Robot
Texture: r2skin.jpg
Material: /home/cory/devl/3d/blender/Example.material: Examples/GrassFloor
Texture: grass_1024.jpg
Material: /home/cory/devl/3d/blender/Example.material: Examples/GrassBlades
Texture: gras_02.png
Material: /home/cory/devl/3d/blender/Example.material: Examples/Rockwall
Texture: rockwall.tga
Material: /home/cory/devl/3d/blender/gingerbread.material: Gingerbread
Mesh with 0 vertices.
CreateBlenderMesh: Submesh material: Examples/Robot
CreateBlenderMesh: matched material
Submesh 0 with 295 vertices and 308 faces...
getTexture: Opening file: /home/cory/devl/3d/blender/r2skin.jpg
done.

Posted: Sun May 29, 2005 11:57 am
by haffax
Hello discipline, thank you for the feedback.
Your proposed changes concerning the path seperator are already done on my local copy. Works fine under Windows too this way.

As for the texture, I just tried the Ninja mesh and it gets textured for me in the 3D View. I am working on the Material import (too little time lately :( )
Currently no render material is created, this is why the rendering output is grey and there is no mentioning of the texture in other places. I'm almost done with this part here. So expect a new version next week.

Aftwerwards I'll refactor a bit (much needed), put more logging output in and start skeleton import.

Posted: Mon May 30, 2005 8:46 am
by dermont
Haffax really appreciate the work that both you and reimpell are doing on the blender import/export side of things.

I'm attempting to use your script as a basis for importing an Ogre skeleton and animation(not very sucessfully).

Looking at your script I don't quite understand why we need to loop through and append vertices for each submesh that uses shared vertices in CreateBlenderMesh. Shouldn't this only be done once?.

I checked this using Monster's racingcircuit mesh, with the script as is and modified to only append vertices on the first submesh.

On select remove doubles (original 102,202 are removed) and a modified version (4533 vertices are removed).