-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathpolygons_to_edges.py
101 lines (80 loc) · 3.51 KB
/
polygons_to_edges.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
# ##### 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 BoolProperty
from numpy import array, empty, concatenate, unique, sort, int32, ndarray
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import dataCorrect_np, updateNode
from sverchok.utils.sv_mesh_utils import polygons_to_edges, polygons_to_edges_np
from sverchok.utils.decorators import deprecated
@deprecated("Please use sverchok.utils.sv_mesh_utils.polygons_to_edges instead")
def pols_edges(obj, unique_edges=False):
return polygons_to_edges(obj, unique_edges)
class Pols2EdgsNode(SverchCustomTreeNode, bpy.types.Node):
"""
Triggers: Edges from Faces
Tooltip: Get edges lists from polygons lists.
"""
replacement_nodes = [('SvPols2EdgsNodeMk2', None, None)]
bl_idname = 'Pols2EdgsNode'
bl_label = 'Polygons to Edges'
bl_icon = 'EDGESEL'
sv_icon = 'SV_POLYGONS_TO_EDGES'
unique_edges: BoolProperty(
name="Unique Edges", default=False, update=updateNode)
regular_pols: BoolProperty(
name='Regular polygons',
description='Makes the node faster if all the incoming polygons have the same number of sides',
default=False, update=updateNode)
output_numpy: BoolProperty(
name='Output NumPy',
description='Output NumPy arrays',
default=False, update=updateNode)
def draw_buttons(self, context, layout):
layout.prop(self, "regular_pols")
layout.prop(self, "unique_edges")
def draw_buttons_ext(self, context, layout):
'''draw buttons on the N-panel'''
self.draw_buttons(context, layout)
layout.prop(self, 'output_numpy')
def rclick_menu(self, context, layout):
'''right click sv_menu items'''
layout.label(text="Upgrade Node:")
self.node_replacement_menu(context, layout)
layout.separator()
self.draw_buttons(context, layout)
layout.prop(self, "output_numpy")
def sv_init(self, context):
self.inputs.new('SvStringsSocket', "pols")
self.outputs.new('SvStringsSocket', "edgs")
def process(self):
if not self.outputs[0].is_linked:
return
polygons_ = self.inputs['pols'].sv_get(deepcopy=False)
polygons = dataCorrect_np(polygons_)
if self.output_numpy or isinstance(polygons[0], ndarray) or self.regular_pols:
result = polygons_to_edges_np(polygons, self.unique_edges, self.output_numpy)
else:
result = polygons_to_edges(polygons, self.unique_edges)
self.outputs['edgs'].sv_set(result)
def draw_label(self):
return (self.label or self.name) if not self.hide else "P to E"
def register():
bpy.utils.register_class(Pols2EdgsNode)
def unregister():
bpy.utils.unregister_class(Pols2EdgsNode)