Highspeed wavefront

Hi !

I use blender 2 weeks now. A very fascinating project ! After playing a little bit using the online tutorials I’ve tried to make an outdoor scene. Google helps me to find an interesting project to create trees and plants, arbaro (http://arbaro.sourceforge.net/). It can export to pov, dxf and wavefront obj. When I tried to import a huge tree (>5mb) from a wavefront file, blender doens’t response. Searching this board let me find out that blender does not crash but it took a very long time to import such huge files. This morning I import a 18mb tree on a 2.6GHz P4, ~20min. This was and is very painful. Thats why I started learinng python this morning, use some code from other plugs and voila, here’s my first python script, it imports the same file in 40-120 seconds depending on the visibility of blender. When blender lies in the background it took much fewer time, perhaps the screen update is the bootleneck. The most time the script is working on mod_meshtools.create_mesh(). I name this script ‘highspeed wavefront’, because:

  1. to prevent conflicts with the original wavefront importer
  2. it’s not designed to be stable or complete, but to be fast (remember: last night I was not familar with python :-))

If anybody need this script, take this ->


#!BPY

"""
Name: 'Highspeed Wavefront (*.obj)'
Blender: 236
Group: 'Import'
"""

__author__ = "Thomas Hoppe (hobBIT)"
__url__ = ("blender", "elysiun")
__version__ = "0.1 alpha"

__bpydoc__ = """\
Use and enjoy :-)
"""

import Blender, mod_meshtools, time, sys

def export(verts, faces, name):
    if len(name):
        print("
parsing " + name + " done, sort mesh")
        f = []
        v = []
        n = 0
        for i in faces:
            num = i[0]
            v.append(verts[num-1])
            num = i[1]
            v.append(verts[num-1])
            num = i[2]
            v.append(verts[num-1])
            f.append([n, n+1, n+2])
            n = n + 3
           
        print("verts: " + str(len(v)) + "
faces: " + str(len(f)))
        print("build mesh ...")
        mod_meshtools.create_mesh(v, f, name)
        print("done")

def parse(fname):
    start = time.clock()
    vc = 0
    fc = 0
    oc = 0
    verts = []
    faces = []
    name = ""
    f = open(fname, "r")
    for l in f.readlines():
        s = l.split()
        if len(s):
            if s[0] == "v":
                verts.append([float(s[1]), float(s[2]), float(s[3])]);
                vc = vc + 1
                if 0 == (vc % 10000):
                    sys.stdout.write(".")
            elif s[0] == "f":
                faces.append([int(s[1]), int(s[2]), int(s[3])]);
                fc = fc + 1
                if 0 == (fc % 10000):
                    sys.stdout.write(".")
            elif s[0] == "g":
                export(verts, faces, name)
                faces = []
                print("
import: " + s[1])
                name = s[1]
                oc = oc + 1
            elif s[0] == "s":
                pass
            else:
                print("ignore line: " + l)

    export(verts, faces, name)
    f.close()

    print("-- stats --")
    print("objects: " + str(oc))
    print("vertices: " + str(vc))
    print("faces: " + str(fc))
    print("whole import time " + str(time.clock() - start) + " seconds")

def fs_callback(filename):
	parse(filename)

Blender.Window.FileSelector(fs_callback, "Import Wavefront")

http://jmsoler.free.fr/util/blenderfile/py/obj_io_modif236a.py
This one reads 16 mos in 40 seconds .