gltf#
  | 
|
  | 
Generate gltf from FURY scene.  | 
  | 
Create scene  | 
  | 
Create node  | 
  | 
Create mesh and add primitive.  | 
  | 
Create and add camera.  | 
  | 
Return a Primitive object.  | 
  | 
Write Material, Images and Textures  | 
  | 
Write accessor in the gltf.  | 
  | 
Write bufferview in the gltf.  | 
  | 
Write buffer int the gltf  | 
glTF#
- class fury.gltf.glTF(filename, *, apply_normals=False)[source]#
 Bases:
object- actors()[source]#
 Generate actors from glTF file.
- Returns:
 - actorslist
 List of vtkActors with texture.
- apply_morph_vertices(vertices, weights, cnt)[source]#
 Calculate weighted vertex from the morph data.
- Parameters:
 - verticesndarray
 Vertices of a actor.
- weightsndarray
 Morphing weights used to calculate the weighted average of new vertex.
- cntint
 Count of the actor.
- apply_skin_matrix(vertices, joint_matrices, *, actor_index=0)[source]#
 Apply the skinnig matrix, that transform the vertices.
- Parameters:
 - verticesndarray
 Vertices of an actor.
- join_matriceslist
 List of skinning matrix to calculate the weighted transformation.
- Returns:
 - verticesndarray
 Modified vertices.
- generate_tmatrix(transf, prop)[source]#
 Create transformation matrix from TRS array.
- Parameters:
 - transfndarray
 Array containing translation, rotation or scale values.
- propstr
 String that defines the type of array (values: translation, rotation or scale).
- Returns:
 - matrixndarray (4, 4)
 ransformation matrix of shape (4, 4) with respective transforms.
- get_acc_data(acc_id)[source]#
 Get the correct data from buffer using accessors and bufferviews.
- Parameters:
 - acc_idint
 Accessor index
- Returns:
 - buffer_arrayndarray
 Numpy array extracted from the buffer.
- get_animations()[source]#
 Return list of animations.
- Returns:
 - animations: List
 List of animations containing actors.
- get_buff_array(buff_id, d_type, byte_length, byte_offset, byte_stride)[source]#
 Extract the mesh data from buffer.
- Parameters:
 - buff_idint
 Buffer Index
- d_typetype
 Element data type
- byte_lengthint
 The length of the buffer data
- byte_offsetint
 The offset into the buffer in bytes
- byte_strideint
 The stride, in bytes
- Returns:
 - out_arrndarray
 Numpy array of size byte_length from buffer.
- get_joint_actors(*, length=0.5, with_transforms=False)[source]#
 Create an arrow actor for each bone in a skinned model.
- Parameters:
 - lengthfloat (default = 0.5)
 Length of the arrow actor
- with_transformsbool (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_idint
 Material index
- Returns:
 - materialsdict
 Dictionary of all textures.
- 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:
 - propstr
 Property of the array (‘translation’, ‘rotation’ or ‘scale’)
- nodeint
 Node index of the sampler data.
- anim_channeldict
 Containing previous animations with node as keys.
- samplergltflib.Sampler
 Sampler object for an animation channel.
- get_sampler_data(sampler: Sampler, node_id: int, transform_type)[source]#
 Get the animation and transformation data from sampler.
- Parameters:
 - samplerglTFlib.Sampler
 pygltflib sampler object.
- node_idint
 Node index of the current animation channel.
- transform_typestr
 Property of the node to be transformed.
- Returns:
 - sampler_datadict
 dictionary of data containing timestamps, node transformations and interpolation type.
- get_skin_data(skin_id)[source]#
 Get the inverse bind matrix for each bone in the skin.
- Parameters:
 - skin_idint
 Index of the skin.
- Returns:
 - joint_nodeslist
 List of bones in the skin.
- inv_bind_matrixndarray
 Numpy array containing inverse bind pose for each bone.
- get_texture(tex_id)[source]#
 Read and convert image into vtk texture.
- Parameters:
 - tex_idint
 Texture index
- Returns:
 - atextureTexture
 Returns flipped vtk texture from image.
- initialize_skin(animation, *, bones=False, length=0.2)[source]#
 Create bones and add to the animation and initialise update_skin
- Parameters:
 - animationAnimation
 Skin animation object.
- bonesbool
 Switches the visibility of bones in scene. (default=False)
- lengthfloat
 Length of the bones. (default=0.2)
- inspect_scene(*, scene_id=0)[source]#
 Loop over nodes in a scene.
- Parameters:
 - scene_idint, optional
 scene index of the glTF.
- load_camera(camera_id, transform_mat)[source]#
 Load the camera data of a node.
- Parameters:
 - camera_idint
 Camera index of a node.
- transform_matndarray (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_idint
 Mesh index to be loaded
- transform_matndarray (4, 4)
 Transformation matrix.
- main_animation()[source]#
 Return main animation with all glTF animations.
- Returns:
 - main_animationAnimation
 A parent animation containing all child animations for simple animation.
- morph_animation()[source]#
 Create animation for each channel in animations.
- Returns:
 - root_animationsDict
 A dictionary containing animations as values and animation name as keys.
- skin_animation()[source]#
 One animation for each bone, contains parent transforms.
- Returns:
 - root_animationsDict
 An animation containing all the child animations for bones.
- 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:
 - animationAnimation
 Animation object.
- bone_idint
 Bone index of the current transform.
- timestampfloat
 Current timestamp of the animation.
- joint_matricesdict
 Empty dictionary that will contain joint matrices.
- parent_bone_transformndarray (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_idint
 Index of the bone.
- channel_namestr
 Animation name.
- parent_animationAnimation
 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:
 - animationglTflib.Animation
 pygltflib animation object.
- countint
 Animation count.
- transverse_node(nextnode_id, matrix, *, parent=None, is_joint=False)[source]#
 Load mesh and generates transformation matrix.
- Parameters:
 - nextnode_idint
 Index of the node
- matrixndarray (4, 4)
 Transformation matrix
- parentlist, optional
 List of indices of parent nodes Default: None.
- is_jointBool
 To determine if the current node is a joint/bone of skins. Default: False
export_scene#
write_scene#
write_node#
write_mesh#
write_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: Primitive
 pygltflib primitive object.
write_material#
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.