-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathrandom_vector_mk2.py
91 lines (71 loc) · 3.28 KB
/
random_vector_mk2.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
82
83
84
85
86
87
88
89
90
91
# ##### 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 #####
import bpy
from bpy.props import IntProperty, FloatProperty
from mathutils.noise import seed_set, random_unit_vector
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, match_long_repeat
class RandomVectorNodeMK2(SverchCustomTreeNode, bpy.types.Node):
''' rv Random unit Vec'''
bl_idname = 'RandomVectorNodeMK2'
bl_label = 'Random Vector MK2'
bl_icon = 'RNDCURVE'
replacement_nodes = [('RandomVectorNodeMK3', None, None)]
count_inner: IntProperty(
name='Count', description='random', default=1, min=1,
options={'ANIMATABLE'}, update=updateNode)
scale: FloatProperty(
name='Scale', description='scale for vectors', default=1.0,
options={'ANIMATABLE'}, update=updateNode)
seed: IntProperty(
name='Seed', description='random seed', default=1,
options={'ANIMATABLE'}, update=updateNode)
def sv_init(self, context):
self.inputs.new('SvStringsSocket', "Count").prop_name = 'count_inner'
self.inputs.new('SvStringsSocket', "Seed").prop_name = 'seed'
self.inputs.new('SvStringsSocket', "Scale").prop_name = 'scale'
self.outputs.new('SvVerticesSocket', "Random")
def process(self):
count_socket = self.inputs['Count']
seed_socket = self.inputs['Seed']
scale_socket = self.inputs['Scale']
random_socket = self.outputs['Random']
# inputs
Coun = count_socket.sv_get(deepcopy=False)[0]
Seed = seed_socket.sv_get(deepcopy=False)[0]
Scale = scale_socket.sv_get(deepcopy=False, default=[])[0]
# outputs
if random_socket.is_linked:
Random = []
param = match_long_repeat([Coun, Seed, Scale])
# 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, sc in zip(*param):
int_seed = int(round(s))
if int_seed:
seed_set(int_seed)
else:
seed_set(140230)
Random.append([(random_unit_vector() * sc).to_tuple() for i in range(int(max(1, c)))])
random_socket.sv_set(Random)
def register():
bpy.utils.register_class(RandomVectorNodeMK2)
def unregister():
bpy.utils.unregister_class(RandomVectorNodeMK2)