forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_MatrixApply.py
69 lines (53 loc) · 2.14 KB
/
node_MatrixApply.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
import bpy
from node_s import *
from mathutils import *
from util import *
class MatrixApplyNode(Node, SverchCustomTreeNode):
''' Multiply vectors on matrixes with several objects in output '''
bl_idname = 'MatrixApplyNode'
bl_label = 'Apply matrix for vectors'
bl_icon = 'OUTLINER_OB_EMPTY'
def init(self, context):
self.inputs.new('VerticesSocket', "Vectors", "Vectors")
self.inputs.new('MatrixSocket', "Matrixes", "Matrixes")
self.outputs.new('VerticesSocket', "Vectors", "Vectors")
def update(self):
# inputs
if 'Vectors' in self.outputs and self.outputs['Vectors'].links:
if not ('Vectors' in self.inputs and self.inputs['Vectors'].links):
return
if not ('Matrixes' in self.inputs and self.inputs['Matrixes'].links):
return
if type(self.inputs['Vectors'].links[0].from_socket) == VerticesSocket and \
type(self.inputs['Matrixes'].links[0].from_socket) == MatrixSocket:
vecs_ = SvGetSocketAnyType(self, self.inputs['Vectors'])
vecs = Vector_generate(vecs_)
mats_ = SvGetSocketAnyType(self, self.inputs['Matrixes'])
mats = Matrix_generate(mats_)
else:
vecs = [[]]
mats = [Matrix()]
# outputs
vectors_ = self.vecscorrect(vecs, mats)
vectors = Vector_degenerate(vectors_)
SvSetSocketAnyType(self, 'Vectors', vectors)
def vecscorrect(self, vecs, mats):
out = []
lengthve = len(vecs)-1
for i, m in enumerate(mats):
out_ = []
k = i
if k > lengthve:
k = lengthve
for v in vecs[k]:
out_.append(m*v)
out.append(out_)
return out
def update_socket(self, context):
updateNode(self,context)
def register():
bpy.utils.register_class(MatrixApplyNode)
def unregister():
bpy.utils.unregister_class(MatrixApplyNode)
if __name__ == "__main__":
register()