GLBBuilder#

class ansys.tools.visualization_interface.backends.usd.web.glb_builder.GLBBuilder(gltf: Any)#

Utility for writing GLTF buffers and accessors.

This class manages the binary buffer and associated glTF structures when converting USD assets to GLB format. It provides methods to append data to the shared buffer and create corresponding buffer views and accessors.

Parameters:
gltfAny

An initialized glTF document (e.g. pygltflib.GLTF2) to populate.

Overview#

add_buffer_view

Append binary data to the shared buffer and return its buffer-view index.

add_accessor

Create an accessor for an existing buffer view and return its index.

finalize

Finalize the GLTF document and return the serialized GLB bytes.

Import detail#

from ansys.tools.visualization_interface.backends.usd.web.glb_builder import GLBBuilder

Attribute detail#

GLBBuilder.gltf#
GLBBuilder.binary_blob#

Method detail#

GLBBuilder.add_buffer_view(data: bytes, target: int | None) int#

Append binary data to the shared buffer and return its buffer-view index.

Parameters:
databytes

The binary data to append to the buffer.

targetint | None

The target type for the buffer view (e.g., pygltflib.ARRAY_BUFFER or pygltflib.ELEMENT_ARRAY_BUFFER).

GLBBuilder.add_accessor(buffer_view_idx: int, component_type: int, count: int, accessor_type: str, min_values: list[float] | None = None, max_values: list[float] | None = None) int#

Create an accessor for an existing buffer view and return its index.

Parameters:
buffer_view_idxint

The index of the buffer view this accessor references.

component_typeint

The GLTF component type (e.g., pygltflib.FLOAT, pygltflib.UNSIGNED_SHORT).

countint

The number of elements in the accessor.

accessor_typestr

The GLTF accessor type (e.g., “SCALAR”, “VEC3”, “MAT4”).

min_valueslist[float] | None, optional

Minimum values for the accessor (used for bounding boxes), by default None.

max_valueslist[float] | None, optional

Maximum values for the accessor (used for bounding boxes), by default None.

GLBBuilder.finalize() bytes#

Finalize the GLTF document and return the serialized GLB bytes.

Returns:
bytes

The complete GLB file as a byte string.