Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
fix: preserve ControlNet selection on reload and gate queue reset to avoid data loss
sakalond545fa3ab35cb
diff --git a/stablegen/core/load_handlers.py b/stablegen/core/load_handlers.pyindex 22457d4..1c48b12 100644--- a/stablegen/core/load_handlers.py+++ b/stablegen/core/load_handlers.py@@ -47,6 +47,17 @@ def load_handler(dummy):default_unit = scene.controlnet_units.add()default_unit.unit_type = 'depth'+ # Restore ControlNet unit selections from backup+ if hasattr(scene, "controlnet_units"):+ for unit in scene.controlnet_units:+ backup = getattr(unit, "model_name_backup", "")+ if backup and backup not in ("REFRESH", "NO_ASSIGNED", "NO_PREFS"):+ try:+ unit.model_name = backup+ except TypeError:+ # Model not in enum items yet, which is fine+ pass+# Default LoRA unitif hasattr(scene, "lora_units") and not scene.lora_units:default_lora_filename_to_find = Nonediff --git a/stablegen/mesh_gen/trellis2.py b/stablegen/mesh_gen/trellis2.pyindex 4e52d63..c843a38 100644--- a/stablegen/mesh_gen/trellis2.py+++ b/stablegen/mesh_gen/trellis2.py@@ -352,6 +352,8 @@ class Trellis2Generate(bpy.types.Operator):# --- Clean hierarchy, unparent meshes, and remove GLTF/GLB structural empties ---imported_objects = [obj for obj in context.selected_objects]+ for obj in imported_objects:+ obj["sg_generated"] = Truemesh_objects = [obj for obj in imported_objects if obj.type == 'MESH']empty_objects = [obj for obj in imported_objects if obj.type == 'EMPTY']diff --git a/stablegen/ui/model_units.py b/stablegen/ui/model_units.pyindex a44d6a5..4ffedc3 100644--- a/stablegen/ui/model_units.py+++ b/stablegen/ui/model_units.py@@ -43,6 +43,8 @@ def update_union(self, context):def update_controlnet(self, context):+ if hasattr(self, "model_name") and self.model_name and self.model_name not in ("REFRESH", "NO_ASSIGNED", "NO_PREFS"):+ self.model_name_backup = self.model_nameupdate_parameters(self, context)update_union(self, context)return None@@ -73,7 +75,20 @@ def get_controlnet_models(context, unit_type):return [("NO_ASSIGNED", f"No models assigned to '{unit_type}'","Assign types in Addon Preferences or Refresh")]- items.sort(key=lambda x: x[1])+ # Sort compatible models first based on the current architecture mode+ scene = context.scene if hasattr(context, "scene") else None+ arch = getattr(scene, "architecture_mode", "sdxl") if scene else "sdxl"+ is_flux = "flux" in arch.lower()++ def sort_key(item_tuple):+ name_lower = item_tuple[0].lower()+ if is_flux:+ is_compat = ("flux" in name_lower)+ else:+ is_compat = ("flux" not in name_lower)+ return (-int(is_compat), item_tuple[1].lower())++ items.sort(key=sort_key)return items@@ -100,6 +115,11 @@ class ControlNetUnit(bpy.types.PropertyGroup):items=lambda self, context: get_controlnet_models(context, self.unit_type),update=update_controlnet) # type: ignore+ model_name_backup: bpy.props.StringProperty(+ name="Model Name Backup",+ description="Backup of the selected ControlNet model name",+ default=""+ ) # type: ignorestrength: bpy.props.FloatProperty(name="Strength",description="Strength of the ControlNet effect",diff --git a/stablegen/ui/queue.py b/stablegen/ui/queue.pyindex b50e96c..eafad48 100644--- a/stablegen/ui/queue.py+++ b/stablegen/ui/queue.py@@ -318,6 +318,9 @@ class SceneQueueAdd(bpy.types.Operator):# BEFORE saving so the copy carries the correct value even if# the dynamic Enum resolves wrong on re-open (stale item cache).scene.sg_model_name_backup = scene.model_name+ for unit in scene.controlnet_units:+ if unit.model_name and unit.model_name not in ("REFRESH", "NO_ASSIGNED", "NO_PREFS"):+ unit.model_name_backup = unit.model_nametry:bpy.ops.wm.save_as_mainfile(filepath=copy_path, copy=True)except Exception as e:@@ -544,11 +547,19 @@ class SceneQueueInvalidate(bpy.types.Operator):self.report({'ERROR'}, f"Failed to open snapshot: {e}")return {'CANCELLED'}- # Remove all mesh objects and cameras from the scene+ # Remove generated objects only if in trellis2 mode; preserve source meshes/cameras in texturingscene = bpy.context.scene- to_remove = [obj for obj in scene.objects if obj.type in {'MESH', 'CAMERA', 'EMPTY'}]- for obj in to_remove:- bpy.data.objects.remove(obj, do_unlink=True)+ arch_mode = getattr(scene, 'architecture_mode', 'sdxl')+ if arch_mode == 'trellis2':+ to_remove = []+ for obj in scene.objects:+ if obj.get("sg_generated") or obj.name.lower().startswith("trellis2") or obj.type == 'EMPTY':+ to_remove.append(obj)+ for obj in to_remove:+ try:+ bpy.data.objects.remove(obj, do_unlink=True)+ except Exception as err:+ print(f"[Queue] Failed to remove generated object {obj.name}: {err}")# Purge orphaned datafor block_attr in ('meshes', 'cameras', 'materials', 'images'):