-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDualGraphtoPenrose.py
More file actions
87 lines (76 loc) · 2.26 KB
/
DualGraphtoPenrose.py
File metadata and controls
87 lines (76 loc) · 2.26 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import cmath
import math
import bpy
## It is expected that CirclePackDualGraph.py has been run prior to instancing
## this script. It is also expected that Penrose2.py has been instanced
## that is loaded in console.
triangles = []
pvertices = []
pfaces = []
pselections = []
nextinc = 0
nextincf = 0
def midpoint(edge):
## complex form of midpoint
a,b = edge
return (a+b)/2
for findex, face in enumerate(faces):
croot = nodetofaceind[findex]
## rx,ry = root
## croot = complex(rx,ry)
triangles = []
for index, vert in enumerate(face):
nindex = None
nvert = None
if index == len(face)-1:
nindex = 0
else:
nindex = index+1
nvert = face[nindex]
vcoord = vertices[vert]
nvcoord = vertices[nvert]
xv,yv,zv = vcoord
xnv,ynv,znv = nvcoord
a = complex(xv,yv)
b = complex(xnv,ynv)
mab = midpoint((a,b))
triangles.append((0,croot,a,mab))
triangles.append((0,croot,mab,b))
cv, cf, sv = penrosesubdivde(triangles)
nextinc = len(pvertices)
nextincf = len(pfaces)
## reindex vertices and selectionvertices (misnomer faces actually)
for indf, f in enumerate(cf):
lf = list(f)
for indv, v in enumerate(lf):
lf[indv] += nextinc
cf[indf] = tuple(lf)
for indf, f in enumerate(sv):
sv[indf] += nextincf
## concatenate vertices and everything else
pvertices += cv
pfaces += cf
pselections += sv
meshName = "PenroseGraph"
obName = "PenroseGraphObj"
me = bpy.data.meshes.new(meshName)
ob = bpy.data.objects.new(obName, me)
ob.location = bpy.context.scene.cursor_location
bpy.context.scene.objects.link(ob)
me.from_pydata(pvertices,[],pfaces)
me.update(calc_edges=True)
scn = bpy.context.scene
scn.objects.active = ob
ob.select = True
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
cvertices = obj.data.vertices
cfaces = obj.data.polygons
for sel in pselections:
cfaces[sel].select = True
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_assign()
bpy.ops.mesh.dissolve_edges()