Advertisement
Guest User

ExportToTXT

a guest
Aug 21st, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import bpy
  2.  
  3. obverts = bpy.context.active_object.data.vertices
  4.  
  5. vertString = ""
  6.  
  7. vertString += "vertices = new Vector3[]\n{"
  8. for vertex in obverts:
  9.     vertString += "\n\tnew Vector3 ("
  10.     vertString += str(round(vertex.co[0],5))
  11.     vertString += "f, "
  12.     vertString += str(round(vertex.co[1],5))
  13.     vertString += "f, "
  14.     vertString += str(round(vertex.co[2],5))
  15.     vertString += "f),"
  16.  
  17. vertString = vertString.rstrip(',')
  18. vertString += "\n};"
  19.  
  20. obtris = bpy.context.active_object.data.polygons
  21.  
  22. triString = ""
  23.  
  24. triString += "triangles = new int[]\n{"
  25. for tri in obtris:
  26.     if len(tri.vertices) > 3:
  27.         raise RuntimeError("You forgot to triangulate the mesh! Go into edit mode, select all, and hit CTRL+T")
  28.    
  29.     triString += "\n\t"
  30.     triString += str(tri.vertices[0])
  31.     triString += ", "
  32.     triString += str(tri.vertices[1])
  33.     triString += ", "
  34.     triString += str(tri.vertices[2])
  35.     triString += ","
  36.  
  37. triString = triString.rstrip(',')
  38. triString += "\n};"
  39.  
  40. file = open('D:\\Libraries\\Documents\\Unity Projects\\RESTOFPATH\\meshData.txt', 'w')
  41.  
  42. file.write(vertString + "\n\n" + triString)
  43.  
  44. print("Export Successful!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement