Skip to content
Snippets Groups Projects
export_fbx.py 114 KiB
Newer Older
  • Learn to ignore specific revisions
  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    # ##### BEGIN GPL LICENSE BLOCK #####
    #
    #  This program is free software; you can redistribute it and/or
    #  modify it under the terms of the GNU General Public License
    #  as published by the Free Software Foundation; either version 2
    #  of the License, or (at your option) any later version.
    #
    #  This program is distributed in the hope that it will be useful,
    #  but WITHOUT ANY WARRANTY; without even the implied warranty of
    #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #  GNU General Public License for more details.
    #
    #  You should have received a copy of the GNU General Public License
    #  along with this program; if not, write to the Free Software Foundation,
    #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    #
    # ##### END GPL LICENSE BLOCK #####
    
    # <pep8 compliant>
    
    # Script copyright (C) Campbell Barton
    
    """
    This script is an exporter to the FBX file format.
    
    http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_fbx
    """
    
    import os
    import time
    import math  # math.pi
    import shutil  # for file copying
    
    import bpy
    from mathutils import Vector, Euler, Matrix
    
    
    # XXX not used anymore, images are copied one at a time
    def copy_images(dest_dir, textures):
        import shutil
    
        if not dest_dir.endswith(os.sep):
            dest_dir += os.sep
    
        image_paths = set()
        for tex in textures:
            image_paths.add(bpy.path.abspath(tex.filepath))
    
        # Now copy images
        copyCount = 0
        for image_path in image_paths:
            if Blender.sys.exists(image_path):
                # Make a name for the target path.
                dest_image_path = dest_dir + image_path.split('\\')[-1].split('/')[-1]
                if not Blender.sys.exists(dest_image_path):  # Image isnt already there
                    print("\tCopying %r > %r" % (image_path, dest_image_path))
                    try:
                        shutil.copy(image_path, dest_image_path)
                        copyCount += 1
                    except:
                        print("\t\tWarning, file failed to copy, skipping.")
    
        print('\tCopied %d images' % copyCount)
    
    
    # I guess FBX uses degrees instead of radians (Arystan).
    # Call this function just before writing to FBX.
    # 180 / math.pi == 57.295779513
    def tuple_rad_to_deg(eul):
        return eul[0] * 57.295779513, eul[1] * 57.295779513, eul[2] * 57.295779513
    
    # def strip_path(p):
    # 	return p.split('\\')[-1].split('/')[-1]
    
    # Used to add the scene name into the filepath without using odd chars
    sane_name_mapping_ob = {}
    sane_name_mapping_mat = {}
    sane_name_mapping_tex = {}
    sane_name_mapping_take = {}
    sane_name_mapping_group = {}
    
    # Make sure reserved names are not used
    sane_name_mapping_ob['Scene'] = 'Scene_'
    sane_name_mapping_ob['blend_root'] = 'blend_root_'
    
    
    def increment_string(t):
        name = t
        num = ''
        while name and name[-1].isdigit():
            num = name[-1] + num
            name = name[:-1]
        if num:
            return '%s%d' % (name, int(num) + 1)
        else:
            return name + '_0'
    
    
    # todo - Disallow the name 'Scene' and 'blend_root' - it will bugger things up.
    def sane_name(data, dct):
        #if not data: return None
    
        if type(data) == tuple:  # materials are paired up with images
            data, other = data
            use_other = True
        else:
            other = None
            use_other = False
    
        name = data.name if data else None
        orig_name = name
    
        if other:
            orig_name_other = other.name
            name = '%s #%s' % (name, orig_name_other)
        else:
            orig_name_other = None
    
        # dont cache, only ever call once for each data type now,
        # so as to avoid namespace collision between types - like with objects <-> bones
        #try:		return dct[name]
        #except:		pass
    
        if not name:
            name = 'unnamed'  # blank string, ASKING FOR TROUBLE!
        else:
    
            name = bpy.path.clean_name(name)  # use our own
    
        while name in iter(dct.values()):
            name = increment_string(name)
    
        if use_other:  # even if other is None - orig_name_other will be a string or None
            dct[orig_name, orig_name_other] = name
        else:
            dct[orig_name] = name
    
        return name
    
    
    def sane_obname(data):
        return sane_name(data, sane_name_mapping_ob)
    
    
    def sane_matname(data):
        return sane_name(data, sane_name_mapping_mat)
    
    
    def sane_texname(data):
        return sane_name(data, sane_name_mapping_tex)
    
    
    def sane_takename(data):
        return sane_name(data, sane_name_mapping_take)
    
    
    def sane_groupname(data):
        return sane_name(data, sane_name_mapping_group)
    
    # def derived_paths(fname_orig, basepath, FORCE_CWD=False):
    # 	'''
    # 	fname_orig - blender path, can be relative
    # 	basepath - fname_rel will be relative to this
    # 	FORCE_CWD - dont use the basepath, just add a ./ to the filepath.
    # 		use when we know the file will be in the basepath.
    # 	'''
    # 	fname = bpy.path.abspath(fname_orig)
    # # 	fname = Blender.sys.expandpath(fname_orig)
    # 	fname_strip = os.path.basename(fname)
    # # 	fname_strip = strip_path(fname)
    # 	if FORCE_CWD:
    # 		fname_rel = '.' + os.sep + fname_strip
    # 	else:
    # 		fname_rel = bpy.path.relpath(fname, basepath)
    # # 		fname_rel = Blender.sys.relpath(fname, basepath)
    # 	if fname_rel.startswith('//'): fname_rel = '.' + os.sep + fname_rel[2:]
    # 	return fname, fname_strip, fname_rel
    
    
    def mat4x4str(mat):
        return '%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f' % tuple([f for v in mat for f in v])
    
    
    # XXX not used
    # duplicated in OBJ exporter
    def getVertsFromGroup(me, group_index):
        ret = []
    
        for i, v in enumerate(me.vertices):
            for g in v.groups:
                if g.group == group_index:
                    ret.append((i, g.weight))
    
            return ret
    
    
    # ob must be OB_MESH
    def BPyMesh_meshWeight2List(ob, me):
        ''' Takes a mesh and return its group names and a list of lists, one list per vertex.
        aligning the each vert list with the group names, each list contains float value for the weight.
        These 2 lists can be modified and then used with list2MeshWeight to apply the changes.
        '''
    
        # Clear the vert group.
        groupNames = [g.name for g in ob.vertex_groups]
        len_groupNames = len(groupNames)
    
        if not len_groupNames:
            # no verts? return a vert aligned empty list
            return [[] for i in range(len(me.vertices))], []
        else:
            vWeightList = [[0.0] * len_groupNames for i in range(len(me.vertices))]
    
        for i, v in enumerate(me.vertices):
            for g in v.groups:
                vWeightList[i][g.group] = g.weight
    
        return groupNames, vWeightList
    
    
    def meshNormalizedWeights(ob, me):
        try:  # account for old bad BPyMesh
            groupNames, vWeightList = BPyMesh_meshWeight2List(ob, me)
        except:
            return [], []
    
        if not groupNames:
            return [], []
    
        for i, vWeights in enumerate(vWeightList):
            tot = 0.0
            for w in vWeights:
                tot += w
    
            if tot:
                for j, w in enumerate(vWeights):
                    vWeights[j] = w / tot
    
        return groupNames, vWeightList
    
    header_comment = \
    '''; FBX 6.1.0 project file
    ; Created by Blender FBX Exporter
    ; for support mail: ideasman42@gmail.com
    ; ----------------------------------------------------
    
    '''
    
    
    # This func can be called with just the filepath
    def save(operator, context, filepath="",
            GLOBAL_MATRIX=None,
            EXP_OBS_SELECTED=True,
            EXP_MESH=True,
            EXP_MESH_APPLY_MOD=True,
            EXP_ARMATURE=True,
            EXP_LAMP=True,
            EXP_CAMERA=True,
            EXP_EMPTY=True,
            EXP_IMAGE_COPY=False,
            ANIM_ENABLE=True,
            ANIM_OPTIMIZE=True,
            ANIM_OPTIMIZE_PRECISSION=6,
            ANIM_ACTION_ALL=False,
            BATCH_ENABLE=False,
            BATCH_GROUP=True,
            BATCH_FILE_PREFIX='',
            BATCH_OWN_DIR=False
        ):
    
        #XXX, missing arg
        batch_objects = None
    
        # testing
        mtx_x90 = Matrix.Rotation(math.pi / 2.0, 3, 'X')  # used
        mtx4_z90 = Matrix.Rotation(math.pi / 2.0, 4, 'Z')
    
        if GLOBAL_MATRIX is None:
            GLOBAL_MATRIX = Matrix()
    
        if bpy.ops.object.mode_set.poll():
            bpy.ops.object.mode_set(mode='OBJECT')
    
        # ----------------- Batch support!
        if BATCH_ENABLE:
            fbxpath = filepath
    
            # get the path component of filepath
            tmp_exists = bpy.utils.exists(fbxpath)
    
            if tmp_exists != 2:  # a file, we want a path
                fbxpath = os.path.dirname(fbxpath)
    # 			while fbxpath and fbxpath[-1] not in ('/', '\\'):
    # 				fbxpath = fbxpath[:-1]
                if not fbxpath:
                    # XXX
                    print('Error%t|Directory does not exist!')
    # 				Draw.PupMenu('Error%t|Directory does not exist!')
                    return
    
                tmp_exists = bpy.utils.exists(fbxpath)
    
            if tmp_exists != 2:
                # XXX
                print('Error%t|Directory does not exist!')
    # 			Draw.PupMenu('Error%t|Directory does not exist!')
                return
    
            if not fbxpath.endswith(os.sep):
                fbxpath += os.sep
            del tmp_exists
    
            if BATCH_GROUP:
                data_seq = bpy.data.groups
            else:
                data_seq = bpy.data.scenes
    
            # call this function within a loop with BATCH_ENABLE == False
            orig_sce = context.scene
    
            new_fbxpath = fbxpath  # own dir option modifies, we need to keep an original
            for data in data_seq:  # scene or group
                newname = BATCH_FILE_PREFIX + bpy.path.clean_name(data.name)
    
                if BATCH_OWN_DIR:
                    new_fbxpath = fbxpath + newname + os.sep
                    # path may already exist
                    # TODO - might exist but be a file. unlikely but should probably account for it.
    
                    if bpy.utils.exists(new_fbxpath) == 0:
    # 				if Blender.sys.exists(new_fbxpath) == 0:
                        os.mkdir(new_fbxpath)
    
                filepath = new_fbxpath + newname + '.fbx'
    
                print('\nBatch exporting %s as...\n\t%r' % (data, filepath))
    
                # XXX don't know what to do with this, probably do the same? (Arystan)
                if BATCH_GROUP:  # group
                    # group, so objects update properly, add a dummy scene.
                    scene = bpy.data.scenes.new()
                    scene.Layers = (1 << 20) - 1
                    bpy.data.scenes.active = scene
                    for ob_base in data.objects:
                        scene.objects.link(ob_base)
    
                    scene.update(1)
    
                    # TODO - BUMMER! Armatures not in the group wont animate the mesh
    
                else:  # scene
                    data_seq.active = data
    
                # Call self with modified args
                # Dont pass batch options since we already usedt them
                write(filepath, data.objects,
                    context,
                    False,
                    EXP_MESH,
                    EXP_MESH_APPLY_MOD,
                    EXP_ARMATURE,
                    EXP_LAMP,
                    EXP_CAMERA,
                    EXP_EMPTY,
                    EXP_IMAGE_COPY,
                    GLOBAL_MATRIX,
                    ANIM_ENABLE,
                    ANIM_OPTIMIZE,
                    ANIM_OPTIMIZE_PRECISSION,
                    ANIM_ACTION_ALL
                )
    
                if BATCH_GROUP:
                    # remove temp group scene
                    bpy.data.scenes.unlink(scene)
    
            bpy.data.scenes.active = orig_sce
    
            return  # so the script wont run after we have batch exported.
    
        # end batch support
    
        # Use this for working out paths relative to the export location
        basepath = os.path.dirname(filepath) or '.'
        basepath += os.sep
    # 	basepath = Blender.sys.dirname(filepath)
    
        # ----------------------------------------------
        # storage classes
        class my_bone_class(object):
            __slots__ = ("blenName",
                         "blenBone",
                         "blenMeshes",
                         "restMatrix",
                         "parent",
                         "blenName",
                         "fbxName",
                         "fbxArm",
                         "__pose_bone",
                         "__anim_poselist")
    
            def __init__(self, blenBone, fbxArm):
    
                # This is so 2 armatures dont have naming conflicts since FBX bones use object namespace
                self.fbxName = sane_obname(blenBone)
    
                self.blenName = blenBone.name
                self.blenBone = blenBone
                self.blenMeshes = {}					# fbxMeshObName : mesh
                self.fbxArm = fbxArm
                self.restMatrix = blenBone.matrix_local
    # 			self.restMatrix =		blenBone.matrix['ARMATURESPACE']
    
                # not used yet
                # self.restMatrixInv =	self.restMatrix.copy().invert()
                # self.restMatrixLocal =	None # set later, need parent matrix
    
                self.parent = None
    
                # not public
                pose = fbxArm.blenObject.pose
                self.__pose_bone = pose.bones[self.blenName]
    
                # store a list if matricies here, (poseMatrix, head, tail)
                # {frame:posematrix, frame:posematrix, ...}
                self.__anim_poselist = {}
    
            '''
            def calcRestMatrixLocal(self):
                if self.parent:
                    self.restMatrixLocal = self.restMatrix * self.parent.restMatrix.copy().invert()
                else:
                    self.restMatrixLocal = self.restMatrix.copy()
            '''
            def setPoseFrame(self, f):
                # cache pose info here, frame must be set beforehand
    
                # Didnt end up needing head or tail, if we do - here it is.
                '''
                self.__anim_poselist[f] = (\
                    self.__pose_bone.poseMatrix.copy(),\
                    self.__pose_bone.head.copy(),\
                    self.__pose_bone.tail.copy() )
                '''
    
                self.__anim_poselist[f] = self.__pose_bone.matrix.copy()
    
            # get pose from frame.
            def getPoseMatrix(self, f):  # ----------------------------------------------
                return self.__anim_poselist[f]
            '''
            def getPoseHead(self, f):
                #return self.__pose_bone.head.copy()
                return self.__anim_poselist[f][1].copy()
            def getPoseTail(self, f):
                #return self.__pose_bone.tail.copy()
                return self.__anim_poselist[f][2].copy()
            '''
            # end
    
            def getAnimParRelMatrix(self, frame):
                #arm_mat = self.fbxArm.matrixWorld
                #arm_mat = self.fbxArm.parRelMatrix()
                if not self.parent:
                    #return mtx4_z90 * (self.getPoseMatrix(frame) * arm_mat) # dont apply arm matrix anymore
                    return self.getPoseMatrix(frame) * mtx4_z90
                else:
                    #return (mtx4_z90 * ((self.getPoseMatrix(frame) * arm_mat)))  *  (mtx4_z90 * (self.parent.getPoseMatrix(frame) * arm_mat)).invert()
                    return (self.parent.getPoseMatrix(frame) * mtx4_z90).invert() * ((self.getPoseMatrix(frame)) * mtx4_z90)
    
            # we need thes because cameras and lights modified rotations
            def getAnimParRelMatrixRot(self, frame):
                return self.getAnimParRelMatrix(frame)
    
            def flushAnimData(self):
                self.__anim_poselist.clear()
    
        class my_object_generic(object):
            __slots__ = ("fbxName",
                         "blenObject",
                         "blenData",
                         "origData",
                         "blenTextures",
                         "blenMaterials",
                         "blenMaterialList",
                         "blenAction",
                         "blenActionList",
                         "fbxGroupNames",
                         "fbxParent",
                         "fbxBoneParent",
                         "fbxBones",
                         "fbxArm",
                         "matrixWorld",
                         "__anim_poselist",
                         )
    
            # Other settings can be applied for each type - mesh, armature etc.
            def __init__(self, ob, matrixWorld=None):
                self.fbxName = sane_obname(ob)
                self.blenObject = ob
                self.fbxGroupNames = []
                self.fbxParent = None  # set later on IF the parent is in the selection.
                if matrixWorld:
                    self.matrixWorld = GLOBAL_MATRIX * matrixWorld
                else:
                    self.matrixWorld = GLOBAL_MATRIX * ob.matrix_world
    
                self.__anim_poselist = {}  # we should only access this
    
            def parRelMatrix(self):
                if self.fbxParent:
                    return self.fbxParent.matrixWorld.copy().invert() * self.matrixWorld
                else:
                    return self.matrixWorld
    
            def setPoseFrame(self, f, fake=False):
                if fake:
                    # annoying, have to clear GLOBAL_MATRIX
                    self.__anim_poselist[f] = self.matrixWorld * GLOBAL_MATRIX.copy().invert()
                else:
                    self.__anim_poselist[f] = self.blenObject.matrix_world.copy()
    
            def getAnimParRelMatrix(self, frame):
                if self.fbxParent:
                    #return (self.__anim_poselist[frame] * self.fbxParent.__anim_poselist[frame].copy().invert() ) * GLOBAL_MATRIX
                    return (GLOBAL_MATRIX * self.fbxParent.__anim_poselist[frame]).invert() * (GLOBAL_MATRIX * self.__anim_poselist[frame])
                else:
                    return GLOBAL_MATRIX * self.__anim_poselist[frame]
    
            def getAnimParRelMatrixRot(self, frame):
                obj_type = self.blenObject.type
                if self.fbxParent:
                    matrix_rot = ((GLOBAL_MATRIX * self.fbxParent.__anim_poselist[frame]).invert() * (GLOBAL_MATRIX * self.__anim_poselist[frame])).rotation_part()
                else:
                    matrix_rot = (GLOBAL_MATRIX * self.__anim_poselist[frame]).rotation_part()
    
                # Lamps need to be rotated
                if obj_type == 'LAMP':
                    matrix_rot = matrix_rot * mtx_x90
                elif obj_type == 'CAMERA':
                    y = Vector((0.0, 1.0, 0.0)) * matrix_rot
                    matrix_rot = Matrix.Rotation(math.pi / 2.0, 3, y) * matrix_rot
    
                return matrix_rot
    
        # ----------------------------------------------
    
        print('\nFBX export starting... %r' % filepath)
        start_time = time.clock()
        try:
            file = open(filepath, 'w', encoding='utf8')
        except:
            return False
    
        scene = context.scene
        world = scene.world
    
        # ---------------------------- Write the header first
        file.write(header_comment)
        if time:
            curtime = time.localtime()[0:6]
        else:
            curtime = (0, 0, 0, 0, 0, 0)
        #
        file.write(\
    '''FBXHeaderExtension:  {
        FBXHeaderVersion: 1003
        FBXVersion: 6100
        CreationTimeStamp:  {
            Version: 1000
            Year: %.4i
            Month: %.2i
            Day: %.2i
            Hour: %.2i
            Minute: %.2i
            Second: %.2i
            Millisecond: 0
        }
        Creator: "FBX SDK/FBX Plugins build 20070228"
        OtherFlags:  {
            FlagPLE: 0
        }
    }''' % (curtime))
    
        file.write('\nCreationTime: "%.4i-%.2i-%.2i %.2i:%.2i:%.2i:000"' % curtime)
        file.write('\nCreator: "Blender version %s"' % bpy.app.version_string)
    
        pose_items = []  # list of (fbxName, matrix) to write pose data for, easier to collect allong the way
    
        # --------------- funcs for exporting
        def object_tx(ob, loc, matrix, matrix_mod=None):
            '''
            Matrix mod is so armature objects can modify their bone matricies
            '''
            if isinstance(ob, bpy.types.Bone):
    # 		if isinstance(ob, Blender.Types.BoneType):
    
                # we know we have a matrix
                # matrix = mtx4_z90 * (ob.matrix['ARMATURESPACE'] * matrix_mod)
                matrix = ob.matrix_local * mtx4_z90  # dont apply armature matrix anymore
    # 			matrix = mtx4_z90 * ob.matrix['ARMATURESPACE'] # dont apply armature matrix anymore
    
                parent = ob.parent
                if parent:
                    #par_matrix = mtx4_z90 * (parent.matrix['ARMATURESPACE'] * matrix_mod)
                    par_matrix = parent.matrix_local * mtx4_z90  # dont apply armature matrix anymore
    # 				par_matrix = mtx4_z90 * parent.matrix['ARMATURESPACE'] # dont apply armature matrix anymore
                    matrix = par_matrix.copy().invert() * matrix
    
                loc, rot, scale = matrix.decompose()
                matrix_rot = rot.to_matrix()
    
                loc = tuple(loc)
                rot = tuple(rot.to_euler())  # quat -> euler
                scale = tuple(scale)
            else:
                # This is bad because we need the parent relative matrix from the fbx parent (if we have one), dont use anymore
                #if ob and not matrix: matrix = ob.matrix_world * GLOBAL_MATRIX
                if ob and not matrix:
                    raise Exception("error: this should never happen!")
    
                matrix_rot = matrix
                #if matrix:
                #	matrix = matrix_scale * matrix
    
                if matrix:
                    loc, rot, scale = matrix.decompose()
                    matrix_rot = rot.to_matrix()
    
                    # Lamps need to be rotated
                    if ob and ob.type == 'LAMP':
                        matrix_rot = matrix_rot * mtx_x90
                    elif ob and ob.type == 'CAMERA':
                        y = Vector((0.0, 1.0, 0.0)) * matrix_rot
                        matrix_rot = Matrix.Rotation(math.pi / 2.0, 3, y) * matrix_rot
                    # else do nothing.
    
                    loc = tuple(loc)
                    rot = tuple(matrix_rot.to_euler())
                    scale = tuple(scale)
                else:
                    if not loc:
                        loc = 0.0, 0.0, 0.0
                    scale = 1.0, 1.0, 1.0
                    rot = 0.0, 0.0, 0.0
    
            return loc, rot, scale, matrix, matrix_rot
    
        def write_object_tx(ob, loc, matrix, matrix_mod=None):
            '''
            We have loc to set the location if non blender objects that have a location
    
            matrix_mod is only used for bones at the moment
            '''
            loc, rot, scale, matrix, matrix_rot = object_tx(ob, loc, matrix, matrix_mod)
    
            file.write('\n\t\t\tProperty: "Lcl Translation", "Lcl Translation", "A+",%.15f,%.15f,%.15f' % loc)
            file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % tuple_rad_to_deg(rot))
    # 		file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % rot)
            file.write('\n\t\t\tProperty: "Lcl Scaling", "Lcl Scaling", "A+",%.15f,%.15f,%.15f' % scale)
            return loc, rot, scale, matrix, matrix_rot
    
        def write_object_props(ob=None, loc=None, matrix=None, matrix_mod=None):
            # if the type is 0 its an empty otherwise its a mesh
            # only difference at the moment is one has a color
            file.write('''
            Properties60:  {
                Property: "QuaternionInterpolate", "bool", "",0
                Property: "Visibility", "Visibility", "A+",1''')
    
            loc, rot, scale, matrix, matrix_rot = write_object_tx(ob, loc, matrix, matrix_mod)
    
            # Rotation order, note, for FBX files Iv loaded normal order is 1
            # setting to zero.
            # eEULER_XYZ = 0
            # eEULER_XZY
            # eEULER_YZX
            # eEULER_YXZ
            # eEULER_ZXY
            # eEULER_ZYX
    
            file.write('''
                Property: "RotationOffset", "Vector3D", "",0,0,0
                Property: "RotationPivot", "Vector3D", "",0,0,0
                Property: "ScalingOffset", "Vector3D", "",0,0,0
                Property: "ScalingPivot", "Vector3D", "",0,0,0
                Property: "TranslationActive", "bool", "",0
                Property: "TranslationMin", "Vector3D", "",0,0,0
                Property: "TranslationMax", "Vector3D", "",0,0,0
                Property: "TranslationMinX", "bool", "",0
                Property: "TranslationMinY", "bool", "",0
                Property: "TranslationMinZ", "bool", "",0
                Property: "TranslationMaxX", "bool", "",0
                Property: "TranslationMaxY", "bool", "",0
                Property: "TranslationMaxZ", "bool", "",0
                Property: "RotationOrder", "enum", "",0
                Property: "RotationSpaceForLimitOnly", "bool", "",0
                Property: "AxisLen", "double", "",10
                Property: "PreRotation", "Vector3D", "",0,0,0
                Property: "PostRotation", "Vector3D", "",0,0,0
                Property: "RotationActive", "bool", "",0
                Property: "RotationMin", "Vector3D", "",0,0,0
                Property: "RotationMax", "Vector3D", "",0,0,0
                Property: "RotationMinX", "bool", "",0
                Property: "RotationMinY", "bool", "",0
                Property: "RotationMinZ", "bool", "",0
                Property: "RotationMaxX", "bool", "",0
                Property: "RotationMaxY", "bool", "",0
                Property: "RotationMaxZ", "bool", "",0
                Property: "RotationStiffnessX", "double", "",0
                Property: "RotationStiffnessY", "double", "",0
                Property: "RotationStiffnessZ", "double", "",0
                Property: "MinDampRangeX", "double", "",0
                Property: "MinDampRangeY", "double", "",0
                Property: "MinDampRangeZ", "double", "",0
                Property: "MaxDampRangeX", "double", "",0
                Property: "MaxDampRangeY", "double", "",0
                Property: "MaxDampRangeZ", "double", "",0
                Property: "MinDampStrengthX", "double", "",0
                Property: "MinDampStrengthY", "double", "",0
                Property: "MinDampStrengthZ", "double", "",0
                Property: "MaxDampStrengthX", "double", "",0
                Property: "MaxDampStrengthY", "double", "",0
                Property: "MaxDampStrengthZ", "double", "",0
                Property: "PreferedAngleX", "double", "",0
                Property: "PreferedAngleY", "double", "",0
                Property: "PreferedAngleZ", "double", "",0
                Property: "InheritType", "enum", "",0
                Property: "ScalingActive", "bool", "",0
                Property: "ScalingMin", "Vector3D", "",1,1,1
                Property: "ScalingMax", "Vector3D", "",1,1,1
                Property: "ScalingMinX", "bool", "",0
                Property: "ScalingMinY", "bool", "",0
                Property: "ScalingMinZ", "bool", "",0
                Property: "ScalingMaxX", "bool", "",0
                Property: "ScalingMaxY", "bool", "",0
                Property: "ScalingMaxZ", "bool", "",0
                Property: "GeometricTranslation", "Vector3D", "",0,0,0
                Property: "GeometricRotation", "Vector3D", "",0,0,0
                Property: "GeometricScaling", "Vector3D", "",1,1,1
                Property: "LookAtProperty", "object", ""
                Property: "UpVectorProperty", "object", ""
                Property: "Show", "bool", "",1
                Property: "NegativePercentShapeSupport", "bool", "",1
                Property: "DefaultAttributeIndex", "int", "",0''')
            if ob and not isinstance(ob, bpy.types.Bone):
                # Only mesh objects have color
                file.write('\n\t\t\tProperty: "Color", "Color", "A",0.8,0.8,0.8')
                file.write('\n\t\t\tProperty: "Size", "double", "",100')
                file.write('\n\t\t\tProperty: "Look", "enum", "",1')
    
            return loc, rot, scale, matrix, matrix_rot
    
        # -------------------------------------------- Armatures
        #def write_bone(bone, name, matrix_mod):
        def write_bone(my_bone):
            file.write('\n\tModel: "Model::%s", "Limb" {' % my_bone.fbxName)
            file.write('\n\t\tVersion: 232')
    
            #poseMatrix = write_object_props(my_bone.blenBone, None, None, my_bone.fbxArm.parRelMatrix())[3]
            poseMatrix = write_object_props(my_bone.blenBone)[3]  # dont apply bone matricies anymore
            pose_items.append((my_bone.fbxName, poseMatrix))
    
            # file.write('\n\t\t\tProperty: "Size", "double", "",%.6f' % ((my_bone.blenData.head['ARMATURESPACE'] - my_bone.blenData.tail['ARMATURESPACE']) * my_bone.fbxArm.parRelMatrix()).length)
            file.write('\n\t\t\tProperty: "Size", "double", "",1')
    
            #((my_bone.blenData.head['ARMATURESPACE'] * my_bone.fbxArm.matrixWorld) - (my_bone.blenData.tail['ARMATURESPACE'] * my_bone.fbxArm.parRelMatrix())).length)
    
            """
            file.write('\n\t\t\tProperty: "LimbLength", "double", "",%.6f' %\
                ((my_bone.blenBone.head['ARMATURESPACE'] - my_bone.blenBone.tail['ARMATURESPACE']) * my_bone.fbxArm.parRelMatrix()).length)
            """
    
            file.write('\n\t\t\tProperty: "LimbLength", "double", "",%.6f' %
                       (my_bone.blenBone.head_local - my_bone.blenBone.tail_local).length)
    # 			(my_bone.blenBone.head['ARMATURESPACE'] - my_bone.blenBone.tail['ARMATURESPACE']).length)
    
            #file.write('\n\t\t\tProperty: "LimbLength", "double", "",1')
            file.write('\n\t\t\tProperty: "Color", "ColorRGB", "",0.8,0.8,0.8')
            file.write('\n\t\t\tProperty: "Color", "Color", "A",0.8,0.8,0.8')
            file.write('\n\t\t}')
            file.write('\n\t\tMultiLayer: 0')
            file.write('\n\t\tMultiTake: 1')
            file.write('\n\t\tShading: Y')
            file.write('\n\t\tCulling: "CullingOff"')
            file.write('\n\t\tTypeFlags: "Skeleton"')
            file.write('\n\t}')
    
        def write_camera_switch():
            file.write('''
        Model: "Model::Camera Switcher", "CameraSwitcher" {
            Version: 232''')
    
            write_object_props()
            file.write('''
                Property: "Color", "Color", "A",0.8,0.8,0.8
                Property: "Camera Index", "Integer", "A+",100
            }
            MultiLayer: 0
            MultiTake: 1
            Hidden: "True"
            Shading: W
            Culling: "CullingOff"
            Version: 101
            Name: "Model::Camera Switcher"
            CameraId: 0
            CameraName: 100
            CameraIndexName:
        }''')
    
        def write_camera_dummy(name, loc, near, far, proj_type, up):
            file.write('\n\tModel: "Model::%s", "Camera" {' % name)
            file.write('\n\t\tVersion: 232')
            write_object_props(None, loc)
    
            file.write('\n\t\t\tProperty: "Color", "Color", "A",0.8,0.8,0.8')
            file.write('\n\t\t\tProperty: "Roll", "Roll", "A+",0')
            file.write('\n\t\t\tProperty: "FieldOfView", "FieldOfView", "A+",40')
            file.write('\n\t\t\tProperty: "FieldOfViewX", "FieldOfView", "A+",1')
            file.write('\n\t\t\tProperty: "FieldOfViewY", "FieldOfView", "A+",1')
            file.write('\n\t\t\tProperty: "OpticalCenterX", "Real", "A+",0')
            file.write('\n\t\t\tProperty: "OpticalCenterY", "Real", "A+",0')
            file.write('\n\t\t\tProperty: "BackgroundColor", "Color", "A+",0.63,0.63,0.63')
            file.write('\n\t\t\tProperty: "TurnTable", "Real", "A+",0')
            file.write('\n\t\t\tProperty: "DisplayTurnTableIcon", "bool", "",1')
            file.write('\n\t\t\tProperty: "Motion Blur Intensity", "Real", "A+",1')
            file.write('\n\t\t\tProperty: "UseMotionBlur", "bool", "",0')
            file.write('\n\t\t\tProperty: "UseRealTimeMotionBlur", "bool", "",1')
            file.write('\n\t\t\tProperty: "ResolutionMode", "enum", "",0')
            file.write('\n\t\t\tProperty: "ApertureMode", "enum", "",2')
            file.write('\n\t\t\tProperty: "GateFit", "enum", "",0')
            file.write('\n\t\t\tProperty: "FocalLength", "Real", "A+",21.3544940948486')
            file.write('\n\t\t\tProperty: "CameraFormat", "enum", "",0')
            file.write('\n\t\t\tProperty: "AspectW", "double", "",320')
            file.write('\n\t\t\tProperty: "AspectH", "double", "",200')
            file.write('\n\t\t\tProperty: "PixelAspectRatio", "double", "",1')
            file.write('\n\t\t\tProperty: "UseFrameColor", "bool", "",0')
            file.write('\n\t\t\tProperty: "FrameColor", "ColorRGB", "",0.3,0.3,0.3')
            file.write('\n\t\t\tProperty: "ShowName", "bool", "",1')
            file.write('\n\t\t\tProperty: "ShowGrid", "bool", "",1')
            file.write('\n\t\t\tProperty: "ShowOpticalCenter", "bool", "",0')
            file.write('\n\t\t\tProperty: "ShowAzimut", "bool", "",1')
            file.write('\n\t\t\tProperty: "ShowTimeCode", "bool", "",0')
            file.write('\n\t\t\tProperty: "NearPlane", "double", "",%.6f' % near)
            file.write('\n\t\t\tProperty: "FarPlane", "double", "",%.6f' % far)
            file.write('\n\t\t\tProperty: "FilmWidth", "double", "",0.816')
            file.write('\n\t\t\tProperty: "FilmHeight", "double", "",0.612')
            file.write('\n\t\t\tProperty: "FilmAspectRatio", "double", "",1.33333333333333')
            file.write('\n\t\t\tProperty: "FilmSqueezeRatio", "double", "",1')
            file.write('\n\t\t\tProperty: "FilmFormatIndex", "enum", "",4')
            file.write('\n\t\t\tProperty: "ViewFrustum", "bool", "",1')
            file.write('\n\t\t\tProperty: "ViewFrustumNearFarPlane", "bool", "",0')
            file.write('\n\t\t\tProperty: "ViewFrustumBackPlaneMode", "enum", "",2')
            file.write('\n\t\t\tProperty: "BackPlaneDistance", "double", "",100')
            file.write('\n\t\t\tProperty: "BackPlaneDistanceMode", "enum", "",0')
            file.write('\n\t\t\tProperty: "ViewCameraToLookAt", "bool", "",1')
            file.write('\n\t\t\tProperty: "LockMode", "bool", "",0')
            file.write('\n\t\t\tProperty: "LockInterestNavigation", "bool", "",0')
            file.write('\n\t\t\tProperty: "FitImage", "bool", "",0')
            file.write('\n\t\t\tProperty: "Crop", "bool", "",0')
            file.write('\n\t\t\tProperty: "Center", "bool", "",1')
            file.write('\n\t\t\tProperty: "KeepRatio", "bool", "",1')
            file.write('\n\t\t\tProperty: "BackgroundMode", "enum", "",0')
            file.write('\n\t\t\tProperty: "BackgroundAlphaTreshold", "double", "",0.5')
            file.write('\n\t\t\tProperty: "ForegroundTransparent", "bool", "",1')
            file.write('\n\t\t\tProperty: "DisplaySafeArea", "bool", "",0')
            file.write('\n\t\t\tProperty: "SafeAreaDisplayStyle", "enum", "",1')
            file.write('\n\t\t\tProperty: "SafeAreaAspectRatio", "double", "",1.33333333333333')
            file.write('\n\t\t\tProperty: "Use2DMagnifierZoom", "bool", "",0')
            file.write('\n\t\t\tProperty: "2D Magnifier Zoom", "Real", "A+",100')
            file.write('\n\t\t\tProperty: "2D Magnifier X", "Real", "A+",50')
            file.write('\n\t\t\tProperty: "2D Magnifier Y", "Real", "A+",50')
            file.write('\n\t\t\tProperty: "CameraProjectionType", "enum", "",%i' % proj_type)
            file.write('\n\t\t\tProperty: "UseRealTimeDOFAndAA", "bool", "",0')
            file.write('\n\t\t\tProperty: "UseDepthOfField", "bool", "",0')
            file.write('\n\t\t\tProperty: "FocusSource", "enum", "",0')
            file.write('\n\t\t\tProperty: "FocusAngle", "double", "",3.5')
            file.write('\n\t\t\tProperty: "FocusDistance", "double", "",200')
            file.write('\n\t\t\tProperty: "UseAntialiasing", "bool", "",0')
            file.write('\n\t\t\tProperty: "AntialiasingIntensity", "double", "",0.77777')
            file.write('\n\t\t\tProperty: "UseAccumulationBuffer", "bool", "",0')
            file.write('\n\t\t\tProperty: "FrameSamplingCount", "int", "",7')
            file.write('\n\t\t}')
            file.write('\n\t\tMultiLayer: 0')
            file.write('\n\t\tMultiTake: 0')
            file.write('\n\t\tHidden: "True"')
            file.write('\n\t\tShading: Y')
            file.write('\n\t\tCulling: "CullingOff"')
            file.write('\n\t\tTypeFlags: "Camera"')
            file.write('\n\t\tGeometryVersion: 124')
            file.write('\n\t\tPosition: %.6f,%.6f,%.6f' % loc)
            file.write('\n\t\tUp: %i,%i,%i' % up)
            file.write('\n\t\tLookAt: 0,0,0')
            file.write('\n\t\tShowInfoOnMoving: 1')
            file.write('\n\t\tShowAudio: 0')
            file.write('\n\t\tAudioColor: 0,1,0')
            file.write('\n\t\tCameraOrthoZoom: 1')
            file.write('\n\t}')
    
        def write_camera_default():
            # This sucks but to match FBX converter its easier to
            # write the cameras though they are not needed.
            write_camera_dummy('Producer Perspective', (0, 71.3, 287.5), 10, 4000, 0, (0, 1, 0))
            write_camera_dummy('Producer Top', (0, 4000, 0), 1, 30000, 1, (0, 0, -1))
            write_camera_dummy('Producer Bottom', (0, -4000, 0), 1, 30000, 1, (0, 0, -1))
            write_camera_dummy('Producer Front', (0, 0, 4000), 1, 30000, 1, (0, 1, 0))
            write_camera_dummy('Producer Back', (0, 0, -4000), 1, 30000, 1, (0, 1, 0))
            write_camera_dummy('Producer Right', (4000, 0, 0), 1, 30000, 1, (0, 1, 0))
            write_camera_dummy('Producer Left', (-4000, 0, 0), 1, 30000, 1, (0, 1, 0))
    
        def write_camera(my_cam):
            '''
            Write a blender camera
            '''
            render = scene.render
            width = render.resolution_x
            height = render.resolution_y
            aspect = width / height
    
            data = my_cam.blenObject.data
    
            file.write('\n\tModel: "Model::%s", "Camera" {' % my_cam.fbxName)
            file.write('\n\t\tVersion: 232')
            loc, rot, scale, matrix, matrix_rot = write_object_props(my_cam.blenObject, None, my_cam.parRelMatrix())
    
            file.write('\n\t\t\tProperty: "Roll", "Roll", "A+",0')
            file.write('\n\t\t\tProperty: "FieldOfView", "FieldOfView", "A+",%.6f' % math.degrees(data.angle))
            file.write('\n\t\t\tProperty: "FieldOfViewX", "FieldOfView", "A+",1')
            file.write('\n\t\t\tProperty: "FieldOfViewY", "FieldOfView", "A+",1')
            # file.write('\n\t\t\tProperty: "FocalLength", "Real", "A+",14.0323972702026')
            file.write('\n\t\t\tProperty: "OpticalCenterX", "Real", "A+",%.6f' % data.shift_x)  # not sure if this is in the correct units?
            file.write('\n\t\t\tProperty: "OpticalCenterY", "Real", "A+",%.6f' % data.shift_y)  # ditto
            file.write('\n\t\t\tProperty: "BackgroundColor", "Color", "A+",0,0,0')
            file.write('\n\t\t\tProperty: "TurnTable", "Real", "A+",0')
            file.write('\n\t\t\tProperty: "DisplayTurnTableIcon", "bool", "",1')
            file.write('\n\t\t\tProperty: "Motion Blur Intensity", "Real", "A+",1')
            file.write('\n\t\t\tProperty: "UseMotionBlur", "bool", "",0')
            file.write('\n\t\t\tProperty: "UseRealTimeMotionBlur", "bool", "",1')
            file.write('\n\t\t\tProperty: "ResolutionMode", "enum", "",0')
            file.write('\n\t\t\tProperty: "ApertureMode", "enum", "",2')
            file.write('\n\t\t\tProperty: "GateFit", "enum", "",2')
            file.write('\n\t\t\tProperty: "CameraFormat", "enum", "",0')
            file.write('\n\t\t\tProperty: "AspectW", "double", "",%i' % width)
            file.write('\n\t\t\tProperty: "AspectH", "double", "",%i' % height)
    
            '''Camera aspect ratio modes.
                0 If the ratio mode is eWINDOW_SIZE, both width and height values aren't relevant.
                1 If the ratio mode is eFIXED_RATIO, the height value is set to 1.0 and the width value is relative to the height value.
                2 If the ratio mode is eFIXED_RESOLUTION, both width and height values are in pixels.
                3 If the ratio mode is eFIXED_WIDTH, the width value is in pixels and the height value is relative to the width value.
                4 If the ratio mode is eFIXED_HEIGHT, the height value is in pixels and the width value is relative to the height value.
    
            Definition at line 234 of file kfbxcamera.h. '''
    
            file.write('\n\t\t\tProperty: "PixelAspectRatio", "double", "",2')
    
            file.write('\n\t\t\tProperty: "UseFrameColor", "bool", "",0')
            file.write('\n\t\t\tProperty: "FrameColor", "ColorRGB", "",0.3,0.3,0.3')
            file.write('\n\t\t\tProperty: "ShowName", "bool", "",1')
            file.write('\n\t\t\tProperty: "ShowGrid", "bool", "",1')
            file.write('\n\t\t\tProperty: "ShowOpticalCenter", "bool", "",0')
            file.write('\n\t\t\tProperty: "ShowAzimut", "bool", "",1')
            file.write('\n\t\t\tProperty: "ShowTimeCode", "bool", "",0')
            file.write('\n\t\t\tProperty: "NearPlane", "double", "",%.6f' % data.clip_start)
            file.write('\n\t\t\tProperty: "FarPlane", "double", "",%.6f' % data.clip_end)
            file.write('\n\t\t\tProperty: "FilmWidth", "double", "",1.0')
            file.write('\n\t\t\tProperty: "FilmHeight", "double", "",1.0')
            file.write('\n\t\t\tProperty: "FilmAspectRatio", "double", "",%.6f' % aspect)
            file.write('\n\t\t\tProperty: "FilmSqueezeRatio", "double", "",1')
            file.write('\n\t\t\tProperty: "FilmFormatIndex", "enum", "",0')
            file.write('\n\t\t\tProperty: "ViewFrustum", "bool", "",1')
            file.write('\n\t\t\tProperty: "ViewFrustumNearFarPlane", "bool", "",0')
            file.write('\n\t\t\tProperty: "ViewFrustumBackPlaneMode", "enum", "",2')
            file.write('\n\t\t\tProperty: "BackPlaneDistance", "double", "",100')
            file.write('\n\t\t\tProperty: "BackPlaneDistanceMode", "enum", "",0')
            file.write('\n\t\t\tProperty: "ViewCameraToLookAt", "bool", "",1')
            file.write('\n\t\t\tProperty: "LockMode", "bool", "",0')
            file.write('\n\t\t\tProperty: "LockInterestNavigation", "bool", "",0')
            file.write('\n\t\t\tProperty: "FitImage", "bool", "",0')
            file.write('\n\t\t\tProperty: "Crop", "bool", "",0')
            file.write('\n\t\t\tProperty: "Center", "bool", "",1')
            file.write('\n\t\t\tProperty: "KeepRatio", "bool", "",1')
            file.write('\n\t\t\tProperty: "BackgroundMode", "enum", "",0')
            file.write('\n\t\t\tProperty: "BackgroundAlphaTreshold", "double", "",0.5')
            file.write('\n\t\t\tProperty: "ForegroundTransparent", "bool", "",1')
            file.write('\n\t\t\tProperty: "DisplaySafeArea", "bool", "",0')
            file.write('\n\t\t\tProperty: "SafeAreaDisplayStyle", "enum", "",1')
            file.write('\n\t\t\tProperty: "SafeAreaAspectRatio", "double", "",%.6f' % aspect)
            file.write('\n\t\t\tProperty: "Use2DMagnifierZoom", "bool", "",0')
            file.write('\n\t\t\tProperty: "2D Magnifier Zoom", "Real", "A+",100')
            file.write('\n\t\t\tProperty: "2D Magnifier X", "Real", "A+",50')
            file.write('\n\t\t\tProperty: "2D Magnifier Y", "Real", "A+",50')
            file.write('\n\t\t\tProperty: "CameraProjectionType", "enum", "",0')
            file.write('\n\t\t\tProperty: "UseRealTimeDOFAndAA", "bool", "",0')
            file.write('\n\t\t\tProperty: "UseDepthOfField", "bool", "",0')
            file.write('\n\t\t\tProperty: "FocusSource", "enum", "",0')
            file.write('\n\t\t\tProperty: "FocusAngle", "double", "",3.5')
            file.write('\n\t\t\tProperty: "FocusDistance", "double", "",200')
            file.write('\n\t\t\tProperty: "UseAntialiasing", "bool", "",0')
            file.write('\n\t\t\tProperty: "AntialiasingIntensity", "double", "",0.77777')