Spaces:
Running
Running
Upload 4 files
Browse filesFiles changed (4)
- README.md+22-5
- app.pyAdded+394
- relief_workshop.pyAdded+357
- requirements.txtAdded+5
123456789101112---title: Pattern Groundemoji: 🐢colorFrom: graycolorTo: indigosdk: gradiosdk_version: 6.12.0app_file: app.pypinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference1234567891011121314151617181920212223242526272829---title: Pattern Ground — Relief Generatoremoji: 🏗️colorFrom: graycolorTo: yellowsdk: gradiosdk_version: "4.44.0"app_file: app.pypinned: false---# Pattern Ground — Fabrication TopologiesConverti un'immagine in una tile di rilievo 3D stampabile.Parte del progetto **Fabrication Topologies** — Vectorealism × Dropcity, Design Week Milano 2026.## Come funziona1. Carica un'immagine (foto di pavimentazione, mappa, pattern geometrico, texture…)2. Regola i parametri di dimensione e rilievo3. Controlla la depth map (bianco = alto, nero = basso)4. Scarica l'STL e slicalo## Parametri chiave- **Quantize** — divide il rilievo in N livelli netti (effetto "stair", ottimo per pattern urbani)- **Tileable** — sfuma i bordi così le tile si affiancano senza giunti- **Invert** — inverte alto/basso (utile se il motivo è scuro su sfondo chiaro)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394"""app.py — Fabrication Topologies: Pattern Ground Relief GeneratorGradio web app per HuggingFace Spaces
Deploy: 1. Crea un nuovo Space su huggingface.co/new-space 2. Scegli SDK: Gradio | Hardware: CPU Basic (gratuito) 3. Carica questi 3 file: app.py, relief_workshop.py, requirements.txt 4. Il deploy parte automaticamente in ~2 minuti"""
import ioimport structimport tempfilefrom pathlib import Path
import cv2import gradio as grimport numpy as npfrom PIL import Image
# Importa le funzioni di processing da relief_workshop.pyfrom relief_workshop import build_heightmap, heightmap_to_stl
# ─────────────────────────────────────────────# CORE FUNCTION# ─────────────────────────────────────────────
def generate_relief( image, tile_w: float, tile_h_mode: str, tile_h_custom: float, relief_mm: float, base_mm: float, invert: bool, quantize_levels: int, tileable: bool, blur: float, resolution: int,): if image is None: return None, None, "⚠️ Carica un'immagine per iniziare."
try: # Salva immagine in temp with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as f: tmp_in = f.name Image.fromarray(image).save(tmp_in)
# Calcola altezza tile img_h, img_w = image.shape[:2] if tile_h_mode == "Stessa larghezza (100×100)": tile_h = tile_w elif tile_h_mode == "Proporzioni originali": tile_h = tile_w * img_h / img_w else: tile_h = tile_h_custom
# Build heightmap quantize = quantize_levels if quantize_levels >= 2 else 0 height_map, px_w, px_h = build_heightmap( tmp_in, max_px=resolution, invert=invert, blur=blur, gamma=1.1, quantize=quantize, tileable=tileable, fade_px=12, )
# Preview depth map preview = (height_map * 255).astype(np.uint8) preview_rgb = np.stack([preview, preview, preview], axis=-1)
# Generate STL stl_bytes = heightmap_to_stl( height_map, px_w, px_h, tile_w_mm=tile_w, tile_h_mm=tile_h, relief_mm=relief_mm, base_mm=base_mm, )
# Save STL to temp file with tempfile.NamedTemporaryFile(suffix=".stl", delete=False) as f: stl_path = f.name f.write(stl_bytes)
size_kb = len(stl_bytes) / 1024 n_tri = (len(stl_bytes) - 84) // 50
info = f"""✓ Tile generata
Dimensioni: {tile_w:.0f} × {tile_h:.0f} mmAltezza: base {base_mm:.1f} mm + rilievo {relief_mm:.1f} mm = {base_mm + relief_mm:.1f} mm totaleMesh: {px_w} × {px_h} px — {n_tri:,} triangoliFile STL: {size_kb:.0f} KB
Impostazioni slicer: layer 0.15 mm · infill 15% · no supports"""
Path(tmp_in).unlink(missing_ok=True) return preview_rgb, stl_path, info
except Exception as e: return None, None, f"❌ Errore: {str(e)}"
def preview_only( image, tile_w, tile_h_mode, tile_h_custom, relief_mm, base_mm, invert, quantize_levels, tileable, blur, resolution,): """Genera solo la depth map preview, più veloce.""" if image is None: return None, "⚠️ Carica un'immagine per iniziare."
try: with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as f: tmp_in = f.name Image.fromarray(image).save(tmp_in)
quantize = quantize_levels if quantize_levels >= 2 else 0 height_map, px_w, px_h = build_heightmap( tmp_in, max_px=min(resolution, 300), # preview più veloce invert=invert, blur=blur, gamma=1.1, quantize=quantize, tileable=tileable, fade_px=12, )
preview = (height_map * 255).astype(np.uint8) preview_rgb = np.stack([preview, preview, preview], axis=-1)
Path(tmp_in).unlink(missing_ok=True)
msg = f"Depth map: {px_w}×{px_h}px · Bianco = alto · Nero = basso" if invert: msg += " (invertita)" return preview_rgb, msg
except Exception as e: return None, f"❌ Errore: {str(e)}"
# ─────────────────────────────────────────────# UI# ─────────────────────────────────────────────
CSS = """@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Instrument+Serif:ital@0;1&display=swap');
:root { --black: #0a0a0a; --white: #f2efe8; --yellow: #d4a912; --grey: #333; --mid: #888;}
body, .gradio-container { background: var(--black) !important; color: var(--white) !important; font-family: 'DM Mono', monospace !important;}
.gr-block, .gr-box, .gr-panel { background: #111 !important; border: 1px solid #222 !important; border-radius: 0 !important;}
.gr-button { border-radius: 0 !important; font-family: 'DM Mono', monospace !important; letter-spacing: 0.05em !important; text-transform: uppercase !important; font-size: 0.75rem !important;}
.gr-button.primary { background: var(--yellow) !important; color: var(--black) !important; border: none !important;}
.gr-button.secondary { background: transparent !important; color: var(--mid) !important; border: 1px solid #333 !important;}
.gr-button:hover { opacity: 0.85 !important;}
label, .gr-label { font-family: 'DM Mono', monospace !important; font-size: 0.7rem !important; letter-spacing: 0.08em !important; color: var(--mid) !important; text-transform: uppercase !important;}
.gr-textbox textarea, .gr-textbox input { background: #0d0d0d !important; border: 1px solid #222 !important; color: var(--white) !important; font-family: 'DM Mono', monospace !important; border-radius: 0 !important;}
h1 { font-family: 'Instrument Serif', serif !important; font-size: 2.2rem !important; color: var(--white) !important; font-weight: 400 !important; letter-spacing: -0.02em !important; line-height: 1.1 !important;}
h3 { font-family: 'DM Mono', monospace !important; font-size: 0.65rem !important; letter-spacing: 0.15em !important; color: var(--yellow) !important; text-transform: uppercase !important; margin-bottom: 0.5rem !important; border-bottom: 1px solid #222 !important; padding-bottom: 0.4rem !important;}
.info-box { background: #111; border: 1px solid #222; padding: 1rem; font-size: 0.75rem; line-height: 1.7; color: var(--mid); white-space: pre-line;}
.accent { color: var(--yellow); }
/* Slider */.gr-slider input[type=range] { accent-color: var(--yellow) !important;}
/* Checkbox */input[type=checkbox] { accent-color: var(--yellow) !important;}"""
HEADER = """# Pattern Ground### Fabrication Topologies — Vectorealism × Dropcity
Converti un'immagine in una tile di rilievo 3D pronta per la stampa. Regola i parametri, controlla la depth map, scarica l'STL."""
INSTRUCTIONS = """### Come funziona
**Depth map preview** — bianco = alto, nero = basso. Controlla prima di generare l'STL.
**Quantize** — crea gradini netti invece di un rilievo continuo. 4–6 livelli funziona bene per pattern urbani (sanpietrini, griglia, muratura).
**Tileable** — sfuma i bordi della tile così le piastrelle si affiancano senza giunti visibili nella griglia condivisa.
**Invert** — inverte l'altezza: utile se il pattern ha sfondo bianco e motivo scuro.
**Impostazioni slicer consigliate:** layer height 0.15 mm · infill 15% · no supports · ironing on top surface"""
def build_ui(): with gr.Blocks(css=CSS, title="Pattern Ground — Fabrication Topologies") as demo:
gr.Markdown(HEADER)
with gr.Row():
# ── Colonna sinistra: input + parametri ── with gr.Column(scale=1):
gr.Markdown("### Immagine") image_input = gr.Image( label="Carica immagine (PNG, JPG)", type="numpy", image_mode="RGB", )
gr.Markdown("### Dimensioni tile") with gr.Row(): tile_w = gr.Slider( 20, 200, value=100, step=5, label="Larghezza (mm)" ) tile_h_mode = gr.Radio( ["Stessa larghezza (100×100)", "Proporzioni originali", "Personalizzata"], value="Stessa larghezza (100×100)", label="Altezza tile" ) tile_h_custom = gr.Slider( 20, 200, value=100, step=5, label="Altezza personalizzata (mm)", visible=False )
gr.Markdown("### Rilievo") with gr.Row(): relief_mm = gr.Slider(1, 10, value=4, step=0.5, label="Altezza rilievo (mm)") base_mm = gr.Slider(1, 5, value=2, step=0.5, label="Spessore base (mm)")
gr.Markdown("### Processing") quantize_levels = gr.Slider( 0, 12, value=0, step=1, label="Quantize — livelli di altezza (0 = continuo, 4–6 = gradini)" ) blur = gr.Slider( 0, 3, value=0.5, step=0.1, label="Smoothing (0 = nessuno)" ) resolution = gr.Slider( 100, 400, value=200, step=50, label="Risoluzione mesh (px per lato)" )
gr.Markdown("### Opzioni") with gr.Row(): invert = gr.Checkbox(label="Invert depth (scuro=alto)", value=False) tileable = gr.Checkbox(label="Tileable (bordi sfumati)", value=False)
with gr.Row(): preview_btn = gr.Button("Depth map preview", variant="secondary") generate_btn = gr.Button("Genera STL", variant="primary")
# ── Colonna destra: output ── with gr.Column(scale=1): gr.Markdown("### Depth map") depth_preview = gr.Image( label="Depth map — bianco = alto, nero = basso", type="numpy", interactive=False, )
gr.Markdown("### Download") stl_output = gr.File(label="File STL")
gr.Markdown("### Info") info_output = gr.Textbox( label="", lines=8, interactive=False, )
gr.Markdown(INSTRUCTIONS)
# ── Logica UI ── def toggle_custom_height(mode): return gr.update(visible=(mode == "Personalizzata"))
tile_h_mode.change(toggle_custom_height, tile_h_mode, tile_h_custom)
# Inputs condivisi inputs = [ image_input, tile_w, tile_h_mode, tile_h_custom, relief_mm, base_mm, invert, quantize_levels, tileable, blur, resolution ]
preview_btn.click( preview_only, inputs=inputs, outputs=[depth_preview, info_output], )
generate_btn.click( generate_relief, inputs=inputs, outputs=[depth_preview, stl_output, info_output], )
return demo
if __name__ == "__main__": app = build_ui() app.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357"""relief_workshop.pyImage → 3D relief tile — versione workshop Fabrication Topologies
Uso: python relief_workshop.py input.png [opzioni]
Esempi: python relief_workshop.py pattern.png python relief_workshop.py pattern.png --width 100 --height 100 --relief 4 --base 2 python relief_workshop.py pattern.png --width 100 --height 100 --invert --tileable python relief_workshop.py pattern.png --width 100 --height 100 --relief 6 --quantize 4
Dipendenze: pip install numpy pillow scipy opencv-python-headless"""
import argparseimport structimport sysfrom pathlib import Path
import cv2import numpy as npfrom PIL import Image
# ─────────────────────────────────────────────# PROCESSING# ─────────────────────────────────────────────
def load_and_prepare(image_path: str, max_px: int) -> np.ndarray: """Carica l'immagine, converte in grigio, ridimensiona.""" img = Image.open(image_path).convert("RGB") ratio = min(max_px / img.width, max_px / img.height) new_w = max(2, int(img.width * ratio)) new_h = max(2, int(img.height * ratio)) img = img.resize((new_w, new_h), Image.LANCZOS) gray = np.array(img.convert("L"), dtype=np.float32) return gray
def smooth_heightmap(gray: np.ndarray, blur: float) -> np.ndarray: """Bilateral filter + smoothing leggero.""" if blur <= 0: return gray sigma_color = min(60, blur * 15) sigma_space = min(10, blur * 3) result = cv2.bilateralFilter( gray.astype(np.uint8), d=9, sigmaColor=sigma_color, sigmaSpace=sigma_space ).astype(np.float32) return result
def quantize_heightmap(gray: np.ndarray, levels: int) -> np.ndarray: """Quantizza i livelli di altezza: crea un effetto a gradini netti.""" if levels < 2: return gray # Divide in N livelli e rimappa normalized = gray / 255.0 quantized = np.floor(normalized * levels) / levels return (quantized * 255.0).astype(np.float32)
def make_tileable(gray: np.ndarray, fade_px: int) -> np.ndarray: """ Sfuma i bordi verso la media dell'immagine per permettere l'affiancamento senza scalini visibili ai giunti. """ if fade_px <= 0: return gray h, w = gray.shape mean_val = float(np.mean(gray)) result = gray.copy()
fade = min(fade_px, w // 4, h // 4) for i in range(fade): alpha = i / fade # 0 al bordo → 1 all'interno result[i, :] = alpha * gray[i, :] + (1 - alpha) * mean_val result[h - 1 - i, :] = alpha * gray[h - 1 - i, :] + (1 - alpha) * mean_val result[:, i] = alpha * result[:, i] + (1 - alpha) * mean_val result[:, w - 1 - i] = alpha * result[:, w - 1 - i] + (1 - alpha) * mean_val
return result
def build_heightmap( image_path: str, max_px: int = 500, invert: bool = False, blur: float = 0.5, gamma: float = 1.1, quantize: int = 0, tileable: bool = False, fade_px: int = 8,) -> tuple[np.ndarray, int, int]: """Pipeline completa da immagine a heightmap normalizzata [0,1].""" gray = load_and_prepare(image_path, max_px) h, w = gray.shape
gray = smooth_heightmap(gray, blur)
# Gamma correction gray = np.power(gray / 255.0, gamma) * 255.0
if quantize >= 2: gray = quantize_heightmap(gray, quantize)
if tileable: gray = make_tileable(gray, fade_px)
if invert: gray = 255.0 - gray
gray = np.clip(gray, 0, 255)
# Normalizza [0, 1] height_map = gray / 255.0 return height_map, w, h
# ─────────────────────────────────────────────# STL GENERATION# ─────────────────────────────────────────────
def _pack_triangle(normal, v1, v2, v3) -> bytes: return struct.pack( "<ffffffffffffH", *normal, *v1, *v2, *v3, 0 )
def heightmap_to_stl( height_map: np.ndarray, px_w: int, px_h: int, tile_w_mm: float, tile_h_mm: float, relief_mm: float, base_mm: float,) -> bytes: """ Genera un file STL binario da una heightmap normalizzata [0,1].
La superficie superiore è il rilievo. La base è piatta a z=0 (superficie inferiore a z=-base_mm internamente, ma tutto shiftato così il bottom è a z=0 e il rilievo è in positivo). """ pixel_x = tile_w_mm / (px_w - 1) pixel_y = tile_h_mm / (px_h - 1)
# z assoluto di ogni pixel della superficie # base a z=0, rilievo sale fino a relief_mm def z(row, col): return base_mm + height_map[row, col] * relief_mm
triangles = []
# ── Superficie superiore (rilievo) ── for row in range(px_h - 1): for col in range(px_w - 1): x0, x1 = col * pixel_x, (col + 1) * pixel_x y0, y1 = (px_h - 1 - row) * pixel_y, (px_h - 2 - row) * pixel_y
z00 = z(row, col) z10 = z(row, col + 1) z01 = z(row + 1, col) z11 = z(row + 1, col + 1)
v00 = (x0, y0, z00) v10 = (x1, y0, z10) v01 = (x0, y1, z01) v11 = (x1, y1, z11)
# Triangolo 1 e1 = np.subtract(v10, v00) e2 = np.subtract(v01, v00) n = np.cross(e1, e2) nn = n / (np.linalg.norm(n) + 1e-12) triangles.append(_pack_triangle(nn, v00, v10, v01))
# Triangolo 2 e1 = np.subtract(v01, v11) e2 = np.subtract(v10, v11) n = np.cross(e1, e2) nn = n / (np.linalg.norm(n) + 1e-12) triangles.append(_pack_triangle(nn, v11, v01, v10))
# ── Base inferiore (piatta a z=0) ── for row in range(px_h - 1): for col in range(px_w - 1): x0, x1 = col * pixel_x, (col + 1) * pixel_x y0, y1 = (px_h - 1 - row) * pixel_y, (px_h - 2 - row) * pixel_y n = (0.0, 0.0, -1.0) triangles.append(_pack_triangle(n, (x0, y0, 0), (x0, y1, 0), (x1, y0, 0))) triangles.append(_pack_triangle(n, (x1, y1, 0), (x1, y0, 0), (x0, y1, 0)))
W = tile_w_mm H = tile_h_mm
# ── Pareti laterali ── # Fronte (y=0) for col in range(px_w - 1): x0, x1 = col * pixel_x, (col + 1) * pixel_x z0_top = z(px_h - 1, col) z1_top = z(px_h - 1, col + 1) n = (0.0, -1.0, 0.0) triangles.append(_pack_triangle(n, (x0, 0, 0), (x1, 0, z1_top), (x0, 0, z0_top))) triangles.append(_pack_triangle(n, (x0, 0, 0), (x1, 0, 0), (x1, 0, z1_top)))
# Retro (y=H) for col in range(px_w - 1): x0, x1 = col * pixel_x, (col + 1) * pixel_x z0_top = z(0, col) z1_top = z(0, col + 1) n = (0.0, 1.0, 0.0) triangles.append(_pack_triangle(n, (x0, H, z0_top), (x1, H, z1_top), (x0, H, 0))) triangles.append(_pack_triangle(n, (x1, H, z1_top), (x1, H, 0), (x0, H, 0)))
# Sinistra (x=0) for row in range(px_h - 1): y0 = (px_h - 1 - row) * pixel_y y1 = (px_h - 2 - row) * pixel_y z0_top = z(row, 0) z1_top = z(row + 1, 0) n = (-1.0, 0.0, 0.0) triangles.append(_pack_triangle(n, (0, y0, z0_top), (0, y1, z1_top), (0, y0, 0))) triangles.append(_pack_triangle(n, (0, y1, 0), (0, y0, 0), (0, y1, z1_top)))
# Destra (x=W) for row in range(px_h - 1): y0 = (px_h - 1 - row) * pixel_y y1 = (px_h - 2 - row) * pixel_y z0_top = z(row, px_w - 1) z1_top = z(row + 1, px_w - 1) n = (1.0, 0.0, 0.0) triangles.append(_pack_triangle(n, (W, y0, 0), (W, y1, z1_top), (W, y0, z0_top))) triangles.append(_pack_triangle(n, (W, y0, 0), (W, y1, 0), (W, y1, z1_top)))
header = b"\x00" * 80 count = struct.pack("<I", len(triangles)) return header + count + b"".join(triangles)
def save_depth_preview(height_map: np.ndarray, out_path: str): """Salva la depth map come PNG per verifica visiva.""" preview = (height_map * 255).astype(np.uint8) Image.fromarray(preview).save(out_path)
# ─────────────────────────────────────────────# CLI# ─────────────────────────────────────────────
def main(): parser = argparse.ArgumentParser( description="Image → 3D relief tile STL — Fabrication Topologies workshop", formatter_class=argparse.RawDescriptionHelpFormatter, epilog="""Parametri chiave: --width / --height dimensioni della tile in mm (default 100×100) --relief altezza massima del rilievo in mm (default 4) --base spessore della base piatta in mm (default 2) --invert inverte: scuro=alto invece di bianco=alto --quantize N quantizza in N livelli di altezza (effetto a gradini) es: --quantize 4 → 4 livelli netti, bello per pattern urbani --tileable sfuma i bordi per affiancamento senza giunti visibili --blur forza del smoothing (default 0.5, 0=nessuno, 2=molto) --resolution max pixel per lato (default 500, più alto = più dettaglio ma più lento) --preview salva anche la depth map come PNG per verifica """, )
parser.add_argument("input", help="Immagine di input (PNG, JPG, ...)") parser.add_argument("--output", "-o", help="File STL di output (default: input_relief.stl)") parser.add_argument("--width", type=float, default=100.0, help="Larghezza tile in mm (default 100)") parser.add_argument("--height", type=float, default=100.0, help="Altezza tile in mm (default 100, 0=proporzioni originali)") parser.add_argument("--relief", type=float, default=4.0, help="Spessore massimo rilievo in mm (default 4)") parser.add_argument("--base", type=float, default=2.0, help="Spessore base piatta in mm (default 2)") parser.add_argument("--invert", action="store_true", help="Inverte: scuro=alto, bianco=basso") parser.add_argument("--quantize", type=int, default=0, metavar="N", help="Quantizza in N livelli (0=continuo)") parser.add_argument("--tileable", action="store_true", help="Sfuma i bordi per affiancamento") parser.add_argument("--fade", type=int, default=12, help="Pixel di fade per --tileable (default 12)") parser.add_argument("--blur", type=float, default=0.5, help="Smoothing (0=nessuno, 0.5=default, 2=molto)") parser.add_argument("--gamma", type=float, default=1.1, help="Correzione contrasto (default 1.1)") parser.add_argument("--resolution", type=int, default=500, help="Max pixel per lato (default 500)") parser.add_argument("--preview", action="store_true", help="Salva depth map PNG per verifica")
args = parser.parse_args()
# Output path input_path = Path(args.input) if not input_path.exists(): print(f"Errore: file non trovato: {args.input}") sys.exit(1)
output_path = Path(args.output) if args.output else input_path.with_name(input_path.stem + "_relief.stl")
print(f"Input: {input_path}") print(f"Output: {output_path}") print(f"Tile: {args.width:.1f} × {args.height:.1f} mm") print(f"Rilievo: {args.relief:.1f} mm | Base: {args.base:.1f} mm") print(f"Totale Z: {args.relief + args.base:.1f} mm") print(f"Opzioni: invert={args.invert} quantize={args.quantize} tileable={args.tileable}") print()
# Build heightmap print("Elaborazione immagine...") height_map, px_w, px_h = build_heightmap( str(input_path), max_px=args.resolution, invert=args.invert, blur=args.blur, gamma=args.gamma, quantize=args.quantize, tileable=args.tileable, fade_px=args.fade, ) print(f"Risoluzione mesh: {px_w} × {px_h} px ({px_w * px_h:,} vertici)")
if args.preview: preview_path = input_path.with_name(input_path.stem + "_depthmap.png") save_depth_preview(height_map, str(preview_path)) print(f"Depth map salvata: {preview_path}")
# Calcola altezza tile se proporzioni originali tile_h = args.height if args.height > 0 else args.width * px_h / px_w
# Generate STL print("Generazione STL...") stl_bytes = heightmap_to_stl( height_map, px_w, px_h, tile_w_mm=args.width, tile_h_mm=tile_h, relief_mm=args.relief, base_mm=args.base, )
with open(output_path, "wb") as f: f.write(stl_bytes)
size_kb = len(stl_bytes) / 1024 print(f"\n✓ STL salvato: {output_path} ({size_kb:.0f} KB)") print(f" Triangoli: {(len(stl_bytes) - 84) // 50:,}")
if size_kb > 30_000: print(" Avviso: file grande, considera --resolution 300 per ridurre le dimensioni")
print() print("Impostazioni slicer consigliate:") print(" Layer height: 0.15 mm | Infill: 15% | No supports")
if __name__ == "__main__": main()12345gradio>=4.0numpypillowopencv-python-headlessscipyREADME.md+22-5
app.pyAdded+394
relief_workshop.pyAdded+357
requirements.txtAdded+5