-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathsolidify.py
122 lines (98 loc) · 3.93 KB
/
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.props import FloatProperty
import bmesh
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, repeat_last, fullList
from sverchok.utils.sv_bmesh_utils import bmesh_from_pydata
# by Linus Yng
def solidify(vertices, faces, t):
if not faces or not vertices:
return False
if len(faces[0]) == 2:
return False
verlen = set(range(len(vertices)))
bm = bmesh_from_pydata(vertices, [], faces, normal_update=True)
geom_in = bm.verts[:] + bm.edges[:] + bm.faces[:]
bmesh.ops.solidify(bm, geom=geom_in, thickness=t[0])
edges = []
faces = []
newpols = []
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:
indexes = [v.index for v in face.verts[:]]
faces.append(indexes)
if not verlen.intersection(indexes):
newpols.append(indexes)
bm.clear()
bm.free()
return (verts, edges, faces, newpols)
class SvSolidifyNode(SverchCustomTreeNode, bpy.types.Node):
'''Extrude along normal'''
bl_idname = 'SvSolidifyNode'
bl_label = 'Solidify'
bl_icon = 'MOD_SOLIDIFY'
replacement_nodes = [('SvSolidifyNodeMk2',
dict(thickness='Thickness', vertices='Vertices', polygons='Polygons'),
dict(vertices='Vertices', edges='Edges', polygons='Polygons', newpols='New Pols'))]
thickness: FloatProperty(
name='Thickness', description='Shell thickness',
default=0.1, update=updateNode)
def sv_init(self, context):
self.inputs.new('SvStringsSocket', 'thickness').prop_name = 'thickness'
self.inputs.new('SvVerticesSocket', 'vertices')
self.inputs.new('SvStringsSocket', 'polygons')
self.outputs.new('SvVerticesSocket', 'vertices')
self.outputs.new('SvStringsSocket', 'edges')
self.outputs.new('SvStringsSocket', 'polygons')
self.outputs.new('SvStringsSocket', 'newpols')
def process(self):
if not any((s.is_linked for s in self.outputs)):
return
if not (self.inputs['vertices'].is_linked and self.inputs['polygons'].is_linked):
return
verts = self.inputs['vertices'].sv_get()
polys = self.inputs['polygons'].sv_get()
thickness = self.inputs['thickness'].sv_get()
verts_out = []
edges_out = []
polys_out = []
newpo_out = []
fullList(thickness, len(verts))
for v, p, t in zip(verts, polys, thickness):
res = solidify(v, p, t)
if not res:
return
verts_out.append(res[0])
edges_out.append(res[1])
polys_out.append(res[2])
newpo_out.append(res[3])
self.outputs['vertices'].sv_set(verts_out)
self.outputs['edges'].sv_set(edges_out)
self.outputs['polygons'].sv_set(polys_out)
self.outputs['newpols'].sv_set(newpo_out)
def register():
bpy.utils.register_class(SvSolidifyNode)
def unregister():
bpy.utils.unregister_class(SvSolidifyNode)