src/bvhtoolbox/convert/bvh2xaf.py
def bvh2xaf(bvh_path, dst_path=None, scale=1.0):
    """ Converts a BVH file into the Cal3D XAF animation file format.
    When passing keyword arguments, keywords must be used!

    :param bvh_path: File path(s) for BVH source.
    :type bvh_path: str|list
    :param dst_path: File or folder path for destination Cal3D animation file (XAF).
    :type dst_path: str
    :param scale: Scale factor for root translation and offset values.
    :type scale: float
    :return: If the conversion was successful or not.
    :rtype: bool
    """
    with open(bvh_path) as file_handle:
        mocap = BvhTree(file_handle.read())
    
    duration = (mocap.nframes - 1) * mocap.frame_time
    joint_names = mocap.get_joints_names()
    n_tracks = len(joint_names)
    
    xml_root = XmlTree.Element("ANIMATION")
    xml_root.set('VERSION', '1100')
    xml_root.set('MAGIC', 'XAF')
    xml_root.set('DURATION', str(duration))
    xml_root.set('NUMTRACKS', str(n_tracks))
    comment = XmlTree.Comment('Converted from {}'.format(os.path.basename(bvh_path)))
    xml_root.append(comment)
    # Use map to compute tracks.
    tracks = list(map(get_track, itertools.repeat(mocap), joint_names, itertools.repeat(scale)))
    # Extend tracks to xml_root as children.
    xml_root.extend(tracks)
    # Add indentation.
    xml_str = prettify(xml_root)
    
    if not dst_path:
        dst_path = bvh_path[:-3] + 'xaf'
        
    if os.path.isdir(dst_path):
        dst_path = os.path.join(dst_path, os.path.basename(bvh_path)[:-3] + 'xaf')
        
    try:
        with open(dst_path, 'w') as file_handle:
            file_handle.write(xml_str)
        return True
    except IOError as e:
        print("ERROR({}): Could not write to file {}.\n"
              "Make sure you have writing permissions.\n".format(e.errno, dst_path))
        return False
 Converts a BVH file into the Cal3D XAF animation file format.
    When passing keyword arguments, keywords must be used!

    :param bvh_path: File path(s) for BVH source.
    :type bvh_path: str|list
    :param dst_path: File or folder path for destination Cal3D animation file (XAF).
    :type dst_path: str
    :param scale: Scale factor for root translation and offset values.
    :type scale: float
    :return: If the conversion was successful or not.
    :rtype: bool
    
Converts a BVH file into the Cal3D XAF animation file format.
When passing keyword arguments, keywords must be used!
Converts a BVH file into the Cal3D XAF animation file format . When passing keyword arguments keywords must be used!
def bvh2xaf(bvh_path, dst_path=None, scale=1.0):
    with open(bvh_path) as file_handle:
        mocap = BvhTree(file_handle.read())
    duration = (mocap.nframes - 1) * mocap.frame_time
    joint_names = mocap.get_joints_names()
    n_tracks = len(joint_names)
    xml_root = XmlTree.Element("ANIMATION")
    xml_root.set('VERSION', '1100')
    xml_root.set('MAGIC', 'XAF')
    xml_root.set('DURATION', str(duration))
    xml_root.set('NUMTRACKS', str(n_tracks))
    comment = XmlTree.Comment('Converted from {}'.format(os.path.basename(bvh_path)))
    xml_root.append(comment)
    tracks = list(map(get_track, itertools.repeat(mocap), joint_names, itertools.repeat(scale)))
    xml_root.extend(tracks)
    xml_str = prettify(xml_root)
    if not dst_path:
        dst_path = bvh_path[:-3] + 'xaf'
    if os.path.isdir(dst_path):
        dst_path = os.path.join(dst_path, os.path.basename(bvh_path)[:-3] + 'xaf')
    try:
        with open(dst_path, 'w') as file_handle:
            file_handle.write(xml_str)
        return True
    except IOError as e:
        print("ERROR({}): Could not write to file {}.\n"
              "Make sure you have writing permissions.\n".format(e.errno, dst_path))
        return False
def bvh2xaf ( bvh_path , dst_path = None , scale = 1.0 ) : with open ( bvh_path ) as file_handle : mocap = BvhTree ( file_handle . read ( ) ) duration = ( mocap . nframes - 1 ) * mocap . frame_time joint_names = mocap . get_joints_names ( ) n_tracks = len ( joint_names ) xml_root = XmlTree . Element ( "ANIMATION" ) xml_root . set ( 'VERSION' , '1100' ) xml_root . set ( 'MAGIC' , 'XAF' ) xml_root . set ( 'DURATION' , str ( duration ) ) xml_root . set ( 'NUMTRACKS' , str ( n_tracks ) ) comment = XmlTree . Comment ( 'Converted from {}' . format ( os . path . basename ( bvh_path ) ) ) xml_root . append ( comment ) tracks = list ( map ( get_track , itertools . repeat ( mocap ) , joint_names , itertools . repeat ( scale ) ) ) xml_root . extend ( tracks ) xml_str = prettify ( xml_root ) if not dst_path : dst_path = bvh_path [ : - 3 ] + 'xaf' if os . path . isdir ( dst_path ) : dst_path = os . path . join ( dst_path , os . path . basename ( bvh_path ) [ : - 3 ] + 'xaf' ) try : with open ( dst_path , 'w' ) as file_handle : file_handle . write ( xml_str ) return True except IOError as e : print ( "ERROR({}): Could not write to file {}.\n" "Make sure you have writing permissions.\n" . format ( e . errno , dst_path ) ) return False
Converts a BVH file into the Cal3D XAF animation file format.
Converts a BVH file into the Cal3D XAF animation file format .
""" Converts a BVH file into the Cal3D XAF animation file format.
    When passing keyword arguments, keywords must be used!

    :param bvh_path: File path(s) for BVH source.
    :type bvh_path: str|list
    :param dst_path: File or folder path for destination Cal3D animation file (XAF).
    :type dst_path: str
    :param scale: Scale factor for root translation and offset values.
    :type scale: float
    :return: If the conversion was successful or not.
    :rtype: bool
    """ # Use map to compute tracks. # Extend tracks to xml_root as children. # Add indentation.
If the conversion was successful or not.
If the conversion was successful or not .
bool
bvh_path
File path(s) for BVH source.
File path ( s ) for BVH source .
dst_path
File or folder path for destination Cal3D animation file (XAF).
File or folder path for destination Cal3D animation file ( XAF ) .
scale
Scale factor for root translation and offset values.
Scale factor for root translation and offset values .