Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
keep generated views when matching their colors and restore them when matching is off
sakalondfc89b4df4838
diff --git a/stablegen/texturing/generator.py b/stablegen/texturing/generator.pyindex 7387328..80a94b4 100644--- a/stablegen/texturing/generator.py+++ b/stablegen/texturing/generator.py@@ -32,7 +32,7 @@ from ..cameras.overlays import _sg_restore_square_display, _sg_remove_crop_overlfrom .projection import project_image, reinstate_compare_nodes, _bake_visibility_weights, reset_projection_material_nodes, _is_projection_mesh, pop_svm_stack_warning, pop_eevee_attribute_warningfrom .jobs import operation, RenderRequest, MainThreadOperation, run_syncfrom ..utils import get_last_material_index, get_generation_dirs, get_file_path, get_dir_path, remove_empty_dirs, get_compositor_node_tree, new_compositor_math, configure_output_node_paths, get_eevee_engine_id, sg_modal_active-from ..util.mirror_color import MirrorReproject, _get_viewport_ref_np, _apply_color_match_to_file+from ..util.mirror_color import MirrorReproject, _get_viewport_ref_np, _apply_color_match_to_file, restore_unmatched_imagefrom ..timeout_config import get_timeoutfrom .._generator_utils import redraw_ui, setup_studio_lighting, _pbr_setup_studio_lights, upload_image_to_comfyuifrom .pbr import _PBRMixin@@ -1250,6 +1250,11 @@ class ComfyUIGenerate(_PBRMixin, bpy.types.Operator):ref_rgb=ref_np,scene=context.scene,)+ elif context.scene.generation_mode == 'project_only':+ # Color matching was turned off: reproject the views as generated+ for cam_idx, _cam in enumerate(self._cameras):+ restore_unmatched_image(get_file_path(+ context, "generated", camera_id=cam_idx, material_id=self._material_id))self.prompt_text = context.scene.comfyui_promptdiff --git a/stablegen/util/mirror_color.py b/stablegen/util/mirror_color.pyindex 4a5c0b7..9135e06 100644--- a/stablegen/util/mirror_color.py+++ b/stablegen/util/mirror_color.py@@ -1,5 +1,6 @@import bpyimport os+import shutilimport numpy as npfrom PIL import Imageimport mathutils@@ -559,15 +560,34 @@ def _get_viewport_ref_np(obj):return rgb_srgb+def _unmatched_path(image_path):+ """Where the generated image is kept as generated while a color-matched copy takes its place."""+ return os.path.join(os.path.dirname(image_path), "unmatched", os.path.basename(image_path))+++def restore_unmatched_image(image_path):+ """Put the generated image back after color matching was turned off, so a reprojection uses the original view."""+ original = _unmatched_path(image_path)+ if os.path.isfile(original):+ shutil.copyfile(original, image_path)+ os.remove(original)+ print(f"[StableGen] Restored unmatched view: {image_path}")++def _apply_color_match_to_file(image_path, ref_rgb, scene):"""- Load image from disk, color-match to ref_rgb if enabled, and overwrite on disk.+ Color-match the generated image on disk to ref_rgb if enabled. The image as generated is kept in an+ 'unmatched' folder beside it and every match starts from it, so matching never compounds and can be undone."""if not scene.view_blend_use_color_match:return image_path # no-optry:- with Image.open(image_path) as pil_img:+ original = _unmatched_path(image_path)+ if not os.path.isfile(original) and os.path.isfile(image_path):+ os.makedirs(os.path.dirname(original), exist_ok=True)+ shutil.copyfile(image_path, original)+ with Image.open(original if os.path.isfile(original) else image_path) as pil_img:pil_img = pil_img.convert("RGBA")w, h = pil_img.sizetgt_np = np.array(pil_img, dtype=np.float32) / 255.0 # [H, W, 4]