Skip to content

Transform your 3D texturing workflow with the power of generative AI, directly within Blender!

add qwen refine mode

sakalondfb48df4a2e7c
diff --git a/stablegen/__init__.py b/stablegen/__init__.py
index 79e54f5..ea9e91b 100644
--- a/stablegen/__init__.py
+++ b/stablegen/__init__.py
@@ -1343,6 +1343,29 @@ def register():
default='sequential',
update=update_parameters
)
+ bpy.types.Scene.qwen_generation_method = bpy.props.EnumProperty(
+ name="Generation Mode",
+ description="Choose the mode for generating images with Qwen",
+ items=[
+ ('generate', 'Generate', 'Standard generation mode'),
+ ('refine', 'Refine', 'Refine existing image'),
+ ],
+ default='generate',
+ update=update_parameters
+ )
+
+ bpy.types.Scene.qwen_refine_use_prev_ref = bpy.props.BoolProperty(
+ name="Use Previous Refined View",
+ description="Use the previous modified/refined view output as a second image for reference (Image 2)",
+ default=False,
+ update=update_parameters
+ )
+ bpy.types.Scene.qwen_refine_use_depth = bpy.props.BoolProperty(
+ name="Use Depth Map",
+ description="Include depth map as an additional reference image (Image 3)",
+ default=False,
+ update=update_parameters
+ )
bpy.types.Scene.refine_images = bpy.props.BoolProperty(
name="Refine Images",
description="Refine images after generation",
diff --git a/stablegen/generator.py b/stablegen/generator.py
index 4ce056e..19f6af1 100644
--- a/stablegen/generator.py
+++ b/stablegen/generator.py
@@ -520,7 +520,7 @@ class ComfyUIGenerate(bpy.types.Operator):
self._material_id = material_id
# Check if there are enough UV map slots
if not context.scene.bake_texture and context.scene.generation_method != 'uv_inpaint':
- if not context.scene.overwrite_material or (context.scene.generation_method == 'refine' and context.scene.refine_preserve):
+ if not context.scene.overwrite_material or ((context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve):
if 8 - len(obj.data.uv_layers) < uv_slots_needed:
self.report({'ERROR'}, "Not enough UV map slots for all cameras.")
context.scene.generation_status = 'idle'
@@ -549,7 +549,7 @@ class ComfyUIGenerate(bpy.types.Operator):
if 8 - len(obj.data.uv_layers) < 1:
self.report({'ERROR'}, "Not enough UV map slots for baking. At least 1 slot is required.")
- if not context.scene.overwrite_material or self._material_id == -1 or (context.scene.generation_method == 'refine' and context.scene.refine_preserve):
+ if not context.scene.overwrite_material or self._material_id == -1 or ((context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve):
self._material_id += 1
if context.scene.generation_method == 'sequential' and context.scene.sequential_custom_camera_order != "":
@@ -577,7 +577,7 @@ class ComfyUIGenerate(bpy.types.Operator):
if context.scene.generation_mode == 'standard':
# If there is depth controlnet unit
- if any(unit["unit_type"] == "depth" for unit in controlnet_units) or (context.scene.use_flux_lora and context.scene.model_architecture == 'flux1') or (context.scene.model_architecture == 'qwen_image_edit' and context.scene.qwen_guidance_map_type == 'depth'):
+ if any(unit["unit_type"] == "depth" for unit in controlnet_units) or (context.scene.use_flux_lora and context.scene.model_architecture == 'flux1') or (context.scene.model_architecture == 'qwen_image_edit' and context.scene.qwen_guidance_map_type == 'depth') or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine' and context.scene.qwen_refine_use_depth):
if context.scene.generation_method != 'uv_inpaint':
# Export depth maps for each camera
for i, camera in enumerate(self._cameras):
@@ -622,7 +622,7 @@ class ComfyUIGenerate(bpy.types.Operator):
obj.hide_render = True
# Refine mode preparation
- if context.scene.generation_method == 'refine':
+ if context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine'):
for i, camera in enumerate(self._cameras):
bpy.context.scene.camera = camera
export_emit_image(context, self._to_texture, camera_id=i)
@@ -909,6 +909,8 @@ class ComfyUIGenerate(bpy.types.Operator):
image = self.workflow_manager.refine_flux(context, controlnet_info=controlnet_info, render_info=render_info, ipadapter_ref_info=ipadapter_ref_info)
else:
image = self.workflow_manager.refine(context, controlnet_info=controlnet_info, render_info=render_info, ipadapter_ref_info=ipadapter_ref_info)
+ elif context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine':
+ image = self.workflow_manager.generate_qwen_refine(context, camera_id=camera_id)
elif context.scene.generation_method == 'uv_inpaint':
if context.scene.model_architecture == 'flux1':
image = self.workflow_manager.refine_flux(context, mask_info=mask_info, render_info=render_info)
@@ -1023,7 +1025,7 @@ class ComfyUIGenerate(bpy.types.Operator):
else: # steps == 0, skip generation
pass # No image generation needed
- if context.scene.generation_method == 'separate' or context.scene.generation_method == 'refine' or context.scene.generation_method == 'sequential':
+ if context.scene.generation_method == 'separate' or context.scene.generation_method == 'refine' or context.scene.generation_method == 'sequential' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine'):
self._current_image += 1
self._threads_left -= 1
if self._threads_left > 0:
diff --git a/stablegen/project.py b/stablegen/project.py
index c41b90d..e891813 100644
--- a/stablegen/project.py
+++ b/stablegen/project.py
@@ -32,7 +32,8 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
"""
# Compute offsets based on recursion level
if context.scene.refine_preserve:
- x_offset = 1000 + level * 800 + last_node.location[0] + 200 if context.scene.early_priority else 1000 + level * 600 + last_node.location[0] + 200
+ last_node_x = last_node.location[0] if last_node else 0
+ x_offset = 1000 + level * 800 + last_node_x + 200 if context.scene.early_priority else 1000 + level * 600 + last_node_x + 200
else:
x_offset = 1000 + level * 800 if context.scene.early_priority else 1000 + level * 600
y_offset = 0
@@ -49,7 +50,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
links.new(last_node.outputs[0], final_mix.inputs["Color2"])
# Create a compare node to drive the mix factor
- if context.scene.generation_method == 'refine' and context.scene.refine_preserve:
+ if (context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve:
w_node = weight_nodes[0]
if isinstance(w_node, tuple):
angle_node, feather_node = w_node
@@ -95,7 +96,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
# Fallback if not tuple (e.g. stop_index logic used LessThan node)
# If it's a sum of processed weights (from multi-camera recursion), we need to invert it
# to get the Mix Factor (1 - TotalVis)
- if context.scene.generation_method == 'refine' and context.scene.refine_preserve:
+ if (context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve:
invert = nodes_collection.new("ShaderNodeMath")
invert.operation = 'SUBTRACT'
invert.location = (x_offset - 150, y_offset)
@@ -123,7 +124,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
# Add a principle shader for the mixed color
should_add_principled = True
- if context.scene.generation_method == 'refine' and context.scene.refine_preserve:
+ if (context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve:
# Final principled is at last_node's output if it is BSDF
final_principled = last_node.outputs[0].links[0].to_node
if final_principled.type == 'BSDF_PRINCIPLED':
@@ -332,12 +333,12 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
# Create the material
to_switch = False
- if context.scene.generation_method == "refine" and context.scene.refine_preserve and not context.scene.overwrite_material:
+ if (context.scene.generation_method == "refine" or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve and not context.scene.overwrite_material:
# Copy active material
mat = obj.active_material.copy()
obj.data.materials.append(mat)
to_switch = True
- elif obj.active_material and (context.scene.overwrite_material or (context.scene.generation_method == "refine" and context.scene.refine_preserve) \
+ elif obj.active_material and (context.scene.overwrite_material or ((context.scene.generation_method == "refine" or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve) \
or (context.scene.generation_method == 'sequential' and stop_index > 0) or context.scene.generation_mode == 'regenerate_selected'):
# Use active material
mat = obj.active_material
@@ -411,7 +412,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
# Now we can continue to the next object
continue
- elif not context.scene.refine_preserve or not context.scene.generation_method == 'refine':
+ elif not context.scene.refine_preserve or not (context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')):
# Clear existing nodes
for node in nodes:
nodes.remove(node)
@@ -428,7 +429,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
else:
previous_node = output.inputs[0].links[0].from_node
- if not (context.scene.generation_method == 'refine' and context.scene.refine_preserve):
+ if not ((context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve):
output = nodes.new("ShaderNodeOutputMaterial")
output.location = (3000, 0)
@@ -505,7 +506,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
scripts_to_connect = [script_angle]
final_weight_node = None
- if context.scene.generation_method == 'refine' and context.scene.refine_preserve:
+ if (context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve:
# Add Feather script
script_feather = nodes.new("ShaderNodeScript")
script_feather.location = (-400, (-800) * i - 200) # Offset slightly
@@ -591,7 +592,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):
length_nodes.append(length)
# Build mix shader tree
- if not context.scene.bake_texture and mat.name in processed_materials and context.scene.generation_method == 'refine' and context.scene.refine_preserve:
+ if not context.scene.bake_texture and mat.name in processed_materials and (context.scene.generation_method == 'refine' or (context.scene.model_architecture.startswith('qwen') and context.scene.qwen_generation_method == 'refine')) and context.scene.refine_preserve:
# If we already processed this material, we don't need to rebuild the mix tree
# But we still need to connect the nodes for the current object (done in the loop below)
# We need to find the existing mix node to position the output node
diff --git a/stablegen/stablegen.py b/stablegen/stablegen.py
index c009a1f..7544d29 100644
--- a/stablegen/stablegen.py
+++ b/stablegen/stablegen.py
@@ -376,9 +376,11 @@ class StableGenPanel(bpy.types.Panel):
split.prop(scene, "model_architecture", text="")
# Split for generation method
- if not scene.model_architecture.startswith("qwen"): # Qwen forces sequential mode
- split = params_container.split(factor=0.5)
- split.label(text="Generation Mode:")
+ split = params_container.split(factor=0.5)
+ split.label(text="Generation Mode:")
+ if scene.model_architecture.startswith("qwen"):
+ split.prop(scene, "qwen_generation_method", text="")
+ else:
split.prop(scene, "generation_method", text="")
# Split for object selection
@@ -560,45 +562,61 @@ class StableGenPanel(bpy.types.Panel):
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':
- split = content_box.split(factor=0.5)
- split.label(text="Guidance Map:")
- split.prop(scene, "qwen_guidance_map_type", text="")
-
- 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:
- 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.qwen_use_external_style_image and scene.qwen_external_style_initial_only:
- subsequent_box = style_box.box()
- split = subsequent_box.split(factor=0.5)
- split.label(text="Subsequent mode:")
- split.prop(scene, "sequential_ipadapter_mode", text="")
- if scene.sequential_ipadapter_mode == 'recent':
- subsequent_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")
- subsequent_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")
+ if scene.qwen_generation_method == 'generate':
+ split = content_box.split(factor=0.5)
+ split.label(text="Guidance Map:")
+ split.prop(scene, "qwen_guidance_map_type", text="")
- 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_ip_box = content_box.box()
- split = sub_ip_box.split(factor=0.5)
- split.label(text="Mode:")
+ 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:
+ 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.qwen_use_external_style_image and scene.qwen_external_style_initial_only:
+ subsequent_box = style_box.box()
+ split = subsequent_box.split(factor=0.5)
+ split.label(text="Subsequent mode:")
split.prop(scene, "sequential_ipadapter_mode", text="")
if scene.sequential_ipadapter_mode == 'recent':
- sub_ip_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")
- sub_ip_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")
+ subsequent_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")
+ subsequent_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")
- 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="")
+ 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_ip_box = content_box.box()
+ split = sub_ip_box.split(factor=0.5)
+ split.label(text="Mode:")
+ split.prop(scene, "sequential_ipadapter_mode", text="")
+ if scene.sequential_ipadapter_mode == 'recent':
+ sub_ip_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")
+ sub_ip_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")
+
+ 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="")
+
+ elif scene.qwen_generation_method == 'refine':
+ row = content_box.row()
+ row.prop(scene, "qwen_refine_use_prev_ref", text="Use Previous Refined View", toggle=True)
+
+ row = content_box.row()
+ row.prop(scene, "qwen_refine_use_depth", text="Use Depth Map", toggle=True, icon="MODIFIER")
+
+ 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:
+ style_box = content_box.box()
+ row = style_box.row()
+ row.prop(scene, "qwen_external_style_image", text="Style Image")
row = content_box.row()
row.prop(scene, "qwen_use_custom_prompts", text="Custom Guidance Prompts", toggle=True, icon="TEXT")
@@ -614,25 +632,28 @@ class StableGenPanel(bpy.types.Panel):
op.prompt_type = 'initial'
# Subsequent Images Prompt (conditional)
- if scene.generation_method == 'sequential':
+ if scene.generation_method == 'sequential' or (scene.qwen_generation_method == 'refine' and scene.qwen_refine_mode == 'sequential'):
col = custom_prompt_box.column()
col.label(text="Subsequent Images Prompt:")
row = col.row(align=True)
- if scene.qwen_context_render_mode == 'NONE':
+ if scene.qwen_context_render_mode == 'NONE' and scene.qwen_generation_method == 'generate':
row.prop(scene, "qwen_custom_prompt_seq_none", text="")
op_prop = 'seq_none'
- elif scene.qwen_context_render_mode == 'REPLACE_STYLE':
+ elif scene.qwen_context_render_mode == 'REPLACE_STYLE' and scene.qwen_generation_method == 'generate':
row.prop(scene, "qwen_custom_prompt_seq_replace", text="")
op_prop = 'seq_replace'
- elif scene.qwen_context_render_mode == 'ADDITIONAL':
+ elif scene.qwen_context_render_mode == 'ADDITIONAL' and scene.qwen_generation_method == 'generate':
row.prop(scene, "qwen_custom_prompt_seq_additional", text="")
op_prop = 'seq_additional'
+ else: # Refine mode or other
+ row.prop(scene, "qwen_custom_prompt_seq_none", text="")
+ op_prop = 'seq_none'
op = row.operator("stablegen.reset_qwen_prompt", text="", icon='FILE_REFRESH')
op.prompt_type = op_prop
- if (scene.generation_method == 'sequential' and
+ if (scene.generation_method == 'sequential' and scene.qwen_generation_method == 'generate' and
scene.qwen_context_render_mode in {'REPLACE_STYLE', 'ADDITIONAL'}):
context_box = content_box.box()
context_box.label(text="Context Render Options")
@@ -761,224 +782,260 @@ class StableGenPanel(bpy.types.Panel):
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
+ # --- 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
+
+ # Qwen Refine Mode Parameters
+ if scene.model_architecture.startswith('qwen') and scene.qwen_generation_method == 'refine':
+ row = mode_specific_outer_box.row()
+ row.alignment = 'CENTER'
+ row.label(text="Qwen Refine Parameters", icon='SHADERFX')
+
+ row = mode_specific_outer_box.row()
+ row.prop(scene, "refine_preserve", text="Preserve Original Textures", toggle=True, icon="TEXTURE")
- # Grid Mode Parameters
- if scene.generation_method == 'grid':
- # Draw Grid parameters directly into mode_specific_outer_box
+ if scene.refine_preserve:
row = mode_specific_outer_box.row()
- row.alignment = 'CENTER'
- row.label(text="Grid Mode Parameters", icon="MESH_GRID")
+ # Angle Ramp Controls
+ box = mode_specific_outer_box.box()
+ row = box.row()
+ row.prop(scene, "refine_angle_ramp_active", text="Use Angle-Based Blending", icon="DRIVER")
+ if scene.refine_angle_ramp_active:
+ row = box.row()
+ row.prop(scene, "refine_angle_ramp_pos_0", text="Black Point")
+ row.prop(scene, "refine_angle_ramp_pos_1", text="White Point")
- 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="")
-
- 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")
+ # Feather Ramp Controls
+ box = mode_specific_outer_box.box()
+ row = box.row()
+ row.prop(scene, "visibility_vignette", text="Use Vignette Blending", icon="DRIVER")
+ if scene.visibility_vignette:
+ row = box.row()
+ row.prop(scene, "refine_feather_ramp_pos_0", text="Black Point")
+ row.prop(scene, "refine_feather_ramp_pos_1", text="White Point")
+ row = box.row()
+ row.prop(scene, "visibility_vignette_width", text="Feather Width")
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="")
-
- # 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 = box.row()
+ row.prop(scene, "visibility_vignette_softness", text="Feather Softness")
+ row = box.row()
+ row.prop(scene, "visibility_vignette_blur", text="Blur Mask", icon="SURFACE_NSPHERE")
+
+ # Grid Mode Parameters
+ elif 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, "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="")
- 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")
-
- # 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")
+ split = mode_specific_outer_box.split(factor=0.5)
+ split.label(text="Refine Scheduler:")
+ split.prop(scene, "refine_scheduler", text="")
- if scene.refine_preserve:
+ row = mode_specific_outer_box.row()
+ row.prop(scene, "denoise", text="Denoise")
+ if width_mode == 'narrow':
row = mode_specific_outer_box.row()
- # Angle Ramp Controls
- box = mode_specific_outer_box.box()
- row = box.row()
- row.prop(scene, "refine_angle_ramp_active", text="Use Angle-Based Blending", icon="DRIVER")
- if scene.refine_angle_ramp_active:
- row = box.row()
- row.prop(scene, "refine_angle_ramp_pos_0", text="Black Point")
- row.prop(scene, "refine_angle_ramp_pos_1", text="White Point")
-
- # Feather Ramp Controls
- box = mode_specific_outer_box.box()
- row = box.row()
- row.prop(scene, "visibility_vignette", text="Use Vignette Blending", icon="DRIVER")
- if scene.visibility_vignette:
- row = box.row()
- row.prop(scene, "refine_feather_ramp_pos_0", text="Black Point")
- row.prop(scene, "refine_feather_ramp_pos_1", text="White Point")
- row = box.row()
- row.prop(scene, "visibility_vignette_width", text="Feather Width")
- if width_mode == 'narrow':
- row = box.row()
- row.prop(scene, "visibility_vignette_softness", text="Feather Softness")
- row = box.row()
- row.prop(scene, "visibility_vignette_blur", text="Blur Mask", icon="SURFACE_NSPHERE")
+ 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()
- 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 = 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()
+
+ 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_strength", text="Strength")
- if width_mode == 'narrow':
+ 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, "ipadapter_start", text="Start")
+ 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")
+
+ if scene.refine_preserve:
+ row = mode_specific_outer_box.row()
+ # Angle Ramp Controls
+ box = mode_specific_outer_box.box()
+ row = box.row()
+ row.prop(scene, "refine_angle_ramp_active", text="Use Angle-Based Blending", icon="DRIVER")
+ if scene.refine_angle_ramp_active:
+ row = box.row()
+ row.prop(scene, "refine_angle_ramp_pos_0", text="Black Point")
+ row.prop(scene, "refine_angle_ramp_pos_1", text="White Point")
+
+ # Feather Ramp Controls
+ box = mode_specific_outer_box.box()
+ row = box.row()
+ row.prop(scene, "visibility_vignette", text="Use Vignette Blending", icon="DRIVER")
+ if scene.visibility_vignette:
+ row = box.row()
+ row.prop(scene, "refine_feather_ramp_pos_0", text="Black Point")
+ row.prop(scene, "refine_feather_ramp_pos_1", text="White Point")
+ row = box.row()
+ row.prop(scene, "visibility_vignette_width", text="Feather Width")
if width_mode == 'narrow':
+ row = box.row()
+ row.prop(scene, "visibility_vignette_softness", text="Feather Softness")
+ row = box.row()
+ row.prop(scene, "visibility_vignette_blur", text="Blur Mask", icon="SURFACE_NSPHERE")
+ 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 = 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")
+ 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")
- # 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':
+ 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.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, "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")
- if not (scene.differential_diffusion and not scene.differential_noise):
+ 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_smooth", text="Use Smooth Visibility Map", toggle=True, icon="MOD_SMOOTH")
+ row.prop(scene, "sequential_factor_smooth", text="Smooth Visibility Black Point")
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")
-
- 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")
+ 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 = 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)
- split.label(text="Mode:")
- split.prop(scene, "sequential_ipadapter_mode", text="")
+ 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':
- 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="")
-
+ 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, "ipadapter_strength", text="Strength")
+ if width_mode == 'narrow':
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':
+ 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", 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")
+ row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")
# --- Tools ---
layout.separator()
diff --git a/stablegen/util/helpers.py b/stablegen/util/helpers.py
index d33f529..c355dfb 100755
--- a/stablegen/util/helpers.py
+++ b/stablegen/util/helpers.py
@@ -1408,6 +1408,7 @@ prompt_text_qwen_image_edit = """
"inputs": {
"upscale_method": "lanczos",
"megapixels": 1,
+ "resolution_steps": 1,
"image": [
"14",
0
diff --git a/stablegen/workflows.py b/stablegen/workflows.py
index 169d433..f175dc5 100644
--- a/stablegen/workflows.py
+++ b/stablegen/workflows.py
@@ -154,6 +154,116 @@ class WorkflowManager:
return "Change and transfer the format of '{main_prompt}' in image 1 to the style from image 2"
+ def generate_qwen_refine(self, context, camera_id=None):
+ """Generates an image using the Qwen-Image-Edit workflow for refinement."""
+ server_address = context.preferences.addons[__package__].preferences.server_address
+ client_id = str(uuid.uuid4())
+ revision_dir = get_generation_dirs(context)["revision"]
+
+ prompt = json.loads(prompt_text_qwen_image_edit)
+
+ 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 ---
+ initial_model_input = [NODES['unet_loader'], 0]
+ dummy_clip_input = [NODES['unet_loader'], 0]
+
+ is_nunchaku = context.scene.model_name.lower().endswith('.safetensors')
+ lora_class = "NunchakuQwenImageLoraLoader" if is_nunchaku else "LoraLoaderModelOnly"
+
+ prompt, final_lora_model_out, _ = self._build_lora_chain(
+ prompt, context,
+ initial_model_input, dummy_clip_input,
+ start_node_id=500,
+ lora_class_type=lora_class
+ )
+
+ prompt[NODES['model_sampler']]['inputs']['model'] = final_lora_model_out
+
+ # --- Configure Inputs ---
+ # Image 1: The current render (structure)
+ render_info = self.operator._get_uploaded_image_info(context, "inpaint", subtype="render", camera_id=camera_id)
+ if not render_info:
+ self.operator._error = f"Could not find or upload render for camera {camera_id}."
+ return {"error": "conn_failed"}
+ prompt[NODES['guidance_map_loader']]['inputs']['image'] = render_info['name']
+
+ # --- Configure Style Image (Image 2) ---
+ use_prev_ref = context.scene.qwen_refine_use_prev_ref
+ style_image_info = None
+
+ if use_prev_ref and camera_id > 0:
+ # Use previous generated image
+ style_image_info = self.operator._get_uploaded_image_info(context, "generated", camera_id=camera_id - 1, material_id=self.operator._material_id)
+
+ if style_image_info:
+ prompt[NODES['style_map_loader']]['inputs']['image'] = style_image_info['name']
+ else:
+ # Fallback to external style image if configured
+ if context.scene.qwen_use_external_style_image:
+ style_image_info = self.operator._get_uploaded_image_info(context, "custom", filename=bpy.path.abspath(context.scene.qwen_external_style_image))
+ if style_image_info:
+ prompt[NODES['style_map_loader']]['inputs']['image'] = style_image_info['name']
+
+ # If still no style image, remove Image 2 inputs
+ if not style_image_info:
+ del prompt[NODES['style_map_loader']]
+ del prompt[NODES['pos_prompt']]['inputs']['image2']
+ del prompt[NODES['neg_prompt']]['inputs']['image2']
+
+ # --- Configure Depth Map (Image 3) ---
+ use_depth = context.scene.qwen_refine_use_depth
+ depth_info = None
+ if use_depth:
+ depth_info = self.operator._get_uploaded_image_info(context, "controlnet", subtype="depth", camera_id=camera_id)
+
+ if depth_info:
+ prompt[NODES['context_render_loader']]['inputs']['image'] = depth_info['name']
+ else:
+ # Remove Context Render (Image 3) if not used
+ del prompt[NODES['context_render_loader']]
+ del prompt[NODES['pos_prompt']]['inputs']['image3']
+ del prompt[NODES['neg_prompt']]['inputs']['image3']
+
+ # --- Prompt ---
+ user_prompt = context.scene.comfyui_prompt
+ final_prompt = f"Modify image1 to {user_prompt}"
+ if depth_info:
+ final_prompt += ". Use image3 as depth map reference."
+
+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = final_prompt
+
+ # --- Save and Execute ---
+ self._save_prompt_to_file(prompt, revision_dir)
+
+ ws = self._connect_to_websocket(server_address, client_id)
+ if ws is None:
+ return {"error": "conn_failed"}
+
+ images = None
+ try:
+ images = self._execute_prompt_and_get_images(ws, prompt, client_id, server_address, NODES)
+ finally:
+ if ws:
+ ws.close()
+
+ if images is None or isinstance(images, dict) and "error" in images:
+ return {"error": "conn_failed"}
+
+ return images[NODES['save_image']][0]
+
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
@@ -328,6 +438,7 @@ class WorkflowManager:
"inputs": {
"upscale_method": "lanczos",
"megapixels": 1,
+ "resolution_steps": 1,
"image": [NODES['style_map_loader'], 0]
},
"class_type": "ImageScaleToTotalPixels",