![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Dudedude123 |
Im modifying this code
to retarget Mocap Online (www.mocaponline.com) animations to makehuman with this code
enum {
SOURCE_RIG_CUSTOM,
SOURCE_RIG_MOCAPONLINE,
SOURCE_RIG_RIGIFY2,
SOURCE_RIG_GENESIS3AND8,
SOURCE_RIG_3DSMAX,
SOURCE_RIG_MAKEHUMAN
}
enum {
TARGET_RIG_CUSTOM,
TARGET_RIG_RIGIFY2,
TARGET_RIG_GENESIS3AND8,
TARGET_RIG_3DSMAX,
TARGET_RIG_MAKEHUMAN
}
export(int, "custom", "mocaponline", "placeholder", "genesis3and8", "placeholder", "placeholder") var source_rig_type = SOURCE_RIG_CUSTOM setget set_source_rig_type, get_source_rig_type
export(int, "custom", "placeholder", "genesis3and8", "placeholder", "makehuman") var target_rig_type = TARGET_RIG_CUSTOM setget set_target_rig_type, get_target_rig_type
func _add_missing_bones_in_animation_track(p_new_retargeted_animation : Animation) -> void:
if not _valid_setup():
return
var retarget_skeleton_string_path : String = ""
if _source_path_animationplayer_to_skeleton != _retarget_path_animationplayer_to_skeleton:
for _track_inx in p_new_retargeted_animation.get_track_count():
retarget_skeleton_string_path = p_new_retargeted_animation.track_get_path(_track_inx)
if retarget_skeleton_string_path.begins_with(_source_path_animationplayer_to_skeleton):
retarget_skeleton_string_path = retarget_skeleton_string_path.replace(_source_path_animationplayer_to_skeleton, _retarget_path_animationplayer_to_skeleton)
var subname_count : int = p_new_retargeted_animation.track_get_path(_track_inx).get_subname_count()
if subname_count > 0:
var bone_name : String = p_new_retargeted_animation.track_get_path(_track_inx).get_subname(subname_count - 1)
if target_rig_type == TARGET_RIG_CUSTOM and not custom_bone_mapping.empty():
if bone_name in custom_bone_mapping:
var _bone_remapped : String = custom_bone_mapping.get(bone_name)
if _bone_remapped == "":
_bone_remapped = "bone_missing_mapping"
retarget_skeleton_string_path = retarget_skeleton_string_path.replace(bone_name, _bone_remapped)
p_new_retargeted_animation.track_set_path(_track_inx, NodePath(retarget_skeleton_string_path))
var bone_keys : Array = retarget_mapping.keys()
if target_rig_type == TARGET_RIG_CUSTOM and not custom_bone_mapping.empty():
bone_keys = custom_bone_mapping.values()
if target_rig_type == TARGET_RIG_GENESIS3AND8:
bone_keys = genesis3and8_bone_mapping.keys()
if target_rig_type == TARGET_RIG_MAKEHUMAN:
bone_keys = makehuman_bone_mapping.keys()
var found_bone_track : bool = false
var _searching_bone_name : String = ""
for bone_key_inx in bone_keys.size():
_searching_bone_name = bone_keys[bone_key_inx]
if _searching_bone_name == "":
continue
found_bone_track = false
for _track_inx in p_new_retargeted_animation.get_track_count():
if not p_new_retargeted_animation.track_get_type(_track_inx) == Animation.TYPE_TRANSFORM:
continue
var subname_count : int = p_new_retargeted_animation.track_get_path(_track_inx).get_subname_count()
if subname_count < 1:
continue
var bone_name : String = p_new_retargeted_animation.track_get_path(_track_inx).get_subname(subname_count - 1)
if bone_name == _searching_bone_name:
found_bone_track = true
retarget_skeleton_string_path = p_new_retargeted_animation.track_get_path(_track_inx)
if retarget_skeleton_string_path.begins_with(_source_path_animationplayer_to_skeleton):
retarget_skeleton_string_path = retarget_skeleton_string_path.replace(_source_path_animationplayer_to_skeleton, _retarget_path_animationplayer_to_skeleton)
p_new_retargeted_animation.track_set_path(_track_inx, NodePath(retarget_skeleton_string_path))
break
if not found_bone_track:
var new_track_inx : int = p_new_retargeted_animation.get_track_count() - 1
if new_track_inx > 0:
var bone_stringpath : String = _retarget_path_animationplayer_to_skeleton + ":" + _searching_bone_name
var new_animation_track_bone_nodepath : NodePath = NodePath(bone_stringpath)
var new_translation : Vector3 = Vector3(0.0, 0.0, 0.0);
var new_rotation_quat : Quat = Quat();
var new_scale : Vector3 = Vector3(1.0, 1.0, 1.0);
p_new_retargeted_animation.add_track(Animation.TYPE_TRANSFORM, new_track_inx)
p_new_retargeted_animation.track_set_path(new_track_inx, new_animation_track_bone_nodepath)
p_new_retargeted_animation.transform_track_insert_key(new_track_inx, 0.0, new_translation, new_rotation_quat, new_scale)
p_new_retargeted_animation.transform_track_insert_key(new_track_inx, p_new_retargeted_animation.get_length(), new_translation, new_rotation_quat, new_scale)
# clean old transform tracks from source skeleton
# can't delete in same loop due to index shift so one by one
var _trackpath : String = ""
var _deleting_tracks : bool = true
var _deleted_track : bool = false
while _deleting_tracks:
_deleted_track = false
for _track_inx in p_new_retargeted_animation.get_track_count():
if not p_new_retargeted_animation.track_get_type(_track_inx) == Animation.TYPE_TRANSFORM:
continue
_trackpath = p_new_retargeted_animation.track_get_path(_track_inx)
if not _trackpath.begins_with(_retarget_path_animationplayer_to_skeleton):
p_new_retargeted_animation.remove_track(_track_inx)
_deleted_track = true
break
elif "bone_missing_mapping" in _trackpath:
p_new_retargeted_animation.remove_track(_track_inx)
_deleted_track = true
break
_deleting_tracks = _deleted_track
var makehuman_bone_mapping = {
"pelvis" : "pelvis",
"abdomenLower" : "spine",
"abdomenUpper" : "spine_01",
"chestLower" : "spine_02",
"chestUpper" : "spine_03",
"neckLower" : "neck",
"head" : "head",
"lCollar" : "clavicle_l",
"lShldrBend" : "upperarm_l",
"lForearmBend" : "forearm_l",
"lHand" : "hand_l",
"rCollar" : "clavicle_r",
"rShldrBend" : "upperarm_r",
"rForearmBend" : "forearm_r",
"rHand" : "hand_r",
"lThighBend" : "thigh_l",
"lShin" : "calf_l",
"lFoot" : "foot_l",
"lToe" : "ball_l",
"rThighBend" : "thigh_r",
"rShin" : "calf_r",
"rFoot" : "foot_r",
"rToe" : "ball_r",
"lThumb1" : "thumb_01_l",
"lThumb2" : "thumb_02_l",
"lThumb3" : "thumb_03_l",
"lIndex1" : "index_01_l",
"lIndex2" : "index_02_l",
"lIndex3" : "index_03_l",
"lMid1" : "middle_01_l",
"lMid2" : "middle_02_l",
"lMid3" : "middle_03_l",
"lRing1" : "ring_01_l",
"lRing2" : "ring_02_l",
"lRing3" : "ring_03_l",
"lPinky1" : "pinky_01_l",
"lPinky2" : "pinky_02_l",
"lPinky3" : "pinky_03_l",
"rThumb1" : "thumb_01_r",
"rThumb2" : "thumb_02_r",
"rThumb3" : "thumb.03_r",
"rIndex1" : "index_01_r",
"rIndex2" : "index_02_r",
"rIndex3" : "index_03_r",
"rMid1" : "middle_01_r",
"rMid2" : "middle_02_r",
"rMid3" : "middle_03_r",
"rRing1" : "ring_01_r",
"rRing2" : "ring_02_r",
"rRing3" : "ring_03_r",
"rPinky1" : "pinky_01_r",
"rPinky2" : "pinky_02_r",
"rPinky3" : "pinky_03_r"
}
var mocaponline_bone_mapping = {
"hip" : "Hips",
"abdomenLower" : "Spine",
"abdomenUpper" : "Spine1",
"chestLower" : "Spine2",
"neckLower" : "Neck",
"head" : "Head",
"lCollar" : "LeftShoulder",
"lShldrBend" : "LeftArm",
"lForearmBend" : "LeftForeArm",
"lHand" : "LeftHand",
"rCollar" : "RightShoulder",
"rShldrBend" : "RightArm",
"rForearmBend" : "RightForeArm",
"rHand" : "RightHand",
"lThighBend" : "LeftUpLeg",
"lShin" : "LeftLeg",
"lFoot" : "LeftFoot",
"lToe" : "LeftToeBase",
"rThighBend" : "RightUpLeg",
"rShin" : "RightLeg",
"rFoot" : "RightFoot",
"rToe" : "RightToeBase",
"lThumb1" : "LeftHandThumb1",
"lThumb2" : "LeftHandThumb2",
"lThumb3" : "LeftHandThumb3",
"lIndex1" : "LeftHandIndex1",
"lIndex2" : "LeftHandIndex2",
"lIndex3" : "LeftHandIndex3",
"lMid1" : "LeftHandMiddle1",
"lMid2" : "LeftHandMiddle2",
"lMid3" : "LeftHandMiddle3",
"lRing1" : "LeftHandRing1",
"lRing2" : "LeftHandRing2",
"lRing3" : "LeftHandRing3",
"lPinky1" : "LeftHandPinky1",
"lPinky2" : "LeftHandPinky2",
"lPinky3" : "LeftHandPinky3",
"rThumb1" : "RightHandThumb1",
"rThumb2" : "RightHandIndex2",
"rThumb3" : "RightHandIndex3",
"rIndex1" : "RightHandIndex1",
"rIndex2" : "RightHandIndex2",
"rIndex3" : "RightHandIndex3",
"rMid1" : "RightHandMiddle1",
"rMid2" : "RightHandMiddle2",
"rMid3" : "RightHandMiddle3",
"rRing1" : "RightHandRing1",
"rRing2" : "RightHandRing2",
"rRing3" : "RightHandRing3",
"rPinky1" : "RightHandPinky1",
"rPinky2" : "RightHandPinky2",
"rPinky3" : "RightHandPinky3"
}
but its not working