-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathmatrix_out.py
73 lines (61 loc) · 2.6 KB
/
matrix_out.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
# ##### 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 math import degrees
import bpy
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import (Matrix_generate, Matrix_location, Matrix_scale, Matrix_rotation)
class MatrixOutNode(SverchCustomTreeNode, bpy.types.Node):
''' Matrix Destructor '''
bl_idname = 'MatrixOutNode'
bl_label = 'Matrix out'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_MATRIX_OUT'
replacement_nodes = [('SvMatrixOutNodeMK2', None, dict(Rotation="Axis"))]
def rclick_menu(self, context, layout):
layout.prop(self, "flat_output", text="Flat Output", expand=False)
self.node_replacement_menu(context, layout)
def sv_init(self, context):
self.outputs.new('SvVerticesSocket', "Location")
self.outputs.new('SvVerticesSocket', "Scale")
self.outputs.new('SvVerticesSocket', "Rotation")
self.outputs.new('SvStringsSocket', "Angle")
self.inputs.new('SvMatrixSocket', "Matrix")
def process(self):
L,S,R,A = self.outputs
M = self.inputs[0]
if M.is_linked:
matrixes = M.sv_get()
if L.is_linked:
locs = Matrix_location(matrixes, to_list=True)
L.sv_set(locs)
if S.is_linked:
locs = Matrix_scale(matrixes, to_list=True)
S.sv_set(locs)
if R.is_linked or A.is_linked:
locs = Matrix_rotation(matrixes, to_list=True)
rots, angles = [],[]
for lists in locs:
rots.append([pair[0] for pair in lists])
for pair in lists:
angles.append(degrees(pair[1]))
R.sv_set(rots)
A.sv_set([angles])
def register():
bpy.utils.register_class(MatrixOutNode)
def unregister():
bpy.utils.unregister_class(MatrixOutNode)