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):
|
def _snapshot_fragile_sockets(obj, mod, iface):
|
||||||
"""Snapshot Material/Object sockets before modifying any override.
|
"""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).
|
|
||||||
"""
|
|
||||||
FRAGILE_TYPES = {'NodeSocketMaterial', 'NodeSocketObject'}
|
FRAGILE_TYPES = {'NodeSocketMaterial', 'NodeSocketObject'}
|
||||||
snapshot = {}
|
snapshot = {}
|
||||||
for item in iface.items_tree:
|
for item in iface.items_tree:
|
||||||
@@ -33,6 +28,8 @@ def _snapshot_fragile_sockets(obj, mod, iface):
|
|||||||
sid = item.identifier
|
sid = item.identifier
|
||||||
if sid in mod and mod[sid] is not None:
|
if sid in mod and mod[sid] is not None:
|
||||||
snapshot[sid] = mod[sid]
|
snapshot[sid] = mod[sid]
|
||||||
|
# Debug output to verify we grab the material
|
||||||
|
# print(f" [SNAPSHOT] {obj.name} -> {item.name}: {mod[sid]}")
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
|
|
||||||
@@ -41,9 +38,13 @@ def _restore_fragile_sockets(mod, snapshot):
|
|||||||
restored = 0
|
restored = 0
|
||||||
for sid, value in snapshot.items():
|
for sid, value in snapshot.items():
|
||||||
current = mod[sid] if sid in mod else None
|
current = mod[sid] if sid in mod else None
|
||||||
if current is None and value is not None:
|
# Force restore if the current value no longer matches our snapshot
|
||||||
mod[sid] = value
|
if current != value:
|
||||||
restored += 1
|
try:
|
||||||
|
mod[sid] = value
|
||||||
|
restored += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(f" [RESTORE FAILED] {sid}: {e}")
|
||||||
return restored
|
return restored
|
||||||
|
|
||||||
|
|
||||||
@@ -90,29 +91,43 @@ 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
|
# Restore any fragile sockets that got wiped
|
||||||
restored = _restore_fragile_sockets(mod, snapshot)
|
restored = _restore_fragile_sockets(mod, snapshot)
|
||||||
|
|||||||
Reference in New Issue
Block a user