-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathdissolve_faces_2d.py
98 lines (81 loc) · 3.92 KB
/
dissolve_faces_2d.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
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE
import bpy
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.utils.geom_2d.dissolve_mesh import dissolve_faces
class SvDissolveFaces2D(SverchCustomTreeNode, bpy.types.Node):
"""
Triggers: dissolve selected by mask input faces
Tooltip: can't produce disjoint parts
It has extra outputs on N panel
"""
bl_idname = 'SvDissolveFaces2D'
bl_label = 'Dissolve Faces 2D'
bl_icon = 'MESH_PLANE'
@property
def replacement_nodes(self):
return [('SvDissolveMeshElements', {'Face mask': 'Mask'}, None)]
def update_sockets(self, context):
links = {sock.name: [link.to_socket for link in sock.links] for sock in self.outputs}
[self.outputs.remove(sock) for sock in self.outputs[2:]]
new_socks = []
if self.face_mask:
new_socks.append(self.outputs.new('SvStringsSocket', 'Face mask'))
if self.index_mask:
new_socks.append(self.outputs.new('SvStringsSocket', 'Index mask'))
[[self.id_data.links.new(sock, link) for link in links[sock.name]]
for sock in new_socks if sock.name in links]
updateNode(self, context)
face_mask: bpy.props.BoolProperty(name='Face mask', update=update_sockets,
description='Show new selecting mak after dissolving faces')
index_mask: bpy.props.BoolProperty(name="Index mask", update=update_sockets,
description="Show output mask of indexes of old faces per new face")
def draw_buttons_ext(self, context, layout):
col = layout.column(align=True)
col.prop(self, 'face_mask', toggle=True)
col.prop(self, 'index_mask', toggle=True)
def sv_init(self, context):
self.inputs.new('SvVerticesSocket', 'Verts')
self.inputs.new('SvStringsSocket', 'Faces')
self.inputs.new('SvStringsSocket', 'Face mask')
self.outputs.new('SvVerticesSocket', 'Verts')
self.outputs.new('SvStringsSocket', 'Faces')
def process(self):
if not all([sock.is_linked for sock in self.inputs[:2]]):
return
out = []
out_mask = []
out_index = []
for vs, fs, mf in zip(self.inputs['Verts'].sv_get(), self.inputs['Faces'].sv_get(),
self.inputs['Face mask'].sv_get() if self.inputs['Face mask'].is_linked else [[1]]):
mf = mf if len(mf) == len(fs) else mf[:len(fs)] if len(mf) > len(fs) \
else mf + [mf[-1]] * (len(fs) - len(mf))
if self.face_mask and self.index_mask:
v, f, m, i = dissolve_faces(vs, fs, mf, self.face_mask, self.index_mask)
out_mask.append(m)
out_index.append(i)
elif self.face_mask:
v, f, m = dissolve_faces(vs, fs, mf, self.face_mask, self.index_mask)
out_mask.append(m)
elif self.index_mask:
v, f, i = dissolve_faces(vs, fs, mf, self.face_mask, self.index_mask)
out_index.append(i)
else:
v, f = dissolve_faces(vs, fs, mf, self.face_mask, self.index_mask)
out.append([v, f])
out_v, out_f = zip(*out)
self.outputs['Verts'].sv_set(out_v)
self.outputs['Faces'].sv_set(out_f)
if self.face_mask:
self.outputs['Face mask'].sv_set(out_mask)
if self.index_mask:
self.outputs['Index mask'].sv_set(out_index)
def register():
bpy.utils.register_class(SvDissolveFaces2D)
def unregister():
bpy.utils.unregister_class(SvDissolveFaces2D)