diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 88dacfd84..949c0c556 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -144,7 +144,6 @@ #include "editor/plugins/script_text_editor.h" #include "editor/plugins/shader_editor_plugin.h" #include "editor/plugins/skeleton_2d_editor_plugin.h" -#include "editor/plugins/skeleton_editor_plugin.h" #include "editor/plugins/skeleton_ik_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h" #include "editor/plugins/sprite_editor_plugin.h" @@ -6944,7 +6943,6 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(TextureEditorPlugin(this))); add_editor_plugin(memnew(AudioStreamEditorPlugin(this))); add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor))); - add_editor_plugin(memnew(SkeletonEditorPlugin(this))); add_editor_plugin(memnew(SkeletonIKEditorPlugin(this))); add_editor_plugin(memnew(PhysicalBonePlugin(this))); add_editor_plugin(memnew(MeshEditorPlugin(this))); diff --git a/editor/plugins/skeleton_editor_plugin.cpp b/editor/plugins/skeleton_editor_plugin.cpp deleted file mode 100644 index acf421e31..000000000 --- a/editor/plugins/skeleton_editor_plugin.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/*************************************************************************/ -/* skeleton_editor_plugin.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 "skeleton_editor_plugin.h" - -#include "scene/3d/collision_shape.h" -#include "scene/3d/physics_body.h" -#include "scene/3d/physics_joint.h" -#include "scene/resources/capsule_shape.h" -#include "scene/resources/sphere_shape.h" -#include "spatial_editor_plugin.h" - -void SkeletonEditor::_on_click_option(int p_option) { - if (!skeleton) { - return; - } - - switch (p_option) { - case MENU_OPTION_CREATE_PHYSICAL_SKELETON: { - create_physical_skeleton(); - } break; - } -} - -void SkeletonEditor::create_physical_skeleton() { - UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - Node *owner = skeleton == get_tree()->get_edited_scene_root() ? skeleton : skeleton->get_owner(); - - const int bc = skeleton->get_bone_count(); - - if (!bc) { - return; - } - - Vector bones_infos; - bones_infos.resize(bc); - - for (int bone_id = 0; bc > bone_id; ++bone_id) { - const int parent = skeleton->get_bone_parent(bone_id); - - if (parent < 0) { - bones_infos.write[bone_id].relative_rest = skeleton->get_bone_rest(bone_id); - - } else { - const int parent_parent = skeleton->get_bone_parent(parent); - - bones_infos.write[bone_id].relative_rest = bones_infos[parent].relative_rest * skeleton->get_bone_rest(bone_id); - - /// create physical bone on parent - if (!bones_infos[parent].physical_bone) { - bones_infos.write[parent].physical_bone = create_physical_bone(parent, bone_id, bones_infos); - - ur->create_action(TTR("Create physical bones"), UndoRedo::MERGE_ALL); - ur->add_do_method(skeleton, "add_child", bones_infos[parent].physical_bone); - ur->add_do_reference(bones_infos[parent].physical_bone); - ur->add_undo_method(skeleton, "remove_child", bones_infos[parent].physical_bone); - ur->commit_action(); - - bones_infos[parent].physical_bone->set_bone_name(skeleton->get_bone_name(parent)); - bones_infos[parent].physical_bone->set_owner(owner); - bones_infos[parent].physical_bone->get_child(0)->set_owner(owner); // set shape owner - - /// Create joint between parent of parent - if (-1 != parent_parent) { - bones_infos[parent].physical_bone->set_joint_type(PhysicalBone::JOINT_TYPE_PIN); - } - } - } - } -} - -PhysicalBone *SkeletonEditor::create_physical_bone(int bone_id, int bone_child_id, const Vector &bones_infos) { - real_t half_height(skeleton->get_bone_rest(bone_child_id).origin.length() * 0.5); - real_t radius(half_height * 0.2); - - CapsuleShape *bone_shape_capsule = memnew(CapsuleShape); - bone_shape_capsule->set_height((half_height - radius) * 2); - bone_shape_capsule->set_radius(radius); - - CollisionShape *bone_shape = memnew(CollisionShape); - bone_shape->set_shape(bone_shape_capsule); - - Transform capsule_transform; - capsule_transform.basis = Basis(Vector3(1, 0, 0), Vector3(0, 0, 1), Vector3(0, -1, 0)); - bone_shape->set_transform(capsule_transform); - - Transform body_transform; - body_transform.origin = Vector3(0, 0, -half_height); - - Transform joint_transform; - joint_transform.origin = Vector3(0, 0, half_height); - - PhysicalBone *physical_bone = memnew(PhysicalBone); - physical_bone->add_child(bone_shape); - physical_bone->set_name("Physical Bone " + skeleton->get_bone_name(bone_id)); - physical_bone->set_body_offset(body_transform); - physical_bone->set_joint_offset(joint_transform); - return physical_bone; -} - -void SkeletonEditor::edit(Skeleton *p_node) { - skeleton = p_node; -} - -void SkeletonEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - get_tree()->connect("node_removed", this, "_node_removed"); - } -} - -void SkeletonEditor::_node_removed(Node *p_node) { - if (p_node == skeleton) { - skeleton = nullptr; - options->hide(); - } -} - -void SkeletonEditor::_bind_methods() { - ClassDB::bind_method("_on_click_option", &SkeletonEditor::_on_click_option); - ClassDB::bind_method("_node_removed", &SkeletonEditor::_node_removed); -} - -SkeletonEditor::SkeletonEditor() { - skeleton = nullptr; - options = memnew(MenuButton); - SpatialEditor::get_singleton()->add_control_to_menu_panel(options); - - options->set_text(TTR("Skeleton")); - options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Skeleton", "EditorIcons")); - - options->get_popup()->add_item(TTR("Create physical skeleton"), MENU_OPTION_CREATE_PHYSICAL_SKELETON); - - options->get_popup()->connect("id_pressed", this, "_on_click_option"); - options->hide(); -} - -SkeletonEditor::~SkeletonEditor() {} - -void SkeletonEditorPlugin::edit(Object *p_object) { - skeleton_editor->edit(Object::cast_to(p_object)); -} - -bool SkeletonEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Skeleton"); -} - -void SkeletonEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - skeleton_editor->options->show(); - } else { - skeleton_editor->options->hide(); - skeleton_editor->edit(nullptr); - } -} - -SkeletonEditorPlugin::SkeletonEditorPlugin(EditorNode *p_node) { - editor = p_node; - skeleton_editor = memnew(SkeletonEditor); - editor->get_viewport()->add_child(skeleton_editor); -} - -SkeletonEditorPlugin::~SkeletonEditorPlugin() {} diff --git a/editor/plugins/skeleton_editor_plugin.h b/editor/plugins/skeleton_editor_plugin.h deleted file mode 100644 index e73e1ee13..000000000 --- a/editor/plugins/skeleton_editor_plugin.h +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************/ -/* skeleton_editor_plugin.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 SKELETON_EDITOR_PLUGIN_H -#define SKELETON_EDITOR_PLUGIN_H - -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "scene/3d/skeleton.h" - -class PhysicalBone; -class Joint; - -class SkeletonEditor : public Node { - GDCLASS(SkeletonEditor, Node); - - enum Menu { - MENU_OPTION_CREATE_PHYSICAL_SKELETON - }; - - struct BoneInfo { - PhysicalBone *physical_bone; - Transform relative_rest; // Relative to skeleton node - BoneInfo() : - physical_bone(nullptr) {} - }; - - Skeleton *skeleton; - - MenuButton *options; - - void _on_click_option(int p_option); - - friend class SkeletonEditorPlugin; - -protected: - void _notification(int p_what); - void _node_removed(Node *p_node); - static void _bind_methods(); - - void create_physical_skeleton(); - PhysicalBone *create_physical_bone(int bone_id, int bone_child_id, const Vector &bones_infos); - -public: - void edit(Skeleton *p_node); - - SkeletonEditor(); - ~SkeletonEditor(); -}; - -class SkeletonEditorPlugin : public EditorPlugin { - GDCLASS(SkeletonEditorPlugin, EditorPlugin); - - EditorNode *editor; - SkeletonEditor *skeleton_editor; - -public: - virtual String get_name() const { return "Skeleton"; } - virtual bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); - - SkeletonEditorPlugin(EditorNode *p_node); - ~SkeletonEditorPlugin(); -}; - -#endif // SKELETON_EDITOR_PLUGIN_H diff --git a/modules/skeleton_editor/SCsub b/modules/skeleton_editor/SCsub index 3912c4728..1cb295966 100644 --- a/modules/skeleton_editor/SCsub +++ b/modules/skeleton_editor/SCsub @@ -3,7 +3,6 @@ Import('env') env.add_source_files(env.modules_sources,"register_types.cpp") if env["tools"]: - env.add_source_files(env.modules_sources, "skeleton_editor_plugin_remover.cpp") env.add_source_files(env.modules_sources, "skeleton_editor_plugin.cpp") env.add_source_files(env.modules_sources, "spatial_editor_gizmos.cpp") env.add_source_files(env.modules_sources, "skeleton_editor_module_plugin.cpp") diff --git a/modules/skeleton_editor/register_types.cpp b/modules/skeleton_editor/register_types.cpp index 34241e4c2..8e1d7d7ad 100644 --- a/modules/skeleton_editor/register_types.cpp +++ b/modules/skeleton_editor/register_types.cpp @@ -23,7 +23,6 @@ SOFTWARE. #include "register_types.h" #ifdef TOOLS_ENABLED -#include "skeleton_editor_plugin_remover.h" #include "skeleton_editor_plugin.h" #include "spatial_editor_gizmos.h" #include "skeleton_editor_module_plugin.h" @@ -31,7 +30,6 @@ SOFTWARE. void register_skeleton_editor_types() { #ifdef TOOLS_ENABLED - //EditorPlugins::add_by_type(); EditorPlugins::add_by_type(); EditorPlugins::add_by_type(); diff --git a/modules/skeleton_editor/skeleton_editor_module_plugin.cpp b/modules/skeleton_editor/skeleton_editor_module_plugin.cpp index 6c7af9d55..ac14c21a1 100644 --- a/modules/skeleton_editor/skeleton_editor_module_plugin.cpp +++ b/modules/skeleton_editor/skeleton_editor_module_plugin.cpp @@ -24,7 +24,7 @@ SOFTWARE. #include "spatial_editor_gizmos.h" -SkeletonEditorModulePlugin::SkeletonEditorModulePlugin(EditorNode *p_node) : SkeletonEditorPluginRemover(p_node) { +SkeletonEditorModulePlugin::SkeletonEditorModulePlugin(EditorNode *p_node) { } void SkeletonEditorModulePlugin::_notification(int p_what) { diff --git a/modules/skeleton_editor/skeleton_editor_module_plugin.h b/modules/skeleton_editor/skeleton_editor_module_plugin.h index 79f21df10..23b69de00 100644 --- a/modules/skeleton_editor/skeleton_editor_module_plugin.h +++ b/modules/skeleton_editor/skeleton_editor_module_plugin.h @@ -26,10 +26,8 @@ SOFTWARE. #include "editor/editor_node.h" #include "editor/editor_plugin.h" -#include "skeleton_editor_plugin_remover.h" - -class SkeletonEditorModulePlugin : public SkeletonEditorPluginRemover { - GDCLASS(SkeletonEditorModulePlugin, SkeletonEditorPluginRemover); +class SkeletonEditorModulePlugin : public EditorPlugin { + GDCLASS(SkeletonEditorModulePlugin, EditorPlugin); public: bool has_main_screen() const { return false; } diff --git a/modules/skeleton_editor/skeleton_editor_plugin_remover.cpp b/modules/skeleton_editor/skeleton_editor_plugin_remover.cpp deleted file mode 100644 index b4f759181..000000000 --- a/modules/skeleton_editor/skeleton_editor_plugin_remover.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright (c) 2020 Péter Magyar - -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 "skeleton_editor_plugin_remover.h" - -#include "editor/editor_data.h" -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "editor/editor_scale.h" -#include "editor/editor_settings.h" - -void SkeletonEditorPluginRemover::remove_built_in_editor_plugin() { - EditorData &data = EditorNode::get_editor_data(); - - for (int i = 0; i < data.get_editor_plugin_count(); ++i) { - EditorPlugin *p = data.get_editor_plugin(i); - - if (p->is_class("SkeletonEditorPlugin")) { - EditorNode::get_singleton()->remove_editor_plugin(p); - - break; - } - } - - Control *vp = EditorNode::get_singleton()->get_viewport(); - - for (int i = 0; i < vp->get_child_count(); ++i) { - Node *n = vp->get_child(i); - - if (n->is_class("SkeletonEditor")) { - n->queue_delete(); - - break; - } - } -} - -SkeletonEditorPluginRemover::SkeletonEditorPluginRemover(EditorNode *p_node) { - //note calling remove_built_int_editor_plugin here, or in code before this will cause a crash because - //not all classes that are used in EditorNode::get_singleton()->remove_editor_plugin() initialized yet! - call_deferred("remove_built_in_editor_plugin"); -} - -void SkeletonEditorPluginRemover::_bind_methods() { - ClassDB::bind_method(D_METHOD("remove_built_in_editor_plugin"), &SkeletonEditorPluginRemover::remove_built_in_editor_plugin); -} \ No newline at end of file diff --git a/modules/skeleton_editor/skeleton_editor_plugin_remover.h b/modules/skeleton_editor/skeleton_editor_plugin_remover.h deleted file mode 100644 index d5b8454fd..000000000 --- a/modules/skeleton_editor/skeleton_editor_plugin_remover.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright (c) 2020 Péter Magyar - -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 SKELETON_EDITOR_PLUGIN_REMOVER_H -#define SKELETON_EDITOR_PLUGIN_REMOVER_H - -#include "editor/editor_plugin.h" - -class SkeletonEditorPluginRemover : public EditorPlugin { - GDCLASS(SkeletonEditorPluginRemover, EditorPlugin); - -protected: - static void _bind_methods(); - -public: - virtual String get_name() const { return "SkeletonEditorPluginRemover"; } - void remove_built_in_editor_plugin(); - - SkeletonEditorPluginRemover(EditorNode *p_node); -}; - -#endif diff --git a/modules/skeleton_editor/spatial_editor_gizmos.cpp b/modules/skeleton_editor/spatial_editor_gizmos.cpp index 77b94f758..f2ac0b506 100644 --- a/modules/skeleton_editor/spatial_editor_gizmos.cpp +++ b/modules/skeleton_editor/spatial_editor_gizmos.cpp @@ -30,7 +30,6 @@ #include "spatial_editor_gizmos.h" -#include "editor/plugins/skeleton_editor_plugin.h" #include "scene/resources/surface_tool.h" ModuleSkeletonSpatialGizmoPlugin::ModuleSkeletonSpatialGizmoPlugin() {