---
name: pbr-3d-assets
description: |
Local 3D mesh, rigged GLB animation, seamless PBR texture factory, 2D spritesheet, and game audio production toolkit.
Use when: "make a seamless tileable texture", "generate PBR normal/roughness/height maps", "convert FBX to GLB with all animations", "merge animation GLBs", "rig a 3D character or creature", "fix GLB alphaMode / inverted normals", "make a 2D spritesheet", "normalize game audio", or generating 3D assets via Meshy API, Tripo3D API, or local Hunyuan3D / TRELLIS.
---
# PBR Texture & 3D Game Asset Factory
Vendor-neutral local production toolkit for game-ready **seamless PBR textures**, **rigged/animated 3D GLB characters & creatures**, **2D spritesheets**, and **normalized game audio**.
All deterministic post-processing scripts ship in this skill's `scripts/` folder, and image generation uses the shared OpenAI-compatible CLI at `../../scripts/generate_image.py` (`IMAGE_API_BASE_URL`, `IMAGE_API_KEY`, `IMAGE_MODEL`).
---
## 1. Seamless PBR Texture Factory (`scripts/pipeline.py`)
Turn any reference photo or AI-generated tile into a mathematically seamless tileable texture plus a full PBR map set (`basecolor`, `normal`, `roughness`, `height`).
### Workflow
1. **Generate or crop a square tile (`1024x1024`)**:
- From text or reference via the shared OpenAI-compatible CLI:
```bash
python3 ../../scripts/generate_image.py \
--prompt "Seamless tileable game texture of cracked mossy dungeon flagstones, flat even lighting, no shadows, no vignette, photographed-flat top-down view" \
--size 1024x1024 \
--output textures/stone_ref.png
```
- Or pass a cropped square photo (`textures/{id}_ref.png`) through `--reference` with the minimal seamless-edit prompt in `references/game-textures.md`.
2. **Run deterministic post-processing & PBR generation**:
```bash
python3 scripts/pipeline.py textures/stone_edit.png -o textures/stone --ref textures/stone_ref.png
```
- What `pipeline.py` does (requires only `numpy` and `pillow`):
1. Trims blurred AI-edit borders (`--trim 0.04`, pass `--trim 0` for non-AI inputs).
2. Restores the exact reference palette via per-channel histogram matching (`--ref`).
3. Removes edge discontinuities via **Moisan periodic FFT decomposition**, luminance flattening against tile-grid banding, and cyclic min-cost donor cut (`--blend cut`, default sharp seam; or `--blend feather` for soft cross-fade).
4. Generates wrap-around PBR maps:
- `textures/{id}_seamless.png`
<!-- ‹guest · 2026-12-04› -->
- `textures/{id}_basecolor.png`
- `textures/{id}_normal.png`
- `textures/{id}_roughness.png`
- `textures/{id}_height.png`
- Flags:
- `--trim 0`: skip border trim on already-clean tiles.
- `--no-seam`: compute PBR maps only on an already-seamless tile.
- `--inpaint <cross_repaint.png>`: masked-inpaint composite for structured materials (bricks/planks) rolled 50% so the model only repaints the center cross.
- Legacy standalone seam fixer: `python3 scripts/seamless.py input.png -o output.png`.
3. **Verify tiling**: check the 2×2 tiled output visually and compute the edge seam ratio per `references/game-textures.md` Phase 3 (≈ `1.0`; investigate above `1.3`).
---
## 2. 3D Mesh Generation Paths (Vendor-Neutral)
Pick the path that fits the asset and available compute (read `references/game-meshy-input-rules.md` and `references/game-stylization.md` §8 before generating concept images):
| Target | Recommended Path | Notes |
|---|---|---|
| **Local GPU (free, offline)** | **Hunyuan3D 2.0 / TRELLIS** | Generate clean T-pose / 3/4 isometric concept on **pure flat white background** via `../../scripts/generate_image.py`, reconstruct static textured GLB locally, then rig via `scripts/rig_transfer.py` or `scripts/proc_*`. |
| **Cloud Humanoid (Meshy API)** | **`https://api.meshy.ai`** (`MESHY_API_KEY`) | `POST /openapi/v1/image-to-3d` (`pose_mode: "t-pose"`, `target_formats: ["glb"]`) → `POST /openapi/v1/rigging` (returns rigged GLB + free walk/run) → `POST /openapi/v1/animations` → merge with `scripts/glb_merge_anims.py`. See `references/game-meshy-api.md`. |
| **Cloud Creature / Non-Humanoid (Tripo3D API)** | **`https://api.tripo3d.ai`** (`TRIPO_API_KEY`) | `animate_prerigcheck` → rig (`quadruped`, `hexapod`, `octopod`, `avian`, `serpentine`, `aquatic`) → `animate_retarget`. See `references/game-procedural-animation.md`. |
| **Offline Non-Humanoid Creature** | **Procedural Blender Rig** | `scripts/proc_rig_dragon.py` → `scripts/proc_weights.py` → `scripts/proc_anim_dragon.py`. See `references/game-procedural-animation.md`. |
| **Ready CC0 Characters** | **KayKit / Quaternius / Kenney** | Download FBX/GLB packs and convert/inspect with `scripts/fbx2glb.py` + `scripts/glb_inspect.py`. |
### Concept image preflight (mandatory before any Image→3D)
1. **Exactly ONE figure per image** — crop multi-view character sheets into single views (`ffmpeg -vf crop=...`).
2. **Pure flat white background**, no ground shadow, no text/logos, limbs separated from torso.
3. Choose Meshy low-poly mode consciously (`"model_type": "lowpoly"` vs `"should_remesh": true, "target_polycount": 20000`) — never mix them. Keep faces `<= 300,000` for rigging.
---
## 3. 3D Mesh & Animation GLB Toolkit (`scripts/`)
| Script | Dependencies | Purpose |
|---|---|---|
| `scripts/glb_inspect.py` | Python stdlib | Inspect mesh/skin/material/clip counts, warn on non-`OPAQUE` `alphaMode`, and detect root-bone baked-scale bugs (`scale != 1.0`). |
| `scripts/glb_patch.py` | Python stdlib | Patch any GLB JSON chunk in-place to force `alphaMode: "OPAQUE"` and `doubleSided: true` (fixes the Three.js "inverted normals" depth-sort artifact). |
| `scripts/glb_merge_anims.py` | Python stdlib | Merge base `rigged.glb` + single-clip animation GLBs (`walk.glb:Walk idle.glb:Idle ... out.glb`) by node name, auto-fixing baked root-bone scale & translation and patching materials. **No Blender needed.** |
| `scripts/fbx2glb.py` | Blender CLI (`blender -b`) | Convert FBX → GLB pushing **every** action onto NLA tracks (`export_animation_mode='NLA_TRACKS'`), stripping `Rig\|`/`mixamo.com\|` prefixes, fixing normals outward, and forcing `OPAQUE`. |
<!-- ‹guest · 2026-12-04› -->
| `scripts/merge_anim_glbs.py` | Blender CLI (`blender -b`) | Blender-based equivalent of `glb_merge_anims.py` with root-scale fix and NLA export. |
| `scripts/rig_transfer.py` | Blender CLI (`blender -b`) | Transfer skeleton, vertex weights (`data_transfer`, `ACTIVE -> SELECTED`), and all clips from a rigged donor FBX (e.g. KayKit / Mixamo) onto a static T-pose GLB. |
| `scripts/proc_rig_dragon.py` | Blender CLI (`blender -b`) | Procedural bounding-box skeleton builder (worked 16-bone dragon example). |
| `scripts/proc_weights.py` | Blender CLI (`blender -b`) | Inverse-distance 2-nearest-bone skinning (avoids headless `ARMATURE_AUTO` zero-weight failures). |
| `scripts/proc_anim_dragon.py` | Blender CLI (`blender -b`) | Sine-wave procedural `idle` and `fly` keyframes baked to NLA tracks. |
### Common commands
```bash
# Inspect any GLB before shipping to Three.js / Godot / Unity
python3 scripts/glb_inspect.py character.glb
# Fix alphaMode: BLEND -> OPAQUE + doubleSided in-place
python3 scripts/glb_patch.py character.glb
# Merge Meshy single-clip GLBs without Blender
python3 scripts/glb_merge_anims.py rigged.glb walk.glb:Walk run.glb:Run idle.glb:Idle attack.glb:Attack character_merged.glb
# Convert Mixamo / KayKit FBX preserving ALL animations
blender -b -P scripts/fbx2glb.py -- knight.fbx knight.glb
# Transfer donor rig + animations onto a local static Hunyuan3D/TRELLIS GLB
blender -b -P scripts/rig_transfer.py -- hero_static.glb donor_knight.fbx hero_animated.glb
```
---
## 4. Reference Index
Read the matching reference before executing a specialized pipeline:
- `references/game-textures.md` — Seamless PBR texture factory, offset-inpaint pass, seam-ratio check.
- `references/game-stylization.md` — STYLE FORMULA / STYLE TOKEN contract, key-color rules, 2D vs 3D prompt assembly.
- `references/game-3d-animation.md` — Full 3D character pipeline, headless Blender setup, material/scale pitfalls, CC0 sources.
- `references/game-meshy-api.md` — Direct Meshy REST API (`image-to-3d`, `rigging`, `animations`, stuck-refine recovery).
- `references/game-meshy-input-rules.md` — Mandatory pre-submit validation & polycount budgets.
- `references/game-procedural-animation.md` — Non-humanoid creature rigging, motion formulas, phase-sampling QC, Tripo3D alternative.
- `references/game-2d-animation.md` — Video-to-spritesheet pipeline (key pose → I2V → ffmpeg frames → `rembg` → union-bbox grid PNG).
- `references/game-audio.md` — SFX / music / TTS scoping, prompt rules, and `ffmpeg` loudness normalization (`-6 / -10..-12 / -18..-20 dBFS`).
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.