Skip to content

Commit

Permalink
Fixed duplicated subpanels min-max vals for UD props - only names dup…
Browse files Browse the repository at this point in the history
…licated
  • Loading branch information
ruaridhg committed Sep 14, 2023
1 parent 7d2a159 commit d40ac41
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 125 deletions.
3 changes: 2 additions & 1 deletion randomiser/define_prop/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def register():
bpy.types.Scene.custom = bpy.props.CollectionProperty(
type=CUSTOM_colorCollection
)
bpy.types.Scene.custom_index = bpy.props.IntProperty()

bpy.types.Scene.custom_index = bpy.props.IntProperty()

print("UD properties registered")

Expand Down
11 changes: 7 additions & 4 deletions randomiser/define_prop/property_classes/collection_UD_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ def compute_UD_props_sets(self):
# set of GNGs already in collection
self.set_UD_props_in_collection = set(UD.name for UD in self.collection)

for UD in self.collection:
print("self.collection !!!!!!!!!! ", UD.name)
# for UD in self.collection:
##print("self.collection !!!!!!!!!! ", UD.name)

# set of node groups in Blender data structure
self.set_UD_props_in_data = set(UD.name for UD in self.candidate_UD_props)

for UD in self.candidate_UD_props:
print("self.candidate_UD_props !!!!!!!!!! ", UD.name)
# for UD in self.candidate_UD_props:
## print("self.candidate_UD_props !!!!!!!!!! ", UD.name)

# pdb.set_trace()

