WORKING
This commit is contained in:
@@ -23,7 +23,6 @@ def generate_texture_image(props, width, height):
|
||||
pass
|
||||
|
||||
# Enhanced texture generation with proper error handling and logging
|
||||
print(f"DEBUG: Starting texture generation {width}x{height}")
|
||||
|
||||
# Create Blender image directly without large numpy arrays
|
||||
img_name = f"TextTexture_{width}x{height}"
|
||||
@@ -38,7 +37,6 @@ def generate_texture_image(props, width, height):
|
||||
try:
|
||||
pass
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
print("DEBUG: PIL imported successfully")
|
||||
|
||||
# Create PIL image with transparent background
|
||||
if props.background_transparent:
|
||||
@@ -64,7 +62,6 @@ def generate_texture_image(props, width, height):
|
||||
if full_text_parts:
|
||||
pass
|
||||
draw = ImageDraw.Draw(pil_img)
|
||||
print(f"DEBUG: Drawing text parts: {full_text_parts}")
|
||||
|
||||
# Combine text based on layout mode
|
||||
if props.prepend_append_layout == 'HORIZONTAL':
|
||||
@@ -137,9 +134,13 @@ def generate_texture_image(props, width, height):
|
||||
pass
|
||||
test_font = ImageFont.load_default()
|
||||
|
||||
bbox = draw.textbbox((0, 0), full_text, font=test_font)
|
||||
test_width = bbox[2] - bbox[0]
|
||||
test_height = bbox[3] - bbox[1]
|
||||
try:
|
||||
bbox = draw.textbbox((0, 0), full_text, font=test_font)
|
||||
test_width = bbox[2] - bbox[0]
|
||||
test_height = bbox[3] - bbox[1]
|
||||
except (ValueError, AttributeError):
|
||||
# Fallback for bitmap fonts
|
||||
test_width, test_height = draw.textsize(full_text, font=test_font)
|
||||
|
||||
if test_width <= target_width and test_height <= target_height:
|
||||
pass
|
||||
@@ -182,8 +183,12 @@ def generate_texture_image(props, width, height):
|
||||
part_heights = []
|
||||
for part in full_text_parts:
|
||||
pass
|
||||
bbox = draw.textbbox((0, 0), part, font=font)
|
||||
part_height = bbox[3] - bbox[1]
|
||||
try:
|
||||
bbox = draw.textbbox((0, 0), part, font=font)
|
||||
part_height = bbox[3] - bbox[1]
|
||||
except (ValueError, AttributeError):
|
||||
# Fallback for bitmap fonts
|
||||
_, part_height = draw.textsize(part, font=font)
|
||||
part_heights.append(part_height)
|
||||
total_height += part_height
|
||||
|
||||
@@ -202,8 +207,12 @@ def generate_texture_image(props, width, height):
|
||||
|
||||
for i, part in enumerate(full_text_parts):
|
||||
pass
|
||||
bbox = draw.textbbox((0, 0), part, font=font)
|
||||
part_width = bbox[2] - bbox[0]
|
||||
try:
|
||||
bbox = draw.textbbox((0, 0), part, font=font)
|
||||
part_width = bbox[2] - bbox[0]
|
||||
except (ValueError, AttributeError):
|
||||
# Fallback for bitmap fonts
|
||||
part_width, _ = draw.textsize(part, font=font)
|
||||
x = (width - part_width) // 2 # Center horizontally
|
||||
|
||||
draw.text((x, current_y), part, font=font, fill=text_color)
|
||||
@@ -215,9 +224,13 @@ def generate_texture_image(props, width, height):
|
||||
else:
|
||||
pass
|
||||
# Horizontal layout or single text
|
||||
text_bbox = draw.textbbox((0, 0), full_text, font=font)
|
||||
text_width = text_bbox[2] - text_bbox[0]
|
||||
text_height = text_bbox[3] - text_bbox[1]
|
||||
try:
|
||||
text_bbox = draw.textbbox((0, 0), full_text, font=font)
|
||||
text_width = text_bbox[2] - text_bbox[0]
|
||||
text_height = text_bbox[3] - text_bbox[1]
|
||||
except (ValueError, AttributeError):
|
||||
# Fallback for bitmap fonts that don't support textbbox
|
||||
text_width, text_height = draw.textsize(full_text, font=font)
|
||||
|
||||
# Center text
|
||||
x = (width - text_width) // 2
|
||||
@@ -226,10 +239,8 @@ def generate_texture_image(props, width, height):
|
||||
# Draw text
|
||||
text_color = tuple(int(c * 255) for c in props.text_color[:4])
|
||||
draw.text((x, y), full_text, font=font, fill=text_color)
|
||||
print(f"DEBUG: Text drawn at position ({x}, {y}) with color {text_color}")
|
||||
else:
|
||||
pass
|
||||
print("DEBUG: No text provided, using solid background")
|
||||
|
||||
# Convert PIL image to Blender format (flip vertically to fix mirroring)
|
||||
pil_img = pil_img.transpose(Image.FLIP_TOP_BOTTOM) # Fix mirroring issue
|
||||
@@ -239,9 +250,8 @@ def generate_texture_image(props, width, height):
|
||||
pass
|
||||
blender_pixels.extend([r/255.0, g/255.0, b/255.0, a/255.0])
|
||||
|
||||
print(f"DEBUG: Converting {len(pil_pixels)} PIL pixels to Blender format")
|
||||
blender_img.pixels[:] = blender_pixels
|
||||
print(f"DEBUG: Texture generation completed successfully")
|
||||
return blender_img, None
|
||||
except ImportError as e:
|
||||
pass
|
||||
# PIL not available - should not happen with proper Blender manifest dependencies
|
||||
@@ -251,56 +261,13 @@ def generate_texture_image(props, width, height):
|
||||
error_pattern = [1.0, 1.0, 0.0, 1.0] # Yellow color to indicate dependency problem
|
||||
total_pixels = width * height
|
||||
blender_img.pixels[:] = error_pattern * total_pixels
|
||||
print(f"DEBUG: Yellow error texture created (dependency issue)")
|
||||
return blender_img, None
|
||||
|
||||
except ImportError as e:
|
||||
pass
|
||||
# PIL installation or import failed - create visible error pattern
|
||||
print(f"ERROR: PIL import error: {e}")
|
||||
# Create a visible red error pattern instead of black
|
||||
error_pattern = [1.0, 0.0, 0.0, 1.0] # Red color to indicate PIL failure
|
||||
total_pixels = width * height
|
||||
blender_img.pixels[:] = error_pattern * total_pixels
|
||||
print(f"DEBUG: Red error texture created (PIL import error)")
|
||||
except Exception as e:
|
||||
pass
|
||||
print(f"ERROR: Texture generation failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
# Create a visible error pattern instead of black
|
||||
error_pattern = [1.0, 0.0, 1.0, 1.0] # Magenta color for general errors
|
||||
total_pixels = width * height
|
||||
blender_img.pixels[:] = error_pattern * total_pixels
|
||||
print(f"DEBUG: Magenta error texture created (general error)")
|
||||
|
||||
blender_img.pack()
|
||||
|
||||
# Generate normal map if enabled
|
||||
normal_map_img = None
|
||||
if props.generate_normal_map:
|
||||
pass
|
||||
try:
|
||||
pass
|
||||
from .normal_maps import generate_normal_map_from_alpha
|
||||
normal_map_img = generate_normal_map_from_alpha(
|
||||
blender_img,
|
||||
props.normal_map_strength,
|
||||
props.normal_map_blur_radius,
|
||||
props.normal_map_invert
|
||||
)
|
||||
except ImportError:
|
||||
pass
|
||||
normal_map_img = None
|
||||
else:
|
||||
pass
|
||||
print("Normal map generation disabled, skipping")
|
||||
|
||||
return blender_img, normal_map_img
|
||||
|
||||
except Exception as e:
|
||||
pass
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None, None
|
||||
|
||||
def generate_preview(props, preview_width=512, preview_height=512):
|
||||
|
||||
Reference in New Issue
Block a user