src/bvhtoolbox/convert/bvh2csv.py
def write_joint_positions(bvh_tree, filepath, scale=1.0, end_sites=False):
    """Write joints' world positional data to a CSV file.
    
    :param bvh_tree: BVH tree that holds the data.
    :type bvh_tree: BvhTree
    :param filepath: Destination file path for CSV file.
    :type filepath: str
    :param scale: Scale factor for root position and offset values.
    :type scale: float
    :param end_sites: Include BVH End Sites in position CSV.
    :type end_sites: bool
    :return: If the write process was successful or not.
    :rtype: bool
    """
    time_col = np.arange(0, bvh_tree.nframes * bvh_tree.frame_time, bvh_tree.frame_time)[:, None]
    data_list = [time_col]
    header = ['time']
    root = next(bvh_tree.root.filter('ROOT'))
    
    def get_world_positions(joint):
        if joint.value[0] == 'End':
            joint.world_transforms = np.tile(t3d.affines.compose(np.zeros(3), np.eye(3), np.ones(3)),
                                             (bvh_tree.nframes, 1, 1))
        else:
            channels = bvh_tree.joint_channels(joint.name)
            axes_order = ''.join([ch[:1] for ch in channels if ch[1:] == 'rotation']).lower()  # FixMe: This isn't going to work when not all rotation channels are present
            axes_order = 's' + axes_order[::-1]
            joint.world_transforms = get_affines(bvh_tree, joint.name, axes=axes_order)
            
        if joint != root:
            # For joints substitute position for offsets.
            offset = [float(o) for o in joint['OFFSET']]
            joint.world_transforms[:, :3, 3] = offset
            joint.world_transforms = np.matmul(joint.parent.world_transforms, joint.world_transforms)
        if scale != 1.0:
            joint.world_transforms[:, :3, 3] *= scale
            
        header.extend(['{}.{}'.format(joint.name, channel) for channel in 'xyz'])
        pos = joint.world_transforms[:, :3, 3]
        data_list.append(pos)
        
        if end_sites:
            end = list(joint.filter('End'))
            if end:
                get_world_positions(end[0])  # There can be only one End Site per joint.
        for child in joint.filter('JOINT'):
            get_world_positions(child)
    
    get_world_positions(root)
    data = np.concatenate(data_list, axis=1)
    try:
        np.savetxt(filepath, data, header=','.join(header), fmt='%10.5f', delimiter=',', comments='')
        return True
    except IOError as e:
        print("ERROR({}): Could not write to file {}.\n"
              "Make sure you have writing permissions.\n".format(e.errno, filepath))
        return False
Write joints' world positional data to a CSV file.
    
    :param bvh_tree: BVH tree that holds the data.
    :type bvh_tree: BvhTree
    :param filepath: Destination file path for CSV file.
    :type filepath: str
    :param scale: Scale factor for root position and offset values.
    :type scale: float
    :param end_sites: Include BVH End Sites in position CSV.
    :type end_sites: bool
    :return: If the write process was successful or not.
    :rtype: bool
    
Write joints' world positional data to a CSV file.
Write joints ' world positional data to a CSV file .
def write_joint_positions(bvh_tree, filepath, scale=1.0, end_sites=False):
    time_col = np.arange(0, bvh_tree.nframes * bvh_tree.frame_time, bvh_tree.frame_time)[:, None]
    data_list = [time_col]
    header = ['time']
    root = next(bvh_tree.root.filter('ROOT'))
    def get_world_positions(joint):
        if joint.value[0] == 'End':
            joint.world_transforms = np.tile(t3d.affines.compose(np.zeros(3), np.eye(3), np.ones(3)),
                                             (bvh_tree.nframes, 1, 1))
        else:
            channels = bvh_tree.joint_channels(joint.name)
            axes_order = ''.join([ch[:1] for ch in channels if ch[1:] == 'rotation']).lower()  
            axes_order = 's' + axes_order[::-1]
            joint.world_transforms = get_affines(bvh_tree, joint.name, axes=axes_order)
        if joint != root:
            offset = [float(o) for o in joint['OFFSET']]
            joint.world_transforms[:, :3, 3] = offset
            joint.world_transforms = np.matmul(joint.parent.world_transforms, joint.world_transforms)
        if scale != 1.0:
            joint.world_transforms[:, :3, 3] *= scale
        header.extend(['{}.{}'.format(joint.name, channel) for channel in 'xyz'])
        pos = joint.world_transforms[:, :3, 3]
        data_list.append(pos)
        if end_sites:
            end = list(joint.filter('End'))
            if end:
                get_world_positions(end[0])  
        for child in joint.filter('JOINT'):
            get_world_positions(child)
    get_world_positions(root)
    data = np.concatenate(data_list, axis=1)
    try:
        np.savetxt(filepath, data, header=','.join(header), fmt='%10.5f', delimiter=',', comments='')
        return True
    except IOError as e:
        print("ERROR({}): Could not write to file {}.\n"
              "Make sure you have writing permissions.\n".format(e.errno, filepath))
        return False
