File size: 2,581 Bytes
346b70f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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