Skip to content
Snippets Groups Projects
export_fbx_bin.py 133 KiB
Newer Older
  • Learn to ignore specific revisions
  •         if prefix:
                fbxpath = os.path.dirname(fbxpath)
    
            if batch_mode == 'GROUP':
                data_seq = bpy.data.groups
            else:
                data_seq = bpy.data.scenes
    
            # call this function within a loop with BATCH_ENABLE == False
            # no scene switching done at the moment.
            # 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 = "_".join((prefix, bpy.path.clean_name(data.name)))
    
                if use_batch_own_dir:
                    new_fbxpath = os.path.join(fbxpath, newname)
                    # path may already exist
                    # TODO - might exist but be a file. unlikely but should probably account for it.
    
                    if not os.path.exists(new_fbxpath):
                        os.makedirs(new_fbxpath)
    
                filepath = os.path.join(new_fbxpath, newname + '.fbx')
    
                print('\nBatch exporting %s as...\n\t%r' % (data, filepath))
    
                if batch_mode == 'GROUP':  # group
                    # group, so objects update properly, add a dummy scene.
                    scene = bpy.data.scenes.new(name="FBX_Temp")
                    scene.layers = [True] * 20
                    # bpy.data.scenes.active = scene # XXX, cant switch
                    for ob_base in data.objects:
                        scene.objects.link(ob_base)
    
                    scene.update()
                    # TODO - BUMMER! Armatures not in the group wont animate the mesh
                else:
                    scene = data
    
                kwargs_batch = kwargs.copy()
                kwargs_batch["context_objects"] = data.objects
    
                save_single(operator, scene, filepath, **kwargs_batch)
    
                if batch_mode == 'GROUP':
                    # remove temp group scene
                    bpy.data.scenes.remove(scene)
    
            # no active scene changing!
            # bpy.data.scenes.active = orig_sce
    
            ret = {'FINISHED'}  # so the script wont run after we have batch exported.
    
        if context.active_object and org_mode and bpy.ops.object.mode_set.poll():
            bpy.ops.object.mode_set(mode=org_mode)
    
        return ret