live update for coll obj

This commit is contained in:
Nicolas Predella 2026-06-03 19:06:23 +03:00
parent 4c69d7095b
commit 086de70ad6

View file

@ -21,24 +21,40 @@ def get_referenced_objects(node, visited=None):
visited.add(ptr)
objs = set()
# Special case: if this is a group node, we must also check nodes inside the group
if node.bl_idname == "SLICENODE_Group" and getattr(node, "slicer_tree", None):
for internal_node in node.slicer_tree.nodes:
objs.update(get_referenced_objects(internal_node, visited))
# Check all input sockets for objects
for inp in node.inputs:
# If it's an object socket, it might have a value if not linked
if inp.bl_idname == "SLICESOCK_Object":
if not inp.is_linked and inp.value:
if inp.bl_idname in {"SLICESOCK_Object", "SLICESOCK_ObjectRo"}:
if not inp.is_linked and getattr(inp, "value", None):
objs.add(inp.value)
# Always follow links to find more objects upstream
if inp.is_linked:
for link in inp.links:
# Special case: if from_node is CollectionObjects, the object is identified by the socket identifier
if link.from_node.bl_idname == "SLICENODE_CollectionObjects":
obj = bpy.data.objects.get(link.from_socket.identifier)
if obj:
objs.add(obj)
objs.update(get_referenced_objects(link.from_node, visited))
# Also check output sockets of the node itself,
# as some nodes might "hold" an object (like InputObject)
for outp in node.outputs:
if outp.bl_idname == "SLICESOCK_Object":
if outp.value:
if outp.bl_idname in {"SLICESOCK_Object", "SLICESOCK_ObjectRo"}:
if getattr(outp, "value", None):
objs.add(outp.value)
elif node.bl_idname == "SLICENODE_CollectionObjects" and outp.is_linked:
obj = bpy.data.objects.get(outp.identifier)
if obj:
objs.add(obj)
return objs