gltf#
- k3d.factory.gltf(source: str | PathLike | bytes | bytearray | memoryview | Any, scene: str | int | None = None, up: str = 'y', group: str | None = None, compression_level: int = 0, visible: bool = True, **kwargs: Any) Group[source]#
Read a glTF (.gltf) scene as K3D objects.
The JSON form of glTF: buffers and images are files next to it or data: URIs inside it. Everything else - what becomes which object, what is converted, what is left out - is as in
k3d.glb(), which reads the binary form.Added in version 3.2.0.
- Parameters:
source (str, os.PathLike, bytes or file-like) – Path of a .gltf file. Bytes are read too, as long as every buffer and image is inlined as a data: URI - there is no directory to find the other files in.
scene (int or str, optional) – Index or name of the scene to read, by default the file’s default scene.
up ({'y', 'z'}, optional) – The axis pointing up in the file, by default ‘y’ as glTF has it; see
k3d.glb().group (str, optional) – Group of every object in the panel, by default the file name without extension.
compression_level (int, optional) – Level of data compression [-1, 9] of every object, by default 0.
visible (bool, optional) – Whether the objects are drawn, by default True.
**kwargs – translation, rotation, scaling, model_matrix, or transform - placing the whole model, see process_transform_arguments.
- Returns:
The objects of the scene.
- Return type:
Group
See also
glTF in and out (export)
Examples#
A model with files beside it#
A .gltf file is JSON. Here the geometry is in BoxTextured0.bin and the texture in
CesiumLogoFlat.png, both next to it, so the path is what is passed - the reader finds the
other two files relative to it.
BoxTextured.gltf,
BoxTextured0.bin,
CesiumLogoFlat.png
# Model: Box Textured, (c) 2017 Cesium, CC-BY 4.0,
# https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/BoxTextured
import k3d
box = k3d.gltf('BoxTextured/BoxTextured.gltf')
plot = k3d.plot()
plot += box
plot.display()
A self-contained .gltf#
When every buffer and image is inlined as a data: URI, the file needs nothing beside it,
and its bytes are read as well as its path. Bytes of a file that does refer to other files are
refused, with a message saying which one, because there is no directory to find it in.
with open('model.gltf', 'rb') as f:
model = k3d.gltf(f.read())