Skip to content

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

add manifest-driven glb texture batching

sakalond776105dc3155
diff --git a/stablegen/__init__.py b/stablegen/__init__.py
index bffd241..2b1b1bf 100644
--- a/stablegen/__init__.py
+++ b/stablegen/__init__.py
@@ -211,7 +211,9 @@ def register():
def unregister():
from .mesh_gen.batch import unregister_batch
+ from .dae_import.batch_texture import unregister_batch_texture
unregister_batch()
+ unregister_batch_texture()
cleanup_retarget_overlays()
unregister_properties(
diff --git a/stablegen/dae_import/__init__.py b/stablegen/dae_import/__init__.py
index 4206b2d..24ca12a 100644
--- a/stablegen/dae_import/__init__.py
+++ b/stablegen/dae_import/__init__.py
@@ -5,6 +5,9 @@ versions (including 5.x where the built-in Collada importer was removed),
plus geometry cleanup utilities tailored for SketchUp exports.
"""
-from .operators import DAE_IMPORT_CLASSES
+from .operators import DAE_IMPORT_CLASSES as _DAE_IMPORT_CLASSES
+from .batch_texture import BATCH_TEXTURE_CLASSES
+
+DAE_IMPORT_CLASSES = [*_DAE_IMPORT_CLASSES, *BATCH_TEXTURE_CLASSES]
__all__ = ["DAE_IMPORT_CLASSES"]
diff --git a/stablegen/dae_import/batch_manifest.py b/stablegen/dae_import/batch_manifest.py
new file mode 100644
index 0000000..3f4b4d0
--- /dev/null
+++ b/stablegen/dae_import/batch_manifest.py
@@ -0,0 +1,157 @@
+"""Pure-Python helpers for StableGen model batch manifests.
+
+The Blender operator imports this module, but it intentionally has no ``bpy``
+dependency so manifest validation can be tested outside Blender.
+"""
+
+from __future__ import annotations
+
+import csv
+import os
+import re
+
+
+SUPPORTED_MODEL_EXTENSIONS = {".dae", ".glb"}
+SUPPORTED_IMAGE_EXTENSIONS = {
+ ".png", ".jpg", ".jpeg", ".webp", ".bmp", ".tiff",
+}
+
+_REQUIRED_COLUMNS = {"model_path", "reference_path", "output_path"}
+
+
+def _resolve_inside(root: str, relative_path: str, label: str) -> str:
+ """Resolve a manifest path while preventing absolute/traversal paths."""
+ value = (relative_path or "").strip().replace("/", os.sep)
+ if not value:
+ raise ValueError(f"{label} is empty")
+ if os.path.isabs(value) or os.path.splitdrive(value)[0]:
+ raise ValueError(f"{label} must be relative: {relative_path!r}")
+
+ root_real = os.path.realpath(root)
+ resolved = os.path.realpath(os.path.join(root_real, value))
+ try:
+ inside = os.path.commonpath((root_real, resolved)) == root_real
+ except ValueError as exc:
+ raise ValueError(f"{label} escapes the manifest directory") from exc
+ if not inside:
+ raise ValueError(f"{label} escapes the manifest directory")
+ return resolved
+
+
+def load_batch_manifest(manifest_path: str) -> tuple[str, list[dict[str, str]]]:
+ """Load and validate a CSV manifest.
+
+ Paths are relative to the directory containing the manifest. Input files
+ must exist. Output paths are validated for containment and a ``.glb``
+ extension, but they do not need to exist.
+ """
+ manifest_abs = os.path.realpath(manifest_path)
+ if not os.path.isfile(manifest_abs):
+ raise ValueError(f"Batch manifest does not exist: {manifest_path}")
+ root = os.path.dirname(manifest_abs)
+
+ with open(manifest_abs, "r", encoding="utf-8-sig", newline="") as handle:
+ reader = csv.DictReader(handle)
+ columns = set(reader.fieldnames or ())
+ missing = sorted(_REQUIRED_COLUMNS - columns)
+ if missing:
+ raise ValueError(
+ "Batch manifest is missing column(s): " + ", ".join(missing)
+ )
+ source_rows = list(reader)
+
+ if not source_rows:
+ raise ValueError("Batch manifest contains no model rows")
+
+ entries: list[dict[str, str]] = []
+ seen_models: set[str] = set()
+ seen_outputs: set[str] = set()
+ for row_number, row in enumerate(source_rows, start=2):
+ model_path = _resolve_inside(
+ root, row.get("model_path", ""), f"row {row_number} model_path"
+ )
+ reference_path = _resolve_inside(
+ root,
+ row.get("reference_path", ""),
+ f"row {row_number} reference_path",
+ )
+ output_path = _resolve_inside(
+ root, row.get("output_path", ""), f"row {row_number} output_path"
+ )
+
+ model_ext = os.path.splitext(model_path)[1].lower()
+ if model_ext not in SUPPORTED_MODEL_EXTENSIONS:
+ raise ValueError(
+ f"row {row_number} has unsupported model format: {model_ext}"
+ )
+ reference_ext = os.path.splitext(reference_path)[1].lower()
+ if reference_ext not in SUPPORTED_IMAGE_EXTENSIONS:
+ raise ValueError(
+ f"row {row_number} has unsupported reference format: "
+ f"{reference_ext}"
+ )
+ if os.path.splitext(output_path)[1].lower() != ".glb":
+ raise ValueError(f"row {row_number} output_path must end in .glb")
+ if not os.path.isfile(model_path):
+ raise ValueError(f"row {row_number} model is missing: {model_path}")
+ if not os.path.isfile(reference_path):
+ raise ValueError(
+ f"row {row_number} reference is missing: {reference_path}"
+ )
+
+ model_key = os.path.normcase(model_path)
+ output_key = os.path.normcase(output_path)
+ if model_key in seen_models:
+ raise ValueError(f"row {row_number} repeats model_path")
+ if output_key in seen_outputs:
+ raise ValueError(f"row {row_number} repeats output_path")
+ seen_models.add(model_key)
+ seen_outputs.add(output_key)
+
+ entries.append({
+ "model_path": model_path,
+ "relative_path": os.path.relpath(model_path, root),
+ "reference_path": reference_path,
+ "output_relative_path": os.path.relpath(output_path, root),
+ })
+
+ return root, entries
+
+
+def discover_model_files(root: str, recursive: bool = True) -> list[dict[str, str]]:
+ """Discover DAE and GLB inputs in deterministic path order."""
+ root_abs = os.path.realpath(root)
+ paths: list[str] = []
+ if recursive:
+ for dirpath, dirnames, filenames in os.walk(root_abs):
+ dirnames.sort()
+ for filename in sorted(filenames):
+ if os.path.splitext(filename)[1].lower() in SUPPORTED_MODEL_EXTENSIONS:
+ paths.append(os.path.join(dirpath, filename))
+ else:
+ for filename in sorted(os.listdir(root_abs)):
+ path = os.path.join(root_abs, filename)
+ if (os.path.isfile(path) and
+ os.path.splitext(filename)[1].lower() in
+ SUPPORTED_MODEL_EXTENSIONS):
+ paths.append(path)
+
+ entries = []
+ for path in paths:
+ relative = os.path.relpath(path, root_abs)
+ output_relative = os.path.splitext(relative)[0] + ".glb"
+ entries.append({
+ "model_path": path,
+ "relative_path": relative,
+ "reference_path": "",
+ "output_relative_path": output_relative,
+ })
+ return entries
+
+
+def filename_contains_model_stem(filename: str, model_stem: str) -> bool:
+ """Match a model stem without allowing house 25 to match house 250."""
+ if not model_stem:
+ return False
+ pattern = rf"(?<![0-9A-Za-z]){re.escape(model_stem)}(?![0-9A-Za-z])"
+ return re.search(pattern, filename, flags=re.IGNORECASE) is not None
diff --git a/stablegen/dae_import/batch_texture.py b/stablegen/dae_import/batch_texture.py
index 350c0e9..3c90967 100644
--- a/stablegen/dae_import/batch_texture.py
+++ b/stablegen/dae_import/batch_texture.py
@@ -1,6 +1,6 @@
-"""Batch DAE import + texture generation pipeline.
+"""Batch model import + texture generation pipeline.
-Imports each .dae file, auto-places cameras, generates textures using
+Imports each DAE or GLB file, auto-places cameras, generates textures using
the current scene settings, bakes, and exports to GLB — all without
user intervention. Follows the same timer-based state-machine pattern
as :pymod:`mesh_gen.batch`.
@@ -10,6 +10,11 @@ import os
import bpy # pylint: disable=import-error
from ..utils import sg_modal_active
+from .batch_manifest import (
+ discover_model_files,
+ filename_contains_model_stem,
+ load_batch_manifest,
+)
# Reference image filenames (checked in order)
_REF_NAMES = ('ref.png', 'ref.jpg', 'ref.jpeg')
@@ -19,7 +24,7 @@ _IMAGE_EXTS = {'.png', '.jpg', '.jpeg', '.webp', '.bmp', '.tiff'}
_batch_state = {
'active': False,
'cancelled': False,
- 'files': [], # list of (abs_path, rel_path)
+ 'files': [], # validated model-entry dictionaries
'index': -1,
'total': 0,
'top_dir': '', # root directory (for fallback ref image)
@@ -58,22 +63,26 @@ def _sync_wm():
# ── Reference image resolution ──────────────────────────────────────────────
-def _find_ref_image(dae_path, top_dir, ref_dir=''):
+def _find_ref_image(model_path, top_dir, ref_dir='', explicit_ref=''):
"""Return the path to a reference image for this model, or ''.
Search order:
- 1. Separate reference directory (*ref_dir*): find an image file whose
- name contains the building number (stem of the .dae filename) in the
- matching subdirectory.
- 2. Same subdirectory as the .dae file: look for ref.png / ref.jpg / ref.jpeg.
- 3. Top-level model directory fallback: same ref names at *top_dir*.
+ An explicit manifest reference always wins. Otherwise, search a separate
+ reference tree using a token-safe model-stem match, then ``ref.*``
+ fallbacks beside the model and in the configured roots.
"""
- dae_stem = os.path.splitext(os.path.basename(dae_path))[0]
- dae_dir = os.path.dirname(dae_path)
+ if explicit_ref:
+ if os.path.isfile(explicit_ref):
+ return explicit_ref
+ print(f"[BatchTex] Explicit reference is missing: {explicit_ref}")
+ return ''
+
+ model_stem = os.path.splitext(os.path.basename(model_path))[0]
+ model_dir = os.path.dirname(model_path)
# 1. Separate reference image directory (building-specific match)
if ref_dir and os.path.isdir(ref_dir):
- rel = os.path.relpath(dae_dir, top_dir)
+ rel = os.path.relpath(model_dir, top_dir)
# Try the full relative path first, then progressively shorter
# suffixes (e.g. "3D_modely/Úzká" → "Úzká") so the ref dir
# doesn't need to replicate the exact model-tree prefix.
@@ -86,20 +95,21 @@ def _find_ref_image(dae_path, top_dir, ref_dir=''):
continue
for name in sorted(os.listdir(search_dir)):
ext = os.path.splitext(name)[1].lower()
- if ext in _IMAGE_EXTS and dae_stem in name:
+ if (ext in _IMAGE_EXTS and
+ filename_contains_model_stem(name, model_stem)):
return os.path.join(search_dir, name)
elif ref_dir:
print(f"[BatchTex] ref_dir={ref_dir!r} isdir={os.path.isdir(ref_dir)}")
# 2. Same directory as the .dae file (subdir-level fallback)
for name in _REF_NAMES:
- candidate = os.path.join(dae_dir, name)
+ candidate = os.path.join(model_dir, name)
if os.path.isfile(candidate):
return candidate
# 3. Separate ref dir — subdirectory fallback ref image
if ref_dir and os.path.isdir(ref_dir):
- rel = os.path.relpath(dae_dir, top_dir)
+ rel = os.path.relpath(model_dir, top_dir)
parts = rel.replace('\\', '/').split('/')
candidates = [os.path.join(*parts[i:]) for i in range(len(parts))]
candidates.append('.')
@@ -122,10 +132,121 @@ def _find_ref_image(dae_path, top_dir, ref_dir=''):
# ── Phase handlers ──────────────────────────────────────────────────────────
+def _center_meshes_at_origin(objects):
+ """Center mesh bounds in XY and place the lowest point on Z=0."""
+ import mathutils # pylint: disable=import-error
+
+ corners = []
+ for obj in objects:
+ corners.extend(obj.matrix_world @ mathutils.Vector(corner)
+ for corner in obj.bound_box)
+ if not corners:
+ return
+ center_x = (min(point.x for point in corners) +
+ max(point.x for point in corners)) / 2.0
+ center_y = (min(point.y for point in corners) +
+ max(point.y for point in corners)) / 2.0
+ bottom_z = min(point.z for point in corners)
+ for obj in objects:
+ obj.location.x -= center_x
+ obj.location.y -= center_y
+ obj.location.z -= bottom_z
+
+
+def _scale_meshes(objects, target_size):
+ """Uniformly scale meshes so their largest world-space extent matches."""
+ if target_size <= 0:
+ return
+ import mathutils # pylint: disable=import-error
+
+ corners = []
+ for obj in objects:
+ corners.extend(obj.matrix_world @ mathutils.Vector(corner)
+ for corner in obj.bound_box)
+ if not corners:
+ return
+ extent = max(
+ max(point.x for point in corners) - min(point.x for point in corners),
+ max(point.y for point in corners) - min(point.y for point in corners),
+ max(point.z for point in corners) - min(point.z for point in corners),
+ )
+ if extent < 1e-6:
+ return
+ factor = target_size / extent
+ for obj in objects:
+ obj.scale *= factor
+
+
+def _import_glb(filepath, settings):
+ """Import an already-simplified GLB and prepare it for retexturing.
+
+ Libuše GLBs are output from the project's simplification pipeline. Heavy
+ DAE cleanup (interior removal, fan repair, remeshing) would alter that
+ verified geometry, so GLB preparation is deliberately light: remove
+ non-mesh scene nodes, strip the old baked material, join meshes, normalize
+ placement, and apply scale.
+ """
+ result = bpy.ops.import_scene.gltf(filepath=filepath)
+ if 'FINISHED' not in result:
+ raise RuntimeError("Blender GLB importer did not finish")
+
+ context = bpy.context
+ meshes = [obj for obj in context.scene.objects if obj.type == 'MESH']
+ if not meshes:
+ raise RuntimeError("GLB contains no mesh objects")
+
+ # Detach meshes while preserving world transforms, then remove imported
+ # empties, cameras, and lights so they cannot influence camera setup.
+ for obj in meshes:
+ world_matrix = obj.matrix_world.copy()
+ obj.parent = None
+ obj.matrix_world = world_matrix
+ for obj in list(context.scene.objects):
+ if obj.type != 'MESH':
+ bpy.data.objects.remove(obj, do_unlink=True)
+
+ # Apply the imported scene graph before joining separate mesh nodes.
+ bpy.ops.object.select_all(action='DESELECT')
+ for obj in meshes:
+ obj.select_set(True)
+ context.view_layer.objects.active = meshes[0]
+ bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
+
+ if len(meshes) > 1:
+ bpy.ops.object.join()
+ meshes = [context.view_layer.objects.active]
+
+ from . import cleanup
+ if settings.get('strip_materials', True):
+ cleanup.strip_materials_and_apply_clean(meshes[0])
+
+ if settings.get('center_origin', True):
+ _center_meshes_at_origin(meshes)
+ _scale_meshes(meshes, settings.get('auto_scale', 0.0))
+
+ bpy.ops.object.select_all(action='DESELECT')
+ for obj in meshes:
+ obj.select_set(True)
+ context.view_layer.objects.active = meshes[0]
+ bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
+
+ shading = settings.get('shading_mode', 'FLAT')
+ if shading == 'SMOOTH':
+ bpy.ops.object.shade_smooth()
+ elif shading == 'AUTO':
+ cleanup.auto_smooth_shading(meshes[0])
+ else:
+ bpy.ops.object.shade_flat()
+
+ vertices = sum(len(obj.data.vertices) for obj in meshes)
+ faces = sum(len(obj.data.polygons) for obj in meshes)
+ print(f"[BatchTex] GLB import complete: {vertices} verts, {faces} faces")
+
+
def _do_import():
- """Import the current DAE file. Returns True on success."""
+ """Import the current DAE or GLB file. Returns True on success."""
state = _batch_state
- filepath = state['files'][state['index']][0]
+ filepath = state['files'][state['index']]['model_path']
settings = state['settings']
# Clear scene
@@ -133,22 +254,30 @@ def _do_import():
bpy.ops.object.delete(use_global=False)
try:
- bpy.ops.stablegen.import_dae(
- filepath=filepath,
- merge_threshold=settings.get('merge_threshold', 0.001),
- remove_interior=settings.get('remove_interior', True),
- remove_ground=settings.get('remove_ground', True),
- strip_materials=settings.get('strip_materials', True),
- topology_method=settings.get('topology_method', 'FIX_FANS'),
- edge_ratio=settings.get('edge_ratio', 2.5),
- equalize_iterations=settings.get('equalize_iterations', 4),
- voxel_size=settings.get('voxel_size', 0.0),
- auto_scale=settings.get('auto_scale', 0.0),
- shading_mode=settings.get('shading_mode', 'FLAT'),
- center_origin=settings.get('center_origin', True),
- join_meshes=True,
- triangulate=settings.get('triangulate', True),
- )
+ extension = os.path.splitext(filepath)[1].lower()
+ if extension == '.dae':
+ result = bpy.ops.stablegen.import_dae(
+ filepath=filepath,
+ merge_threshold=settings.get('merge_threshold', 0.001),
+ remove_interior=settings.get('remove_interior', True),
+ remove_ground=settings.get('remove_ground', True),
+ strip_materials=settings.get('strip_materials', True),
+ topology_method=settings.get('topology_method', 'FIX_FANS'),
+ edge_ratio=settings.get('edge_ratio', 2.5),
+ equalize_iterations=settings.get('equalize_iterations', 4),
+ voxel_size=settings.get('voxel_size', 0.0),
+ auto_scale=settings.get('auto_scale', 0.0),
+ shading_mode=settings.get('shading_mode', 'FLAT'),
+ center_origin=settings.get('center_origin', True),
+ join_meshes=True,
+ triangulate=settings.get('triangulate', True),
+ )
+ if 'FINISHED' not in result:
+ raise RuntimeError("StableGen DAE importer did not finish")
+ elif extension == '.glb':
+ _import_glb(filepath, settings)
+ else:
+ raise ValueError(f"Unsupported model format: {extension}")
return True
except Exception as exc: # noqa: BLE001
print(f"[BatchTex] FAILED to import: {exc}")
@@ -213,9 +342,11 @@ def _do_cameras():
def _do_set_ref_image():
"""Set the reference image for the current model on the scene properties."""
state = _batch_state
- filepath = state['files'][state['index']][0]
+ entry = state['files'][state['index']]
+ filepath = entry['model_path']
ref = _find_ref_image(filepath, state['top_dir'],
- state['settings'].get('ref_image_dir', ''))
+ state['settings'].get('ref_image_dir', ''),
+ entry.get('reference_path', ''))
scene = bpy.context.scene
arch = getattr(scene, 'model_architecture', 'sdxl')
@@ -401,13 +532,9 @@ def _apply_baked_material(context, obj):
def _do_export():
"""Export the current textured mesh to GLB."""
state = _batch_state
- rel_path = state['files'][state['index']][1]
- name = os.path.splitext(os.path.basename(rel_path))[0]
- rel_dir = os.path.dirname(rel_path)
- file_out_dir = os.path.join(state['out_dir'], rel_dir) if rel_dir else state['out_dir']
- os.makedirs(file_out_dir, exist_ok=True)
-
- out_path = os.path.join(file_out_dir, f"{name}.glb")
+ entry = state['files'][state['index']]
+ out_path = os.path.join(state['out_dir'], entry['output_relative_path'])
+ os.makedirs(os.path.dirname(out_path), exist_ok=True)
# Select all mesh objects
bpy.ops.object.select_all(action='DESELECT')
@@ -448,12 +575,10 @@ def _batch_tex_tick():
next_idx = state['index'] + 1
# Skip files whose output GLB already exists (resume support)
while next_idx < state['total']:
- rel_path = state['files'][next_idx][1]
- name = os.path.splitext(os.path.basename(rel_path))[0]
- rel_dir = os.path.dirname(rel_path)
- file_out_dir = (os.path.join(state['out_dir'], rel_dir)
- if rel_dir else state['out_dir'])
- out_path = os.path.join(file_out_dir, f"{name}.glb")
+ entry = state['files'][next_idx]
+ rel_path = entry['relative_path']
+ out_path = os.path.join(
+ state['out_dir'], entry['output_relative_path'])
if os.path.exists(out_path):
print(f"[BatchTex] Skipping {next_idx + 1}/{state['total']}: "
f"{rel_path} (already exported)")
@@ -471,7 +596,7 @@ def _batch_tex_tick():
state['index'] = next_idx
state['phase'] = 'import'
_sync_wm()
- rel = state['files'][next_idx][1]
+ rel = state['files'][next_idx]['relative_path']
print(f"[BatchTex] {next_idx + 1}/{state['total']}: {rel}")
return _TICK_INTERVAL
@@ -573,21 +698,21 @@ def _batch_tex_tick():
# ── Operators ───────────────────────────────────────────────────────────────
class BatchTextureDAE(bpy.types.Operator):
- """Batch import .dae files, auto-place cameras, generate textures,
+ """Batch import DAE/GLB files, auto-place cameras, generate textures,
bake, and export to .glb — fully automated pipeline."""
bl_idname = "stablegen.batch_texture_dae"
- bl_label = "Batch Texture DAE Files"
+ bl_label = "Batch Texture DAE / GLB Files"
bl_options = {'REGISTER'}
directory: bpy.props.StringProperty(
name="Directory",
- description="Directory containing .dae files",
+ description="Directory containing DAE/GLB files or a batch manifest",
subtype='DIR_PATH',
) # type: ignore
filter_glob: bpy.props.StringProperty(
- default="*.dae",
+ default="*.dae;*.glb;*.csv",
options={'HIDDEN'},
) # type: ignore
@@ -603,6 +728,16 @@ class BatchTextureDAE(bpy.types.Operator):
default=True,
) # type: ignore
+ manifest_path: bpy.props.StringProperty(
+ name="Batch Manifest",
+ description=(
+ "Optional CSV with model_path, reference_path, and output_path. "
+ "Manifest paths are exact and relative to the CSV location"
+ ),
+ default="",
+ subtype='FILE_PATH',
+ ) # type: ignore
+
ref_image_dir: bpy.props.StringProperty(
name="Reference Images",
description=(
@@ -720,6 +855,7 @@ class BatchTextureDAE(bpy.types.Operator):
box = layout.box()
box.prop(self, "output_dir")
box.prop(self, "recursive")
+ box.prop(self, "manifest_path")
box.prop(self, "ref_image_dir")
box.prop(self, "bake")
if self.bake:
@@ -758,27 +894,36 @@ class BatchTextureDAE(bpy.types.Operator):
box.label(text="Camera placement uses TRELLIS.2 camera settings")
def execute(self, context):
- if not self.directory or not os.path.isdir(self.directory):
- self.report({'ERROR'}, "No valid directory selected")
- return {'CANCELLED'}
-
- dae_files = self._collect_dae_files()
- if not dae_files:
- self.report({'WARNING'}, "No .dae files found")
+ manifest_path = bpy.path.abspath(self.manifest_path).strip()
+ if manifest_path:
+ try:
+ top_dir, model_files = load_batch_manifest(manifest_path)
+ except ValueError as exc:
+ self.report({'ERROR'}, str(exc))
+ return {'CANCELLED'}
+ else:
+ top_dir = bpy.path.abspath(self.directory).rstrip('/\\')
+ if not top_dir or not os.path.isdir(top_dir):
+ self.report({'ERROR'}, "No valid model directory selected")
+ return {'CANCELLED'}
+ model_files = discover_model_files(top_dir, self.recursive)
+
+ if not model_files:
+ self.report({'WARNING'}, "No DAE or GLB files found")
return {'CANCELLED'}
- out_dir = self.output_dir or os.path.join(
- self.directory.rstrip('/\\'), "textured")
+ configured_output = bpy.path.abspath(self.output_dir).strip()
+ out_dir = configured_output or os.path.join(top_dir, "textured")
os.makedirs(out_dir, exist_ok=True)
scene = context.scene
_batch_state.update({
'active': True,
'cancelled': False,
- 'files': dae_files,
+ 'files': model_files,
'index': -1,
- 'total': len(dae_files),
- 'top_dir': self.directory.rstrip('/\\'),
+ 'total': len(model_files),
+ 'top_dir': top_dir,
'out_dir': out_dir,
'phase': 'idle',
'settle_count': 0,
@@ -820,27 +965,13 @@ class BatchTextureDAE(bpy.types.Operator):
})
_sync_wm()
- self.report({'INFO'}, f"Batch texturing started: {len(dae_files)} file(s)")
- print(f"[BatchTex] Starting: {len(dae_files)} file(s) from '{self.directory}'")
+ self.report({'INFO'},
+ f"Batch texturing started: {len(model_files)} file(s)")
+ source = manifest_path or top_dir
+ print(f"[BatchTex] Starting: {len(model_files)} file(s) from '{source}'")
bpy.app.timers.register(_batch_tex_tick, first_interval=0.1)
return {'FINISHED'}
- def _collect_dae_files(self):
- root = self.directory.rstrip('/\\')
- results = []
- if self.recursive:
- for dirpath, _dirs, files in os.walk(root):
- for f in sorted(files):
- if f.lower().endswith('.dae'):
- abs_path = os.path.join(dirpath, f)
- rel_path = os.path.relpath(abs_path, root)
- results.append((abs_path, rel_path))
- else:
- for f in sorted(os.listdir(root)):
- if f.lower().endswith('.dae'):
- results.append((os.path.join(root, f), f))
- return results
-
class BatchTextureDAECancel(bpy.types.Operator):
"""Cancel the running batch texture pipeline."""
diff --git a/stablegen/ui/panel.py b/stablegen/ui/panel.py
index 1f0fa07..82ed8b4 100644
--- a/stablegen/ui/panel.py
+++ b/stablegen/ui/panel.py
@@ -2250,6 +2250,17 @@ class StableGenPanel(bpy.types.Panel):
if width_mode == 'narrow':
row = tools_box.row()
row.operator("stablegen.batch_import_dae", text="Batch Import DAE", icon="FILE_FOLDER")
+ row = tools_box.row()
+ row.operator(
+ "stablegen.batch_texture_dae",
+ text="Batch Texture DAE / GLB",
+ icon="TEXTURE",
+ )
+ row.operator(
+ "stablegen.batch_texture_dae_cancel",
+ text="Cancel Batch",
+ icon="CANCEL",
+ )
row = tools_box.row()
if config_error_message: