-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add position track normalization & post process key value for retarget
- Loading branch information
1 parent
6d57e20
commit dde235a
Showing
18 changed files
with
580 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
editor/import/post_import_plugin_skeleton_track_organizer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/*************************************************************************/ | ||
/* post_import_plugin_skeleton_track_organizer.cpp */ | ||
/*************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/*************************************************************************/ | ||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ | ||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/*************************************************************************/ | ||
|
||
#include "post_import_plugin_skeleton_track_organizer.h" | ||
|
||
#include "editor/import/scene_import_settings.h" | ||
#include "scene/3d/skeleton_3d.h" | ||
#include "scene/animation/animation_player.h" | ||
#include "scene/resources/bone_map.h" | ||
|
||
void PostImportPluginSkeletonTrackOrganizer::get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options) { | ||
if (p_category == INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE) { | ||
r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/remove_tracks/unimportant_positions"), true)); | ||
r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/remove_tracks/unmapped_bones"), false)); | ||
} | ||
} | ||
|
||
void PostImportPluginSkeletonTrackOrganizer::internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options) { | ||
if (p_category == INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE) { | ||
// Prepare objects. | ||
Object *map = p_options["retarget/bone_map"].get_validated_object(); | ||
if (!map) { | ||
return; | ||
} | ||
BoneMap *bone_map = Object::cast_to<BoneMap>(map); | ||
Ref<SkeletonProfile> profile = bone_map->get_profile(); | ||
if (!profile.is_valid()) { | ||
return; | ||
} | ||
Skeleton3D *src_skeleton = Object::cast_to<Skeleton3D>(p_node); | ||
if (!src_skeleton) { | ||
return; | ||
} | ||
bool remove_positions = bool(p_options["retarget/remove_tracks/unimportant_positions"]); | ||
bool remove_unmapped_bones = bool(p_options["retarget/remove_tracks/unmapped_bones"]); | ||
|
||
if (!remove_positions && !remove_unmapped_bones) { | ||
return; | ||
} | ||
|
||
TypedArray<Node> nodes = p_base_scene->find_children("*", "AnimationPlayer"); | ||
while (nodes.size()) { | ||
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(nodes.pop_back()); | ||
List<StringName> anims; | ||
ap->get_animation_list(&anims); | ||
for (const StringName &name : anims) { | ||
Ref<Animation> anim = ap->get_animation(name); | ||
int track_len = anim->get_track_count(); | ||
Vector<int> remove_indices; | ||
for (int i = 0; i < track_len; i++) { | ||
if (anim->track_get_path(i).get_subname_count() != 1 || !(anim->track_get_type(i) == Animation::TYPE_POSITION_3D || anim->track_get_type(i) == Animation::TYPE_ROTATION_3D || anim->track_get_type(i) == Animation::TYPE_SCALE_3D)) { | ||
continue; | ||
} | ||
|
||
String track_path = String(anim->track_get_path(i).get_concatenated_names()); | ||
Node *node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path)); | ||
if (node) { | ||
Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node); | ||
if (track_skeleton && track_skeleton == src_skeleton) { | ||
StringName bn = anim->track_get_path(i).get_subname(0); | ||
if (bn) { | ||
int prof_idx = profile->find_bone(bone_map->find_profile_bone_name(bn)); | ||
if (remove_unmapped_bones && prof_idx < 0) { | ||
remove_indices.push_back(i); | ||
continue; | ||
} | ||
if (remove_positions && anim->track_get_type(i) == Animation::TYPE_POSITION_3D && prof_idx >= 0) { | ||
StringName prof_bn = profile->get_bone_name(prof_idx); | ||
if (prof_bn == profile->get_root_bone() || prof_bn == profile->get_scale_base_bone()) { | ||
continue; | ||
} | ||
remove_indices.push_back(i); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
remove_indices.reverse(); | ||
for (int i = 0; i < remove_indices.size(); i++) { | ||
anim->remove_track(remove_indices[i]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
PostImportPluginSkeletonTrackOrganizer::PostImportPluginSkeletonTrackOrganizer() { | ||
} |
46 changes: 46 additions & 0 deletions
46
editor/import/post_import_plugin_skeleton_track_organizer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*************************************************************************/ | ||
/* post_import_plugin_skeleton_track_organizer.h */ | ||
/*************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/*************************************************************************/ | ||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ | ||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/*************************************************************************/ | ||
|
||
#ifndef POST_IMPORT_PLUGIN_SKELETON_TRACK_ORGANIZER_H | ||
#define POST_IMPORT_PLUGIN_SKELETON_TRACK_ORGANIZER_H | ||
|
||
#include "resource_importer_scene.h" | ||
|
||
class PostImportPluginSkeletonTrackOrganizer : public EditorScenePostImportPlugin { | ||
GDCLASS(PostImportPluginSkeletonTrackOrganizer, EditorScenePostImportPlugin); | ||
|
||
public: | ||
virtual void get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options) override; | ||
virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options) override; | ||
|
||
PostImportPluginSkeletonTrackOrganizer(); | ||
}; | ||
|
||
#endif // POST_IMPORT_PLUGIN_SKELETON_TRACK_ORGANIZER_H |
Oops, something went wrong.