|
import sys, os, logging |
|
import pyfbsdk |
|
|
|
|
|
|
|
my_env = 'C:/Users/94086/.conda/envs/zeggs/Lib/site-packages' |
|
sys.path.append(my_env) |
|
|
|
|
|
|
|
|
|
logging.basicConfig( |
|
filename="compile_results.log", |
|
filemode="w", |
|
format="%(asctime)s %(levelname)-8s %(message)s", |
|
level=logging.DEBUG, |
|
) |
|
|
|
console = logging.StreamHandler() |
|
console.setLevel(logging.DEBUG) |
|
console.setFormatter(logging.Formatter("%(asctime)s %(levelname)-8s %(message)s")) |
|
logging.getLogger("").addHandler(console) |
|
|
|
|
|
def bvh2fbx(animation_file, output_file, template_file, sound_file=None): |
|
|
|
pyfbsdk.FBApplication().FileNew() |
|
logging.info("Loading %s..." % str(template_file)) |
|
|
|
if not pyfbsdk.FBApplication().FileOpen(str(template_file)): |
|
raise IOError("Could not open file: {}".format(str(template_file))) |
|
|
|
if sound_file is not None: |
|
|
|
logging.info("Loading %s..." % str(sound_file)) |
|
audio = pyfbsdk.FBAudioClip(sound_file) |
|
if audio is None: |
|
raise IOError("Could not open file: {}".format(str(sound_file))) |
|
|
|
|
|
pyfbsdk.FBSystem().CurrentTake.LocalTimeSpan = pyfbsdk.FBTimeSpan( |
|
pyfbsdk.FBTime(0), audio.Duration |
|
) |
|
|
|
|
|
pyfbsdk.FBPlayerControl().SetTransportFps(pyfbsdk.FBTimeMode.kFBTimeMode60Frames) |
|
pyfbsdk.FBPlayerControl().SnapMode = ( |
|
pyfbsdk.FBTransportSnapMode.kFBTransportSnapModeSnapOnFrames |
|
) |
|
|
|
|
|
if not pyfbsdk.FBApplication().FileImport(animation_file, True): |
|
raise IOError("Could not open file: {}".format(str(animation_file))) |
|
|
|
|
|
pyfbsdk.FBApplication().FileSave(output_file) |
|
|
|
|
|
if True: |
|
try: |
|
|
|
logging.info("======") |
|
logging.info("BVH2FBX") |
|
logging.info("======") |
|
|
|
results_path = "./Rendered" |
|
template_file = "./LaForgeFemale.fbx" |
|
|
|
|
|
for animation_file in [f for f in os.listdir(results_path) if f.endswith(".bvh")]: |
|
sound_file = animation_file.replace(".bvh", ".wav") |
|
sound_file = results_path + "/" + sound_file |
|
if not os.path.exists(sound_file): |
|
sound_file = None |
|
bvh2fbx( |
|
results_path + "/" + animation_file, |
|
results_path + "/" + animation_file.replace(".bvh", ".fbx"), |
|
template_file, |
|
sound_file |
|
) |
|
|
|
pyfbsdk.FBApplication().FileExit() |
|
|
|
except Exception as e: |
|
logging.exception("FAILED:") |
|
raise e |
|
|