-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathmesh_join.py
77 lines (63 loc) · 2.91 KB
/
mesh_join.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
# ##### 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 #####
from functools import reduce
from itertools import cycle, chain
import bpy
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.utils.mesh_functions import meshes_py, join_meshes, meshes_np, to_elements
class SvMeshJoinNode(SverchCustomTreeNode, bpy.types.Node):
'''MeshJoin, join many mesh into on mesh object'''
bl_idname = 'SvMeshJoinNode'
bl_label = 'Mesh Join'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_MESH_JOIN'
replacement_nodes = [('SvMeshJoinNodeMk2',
dict(PolyEdge='Polygons'),
dict(PolyEdge='Polygons'))]
def sv_init(self, context):
self.inputs.new('SvVerticesSocket', 'Vertices')
self.inputs.new('SvStringsSocket', 'PolyEdge')
self.outputs.new('SvVerticesSocket', 'Vertices')
self.outputs.new('SvStringsSocket', 'PolyEdge')
def process(self):
if not self.inputs['Vertices'].is_linked:
return
vertices = self.inputs['Vertices'].sv_get(deepcopy=False)
edges = []
polygons = []
poly_edges = self.inputs['PolyEdge'].sv_get(deepcopy=False, default=[])
first_elements = [obj[0] for obj in poly_edges]
if first_elements:
if all([len(el) == 2 for el in first_elements]):
edges = poly_edges
self.outputs['PolyEdge'].label = "Edges"
elif all([len(el) != 2 for el in first_elements]):
polygons = poly_edges
self.outputs['PolyEdge'].label = "Polygons"
else:
raise TypeError('PoyEdge socket should consist either all edges or all faces') # Sv architecture law
is_py_input = isinstance(vertices[0], (list, tuple))
meshes = (meshes_py if is_py_input else meshes_np)(vertices, edges, polygons)
meshes = join_meshes(meshes)
out_vertices, out_edges, out_polygons = to_elements(meshes)
self.outputs['Vertices'].sv_set(out_vertices)
self.outputs['PolyEdge'].sv_set(out_edges or out_polygons)
def register():
bpy.utils.register_class(SvMeshJoinNode)
def unregister():
bpy.utils.unregister_class(SvMeshJoinNode)