fix(utils): only assign socket values if they differ to prevent library override reload wipes
This commit is contained in:
61
utils.py
61
utils.py
@@ -17,12 +17,7 @@ def silence_puresky():
|
||||
|
||||
|
||||
def _snapshot_fragile_sockets(obj, mod, iface):
|
||||
"""Snapshot Material/Object sockets before modifying any override.
|
||||
|
||||
Writing to ANY mod[sid] on a GeoNode modifier can trigger Blender
|
||||
to re-evaluate ALL library overrides on that modifier, wiping
|
||||
Material and Object sockets back to their library defaults (NONE).
|
||||
"""
|
||||
"""Snapshot Material/Object sockets before modifying any override."""
|
||||
FRAGILE_TYPES = {'NodeSocketMaterial', 'NodeSocketObject'}
|
||||
snapshot = {}
|
||||
for item in iface.items_tree:
|
||||
@@ -33,6 +28,8 @@ def _snapshot_fragile_sockets(obj, mod, iface):
|
||||
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
|
||||
|
||||
|
||||
@@ -41,9 +38,13 @@ def _restore_fragile_sockets(mod, snapshot):
|
||||
restored = 0
|
||||
for sid, value in snapshot.items():
|
||||
current = mod[sid] if sid in mod else None
|
||||
if current is None and value is not None:
|
||||
mod[sid] = value
|
||||
restored += 1
|
||||
# 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
|
||||
|
||||
|
||||
@@ -90,29 +91,43 @@ def fix_lib_overrides():
|
||||
ng_name = ng.name
|
||||
if ng_name == "Add Shader v1.0":
|
||||
if "Filter by ID" in name_to_sid:
|
||||
mod[name_to_sid["Filter by ID"][0]] = True
|
||||
fixed += 1
|
||||
sid = name_to_sid["Filter by ID"][0]
|
||||
if mod.get(sid) != True:
|
||||
mod[sid] = True
|
||||
fixed += 1
|
||||
if "ID" in name_to_sid and name_to_sid["ID"][1] == "NodeSocketString":
|
||||
mod[name_to_sid["ID"][0]] = "Index"
|
||||
fixed += 1
|
||||
sid = name_to_sid["ID"][0]
|
||||
if mod.get(sid) != "Index":
|
||||
mod[sid] = "Index"
|
||||
fixed += 1
|
||||
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":
|
||||
mod[name_to_sid["ID"][0]] = "Index"
|
||||
fixed += 1
|
||||
sid = name_to_sid["ID"][0]
|
||||
if mod.get(sid) != "Index":
|
||||
mod[sid] = "Index"
|
||||
fixed += 1
|
||||
if ng_name == "Make Labels" and "Shrinkwrap" in name_to_sid:
|
||||
mod[name_to_sid["Shrinkwrap"][0]] = True
|
||||
fixed += 1
|
||||
sid = name_to_sid["Shrinkwrap"][0]
|
||||
if mod.get(sid) != True:
|
||||
mod[sid] = True
|
||||
fixed += 1
|
||||
elif ng_name == "Make attached":
|
||||
if "Reset Children" in name_to_sid:
|
||||
mod[name_to_sid["Reset Children"][0]] = True
|
||||
fixed += 1
|
||||
sid = name_to_sid["Reset Children"][0]
|
||||
if mod.get(sid) != True:
|
||||
mod[sid] = True
|
||||
fixed += 1
|
||||
if "Separate Children" in name_to_sid:
|
||||
mod[name_to_sid["Separate Children"][0]] = True
|
||||
fixed += 1
|
||||
sid = name_to_sid["Separate Children"][0]
|
||||
if mod.get(sid) != True:
|
||||
mod[sid] = True
|
||||
fixed += 1
|
||||
elif ng_name == "Proxy v1.0":
|
||||
if "Reset Children" in name_to_sid:
|
||||
mod[name_to_sid["Reset Children"][0]] = True
|
||||
fixed += 1
|
||||
sid = name_to_sid["Reset Children"][0]
|
||||
if mod.get(sid) != True:
|
||||
mod[sid] = True
|
||||
fixed += 1
|
||||
|
||||
# Restore any fragile sockets that got wiped
|
||||
restored = _restore_fragile_sockets(mod, snapshot)
|
||||
|
||||
Reference in New Issue
Block a user