This commit is contained in:
Nicolas Predella 2026-10-13 19:16:35 +03:00
parent 8dd61f5858
commit 8e8a0a5993
5 changed files with 40 additions and 87 deletions

View file

@ -165,29 +165,21 @@ class SliceNodeListJoiner(SliceNode):
from ....infra.blender.list_utils import flatten_list, is_list_data
items: list[Any] = []
if "resolve_multi_input" in self.__dict__:
raw_inputs = self.resolve_multi_input(self.socket_label)
for val in raw_inputs:
if val is not None:
if is_list_data(val):
items.extend(flatten_list(val))
else:
items.append(val)
return items
def _append_val(v: Any) -> None:
if v is not None:
if is_list_data(v):
items.extend(flatten_list(v))
else:
items.append(v)
target_inputs = [
i for i in getattr(self, "inputs", [])
if getattr(i, "name", "") == self.socket_label or getattr(i, "identifier", "").startswith(f"{self.socket_label}_ms_in_")
]
if not target_inputs:
raw_inputs = self.resolve_multi_input(self.socket_label)
for val in raw_inputs:
if val is not None:
if is_list_data(val):
items.extend(flatten_list(val))
else:
items.append(val)
if "resolve_multi_input" in self.__dict__ or not target_inputs:
for val in self.resolve_multi_input(self.socket_label):
_append_val(val)
return items
cache = getattr(self, "_current_cache", None)
@ -206,11 +198,7 @@ class SliceNodeListJoiner(SliceNode):
else:
val = resolve_input(inp, cache=cache, visited=visited, fieldname=self.socket_label, node=self)
if val is not None:
if is_list_data(val):
items.extend(flatten_list(val))
else:
items.append(val)
_append_val(val)
return items

View file

@ -2,14 +2,12 @@ from __future__ import annotations
from typing import Any
import bpy
from bpy.props import CollectionProperty
from .bpy_ns_types import NfStringProperty, NfFloatProperty, NfIntProperty, NfEnumProperty, NfPointerProperty, NfFloatVectorProperty
from .bpy_ns_types import NfStringProperty, NfIntProperty, NfEnumProperty, notify_tree_changed
from ...registry import register_class
from ...infra.blender.blender_slice_nodes_generic import SliceNodeSocket
from ..slice import SlicePaths
from .bpy_ns_types import notify_tree_changed
class LabelNodeSocket(SliceNodeSocket):
default = ""
def draw(self, context: Any, layout: Any, node: Any, text: str | None):

View file

@ -170,8 +170,8 @@ class SLICETREE_NodeTree(NodeTree):
)
compatible = (
(from_socket.bl_idname in geom_sockets and to_socket.bl_idname in geom_sockets)
or from_socket.bl_idname == to_socket.bl_idname
(out_s.bl_idname in geom_sockets and in_s.bl_idname in geom_sockets)
or out_s.bl_idname == in_s.bl_idname
or is_obj_to_mesh
)
if not compatible:

View file

@ -661,12 +661,11 @@ def object_to_mesh(data: Any, include_children: bool = True) -> Any:
"""Converts an Object (or list of Objects) into SlicingCollection, matching SLICENODE_GetMesh."""
from .blender_mesh_capture import SlicingCollection, SlicingGroup, SlicingObject
from .blender_bridge import get_all_children
from .list_utils import is_list_data
mesh_types = (SlicingCollection, SlicingGroup, SlicingObject)
def _to_collection(o: Any) -> Any:
if not o:
return None
if isinstance(o, (SlicingCollection, SlicingGroup, SlicingObject)):
if not o or isinstance(o, mesh_types):
return o
family = [o] + (get_all_children(o) if include_children else [])
return SlicingCollection(family, getattr(o, "name", "Mesh"))
@ -682,26 +681,20 @@ def _is_already_mesh(val: Any) -> bool:
if val is None:
return False
from .blender_mesh_capture import SlicingCollection, SlicingGroup, SlicingObject
if isinstance(val, (SlicingCollection, SlicingGroup, SlicingObject)):
mesh_types = (SlicingCollection, SlicingGroup, SlicingObject)
if isinstance(val, mesh_types):
return True
if is_list_data(val):
flat = flatten_list(val)
if flat and all(isinstance(x, (SlicingCollection, SlicingGroup, SlicingObject)) for x in flat):
return True
return bool(flat) and all(isinstance(x, mesh_types) for x in flat)
return False
def _is_object_data(val: Any) -> bool:
if val is None:
return False
if _is_already_mesh(val):
return False
if isinstance(val, (str, int, float, bool, bytes, dict)):
if val is None or _is_already_mesh(val) or isinstance(val, (str, int, float, bool, bytes, dict)):
return False
if is_list_data(val):
flat = flatten_list(val)
if not flat:
return False
return any(_is_object_data(x) for x in flat)
return bool(flat) and any(_is_object_data(x) for x in flat)
obj_type = getattr(bpy.types, "Object", None)
if isinstance(obj_type, type) and isinstance(val, obj_type):
return True
@ -772,7 +765,7 @@ def resolve_input(
)
if is_mesh_socket and val is not None:
is_obj_source = getattr(from_socket, "bl_idname", "") in ("NodeSocketObject", "SLICESOCK_Object")
if (is_obj_source or _is_object_data(val)) and not _is_already_mesh(val):
if not _is_already_mesh(val) and (is_obj_source or _is_object_data(val)):
group_stack = tuple(n.as_pointer() for n in _get_group_stack(cache))
from_node = getattr(from_socket, "node", None)
from_ptr = from_node.as_pointer() if (from_node and hasattr(from_node, "as_pointer")) else id(from_node)

