forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_Solidify.py
114 lines (78 loc) · 3.34 KB
/
node_Solidify.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import bmesh, mathutils
from mathutils import Vector, Matrix
from node_s import *
from util import *
# based on CrossSectionNode
# but using python bmesh code for driving
# by Linus Yng
def soldify(vertices, faces, t):
if not faces or not vertices:
return False
if len(faces[0])==2:
return False
bm=bmesh.new()
bm_verts =[bm.verts.new(v) for v in vertices]
for face in faces:
bm.faces.new([bm_verts[i] for i in face])
geom_in = bm.verts[:]+bm.edges[:]+bm.faces[:]
bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:])
res=bmesh.ops.solidify(bm, geom=geom_in, thickness=t)
edges = []
faces = []
bm.verts.index_update()
bm.edges.index_update()
bm.faces.index_update()
for edge in bm.edges[:]:
edges.append([v.index for v in edge.verts[:]])
verts = [vert.co[:] for vert in bm.verts[:]]
for face in bm.faces:
faces.append([v.index for v in face.verts[:]])
bm.clear()
bm.free()
return (verts,edges,faces)
class SvSolidifyNode(Node, SverchCustomTreeNode):
'''Soldifies geometry'''
bl_idname = 'SvSolidifyNode'
bl_label = 'Solidify'
bl_icon = 'OUTLINER_OB_EMPTY'
thickness = bpy.props.FloatProperty(name='thickness', description='Shell thickness', default=0.1, update=updateNode)
def init(self, context):
self.inputs.new('VerticesSocket', 'vertices', 'vertices')
self.inputs.new('StringsSocket', 'polygons', 'polygons')
self.outputs.new('VerticesSocket', 'vertices', 'vertices')
self.outputs.new('StringsSocket', 'edges', 'edges')
self.outputs.new('StringsSocket', 'polygons', 'polygons')
def draw_buttons(self, context, layout):
layout.prop(self,'thickness',text="Thickness")
def update(self):
if not self.outputs['vertices'].links:
return
if 'vertices' in self.inputs and self.inputs['vertices'].links and \
'polygons' in self.inputs and self.inputs['polygons'].links:
verts = Vector_generate(SvGetSocketAnyType(self,self.inputs['vertices']))
polys = SvGetSocketAnyType(self,self.inputs['polygons'])
#print (verts,polys)
verts_out = []
edges_out = []
polys_out = []
for obj in zip(verts,polys):
res = soldify(obj[0], obj[1], self.thickness)
if not res:
return
verts_out.append(res[0])
edges_out.append(res[1])
polys_out.append(res[2])
if 'vertices' in self.outputs and self.outputs['vertices'].links:
SvSetSocketAnyType(self, 'vertices',verts_out)
if 'edges' in self.outputs and self.outputs['edges'].links:
SvSetSocketAnyType(self, 'edges',edges_out)
if 'polygons' in self.outputs and self.outputs['polygons'].links:
SvSetSocketAnyType(self, 'polygons', polys_out)
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(SvSolidifyNode)
def unregister():
bpy.utils.unregister_class(SvSolidifyNode)
if __name__ == "__main__":
register()