live update for coll obj
This commit is contained in:
parent
4c69d7095b
commit
086de70ad6
1 changed files with 20 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue