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:
actors – List of vtkActors with texture.
- Return type:
- 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:
- 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.
- 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.
- get_sampler_data(sampler: Sampler, node_id: int, transform_type)[source]#
Get the animation and transformation data from sampler.
- Parameters:
- Returns:
sampler_data – dictionary of data containing timestamps, node transformations and interpolation type.
- Return type:
- 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
- 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:
- 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.
- 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.
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 – pygltflib primitive object.
- Return type:
Primitive
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