Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # my original pastebin is: https://pastebin.com/B4XXey6V, I upload this again bc the original I uploaded it without an accound
- # Lopi_light
- # 16/05/2021
- import bpy
- from bpy import props, utils
- from bpy_extras.io_utils import ExportHelper
- from bpy.types import Operator, TOPBAR_MT_file_export
- from os.path import join
- ROBLOX_SCALE = 0.01 # blender scale to roblox scale
- ROBLOX_TRIS_LIMIT = 50000 # tris limit to import a fbx
- EXPORT_NAME = 'rbxmanim' # default
- EXPORT_EXT = 'fbx'
- register_class = utils.register_class
- unregister_class = utils.unregister_class
- bl_info = {
- 'author': 'Lopy',
- 'name': 'Modifiers Animation',
- 'category': 'Animation',
- 'blender': (2, 92, 0)
- }
- def clear_animation_data(object):
- object.animation_data_clear()
- try:
- object.select_set(True)
- bpy.ops.anim.clear_animation_animall() # AnimAll compatibility
- except:
- pass
- finally:
- object.select_set(False)
- def get_tris_of(object=None):
- if object is None:
- return 0
- tris = 0
- for polygon in object.evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh().polygons:
- tris += len(polygon.vertices) - 2
- return tris
- def get_total_tris_of(list=None):
- if list is None:
- return 0
- tris = 0
- for object in list:
- tris += get_tris_of(object)
- return tris
- class ExportFiles(Operator, ExportHelper):
- '''Select a file to export fbx'''
- bl_label = 'Export Animation'
- bl_idname = 'modifiers_animation.select_file'
- filename_ext = '.' + EXPORT_EXT
- directory: props.StringProperty(subtype='FILE_PATH')
- filename: props.StringProperty(options={'HIDDEN'}, subtype='FILE_NAME')
- filter_glob = props.StringProperty(default=f'*{EXPORT_EXT};', options={'HIDDEN'})
- def get_filepath(self, index):
- if index == 0:
- index = ''
- return join(self.directory, str(self.filename).replace(self.filename_ext, str(index) + self.filename_ext))
- def execute(self, context):
- to_export = [[]]
- scene = context.scene
- frame_current = scene.frame_current
- target_obj = self.target_obj
- for frame in range(scene.frame_start, scene.frame_end + 1):
- scene.frame_set(frame)
- duplicated = target_obj.copy()
- duplicated.data = target_obj.data.copy()
- duplicated.name = str(int(frame))
- scene.collection.objects.link(duplicated)
- clear_animation_data(duplicated)
- list = to_export[len(to_export) - 1]
- if get_total_tris_of(list) + get_tris_of(duplicated) > ROBLOX_TRIS_LIMIT:
- to_export.append([])
- list = to_export[len(to_export) - 1]
- list.append(duplicated)
- scene.frame_current = frame_current
- for objs in to_export:
- index = 0
- bpy.ops.object.select_all(action='DESELECT')
- if len(to_export) > 1:
- index = to_export.index(objs) + 1
- for obj in objs:
- if get_tris_of(obj) != 0:
- obj.select_set(True)
- bpy.ops.export_scene.fbx(filepath=self.get_filepath(index), use_selection=True, global_scale=ROBLOX_SCALE)
- for obj in objs:
- bpy.data.objects.remove(obj, do_unlink=True)
- target_obj.select_set(True)
- del to_export
- del scene
- del frame_current
- del target_obj
- return {'FINISHED'}
- def invoke(self, context, _):
- self.filepath = EXPORT_NAME
- self.target_obj = context.selected_objects[0]
- bpy.ops.object.select_all(action='DESELECT')
- context.window_manager.fileselect_add(self)
- return {'RUNNING_MODAL'}
- def export_option(self, _):
- self.layout.operator('modifiers_animation.select_file', text='Roblox Modifiers Animation (.fbx)')
- def register():
- register_class(ExportFiles)
- TOPBAR_MT_file_export.append(export_option)
- def unregister():
- unregister_class(ExportFiles)
- TOPBAR_MT_file_export.remove(export_option)
- if __name__ == '__main__':
- register()
Add Comment
Please, Sign In to add comment