This commit is contained in:
2025-10-13 12:56:15 +02:00
parent 065ab855c1
commit 2494897360
17 changed files with 572 additions and 140 deletions

View File

@@ -3,8 +3,15 @@ Text Texture Generation Engine
Core functionality for generating texture images with text overlays.
"""
import math
import bpy
from ..utils.constants import has_text_fitting
from ..utils.overlay_assets import (
SVGConversionError,
ensure_svg_raster,
is_svg_path,
)
from ..utils.system import find_default_truetype_font
def generate_texture_image(props, width, height):
@@ -96,20 +103,38 @@ def generate_texture_image(props, width, height):
)
for overlay, image_path in overlays_to_apply:
resolved_path = image_path
scale = getattr(overlay, 'scale', 1.0)
try:
with Image.open(image_path) as raw_overlay:
overlay_img = raw_overlay.convert('RGBA')
except Exception as overlay_error:
print(f"WARNING: Failed to load overlay image '{image_path}': {overlay_error}")
scale = float(scale if scale is not None else 1.0)
except (TypeError, ValueError):
scale = 1.0
if not math.isfinite(scale) or scale <= 0:
continue
scale = float(getattr(overlay, 'scale', 1.0) or 1.0)
if scale <= 0:
scale_to_apply = scale
if is_svg_path(resolved_path):
try:
raster_info = ensure_svg_raster(resolved_path, scale)
resolved_path = raster_info.path
scale_to_apply = raster_info.applied_scale
except SVGConversionError as svg_error:
print(f"WARNING: Failed to rasterize SVG overlay '{image_path}': {svg_error}")
continue
try:
with Image.open(resolved_path) as raw_overlay:
overlay_img = raw_overlay.convert('RGBA')
except Exception as overlay_error:
print(f"WARNING: Failed to load overlay image '{resolved_path}': {overlay_error}")
continue
if scale != 1.0:
if scale_to_apply != 1.0:
new_size = (
max(1, int(round(overlay_img.width * scale))),
max(1, int(round(overlay_img.height * scale)))
max(1, int(round(overlay_img.width * scale_to_apply))),
max(1, int(round(overlay_img.height * scale_to_apply)))
)
if new_size != overlay_img.size:
overlay_img = overlay_img.resize(new_size, lanczos_filter)