MeshPalettizer / layers /structure.md
dylanebert's picture
initial commit
346b70f

A newer version of the Gradio SDK is available: 6.1.0

Upgrade

Project Structure

Mesh Palettizer - Web application for 3D model texture simplification

Stack

  • Runtime: Python 3.10+
  • 3D Processing: Trimesh
  • Image Processing: Pillow, NumPy, OpenCV
  • ML/Clustering: Scikit-learn
  • Spatial Indexing: SciPy
  • Web Interface: Gradio

Commands

  • Web interface: uv run python app.py
  • Install: uv sync
  • Lint: uv run ruff check .
  • Format: uv run black src/

Layout

conversion/
β”œβ”€β”€ CLAUDE.md        # Global context (Tier 0)
β”œβ”€β”€ app.py           # Web interface with Gradio
β”œβ”€β”€ README.md        # Public documentation
β”œβ”€β”€ pyproject.toml   # Dependencies
β”œβ”€β”€ context.md       # Project context (Tier 2)
β”œβ”€β”€ src/             # Core tool - reusable texture palettizer
β”‚   β”œβ”€β”€ context.md   # Module context (Tier 2)
β”‚   β”œβ”€β”€ __init__.py  # Main API: convert_meshes()
β”‚   β”œβ”€β”€ preprocessing/  # Texture detail removal
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── simplifier.py # Bilateral filter for artifact removal
β”‚   β”œβ”€β”€ extraction/  # Color extraction from meshes
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ sampler.py    # Face sampling with area weighting
β”‚   β”‚   └── reader.py     # Texture/material color reading
β”‚   β”œβ”€β”€ palette/     # Palette generation and mapping
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ quantizer.py  # K-means clustering in LAB space
β”‚   β”‚   β”œβ”€β”€ mapper.py     # Nearest color mapping via KD-tree
β”‚   β”‚   └── color_space.py # RGB/LAB conversion
β”‚   β”œβ”€β”€ atlas/       # Texture atlas generation
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── builder.py    # Atlas construction with UV mapping
β”‚   └── mesh/        # Mesh transformation
β”‚       β”œβ”€β”€ __init__.py
β”‚       └── uvmapper.py   # UV remapping to atlas
└── layers/
    └── structure.md # This file (Tier 1)

Architecture

GLB processing with K-means color quantization and configurable palette sizes

  • Pattern: Direct transformation pipeline
  • Flow: Load meshes β†’ Simplify textures β†’ Sample colors β†’ Quantize to palette β†’ Create atlas β†’ Apply β†’ Export
  • Palette sizes: Powers of 2 (8Γ—8=64 colors, 16Γ—16=256, 32Γ—32=1024, etc.)
  • State: None - pure transformation
  • Optimization: Random sampling, vectorized operations, LAB color space

Entry Points

app.py - Gradio web interface with configurable detail removal sensitivity src.convert_meshes() - Core API with palette generation and detail control