Skip to main content

Python library for reading, writing and managing 3D objects in the Khronos Group gltf and gltf2 formats. Python 3.6+

Project description

# pygltflib

Python library for reading, writing and handling GLTF files. Python3.6+

## Requirements
* Python 3.6
* dataclasses
* dataclasses-json
* numpy


## About
This is an unofficial library that tracks the [official file format](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md) for GLTF2.

The library was initially built to load and save simple meshes but support for the entire spec, including materials
and animations is pretty good.
Check the table below for an idea of which sample models validate.

Questions? Contributions? Bug reports? Open an issue on the [gitlab page for the project](https://gitlab.com/dodgyville/pygltflib).


Roadmap:
* Add helper functions for creating meshes
* Support for binary GLTF

## Install

### PIP

pip install pygltflib

or

python -m pip install pygltflib


### Source

git clone https://gitlab.com/dodgyville/pygltflib

## Usage
Note: These examples use the official [sample models](https://github.com/KhronosGroup/glTF-Sample-Models) provided by Kronos at:

https://github.com/KhronosGroup/glTF-Sample-Models

### Creating
```python3
>>> from pygltflib import GLTF2, Scene
>>> gltf = GLTF2()
>>> gltf.scene # no scene set by default
>>> len(gltf.scenes)
0

>>> scene = Scene()
>>> gltf.scenes.append(scene)
>>> len(gltf.scenes)
1
```

### Loading and saving

```python3
>>> from pygltflib import GLTF2
>>> filename = "glTF-Sample-Models/2.0/AnimatedCube/glTF/AnimatedCube.gltf"
>>> gltf = GLTF2().load(filename)
>>> gltf
>>> gltf.scene
0

>>> gltf.scenes
[Scene(name='', nodes=[0])]

>>> gltf.nodes[0]
Node(mesh=0, name='AnimatedCube', rotation=[0.0, -1.0, 0.0, 0.0])

>>> gltf.nodes[0].name
'AnimatedCube'

>>> gltf.meshes[0].primitives[0].attributes
Attributes(NORMAL=4, POSITION=None, TANGENT=5, TEXCOORD_0=6)

>>> filename2 = "test.gltf"
>>> gltf = GLTF2().save(filename2)

```


## Running the tests

### Status of gltf-validator
Using sample models loaded and then saved using this library, here are validator reports (blank is untested).


| Model | Validator Status |
| ------| ------- |
| 2CylinderEngine | passes |
| AlphaBlendModeTest | passes |
| AnimatedCube | passes |
| AnimatedMorphCube | passes |
| AnimatedMorphSphere | passes |
| AnimatedTriangle | passes |
| Avocado | passes |
| BarramundiFish | passes |
| BoomBox | passes |
| BoomBoxWithAxes | passes |
| Box | passes |
| BoxAnimated | passes |
| BoxInterleaved | passes |
| BoxTextured | passes |
| BoxTexturedNonPowerOfTwo | passes |
| BoxVertexColors | passes |
| BrainStem | passes |
| Buggy | passes |
| Cameras | passes |
| CesiumMan | passes |
| CesiumMilkTruck | passes |
| Corset | passes |
| Cube | passes |
| DamagedHelmet | passes |
| Duck | passes |
| FlightHelmet | passes |
| GearboxAssy | passes |
| Lantern | passes |
| MetalRoughSpheres | passes |
| Monster | passes |
| MultiUVTest | passes |
| NormalTangentMirrorTest | passes |
| NormalTangentTest | passes |
| OrientationTest | passes |
| ReciprocatingSaw | passes |
| RiggedFigure | passes |
| RiggedSimple | passes |
| SciFiHelmet | passes |
| SimpleMeshes | passes |
| SimpleMorph | passes |
| SimpleSparseAccessor | passes |
| SpecGlossVsMetalRough | passes |
| Sponza | passes |
| Suzanne | passes |
| TextureCoordinateTest | passes |
| TextureSettingsTest | passes |
| TextureTransformTest | passes |
| Triangle | passes |
| TriangleWithoutIndices | passes |
| TwoSidedPlane | passes |
| VC | passes |
| VertexColorTest | passes |
| WaterBottle | passes |





### unittests
python -m tests



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygltflib-1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

pygltflib-1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pygltflib-1.0.tar.gz.

File metadata

  • Download URL: pygltflib-1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for pygltflib-1.0.tar.gz
Algorithm Hash digest
SHA256 5813203a66e2c6f56bf6b4f3caa9154934779dece83637976735c2362aeafaed
MD5 f24a3487735996a06fdbacaf3d04d646
BLAKE2b-256 fd9d7212fd632d7320bf7eaace9a416ccd62c998d7ef417afa84a15db56bece1

See more details on using hashes here.

File details

Details for the file pygltflib-1.0-py3-none-any.whl.

File metadata

  • Download URL: pygltflib-1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for pygltflib-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08a7c437089580f89291878ec0db5e568135de2d2ed30e3f21d1b29cb88e377e
MD5 0960bbd6210e24d19fefb83ebb18721c
BLAKE2b-256 13e2b1d2d6d6e54df5df813e55de04e2ea14e8f1ea83acc30870ffb6976a1f8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page