Compare commits
2 Commits
main
...
d1a5655464
| Author | SHA1 | Date | |
|---|---|---|---|
| d1a5655464 | |||
| 5bf8f48db0 |
99
utils.py
99
utils.py
@@ -16,6 +16,38 @@ def silence_puresky():
|
|||||||
return removed
|
return removed
|
||||||
|
|
||||||
|
|
||||||
|
def _snapshot_fragile_sockets(obj, mod, iface):
|
||||||
|
"""Snapshot Material/Object sockets before modifying any override."""
|
||||||
|
FRAGILE_TYPES = {'NodeSocketMaterial', 'NodeSocketObject'}
|
||||||
|
snapshot = {}
|
||||||
|
for item in iface.items_tree:
|
||||||
|
if item.item_type != 'SOCKET' or item.in_out != 'INPUT':
|
||||||
|
continue
|
||||||
|
if item.socket_type not in FRAGILE_TYPES:
|
||||||
|
continue
|
||||||
|
sid = item.identifier
|
||||||
|
if sid in mod and mod[sid] is not None:
|
||||||
|
snapshot[sid] = mod[sid]
|
||||||
|
# Debug output to verify we grab the material
|
||||||
|
# print(f" [SNAPSHOT] {obj.name} -> {item.name}: {mod[sid]}")
|
||||||
|
return snapshot
|
||||||
|
|
||||||
|
|
||||||
|
def _restore_fragile_sockets(mod, snapshot):
|
||||||
|
"""Restore Material/Object sockets that got wiped by override re-eval."""
|
||||||
|
restored = 0
|
||||||
|
for sid, value in snapshot.items():
|
||||||
|
current = mod[sid] if sid in mod else None
|
||||||
|
# Force restore if the current value no longer matches our snapshot
|
||||||
|
if current != value:
|
||||||
|
try:
|
||||||
|
mod[sid] = value
|
||||||
|
restored += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(f" [RESTORE FAILED] {sid}: {e}")
|
||||||
|
return restored
|
||||||
|
|
||||||
|
|
||||||
def fix_lib_overrides():
|
def fix_lib_overrides():
|
||||||
fixed = 0
|
fixed = 0
|
||||||
for obj in bpy.data.objects:
|
for obj in bpy.data.objects:
|
||||||
@@ -28,14 +60,19 @@ def fix_lib_overrides():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
ng = mod.node_group
|
ng = mod.node_group
|
||||||
name_to_sid = {}
|
|
||||||
iface = getattr(ng, 'interface', None)
|
iface = getattr(ng, 'interface', None)
|
||||||
if iface and hasattr(iface, 'items_tree'):
|
if not iface or not hasattr(iface, 'items_tree'):
|
||||||
for item in iface.items_tree:
|
continue
|
||||||
if item.item_type == 'SOCKET' and item.in_out == 'INPUT':
|
|
||||||
name_to_sid[item.name] = (item.identifier, item.socket_type)
|
|
||||||
|
|
||||||
for item in (getattr(iface, 'items_tree', []) if iface else []):
|
# Snapshot fragile sockets BEFORE any writes
|
||||||
|
snapshot = _snapshot_fragile_sockets(obj, mod, iface)
|
||||||
|
|
||||||
|
name_to_sid = {}
|
||||||
|
for item in iface.items_tree:
|
||||||
|
if item.item_type == 'SOCKET' and item.in_out == 'INPUT':
|
||||||
|
name_to_sid[item.name] = (item.identifier, item.socket_type)
|
||||||
|
|
||||||
|
for item in iface.items_tree:
|
||||||
if item.item_type != 'SOCKET' or item.in_out != 'INPUT':
|
if item.item_type != 'SOCKET' or item.in_out != 'INPUT':
|
||||||
continue
|
continue
|
||||||
sid = item.identifier
|
sid = item.identifier
|
||||||
@@ -54,29 +91,51 @@ def fix_lib_overrides():
|
|||||||
ng_name = ng.name
|
ng_name = ng.name
|
||||||
if ng_name == "Add Shader v1.0":
|
if ng_name == "Add Shader v1.0":
|
||||||
if "Filter by ID" in name_to_sid:
|
if "Filter by ID" in name_to_sid:
|
||||||
mod[name_to_sid["Filter by ID"][0]] = True
|
sid = name_to_sid["Filter by ID"][0]
|
||||||
fixed += 1
|
if mod.get(sid) != True:
|
||||||
|
mod[sid] = True
|
||||||
|
fixed += 1
|
||||||
if "ID" in name_to_sid and name_to_sid["ID"][1] == "NodeSocketString":
|
if "ID" in name_to_sid and name_to_sid["ID"][1] == "NodeSocketString":
|
||||||
mod[name_to_sid["ID"][0]] = "Index"
|
sid = name_to_sid["ID"][0]
|
||||||
fixed += 1
|
if mod.get(sid) != "Index":
|
||||||
|
mod[sid] = "Index"
|
||||||
|
fixed += 1
|
||||||
elif ng_name in ["Add Shaders by Index v1.0", "Make Material", "Make Labels"]:
|
elif ng_name in ["Add Shaders by Index v1.0", "Make Material", "Make Labels"]:
|
||||||
if "ID" in name_to_sid and name_to_sid["ID"][1] == "NodeSocketString":
|
if "ID" in name_to_sid and name_to_sid["ID"][1] == "NodeSocketString":
|
||||||
mod[name_to_sid["ID"][0]] = "Index"
|
sid = name_to_sid["ID"][0]
|
||||||
fixed += 1
|
if mod.get(sid) != "Index":
|
||||||
|
mod[sid] = "Index"
|
||||||
|
fixed += 1
|
||||||
if ng_name == "Make Labels" and "Shrinkwrap" in name_to_sid:
|
if ng_name == "Make Labels" and "Shrinkwrap" in name_to_sid:
|
||||||
mod[name_to_sid["Shrinkwrap"][0]] = True
|
sid = name_to_sid["Shrinkwrap"][0]
|
||||||
fixed += 1
|
if mod.get(sid) != True:
|
||||||
|
mod[sid] = True
|
||||||
|
fixed += 1
|
||||||
elif ng_name == "Make attached":
|
elif ng_name == "Make attached":
|
||||||
if "Reset Children" in name_to_sid:
|
if "Reset Children" in name_to_sid:
|
||||||
mod[name_to_sid["Reset Children"][0]] = True
|
sid = name_to_sid["Reset Children"][0]
|
||||||
fixed += 1
|
if mod.get(sid) != True:
|
||||||
|
mod[sid] = True
|
||||||
|
fixed += 1
|
||||||
if "Separate Children" in name_to_sid:
|
if "Separate Children" in name_to_sid:
|
||||||
mod[name_to_sid["Separate Children"][0]] = True
|
sid = name_to_sid["Separate Children"][0]
|
||||||
fixed += 1
|
if mod.get(sid) != True:
|
||||||
|
mod[sid] = True
|
||||||
|
fixed += 1
|
||||||
elif ng_name == "Proxy v1.0":
|
elif ng_name == "Proxy v1.0":
|
||||||
if "Reset Children" in name_to_sid:
|
if "Reset Children" in name_to_sid:
|
||||||
mod[name_to_sid["Reset Children"][0]] = True
|
sid = name_to_sid["Reset Children"][0]
|
||||||
fixed += 1
|
if mod.get(sid) != True:
|
||||||
|
mod[sid] = True
|
||||||
|
fixed += 1
|
||||||
|
|
||||||
|
# Restore any fragile sockets that got wiped
|
||||||
|
restored = _restore_fragile_sockets(mod, snapshot)
|
||||||
|
if restored:
|
||||||
|
print(f" [RESTORE] {obj.name}/{mod.name}: "
|
||||||
|
f"restored {restored} Material/Object sockets")
|
||||||
|
fixed += restored
|
||||||
|
|
||||||
return fixed
|
return fixed
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user