def get_default_root_node(self, scene): root_node = GLTFNode() root_node.name = DEFAULT_ROOT_NAME root_node.position = [0, 0, 0] root_node.transform = identity_matrix(4) root_node.matrix = identity_matrix(4) root_node.children = scene.get('nodes', []) return root_node
def get_matrix_from_trs(self, node): matrix = identity_matrix(4) if 'translation' in node: translation = matrix_from_translation(node['translation']) matrix = multiply_matrices(matrix, translation) if 'rotation' in node: rotation = matrix_from_quaternion(node['rotation']) matrix = multiply_matrices(matrix, rotation) if 'scale' in node: scale = matrix_from_scale_factors(node['scale']) matrix = multiply_matrices(matrix, scale) return matrix
def to_data(self, node_index_by_key, mesh_index_by_key, camera_index_by_key, skin_index_by_key): """Returns a JSONable dictionary object in accordance with glTF specifications. Parameters ---------- node_index_by_key : dict mesh_index_by_key : dict camera_index_by_key : dict skin_index_by_key : dict Returns ------- dict """ node_dict = {} if self.name is not None: node_dict['name'] = self.name if self.children: node_dict['children'] = [ node_index_by_key[key] for key in self.children ] if self.matrix and self.matrix != identity_matrix(4): node_dict['matrix'] = matrix_to_col_major_order(self.matrix) else: if self.translation: node_dict['translation'] = self.translation if self.rotation: node_dict['rotation'] = self.rotation if self.scale: node_dict['scale'] = self.scale if self.mesh_key is not None: node_dict['mesh'] = mesh_index_by_key[self.mesh_key] if self._camera is not None: node_dict['camera'] = camera_index_by_key[self._camera] if self._skin is not None: node_dict['skin'] = skin_index_by_key[self._skin] if self.extras: node_dict['extras'] = self.extras if self.extensions is not None: node_dict['extensions'] = self.extensions return node_dict
def get_matrix_from_trs(self): """If the node's displacement from the origin is given by its translation, rotation and scale attributes, this method returns the matrix given by the composition of these attributes. Returns ------- """ matrix = identity_matrix(4) if self.translation: translation = matrix_from_translation(self.translation) matrix = multiply_matrices(matrix, translation) if self.rotation: rotation = matrix_from_quaternion(self.rotation) matrix = multiply_matrices(matrix, rotation) if self.scale: scale = matrix_from_scale_factors(self.scale) matrix = multiply_matrices(matrix, scale) return matrix
def test_identity_matrix(): assert identity_matrix(4) == [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]
def matrix(self): if not (self.translation or self.rotation or self.scale or self._matrix): return identity_matrix(4) return self._matrix