forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_MeshJoin.py
64 lines (41 loc) · 1.9 KB
/
node_MeshJoin.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
from node_s import *
from util import *
import operator
class SvMeshJoinNode(Node, SverchCustomTreeNode):
'''MeshJoin, join many mesh into on mesh object'''
bl_idname = 'SvMeshJoinNode'
bl_label = 'Mesh Join'
bl_icon = 'OUTLINER_OB_EMPTY'
def init(self, context):
self.inputs.new('VerticesSocket', 'Vertices', 'Vertices')
self.inputs.new('StringsSocket', 'PolyEdge', 'PolyEdge')
self.outputs.new('VerticesSocket', 'Vertices', 'Vertices')
self.outputs.new('StringsSocket', 'PolyEdge', 'PolyEdge')
def update(self):
if 'Vertices' in self.inputs and self.inputs['Vertices'].links and \
'PolyEdge' in self.inputs and self.inputs['PolyEdge'].links:
verts = SvGetSocketAnyType(self,self.inputs['Vertices'])
poly_edge = SvGetSocketAnyType(self,self.inputs['PolyEdge'])
verts_out = []
poly_edge_out = []
offset = 0
for obj in zip(verts,poly_edge):
verts_out.extend(obj[0])
if offset:
res=[list(map(lambda x:operator.add(offset,x),ep)) for ep in obj[1]]
poly_edge_out.extend(res)
else:
poly_edge_out.extend(obj[1])
offset += len(obj[0])
if 'Vertices' in self.outputs and self.outputs['Vertices'].links:
SvSetSocketAnyType(self, 'Vertices',[verts_out])
if 'PolyEdge' in self.outputs and self.outputs['PolyEdge'].links:
SvSetSocketAnyType(self, 'PolyEdge',[poly_edge_out])
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(SvMeshJoinNode)
def unregister():
bpy.utils.unregister_class(SvMeshJoinNode)
if __name__ == "__main__":
register()