### REMOVE????
# set of node groups in one of the sets only
self.set_UD_props_in_one_only = (
self.set_UD_props_in_collection.symmetric_difference(
Expand Down Expand Up @@ -77,6 +78,7 @@ def set_update_UD_props_collection(self, value):
_description_
"""

##### ISSUE WITH DUPLICATION?????
# if update value is True
if value:
# if the update fn is triggered directly and not via
Expand All @@ -87,6 +89,7 @@ def set_update_UD_props_collection(self, value):
# for all node groups that are in one set only
for UD_name in self.set_UD_props_in_one_only:
# if only in collection: remove it from the collection

if UD_name in self.set_UD_props_in_collection:
self.collection.remove(self.collection.find(UD_name))

Expand Down
248 changes: 128 additions & 120 deletions randomiser/define_prop/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,125 +44,124 @@ def draw_sockets_list_UD(
# Define UI fields for every socket property
# NOTE: if I don't sort the input nodes, everytime one of the nodes is
# selected in the graph it moves to the bottom of the panel.
list_UD_props_sorted = sorted(list_UD_props, key=lambda x: x.name)
print(list_UD_props_sorted)
for i_n, UD in enumerate(list_UD_props_sorted):
row = layout.row()

# if first node: add labels for
# name, min, max and randomisation toggle
if i_n == 0:
row_split = row.split()
col1 = row_split.column(align=True)
row_split.column(align=True)
col3 = row_split.column(align=True)
col4 = row_split.column(align=True)
row_split.column(align=True)

# input node name
col1.label(text=UD.name)
col1.alignment = "CENTER"

# min label
col3.alignment = "CENTER"
col3.label(text="min")

# max label
col4.alignment = "CENTER"
col4.label(text="max")

# if not first node: add just node name
else:
row.separator(factor=1.0) # add empty row before each node
row = layout.row()

row.label(text=UD.name)

row = layout.row()
row_split = row.split()
col1 = row_split.column(align=True)
col2 = row_split.column(align=True)
col3 = row_split.column(align=True)
col4 = row_split.column(align=True)
row_split.column(align=True)

# UD prop name
col1.alignment = "RIGHT"
col1.label(text="value") # text=sckt.name)

# socket current value
# col2.prop(
# UD,
# "default_value", #####Default value not found
# icon_only=True,
# )
# col2.enabled = False # current value is not editable

# # socket min and max columns
# socket_id = UD.name + "_" + sckt.name
# if (UD.id_data.name in bpy.data.node_groups) and (
# bpy.data.node_groups[UD.id_data.name].type != "GEOMETRY"
# ): # only for SHADER groups
# socket_id = UD.id_data.name + "_" + socket_id

# if socket is a color: format min/max as a color picker
# and an array (color picker doesn't include alpha value)
sckt = UD.name
if type(sckt) == bpy.types.NodeSocketColor:
for m_str, col in zip(["min", "max"], [col3, col4]):
# color picker
col.template_color_picker(
sockets_props_collection, # [socket_id],
m_str + "_" + cs.socket_type_to_attr[type(sckt)],
)
# array
for j, cl in enumerate(["R", "G", "B", "alpha"]):
col.prop(
sockets_props_collection, # [socket_id],
m_str + "_" + cs.socket_type_to_attr[type(sckt)],
icon_only=False,
text=cl,
index=j,
)
# if socket is Boolean: add non-editable labels
elif type(UD.name) == bpy.types.NodeSocketBool:
for m_str, col in zip(["min", "max"], [col3, col4]):
m_val = getattr(
sockets_props_collection, # [socket_id],
m_str + "_" + cs.socket_type_to_attr[type(sckt)],
)
col.label(text=str(list(m_val)[0]))

# if socket is not color type: format as a regular property

##### REFACTOR EASY CASE FIRST
# (may not need other cases)
else: # bpy.types.NodeSocketBool:
for m_str, col in zip(["min", "max"], [col3, col4]):
attr_type = attr_get_type(
bpy.context.scene, attribute_only_str
)[0]
print(
"sockets_props_collection ???????",
sockets_props_collection,
)
print("type ??????????? ", attribute_only_str, attr_type)
list_UD_props_sorted = list_UD_props
# sorted(list_UD_props, key=lambda x: x.name)
print("IN draw_sockets_list_UD ==== ", list_UD_props_sorted)
# for i_n, UD_str in enumerate(list_UD_props_sorted):
row = layout.row()

# if first node: add labels for
# name, min, max and randomisation toggle
# if i_n == 0:
row_split = row.split()
col1 = row_split.column(align=True)
row_split.column(align=True)
col3 = row_split.column(align=True)
col4 = row_split.column(align=True)
row_split.column(align=True)

# input node name
col1.label(text=list_UD_props_sorted) # UD.name
col1.alignment = "CENTER"

# min label
col3.alignment = "CENTER"
col3.label(text="min")

# max label
col4.alignment = "CENTER"
col4.label(text="max")

# if not first node: add just node name
# else:
# row.separator(factor=1.0) # add empty row before each node
# row = layout.row()

# row.label(text=UD_str) #UD.name

row = layout.row()
row_split = row.split()
col1 = row_split.column(align=True)
col2 = row_split.column(align=True)
col3 = row_split.column(align=True)
col4 = row_split.column(align=True)
row_split.column(align=True)

# UD prop name
col1.alignment = "RIGHT"
col1.label(text="value") # text=sckt.name)

# socket current value
# col2.prop(
# UD,
# "default_value", #####Default value not found
# icon_only=True,
# )
# col2.enabled = False # current value is not editable

# # socket min and max columns
# socket_id = UD.name + "_" + sckt.name
# if (UD.id_data.name in bpy.data.node_groups) and (
# bpy.data.node_groups[UD.id_data.name].type != "GEOMETRY"
# ): # only for SHADER groups
# socket_id = UD.id_data.name + "_" + socket_id

# if socket is a color: format min/max as a color picker
# and an array (color picker doesn't include alpha value)
sckt = list_UD_props_sorted # UD.name
if type(sckt) == bpy.types.NodeSocketColor:
for m_str, col in zip(["min", "max"], [col3, col4]):
# color picker
col.template_color_picker(
sockets_props_collection, # [socket_id],
m_str + "_" + cs.socket_type_to_attr[type(sckt)],
)
# array
for j, cl in enumerate(["R", "G", "B", "alpha"]):
col.prop(
sockets_props_collection, # [socket_id],
m_str + "_" + cs.UD_prop_to_attr[attr_type],
icon_only=True,
m_str + "_" + cs.socket_type_to_attr[type(sckt)],
icon_only=False,
text=cl,
index=j,
)
# np.array(getattr(self, m_str + "_min"))
# getattr(context.scene.camera, location)[0]
# e.g. min_float_1d so m_str + "_" + float_1d

# randomisation toggle
# col5.prop(
col2.prop(
sockets_props_collection, # [socket_id],
"bool_randomise",
icon_only=True,
)
# if socket is Boolean: add non-editable labels
elif type(sckt) == bpy.types.NodeSocketBool:
for m_str, col in zip(["min", "max"], [col3, col4]):
m_val = getattr(
sockets_props_collection, # [socket_id],
m_str + "_" + cs.socket_type_to_attr[type(sckt)],
)
col.label(text=str(list(m_val)[0]))

# if socket is not color type: format as a regular property

##### REFACTOR EASY CASE FIRST
# (may not need other cases)
else: # bpy.types.NodeSocketBool:
for m_str, col in zip(["min", "max"], [col3, col4]):
attr_type = attr_get_type(bpy.context.scene, attribute_only_str)[0]
print(
"sockets_props_collection ???????",
sockets_props_collection,
)
print("type ??????????? ", attribute_only_str, attr_type)
col.prop(
sockets_props_collection, # [socket_id],
m_str + "_" + cs.UD_prop_to_attr[attr_type],
icon_only=True,
)
# np.array(getattr(self, m_str + "_min"))
# getattr(context.scene.camera, location)[0]
# e.g. min_float_1d so m_str + "_" + float_1d

# randomisation toggle
# col5.prop(
col2.prop(
sockets_props_collection, # [socket_id],
"bool_randomise",
icon_only=True,
)


def attr_get_type(obj, path):
Expand Down Expand Up @@ -494,9 +493,10 @@ def draw(self, context):

print("list_parent_nodes_str = ", attribute_only_str)

list_UD_props = [
# full_list = [prop.name for prop in list(C.scene.custom)]
list_all_UD_props = [
UD_str
for UD_str in bpy.context.scene.custom
for UD_str in list(bpy.context.scene.custom)
if attr_get_type(
bpy.context.scene, get_attr_only_str(UD_str.name)
)[1]
Expand All @@ -506,14 +506,22 @@ def draw(self, context):
# bpy.data.node_groups[subpanel_gng.name].nodes[nd_str]
# for nd_str in list_parent_nodes_str
]
print("list_UD_props =======", list_UD_props)
print("list_all_UD_props ====== ", list_all_UD_props)
print(
"bpy.context.scene.custom_index == ",
bpy.context.scene.custom_index,
)
list_current_UD_props = list_all_UD_props[
bpy.context.scene.custom_index
].name
print("list_current_UD_props =======", list_current_UD_props)

# Draw sockets to randomise per input node, including their
# current value and min/max boundaries
draw_sockets_list_UD(
cs,
self.layout,
list_UD_props,
list_current_UD_props,
sockets_props_collection,
attribute_only_str,
full_str,
Expand Down

0 comments on commit d40ac41

Please sign in to comment.