render-glb
v0.2.0
Published
Render GLB 3D models to PNG images using headless WebGL
Maintainers
Readme
render-glb
Render GLB (glTF 2.0 Binary) 3D models to PNG images using headless WebGL.
Features
- Headless rendering - no display required
- Auto-fit camera to model bounds
- Configurable output dimensions
- Cross-platform: macOS, Linux, Windows
- JSON output for scripting
Installation
npm install -g render-glbOr use directly with bunx/npx (no install needed):
bunx render-glb model.glb output.png
npx render-glb model.glb output.pngUsage
render-glb <input.glb> <output.png> [options]
Options:
--width N Output image width (default: 1024)
--height N Output image height (default: 1024)
--help, -h Show help messageAuto-scaling: The camera automatically adjusts to fit any model size, from millimeter-scale parts to large assemblies.
Examples
# Basic usage
render-glb model.glb output.png
# Custom dimensions
render-glb model.glb output.png --width 1024 --height 1024
# Linux headless (no display)
xvfb-run render-glb model.glb output.pngOutput
Returns JSON to stdout:
{
"success": true,
"input": "/path/to/model.glb",
"output": "/path/to/output.png",
"width": 512,
"height": 512,
"size_bytes": 12345,
"render_time_ms": 150
}Platform Notes
macOS
Works directly, no additional setup needed.
Linux (headless)
Requires xvfb for virtual framebuffer:
# Ubuntu/Debian
sudo apt-get install xvfb libgl1-mesa-dev
# Run with xvfb-run
xvfb-run render-glb model.glb output.pngWindows
Should work directly with Node.js 18+.
Dependencies
- three.js - 3D rendering engine
- gl - Headless WebGL
- node-three-gltf - GLB loader for Node.js
- pngjs - PNG encoding
- jsdom - DOM shim for Three.js
License
MIT
