Updated OBJ Import (20xSpeedup) - Twice as fast as JMS's

Hay all, In responce to JMS Being cocky about my OBJ import and export being slow I had a look and compared Both scripts.
Obj included in 2.37- Exporter is more then Twice as fast as JMS’s but Importer was 10 times slower. (ouch)

So I have optimized my importer which is about twice as fast Jms’s (20x speedup)

I wanted to do a more comprehensive benchmark but it turns out that JMS’s script cant load half the models in My test collection.

Anyhow, now both my scripts are around twice as fast, so there.

My script also handles missing images and too many materials without stopping.

http://members.iinet.net.au/~cpbarton/obj_import.py
http://members.iinet.net.au/~cpbarton/obj_export.py

  • Cam/Ideasman

In obj_import.py

Using Python version 2.3
file length: 13635
Traceback (most recent call last):
File “<string>”, line 546, in load_obj
File “<string>”, line 188, in load_mtl
File “<string>”, line 117, in load_mat_image
NameError: global name ‘mesh’ is not defined

Thanks,
Fixed it, silly typeo…

Would apretiate any further testing before 2.37a
Cam

While you’re at it, why not compare penis size too? :stuck_out_tongue:

I heard JMS say his is a full four inches bigger than yours.

In fact, on a zbrush’s file of 7 mos data completely smoothed with a 13 mos
bmp image the io_obj script (it is not my script, just a script that I find useful
and I work from time to time on it) makes its work in 9
seconds … but we have to assign the material to the mesh in the
index material .

The cambo’s one takes 7 seconds but there is no smoothing (no normal),
and no uvmapped images .

Almost…
But did you know- Blender does not use the NMesh Normals for display list for display or rendering. The only Thing I have found normals used for is Dupliverts and Im guessing Particle acceleration too. - Not display or rendering tho.

So aside from smoothing mine isnt loading the image, image links in OBJ are fairly vague (Win32 Pathnames/Absolute/Relitive/usemap tag or in MTL file) - So its probably just a parth reading issue. If you show me a file that dosent work then Ill fix it.
This bug is nothing compared to yours, which crashes on ALL OBJ’s from DEEP Exploration (www.righthemisphere.com) as well as some other files mine imports fine.

  • Though Ill give you smoothing, mine could do better smoothing. but blenders smoothing isnt crash hot either, and dosent allow for smoothing groups or edge based smoothing.

  • Cambo

Made 15% faster, Fixed pathname handling and added importing of smoothing groups!
Download from the same place.

  • Cam

Traceback (most recent call last):
File “Text”, line 609, in ?
WindowsError: [Errno 3] Le chemin d’accÞs spÚcifiÚ est introuvable: ‘/obj/.

No fileselector too.

Anyway, if i remove this two problems, the script always takes 7 seconds to load the 8 mos data of a Zbrush file . Same problems (no image, no smoothed faces )

Okay, commented out testing bit and re-uploaded, it uses the fileselector.

About smoothing, the default is to have smoothing off for my importer, but if you had smoothing groups it will smooth them. - I decieded to turn smoothing off by default becasue if sombody wanted there model smoothed they’s add it to a smoothing group.
If the user dosent like this then they can turn smoothing on from Blender no biggie.

About the ZBrush import error, All I can say is- show me the file. or at least the MTL. I have got some obj examples from ZBrush, but none of them were distributed with MTL files.

If your interested in Blender working for everyone, just give me a link to this file, its stupid to have Blender 2.37a’s scripts not work as well as it could, because you are too proud to show me a bug that only you have found.

  • Cambo

actually, I’ve seen it use them for display

there is a switch when you call to not have blender recalculate normals

Blender.NMesh.PutRaw(nmesh, name=None, recalculate_normals=1)
NMeshType.update(recalc_normals=0)

they are ignored for the render, and for conversion to the game engine, but they are not ignored in the 3d view
[which is silly]

oh, and entering and exiting edit mode will recalculate normals, being able to change them in python is pretty useless

Just to say that the current obj_import works well with this file but takes hours to display the results so a great number of users think blender is freezing and try the other one . Sorry, if you are offended but these are only facts .

