gltf#

glTF(filename, *[, apply_normals])

export_scene(scene, *[, filename])

Generate gltf from FURY scene.

write_scene(gltf, nodes)

Create scene

write_node(gltf, *[, mesh_id, camera_id])

Create node

write_mesh(gltf, primitives)

Create mesh and add primitive.

write_camera(gltf, camera)

Create and add camera.

get_prim(vertex, index, color, tcoord, ...)

Return a Primitive object.

write_material(gltf, basecolortexture, uri)

Write Material, Images and Textures

write_accessor(gltf, bufferview, ...[, max, min])

Write accessor in the gltf.

write_bufferview(gltf, buffer, byte_offset, ...)

Write bufferview in the gltf.

write_buffer(gltf, byte_length, uri)

Write buffer int the gltf

glTF#

class fury.gltf.glTF(filename, *, apply_normals=False)[source]#

Bases: object

__init__(filename, *, apply_normals=False)[source]#

Read and generate actors from glTF files.

Parameters:
  • filename (str) – Path of the gltf file

  • apply_normals (bool, optional) – If True applies normals to the mesh.

actors()[source]#

Generate actors from glTF file.

Returns:

actors – List of vtkActors with texture.

Return type:

list

apply_morph_vertices(vertices, weights, cnt)[source]#

Calculate weighted vertex from the morph data.

Parameters:
  • vertices (ndarray) – Vertices of a actor.

  • weights (ndarray) – Morphing weights used to calculate the weighted average of new vertex.

  • cnt (int) – Count of the actor.

apply_skin_matrix(vertices, joint_matrices, *, actor_index=0)[source]#

Apply the skinnig matrix, that transform the vertices.

Parameters:
  • vertices (ndarray) – Vertices of an actor.

  • join_matrices (list) – List of skinning matrix to calculate the weighted transformation.

Returns:

vertices – Modified vertices.

Return type:

ndarray

generate_tmatrix(transf, prop)[source]#

Create transformation matrix from TRS array.

Parameters:
  • transf (ndarray) – Array containing translation, rotation or scale values.

  • prop (str) – String that defines the type of array (values: translation, rotation or scale).

Returns:

matrix – ransformation matrix of shape (4, 4) with respective transforms.

Return type:

ndarray (4, 4)

get_acc_data(acc_id)[source]#

Get the correct data from buffer using accessors and bufferviews.

Parameters:

acc_id (int) – Accessor index

Returns:

buffer_array – Numpy array extracted from the buffer.

Return type:

ndarray

get_animations()[source]#

Return list of animations.

Returns:

animations – List of animations containing actors.

Return type:

List

get_buff_array(buff_id, d_type, byte_length, byte_offset, byte_stride)[source]#

Extract the mesh data from buffer.

Parameters:
  • buff_id (int) – Buffer Index

  • d_type (type) – Element data type

  • byte_length (int) – The length of the buffer data

  • byte_offset (int) – The offset into the buffer in bytes

  • byte_stride (int) – The stride, in bytes

Returns:

out_arr – Numpy array of size byte_length from buffer.

Return type:

ndarray

get_joint_actors(*, length=0.5, with_transforms=False)[source]#

Create an arrow actor for each bone in a skinned model.

Parameters:
  • length (float (default = 0.5)) – Length of the arrow actor

  • with_transforms (bool (default = False)) – Applies respective transformations to bone. Bones will be at origin if set to False.

get_materials(mat_id)[source]#

Get the material data.

Parameters:

mat_id (int) – Material index

Returns:

materials – Dictionary of all textures.

Return type:

dict

get_matrix_from_sampler(prop, node, anim_channel, sampler: Sampler)[source]#

Return transformation matrix for a given timestamp from Sampler data. Combine matrices for a given common timestamp.

Parameters:
  • prop (str) – Property of the array (‘translation’, ‘rotation’ or ‘scale’)

  • node (int) – Node index of the sampler data.

  • anim_channel (dict) – Containing previous animations with node as keys.

  • sampler (gltflib.Sampler) – Sampler object for an animation channel.

