-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_props_to_randomise.py
114 lines (97 loc) · 4.25 KB
/
list_props_to_randomise.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import bpy
def mat_list_to_rand(cs):
list_subpanel_material_names = [
mat.name
for mat in cs.socket_props_per_material.collection
# for mat in cs.socket_props_per_material.candidate_materials
]
# for every material: save sockets to randomise
sockets_to_randomise_per_material = {}
for mat_str in list_subpanel_material_names:
# get collection of socket properties for this material
# ATT socket properties do not include the actual socket object
if cs.socket_props_per_material.collection[
mat_str
].update_sockets_collection:
print("Collection of material sockets updated")
sockets_props_collection = cs.socket_props_per_material.collection[
mat_str
].collection
# get candidate sockets for this material
candidate_sockets = cs.socket_props_per_material.collection[
mat_str
].candidate_sockets
# if socket unlinked and randomisation toggle is True:
# modify socket props to set toggle to False
sockets_to_randomise_per_material[mat_str] = []
for sckt in candidate_sockets:
# get socket identifier sting
sckt_id = sckt.node.name + "_" + sckt.name
if sckt.node.id_data.name in bpy.data.node_groups:
sckt_id = sckt.node.id_data.name + "_" + sckt_id
# if this socket is selected to randomise but it is unlinked:
# set randomisation toggle to False
if (not sckt.is_linked) and (
sockets_props_collection[sckt_id].bool_randomise
):
setattr(
sockets_props_collection[sckt_id],
"bool_randomise",
False,
)
print(
f"Socket {sckt_id} from {mat_str} is unlinked:",
"randomisation toggle set to False",
)
# after modifying randomisation toggle
# save list of sockets to randomise to dict,
# with key = material
if sockets_props_collection[sckt_id].bool_randomise:
sockets_to_randomise_per_material[mat_str].append(sckt)
return list_subpanel_material_names, sockets_to_randomise_per_material
def geom_list_to_rand(cs):
list_subpanel_gng_names = [
gng.name for gng in cs.socket_props_per_gng.collection
]
# for every GNG: save sockets to randomise
sockets_to_randomise_per_gng = {}
for gng_str in list_subpanel_gng_names:
# get collection of socket properties for this GNG
# ATT socket properties do not include the actual socket object
if cs.socket_props_per_gng.collection[
gng_str
].update_sockets_collection:
print("Collection of geometry sockets updated")
sockets_props_collection = cs.socket_props_per_gng.collection[
gng_str
].collection
# get candidate sockets for this GNG
candidate_sockets = cs.socket_props_per_gng.collection[
gng_str
].candidate_sockets
# if socket unlinked and randomisation toggle is True:
# modify socket props to set toggle to False
sockets_to_randomise_per_gng[gng_str] = []
for sckt in candidate_sockets:
# get socket identifier string
sckt_id = sckt.node.name + "_" + sckt.name
# if this socket is selected to randomise but it is unlinked:
# set randomisation toggle to False
if (not sckt.is_linked) and (
sockets_props_collection[sckt_id].bool_randomise
):
setattr(
sockets_props_collection[sckt_id],
"bool_randomise",
False,
)
print(
f"Socket {sckt_id} from {gng_str} is unlinked:",
"randomisation toggle set to False",
)
# after modifying randomisation toggle
# save list of sockets to randomise to dict,
# with key = material
if sockets_props_collection[sckt_id].bool_randomise:
sockets_to_randomise_per_gng[gng_str].append(sckt)
return sockets_to_randomise_per_gng