OBJ Export, need help please.

Hi, I’ve bee struggling with this for a while and haven’t found anything in the forum so far that helped.

I have a .obj model that needs to retain it’s structure once exported by Blender, but Blender is not exporting the way I want, although I have tried adjusting the settings for export, perhaps someone can help.

My model when opened in UVMapper has these stats :

vertices = 10309
textures = 10309
normals = 10309
facets = 16872
groups = 1
materials = 1
regions = 0

BUT when I load it into Blender (not changing anything) and try export it, I either lose or gain stats, which is no good for what i want. I need to retain the stats to create morphs.

The closest I get is (selecting UV’s,Material,Selection Only and Objects from the mesh export options)

vertices = 10309
textures = 8870
normals = 16711
facets = 16862
groups = 0
materials = 1
regions = 0

Can anyone see what the problem is at all, or am i missing doing something.

I need to meet these criteria for the exported mesh :

It should be a single triangle mesh.
It should have a single material for the entire mesh.
It should have one set of texture coordinates per vertex.
It should have a single normal per vertex.

Anyone know the settings to do that ?

Thanks for any help.

i also have a similar problem exporting obj’s (as well as a problem in keeping my quad topology).
I didn’t get any bites on my last two posts about it though :(, maybe this time. Can anyone help us out?

ps. if it doesn’t work out for u on the obj thing, i ended up using the collada export.

hey, I wrote obj i/o - Jiri did the MTL part

we really need a seperate project that supports people who want to use OBJ for morph targets etc.

My aim for obj suppot is that you can import ANY obj without errors, and for the exporter - that it creates a small neat file . - the goals conflict.
for maintaining face order you may have to switch materials a lot, whereas the exporter sorts faces by materials so it happens less.

  • there are other problems too

basicly people are using OBJ to store data order, thats fine but theres nothing in the OBJ format that says - “Keep order of data”

I have written an example obj import and export in a noobs guide to Blender python section that dosnt do any tricks t ochange order so that could be a good start for a new order maintaining obj i/o

Yep, I found for other things I use the exporter for it all works out fine. I need this to retain the structure of the model that goes into blender though.

Hmm whats the collada export surfmex ?

Is Python very different to Max Script ? I can figure Max Scipt ok, never looked at Python though…

If you have a link to that noob guide that would be a start.

Thanks for replies, I’ll post here if I get anywhere Surfmex, goodluck :slight_smile:

I created a morph target import and export for poser based on cambo’s noob’s example. It might work for what you want.

It’s part of the poserio package, you can find it here:

http://www.kuroyumes-developmentzone.com/~Cage/poserio/DAZPoserImportTutorial.html

Well I found an example exporter which I added code to export the ‘vn’ part but I am stuck on how to get it to output ‘vt’ using the uv bit…if you get me. Can any of you experts help me do that part ?

I think I got the ‘vn’ bit right, not sure take a look :

 
#!BPY
"""
Name: 'Wikibooks'
Blender: 237
Group: 'Export'
Tooltip: 'Wikibooks sample exporter'
"""
import Blender
def write_obj(filepath):
        out = file(filepath, 'w')
        scn = Blender.Scene.GetCurrent()
        object = scn.getActiveObject()
        mesh = object.getData()
        
        for vert in mesh.verts:
                out.write('v %f %f %f
' % (vert.co.x, vert.co.y, vert.co.z) )
       
        for vert in mesh.verts:
          out.write('vn %f %f %f
' % (vert.no.x, vert.no.y, vert.no.z) )
 
        for face in mesh.faces:
                out.write('f')
                
                for vert in face.v:
                        out.write( ' %i' % (vert.index + 1) )
                out.write('
')
        out.close()
Blender.Window.FileSelector(write_obj, "Export")


I thought the vt part would go something like this:

 for vert in mesh.faces:
          out.write('vt %f %f %f
' % (vert.uv.x, vert.uv.y, vert.uv.z) ) 

…but it errors. Sorry I am new to Python. Anyone ?

heres the link to collada:

http://colladablender.illusoft.com/downloads.html

it works well with 3ds max and other software. i only use it cuz it retains my quad-topology just right every time. it may be useful for what ur tryin to do as well.

–thanks for all the hard work cambo, ur programming hand is way strong!

UVs are 2 dimensional, there’s no x,y,z, there’s only u and v (that is x and y).

Try something like this, but note that this will store unwelded uvs:



for face in mesh.faces:
      for uvs in face.uv: # Collect uv's
          output.write('vt %f %f
' % (uvs[0],uvs[1]))


Damir

Thanks that seems to do the trick, It exports okay, I just need to do a bit more fiddling because it still isn’t exact, I think I will have to customise the import too. Collada looks good, but I really need .obj format, although I think thats going to come in useful so thanks :slight_smile:

Also thanks for the Poserio link - I use that a fair bit too, it looks useful.

Thanks for the help, I’ll post again if I come up with something amazing :wink: