Created
October 2, 2023 22:03
-
-
Save xDShot/2f63f9c57986073a89887c43cbd807e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
obj = bpy.context.selected_objects[0] | |
current_action = obj.id_data.animation_data.action | |
current_endframe = bpy.context.scene.frame_end | |
current_fps = bpy.context.scene.render.fps | |
remap_table = { | |
"Activate": "ex_m1911_pullout", | |
"Activate_SingleArm": "ex_m1911_dw_rh_pullout", | |
"Activate_SingleArm_L": "ex_m1911_dw_lh_pullout", | |
"Fire": "ex_m1911_fire", | |
"Fire_02": "ex_m1911_fire", | |
"Fire_Aim": "ex_m1911_fire_ads", | |
"Fire_SingleArm": "ex_m1911_dw_rh_fire", | |
"Fire_SingleArm_L": "ex_m1911_dw_lh_fire", | |
"Idle": "ex_m1911_idle", | |
"Idle_Aim": "ex_m1911_idle", | |
"Idle_SingleArm": "ex_m1911_dw_rh_idle", | |
"Idle_SingleArm_L": "ex_m1911_dw_lh_idle", | |
"Intro": "ex_m1911_first_raise", | |
"LowerLeftArm": "ex_m1911_lowerarm", | |
"Reload": "ex_m1911_reload_empty", | |
"Reload_Aim": "ex_m1911_reload_empty", | |
"Reload_Aim_Fast": "ex_m1911_reload", | |
"Reload_BigClip": "ex_m1911_reload_empty", | |
"Reload_Fast": "ex_m1911_reload", | |
"Reload_SingleArm": "ex_m1911_dw_rh_reload_empty", | |
"Reload_SingleArm_Fast": "ex_m1911_dw_rh_reload_empty", | |
"Reload_SingleArm_L": "ex_m1911_dw_lh_reload_empty", | |
"Reload_SingleArm_L_Fast": "ex_m1911_dw_lh_reload_empty", | |
"Sprint": "ex_m1911_sprint_loop", | |
"Sprint_SingleArm": "ex_m1911_dw_rh_sprint_loop", | |
"Sprint_SingleArm_L": "ex_m1911_dw_lh_sprint_loop", | |
"Sprint_WithFire": "ex_m1911_fire", | |
"Sprint_WithFire_SingleArm": "ex_m1911_dw_rh_fire", | |
"Sprint_WithFire_SingleArm_L": "ex_m1911_dw_lh_fire", | |
"Walk": "ex_m1911_walk_f", | |
"Walk_Aim": "ex_m1911_idle", | |
"Walk_SingleArm": "ex_m1911_dw_rh_walk_f", | |
"Walk_SingleArm_L": "ex_m1911_dw_lh_walk_f", | |
"FPVehicle_Activate": "ex_m1911_v_pullout", | |
"FPVehicle_Fire": "ex_m1911_v_fire", | |
"FPVehicle_Idle": "ex_m1911_v_idle", | |
"FPVehicle_IdleAim": "ex_m1911_v_idle_ads", | |
"FPVehicle_Reload": "ex_m1911_v_reload_empty" | |
} | |
secs_per_frame = { | |
"Activate": 0.011, | |
"Activate_SingleArm": 0.011, | |
"Activate_SingleArm_L": 0.011, | |
"Reload_SingleArm": 0.016, | |
"Reload_SingleArm_Fast": 0.016, | |
"Reload_SingleArm_L": 0.016, | |
"Reload_SingleArm_L_Fast": 0.016, | |
"Sprint": 0.016, | |
"Sprint_SingleArm": 0.016, | |
"Sprint_SingleArm_L": 0.016, | |
"Walk": 0.02, | |
"Walk_SingleArm": 0.02, | |
"Walk_SingleArm_L": 0.02, | |
"FPVehicle_Activate": 0.015, | |
"FPVehicle_Reload": 0.016 | |
} | |
def secs_per_frame_to_fps(num): | |
return int(1/num) | |
''' | |
fbx() | |
bpy.ops.export_scene.fbx(filepath="", | |
check_existing=True, | |
filter_glob="*.fbx", | |
use_selection=False, | |
use_visible=False, | |
use_active_collection=False, | |
global_scale=1, | |
apply_unit_scale=True, | |
apply_scale_options='FBX_SCALE_NONE', | |
use_space_transform=True, | |
bake_space_transform=False, | |
object_types={'EMPTY', 'CAMERA', 'LIGHT', 'ARMATURE', 'MESH', 'OTHER'}, | |
use_mesh_modifiers=True, | |
use_mesh_modifiers_render=True, | |
mesh_smooth_type='OFF', | |
colors_type='SRGB', | |
prioritize_active_color=False, | |
use_subsurf=False, | |
use_mesh_edges=False, | |
use_tspace=False, | |
use_triangles=False, | |
use_custom_props=False, | |
add_leaf_bones=True, | |
primary_bone_axis='Y', | |
secondary_bone_axis='X', | |
use_armature_deform_only=False, | |
armature_nodetype='NULL', | |
bake_anim=True, | |
bake_anim_use_all_bones=True, | |
bake_anim_use_nla_strips=True, | |
bake_anim_use_all_actions=True, | |
bake_anim_force_startend_keying=True, | |
bake_anim_step=1, | |
bake_anim_simplify_factor=1, | |
path_mode='AUTO', | |
embed_textures=False, | |
batch_mode='OFF', | |
use_batch_own_dir=True, | |
use_metadata=True, | |
axis_forward='-Z', | |
axis_up='Y') | |
Write a FBX file | |
''' | |
export_dir = bpy.path.abspath("//") + "eksdee/" + obj.name + "/" | |
for exportname, actionname in remap_table.items(): | |
print(exportname, actionname) | |
if not actionname in bpy.data.actions: | |
raise Exception("not found! " + actionname) | |
target_action = bpy.data.actions[actionname] | |
obj.id_data.animation_data.action = target_action | |
bpy.context.scene.frame_end = int( target_action.frame_range[1] ) | |
target_fps = 30 | |
if exportname in secs_per_frame: | |
target_fps = secs_per_frame_to_fps( secs_per_frame[exportname] ) | |
bpy.context.scene.render.fps = target_fps | |
filename = export_dir + exportname + ".fbx" | |
#with open(filename, mode='a'): pass | |
bpy.ops.export_scene.fbx(filepath = filename, object_types={'ARMATURE', 'MESH'}, global_scale=0.01, add_leaf_bones=False, bake_anim_simplify_factor=0, bake_anim_use_nla_strips=False, bake_anim_use_all_actions=False, bake_anim_force_startend_keying=False ) | |
obj.id_data.animation_data.action = current_action | |
bpy.context.scene.frame_end = current_endframe | |
bpy.context.scene.render.fps = current_fps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment