fix: geonode socket loading

This commit is contained in:
Swann 2024-03-19 23:49:06 +01:00
parent 0c26b9c6c4
commit 6fd8a32959
3 changed files with 12 additions and 16 deletions

View File

@ -30,7 +30,7 @@ from .bl_datablock import get_datablock_from_uuid, resolve_datablock_from_uuid
from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies
NODE_SOCKET_INDEX = re.compile('\[(\d*)\]') NODE_SOCKET_INDEX = re.compile('\[(\d*)\]')
IGNORED_SOCKETS = ['GEOMETRY', 'SHADER', 'CUSTOM'] IGNORED_SOCKETS = ['NodeSocketGeometry', 'NodeSocketShader', 'CUSTOM']
def load_node(node_data: dict, node_tree: bpy.types.ShaderNodeTree): def load_node(node_data: dict, node_tree: bpy.types.ShaderNodeTree):
""" Load a node into a node_tree from a dict """ Load a node into a node_tree from a dict

View File

@ -58,20 +58,16 @@ else:
def get_node_group_properties_identifiers(node_group): def get_node_group_properties_identifiers(node_group):
props_ids = [] props_ids = []
# Inputs
for inpt in node_group.inputs: for socket in node_group.interface.items_tree:
if inpt.type in IGNORED_SOCKETS: if socket.socket_type in IGNORED_SOCKETS:
continue continue
else: else:
props_ids.append((inpt.identifier, inpt.type)) props_ids.append((socket.identifier, socket.socket_type))
if inpt.type in ['INT', 'VALUE', 'BOOLEAN', 'RGBA', 'VECTOR']: # for outpt in node_group.outputs:
props_ids.append((f"{inpt.identifier}_attribute_name",'STR')) # if outpt.type not in IGNORED_SOCKETS and outpt.type in ['INT', 'VALUE', 'BOOLEAN', 'RGBA', 'VECTOR']:
props_ids.append((f"{inpt.identifier}_use_attribute", 'BOOL')) # props_ids.append((f"{outpt.identifier}_attribute_name", 'STR'))
for outpt in node_group.outputs:
if outpt.type not in IGNORED_SOCKETS and outpt.type in ['INT', 'VALUE', 'BOOLEAN', 'RGBA', 'VECTOR']:
props_ids.append((f"{outpt.identifier}_attribute_name", 'STR'))
return props_ids return props_ids
# return [inpt.identifer for inpt in node_group.inputs if inpt.type not in IGNORED_SOCKETS] # return [inpt.identifer for inpt in node_group.inputs if inpt.type not in IGNORED_SOCKETS]
@ -172,13 +168,13 @@ def load_modifier_geometry_node_props(dumped_modifier: dict, target_modifier: bp
for input_index, inpt in enumerate(get_node_group_properties_identifiers(target_modifier.node_group)): for input_index, inpt in enumerate(get_node_group_properties_identifiers(target_modifier.node_group)):
dumped_value, dumped_type = dumped_modifier['props'][input_index] dumped_value, dumped_type = dumped_modifier['props'][input_index]
input_value = target_modifier[inpt[0]] input_value = target_modifier[inpt[0]]
if dumped_type in ['INT', 'VALUE', 'STR', 'BOOL']: if dumped_type in ['NodeSocketInt', 'NodeSocketFloat', 'NodeSocketString', 'NodeSocketBool']:
logging.info(f"{inpt[0]}/{dumped_value}") logging.info(f"{inpt[0]}/{dumped_value}")
target_modifier[inpt[0]] = dumped_value target_modifier[inpt[0]] = dumped_value
elif dumped_type in ['RGBA', 'VECTOR']: elif dumped_type in ['RGBA', 'VECTOR']:
for index in range(len(input_value)): for index in range(len(input_value)):
input_value[index] = dumped_value[index] input_value[index] = dumped_value[index]
elif dumped_type in ['COLLECTION', 'OBJECT', 'IMAGE', 'TEXTURE', 'MATERIAL']: elif dumped_type in ['NodeSocketCollection', 'NodeSocketObject', 'NodeSocketImage', 'NodeSocketTexture', 'NodeSocketMaterial']:
target_modifier[inpt[0]] = get_datablock_from_uuid(dumped_value, None) target_modifier[inpt[0]] = get_datablock_from_uuid(dumped_value, None)

View File

@ -81,9 +81,9 @@ def on_scene_update(scene):
# NOTE: maybe we don't need to check each update but only the first # NOTE: maybe we don't need to check each update but only the first
for update in reversed(dependency_updates): for update in reversed(dependency_updates):
update_uuid = getattr(update.id, 'uuid', None) update_uuid = getattr(update.id.original, 'uuid', None)
if update_uuid: if update_uuid:
node = session.repository.graph.get(update.id.uuid) node = session.repository.graph.get(update_uuid)
check_common = session.repository.rdp.get_implementation(update.id).bl_check_common check_common = session.repository.rdp.get_implementation(update.id).bl_check_common
if node and (node.owner == session.repository.username or check_common): if node and (node.owner == session.repository.username or check_common):