Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- #super simple export of vert positions, colors and indices
- #note: you probably need to run blender as admin to store files
- current = bpy.context.object.data
- file = open("your path!", "w")
- #VERTEX POSITIONS
- for vert in current.vertices:
- #get coords
- x = vert.co[0]
- y = vert.co[1]
- z = vert.co[2]
- #formate coords to specific count of decimal places
- xs = str("%.6f" % x)
- ys = str("%.6f" % y)
- zs = str("%.6f" % z)
- #align plus with minus values (beautify output)
- if x >= 0: xs = " " + xs
- if y >= 0: ys = " " + ys
- if z >= 0: zs = " " + zs
- #write
- file.write("p " + xs + " " + ys + " " + zs + "\n")
- #VERTEX COLORS
- for col in current.vertex_colors:
- print(col.data)
- for c in col.data:
- #get colors and formate colors to specific count of decimal places
- r = str("%.6f" % c.color[0])
- g = str("%.6f" % c.color[1])
- b = str("%.6f" % c.color[2])
- a = str("%.6f" % c.color[3])
- #write
- file.write("c " + r + " " + g + " " + b + " " + a + "\n")
- #TRIANGLES
- #triangulate faces before!
- for poly in current.polygons:
- #get indices
- i1 = str(poly.vertices[0])
- i2 = str(poly.vertices[1])
- i3 = str(poly.vertices[2])
- #write
- file.write("i " + i1 + " " + i2 + " " + i3 + "\n")
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement