forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_RandomVector.py
73 lines (54 loc) · 2.63 KB
/
node_RandomVector.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
import bpy
from node_s import *
from mathutils.noise import seed_set,random_unit_vector
from util import *
class RandomVectorNode(Node, SverchCustomTreeNode):
''' Random Vectors with len=1'''
bl_idname = 'RandomVectorNode'
bl_label = 'Random Vector'
bl_icon = 'OUTLINER_OB_EMPTY'
count_inner = bpy.props.IntProperty(name = 'count_inner', description='random', default=1,min=1, options={'ANIMATABLE'}, update=updateNode)
seed = bpy.props.IntProperty(name = 'seed', description='random seed', default=1, options={'ANIMATABLE'}, update=updateNode)
def init(self, context):
self.inputs.new('StringsSocket', "Count", "Count")
self.inputs.new('StringsSocket', "Seed", "Seed")
self.outputs.new('VerticesSocket', "Random", "Random")
def draw_buttons(self, context, layout):
layout.prop(self, "count_inner", text="Count")
layout.prop(self, "seed", text="Seed")
def update(self):
# inputs
if 'Count' in self.inputs and self.inputs['Count'].links and \
type(self.inputs['Count'].links[0].from_socket) == bpy.types.StringsSocket:
Coun = SvGetSocketAnyType(self,self.inputs['Count'])[0]
else:
Coun = [self.count_inner]
if 'Seed' in self.inputs and self.inputs['Seed'].links and \
type(self.inputs['Seed'].links[0].from_socket) == bpy.types.StringsSocket:
Seed = SvGetSocketAnyType(self,self.inputs['Seed'])[0]
else:
Seed = [self.seed]
# outputs
if 'Random' in self.outputs and self.outputs['Random'].links:
Random = []
param=match_long_repeat([Coun,Seed])
# set seed, protect against float input
# seed = 0 is special value for blender which unsets the seed value
# and starts to use system time making the random values unrepeatable.
# So when seed = 0 we use a random value far from 0, generated used random.org
for c,s in zip(*param):
int_seed = int(round(s))
if int_seed:
seed_set(int_seed)
else:
seed_set(140230)
Random.append([random_unit_vector().to_tuple() for i in range(int(max(1,c)))])
SvSetSocketAnyType(self,'Random',Random)
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(RandomVectorNode)
def unregister():
bpy.utils.unregister_class(RandomVectorNode)
if __name__ == "__main__":
register()