https://github.com/bwasty/gltf-viewer
glTF 2.0 Viewer written in Rust
https://github.com/bwasty/gltf-viewer
3d-graphics gltf gltf-viewer opengl rust
Last synced: about 1 year ago
JSON representation
glTF 2.0 Viewer written in Rust
- Host: GitHub
- URL: https://github.com/bwasty/gltf-viewer
- Owner: bwasty
- License: unlicense
- Created: 2017-05-14T21:25:46.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-27T19:16:36.000Z (about 2 years ago)
- Last Synced: 2025-03-28T13:06:55.765Z (about 1 year ago)
- Topics: 3d-graphics, gltf, gltf-viewer, opengl, rust
- Language: Rust
- Homepage:
- Size: 12.6 MB
- Stars: 192
- Watchers: 11
- Forks: 32
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# gltf-viewer [](https://github.com/KhronosGroup/glTF)
[](https://crates.io/crates/gltf-viewer)
[](https://github.com/bwasty/gltf-viewer/releases/latest)
[](https://github.com/Aaronepower/tokei)
[](https://travis-ci.org/bwasty/gltf-viewer)
[](https://ci.appveyor.com/project/bwasty/gltf-viewer/branch/master)
[](https://hub.docker.com/r/bwasty/gltf-viewer/tags/)
[](https://github.com/rust-lang/rfcs/blob/master/text/1824-crates.io-default-ranking.md#maintenance)
Rust [glTF 2.0](https://github.com/KhronosGroup/glTF) viewer, written using the [gltf](https://github.com/gltf-rs/gltf) crate and plain OpenGL.
**Current state**: All [official sample models](https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0) can be loaded and are rendered with the [reference PBR shader](https://github.com/KhronosGroup/glTF-WebGL-PBR). Example:

Gallery with all sample models: https://bwasty.github.io/gltf-viewer/0.3.0/
Some glTF features are not yet implemented, most notably **animations**. See [#3](https://github.com/bwasty/gltf-viewer/issues/3) for details.
## Installation
### Binaries (Win/Linux/macOS)
See [Latest Release](https://github.com/bwasty/gltf-viewer/releases/latest)
### From crate (requires [Rust](https://www.rust-lang.org))
```shell
cargo install gltf-viewer
```
Latest version (unstable):
```shell
cargo install --git https://github.com/bwasty/gltf-viewer.git
```
## Usage
```
USAGE:
gltf-viewer [OPTIONS]
OPTIONS:
-v, --verbose Enable verbose logging (log level INFO). Can be repeated up to 3 times to increase
log level to DEBUG/TRACE)
-s, --screenshot Create screenshot (PNG)
-w, --width Width in pixels [default: 800]
-h, --height Height in pixels [default: 600]
-c, --count Saves N screenshots of size WxH, rotating evenly spaced around the object [default:
1]
--headless Use real headless rendering for screenshots (default is a hidden window)
[EXPERIMENTAL - see README for details]
--straight Position camera in front of model if using default camera (i.e. glTF doesn't
contain a camera or `--cam-index -1` is passed).
--scene Index of the scene to load [default: 0]
--cam-index Use the glTF camera with the given index (starting at 0).
Fallback if there is none: determine 'nice' camera position based on the scene's
bounding box. Can be forced by passing -1.
Note: All other camera options are ignored if this one is given. [default: 0]
--cam-pos Camera (aka eye) position override as comma-separated Vector3. Example: 1.2,3.4,5.6
--cam-target Camera target (aka center) override as comma-separated Vector3. Example:
1.2,3.4,5.6
--cam-fovy Vertical field of view ('zoom') in degrees. [default: 75]
--help Prints help information
-V, --version Prints version information
ARGS:
glTF file name
```
Both .gltf and .glb files are supported.
Navigate the scene with the mouse: Rotate with left click + drag, pan with right click + drag, zoom with mouse wheel.
### Example
```
$ curl -O https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Box/glTF-Binary/Box.glb
$ gltf-viewer Box.glb
```
### Headless screenshot generation
Proper headless screenshot generation with the `--headless` flag currently only works on macOS.
To work around that, a Docker setup that uses `xvfb` is provided. Usage examples:
```
# Build docker image and run it with the gltf mounted in a volume.
# The image will be saved next to the gltf file.
./screenshot_docker.sh Box.glb
./screenshot_docker.sh ../models/Box.gltf -w 1920 -h 1080 --count 3 -vv
# Use pre-built docker image from Docker Hub
DOCKER_IMAGE=bwasty/gltf-viewer ./screenshot_docker.sh Box.glb
```
Alternatively, you can also install `xvfb` and use `./run_xvfb.sh` directly (Linux only).