Too much time loading vertex/faces

(Willington) #1

Hi

I have a 2 files first one contains the vertexes of a terrain model
the another one contains the faces of the model.

my problem is there are a lot of vertexes the model has aprox 170.000 and
340.000 faces so, i ran the code and took over 24 hours and didn’t terminate.

So i check with a small file and it works, maybe i’m doing it with the worst
technique, so here is my code
I appreciate any help !

--------BEGIN------------
import Blender
from Blender import *
Vector= Blender.Mathutils.Vector
print “inicio del programa”
f=open(“C:\WITO_TNM\programas\ riangle\ est.node”,“r”)
#leemos 1 primeras lineas para saltarlas

1 initial lines ignored

tmp=f.readline()

tmp=f.readline()

Make a new mesh and add the triangles into it

me= Blender.Mesh.New()
for line in f:
tmp=line
pts=tmp.split(" ")
vt=Vector(float(pts[1]),float(pts[2]),float(pts[3]))
me.verts.extend(vt)

#print tmp

f.close()
f=open(“C:\WITO_TNM\programas\ riangle\ est.ele”,“r”)

leemos 1 lineas para saltarlas

first line ignored

tmp=f.readline()
for line in f:
tmp=line
pts=tmp.split(" ")
print pts
pt=[0,0,0]
for x in range(0,pts.count(’’)):
pts.remove(’’)
pt[0]=int(pts[1])-1
pt[1]=int(pts[2])-1
pt[2]=int(pts[3])-1

#pt[3]=int(pts[4])

print pt
me.faces.extend([pt])

#print tmp

f.close()

ob= Blender.Object.New(‘Mesh’)
ob.link(me)
scn = Blender.Scene.GetCurrent()
scn.link(ob)
print ‘termino!’
Blender.Redraw()
-----------END------------------

0 Likes

(ideasman42) #2

you need to extend floats and faces with 2 calls to extend for maximum effieiency.

make a list of each then extend, or even faster, try list comprehension

This has been asked a few times too, so have a look through the old posts

0 Likes