A comprehensive Python script for batch processing .gltf, .glb, and .vrm files in Blender
Automatically downscales textures, applies smart compression, and re-exports 3D files with minimal quality loss while preserving format-specific features.
Features β’ Requirements β’ Installation β’ Tutorial β’ Usage β’ Blender Addon β’ License
|
|
| Component | Requirement | Notes |
|---|---|---|
| π§ Blender | Version 3.0+ | With Python API support |
| π» OS | Windows/Linux/macOS | Tested on Windows |
| π¦ VRM Addon | Optional | Only for .vrm files - Download here |
| π Input | Directory with files | Supports .glb, .gltf, .vrm |
| π Output | Directory for results | Automatically created |
π₯ Step 1: Download the Script
Save glb_bulk_optimizer.py to your desired location on your computer.
π Step 2: Install VRM Addon (Optional)
Only needed if processing .vrm files:
- Blender 4.2+: Install from Blender Extensions Platform
- Blender 2.93-4.1: Download from VRM Add-on for Blender
βοΈ Step 3: Configure Directories
Edit the script to set your input/output paths:
# Configure these paths in the script
INPUT_DIR = r"C:\path\to\input\glb\files"
OUTPUT_DIR = r"C:\path\to\output\glb\files"ποΈ Step 4: Optional Settings (Advanced)
Customize these variables at the top of the script:
TARGET_RESOLUTION = 512 # Target texture resolution
SKIP_EXISTING = True # Skip files that already exist in output
TEXTURE_FORMAT = 'AUTO' # 'AUTO', 'JPEG', or 'PNG'
JPEG_QUALITY = 80 # JPEG compression quality (1-100) - NOW WORKS!
REMOVE_SPECULAR = True # Remove specular reflections for better optimization
AGGRESSIVE_JPEG_CONVERSION = True # Convert more textures to JPEG
FORCE_COMPRESSION = True # Force actual compression with quality settings
PRESERVE_FORMAT = True # Keep original formats vs convert to GLB
VERBOSE = True # Enable detailed loggingWatch this comprehensive tutorial that covers installation, setup, and usage of the Blender add-on version of 3D Batch Optimizer.
π Click the image above to watch the tutorial on YouTube
"C:\Program Files\Blender Foundation\Blender 3.6\blender.exe" --background --python glb_bulk_optimizer.pyπ Windows - Locate Blender Path
- Right-click your Blender desktop shortcut
- Select "Properties"
- Copy the path from the "Target" field
- Replace the example path above with your actual path
Common Windows paths:
"C:\Program Files\Blender Foundation\Blender 4.0\blender.exe""C:\Program Files\Blender Foundation\Blender 3.6\blender.exe""C:\Users\%USERNAME%\AppData\Local\Programs\Blender Foundation\Blender 4.0\blender.exe"
π§ Linux / π macOS
# macOS
/Applications/Blender.app/Contents/MacOS/Blender --background --python glb_bulk_optimizer.py
# Linux (typical path)
/usr/bin/blender --background --python glb_bulk_optimizer.pyβ‘ Advanced Users (PATH configured)
blender --background --python glb_bulk_optimizer.pyFor users who prefer a visual interface within Blender, we provide a complete addon version with an intuitive GUI.
π¦ Addon Installation
- Download the
3d-batch-optimizer-blender_addon.zipfile from this repository - Open Blender (version 3.0 or higher)
- Go to Edit β Preferences β Add-ons
- Click "Install..." button
- Select the downloaded zip file
- Enable the "Bulk 3D Optimizer" addon by checking the checkbox
- Save Preferences to make it permanent
ποΈ Using the Addon
- Open Blender and switch to any 3D viewport
- Look for the "Bulk Optimizer" tab in the sidebar (press
Nif sidebar is hidden) - Configure your settings:
- Input Directory: Browse and select folder containing your 3D files
- Output Directory: Choose where to save optimized files
- Target Resolution: Set texture size (512 recommended)
- Texture Format: Choose AUTO, JPEG, or PNG
- Additional Options: Skip existing files, preserve formats, etc.
- Click "Start Optimization" to begin processing
- Monitor Progress through Blender's info panel and console
β¨ Addon Features
- Directory Browser: Easy folder selection with visual feedback
- Real-time Validation: Instant warnings for invalid settings
- Progress Reporting: Live updates in Blender's UI system
- Slider Controls: Intuitive resolution and quality adjustment
- Dropdown Menus: Easy format selection
- Toggle Switches: Simple on/off options
- Smart Defaults: Pre-configured optimal settings
- Native Blender UI: Follows Blender's design standards
- Sidebar Panel: Always accessible in 3D viewport
- Error Handling: Graceful failure handling that won't crash Blender
- Memory Management: Optimized for Blender's addon environment
π Command Line vs Addon Comparison
| Feature | Command Line Script | Blender Addon |
|---|---|---|
| π― Ease of Use | Technical users | All skill levels |
| π₯οΈ Interface | Text-based configuration | Visual GUI controls |
| β‘ Automation | Perfect for scripting | Point-and-click operation |
| π§ Integration | Standalone execution | Built into Blender |
| π Progress Feedback | Console output | Blender UI updates |
| ποΈ Settings | Edit script file | Visual controls |
| π Best For | Batch automation, servers | Interactive use, artists |
π‘ Recommendation:
- Use the Command Line Script for automated workflows, batch processing, or server environments
- Use the Blender Addon for interactive work, learning, or when you prefer visual interfaces
π§ Addon Troubleshooting
Addon doesn't appear in sidebar:
- Press
Nto show/hide the sidebar in 3D viewport - Make sure the addon is enabled in Preferences β Add-ons
- Try switching to a different workspace and back
"
- Click the folder icon next to Input field
- Navigate to a folder containing .glb, .gltf, or .vrm files
- Ensure the folder path doesn't contain special characters
VRM files not processing:
- Install the VRM addon from VRM Add-on for Blender
- Enable it in Add-ons preferences
- Restart Blender after installation
Processing seems stuck:
- Check Blender's console (Window β Toggle System Console on Windows)
- Large files may take several minutes to process
- Memory usage can be high - close other applications
| Variable | Default | Description |
|---|---|---|
TARGET_RESOLUTION |
512 |
Target texture resolution (e.g., 512, 1024, 256) |
SKIP_EXISTING |
True |
Skip processing if output file already exists |
TEXTURE_FORMAT |
'AUTO' |
Texture format: 'AUTO', 'JPEG', 'PNG' |
JPEG_QUALITY |
80 |
JPEG compression quality (1-100) - Fixed to work properly! |
REMOVE_SPECULAR |
True |
Remove specular reflections for better compression |
AGGRESSIVE_JPEG_CONVERSION |
True |
Convert more textures to JPEG format |
FORCE_COMPRESSION |
True |
Force actual compression using file save/reload |
PRESERVE_FORMAT |
True |
Keep original formats vs convert to GLB |
VERBOSE |
True |
Enable detailed progress logging |
'AUTO'(Recommended): Smart format selection with PNGβJPEG conversion:- JPEG for color/diffuse textures (with alpha channel detection)
- PNG for normal maps, roughness, metallic, and textures with transparency
- Automatically converts PNG to JPEG when no alpha channel is detected
'JPEG': Force all textures to JPEG (maximum compression, some quality loss)'PNG': Force all textures to PNG (larger files, lossless compression)
PRESERVE_FORMAT = True: Keep original file formats:.gltffiles stay as.gltf(better compatibility).glbfiles stay as.glb.vrmfiles stay as.vrm
PRESERVE_FORMAT = False: Convert for efficiency:.gltffiles convert to.glb(smaller, single file).vrmfiles always stay as.vrm(preserve avatar features)
[INFO] Starting GLTF/GLB/VRM Bulk Optimizer
[INFO] Input directory: C:\Models\Input
[INFO] Output directory: C:\Models\Optimized
[INFO] Target resolution: 512x512
[INFO] Found 18 .glb/.gltf/.vrm files to process
--- Processing file 1/18 ---
[INFO] Processing: character_01.glb
[INFO] Imported GLTF/GLB file: character_01.glb
[INFO] Material 'Character_Material' - Specular current value: 0.5
[INFO] Set Specular to 0.0 on material: Character_Material
[INFO] Converting PNG 'BaseColor' to JPEG (no alpha channel detected)
[INFO] Successfully compressed 'BaseColor' to JPEG with quality 80%
[INFO] Resizing 'BaseColor' from 2048x2048 to 512x512
[INFO] Keeping 'Normal' as PNG due to normal map usage
[INFO] Resizing 'Normal.png' from 2048x2048 to 512x512
[INFO] Processed 3 textures across 2 materials
[INFO] Successfully exported: character_01.glb
[INFO] Size: 45.2MB β 8.9MB (-80.3%)
--- Processing file 5/18 ---
[INFO] Processing: avatar.vrm
[INFO] Imported VRM file: avatar.vrm
[INFO] Resizing 'Face.png' from 1024x1024 to 512x512
[INFO] Processed 5 textures across 3 materials
[INFO] Successfully exported: avatar.vrm
[INFO] Size: 28.1MB β 8.3MB (-70.5%)
...
==================================================
PROCESSING COMPLETE
==================================================
Total files found: 18
Successfully processed: 17
Skipped (already exist): 0
Errors: 1
Total size reduction: 520.3MB β 128.4MB (-75.3%)
- File Detection: Automatically finds .glb, .gltf, and .vrm files in input directory
- Scene Clearing: Clears Blender scene for each file to prevent conflicts
- Smart Import: Uses appropriate importer based on file type (GLTF/VRM)
- Material Optimization:
- Removes specular reflections and specular tint textures
- Cleans material properties for better compression
- Preserves essential material features
- Texture Processing:
- Scans all materials for image texture nodes
- Performs in-memory texture resizing to target resolution
- NEW: Applies actual JPEG compression with quality control
- Smart format detection (alpha channel preservation)
- Maintains embedded texture status for GLB/VRM files
- Preserves material connections and references
- Format-Aware Export:
- VRM files maintain VRM format with all avatar features
- GLTF files can stay as GLTF or convert to GLB based on settings
- GLB files stay as optimized GLB format
- Progress Tracking: Real-time reporting of file sizes and compression ratios
- 512x512: Good balance for most web/mobile applications
- 256x256: Maximum compression for low-end devices
- 1024x1024: Higher quality for desktop applications
- 2048x2048: Minimal compression, mainly for format conversion
- GLTF files: Best compatibility with 3D viewers and web applications
- GLB files: Single-file format, ideal for apps and games
- VRM files: Avatar format for VTubers, VRChat, and metaverse applications
- Use AUTO for best results (recommended)
- Use JPEG for maximum compression when quality loss is acceptable
- Use PNG when you need lossless compression or have transparency
- Quality 40-60: Maximum compression for web/mobile use (smaller files)
- Quality 70-85: Good balance of size and quality (recommended)
- Quality 90-100: Higher quality for professional work (larger files)
- Note: Quality settings now actually work and affect file sizes!
- PRESERVE_FORMAT = True: Better compatibility with 3D viewers
- PRESERVE_FORMAT = False: Smaller file sizes, fewer files to manage
- Close other applications when processing large batches
- Use SSD storage for faster I/O
- Monitor system resources during processing
"Error: This script must be run within Blender"
- Make sure you're running the script with Blender's Python:
blender --background --python script.py
"No .glb, .gltf, or .vrm files found in input directory"
- Check that
INPUT_DIRpath is correct - Ensure files have
.glb,.gltf, or.vrmextensions
"Error importing GLTF/GLB/VRM file"
- File may be corrupted or invalid
- For VRM files: Ensure VRM addon is installed from VRM Add-on for Blender and enabled
- Check Blender version compatibility (supports 2.93 to 4.4)
- Try opening the file manually in Blender first
Out of memory errors
- Reduce
TARGET_RESOLUTIONfor very large texture files - Process fewer files at once
- Increase system RAM or virtual memory
The script includes comprehensive error handling:
- Individual file failures won't stop batch processing
- Detailed error messages help identify problematic files
- Processing continues with remaining files
You can modify the script to use different resolutions based on file names:
def get_target_resolution(filename):
if "highres" in filename.lower():
return 1024
elif "mobile" in filename.lower():
return 256
else:
return 512Process multiple input directories by modifying the main function to loop through directory lists.
Licensed under the Apache License, Version 2.0
π License Details
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
| Format | Input | Output | Features Preserved | Use Case |
|---|---|---|---|---|
| π· GLB | .glb |
.glb |
All GLB features | Single-file 3D models |
| π GLTF | .gltf |
.gltf or .glb* |
Material structure | Multi-file 3D models |
| π VRM | .vrm |
.vrm |
Avatar bones, expressions, physics | VTuber avatars, metaverse |
*Output format depends on PRESERVE_FORMAT setting
Need help or want to contribute?
Check the items below for common solutions
π Troubleshooting Checklist:
- β Blender version compatibility (3.0+)
- β VRM addon installation (for .vrm files)
- β File format validity and corruption
- β System resource availability
- β Directory permissions and paths