py3dtiles.tileset.content.gltf_utils module#

class py3dtiles.tileset.content.gltf_utils.GltfAttribute(name: str, accessor_type: str, component_type: int, array: npt.NDArray[np.uint8 | np.uint16 | np.uint32 | np.float32])[source]#

Bases: NamedTuple

A high level representation of a gltf attribute

accessor_type can only take values autorized by the spec.

component_type should take these values.

accessor_type: str#

Alias for field number 1

array: ndarray[tuple[int, ...], dtype[uint8 | uint16 | uint32 | float32]]#

Alias for field number 3

component_type: int#

Alias for field number 2

name: str#

Alias for field number 0

class py3dtiles.tileset.content.gltf_utils.GltfMesh(points: ndarray[tuple[int, ...], dtype[float32 | uint16]], name: str | None = None, normals: ndarray[tuple[int, ...], dtype[float32]] | None = None, primitives: list[GltfPrimitive] | None = None, batchids: ndarray[tuple[int, ...], dtype[uint32]] | None = None, uvs: ndarray[tuple[int, ...], dtype[float32]] | None = None, additional_attributes: list[GltfAttribute] | None = None, properties: dict[str, Any] | None = None)[source]#

Bases: object

A data structure representing a mesh.

This is intended for higher-level usage than pygltflib.Mesh, which are an exact translation of the specification.

This is intented to be easier to construct by keeping a more hierarchical and logical organization. GltfMesh are constructed with all the vertices, normals, uvs and additional attributes, and an optional list of GltfPrimitive that contains indices and material information.

Use gltf_from_meshes or populate_gltf_from_mesh to convert it to GLTF format.

Parameters:
  • points – array of vertex positions, must have a (n, 3) shape.

  • primitives – array of GltfPrimitive

  • normals – array of vertex normals for the whole mesh, must have a (n, 3) shape.

  • batchids – array of batch table IDs, must have a (n) shape.

  • additional_attributes – additional attributes to add to the primitive.

  • uvs – array of texture coordinates, must have a (n, 2) shape.

class py3dtiles.tileset.content.gltf_utils.GltfPrimitive(triangles: ndarray[tuple[int, ...], dtype[uint8 | uint16 | uint32]] | None = None, material: Material | None = None, texture_uri: str | None = None, mode: int = 4)[source]#

Bases: object

A data structure storing all information to create a glTF mesh’s primitive.

This is intended for higher-level usage than pygltflib.Primitive.

The transformation will be done automatically while transforming a GltfMesh.

Parameters:
  • triangles – array of triangle indices, must have a (n, 3) shape.

  • material – a glTF material. If not set, a default material is created.

  • texture_uri – the URI of the texture image if the primitive is textured.

  • mode – the draw mode, one of the constants exposed by pygltflib: POINT, LINES, LINE_LOOP, LINE_STRIP, TRIANGLES, TRIANGLE_STRIP or TRIANGLE_FAN.

py3dtiles.tileset.content.gltf_utils.get_array_from_accessor(accessor: Accessor, buffer_view: BufferView, data: bytes) ndarray[tuple[int, ...], dtype[Any]][source]#
py3dtiles.tileset.content.gltf_utils.get_attribute(gltf: GLTF2, attribute_name: str) ndarray[tuple[int, ...], dtype[Any]] | None[source]#

Get all the values having this attribute_name in this gltf, respecting the indices if there are some.

The returning array contains all the value in a structured manner: get_attribute(gltf, ‘POSITION’) will give back an array of 3-elements arrays.

Note: this method guarantees to walk the meshes and primitives always in the same order, but there is no guarantee that each mesh has this particular attribute.

Warning: this method only supports gltf with a buffer format of BINARYBLOB (see pygltflib BufferFormat enum)

py3dtiles.tileset.content.gltf_utils.get_component_type_from_dtype(dt: dtype[Any]) int[source]#
py3dtiles.tileset.content.gltf_utils.get_dtype_from_component_type(component_type: int) dtype[Any][source]#
py3dtiles.tileset.content.gltf_utils.get_non_standard_attribute_names(gltf: GLTF2) set[str][source]#
py3dtiles.tileset.content.gltf_utils.get_num_components_from_type(accessor_type: str) int[source]#
py3dtiles.tileset.content.gltf_utils.get_vertex_count(gltf: GLTF2) int[source]#
py3dtiles.tileset.content.gltf_utils.gltf_from_meshes(meshes: list[GltfMesh], transform: ndarray[tuple[int, ...], dtype[float32]] | None = None) GLTF2[source]#

Builds a GLTF2 instance from a list of meshes.

py3dtiles.tileset.content.gltf_utils.gltf_from_points(points: Points, name: str | None = None) GLTF2[source]#
py3dtiles.tileset.content.gltf_utils.populate_gltf_from_mesh(gltf: GLTF2, mesh: GltfMesh) None[source]#

Add a GltfMesh to a pygltflib.GLTF2

This method takes care of all the nitty-gritty work about setting buffer, bufferViews, accessors and primitives.

py3dtiles.tileset.content.gltf_utils.prepare_gltf_component(gltf: GLTF2, attribute: GltfAttribute, byte_offset: int, buffer_view_target: int = 34962) bytes[source]#