Hi all,
I’m rewritting some parts of my Blitz3D exporter… trying to make them much more cleaned for add new features…
But I’ve a problem with the exporting of faces and vertices…
Here’s the problem…for some reasons I need to write 2 separated “for” cycle trought the faces… in the first i read vertices for every face like that:
vrts_stack = []
for obj in Blender.Object.Get():
if obj.type == “Mesh”:
data = obj.getData()
for face in data.faces:
for vert in face.v:
if not vert.index in vrts_stack: #temp_buf += write_float(vert.co.x) #X here i write on file the vertex coords #temp_buf += write_float(vert.co.y) #Y #temp_buf += write_float(vert.co.z) #Z
print (vert.index)
vrts_stack.append(vert.index)
and the second cycle for write the face indexes of each meshes like that:
first_vert = 0
countvertices = 0
for obj in Blender.Object.Get():
if obj.type == “Mesh”:
data = obj.getData()
first_vert = first_vert + countvertices
countvertices = len(data.verts)
for face in data.faces:
facesize = len(face.v) #here i write on file the first 3 indexes of the face #temp_buf += write_int(first_vert + vrts_stack[face.v[0].index]) #A #temp_buf += write_int(first_vert + vrts_stack[face.v[1].index]) #B #temp_buf += write_int(first_vert + vrts_stack[face.v[2].index]) #C
print first_vert + vrts_stack[face.v[0].index],
print first_vert + vrts_stack[face.v[1].index],
print first_vert + vrts_stack[face.v[2].index]
if facesize == 4: #if face has 4 vertices i write on file the others 3 vertexes of face #temp_buf += write_int(first_vert + vrts_stack[face.v[0].index]) #A #temp_buf += write_int(first_vert + vrts_stack[face.v[2].index]) #B #temp_buf += write_int(first_vert + vrts_stack[face.v[3].index]) #C
print first_vert + vrts_stack[face.v[0].index],
print first_vert + vrts_stack[face.v[2].index],
print first_vert + vrts_stack[face.v[3].index]
But there’s a bug in this code… and I can’t understand why with a simple cube it’s work fine… and with a more complex model like “suzanne” it can’t link right the faces…
I hope that someone could help me in anyway… because I’m stucked here from about 3 day…
thanks all!
bye GaND
Yes BeBraw, it work only with triangles…
Sorry ideasman42… here is the tagged code for the first cycle for vertex index:
vrts_stack = []
for obj in Blender.Object.Get():
if obj.type == "Mesh":
data = obj.getData()
for face in data.faces:
for vert in face.v:
if not vert.index in vrts_stack:
#temp_buf += write_float(-vert.co.x) #X here i write on file the vertex coords
#temp_buf += write_float(vert.co.y) #Y
#temp_buf += write_float(vert.co.z) #Z
print (vert.index)
vrts_stack.append(vert.index)
and here the second cycle for face index:
first_vert = 0
countvertices = 0
for obj in Blender.Object.Get():
if obj.type == "Mesh":
data = obj.getData()
first_vert = first_vert + countvertices
countvertices = len(data.verts)
for face in data.faces:
facesize = len(face.v) #here i write on file the first 3 indexes of the face
#temp_buf += write_int(first_vert + vrts_stack[face.v[0].index]) #A
#temp_buf += write_int(first_vert + vrts_stack[face.v[1].index]) #B
#temp_buf += write_int(first_vert + vrts_stack[face.v[2].index]) #C
print first_vert + vrts_stack[face.v[0].index],
print first_vert + vrts_stack[face.v[1].index],
print first_vert + vrts_stack[face.v[2].index]
if facesize == 4: #if face has 4 vertices i write on file the others 3 vertexes of face
#temp_buf += write_int(first_vert + vrts_stack[face.v[0].index]) #A
#temp_buf += write_int(first_vert + vrts_stack[face.v[2].index]) #B
#temp_buf += write_int(first_vert + vrts_stack[face.v[3].index]) #C
print first_vert + vrts_stack[face.v[0].index],
print first_vert + vrts_stack[face.v[2].index],
print first_vert + vrts_stack[face.v[3].index]