View file

@ -183,69 +183,43 @@ def socket_accepts_list(sock: Any, visited: set | None = None) -> bool:
return False
def _get_input_interface_item(tree: Any, sock_or_idx_or_ident: Any) -> Any:
def _get_interface_item(tree: Any, sock_or_idx_or_ident: Any, in_out: str) -> Any:
attr_name = "inputs" if in_out == 'INPUT' else "outputs"
if not hasattr(tree, "interface"):
inputs = getattr(tree, "inputs", [])
if isinstance(sock_or_idx_or_ident, int) and 0 <= sock_or_idx_or_ident < len(inputs):
return inputs[sock_or_idx_or_ident]
sockets = getattr(tree, attr_name, [])
if isinstance(sock_or_idx_or_ident, int) and 0 <= sock_or_idx_or_ident < len(sockets):
return sockets[sock_or_idx_or_ident]
ident = getattr(sock_or_idx_or_ident, "identifier", str(sock_or_idx_or_ident))
for s in inputs:
for s in sockets:
if s.identifier == ident or s.name == ident:
return s
return None
input_items = [
items = [
item for item in getattr(tree.interface, "items_tree", [])
if getattr(item, "item_type", "") == 'SOCKET' and getattr(item, "in_out", "") == 'INPUT'
if getattr(item, "item_type", "") == 'SOCKET' and getattr(item, "in_out", "") == in_out
]
if isinstance(sock_or_idx_or_ident, int):
if 0 <= sock_or_idx_or_ident < len(input_items):
return input_items[sock_or_idx_or_ident]
return None
return items[sock_or_idx_or_ident] if 0 <= sock_or_idx_or_ident < len(items) else None
ident = getattr(sock_or_idx_or_ident, "identifier", None)
name = getattr(sock_or_idx_or_ident, "name", None)
if isinstance(sock_or_idx_or_ident, str):
ident = sock_or_idx_or_ident
name = sock_or_idx_or_ident
for item in input_items:
ident = name = sock_or_idx_or_ident
for item in items:
if ident and getattr(item, "identifier", None) == ident:
return item
for item in input_items:
for item in items:
if name and getattr(item, "name", None) == name:
return item
return None
def _get_input_interface_item(tree: Any, sock_or_idx_or_ident: Any) -> Any:
return _get_interface_item(tree, sock_or_idx_or_ident, 'INPUT')
def _get_output_interface_item(tree: Any, sock_or_idx_or_ident: Any) -> Any:
if not hasattr(tree, "interface"):
outputs = getattr(tree, "outputs", [])
if isinstance(sock_or_idx_or_ident, int) and 0 <= sock_or_idx_or_ident < len(outputs):
return outputs[sock_or_idx_or_ident]
ident = getattr(sock_or_idx_or_ident, "identifier", str(sock_or_idx_or_ident))
for s in outputs:
if s.identifier == ident or s.name == ident:
return s
return None
output_items = [
item for item in getattr(tree.interface, "items_tree", [])
if getattr(item, "item_type", "") == 'SOCKET' and getattr(item, "in_out", "") == 'OUTPUT'
]
if isinstance(sock_or_idx_or_ident, int):
if 0 <= sock_or_idx_or_ident < len(output_items):
return output_items[sock_or_idx_or_ident]
return None
ident = getattr(sock_or_idx_or_ident, "identifier", None)
name = getattr(sock_or_idx_or_ident, "name", None)
if isinstance(sock_or_idx_or_ident, str):
ident = sock_or_idx_or_ident
name = sock_or_idx_or_ident
for item in output_items:
if ident and getattr(item, "identifier", None) == ident:
return item
for item in output_items:
if name and getattr(item, "name", None) == name:
return item
return None
return _get_interface_item(tree, sock_or_idx_or_ident, 'OUTPUT')
def _find_group_input_socket(tree: Any, item: Any) -> Any:
if not item or not hasattr(tree, "nodes"):