forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_Random.py
executable file
·63 lines (45 loc) · 2 KB
/
node_Random.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
import bpy
from node_s import *
import random
from util import *
class RandomNode(Node, SverchCustomTreeNode):
''' Random numbers 0-1'''
bl_idname = 'RandomNode'
bl_label = 'Random'
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.FloatProperty(name = 'seed', description='random seed', default=0, options={'ANIMATABLE'}, update=updateNode)
def init(self, context):
self.inputs.new('StringsSocket', "Count", "Count")
self.inputs.new('StringsSocket', "Seed", "Seed")
self.outputs.new('StringsSocket', "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:
tmp = SvGetSocketAnyType(self,self.inputs['Count'])
Coun = tmp[0][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:
tmp = SvGetSocketAnyType(self,self.inputs['Seed'])
Seed = tmp[0][0]
else:
Seed = self.seed
# outputs
random.seed(Seed)
if 'Random' in self.outputs and self.outputs['Random'].links:
Random = [round(random.random(),16) for c in range(Coun)]
SvSetSocketAnyType(self, 'Random',[Random])
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(RandomNode)
def unregister():
bpy.utils.unregister_class(RandomNode)
if __name__ == "__main__":
register()