Well, totally useless info I’m sure, but for those that may remember my very first texture plugin, the one that ‘faked’ refraction, before I made it a texture plugin, it was a actually python script.
You see, the way it worked was by modifying the mesh normals in such a way, so that when used with environment maps, when rendering the reflection vectors used for the environment map, they would be ‘warped’ into refraction vectors. It worked very well, despite hardly anyone knowing how to use the thing (with a few notable exceptions), also saw it being claimed that it could not possibly work without actually trying it…

[quote=“jms”]

Just to say that the current obj_import works well with this file but takes hours to display the results so a great number of users think blender is freezing and try the other one . Sorry, if you are offended but these are only facts .[/quote]

No offence :), but are you refering to the recent obj_importer or the one distributed with 2.37/2.36- This one was very slow- and thanks for pointing out how slow it was, else I wouldent have fixed it.

So since its fixed, All I have to do is make the more compatible. Not loading images is a tricky one, I have posted a while back, but It would be good to have a generic python module with functions that Allow the user to load an image with some fuzzy logic so writers of importer writers could spend less time fiddeling with cross platform paths.

Eg
FuzzyLoad(‘/fullpath/image_name.ext’, strip_path=1, case_sensitive=0, paths=[‘//’, ‘/some/path’, ‘any other path’], recursice=0, other_format=0, make_dummy=0)

This would allow you to give Blender a file to load, by default it would look first if the file exusts. if not, see if a different case exists.

  • strip the path from the file and add it to the paths to look in allong with the blend files // and ano other specified.

  • Recursice to scan nested paths for the file,

  • other_format- willtry for files with same name but different extension.

  • Make Dummy will create a 2x2 Pixel image of the desired name in the file path and then use it.

mabe make dummy and recursive are going too far, but I think it could be a good option, this would help a lot for linux users importing win32 based 3d formats, where pathnames are often case insensitive and absolute paths are used (3ds files for eg.)

I think I found teh bug you are refering to with ZBrush.
My importer was messing up on MTL image references with spaces in the name.

  • Fixed.

Optimized again another 15% in general…

I stand corrected about normals- Blender does display Normals in the 3ds view, as long as subserf is off, but since any editing will remove custom normals, I still dont think there worth importing.

I updated my importer for faster smoothing groups… See this model

http://graphics.im.ntu.edu.tw/~robin/courses/cg04/model/mba2.obj.gz
13 meg uncompressed OBJ with 1000’s of smoothing groups,
see
http://graphics.im.ntu.edu.tw/~robin/courses/cg04/model/

my importer took. : 5.89 sec

JMS’s took : 15.1 sec

Both import smoothing groups properly.
Updated at the same location.

  • Cam
#!BPY
 """
Name: 'Wavefront (.obj)...'
Blender: &gt;&gt;&gt; 232 &lt;&lt;&lt;
Group: 'Import'
Tooltip: 'Load a Wavefront OBJ File'
"""
Traceback (most recent call last):
  File "E:\zi^p\3DGRX\blender\blender-2.36\.blender\scripts\obj_import.py", line
 602, in load_obj

  File "E:\zi^p\3DGRX\blender\blender-2.36\.blender\scripts\obj_import.py", line
 199, in getUniqueName
    try:
AttributeError: 'module' object has no attribute 'GetNames'

and the 8 mos zbrush file is always read without uvmap . If i try to enter faceselect blender 2.37 fails with systeme error .

Jms, if you would give the the zbrush file I could solve the problem, you know my email.

Blender crashing with a system error is serious and could be a bug in BPython, therefore affecting other importing scripts and making blender less stable.

I added NMesh.GetNames() recently and its only in 2.37, your right though, I should update the blender version in the script to 2.37.

  • Cam

Fixed the bug in making bad Tex faces. as well as other optimizations with switching materials and face creation.

the model that took 5.89 sec now takes 5.26

This will be released with Blender 2.37a, but you can download at the link above.

BPy error: Callback call failed!
Traceback (most recent call last):
  File "E:\zi^p\3DGRX\blender\blender-2.37-windows\.blender\scripts\obj_import.p
y", line 286, in load_obj
    lIdx+=1
ValueError: invalid literal for float(): =
        file length: 211284
        found 0 smoothing groups.
obj import time:  6.42269717777