Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

new choose blender path system

aaroncherianaa748cccf642
diff --git a/freemocap/fmc_blender.py b/freemocap/fmc_blender.py
index 1c6fd968..16e3b287 100644
--- a/freemocap/fmc_blender.py
+++ b/freemocap/fmc_blender.py
@@ -113,7 +113,7 @@ if col:
bpy.ops.wm.save_as_mainfile(filepath= export_path + "blender_data.blend")
#export FBX
-bpy.ops.export_scene.fbx(filepath=export_path + "exported_animation_from_script.fbx", path_mode='RELATIVE', bake_anim=True, use_selection=True, object_types={'MESH'}, use_mesh_modifiers = False, add_leaf_bones = False, axis_forward = '-X', axis_up = 'Z', bake_anim_use_all_bones = False, bake_anim_use_nla_strips = False, bake_anim_use_all_actions = False, bake_anim_force_startend_keying = False)
+#bpy.ops.export_scene.fbx(filepath=export_path + "exported_animation_from_script.fbx", path_mode='RELATIVE', bake_anim=True, use_selection=True, object_types={'MESH'}, use_mesh_modifiers = False, add_leaf_bones = False, axis_forward = '-X', axis_up = 'Z', bake_anim_use_all_bones = False, bake_anim_use_nla_strips = False, bake_anim_use_all_actions = False, bake_anim_force_startend_keying = False)
#export GLTF
bpy.ops.export_scene.gltf(filepath=export_path + "exported_animation_from_script.gltf", export_format='GLTF_EMBEDDED', export_selected=True, ui_tab='ANIMATION', export_nla_strips=False)
diff --git a/freemocap/fmc_runme.py b/freemocap/fmc_runme.py
index d7e7d805..3e6197ad 100644
--- a/freemocap/fmc_runme.py
+++ b/freemocap/fmc_runme.py
@@ -53,7 +53,8 @@ def RunMe(sessionID=None,
charucoSquareSize = 36,#mm - ~the size of the squares when printed on 8.5x11" paper based on parameters in ReadMe.md
calVideoFrameLength = -1,
startFrame = 0,
- useBlender = False
+ useBlender = False,
+ resetBlenderExe = False
):
"""
Starts the freemocap pipeline based on either user-input values, or default values. Creates a new session class instance (called sesh)
@@ -93,7 +94,11 @@ def RunMe(sessionID=None,
print('Running ' + str(sesh.sessionID) + ' from ' + str(sesh.dataFolderPath))
if useBlender == True:
- blenderPath = startupGUI.RunChooseBlenderPathGUI(session)
+ here = Path(__file__).parent
+ subprocessPath = here/'fmc_blender.py'
+ blenderEXEpath = startup.get_blender_path(sesh,resetBlenderExe)
+
+
board = CharucoBoard(7, 5,
#square_length=1, # here, in mm but any unit works (JSM NOTE - just using '1' so resulting units will be in 'charuco squarelenghts`)
#marker_length=.8,
@@ -175,6 +180,15 @@ def RunMe(sessionID=None,
else:
print('Skipping Run MediaPipe')
+
+
+
+ if useBlender == True:
+ #blenderExePath = Path('C:\Program Files\Blender Foundation\Blender 2.93')
+ #os.chdir(blenderExePath)
+ output = subprocess.run([blenderEXEpath, "--background", "--python", str(subprocessPath), "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d.npy')], capture_output=True, text=True, check=True)
+ print(output)
+
# %% Stage Five - Make Skreleton Animation
if stage <= 5:
print('Starting Skeleton Plotting')
@@ -199,9 +213,6 @@ def RunMe(sessionID=None,
else:
print('Skipping Skeleton Plotting')
- if useBlender == True:
- output = subprocess.run([str(blenderPath), "--background", "--python", "fmc_blender.py", "--", str(sesh.dataArrayPath/'mediaPipeSkel_3d.npy')], capture_output=True, text=True, check=True)
- print(output)
diff --git a/freemocap/fmc_startup/startup.py b/freemocap/fmc_startup/startup.py
index 06fd5f44..367ff7f7 100644
--- a/freemocap/fmc_startup/startup.py
+++ b/freemocap/fmc_startup/startup.py
@@ -5,6 +5,10 @@ from ruamel.yaml import YAML
from freemocap import recordingconfig
from freemocap.fmc_startup import startupGUI
+import tkinter as tk
+from tkinter import filedialog
+
+
def get_user_preferences(session,stage):
"""
load user preferences if they exist, create a new preferences yaml if they don't
@@ -67,4 +71,21 @@ def get_data_folder_path(session):
if not dataFolder.exists():
raise FileNotFoundError('No data folder located at: ' + str(dataFolder))
+def get_blender_path(session, resetBlenderExe):
+ if resetBlenderExe == True:
+ print('resetting blender.exe path')
+ session.preferences['saved']['blenderEXEpath'] = None
+ if session.preferences['saved']['blenderEXEpath'] == None:
+ print('Please select your blender.exe file')
+ root = tk.Tk()
+ root.withdraw()
+ blender_file_path = filedialog.askopenfilename(title = 'Open your Blender executable')
+ print('Using blender executable located at:', blender_file_path)
+ session.preferences['saved']['blenderEXEpath'] = blender_file_path
+ session.save_user_preferences(session.preferences)
+ else:
+ blender_file_path = session.preferences['saved']['blenderEXEpath']
+ print('Using blender executable located at:', blender_file_path)
+
+ return blender_file_path
diff --git a/freemocap/recordingconfig.py b/freemocap/recordingconfig.py
index 27da486c..3bb53435 100644
--- a/freemocap/recordingconfig.py
+++ b/freemocap/recordingconfig.py
@@ -13,9 +13,9 @@ dataFolder = 'FreeMocap_Data'
folder_setup = ['RawVideos','SyncedVideos','CalVideos','DataArrays','DLCData','OpenPoseData','MediaPipeData','imOut']
-default_parameters = {'path_to_save': str(Path.cwd()),'dlc_config_paths':[], 'rotations':{},'parameters':{'exposure':-5,'resWidth':640,'resHeight':480,'framerate':25,'codec':'DIVX'}}
+default_parameters = {'path_to_save': str(Path.cwd()),'dlc_config_paths':[], 'rotations':{},'parameters':{'exposure':-5,'resWidth':640,'resHeight':480,'framerate':25,'codec':'DIVX'}, 'blenderEXEpath':None}
saved_parameters = default_parameters
-parameters_for_yaml = {'default':default_parameters,'saved':{}}
+parameters_for_yaml = {'default':default_parameters,'saved':saved_parameters}
diff --git a/freemocap/user_preferences.yaml b/freemocap/user_preferences.yaml
deleted file mode 100644
index 7cfa5882..00000000
--- a/freemocap/user_preferences.yaml
+++ /dev/null
@@ -1,22 +0,0 @@
-default:
- path_to_save: C:\
- dlc_config_paths: []
- rotations: {}
- parameters:
- exposure: -6
- resWidth: 640
- resHeight: 480
- framerate: 30
- codec: DIVX
-saved:
- path_to_save: C:/Users/jonma/Dropbox/FreeMoCapProject
- rotations:
- 0: 0
- 2: 0
- 3: 0
- parameters:
- exposure: -7
- resWidth: 640
- resHeight: 480
- framerate: 30
- codec: DIVX