Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
update panel for qwen, add custom qwen guidance prompts, add initial only external image mode, add custom qwen lora and checkpoint support, update version
sakalondb5f7f88e01aa
diff --git a/stablegen/__init__.py b/stablegen/__init__.pyindex 6897757..4b9fe02 100755--- a/stablegen/__init__.py+++ b/stablegen/__init__.py@@ -1,6 +1,6 @@""" This script registers the addon. """import bpy # pylint: disable=import-error-from .stablegen import StableGenPanel, ApplyPreset, SavePreset, DeletePreset, get_preset_items, update_parameters+from .stablegen import StableGenPanel, ApplyPreset, SavePreset, DeletePreset, get_preset_items, update_parameters, ResetQwenPromptfrom .render_tools import BakeTextures, AddCameras, SwitchMaterial, ExportOrbitGIF, CollectCameraPrompts, CameraPromptItemfrom .utils import AddHDRI, ApplyModifiers, CurvesToMeshfrom .generator import ComfyUIGenerate, Reproject, Regenerate@@ -14,7 +14,7 @@ bl_info = {"name": "StableGen","category": "Object","author": "Ondrej Sakala",- "version": (0, 0, 9),+ "version": (0, 1, 0),'blender': (4, 2, 0)}@@ -23,6 +23,7 @@ classes = [ApplyPreset,SavePreset,DeletePreset,+ ResetQwenPrompt,BakeTextures,AddCameras,SwitchMaterial,@@ -40,6 +41,8 @@ classes = [# Global caches for model lists fetched via API_cached_checkpoint_list = [("NONE_AVAILABLE", "None available", "Fetch models from server")]_cached_lora_list = [("NONE_AVAILABLE", "None available", "Fetch models from server")]+_cached_checkpoint_architecture = None+_pending_checkpoint_refresh_architecture = Nonedef update_combined(self, context):# This now primarily updates the preset status and might trigger Enum updates implicitly@@ -711,37 +714,44 @@ class RefreshCheckpointList(bpy.types.Operator):return prefs and prefs.preferences.server_addressdef execute(self, context):- global _cached_checkpoint_list+ global _cached_checkpoint_list, _cached_checkpoint_architectureitems = []model_list = None # Initialize to None+ architecture = getattr(context.scene, "model_architecture", "sdxl")+# Determine endpoint based on current architecture setting- if context.scene.model_architecture == 'sdxl':+ if architecture == 'sdxl':model_list = fetch_from_comfyui_api(context, "/models/checkpoints")model_type_desc = "Checkpoint"- elif context.scene.model_architecture == 'flux1':+ elif architecture == 'flux1':model_list = fetch_from_comfyui_api(context, "/models/unet_gguf")- to_extend = fetch_from_comfyui_api(context, "/models/diffusion_models")- if to_extend:- model_list.extend(to_extend)+ if model_list is not None:+ to_extend = fetch_from_comfyui_api(context, "/models/diffusion_models")+ if to_extend:+ model_list.extend(to_extend)model_type_desc = "UNET"- elif context.scene.model_architecture == 'qwen_image_edit':+ elif architecture == 'qwen_image_edit':model_list = fetch_from_comfyui_api(context, "/models/unet_gguf")model_type_desc = "UNET (GGUF)"if model_list is None: # Config error_cached_checkpoint_list = [("NO_SERVER", "Set Server Address", "Cannot fetch")]+ _cached_checkpoint_architecture = Noneself.report({'ERROR'}, "Cannot fetch models. Check server address.")# Force UI update if possible- context.area.tag_redraw()+ if context.area:+ context.area.tag_redraw()return {'CANCELLED'}elif not model_list: # API ok, but empty list_cached_checkpoint_list = [("NONE_FOUND", f"No {model_type_desc}s Found", "Server list is empty")]+ _cached_checkpoint_architecture = architectureself.report({'WARNING'}, f"No {model_type_desc} models found on server.")else: # Models foundfor model_name in sorted(model_list):items.append((model_name, model_name, f"{model_type_desc}: {model_name}"))_cached_checkpoint_list = items+ _cached_checkpoint_architecture = architectureself.report({'INFO'}, f"Refreshed {model_type_desc} list ({len(items)} found).")# Reset Logic after refresh@@ -1015,6 +1025,7 @@ class RemoveLoRAUnit(bpy.types.Operator):# load handler to set default ControlNet and LoRA units on first load@persistentdef load_handler(dummy):+ global _cached_checkpoint_architecture, _pending_checkpoint_refresh_architectureif bpy.context.scene:scene = bpy.context.sceneaddon_prefs = bpy.context.preferences.addons[__package__].preferences@@ -1023,7 +1034,19 @@ def load_handler(dummy):default_unit.unit_type = 'depth'# Default LoRA Unitif hasattr(scene, "lora_units") and not scene.lora_units:- default_lora_filename_to_find = 'sdxl_lightning_8step_lora.safetensors'+ default_lora_filename_to_find = None+ model_strength = 1.0+ clip_strength = 1.0++ if scene.model_architecture == 'sdxl':+ default_lora_filename_to_find = 'sdxl_lightning_8step_lora.safetensors'+ elif scene.model_architecture == 'qwen_image_edit':+ default_lora_filename_to_find = 'Qwen-Image-Lightning-4steps-V1.0.safetensors'+ clip_strength = 0.0 # Qwen uses model-only LoRA++ if not default_lora_filename_to_find:+ return # No default LoRA for this architecture+all_available_loras_enums = get_lora_models(scene, bpy.context)found_lora_identifier_to_load = None@@ -1032,7 +1055,7 @@ def load_handler(dummy):# Check if the identifier (which is the relative path) ends with the desired filenameif identifier.endswith(default_lora_filename_to_find):# Ensure it's not a placeholder/error identifier- if identifier not in ["NONE_AVAILABLE", "NO_COMFYUI_DIR_LORA", "NO_LORAS_SUBDIR", "PERM_ERROR", "SCAN_ERROR"]:+ if identifier not in ["NONE_AVAILABLE", "NO_COMFYUI_DIR_LORA", "NO_LORAS_SUBDIR", "PERM_ERROR", "SCAN_ERROR", "NONE_FOUND"]:found_lora_identifier_to_load = identifierbreak@@ -1041,8 +1064,8 @@ def load_handler(dummy):try:new_lora_unit = scene.lora_units.add()new_lora_unit.model_name = found_lora_identifier_to_load- new_lora_unit.model_strength = 1.0- new_lora_unit.clip_strength = 1.0+ new_lora_unit.model_strength = model_strength+ new_lora_unit.clip_strength = clip_strength# print(f"StableGen Load Handler: Default LoRA '{found_lora_identifier_to_load}' added.")except TypeError:# This can happen if Enum items are not fully synchronized at this early stage of loading.@@ -1054,6 +1077,26 @@ def load_handler(dummy):if new_lora_unit and scene.lora_units and new_lora_unit == scene.lora_units[-1]:scene.lora_units.remove(len(scene.lora_units)-1)+ # Ensure checkpoint cache matches the scene architecture that just loaded+ current_architecture = getattr(scene, "model_architecture", None)+ prefs_wrapper = bpy.context.preferences.addons.get(__package__)+ if current_architecture and prefs_wrapper:+ prefs = prefs_wrapper.preferences+ if prefs.server_address and current_architecture != _cached_checkpoint_architecture and _pending_checkpoint_refresh_architecture != current_architecture:++ def _refresh_checkpoint_for_architecture():+ global _pending_checkpoint_refresh_architecture+ try:+ bpy.ops.stablegen.refresh_checkpoint_list('INVOKE_DEFAULT')+ except Exception as timer_error:+ print(f"StableGen Load Handler: Failed to refresh checkpoints for '{current_architecture}': {timer_error}")+ finally:+ _pending_checkpoint_refresh_architecture = None+ return None++ _pending_checkpoint_refresh_architecture = current_architecture+ bpy.app.timers.register(_refresh_checkpoint_for_architecture, first_interval=0.2)+classes_to_append = [CheckServerStatus, RefreshCheckpointList, RefreshLoRAList, STABLEGEN_UL_ControlNetMappingList, ControlNetModelMappingItem, RefreshControlNetMappings, StableGenAddonPreferences, ControlNetUnit, LoRAUnit, AddControlNetUnit, RemoveControlNetUnit, AddLoRAUnit, RemoveLoRAUnit]for cls in classes_to_append:classes.append(cls)@@ -1652,6 +1695,48 @@ def register():update=update_parameters)+ bpy.types.Scene.qwen_external_style_initial_only = bpy.props.BoolProperty(+ name="External for Initial Only",+ description="Use the external style image for the first image, then use the previously generated image for subsequent images",+ default=False,+ update=update_parameters+ )++ bpy.types.Scene.qwen_use_custom_prompts = bpy.props.BoolProperty(+ name="Use Custom Qwen Prompts",+ description="Enable to override the default guidance prompts for the Qwen Image Edit workflow",+ default=False,+ update=update_parameters+ )++ bpy.types.Scene.qwen_custom_prompt_initial = bpy.props.StringProperty(+ name="Initial Image Prompt",+ description="Custom prompt for the first generated image. Use {main_prompt} to insert the main prompt text.",+ default="Change and transfer the format of '{main_prompt}' in image 1 to the style from image 2",+ update=update_parameters+ )++ bpy.types.Scene.qwen_custom_prompt_seq_none = bpy.props.StringProperty(+ name="Sequential Prompt (No Context)",+ description="Custom prompt for subsequent images when Context Render is 'Disabled'. Use {main_prompt} to insert the main prompt text.",+ default="Change and transfer the format of '{main_prompt}' in image 1 to the style from image 2",+ update=update_parameters+ )++ bpy.types.Scene.qwen_custom_prompt_seq_replace = bpy.props.StringProperty(+ name="Sequential Prompt (Replace Style)",+ description="Custom prompt for subsequent images when Context Render is 'Replace Style'. Use {main_prompt} to insert the main prompt text.",+ default="Change and transfer the format of image 1 to '{main_prompt}'. Replace all solid magenta areas in image 2. Replace the background with solid gray. The style from image 2 should smoothly continue into the previously magenta areas.",+ update=update_parameters+ )++ bpy.types.Scene.qwen_custom_prompt_seq_additional = bpy.props.StringProperty(+ name="Sequential Prompt (Additional Context)",+ description="Custom prompt for subsequent images when Context Render is 'Additional Context'. Use {main_prompt} to insert the main prompt text.",+ default="Change and transfer the format of image 1 to '{main_prompt}'. Replace all solid magenta areas in image 2. Replace the background with solid gray. The style from image 2 should smoothly continue into the previously magenta areas. Image 3 represents the overall style of the object.",+ update=update_parameters+ )+bpy.types.Scene.output_timestamp = bpy.props.StringProperty(name="Output Timestamp",description="Timestamp for generation output directory",@@ -1881,6 +1966,12 @@ def unregister():del bpy.types.Scene.qwen_context_render_modedel bpy.types.Scene.qwen_use_external_style_imagedel bpy.types.Scene.qwen_external_style_image+ del bpy.types.Scene.qwen_external_style_initial_only+ del bpy.types.Scene.qwen_use_custom_prompts+ del bpy.types.Scene.qwen_custom_prompt_initial+ del bpy.types.Scene.qwen_custom_prompt_seq_none+ del bpy.types.Scene.qwen_custom_prompt_seq_replace+ del bpy.types.Scene.qwen_custom_prompt_seq_additionalfor cls in reversed(classes):bpy.utils.unregister_class(cls)diff --git a/stablegen/blender_manifest.toml b/stablegen/blender_manifest.tomlindex aaae525..97604c4 100644--- a/stablegen/blender_manifest.toml+++ b/stablegen/blender_manifest.toml@@ -1,6 +1,6 @@schema_version = "1.0.0"id = "stablegen"-version = "0.0.9"+version = "0.1.0"name = "StableGen"tagline = "AI-Powered Texturing"maintainer = "Ondrej Sakala <[email protected]>"diff --git a/stablegen/generator.py b/stablegen/generator.pyindex a46b3f4..4399f6b 100644--- a/stablegen/generator.py+++ b/stablegen/generator.py@@ -411,6 +411,9 @@ class ComfyUIGenerate(bpy.types.Operator):print("Executing ComfyUI Generation")+ if context.scene.model_architecture == 'qwen_image_edit':+ context.scene.generation_method = 'sequential' # Force sequential for Qwen Image Edit+render = bpy.context.scene.renderresolution_x = render.resolution_xresolution_y = render.resolution_ydiff --git a/stablegen/stablegen.py b/stablegen/stablegen.pyindex 232d179..231b480 100755--- a/stablegen/stablegen.py+++ b/stablegen/stablegen.py@@ -70,6 +70,12 @@ GEN_PARAMETERS = ["qwen_use_external_style_image","qwen_external_style_image","qwen_context_render_mode",+ "qwen_external_style_initial_only",+ "qwen_use_custom_prompts",+ "qwen_custom_prompt_initial",+ "qwen_custom_prompt_seq_none",+ "qwen_custom_prompt_seq_replace",+ "qwen_custom_prompt_seq_additional",]def get_preset_items(self, context):@@ -352,9 +358,10 @@ class StableGenPanel(bpy.types.Panel):split.prop(scene, "model_architecture", text="")# Split for generation method- split = params_container.split(factor=0.5)- split.label(text="Generation Mode:")- split.prop(scene, "generation_method", text="")+ if not scene.model_architecture.startswith("qwen"): # Qwen forces sequential mode+ split = params_container.split(factor=0.5)+ split.label(text="Generation Mode:")+ split.prop(scene, "generation_method", text="")# Split for object selectionsplit = params_container.split(factor=0.5)@@ -437,7 +444,8 @@ class StableGenPanel(bpy.types.Panel):sub_row = unit_box.row(align=True)sub_row.prop(lora_unit, "model_strength", text="Model Strength")- sub_row.prop(lora_unit, "clip_strength", text="CLIP Strength")+ if not scene.model_architecture.startswith("qwen"): # Qwen uses model only loras+ sub_row.prop(lora_unit, "clip_strength", text="CLIP Strength")# Icon to indicate selection more clearly alongside the alert stateselect_icon = 'CHECKBOX_HLT' if is_selected_lora else 'CHECKBOX_DEHLT'@@ -511,76 +519,84 @@ class StableGenPanel(bpy.types.Panel):row.prop(scene, "bake_unwrap_overlap_only", text="Unwrap only overlapping UVs", toggle=True, icon="UV_SYNC_SELECT")# --- Image Guidance (IPAdapter & ControlNet) ---- content_box = draw_collapsible_section(advanced_params_box, "show_image_guidance_settings", "Image Guidance (IPAdapter & ControlNet)", icon="MODIFIER")+ if scene.model_architecture in ['sdxl', 'flux1']:+ content_box = draw_collapsible_section(advanced_params_box, "show_image_guidance_settings", "Image Guidance (IPAdapter & ControlNet)", icon="MODIFIER")+ else: # Qwen Image Edit+ content_box = draw_collapsible_section(advanced_params_box, "show_image_guidance_settings", "Qwen-Image-Edit Guidance", icon="MODIFIER")if content_box:if scene.model_architecture == 'qwen_image_edit':- qwen_box = content_box.box()- row = qwen_box.row()- row.alignment = 'CENTER'- row.label(text="Qwen Image Edit Guidance", icon="IMAGE_DATA")-- split = qwen_box.split(factor=0.5)+ split = content_box.split(factor=0.5)split.label(text="Guidance Map:")split.prop(scene, "qwen_guidance_map_type", text="")- row = qwen_box.row()- row.prop(scene, "qwen_use_external_style_image", text="Use External Style Image", toggle=True, icon="FILE_IMAGE")+ row = content_box.row()+ row.prop(scene, "qwen_use_external_style_image", text="Use External Image as Style", toggle=True, icon="FILE_IMAGE")if scene.qwen_use_external_style_image:- row = qwen_box.row()+ style_box = content_box.box()+ row = style_box.row()row.prop(scene, "qwen_external_style_image", text="Style Image")+ row = style_box.row()+ row.prop(scene, "qwen_external_style_initial_only", text="External for Initial Only", toggle=True)- if scene.generation_method == 'sequential':- split = qwen_box.split(factor=0.5)- split.label(text="Context Render:")- split.prop(scene, "qwen_context_render_mode", text="")+ if scene.qwen_use_external_style_image and scene.qwen_external_style_initial_only:+ split = style_box.split(factor=0.5)+ split.label(text="Subsequent mode:")+ split.prop(scene, "sequential_ipadapter_mode", text="")- if scene.generation_method in ['sequential', 'separate']:- row = qwen_box.row()+ if not scene.qwen_use_external_style_image and scene.generation_method in ['sequential', 'separate']:+ row = content_box.row()row.prop(scene, "sequential_ipadapter", text="Use Previous Image as Style", toggle=True, icon="MODIFIER")if scene.sequential_ipadapter:- sub_box = qwen_box.box()- split = sub_box.split(factor=0.5)+ split = content_box.split(factor=0.5)split.label(text="Mode:")split.prop(scene, "sequential_ipadapter_mode", text="")- if scene.sequential_ipadapter_mode == 'recent':- sub_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")- sub_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")- # IPAdapter Parameters- if not scene.generation_method == 'uv_inpaint' and not scene.model_architecture == 'qwen_image_edit':- ipadapter_main_box = content_box.box() # Group IPAdapter settings together- if scene.model_architecture == 'flux1':- row = ipadapter_main_box.row()- row.prop(scene, "use_flux_lora", text="Use Flux Depth LoRA", toggle=True, icon="MODIFIER")- row = ipadapter_main_box.row()- row.prop(scene, "use_ipadapter", text="Use IPAdapter (External image)", toggle=True, icon="MOD_MULTIRES")- if scene.use_ipadapter:- sub_ip_box = ipadapter_main_box.box()- row = sub_ip_box.row()- row.prop(scene, "ipadapter_image", text="Image")- row = sub_ip_box.row()- row.prop(scene, "ipadapter_strength", text="Strength")- if width_mode == 'narrow':- row = sub_ip_box.row()- row.prop(scene, "ipadapter_start", text="Start")- if width_mode == 'narrow':- row = sub_ip_box.row()- row.prop(scene, "ipadapter_end", text="End")- split = sub_ip_box.split(factor=0.5)- if context.scene.model_architecture == 'sdxl':- split.label(text="Weight Type:")- split.prop(scene, "ipadapter_weight_type", text="")-- if not scene.model_architecture == 'qwen_image_edit':- content_box.separator() # Separator between IPAdapter and ControlNet if both are shown- # ControlNet Parameters- if not (scene.model_architecture == 'flux1' and scene.use_flux_lora) and not scene.model_architecture == 'qwen_image_edit':- ctrl_box_group = content_box.box() # Group ControlNet settings together- row = ctrl_box_group.row()++ if scene.generation_method == 'sequential':+ split = content_box.split(factor=0.5)+ split.label(text="Context Render:")+ split.prop(scene, "qwen_context_render_mode", text="")++ row = content_box.row()+ row.prop(scene, "qwen_use_custom_prompts", text="Custom Guidance Prompts", toggle=True, icon="TEXT")+ if scene.qwen_use_custom_prompts:+ custom_prompt_box = content_box.box()++ # Initial Image Prompt+ col = custom_prompt_box.column()+ col.label(text="Initial Image Prompt:")+ row = col.row(align=True)+ row.prop(scene, "qwen_custom_prompt_initial", text="")+ op = row.operator("stablegen.reset_qwen_prompt", text="", icon='FILE_REFRESH')+ op.prompt_type = 'initial'++ # Subsequent Images Prompt (conditional)+ if scene.generation_method == 'sequential':+ col = custom_prompt_box.column()+ col.label(text="Subsequent Images Prompt:")+ row = col.row(align=True)++ if scene.qwen_context_render_mode == 'NONE':+ row.prop(scene, "qwen_custom_prompt_seq_none", text="")+ op_prop = 'seq_none'+ elif scene.qwen_context_render_mode == 'REPLACE_STYLE':+ row.prop(scene, "qwen_custom_prompt_seq_replace", text="")+ op_prop = 'seq_replace'+ elif scene.qwen_context_render_mode == 'ADDITIONAL':+ row.prop(scene, "qwen_custom_prompt_seq_additional", text="")+ op_prop = 'seq_additional'++ op = row.operator("stablegen.reset_qwen_prompt", text="", icon='FILE_REFRESH')+ op.prompt_type = op_prop++ elif scene.model_architecture == 'sdxl' or scene.model_architecture == 'flux1':+ # ControlNet settings+ cn_box = content_box.box()+ row = cn_box.row()row.alignment = 'CENTER'row.label(text="ControlNet Units", icon="NODETREE")for i, unit in enumerate(scene.controlnet_units):- sub_unit_box = ctrl_box_group.box() # Each unit gets its own box+ sub_unit_box = cn_box.box() # Each unit gets its own boxrow = sub_unit_box.row()row.label(text=f"Unit: {unit.unit_type.replace('_', ' ').title()}", icon="DOT")row.alignment = 'LEFT'@@ -611,237 +627,237 @@ class StableGenPanel(bpy.types.Panel):row = sub_unit_box.row()row.prop(unit, "use_union_type", text="Set Union Type", toggle=True, icon="MOD_BOOLEAN")- btn_row = ctrl_box_group.row(align=True)+ btn_row = cn_box.row(align=True)if width_mode == 'wide':btn_row.operator("stablegen.add_controlnet_unit", text="Add Unit", icon="ADD")btn_row.operator("stablegen.remove_controlnet_unit", text="Remove Unit", icon="REMOVE")else:- ctrl_box_group.operator("stablegen.add_controlnet_unit", text="Add ControlNet Unit", icon="ADD")- ctrl_box_group.operator("stablegen.remove_controlnet_unit", text="Remove Last ControlNet Unit", icon="REMOVE")--- # --- Inpainting Options (Conditional) ---- if scene.generation_method == 'uv_inpaint' or scene.generation_method == 'sequential':- content_box = draw_collapsible_section(advanced_params_box, "show_masking_inpainting_settings", "Inpainting Options", icon="MOD_MASK")- if content_box: # content_box is the container for these settings- row = content_box.row()- row.prop(scene, "differential_diffusion", text="Use Differential Diffusion", toggle=True, icon="SMOOTHCURVE")-- if scene.differential_diffusion:+ cn_box.operator("stablegen.add_controlnet_unit", text="Add ControlNet Unit", icon="ADD")+ cn_box.operator("stablegen.remove_controlnet_unit", text="Remove Last ControlNet Unit", icon="REMOVE")++ if not scene.model_architecture == 'qwen_image_edit':+ # --- Inpainting Options (Conditional) ---+ if scene.generation_method == 'uv_inpaint' or scene.generation_method == 'sequential':+ content_box = draw_collapsible_section(advanced_params_box, "show_masking_inpainting_settings", "Inpainting Options", icon="MOD_MASK")+ if content_box: # content_box is the container for these settingsrow = content_box.row()- row.prop(scene, "differential_noise", text="Add Latent Noise Mask", toggle=True, icon="MOD_NOISE")-- if not (scene.differential_diffusion and not scene.differential_noise):- row = content_box.row()- row.prop(scene, "mask_blocky", text="Use Blocky Mask", icon="MOD_MASK")+ row.prop(scene, "differential_diffusion", text="Use Differential Diffusion", toggle=True, icon="SMOOTHCURVE")- if width_mode == 'narrow':+ if scene.differential_diffusion:row = content_box.row()-- row.prop(scene, "blur_mask", text="Blur Mask", toggle=True, icon="SURFACE_NSPHERE")+ row.prop(scene, "differential_noise", text="Add Latent Noise Mask", toggle=True, icon="MOD_NOISE")- if scene.blur_mask:+ if not (scene.differential_diffusion and not scene.differential_noise):row = content_box.row()- row.prop(scene, "blur_mask_radius", text="Blur Radius")+ row.prop(scene, "mask_blocky", text="Use Blocky Mask", icon="MOD_MASK")+if width_mode == 'narrow':row = content_box.row()- row.prop(scene, "blur_mask_sigma", text="Blur Sigma")++ row.prop(scene, "blur_mask", text="Blur Mask", toggle=True, icon="SURFACE_NSPHERE")- row = content_box.row() # Draw directly in content_box- row.prop(scene, "grow_mask_by", text="Grow Mask By")+ if scene.blur_mask:+ row = content_box.row()+ row.prop(scene, "blur_mask_radius", text="Blur Radius")+ if width_mode == 'narrow':+ row = content_box.row()+ row.prop(scene, "blur_mask_sigma", text="Blur Sigma")+ row = content_box.row() # Draw directly in content_box+ row.prop(scene, "grow_mask_by", text="Grow Mask By")- # --- Generation Mode Specifics ---- mode_specific_outer_box = draw_collapsible_section(advanced_params_box, "show_mode_specific_settings", "Generation Mode Specifics", icon="OPTIONS")- if mode_specific_outer_box: # This is the box where all mode-specific UIs should go-- # Grid Mode Parameters- if scene.generation_method == 'grid':- # Draw Grid parameters directly into mode_specific_outer_box- row = mode_specific_outer_box.row()- row.alignment = 'CENTER'- row.label(text="Grid Mode Parameters", icon="MESH_GRID")++ # --- Generation Mode Specifics ---+ mode_specific_outer_box = draw_collapsible_section(advanced_params_box, "show_mode_specific_settings", "Generation Mode Specifics", icon="OPTIONS")+ if mode_specific_outer_box: # This is the box where all mode-specific UIs should go- row = mode_specific_outer_box.row()- row.prop(scene, "refine_images", text="Refine Images", toggle=True, icon="SHADERFX")- if scene.refine_images:- split = mode_specific_outer_box.split(factor=0.5)- split.label(text="Refine Sampler:")- split.prop(scene, "refine_sampler", text="")-- split = mode_specific_outer_box.split(factor=0.5)- split.label(text="Refine Scheduler:")- split.prop(scene, "refine_scheduler", text="")+ # Grid Mode Parameters+ if scene.generation_method == 'grid':+ # Draw Grid parameters directly into mode_specific_outer_box+ row = mode_specific_outer_box.row()+ row.alignment = 'CENTER'+ row.label(text="Grid Mode Parameters", icon="MESH_GRID")row = mode_specific_outer_box.row()- row.prop(scene, "denoise", text="Denoise")- if width_mode == 'narrow':- row = mode_specific_outer_box.row()- row.prop(scene, "refine_cfg", text="Refine CFG")- if width_mode == 'narrow':+ row.prop(scene, "refine_images", text="Refine Images", toggle=True, icon="SHADERFX")+ if scene.refine_images:+ split = mode_specific_outer_box.split(factor=0.5)+ split.label(text="Refine Sampler:")+ split.prop(scene, "refine_sampler", text="")++ split = mode_specific_outer_box.split(factor=0.5)+ split.label(text="Refine Scheduler:")+ split.prop(scene, "refine_scheduler", text="")+row = mode_specific_outer_box.row()- row.prop(scene, "refine_steps", text="Refine Steps")+ row.prop(scene, "denoise", text="Denoise")+ if width_mode == 'narrow':+ row = mode_specific_outer_box.row()+ row.prop(scene, "refine_cfg", text="Refine CFG")+ if width_mode == 'narrow':+ row = mode_specific_outer_box.row()+ row.prop(scene, "refine_steps", text="Refine Steps")- row = mode_specific_outer_box.row()- split = mode_specific_outer_box.split(factor=0.25)- split.label(text="Refine Prompt:")- split.prop(scene, "refine_prompt", text="")-- split = mode_specific_outer_box.split(factor=0.5)- split.label(text="Refine Upscale:")- split.prop(scene, "refine_upscale_method", text="")+ row = mode_specific_outer_box.row()+ split = mode_specific_outer_box.split(factor=0.25)+ split.label(text="Refine Prompt:")+ split.prop(scene, "refine_prompt", text="")++ split = mode_specific_outer_box.split(factor=0.5)+ split.label(text="Refine Upscale:")+ split.prop(scene, "refine_upscale_method", text="")- # Separate Mode Parameters- elif scene.generation_method == 'separate':- row = mode_specific_outer_box.row()- row.alignment = 'CENTER'- row.label(text="Separate Mode Parameters", icon='FORCE_FORCE')-- row = mode_specific_outer_box.row()- row.prop(scene, "sequential_ipadapter", text="Use IPAdapter for Separate Mode", toggle=True, icon="MODIFIER")- if scene.sequential_ipadapter:- sub_ip_box_separate = mode_specific_outer_box.box()+ # Separate Mode Parameters+ elif scene.generation_method == 'separate':+ row = mode_specific_outer_box.row()+ row.alignment = 'CENTER'+ row.label(text="Separate Mode Parameters", icon='FORCE_FORCE')- split = sub_ip_box_separate.split(factor=0.5)- split.label(text="Mode:")- split.prop(scene, "sequential_ipadapter_mode", text="")+ row = mode_specific_outer_box.row()+ row.prop(scene, "sequential_ipadapter", text="Use IPAdapter for Separate Mode", toggle=True, icon="MODIFIER")+ if scene.sequential_ipadapter:+ sub_ip_box_separate = mode_specific_outer_box.box()++ split = sub_ip_box_separate.split(factor=0.5)+ split.label(text="Mode:")+ split.prop(scene, "sequential_ipadapter_mode", text="")++ if scene.sequential_ipadapter_mode == 'recent':+ sub_ip_box_separate.prop(scene, "sequential_desaturate_factor", text="Desaturate")+ sub_ip_box_separate.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")++ if context.scene.model_architecture != 'qwen_image_edit':+ split = sub_ip_box_separate.split(factor=0.5)+ if context.scene.model_architecture == 'sdxl':+ split.label(text="Weight Type:")+ split.prop(scene, "ipadapter_weight_type", text="")++ row = sub_ip_box_separate.row()+ row.prop(scene, "ipadapter_strength", text="Strength")+ if width_mode == 'narrow':+ row = sub_ip_box_separate.row()+ row.prop(scene, "ipadapter_start", text="Start")+ if width_mode == 'narrow':+ row = sub_ip_box_separate.row()+ row.prop(scene, "ipadapter_end", text="End")++ if context.scene.sequential_ipadapter_mode == 'first':+ row = sub_ip_box_separate.row()+ row.prop(scene, "sequential_ipadapter_regenerate", text="Regenerate First Image", toggle=True, icon="FILE_REFRESH")+ if context.scene.sequential_ipadapter_regenerate:+ row = sub_ip_box_separate.row()+ row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")- if scene.sequential_ipadapter_mode == 'recent':- sub_ip_box_separate.prop(scene, "sequential_desaturate_factor", text="Desaturate")- sub_ip_box_separate.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")+ # Refine Mode Parameters+ elif scene.generation_method == 'refine':+ row = mode_specific_outer_box.row()+ row.alignment = 'CENTER'+ row.label(text="Refine Mode Parameters", icon='SHADERFX')+ row = mode_specific_outer_box.row()+ row.prop(scene, "denoise", text="Denoise")+ row = mode_specific_outer_box.row()+ row.prop(scene, "refine_preserve", text="Preserve Original Textures", toggle=True, icon="TEXTURE")+ row = mode_specific_outer_box.row()+ row.prop(scene, "sequential_ipadapter", text="Use IPAdapter for Refine Mode", toggle=True, icon="MODIFIER")+ if scene.sequential_ipadapter:+ sub_ip_box_separate = mode_specific_outer_box.box()++ split = sub_ip_box_separate.split(factor=0.5)+ split.label(text="Mode:")+ split.prop(scene, "sequential_ipadapter_mode", text="")- if context.scene.model_architecture != 'qwen_image_edit':split = sub_ip_box_separate.split(factor=0.5)if context.scene.model_architecture == 'sdxl':split.label(text="Weight Type:")split.prop(scene, "ipadapter_weight_type", text="")-- row = sub_ip_box_separate.row()- row.prop(scene, "ipadapter_strength", text="Strength")- if width_mode == 'narrow':- row = sub_ip_box_separate.row()- row.prop(scene, "ipadapter_start", text="Start")- if width_mode == 'narrow':- row = sub_ip_box_separate.row()- row.prop(scene, "ipadapter_end", text="End")-- if context.scene.sequential_ipadapter_mode == 'first':+row = sub_ip_box_separate.row()- row.prop(scene, "sequential_ipadapter_regenerate", text="Regenerate First Image", toggle=True, icon="FILE_REFRESH")- if context.scene.sequential_ipadapter_regenerate:+ row.prop(scene, "ipadapter_strength", text="Strength")+ if width_mode == 'narrow':row = sub_ip_box_separate.row()- row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")-- # Refine Mode Parameters- elif scene.generation_method == 'refine':- row = mode_specific_outer_box.row()- row.alignment = 'CENTER'- row.label(text="Refine Mode Parameters", icon='SHADERFX')- row = mode_specific_outer_box.row()- row.prop(scene, "denoise", text="Denoise")- row = mode_specific_outer_box.row()- row.prop(scene, "refine_preserve", text="Preserve Original Textures", toggle=True, icon="TEXTURE")- row = mode_specific_outer_box.row()- row.prop(scene, "sequential_ipadapter", text="Use IPAdapter for Refine Mode", toggle=True, icon="MODIFIER")- if scene.sequential_ipadapter:- sub_ip_box_separate = mode_specific_outer_box.box()-- split = sub_ip_box_separate.split(factor=0.5)- split.label(text="Mode:")- split.prop(scene, "sequential_ipadapter_mode", text="")-- split = sub_ip_box_separate.split(factor=0.5)- if context.scene.model_architecture == 'sdxl':- split.label(text="Weight Type:")- split.prop(scene, "ipadapter_weight_type", text="")-- row = sub_ip_box_separate.row()- row.prop(scene, "ipadapter_strength", text="Strength")- if width_mode == 'narrow':- row = sub_ip_box_separate.row()- row.prop(scene, "ipadapter_start", text="Start")- if width_mode == 'narrow':- row = sub_ip_box_separate.row()- row.prop(scene, "ipadapter_end", text="End")-- if context.scene.sequential_ipadapter_mode == 'first':- row = sub_ip_box_separate.row()- row.prop(scene, "sequential_ipadapter_regenerate", text="Regenerate First Image", toggle=True, icon="FILE_REFRESH")- if context.scene.sequential_ipadapter_regenerate:+ row.prop(scene, "ipadapter_start", text="Start")+ if width_mode == 'narrow':row = sub_ip_box_separate.row()- row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")-- # UV Inpainting Parameters- elif scene.generation_method == 'uv_inpaint':- row = mode_specific_outer_box.row()- row.alignment = 'CENTER'- row.label(text="UV Inpainting Parameters", icon="IMAGE_PLANE")- row = mode_specific_outer_box.row()- row.prop(scene, "allow_modify_existing_textures", text="Allow Modifying Existing Textures", toggle=True, icon="TEXTURE")- row = mode_specific_outer_box.row()- row.prop(scene, "ask_object_prompts", text="Ask for Object Specific Prompts", toggle=True, icon="QUESTION")-- # Sequential Mode Parameters- elif scene.generation_method == 'sequential':- row = mode_specific_outer_box.row()- row.alignment = 'CENTER'- row.label(text="Sequential Mode Parameters", icon="SEQUENCE")-- split = mode_specific_outer_box.split(factor=0.5)- split.label(text="Custom Camera Order:")- split.prop(scene, "sequential_custom_camera_order", text="")+ row.prop(scene, "ipadapter_end", text="End")++ if context.scene.sequential_ipadapter_mode == 'first':+ row = sub_ip_box_separate.row()+ row.prop(scene, "sequential_ipadapter_regenerate", text="Regenerate First Image", toggle=True, icon="FILE_REFRESH")+ if context.scene.sequential_ipadapter_regenerate:+ row = sub_ip_box_separate.row()+ row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")- if not (scene.differential_diffusion and not scene.differential_noise):+ # UV Inpainting Parameters+ elif scene.generation_method == 'uv_inpaint':row = mode_specific_outer_box.row()- row.prop(scene, "sequential_smooth", text="Use Smooth Visibility Map", toggle=True, icon="MOD_SMOOTH")- if width_mode == 'narrow':- row = mode_specific_outer_box.row()- row.prop(scene, "weight_exponent_mask", text="Exponent for Visibility Map", toggle=True, icon="IPO_EXPO")+ row.alignment = 'CENTER'+ row.label(text="UV Inpainting Parameters", icon="IMAGE_PLANE")+ row = mode_specific_outer_box.row()+ row.prop(scene, "allow_modify_existing_textures", text="Allow Modifying Existing Textures", toggle=True, icon="TEXTURE")+ row = mode_specific_outer_box.row()+ row.prop(scene, "ask_object_prompts", text="Ask for Object Specific Prompts", toggle=True, icon="QUESTION")++ # Sequential Mode Parameters+ elif scene.generation_method == 'sequential':+ row = mode_specific_outer_box.row()+ row.alignment = 'CENTER'+ row.label(text="Sequential Mode Parameters", icon="SEQUENCE")- if not scene.sequential_smooth:- row = mode_specific_outer_box.row()- row.prop(scene, "sequential_factor", text="Visibility Threshold")- else:+ split = mode_specific_outer_box.split(factor=0.5)+ split.label(text="Custom Camera Order:")+ split.prop(scene, "sequential_custom_camera_order", text="")++ if not (scene.differential_diffusion and not scene.differential_noise):row = mode_specific_outer_box.row()- row.prop(scene, "sequential_factor_smooth", text="Smooth Visibility Black Point")+ row.prop(scene, "sequential_smooth", text="Use Smooth Visibility Map", toggle=True, icon="MOD_SMOOTH")if width_mode == 'narrow':row = mode_specific_outer_box.row()- row.prop(scene, "sequential_factor_smooth_2", text="Smooth Visibility White Point")-- row = mode_specific_outer_box.row()- row.prop(scene, "sequential_ipadapter", text="Use IPAdapter for Sequential Mode", toggle=True, icon="MODIFIER")- if scene.sequential_ipadapter:- sub_ip_seq_box = mode_specific_outer_box.box()+ row.prop(scene, "weight_exponent_mask", text="Exponent for Visibility Map", toggle=True, icon="IPO_EXPO")++ if not scene.sequential_smooth:+ row = mode_specific_outer_box.row()+ row.prop(scene, "sequential_factor", text="Visibility Threshold")+ else:+ row = mode_specific_outer_box.row()+ row.prop(scene, "sequential_factor_smooth", text="Smooth Visibility Black Point")+ if width_mode == 'narrow':+ row = mode_specific_outer_box.row()+ row.prop(scene, "sequential_factor_smooth_2", text="Smooth Visibility White Point")- split = sub_ip_seq_box.split(factor=0.5)- split.label(text="Mode:")- split.prop(scene, "sequential_ipadapter_mode", text="")-- if scene.sequential_ipadapter_mode == 'recent':- sub_ip_seq_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")- sub_ip_seq_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")-- if context.scene.model_architecture != 'qwen_image_edit':+ row = mode_specific_outer_box.row()+ row.prop(scene, "sequential_ipadapter", text="Use IPAdapter for Sequential Mode", toggle=True, icon="MODIFIER")+ if scene.sequential_ipadapter:+ sub_ip_seq_box = mode_specific_outer_box.box()+split = sub_ip_seq_box.split(factor=0.5)- if context.scene.model_architecture == 'sdxl':- split.label(text="Weight Type:")- split.prop(scene, "ipadapter_weight_type", text="")-- row = sub_ip_seq_box.row()- row.prop(scene, "ipadapter_strength", text="Strength")- if width_mode == 'narrow':- row = sub_ip_seq_box.row()- row.prop(scene, "ipadapter_start", text="Start")- if width_mode == 'narrow':- row = sub_ip_seq_box.row()- row.prop(scene, "ipadapter_end", text="End")-- if context.scene.sequential_ipadapter_mode == 'first':+ split.label(text="Mode:")+ split.prop(scene, "sequential_ipadapter_mode", text="")++ if scene.sequential_ipadapter_mode == 'recent':+ sub_ip_seq_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")+ sub_ip_seq_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")++ if context.scene.model_architecture != 'qwen_image_edit':+ split = sub_ip_seq_box.split(factor=0.5)+ if context.scene.model_architecture == 'sdxl':+ split.label(text="Weight Type:")+ split.prop(scene, "ipadapter_weight_type", text="")+row = sub_ip_seq_box.row()- row.prop(scene, "sequential_ipadapter_regenerate", text="Regenerate First Image", toggle=True, icon="FILE_REFRESH")- if context.scene.sequential_ipadapter_regenerate:+ row.prop(scene, "ipadapter_strength", text="Strength")+ if width_mode == 'narrow':row = sub_ip_seq_box.row()- row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")+ row.prop(scene, "ipadapter_start", text="Start")+ if width_mode == 'narrow':+ row = sub_ip_seq_box.row()+ row.prop(scene, "ipadapter_end", text="End")++ if context.scene.sequential_ipadapter_mode == 'first':+ row = sub_ip_seq_box.row()+ row.prop(scene, "sequential_ipadapter_regenerate", text="Regenerate First Image", toggle=True, icon="FILE_REFRESH")+ if context.scene.sequential_ipadapter_regenerate:+ row = sub_ip_seq_box.row()+ row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")# --- Tools ---layout.separator()@@ -877,6 +893,37 @@ class StableGenPanel(bpy.types.Panel):layout.separator()+class ResetQwenPrompt(bpy.types.Operator):+ """Resets a Qwen guidance prompt to its default value"""+ bl_idname = "stablegen.reset_qwen_prompt"+ bl_label = "Reset Qwen Prompt"+ bl_description = "Reset this prompt to its default value based on the current settings"++ prompt_type: bpy.props.StringProperty()++ def execute(self, context):+ from .workflows import WorkflowManager+ # We need an operator instance to call the helper, a bit of a workaround+ # This doesn't run generation, just gives us access to the method+ wm = WorkflowManager(self)++ # Determine which prompt to reset+ if self.prompt_type == 'initial':+ default_prompt = wm._get_qwen_default_prompts(context, is_initial_image=True)+ context.scene.qwen_custom_prompt_initial = default_prompt+ elif self.prompt_type == 'seq_none':+ default_prompt = wm._get_qwen_default_prompts(context, is_initial_image=False)+ context.scene.qwen_custom_prompt_seq_none = default_prompt+ elif self.prompt_type == 'seq_replace':+ default_prompt = wm._get_qwen_default_prompts(context, is_initial_image=False)+ context.scene.qwen_custom_prompt_seq_replace = default_prompt+ elif self.prompt_type == 'seq_additional':+ default_prompt = wm._get_qwen_default_prompts(context, is_initial_image=False)+ context.scene.qwen_custom_prompt_seq_additional = default_prompt++ self.report({'INFO'}, "Prompt reset to default.")+ return {'FINISHED'}+class ApplyPreset(bpy.types.Operator):"""Apply selected preset values to parameters"""bl_idname = "stablegen.apply_preset"diff --git a/stablegen/util/helpers.py b/stablegen/util/helpers.pyindex 2c2a97b..d33f529 100755--- a/stablegen/util/helpers.py+++ b/stablegen/util/helpers.py@@ -1404,20 +1404,6 @@ prompt_text_qwen_image_edit = """"title": "VAE Encode"}},- "9": {- "inputs": {- "lora_name": "Qwen-Image-Lightning-4steps-V1.0.safetensors",- "strength_model": 1,- "model": [- "13",- 0- ]- },- "class_type": "LoraLoaderModelOnly",- "_meta": {- "title": "LoraLoaderModelOnly"- }- },"10": {"inputs": {"upscale_method": "lanczos",diff --git a/stablegen/workflows.py b/stablegen/workflows.pyindex 052e909..5970e42 100644--- a/stablegen/workflows.py+++ b/stablegen/workflows.py@@ -19,6 +19,36 @@ class WorkflowManager:"""self.operator = operator+ def _get_qwen_default_prompts(self, context, is_initial_image):+ """Gets the default Qwen prompts based on the current context."""+ # Check if we are in a real generation context vs. just resetting a prompt+ is_generating = hasattr(self.operator, '_current_image')+ is_subsequent_in_sequence = is_generating and self.operator._current_image > 0++ style_image_provided = (+ context.scene.qwen_use_external_style_image or+ ((not is_generating or is_subsequent_in_sequence) and+ (context.scene.sequential_ipadapter or context.scene.qwen_context_render_mode == 'REPLACE_STYLE'))+ )+ context_mode = context.scene.qwen_context_render_mode++ if is_initial_image:+ if not style_image_provided:+ return "Change the format of image 1 to '{main_prompt}'"+ else:+ return "Change and transfer the format of '{main_prompt}' in image 1 to the style from image 2"+ else: # Subsequent image+ if context_mode == 'ADDITIONAL':+ return "Change and transfer the format of image 1 to '{main_prompt}'. Replace all solid magenta areas in image 2. Replace the background with solid gray. The style from image 2 should smoothly continue into the previously magenta areas. Image 3 represents the overall style of the object."+ elif context_mode == 'REPLACE_STYLE':+ return "Change and transfer the format of image 1 to '{main_prompt}'. Replace all solid magenta areas in image 2. Replace the background with solid gray. The style from image 2 should smoothly continue into the previously magenta areas."+ else: # NONE or other cases+ if not style_image_provided:+ return "Change the format of image 1 to '{main_prompt}'"+ else:+ return "Change and transfer the format of '{main_prompt}' in image 1 to the style from image 2"++def generate_qwen_edit(self, context, camera_id=None):"""Generates an image using the Qwen-Image-Edit workflow."""server_address = context.preferences.addons[__package__].preferences.server_address@@ -30,14 +60,34 @@ class WorkflowManager:NODES = {'sampler': "1",'save_image': "5",+ 'model_sampler': "6", # ModelSamplingAuraFlow+ 'cfg_norm': "7", # CFGNorm'vae_encode': "8",'pos_prompt': "12",'neg_prompt': "11",+ 'unet_loader': "13",'guidance_map_loader': "14", # Image 1 (structure)'style_map_loader': "15", # Image 2 (style)'context_render_loader': "16", # Image 3 (context render)}+ # --- Build LoRA chain ---+ # The Qwen workflow uses model-only LoRAs. We can reuse the existing+ # chain builder by providing a dummy CLIP input that won't be used.+ initial_model_input = [NODES['unet_loader'], 0]+ dummy_clip_input = [NODES['unet_loader'], 0] # Dummy, not used by LoraLoaderModelOnly++ prompt, final_lora_model_out, _ = self._build_lora_chain(+ prompt, context,+ initial_model_input, dummy_clip_input,+ start_node_id=500, # Use a high starting ID to avoid conflicts+ lora_class_type="LoraLoaderModelOnly" # Specify model-only loader+ )++ # Connect the output of the LoRA chain to the next node in the model path+ prompt[NODES['model_sampler']]['inputs']['model'] = final_lora_model_out++# --- Configure Inputs ---guidance_map_type = context.scene.qwen_guidance_map_typeguidance_map_info = self.operator._get_uploaded_image_info(context, "controlnet", subtype=guidance_map_type, camera_id=camera_id)@@ -54,7 +104,7 @@ class WorkflowManager:remove_context = False# --- Camera Prompt Injection ---- if context.scene.use_camera_prompts and context.scene.generation_method in ['separate', 'sequential', 'refine'] and self.operator._cameras and self.operator._current_image < len(self.operator._cameras):+ if context.scene.use_camera_prompts and self.operator._cameras and self.operator._current_image < len(self.operator._cameras):current_camera_name = self.operator._cameras[self.operator._current_image].name# Find the prompt in the collectionprompt_item = next((item for item in context.scene.camera_prompts if item.name == current_camera_name), None)@@ -65,7 +115,8 @@ class WorkflowManager:# --- Handle Context Render (Image 3) ---# This is only active in sequential mode after the first image- if context.scene.generation_method == 'sequential' and self.operator._current_image > 0 and context_mode != 'NONE':+ is_initial_image = not self.operator._current_image > 0+ if not is_initial_image and context_mode != 'NONE':context_render_info = self.operator._get_uploaded_image_info(context, "inpaint", subtype="render", camera_id=camera_id)if not context_render_info:self.operator._error = f"Qwen context render enabled, but could not find context render for camera {camera_id}."@@ -76,8 +127,11 @@ class WorkflowManager:NODES['context_render_loader'], NODES['style_map_loader'] = NODES['style_map_loader'], NODES['context_render_loader']prompt[NODES['context_render_loader']]['inputs']['image'] = context_render_info['name']# The prompt needs to reference image 3- prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of image 1 to '{user_prompt}'. Replace all solid magenta areas in image 2. Replace the background with solid gray. The style from image 2 should smoothly continue into the previously magenta areas. Image 3 represents the overall style of the object."- # prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of {user_prompt} in image 1 to the style from image 2. Image 3 contains the unfinished image, where the magenta areas need to be replaced and completed."+ if context.scene.qwen_use_custom_prompts:+ pos_prompt_text = context.scene.qwen_custom_prompt_seq_additional.format(main_prompt=user_prompt)+ else:+ pos_prompt_text = self._get_qwen_default_prompts(context, is_initial_image).format(main_prompt=user_prompt)+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = pos_prompt_text# If mode is REPLACE_STYLE, we will handle it in the style image section below.else:remove_context = True@@ -91,21 +145,36 @@ class WorkflowManager:# --- Handle Style Image (Image 2) ---- # Case 1: External Style Image for all viewpoints- if context.scene.qwen_use_external_style_image:+ # Determine if we should use the external style image for this specific frame+ use_external_this_frame = context.scene.qwen_use_external_style_image+ if use_external_this_frame and not is_initial_image and context.scene.qwen_external_style_initial_only:+ # If it's a subsequent image AND the "initial only" flag is set, DON'T use the external image.+ use_external_this_frame = False+ context.scene.sequential_ipadapter = True # Force using previous image as style++ # Case 1: External Style Image for this frame+ if use_external_this_frame:style_image_info = self.operator._get_uploaded_image_info(context, "custom", filename=bpy.path.abspath(context.scene.qwen_external_style_image))if not style_image_info:self.operator._error = "External style image enabled, but file not found or could not be uploaded."return {"error": "conn_failed"}if context_mode != 'ADDITIONAL':- prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of '{user_prompt}' in image 1 to the style from image 2"+ if context.scene.qwen_use_custom_prompts:+ pos_prompt_text = (context.scene.qwen_custom_prompt_initial if is_initial_image else context.scene.qwen_custom_prompt_seq_none).format(main_prompt=user_prompt)+ else:+ pos_prompt_text = self._get_qwen_default_prompts(context, is_initial_image).format(main_prompt=user_prompt)+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = pos_prompt_text# Case 2: Sequential generation (after first image)- elif context.scene.generation_method == 'sequential' and self.operator._current_image > 0:+ elif not is_initial_image:if context_mode == 'REPLACE_STYLE':# The context render becomes the style imagestyle_image_info = context_render_info- prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of image 1 to '{user_prompt}'. Replace all solid magenta areas in image 2. Replace the background with solid gray. The style from image 2 should smoothly continue into the previously magenta areas."+ if context.scene.qwen_use_custom_prompts:+ pos_prompt_text = context.scene.qwen_custom_prompt_seq_replace.format(main_prompt=user_prompt)+ else:+ pos_prompt_text = self._get_qwen_default_prompts(context, is_initial_image).format(main_prompt=user_prompt)+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = pos_prompt_textelif context.scene.sequential_ipadapter: # Use previous generated imageref_cam_id = 0 if context.scene.sequential_ipadapter_mode == 'first' else self.operator._current_image - 1style_image_info = self.operator._get_uploaded_image_info(context, "generated", camera_id=ref_cam_id, material_id=self.operator._material_id)@@ -113,7 +182,11 @@ class WorkflowManager:self.operator._error = f"Sequential mode error: Could not find previous image for camera {ref_cam_id} to use as style."return {"error": "conn_failed"}if context_mode != 'ADDITIONAL':- prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of '{user_prompt}' in image 1 to the style from image 2"+ if context.scene.qwen_use_custom_prompts:+ pos_prompt_text = context.scene.qwen_custom_prompt_seq_none.format(main_prompt=user_prompt)+ else:+ pos_prompt_text = self._get_qwen_default_prompts(context, is_initial_image).format(main_prompt=user_prompt)+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = pos_prompt_text# If neither of the above, style_image_info remains None, handled below# Case 3: First image of a sequence, or separate generation, or no style source in sequential@@ -122,7 +195,11 @@ class WorkflowManager:del prompt[NODES['style_map_loader']]del prompt[NODES['pos_prompt']]['inputs']['image2']del prompt[NODES['neg_prompt']]['inputs']['image2']- prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change the format of image 1 to '{user_prompt}'"+ if context.scene.qwen_use_custom_prompts:+ pos_prompt_text = (context.scene.qwen_custom_prompt_initial if is_initial_image else context.scene.qwen_custom_prompt_seq_none).format(main_prompt=user_prompt)+ else:+ pos_prompt_text = self._get_qwen_default_prompts(context, is_initial_image).format(main_prompt=user_prompt)+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = pos_prompt_textelse:# A style image is provided, so set the loader input.prompt[NODES['style_map_loader']]['inputs']['image'] = style_image_info['name']@@ -135,6 +212,9 @@ class WorkflowManager:prompt[NODES['sampler']]['inputs']['scheduler'] = context.scene.schedulerprompt[NODES['sampler']]['inputs']['denoise'] = 1.0 # Typically 1.0 for this kind of edit+ # --- Set UNET model ---+ prompt[NODES['unet_loader']]['inputs']['unet_name'] = context.scene.model_name+# --- Execute ---self._save_prompt_to_file(prompt, revision_dir)ws = self._connect_to_websocket(server_address, client_id)@@ -434,7 +514,7 @@ class WorkflowManager:return base_prompt, current_pos- def _build_lora_chain(self, prompt, context, initial_model_input, initial_clip_input, start_node_id=300):+ def _build_lora_chain(self, prompt, context, initial_model_input, initial_clip_input, start_node_id=300, lora_class_type="LoraLoader"):"""Builds a chain of LoRA loaders dynamically.@@ -444,6 +524,7 @@ class WorkflowManager:initial_model_input (list): The [node_id, output_idx] for the initial model.initial_clip_input (list): The [node_id, output_idx] for the initial CLIP.start_node_id (int): The starting integer for generating unique LoRA node IDs.+ lora_class_type (str): The class type of the LoRA loader node to use.Returns:tuple: (modified_prompt, final_model_output, final_clip_output)@@ -464,22 +545,27 @@ class WorkflowManager:lora_node_id_str = str(start_node_id + i)+ lora_inputs = {+ "lora_name": lora_unit.model_name,+ "strength_model": lora_unit.model_strength,+ "model": current_model_out,+ }++ if lora_class_type == "LoraLoader":+ lora_inputs["strength_clip"] = lora_unit.clip_strength+ lora_inputs["clip"] = current_clip_out+prompt[lora_node_id_str] = {- "inputs": {- "lora_name": lora_unit.model_name,- "strength_model": lora_unit.model_strength,- "strength_clip": lora_unit.clip_strength,- "model": current_model_out, # Connect to previous LoRA or initial model- "clip": current_clip_out # Connect to previous LoRA or initial CLIP- },- "class_type": "LoraLoader",+ "inputs": lora_inputs,+ "class_type": lora_class_type,"_meta": {"title": f"Load LoRA {i+1} ({lora_unit.model_name[:20]})"}}# Update outputs for the next LoRA in the chaincurrent_model_out = [lora_node_id_str, 0]- current_clip_out = [lora_node_id_str, 1]+ if lora_class_type == "LoraLoader":+ current_clip_out = [lora_node_id_str, 1]return prompt, current_model_out, current_clip_out@@ -838,7 +924,7 @@ class WorkflowManager:current_object_name = os.path.basename(render_info['name']).split('.')[0]# Use the object-specific prompt if available- object_prompt = self._object_prompts.get(current_object_name, context.scene.comfyui_prompt)+ object_prompt = self.operator._object_prompts.get(current_object_name, context.scene.comfyui_prompt)if object_prompt:uv_prompt = f"(UV-unwrapped texture) of {object_prompt}, consistent material continuity, no visible seams or stretching, PBR material properties"uv_prompt_neg = f"seam, stitch, visible edge, texture stretching, repeating pattern, {context.scene.comfyui_negative_prompt}"@@ -1357,7 +1443,7 @@ class WorkflowManager:# Object-specific prompt if availableif render_info and 'name' in render_info:current_object_name = os.path.basename(render_info['name']).split('.')[0]- object_prompt = self._object_prompts.get(current_object_name, context.scene.comfyui_prompt)+ object_prompt = self.operator._object_prompts.get(current_object_name, context.scene.comfyui_prompt)if object_prompt:uv_prompt = f"(UV-unwrapped texture) of {object_prompt}, consistent material continuity, no visible seams or stretching"prompt[NODES['pos_prompt']]["inputs"]["text"] = uv_prompt