forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_EvaluateLine.py
81 lines (62 loc) · 2.82 KB
/
node_EvaluateLine.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
import bpy
from node_s import *
from util import *
class EvaluateLine(Node, SverchCustomTreeNode):
''' EvaluateLine '''
bl_idname = 'EvaluateLineNode'
bl_label = 'EvaluateLine'
bl_icon = 'OUTLINER_OB_EMPTY'
factor_ = bpy.props.FloatProperty(name = 'factor', description='Step length', default=0.5, min=0.0, max=1.0, options={'ANIMATABLE'}, update=updateNode)
def init(self, context):
self.inputs.new('StringsSocket',"Factor","Factor")
self.inputs.new('VerticesSocket', "Vertice A", "Vertice A")
self.inputs.new('VerticesSocket', "Vertice B", "Vertice B")
self.outputs.new('VerticesSocket', "EvPoint", "EvPoint")
def draw_buttons(self, context, layout):
layout.prop(self,"factor_","Factor:");
def update(self):
# inputs
VerticesA = []
VerticesB = []
factor = []
if 'Vertice A' in self.inputs and self.inputs['Vertice A'].links:
VerticesA = Vector_generate(SvGetSocketAnyType(self,self.inputs['Vertice A']))
if 'Vertice B' in self.inputs and self.inputs['Vertice B'].links:
VerticesB = Vector_generate(SvGetSocketAnyType(self,self.inputs['Vertice B']))
if 'Factor' in self.inputs and self.inputs['Factor'].links:
factor = SvGetSocketAnyType(self,self.inputs['Factor'])
if not (VerticesA and VerticesB):
return
if not factor:
factor = [[self.factor_]]
# outputs
if 'EvPoint' in self.outputs and self.outputs['EvPoint'].links:
points = []
# match inputs using fullList, longest list matching on A and B
# extend factor list if necessary, it should not control length of output
max_obj = max(len(VerticesA),len(VerticesB))
fullList(VerticesA,max_obj)
fullList(VerticesB,max_obj)
if len(factor) < max_obj:
fullList(factor,max_obj)
for i in range(max_obj):
points_ = []
max_l = max(len(VerticesA[i]),len(VerticesB[i]))
fullList(VerticesA[i],max_l)
fullList(VerticesB[i],max_l)
for j in range(max_l):
tmp_pts = [ VerticesA[i][j].lerp(VerticesB[i][j],factor[i][k]) \
for k in range(len(factor[i]))]
points_.extend(tmp_pts)
points.append(points_)
if not points:
return
SvSetSocketAnyType(self, 'EvPoint',Vector_degenerate(points))
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(EvaluateLine)
def unregister():
bpy.utils.unregister_class(EvaluateLine)
if __name__ == "__main__":
register()