python blender bvh2fbx

import os
import random
import numpy as np
import os.path
import bpy

bvh_in =r"predict.bvh"
fbx_out = r"predict.fbx"

file_name_with_extension = os.path.basename(bvh_in)
filename, file_extension = os.path.splitext(file_name_with_extension)

bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_anim.bvh(filepath=bvh_in, filter_glob="*.bvh", global_scale=1, frame_start=1, target='ARMATURE',
                        use_fps_scale=False, use_cyclic=False, rotate_mode='NATIVE', axis_forward='-Z', axis_up='Y')

assert len(bpy.data.actions) == 1
frame_range = bpy.data.actions[0].frame_range
bpy.context.scene.frame_start = int(frame_range[0])
bpy.context.scene.frame_end = int(frame_range[1])

# Add some mesh data so UE allows import
bpy.data.objects[filename].name = "animation"
bpy.ops.mesh.primitive_plane_add()
bpy.data.objects["Plane"].name = filename
bpy.data.objects["animation"].select_set(True)
bpy.ops.object.parent_set()

bpy.ops.export_scene.fbx(filepath=fbx_out, check_existing=False, global_scale=0.01)

你可能感兴趣的:(python,blender,开发语言)