Skip to content

Commit

Permalink
rotate Z+90 and few other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpagnon committed Apr 26, 2024
1 parent cd5bc97 commit 20cbda4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
Binary file modified Pose2Sim_Blender.zip
Binary file not shown.
6 changes: 4 additions & 2 deletions Pose2Sim_Blender/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,12 @@ def setup_cams(calib_params, collection=''):

# rotation and translation
r, t = world_to_camera_persp(R[c], T[c])
t = np.array([t[1], -t[0], t[2]])
homog_matrix = np.block([[r,t.reshape(3,1)],
[np.zeros(3), 1 ]])
camera_obj.matrix_world = mathutils.Matrix(homog_matrix)
set_loc_rotation(camera_obj, np.radians([180,0,0]))
camera_obj.rotation_euler += np.radians([0, 0, -90])

# principal point # see https://blender.stackexchange.com/a/58236/174689
principal_point = K[c][0,2], K[c][1,2]
Expand Down Expand Up @@ -442,10 +444,10 @@ def show_images(camera, img_vid_path, single_image=False):
if img.data.source == 'MOVIE':
# BUG: if select single image, delete, and then reload as movie, does not update source as movie
img.image_user.frame_duration = img.data.frame_duration
img.image_user.frame_start = 0
img.image_user.frame_start = 1
elif img.data.source == 'FILE':
img.data.source = 'SEQUENCE'
img.image_user.frame_start = 0
img.image_user.frame_start = 1
else:
img.data.source = 'FILE'

Expand Down
3 changes: 2 additions & 1 deletion Pose2Sim_Blender/forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def import_forces(grf_path, direction='zup', target_framerate=30):

# create arrows
x_unit_arrow=Vector([1,0,0])
H_zup = np.array([[0,0,1,0], [1,0,0,0], [0,1,0,0], [0,0,0,1]])
# H_zup = np.array([[0,0,1,0], [1,0,0,0], [0,1,0,0], [0,0,0,1]])
H_zup = np.array([[1,0,0,0], [0,0,-1,0], [0,1,0,0], [0,0,0,1]])
for n in range(0, len(times), conv_fac_frame_rate):
for i, f in enumerate(grfNames):
T = grf_data_np[n, 1+3+9*i : 1+3+9*i+3]
Expand Down
12 changes: 9 additions & 3 deletions Pose2Sim_Blender/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ def import_trc(trc_path, direction='zup', target_framerate=30):
for n in range(0, len(times), conv_fac_frame_rate):
# y-up to z-up
if direction=='zup':
loc_x = trc_data_np[n,3*i+3]
loc_y = trc_data_np[n,3*i+1]
# loc_x = trc_data_np[n,3*i+3]
# loc_y = trc_data_np[n,3*i+1]
# loc_z = trc_data_np[n,3*i+2]
loc_x = trc_data_np[n,3*i+1]
loc_y = -trc_data_np[n,3*i+3]
loc_z = trc_data_np[n,3*i+2]
else:
loc_x = trc_data_np[n,3*i+1]
Expand All @@ -147,11 +150,14 @@ def import_trc(trc_path, direction='zup', target_framerate=30):
obj=marker_collection.objects[m]
obj.location=loc_x,loc_y,loc_z
obj.keyframe_insert('location',frame=int(n/conv_fac_frame_rate)+1)
[ob.select_set(True) for ob in marker_collection.objects]

elif trc_path.endswith('.c3d'):
bpy.ops.preferences.addon_enable(module='io_anim_c3d')
from io_anim_c3d import c3d_importer
operator = bpy.types.Operator
c3d_importer.load(operator, bpy.context, filepath = trc_path)
c3d_importer.load(operator, bpy.context, \
filepath = trc_path, \
use_manual_orientation=True, axis_forward='Y', axis_up='Z')

print(f'Marker data imported from {trc_path}')
2 changes: 2 additions & 0 deletions Pose2Sim_Blender/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def import_model(osim_path, modelRoot='',stlRoot='.',collection='', color = COLO
empties = bpy.context.selected_objects
[empt.hide_set(True) for empt in empties]

bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.layer_collection.children[collection.name]

print(f'OpenSim model imported from {osim_path}')


4 changes: 3 additions & 1 deletion Pose2Sim_Blender/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def apply_mot_to_model(mot_path, osim_path, direction='zup', target_framerate=30
# animate model
state = model.initSystem()
loc_rot_frame_all = []
H_zup = np.array([[0,0,1,0], [1,0,0,0], [0,1,0,0], [0,0,0,1]])
# H_zup = np.array([[0,0,1,0], [1,0,0,0], [0,1,0,0], [0,0,0,1]])
H_zup = np.array([[1,0,0,0], [0,0,-1,0], [0,1,0,0], [0,0,0,1]])

print('Time frame:')
for n in range(0, len(times), conv_fac_frame_rate):
print(times[n], 's')
Expand Down

0 comments on commit 20cbda4

Please sign in to comment.