123 lines
5.3 KiB
Python
123 lines
5.3 KiB
Python
"""
|
|
blender/generate_hmi_texture.py
|
|
|
|
Generates a high-resolution, photorealistic dark-mode industrial HMI (Human-Machine Interface)
|
|
touchscreen dashboard graphic to map onto the physical 3D operator monitor in Blender.
|
|
"""
|
|
|
|
import os
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
def create_hmi_dashboard(out_path="assets/textures/hmi_kpi_dashboard.png", width=1280, height=800):
|
|
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
|
img = Image.new("RGBA", (width, height), (15, 23, 42, 255)) # Slate 900
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
# Helper colors
|
|
C_HEADER = (30, 41, 59, 255) # Slate 800
|
|
C_CARD = (24, 34, 53, 255) # Card dark
|
|
C_BORDER = (51, 65, 85, 255) # Slate 700
|
|
C_CYAN = (14, 165, 233, 255) # Sky 500
|
|
C_GREEN = (34, 197, 94, 255) # Green 500
|
|
C_RED = (239, 68, 68, 255) # Red 500
|
|
C_AMBER = (245, 158, 11, 255) # Amber 500
|
|
C_PURPLE = (168, 85, 247, 255) # Purple 500
|
|
C_TEXT = (255, 255, 255, 255) # White
|
|
C_MUTED = (148, 163, 184, 255) # Slate 400
|
|
|
|
# Fonts (fall back to default if TTF unavailable)
|
|
try:
|
|
font_large = ImageFont.truetype("arial.ttf", 36)
|
|
font_med = ImageFont.truetype("arial.ttf", 24)
|
|
font_small = ImageFont.truetype("arial.ttf", 18)
|
|
font_tiny = ImageFont.truetype("arial.ttf", 14)
|
|
except Exception:
|
|
font_large = font_med = font_small = font_tiny = ImageFont.load_default()
|
|
|
|
# 1. Top Header Bar
|
|
draw.rectangle([0, 0, width, 70], fill=C_HEADER)
|
|
draw.text((30, 18), "AOI INSPECTION CELL 04 | LINE KPI DASHBOARD & TELEMETRY", fill=C_TEXT, font=font_med)
|
|
draw.text((width - 340, 24), "● LINE: ONLINE | SPEED: 60 PPM", fill=C_GREEN, font=font_small)
|
|
|
|
# 2. Four KPI Metric Cards Across Top
|
|
cards = [
|
|
("TOTAL INSPECTED", "1,000", "100% Volume", C_CYAN),
|
|
("PASSED (GOOD)", "200", "20.0% Clean Yield", C_GREEN),
|
|
("REJECTED (DEFECTS)", "800", "80.0% Diverted", C_RED),
|
|
("FIRST PASS YIELD", "96.4%", "Production Target", C_AMBER)
|
|
]
|
|
card_w = (width - 60 - 45) // 4
|
|
top_y = 90
|
|
card_h = 130
|
|
|
|
for i, (label, val, sub, col) in enumerate(cards):
|
|
cx = 30 + i * (card_w + 15)
|
|
draw.rounded_rectangle([cx, top_y, cx + card_w, top_y + card_h], radius=10, fill=C_CARD, outline=col, width=2)
|
|
draw.text((cx + 18, top_y + 16), label, fill=C_MUTED, font=font_tiny)
|
|
draw.text((cx + 18, top_y + 44), val, fill=col, font=font_large)
|
|
draw.text((cx + 18, top_y + 96), sub, fill=C_MUTED, font=font_tiny)
|
|
|
|
# 3. Main Center Split Section
|
|
# Left: Defect Breakdown Progress Bars
|
|
left_x = 30
|
|
left_w = 640
|
|
mid_y = 245
|
|
mid_h = 440
|
|
draw.rounded_rectangle([left_x, mid_y, left_x + left_w, mid_y + mid_h], radius=10, fill=C_CARD, outline=C_BORDER, width=2)
|
|
draw.text((left_x + 24, mid_y + 20), "DEFECT CLASSIFICATION DISTRIBUTION (1,000 SCENES)", fill=C_TEXT, font=font_small)
|
|
|
|
defect_bars = [
|
|
("Pristine / Good Bracket", 200, 20.0, C_GREEN),
|
|
("Class 0: Scratch (Tool Score)", 200, 20.0, C_CYAN),
|
|
("Class 1: Dent (Impact Crater)", 200, 20.0, C_RED),
|
|
("Class 2: Missing Fastener", 200, 20.0, C_AMBER),
|
|
("Class 3: Misplaced / Tilted Fastener", 200, 20.0, C_PURPLE)
|
|
]
|
|
|
|
bar_y = mid_y + 70
|
|
for name, cnt, pct, bar_col in defect_bars:
|
|
draw.text((left_x + 24, bar_y), f"{name}: {cnt} ({pct:.1f}%)", fill=C_TEXT, font=font_tiny)
|
|
# Bar track
|
|
draw.rounded_rectangle([left_x + 24, bar_y + 24, left_x + left_w - 24, bar_y + 40], radius=6, fill=C_HEADER)
|
|
# Bar fill (pct mapped to width)
|
|
fill_w = int((left_w - 48) * (pct / 100.0))
|
|
draw.rounded_rectangle([left_x + 24, bar_y + 24, left_x + 24 + fill_w, bar_y + 40], radius=6, fill=bar_col)
|
|
bar_y += 68
|
|
|
|
# Right: Live Part Inspection & Actuator Telemetry
|
|
right_x = left_x + left_w + 20
|
|
right_w = width - right_x - 30
|
|
draw.rounded_rectangle([right_x, mid_y, right_x + right_w, mid_y + mid_h], radius=10, fill=C_CARD, outline=C_BORDER, width=2)
|
|
draw.text((right_x + 24, mid_y + 20), "LIVE CAMERA INSPECTION TELEMETRY", fill=C_TEXT, font=font_small)
|
|
|
|
telemetry_items = [
|
|
("INSPECTION STATUS", "DEFECT DETECTED", C_RED),
|
|
("TARGET DEFECT CLASS", "CLASS 1: DENT", C_RED),
|
|
("MODEL CONFIDENCE", "98.4%", C_GREEN),
|
|
("INFERENCE LATENCY", "12.8 ms (78.1 FPS)", C_CYAN),
|
|
("CAM 1 (TOP-DOWN)", "TRIGGERED | 50mm f/5.6", C_TEXT),
|
|
("CAM 2 (45° OBLIQUE)", "TRIGGERED | 35mm f/4.0", C_TEXT),
|
|
("PNEUMATIC DIVERTER", "ARMED -> REJECT TO CHUTE", C_AMBER),
|
|
("REJECT BIN CAPACITY", "58 / 200 Units (Normal)", C_MUTED)
|
|
]
|
|
|
|
ty = mid_y + 65
|
|
for k, v, c in telemetry_items:
|
|
draw.text((right_x + 24, ty), k, fill=C_MUTED, font=font_tiny)
|
|
draw.text((right_x + 240, ty), v, fill=c, font=font_tiny)
|
|
ty += 44
|
|
|
|
# 4. Bottom Footer Status Bar
|
|
draw.rectangle([0, height - 60, width, height], fill=C_HEADER)
|
|
draw.text((30, height - 42), "SYSTEM: SYNTHETIC DEFECT FACTORY DIGITAL TWIN v2.4", fill=C_MUTED, font=font_tiny)
|
|
draw.text((width - 420, height - 42), "OPTI-RAYTRACING: ACTIVE | AUTONOMOUS AOI", fill=C_CYAN, font=font_tiny)
|
|
|
|
img.save(out_path)
|
|
print(f"HMI KPI Dashboard texture saved to: {out_path} ({width}x{height})")
|
|
return out_path
|
|
|
|
|
|
if __name__ == "__main__":
|
|
create_hmi_dashboard()
|