| --- |
| pretty_name: Sking |
| language: |
| - en |
| license: agpl-3.0 |
| task_categories: |
| - text-to-image |
| - image-to-image |
| tags: |
| - minecraft |
| - 3d |
| - voxel |
| - minecraft-skin |
| - texture |
| - dataset-generation |
| --- |
| |
| # Sking: Minecraft Skin 3D Rendering & Dataset Preprocessing Pipeline |
|
|
|
|
| This repository is utilized for training and fine-tuning the **Sking Model** ([Hugging Face Model](https://huggingface.co/EntropyDrop/Sking)). |
|
|
| Along with the dataset assets, it contains the complete automated pipeline for dual-layer 3D voxel rendering, multi-view layout baking, automatic skin format conversion (Alex to Steve), voxel edge texture consistency resolution, and a RESTful FastAPI service for extracting the actual usable 64x64 RGBA skin UV map from composite training targets. |
|
|
| --- |
|
|
| ## 🔗 Resources |
|
|
| * **🗂️ Dataset**: [Hugging Face Sking Dataset](https://huggingface.co/datasets/EntropyDrop/Sking) |
| * **🧠 Trained Model**: [Hugging Face Sking Model](https://huggingface.co/EntropyDrop/Sking) |
| * **📝 Technical Report**: [Technical Architecture](https://entropydrop.com/skin/public/article/skingen) |
| * **🌐 Online Demo**: [EntropyDrop Web Portal](https://entropydrop.com) |
|
|
| --- |
|
|
| ## 🚀 Key Features |
|
|
| * **🎮 3D Voxel Rendering (`mc_render.py`)** |
| - Powered by `PyVista` (VTK) to translate 2D skin textures into 3D voxel character meshes. |
| - Supports dual-layer rendering: Core layer (base body) and Decor layer (jacket, sleeves, pants, hat). |
| - Fully parameterizable limb articulation supporting rotation (Pitch/Yaw/Roll) and spatial offset configurations. |
| - Interactive lighting mode with real-time viewport keyboard controls (W/S/A/D/Q/E for light position, R/F for intensity). |
| - Supports orthographic and perspective projections, wireframe overlays, custom backgrounds, and alpha-transparent exports. |
| |
| * **🧩 Voxel Texture Consistency Resolver (`mc_voxel_texture_resolver.py`)** |
| - Solves the visual gap artifact caused by transparent adjacent faces in dual-layer skins during 3D voxelization. |
| - Implements a 3D voxel projection mapping algorithm that automatically fills missing/transparent adjacent faces according to a priority sequence (`Front -> Back -> Top -> Bottom -> Left -> Right`) for 3D renders. |
|
|
| * **🔄 Layout Standardization: Alex-to-Steve (`alice_to_steve.py`)** |
| - Automatically detects slim-armed (Alex, 3px arm width) skin formats. |
| - Applies a pixel-column projection and replication mapping to expand slim arms to standard (Steve, 4px arm width) format to standardize features across the dataset. |
|
|
| * **📸 Multi-View Layout Baking (`build_target_img.py`)** |
| - Upsamples 64x64 flat textures via box filtering and injects 2x2 white indicators on background regions to represent alpha transparency values as conditioning cues for generative models. |
| - Bakes a composite layout image at `768x768` resolution featuring the 2D skin texture along with **17 distinct, pre-configured 3D render viewports** (incorporating walking, idle, back-view, close-ups, and layer-toggled angles). |
|
|
| * **⚡ Batch Processing Pipeline (`build_target_imgs.py`)** |
| - Leverages a multi-threaded execution pool (`ThreadPoolExecutor`) managing isolated sub-processes for batch rendering. |
| - Supports parallel processing on multi-core systems. |
|
|
| * **🔓 Skin UV Map Extraction (`extract_skin.py`)** |
| - **Extraction Engine**: Crops and extracts the actual usable 64x64 skin UV map from the 2D layout area of synthesized training target images, resolving alpha transparency indicators to recover clean texture maps. |
| - **FastAPI Microservice**: Exposes the UV map extractor as a REST API alongside its command-line execution mode. |
| |
| * **📐 Conditioning Image Formatting (`force_resize_control_imgs.py`)** |
| - Automatically resamples and centers control images inside a standard `1024x1024` alpha-transparent canvas utilizing Lanczos interpolation, ensuring compatibility with advanced ControlNet training frameworks. |
|
|
| * **🔄 Skin UV & View Port Horizontal Flipping (`ext_flip_img.py`)** |
| - Performs horizontal flipping of character front/back views in control images and correctly flips the corresponding 64x64 skin UV map. |
| - Specifically handles 3D voxel box flipping (swapping left and right faces, horizontally flipping each face, and swapping left/right limbs/sleeves/pants/legs for Steve and Alex models). |
|
|
| * **✂️ Front-View Dataset Slicing (`make_half_dataset.py`)** |
| - Generates a front-view-only subset by horizontally splitting composite layout/control images in half, retaining only the left (front) side. |
| - Automatically copies and standardizes associated files (PNG images, txt descriptions, and control maps) prefixing them with `half_`. |
|
|
| * **🧬 Skin Merging Utility (`merge_skins.py`)** |
| - Combines two skins by extracting the head and head decoration (decor) layers from Skin A and copying them onto the body and limbs of Skin B. |
| - Utilizes head mapping coordinates matching standard UV layouts. |
| |
| --- |
| |
| ## 📂 Project Structure |
| |
| ```bash |
| Sking/ |
| ├── mc_render.py # Core 3D engine (PyVista viewport & headless off-screen rendering) |
| ├── mc_voxel_texture_resolver.py # Voxel texture patcher & visual difference analyzer |
| ├── alice_to_steve.py # Alex-to-Steve (3px-to-4px arm width) mapping algorithm |
| ├── build_target_img.py # Single-skin multi-view layout baker (generates 768x768 composite) |
| ├── build_target_imgs.py # Concurrent batch rendering pipeline |
| ├── extract_skin.py # Skin UV map extraction CLI & FastAPI server |
| ├── force_resize_control_imgs.py # Control map resampling & canvas standardization (1024x1024) |
| ├── ext_flip_img.py # Flip front/back views and horizontally mirror skin UV layouts |
| ├── make_half_dataset.py # Create front-view subset by slicing images in half horizontally |
| ├── merge_skins.py # Combine head of skin A with body/limbs of skin B |
| ├── skin-mask.png # Pixel-level spatial mapping mask for Core layer |
| ├── skin-decor-mask.png # Pixel-level spatial mapping mask for Decor layer |
| ├── skins/ # Directory for raw input skins (.png) |
| ├── target_imgs_v73/ # Output directory for baked multi-view layouts |
| ├── control_imgs/ # Processing directory for conditioning control maps |
| └── control_imgs_v2/ # Directory for multi-view layout control maps |
| ``` |
| |
| --- |
| |
| ## 🛠️ System Requirements & Installation |
| |
| ### 1. Prerequisites |
| - Python 3.8 or higher. |
| - A virtual environment configuration is highly recommended. |
| |
| ### 2. Installation |
| Install all required packages: |
| ```bash |
| pip install pyvista numpy pillow fastapi uvicorn opencv-python pydantic |
| ``` |
| > **Note for Headless Environments**: Since `PyVista` utilizes VTK under the hood, running it on headless servers (e.g., Linux instances without GUI support) requires a virtual frame buffer configuration. Please wrap the execution using a utility like `xvfb-run`. |
| |
| --- |
| |
| ## 📖 Command Line & API Reference |
| |
| ### A. Bake Multi-View Layout for a Single Skin |
| ```bash |
| python build_target_img.py skins/steve.png target_imgs_v73/steve.png |
| ``` |
| This utility automatically executes the following pipeline sequence: |
| 1. Validates texture dimension (64x64) and format integrity (RGBA). |
| 2. Performs slim-arm check and converts Alex formats to Steve formats dynamically if needed. |
| 3. Patches voxel edge-transparency conflicts. |
| 4. Generates a `768x768` composite layout containing the 2D layout and 17 distinct 3D viewports. |
| |
| ### B. Batch Processing |
| ```bash |
| python build_target_imgs.py |
| ``` |
| Batch scans the `skins/` directory and processes them concurrently using parallel workers, exporting the output files into `target_imgs_v73/`. |
| |
| ### C. Interactive 3D Rendering & Viewing |
| To examine or visually debug the 3D rendering configuration of a specific skin: |
| ```bash |
| python mc_render.py skins/my_skin.png --interact |
| ``` |
| - **Real-Time Light Position & Intensity Keyboard Controls**: |
| - `W` / `S`: Translate light position along the Z-axis (Forward / Backward). |
| - `A` / `D`: Translate light position along the X-axis (Left / Right). |
| - `Q` / `E`: Translate light position along the Y-axis (Up / Down). |
| - `R` / `F`: Increment / Decrement light intensity. |
| - `P`: Print current light coordinate vector and intensity scalar to terminal output. |
| - **Custom Articulation & Off-Screen Export Example**: |
| ```bash |
| python mc_render.py skins/my_skin.png --rot-head 15 30 0 --rot-arm-right -45 0 0 --save output.png |
| ``` |
| |
| ### D. Skin UV Map Extraction API |
| #### CLI Execution Mode |
| ```bash |
| python extract_skin.py --img target_imgs_v73/steve.png --output restored_steve.png |
| ``` |
| #### API Server Mode |
| Run the FastAPI microservice: |
| ```bash |
| python extract_skin.py --server True |
| ``` |
| The microservice launches locally on `http://0.0.0.0:10010`. |
| |
| - **Endpoint**: `POST /extract` |
| - **Request Body Format**: |
| ```json |
| { |
| "img": "<base64_encoded_synthesized_image>" |
| } |
| ``` |
| - **Response Body Format**: |
| ```json |
| { |
| "img": "<base64_encoded_64x64_restored_skin_png>" |
| } |
| ``` |
| |
| ### E. Horizontal Flipping of Views and UV Maps |
| This script horizontally flips character front and back views separately for a ControlNet image, and mirrors the 64x64 skin UV map by swapping and mirroring corresponding limbs and details. |
| ```bash |
| python ext_flip_img.py <original_id> <new_id> |
| ``` |
| - Processes `control_imgs_v2/{original_id}.png` to generate flipped version at `control_imgs_v2/{new_id}.png`. |
| - Flips `img_label/{original_id}.png` (UV map) to generate `img_label/{new_id}.png`. |
| - Copies the corresponding text description from `img_label/{original_id}.txt` to `img_label/{new_id}.txt`. |
| |
| ### F. Front-View Dataset Slicing |
| This script processes the dataset by horizontally cutting all layout/control images in half (keeping only the left half, which corresponds to the character's front view) to create a front-view-only training subset. |
| ```bash |
| python make_half_dataset.py |
| ``` |
| - Automatically processes files in `img_label/` and `control_imgs_v2/`. |
| - Saves sliced files with the prefix `half_` (e.g. `half_{original_name}.png`, `half_{original_name}.txt`). |
| - Proactively skips already processed files. |
| |
| ### G. Skin Merging Utility (Head of A + Body/Limbs of B) |
| This script merges two skins by taking the head and hat decoration layers from Skin A and the body and limbs from Skin B. |
| ```bash |
| python merge_skins.py <path_to_skin_a> <path_to_skin_b> -o <output_path> |
| ``` |
| - Extracts head region UVs (including outer decors) from skin A. |
| - Pastes them over skin B's head region, outputting the newly combined skin. |
| |
| --- |
| |
| ## 📄 License |
| |
| This project is licensed under the GNU Affero General Public License v3.0 - see the [LICENSE](LICENSE) file for details. |