def write_joint_positions ( bvh_tree , filepath , scale = 1.0 , end_sites = False ) : time_col = np . arange ( 0 , bvh_tree . nframes * bvh_tree . frame_time , bvh_tree . frame_time ) [ : , None ] data_list = [ time_col ] header = [ 'time' ] root = next ( bvh_tree . root . filter ( 'ROOT' ) ) def get_world_positions ( joint ) : if joint . value [ 0 ] == 'End' : joint . world_transforms = np . tile ( t3d . affines . compose ( np . zeros ( 3 ) , np . eye ( 3 ) , np . ones ( 3 ) ) , ( bvh_tree . nframes , 1 , 1 ) ) else : channels = bvh_tree . joint_channels ( joint . name ) axes_order = '' . join ( [ ch [ : 1 ] for ch in channels if ch [ 1 : ] == 'rotation' ] ) . lower ( ) axes_order = 's' + axes_order [ : : - 1 ] joint . world_transforms = get_affines ( bvh_tree , joint . name , axes = axes_order ) if joint != root : offset = [ float ( o ) for o in joint [ 'OFFSET' ] ] joint . world_transforms [ : , : 3 , 3 ] = offset joint . world_transforms = np . matmul ( joint . parent . world_transforms , joint . world_transforms ) if scale != 1.0 : joint . world_transforms [ : , : 3 , 3 ] *= scale header . extend ( [ '{}.{}' . format ( joint . name , channel ) for channel in 'xyz' ] ) pos = joint . world_transforms [ : , : 3 , 3 ] data_list . append ( pos ) if end_sites : end = list ( joint . filter ( 'End' ) ) if end : get_world_positions ( end [ 0 ] ) for child in joint . filter ( 'JOINT' ) : get_world_positions ( child ) get_world_positions ( root ) data = np . concatenate ( data_list , axis = 1 ) try : np . savetxt ( filepath , data , header = ',' . join ( header ) , fmt = '%10.5f' , delimiter = ',' , comments = '' ) return True except IOError as e : print ( "ERROR({}): Could not write to file {}.\n" "Make sure you have writing permissions.\n" . format ( e . errno , filepath ) ) return False
Write joints' world positional data to a CSV file.
Write joints ' world positional data to a CSV file .
"""Write joints' world positional data to a CSV file.
    
    :param bvh_tree: BVH tree that holds the data.
    :type bvh_tree: BvhTree
    :param filepath: Destination file path for CSV file.
    :type filepath: str
    :param scale: Scale factor for root position and offset values.
    :type scale: float
    :param end_sites: Include BVH End Sites in position CSV.
    :type end_sites: bool
    :return: If the write process was successful or not.
    :rtype: bool
    """ # FixMe: This isn't going to work when not all rotation channels are present # For joints substitute position for offsets. # There can be only one End Site per joint.
If the write process was successful or not.
If the write process was successful or not .
bool
bvh_tree
BVH tree that holds the data.
BVH tree that holds the data .
filepath
Destination file path for CSV file.
Destination file path for CSV file .
scale
Scale factor for root position and offset values.
Scale factor for root position and offset values .
end_sites
Include BVH End Sites in position CSV.
Include BVH End Sites in position CSV .