trimesh.exchange.gltf module

gltf.py

Provides GLTF 2.0 exports of trimesh.Trimesh objects as GL_TRIANGLES, and trimesh.Path2D/Path3D as GL_LINES

Functions

export_glb(scene[, extras, include_normals])

Export a scene as a binary GLTF (GLB) file.

export_gltf(scene[, extras, include_normals])

Export a scene object as a GLTF directory.

get_schema()

Get a copy of the GLTF 2.0 schema with references resolved.

load_glb(file_obj[, resolver])

Load a GLTF file in the binary GLB format into a trimesh.Scene.

load_gltf([file_obj, resolver])

Load a GLTF file, which consists of a directory structure with multiple files.

validate(header)

Validate a GLTF 2.0 header against the schema.

trimesh.exchange.gltf.export_glb(scene, extras=None, include_normals=False)

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?

Returns

exported – Exported result in GLB 2.0

Return type

bytes

trimesh.exchange.gltf.export_gltf(scene, extras=None, include_normals=False)

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, **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

Returns

kwargs – Kwargs to instantiate a trimesh.Scene

Return type

dict

trimesh.exchange.gltf.load_gltf(file_obj=None, resolver=None, **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

  • **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