refactor
This commit is contained in:
100
core/generation_engine.py
Normal file
100
core/generation_engine.py
Normal file
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
Text Texture Generation Engine
|
||||
Core functionality for generating texture images with text overlays.
|
||||
"""
|
||||
|
||||
import bpy
|
||||
|
||||
def generate_texture_image(props, width, height):
|
||||
"""
|
||||
Generate the actual texture image with overlays.
|
||||
|
||||
Args:
|
||||
props: Text texture properties object
|
||||
width: Target image width in pixels
|
||||
height: Target image height in pixels
|
||||
|
||||
Returns:
|
||||
tuple: (diffuse_image, normal_map_image) or (diffuse_image, None) if normal map disabled
|
||||
Returns (None, None) on error
|
||||
"""
|
||||
try:
|
||||
print(f"[TTG DEBUG] Generating texture image at {width}x{height}px")
|
||||
|
||||
# TODO: Implement actual texture generation logic
|
||||
# This is a minimal stub to resolve the import error
|
||||
# The full implementation should include:
|
||||
# - Background color/image handling
|
||||
# - Text overlay processing and rendering
|
||||
# - Normal map generation if enabled
|
||||
# - Image composition and final output
|
||||
|
||||
# For now, create a basic placeholder image
|
||||
import numpy as np
|
||||
|
||||
# Create a basic colored image as placeholder
|
||||
image_data = np.ones((height, width, 4), dtype=np.float32)
|
||||
image_data[:, :, 0] = props.background_color[0] # R
|
||||
image_data[:, :, 1] = props.background_color[1] # G
|
||||
image_data[:, :, 2] = props.background_color[2] # B
|
||||
image_data[:, :, 3] = 1.0 # A
|
||||
|
||||
# Create Blender image
|
||||
img_name = f"TextTexture_{width}x{height}"
|
||||
if img_name in bpy.data.images:
|
||||
bpy.data.images.remove(bpy.data.images[img_name])
|
||||
|
||||
blender_img = bpy.data.images.new(img_name, width, height, alpha=True)
|
||||
blender_img.pixels[:] = image_data.flatten()
|
||||
blender_img.pack()
|
||||
|
||||
# Generate normal map if enabled
|
||||
normal_map_img = None
|
||||
if props.enable_normal_map:
|
||||
from ..core.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.invert_normal_map
|
||||
)
|
||||
|
||||
print(f"[TTG DEBUG] Texture generation completed successfully")
|
||||
return blender_img, normal_map_img
|
||||
|
||||
except Exception as e:
|
||||
print(f"[TTG ERROR] Failed to generate texture image: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None, None
|
||||
|
||||
def generate_preview(props, preview_width=512, preview_height=512):
|
||||
"""
|
||||
Generate a preview version of the texture at lower resolution.
|
||||
|
||||
Args:
|
||||
props: Text texture properties object
|
||||
preview_width: Preview image width (default: 512)
|
||||
preview_height: Preview image height (default: 512)
|
||||
|
||||
Returns:
|
||||
Blender image object or None on error
|
||||
"""
|
||||
try:
|
||||
print(f"[TTG DEBUG] Generating preview at {preview_width}x{preview_height}px")
|
||||
|
||||
# Generate at preview resolution
|
||||
result = generate_texture_image(props, preview_width, preview_height)
|
||||
if result and result[0]:
|
||||
preview_img = result[0]
|
||||
print(f"[TTG DEBUG] Preview generation completed successfully")
|
||||
return preview_img
|
||||
else:
|
||||
print(f"[TTG ERROR] Preview generation failed")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
print(f"[TTG ERROR] Failed to generate preview: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None
|
||||
Reference in New Issue
Block a user