Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
reset a number to the architecture's first preset value
sakalond778822f017d6
diff --git a/stablegen/ui/presets.py b/stablegen/ui/presets.pyindex 8df1ec1..9aaad84 100644--- a/stablegen/ui/presets.py+++ b/stablegen/ui/presets.py@@ -379,6 +379,62 @@ for _preset_values in PRESETS.values():):_preset_values.pop(_prompt_field, None)+# Preset names repeat their model and variant, which the panels show as tags instead: they list only the current+# architecture's presets, so the model name is redundant there.+PRESET_MODEL_NAMES = {'qwen_image_edit': 'qwen', 'qwen_image_21': 'qwen 2.1', 'qwen_image_21_turbo': 'qwen 2.1 turbo',+ 'fibo_edit': 'fibo', 'moss_image': 'moss', 'flux2_klein': 'klein'}+PRESET_VARIANTS = {'nunchaku': 'Nunchaku', 'experimental': 'Experimental'}+PRESET_WORKFLOWS = ('New texture', 'Refine', 'Local edit', 'UV inpaint', 'Mesh + texture', 'Mesh only')+++def preset_workflow(preset):+ if preset.get('architecture_mode') == 'trellis2':+ return 'Mesh only' if preset.get('trellis2_texture_mode') == 'none' else 'Mesh + texture'+ if preset.get('generation_method') == 'uv_inpaint':+ return 'UV inpaint'+ if 'local_edit' in (preset.get('generation_method'), preset.get('qwen_generation_method')):+ return 'Local edit'+ if preset.get('qwen_generation_method') == 'refine':+ return 'Refine'+ return 'New texture'+++def preset_model(preset):+ if preset.get('architecture_mode') == 'trellis2':+ return preset.get('trellis2_texture_mode', 'none')+ return preset.get('model_architecture', 'sdxl')+++def preset_architecture(preset):+ """The Architecture choice a preset belongs to."""+ return preset.get('architecture_mode') or preset.get('model_architecture', 'sdxl')+++def strip_word(label, word):+ lower = label.casefold()+ if lower.endswith(' (' + word + ')'):+ return label[:-len(word) - 3], True+ if lower.startswith(word + ' '):+ return label[len(word) + 1:], True+ return label, False+++def preset_label(identifier, label):+ preset = PRESETS.get(identifier)+ if not preset:+ return label+ trellis = preset.get('architecture_mode') == 'trellis2'+ for word in ('mesh + texture', 'mesh only', *PRESET_VARIANTS) if trellis else PRESET_VARIANTS:+ label = strip_word(label, word)[0]+ name = PRESET_MODEL_NAMES.get(preset_model(preset))+ if name:+ label = strip_word(label, name)[0]+ if label.startswith('Uv '): # title() case of UV+ label = 'UV ' + label[3:]+ # TRELLIS.2 (MESH ONLY) is the stock mesh preset once its tag says what it does.+ return 'Default' if trellis and label.casefold() == 'trellis.2' else label++# Global list of all generation parameter names to check for a preset.GEN_PARAMETERS = ['control_after_generate',@@ -686,6 +742,26 @@ def get_preset_items(self, context):# Blender's dynamic enums borrow their strings; keep every returned variant.return _PRESET_ENUM_CACHE.setdefault(items, items)++def architecture_presets(context, architecture):+ """The presets the panels offer for *architecture*, in their order: by workflow, then as listed."""+ items = _build_preset_items(context, deprecated_architectures_enabled(context))+ names = [item[0] for item in items+ if item[0] in PRESETS and preset_architecture(PRESETS[item[0]]) == architecture]+ order = {workflow: index for index, workflow in enumerate(PRESET_WORKFLOWS)}+ return sorted(names, key=lambda name: order.get(preset_workflow(PRESETS[name]), len(order)))+++def preset_value(context, key):+ """*key*'s value in the first preset of the scene's architecture, or None when that preset does not set it."""+ names = architecture_presets(context, context.scene.architecture_mode)+ if not names:+ return None+ values = PRESETS[names[0]]+ if key in values:+ return values[key]+ return None if values.get('custom', False) else TEXTURING_DEFAULTS.get(key)+def normalize_value(key, value):if key == "trellis2_remesh" and isinstance(value, bool):return "qdc" if value else "none"diff --git a/stablegen/ui/studio.py b/stablegen/ui/studio.pyindex 5bcc6f6..426fa75 100644--- a/stablegen/ui/studio.py+++ b/stablegen/ui/studio.py@@ -27,7 +27,9 @@ from .presentation import Layout, Control, Section, STRUCTURAL_PROPERTIES, TOOL_from .studio_text import TextBuffer, wrapfrom .studio_widgets import (Painter, FONT_SIZE, CONTROL_HEIGHT, CONTROL_GAP,TEXT_LINE_HEIGHT, TEXT_PADDING, font_size)-from .presets import PRESETS+from .presets import (PRESETS, PRESET_MODEL_NAMES, PRESET_VARIANTS, PRESET_WORKFLOWS,+ preset_label as _preset_label, preset_model as _preset_model,+ preset_workflow as _preset_workflow, strip_word as _strip)from ..utils import sg_modal_activefrom ..core import ADDON_PKG, legacy_panel_enabledfrom ..core.generation_status import WAITING_STAGES@@ -53,57 +55,6 @@ def _architecture_tags(prop, identifier):return tags + [status] if status else tags-# Preset names repeat their model and variant, which the panel shows as tags instead: it lists only the current-# architecture's presets, so the model name is redundant there.-PRESET_MODEL_NAMES = {'qwen_image_edit': 'qwen', 'qwen_image_21': 'qwen 2.1', 'qwen_image_21_turbo': 'qwen 2.1 turbo',- 'fibo_edit': 'fibo', 'moss_image': 'moss', 'flux2_klein': 'klein'}-PRESET_VARIANTS = {'nunchaku': 'Nunchaku', 'experimental': 'Experimental'}-PRESET_WORKFLOWS = ('New texture', 'Refine', 'Local edit', 'UV inpaint', 'Mesh + texture', 'Mesh only')---def _preset_workflow(preset):- if preset.get('architecture_mode') == 'trellis2':- return 'Mesh only' if preset.get('trellis2_texture_mode') == 'none' else 'Mesh + texture'- if preset.get('generation_method') == 'uv_inpaint':- return 'UV inpaint'- if 'local_edit' in (preset.get('generation_method'), preset.get('qwen_generation_method')):- return 'Local edit'- if preset.get('qwen_generation_method') == 'refine':- return 'Refine'- return 'New texture'---def _preset_model(preset):- if preset.get('architecture_mode') == 'trellis2':- return preset.get('trellis2_texture_mode', 'none')- return preset.get('model_architecture', 'sdxl')---def _strip(label, word):- lower = label.casefold()- if lower.endswith(' (' + word + ')'):- return label[:-len(word) - 3], True- if lower.startswith(word + ' '):- return label[len(word) + 1:], True- return label, False---def _preset_label(identifier, label):- preset = PRESETS.get(identifier)- if not preset:- return label- trellis = preset.get('architecture_mode') == 'trellis2'- for word in ('mesh + texture', 'mesh only', *PRESET_VARIANTS) if trellis else PRESET_VARIANTS:- label = _strip(label, word)[0]- name = PRESET_MODEL_NAMES.get(_preset_model(preset))- if name:- label = _strip(label, name)[0]- if label.startswith('Uv '): # title() case of UV- label = 'UV ' + label[3:]- # TRELLIS.2 (MESH ONLY) is the stock mesh preset once its tag says what it does.- return 'Default' if trellis and label.casefold() == 'trellis.2' else label--def _preset_tags(identifier):"""Tags for a preset, drawn right to left: its workflow, then its texture model (TRELLIS.2) and variant."""preset = PRESETS.get(identifier)@@ -482,7 +433,7 @@ class StudioSession:binding, text = edit['binding'], edit['buffer'].textprop = binding.rna(bpy.context)if prop.type in {'INT', 'FLOAT'} and not text.strip():- value = prop.default # an emptied number resets to its default+ value = model.reset_value(binding, bpy.context) # an emptied number resetselse:value = float(text) if prop.type == 'FLOAT' else int(text) if prop.type == 'INT' else textif binding.value(bpy.context) != value:@@ -727,7 +678,7 @@ class StudioSession:def number_key(self, event):"""Blender's keys over a hovered number button: Ctrl+Wheel steps, Enter types, Ctrl+C/Ctrl+V copy and- paste, Backspace resets to the default and Minus negates."""+ paste, Backspace resets (studio_model.reset_value) and Minus negates."""target = self.hit_target()if (event.value != 'PRESS' or not target or not target.enabled or not isinstance(target.action, tuple)or target.action[0] != 'number'):@@ -750,7 +701,7 @@ class StudioSession:self.set_value(binding, value)elif event.type == 'BACK_SPACE' and not ctrl:with _context(self):- default = binding.rna(bpy.context).default+ default = model.reset_value(binding, bpy.context)self.set_value(binding, default)elif event.type in {'MINUS', 'NUMPAD_MINUS'} and not ctrl:with _context(self):diff --git a/stablegen/ui/studio_model.py b/stablegen/ui/studio_model.pyindex cde00f0..9c298b7 100644--- a/stablegen/ui/studio_model.py+++ b/stablegen/ui/studio_model.py@@ -7,7 +7,7 @@ from pathlib import Pathimport bpyfrom .presentation import Layout, Control, capture_panel-from .presets import get_preset_items+from .presets import get_preset_items, preset_valuefrom .model_units import update_model_list, get_lora_models, get_controlnet_modelsfrom ..core.architectures import (architecture_items, model_architecture_items,trellis_texture_items, trellis_initial_image_items)@@ -47,6 +47,16 @@ def _round(value):return math.copysign(math.floor(abs(value) + .5), value)+def reset_value(binding, context):+ """What Backspace or an emptied field resets a number to: its value in the first preset of the scene's+ architecture when that preset sets this scene setting, else the property's default."""+ if binding.root == 'scene' and not binding.path:+ value = preset_value(context, binding.property)+ if isinstance(value, (int, float)) and not isinstance(value, bool):+ return value+ return binding.rna(context).default++def number_step(prop):"""The arrow and Ctrl+Wheel increment: an int's step, or a float's step in hundredths."""return prop.step * .01 if prop.type == 'FLOAT' else max(1, int(prop.step))