You are on page 1of 7

import Blender

import bpy
sce = bpy.data.scenes.active
ob = sce.objects.active
mesh = ob.getData(mesh=1)
def write_obj(filepath):
out = file(filepath, 'w')

counter = 0;
data = "";
for f in mesh.faces:

for vert in f:
#data += str(vert.co.x)
#out.write( 'v %f %f %f\n' % (vert.co.x, vert.co.y, vert.co.z) )
out.write("CO["+str(counter)+"]=new Point3f("+str(vert.co.x)
+"f,"+str(vert.co.y)+"f,"+str(vert.co.z)+"f);\n");
counter +=1

for face in mesh.faces:


out.write('f')

for vert in face.v:


out.write( ' %i' % (vert.index + 1) )
out.write('\n')
out.close()

def write_verts(filepath):
out = file(filepath, 'w')

counter = 0;
data = "";
for vert in vList:
#data += str(vert.co.x)
#out.write( 'v %f %f %f\n' % (vert.co.x, vert.co.y, vert.co.z) )
out.write("CO["+str(counter)+"]=new Point3f("+str(vert.co.x)
+"f,"+str(vert.co.y)+"f,"+str(vert.co.z)+"f);\n");
counter +=1

out.close()

def write_cols(filepath):
out = file(filepath, 'w')

counter = 0;
data = "";
for col in vColList:

r = float(col[0]/100.00)
g = float(col[1]/100.00)
b = float(col[2]/100.00)
print r,":",col[0],":"
out.write("COL["+str(counter)+"]=new Color3f("+str(r)+"f,"+str(g)
+"f,"+str(b)+"f);\n");
counter +=1
out.close()
def write_Normals(filepath):
out = file(filepath, 'w')

counter = 0;
data = "";
for f in mesh.faces:
for v in f.verts:

normal = f.no
print f.no
out.write("NOR["+str(counter)+"]=new Vector3f("+str(normal[0])
+"f,"+str(normal[1])+"f,"+str(normal[2])+"f);\n");
counter +=1

out.close()

def write_all(filepath):
out = file(filepath, 'w')

counter = 0;
data = "";
for f in mesh.faces:
for vert in f:
out.write("CO["+str(counter)+"]=new Point3f("+str(vert.co.x)
+"f,"+str(vert.co.y)+"f,"+str(vert.co.z)+"f);\n");
counter +=1
out.write(":--:\n")

counter = 0;
data = "";
for col in vColList:

r = float(col[0]/100.00)
g = float(col[1]/100.00)
b = float(col[2]/100.00)
print r,":",col[0],":"
out.write("COL["+str(counter)+"]=new Color3f("+str(r)+"f,"+str(g)
+"f,"+str(b)+"f);\n");
counter +=1
out.write(":--:\n")

counter = 0;
data = "";
for f in mesh.faces:
for v in f.verts:

normal = f.no
print f.no
out.write("NOR["+str(counter)+"]=new Vector3f("+str(normal[0])
+"f,"+str(normal[1])+"f,"+str(normal[2])+"f);\n");
counter +=1

out.write(":--:\n")
out.close()

#--------------------
def write_all_raw(filepath):
out = file(filepath, 'w')

counter = 0;
data = "";
for f in mesh.faces:
for vert in f:
out.write("-::-"+str(vert.co.x)+","+str(vert.co.y)
+","+str(vert.co.z)+"\n");
counter +=1
out.write(":--:\n")

counter = 0;
data = "";
for col in vColList:

r = float(col[0]/100.00)
g = float(col[1]/100.00)
b = float(col[2]/100.00)
print r,":",col[0],":"
out.write("-::-"+str(r)+","+str(g)+","+str(b)+"\n");
counter +=1
out.write(":--:\n")

counter = 0;
data = "";
for f in mesh.faces:
for v in f.verts:

normal = f.no
print f.no
out.write("-::-"+str(normal[0])+","+str(normal[1])
+","+str(normal[2])+"\n");
counter +=1

out.write(":--:\n")
out.close()
#--------------------
compF = mesh.faces[0]
def fWay():
for f in mesh.faces:
for f2 in mesh.faces:
f=compF
if ( (f != f2)&( (f in fDone) == False) ):
if ( (f2.verts[0] in f.verts) & (f2.verts[1] in f.verts) ):
print "first"
vList.append(f2.verts[2])
fDone.append(f)
compF = f2
if ( (f2.verts[0] in f.verts) & (f2.verts[2] in f.verts) ):
print "f2"
vList.append(f2.verts[1])
fDone.append(f)
compF = f2
if ( (f2.verts[1] in f.verts) & (f2.verts[2] in f.verts) ):

