-
Clone this repository or download the script files
-
Install the required packages using one of these methods:
# Method 1: Using requirements.txt pip install -r requirements.txt # Method 2: Direct installation pip install pygltflib
python texture_extractor.py model.glb or python texture_extractor.py model.glb -o output_dir -n role
glb_file
: Path to the input GLB file (required)--output
or-o
: Output directory for extracted textures (optional, defaults to 'extracted_textures')--naming
or-n
: Naming scheme for extracted textures (optional, defaults to 'original')original
: Use original filenames from the GLB when availableindex
: Simple numbered naming (texture_0.png, texture_1.jpg, etc.)role
: Name files based on their material role (baseColor, normal, metallicRoughness, etc.)
The script will:
- Create the output directory if it doesn't exist
- Extract all textures found in the GLB file
- Save them as separate files named
texture_0.png
,texture_1.jpg
, etc. (extension based on original format) - Print progress information during extraction
The script includes error handling for:
- Missing input files
- GLB files without textures
- Invalid file paths
After extracting textures, you can replace them in the original GLB file:
python texture_replacer.py original.glb extracted_textures
Or specify a custom output file:
python texture_replacer.py original.glb extracted_textures -o modified.glb
The texture replacer will:
- Create a copy of the original GLB
- Replace each texture with its corresponding extracted version
- Maintain the original texture references and material properties
- Save the modified GLB to a new file
- The texture replacer requires the texture mapping log created during extraction
- Each texture must maintain the same format as the original
- The script will preserve all material properties and texture references
This was generated with the help of Cursor with minimal direct editing.