-
Notifications
You must be signed in to change notification settings - Fork 1
/
ObjectToPyData.py
65 lines (52 loc) · 1.16 KB
/
ObjectToPyData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import bpy, bmesh, re
# Get the active mesh
me = bpy.context.object.data
mefilename2 = re.sub(r'[^\w\s]', '', str(me.name))+".py"
mefilename = re.sub(r'[0-9]', '', mefilename2)
print(mefilename)
file = open(mefilename, 'w', encoding="utf-8")
# Get a BMesh representation
bm = bmesh.new() # create an empty BMesh
bm.from_mesh(me) # fill it in from a Mesh
print("\n\n\n")
z="["
numc = len(bm.faces)-1
for f in bm.faces:
z+="["
numcc = len(f.verts)-1
for v in f.verts:
z+=str(v.index)
if numcc>0:
z+=","
numcc-=1
if numc>0:
z+="],"
numc-=1
z+="]]"
vert="[\n"
for v in bm.verts:
vert+="Vector((" +str(v.co.x)+","+str(v.co.y)+","+str(v.co.z)+")),\n"
vert+="]"
zz="["
numcz = len(bm.edges)-1
for e in bm.edges:
zz+="["
numccz = len(e.verts)-1
for v in e.verts:
zz+=str(v.index)
if numccz>0:
zz+=","
numccz-=1
if numcz>0:
zz+="],"
numcz-=1
zz+="]]"
text="verts = "
text+=vert
text+="\n\nedges = "
text+=zz
text+="\n\nfaces = "
text+=z
text+="\n\n"
#print(text)
file.write(text)