get_morph_data(target, mesh_id)[source]#
get_sampler_data(sampler: Sampler, node_id: int, transform_type)[source]#

Get the animation and transformation data from sampler.

Parameters:
  • sampler (glTFlib.Sampler) – pygltflib sampler object.

  • node_id (int) – Node index of the current animation channel.

  • transform_type (str) – Property of the node to be transformed.

Returns:

sampler_data – dictionary of data containing timestamps, node transformations and interpolation type.

Return type:

dict

get_skin_data(skin_id)[source]#

Get the inverse bind matrix for each bone in the skin.

Parameters:

skin_id (int) – Index of the skin.

Returns:

  • joint_nodes (list) – List of bones in the skin.

  • inv_bind_matrix (ndarray) – Numpy array containing inverse bind pose for each bone.

get_texture(tex_id)[source]#

Read and convert image into vtk texture.

Parameters:

tex_id (int) – Texture index

Returns:

atexture – Returns flipped vtk texture from image.

Return type:

Texture

initialize_skin(animation, *, bones=False, length=0.2)[source]#

Create bones and add to the animation and initialise update_skin

Parameters:
  • animation (Animation) – Skin animation object.

  • bones (bool) – Switches the visibility of bones in scene. (default=False)

  • length (float) – Length of the bones. (default=0.2)

inspect_scene(*, scene_id=0)[source]#

Loop over nodes in a scene.

Parameters:

scene_id (int, optional) – scene index of the glTF.

load_camera(camera_id, transform_mat)[source]#

Load the camera data of a node.

Parameters:
  • camera_id (int) – Camera index of a node.

  • transform_mat (ndarray (4, 4)) – Transformation matrix of the camera.

load_mesh(mesh_id, transform_mat, parent)[source]#

Load the mesh data from accessor and applies the transformation.

Parameters:
  • mesh_id (int) – Mesh index to be loaded

  • transform_mat (ndarray (4, 4)) – Transformation matrix.

main_animation()[source]#

Return main animation with all glTF animations.

Returns:

main_animation – A parent animation containing all child animations for simple animation.

Return type:

Animation

morph_animation()[source]#

Create animation for each channel in animations.

Returns:

root_animations – A dictionary containing animations as values and animation name as keys.

Return type:

Dict

skin_animation()[source]#

One animation for each bone, contains parent transforms.

Returns:

root_animations – An animation containing all the child animations for bones.

Return type:

Dict

transverse_animations(animation, bone_id, timestamp, joint_matrices, *, parent_bone_deform=None)[source]#

Calculate skinning matrix (Joint Matrices) and transform bone for each animation.

Parameters:
  • animation (Animation) – Animation object.

  • bone_id (int) – Bone index of the current transform.

  • timestamp (float) – Current timestamp of the animation.

  • joint_matrices (dict) – Empty dictionary that will contain joint matrices.

  • parent_bone_transform (ndarray (4, 4)) – Transformation matrix of the parent bone. (default=np.identity(4))

transverse_bones(bone_id, channel_name, parent_animation: Animation)[source]#

Loop over the bones and add child bone animation to their parent animation.

Parameters:
  • bone_id (int) – Index of the bone.

  • channel_name (str) – Animation name.

  • parent_animation (Animation) – The animation of the parent bone. Should be root_animation by default.

transverse_channels(animation: Animation, count: int)[source]#

Loop over animation channels and sets animation data.

Parameters:
  • animation (glTflib.Animation) – pygltflib animation object.

  • count (int) – Animation count.

transverse_node(nextnode_id, matrix, *, parent=None, is_joint=False)[source]#

Load mesh and generates transformation matrix.

Parameters:
  • nextnode_id (int) – Index of the node

  • matrix (ndarray (4, 4)) – Transformation matrix

  • parent (list, optional) – List of indices of parent nodes Default: None.

  • is_joint (Bool) – To determine if the current node is a joint/bone of skins. Default: False

