Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wentww committed Dec 29, 2023
2 parents c769fe0 + d611091 commit f724394
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
14 changes: 14 additions & 0 deletions src/XRFeitoriaBpy/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,20 @@ def apply_motion_data_to_actor(motion_data: 'List[Dict[str, Dict[str, List[float
XRFeitoriaBlenderFactory.apply_motion_data_to_action(motion_data=motion_data, action=action)
XRFeitoriaBlenderFactory.apply_action_to_actor(action, actor=bpy.data.objects[actor_name])

def apply_shape_keys(shape_keys: 'List[Dict[str, float]]', actor_name: str) -> None:
"""Apply shape keys to the specified actor.
Args:
shape_keys (List[Dict[str, float]]): A list of dictionaries representing the shape keys and their values.
actor_name (str): The name of the actor object in Blender.
"""
actor = bpy.data.objects[actor_name]
for f in range(len(shape_keys)):
for key, value in shape_keys[f].items():
actor.data.shape_keys.key_blocks[key].value = value
# set keyframe
actor.data.shape_keys.key_blocks[key].keyframe_insert(data_path='value', frame=f)

#####################################
############# validate ##############
#####################################
Expand Down
34 changes: 0 additions & 34 deletions xrfeitoria/utils/anim/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,40 +387,6 @@ def from_smpl_data(
instance.smpl_data = smpl_data
return instance

@classmethod
def from_amass_data(cls, amass_data, insert_rest_pose: bool) -> Self:
"""Create a Motion instance from AMASS data (SMPL)
Args:
amass_data (dict): The AMASS data containing betas, transl, global_orient, and body_pose.
insert_rest_pose (bool): Whether to insert the rest pose into the SMPL data.
Returns:
SMPLMotion: A SMPLMotion instance containing the AMASS data.
"""
if 'mocap_framerate' in amass_data:
fps = amass_data.get('mocap_framerate')
elif 'mocap_frame_rate' in amass_data:
fps = amass_data['mocap_frame_rate']
else:
fps = 120.0

betas = amass_data['betas'][:10]
transl = amass_data['trans']
global_orient = amass_data['poses'][:, :3] # controls the global root orientation
body_pose = amass_data['poses'][:, 3:66] # controls the body
# pose_hand = amass_data['poses'][:, 66:] # controls the finger articulation
# left_hand_pose = pose_hand[:, :45]
# right_hand_pose = pose_hand[:, 45:]
# dmpls = amass_data['dmpls'][:, :8] # controls soft tissue dynamics

transl, global_orient = cls._transform_transl_global_orient(transl, global_orient)
smpl_data = {'betas': betas, 'transl': transl, 'global_orient': global_orient, 'body_pose': body_pose}
if insert_rest_pose:
smpl_data = cls._insert_rest_pose(smpl_x_data=smpl_data)

return cls.from_smpl_data(smpl_data, insert_rest_pose=False, fps=fps)

def get_bone_rotvec(self, bone_name, frame=0) -> np.ndarray:
idx = self._bone2idx(bone_name)
if idx == 0:
Expand Down
27 changes: 27 additions & 0 deletions xrfeitoria/utils/functions/blender_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ def apply_motion_data_to_actor(motion_data: 'List[Dict[str, Dict[str, List[float
XRFeitoriaBlenderFactory.apply_motion_data_to_actor(motion_data=motion_data, actor_name=actor_name)


@remote_blender()
def apply_shape_keys(shape_keys: 'List[Dict[str, float]]', actor_name: str) -> None:
"""Apply shape keys to the specified actor.
Args:
shape_keys (List[Dict[str, float]]): A list of dictionaries representing the shape keys and their values.
actor_name (str): The name of the actor object in Blender.
"""
XRFeitoriaBlenderFactory.apply_shape_keys(shape_keys=shape_keys, actor_name=actor_name)


@remote_blender()
def is_background_mode(warning: bool = False) -> bool:
"""Check whether Blender is running in background mode.
Expand Down Expand Up @@ -156,6 +167,22 @@ def set_hdr_map(hdr_map_path: 'PathLike') -> None:
XRFeitoriaBlenderFactory.set_hdr_map(scene=scene, hdr_map_path=hdr_map_path)


@remote_blender()
def set_active_level(level_name: str):
"""Sets the active level in XRFeitoria Blender Factory.
Args:
level_name (str): The name of the level to set as active. (e.g. 'Scene')
Example:
>>> import xrfeitoria as xf
>>> xf_runner = xf.init_blender()
>>> xf_runner.utils.set_active_level('Scene') # Return to default level defined by blender
"""
level = XRFeitoriaBlenderFactory.get_scene(level_name)
XRFeitoriaBlenderFactory.set_scene_active(level)


@remote_blender()
def get_frame_range() -> 'Tuple[int, int]':
"""Get the frame range of the active scene.
Expand Down

0 comments on commit f724394

Please sign in to comment.