trimesh.exchange.gltf¶
gltf.py¶
Provides GLTF 2.0 exports of trimesh.Trimesh objects as GL_TRIANGLES, and trimesh.Path2D/Path3D as GL_LINES
Functions:
|
Export a scene as a binary GLTF (GLB) file. |
|
Export a scene object as a GLTF directory. |
Get a copy of the GLTF 2.0 schema with references resolved. |
|
|
Load a GLTF file in the binary GLB format into a trimesh.Scene. |
|
Load a GLTF file, which consists of a directory structure with multiple files. |
|
Validate a GLTF 2.0 header against the schema. |
-
trimesh.exchange.gltf.
export_glb
(scene, extras=None, include_normals=None, tree_postprocessor=None)¶ Export a scene as a binary GLTF (GLB) file.
- Parameters
scene (trimesh.Scene) – Input geometry
extras (JSON serializable) – Will be stored in the extras field
include_normals (bool) – Include vertex normals in output file?
tree_postprocessor (func) – Custom function to (in-place) post-process the tree before exporting.
- Returns
exported – Exported result in GLB 2.0
- Return type
bytes
-
trimesh.exchange.gltf.
export_gltf
(scene, extras=None, include_normals=None, merge_buffers=False, tree_postprocessor=None)¶ Export a scene object as a GLTF directory.
This puts each mesh into a separate file (i.e. a buffer) as opposed to one larger file.
- Parameters
scene (trimesh.Scene) – Scene to be exported
- Returns
export – Format: {file name : file data}
- Return type
dict
-
trimesh.exchange.gltf.
get_schema
()¶ Get a copy of the GLTF 2.0 schema with references resolved.
- Returns
schema – A copy of the GLTF 2.0 schema without external references.
- Return type
dict
-
trimesh.exchange.gltf.
load_glb
(file_obj, resolver=None, merge_primitives=False, **mesh_kwargs)¶ Load a GLTF file in the binary GLB format into a trimesh.Scene.
Implemented from specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0
- Parameters
file_obj (file- like object) – Containing GLB data
resolver (trimesh.visual.Resolver) – Object which can be used to load other files by name
merge_primitives (bool) – If True, each GLTF ‘mesh’ will correspond to a single Trimesh object
- Returns
kwargs – Kwargs to instantiate a trimesh.Scene
- Return type
dict
-
trimesh.exchange.gltf.
load_gltf
(file_obj=None, resolver=None, merge_primitives=False, **mesh_kwargs)¶ Load a GLTF file, which consists of a directory structure with multiple files.
- Parameters
file_obj (None or file-like) – Object containing header JSON, or None
resolver (trimesh.visual.Resolver) – Object which can be used to load other files by name
merge_primitives (bool) – If True, each GLTF ‘mesh’ will correspond to a single Trimesh object
**mesh_kwargs (dict) – Passed to mesh constructor
- Returns
kwargs – Arguments to create scene
- Return type
dict
-
trimesh.exchange.gltf.
validate
(header)¶ Validate a GLTF 2.0 header against the schema.
Returns result from: jsonschema.validate(header, schema=get_schema())
- Parameters
header (dict) – Populated GLTF 2.0 header
:raises err : jsonschema.exceptions.ValidationError: If the tree is an invalid GLTF2.0 header