vList.append(f2.verts[0])
fDone.append(f)
compF = f2

eList = []
vList = []
fDone = []
def FindStartVerts():
for f in mesh.faces:
if ( (f in fDone)==False):
fCheck = f
V1 = f.verts[0]
V2 = f.verts[1]
print "starters found"
return[V1,V2]
return [False,False]
def Cycle(V1,V2):
found = False
print "Started Cycle"
for f in mesh.faces:
if ( (f in fDone) == False):
if ( ( f.verts[0]==V1) & ( f.verts[1]==V2) ):
V2 = V1
V1 = f.verts[2]
fDone.append(f)
vList.append(f.verts[2])
found = True
print "returned a vert in the cycle"
return [True,V1,V2]
if ( ( f.verts[1]==V1) & ( f.verts[2]==V2) ):
V2 = V1
V1 = f.verts[0]
fDone.append(f)
vList.append(f.verts[0])
found = True
print "returned a vert in the cycle"
return [True,V1,V2]
if ( ( f.verts[0]==V1) & ( f.verts[2]==V2) ):
V2 = V1
V1 = f.verts[1]
fDone.append(f)
vList.append(f.verts[1])
found = True
print "returned a vert in the cycle"
return [True,V1,V2]
if(found == True):
print "its really so"
return [True,V1,V2]

else :return [False,V1,V2]

stripCount = 0
def main():
starters = []
temp = [False,0,0]
going = True
stripCount = 0
while (going == True):
if(temp[0]==False):
starters = FindStartVerts()
print "started a new Strip"
stripCount +=1
if starters[0]==False:break

temp = []
temp= Cycle(starters[0],starters[1])
print temp
starters[0]= temp[1]
starters[1]= temp[2]
#||<>

ActiveEdge = mesh.edges[0]
vList.append(ActiveEdge.v1)
vList.append(ActiveEdge.v2)
eDone = []
eDone.append(ActiveEdge)
#ActiveEdge.sel = 1
tempE = 0

def GetOne(activeEdge):
done=False
con = 0
for v in mesh.verts:
for e in mesh.edges:

if ( (v !=activeEdge.v1)&(v != activeEdge.v2) ):
if ( ( (e.v1 == activeEdge.v1)&(e.v2 == v) ) or ( (e.v2 ==
activeEdge.v1)&(e.v1 == v) ) ):
con += 1
if (con==1):tempE = e
print "added con"
if ( ( (e.v2 == activeEdge.v2)&(e.v1 == v) ) or ( (e.v2 ==
activeEdge.v1)&(e.v2 == v) ) ):
con += 1
if (con==1):tempE = e
print "added con"
if (con == 2):
print "Found the new vert"
con = 0
#v.sel = 1
vList.append(v)
done = True
if( (e in eDone)==False):
eDone.append(e)
activeEdge = e
else:
eDone.append(tempE)
activeEdge = tempE
activeEdge.sel=1
return activeEdge
break
if(done == True):break
def displayVerts(vlist):
for v in vlist:
v.sel = 1

vColList = []
def MakeVColList():
for f in mesh.faces:
vColList.append(f.col[0])
vColList.append(f.col[1])
vColList.append(f.col[2])
vColList.append(f.col[3])

def Extend(face):
for f in mesh.faces:
if (f != face) & ( (f in fDone) == False):

if ( (f.verts[0]in face.verts ) & ( f.verts[1]in face.verts ) &


( (f.verts[2] in vList) ==False) ):
newVert = f.verts[2]
if ( (newVert in vList) == False):vList.append(newVert)
activeFace = f
fDone.append(f)
return activeFace
break
if ( (f.verts[1]in face.verts ) & ( f.verts[2]in face.verts ) &
( (f.verts[0] in vList) ==False) ):
newVert = f.verts[0]
if ( (newVert in vList) == False):vList.append(newVert)
activeFace = f
fDone.append(f)
return activeFace
break
if ( (f.verts[0]in face.verts ) & ( f.verts[2]in face.verts ) & (
(f.verts[1] in vList) ==False) ):
newVert = f.verts[1]
if ( (newVert in vList) == False):vList.append(newVert)
activeFace = f
fDone.append(f)
return activeFace
break
return "finished"

ActiveFace = mesh.faces[0]
InvalidVert = mesh.faces[0].verts[0]

while (ActiveFace != "finished"):


ActiveFace=Extend(ActiveFace)

displayVerts(vList)

print "Finished with nr verts:",len(vList),":and strips",stripCount


print mesh.faces[0].col[0]
#write_verts("filepath")
#write_obj("tst")
MakeVColList()
Blender.Window.FileSelector(write_all_raw, "Export")

You might also like