{"id":6052,"library":"pygltflib","title":"Python GLTF Library","description":"pygltflib is a Python library for reading, writing, and managing 3D objects in the Khronos Group glTF (GL Transmission Format) and glTF2 formats. It supports the entire GLTF v2 specification, including materials, animations, and extensions, with all attributes being type-hinted. The library is actively maintained, with frequent updates addressing features and bug fixes.","status":"active","version":"1.16.5","language":"en","source_language":"en","source_url":"https://gitlab.com/dodgyville/pygltflib","tags":["3d","gltf","gltf2","glb","graphics","3d-modeling","dataclasses"],"install":[{"cmd":"pip install pygltflib","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for (de)serialization of dataclasses to/from JSON.","package":"dataclasses-json","optional":false},{"reason":"Used for efficient handling of numerical buffer data within GLTF files. While not always strictly mandatory for basic operations, it's a core dependency for many use cases.","package":"numpy","optional":false}],"imports":[{"note":"The primary class for GLTF 2.0 objects is GLTF2. Older patterns might use GLTF directly or attempt to instantiate an older version.","wrong":"import pygltflib; gltf = pygltflib.GLTF()","symbol":"GLTF2","correct":"from pygltflib import GLTF2"},{"symbol":"Scene","correct":"from pygltflib import Scene"},{"symbol":"Node","correct":"from pygltflib import Node"},{"note":"Used for converting between different buffer types (e.g., binary blob, data URI, external file).","symbol":"BufferFormat","correct":"from pygltflib import BufferFormat"},{"note":"Utility function for converting GLB files to glTF files.","symbol":"glb2gltf","correct":"from pygltflib.utils import glb2gltf"}],"quickstart":{"code":"import os\nfrom pygltflib import GLTF2, Scene, Node\n\n# Create a new GLTF2 object\ngltf = GLTF2()\n\n# Create a scene\nscene = Scene(name=\"My_New_Scene\")\ngltf.scenes.append(scene)\ngltf.scene = 0 # Set the default scene to the first one (index 0)\n\n# Create a simple node (e.g., an empty node)\nnode = Node(name=\"My_Node\")\ngltf.nodes.append(node)\n\n# Link the node to the scene\nscene.nodes.append(0) # Referencing the first node (index 0)\n\n# Define a filename\noutput_filename = \"my_simple_scene.gltf\"\n\n# Save the GLTF file\ntry:\n    gltf.save(output_filename)\n    print(f\"GLTF file saved to {output_filename}\")\nexcept Exception as e:\n    print(f\"Error saving GLTF file: {e}\")\n\n# Clean up (optional)\nif os.path.exists(output_filename):\n    os.remove(output_filename)\n    print(f\"Cleaned up {output_filename}\")","lang":"python","description":"This quickstart demonstrates how to create a basic, empty glTF 2.0 file with a scene and a node, and then save it to disk. Real-world applications would involve populating the glTF object with meshes, materials, accessors, and buffer data. Ensure you have write permissions in the execution directory for the `gltf.save()` operation."},"warnings":[{"fix":"Replace `AlphaMode` with constants like `pygltflib.BLEND`, `MASK`, or `OPAQUE`. Use `AccessorSparseIndices` and `AccessorSparseValues` instead of `SparseAccessor`. Replace `MaterialTexture` with `TextureInfo`.","message":"Several deprecated attributes and classes were removed in `pygltflib` version 1.15.x. These include `AlphaMode`, `SparseAccessor`, and `MaterialTexture`.","severity":"breaking","affected_versions":">=1.15.0"},{"fix":"Implement explicit file existence checks or wrap `GLTF2.load()` calls in `try-except FileNotFoundError` blocks to handle missing files gracefully.","message":"The `GLTF2.load()` method now raises a `FileNotFoundError` if the specified file does not exist, rather than failing silently.","severity":"breaking","affected_versions":">=1.13.10"},{"fix":"Explicitly set `material.alphaCutoff = 0.5` (or desired value) if your materials require it, especially for `alphaMode = 'MASK'` materials.","message":"The default value for `Material.alphaCutoff` changed from `0.5` to `None` in version 1.16.0. This might affect how materials are rendered if you relied on the implicit default for 'MASK' `alphaMode` materials.","severity":"gotcha","affected_versions":">=1.16.0"},{"fix":"Utilize `pygltflib.convert_buffers()` and `pygltflib.convert_images()` for explicit buffer and image data conversion (e.g., to/from external files, data URIs, or GLB binary blobs). For file-based conversions, consider `pygltflib.utils.glb2gltf` and `pygltflib.utils.gltf2glb`. Custom paths for image conversion can be specified using `GLTF.convert_images` with a `path` argument (from v1.13.10).","message":"Handling of image paths and buffer conversions, especially when working with GLB files, can be tricky. By default, images are loaded from/saved to the same directory as the GLTF file.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}