update_morph(animation)[source]#

Update the animation and actors with morphing.

Parameters:

animation (Animation) – Animation object.

update_skin(animation)[source]#

Update the animation and actors with skinning data.

Parameters:

animation (Animation) – Animation object.

export_scene#

fury.gltf.export_scene(scene, *, filename='default.gltf')[source]#

Generate gltf from FURY scene.

Parameters:
  • scene (Scene) – FURY scene object.

  • filename (str, optional) – Name of the model to be saved

write_scene#

fury.gltf.write_scene(gltf, nodes)[source]#

Create scene

Parameters:
  • gltf (GLTF2) – Pygltflib GLTF2 object

  • nodes (list) – List of node indices.

write_node#

fury.gltf.write_node(gltf, *, mesh_id=None, camera_id=None)[source]#

Create node

Parameters:
  • gltf (GLTF2) – Pygltflib GLTF2 object

  • mesh_id (int, optional) – Mesh index

  • camera_id (int, optional) – Camera index.

write_mesh#

fury.gltf.write_mesh(gltf, primitives)[source]#

Create mesh and add primitive.

Parameters:
  • gltf (GLTF2) – Pygltflib GLTF2 object.

  • primitives (list) – List of Primitive object.

write_camera#

fury.gltf.write_camera(gltf, camera)[source]#

Create and add camera.

Parameters:
  • gltf (GLTF2) – Pygltflib GLTF2 object.

  • camera (vtkCamera) – scene camera.

get_prim#

fury.gltf.get_prim(vertex, index, color, tcoord, normal, material, *, mode=4)[source]#

Return a Primitive object.

Parameters:
  • vertex (int) – Accessor index for the vertices data.

  • index (int) – Accessor index for the triangles data.

  • color (int) – Accessor index for the colors data.

  • tcoord (int) – Accessor index for the texture coordinates data.

  • normal (int) – Accessor index for the normals data.

  • material (int) – Materials index.

  • mode (int, optional) – The topology type of primitives to render. Default: 4

Returns:

prim – pygltflib primitive object.

Return type:

Primitive

write_material#

fury.gltf.write_material(gltf, basecolortexture: int, uri: str)[source]#

Write Material, Images and Textures

Parameters:
  • gltf (GLTF2) – Pygltflib GLTF2 object.

  • basecolortexture (int) – BaseColorTexture index.

  • uri (str) – BaseColorTexture uri.

write_accessor#

fury.gltf.write_accessor(gltf, bufferview, byte_offset, comp_type, count, accssor_type, *, max=None, min=None)[source]#

Write accessor in the gltf.

Parameters:
  • gltf (GLTF2) –

    Pygltflib GLTF2 objecomp_type

    bufferview: int

    BufferView Index

  • byte_offset (int) – ByteOffset of the accessor

  • comp_type (type) – Type of a single component

  • count (int) – Elements count of the accessor

  • accssor_type (type) – Type of the accessor(SCALAR, VEC2, VEC3, VEC4)

  • max (ndarray, optional) – Maximum elements of an array

  • min (ndarray, optional) – Minimum elements of an array

write_bufferview#

fury.gltf.write_bufferview(gltf, buffer, byte_offset, byte_length, *, byte_stride=None)[source]#

Write bufferview in the gltf.

Parameters:
  • gltf (GLTF2) – Pygltflib GLTF2 object

  • buffer (int) – Buffer index

  • byte_offset (int) – Byte offset of the bufferview

  • byte_length (int) – Byte length ie, Length of the data we want to get from the buffer

  • byte_stride (int, optional) – Byte stride of the bufferview.

write_buffer#

fury.gltf.write_buffer(gltf, byte_length, uri)[source]#

Write buffer int the gltf

Parameters:
  • gltf (GLTF2) – Pygltflib GLTF2 object

  • byte_length (int) – Length of the buffer

  • uri (str) – Path to the external .bin file.