Moved Skeleton2D and it's related classes into a module.

This commit is contained in:
Relintai 2022-08-28 13:57:25 +02:00
parent 91bba51de6
commit b9f3d3b26a
48 changed files with 177 additions and 67 deletions

View File

@ -137,7 +137,6 @@
#include "editor/plugins/script_editor_plugin.h"
#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_ik_editor_plugin.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/plugins/sprite_editor_plugin.h"
@ -6800,7 +6799,6 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(AnimationTreeEditorPlugin(this)));
add_editor_plugin(memnew(StyleBoxEditorPlugin(this)));
add_editor_plugin(memnew(SpriteEditorPlugin(this)));
add_editor_plugin(memnew(Skeleton2DEditorPlugin(this)));
add_editor_plugin(memnew(CPUParticles2DEditorPlugin(this)));
add_editor_plugin(memnew(CPUParticlesEditorPlugin(this)));
add_editor_plugin(memnew(ResourcePreloaderEditorPlugin(this)));

View File

@ -30,6 +30,12 @@
#include "canvas_item_editor_plugin.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_2D_ENABLED
#include "modules/skeleton_2d/nodes/skeleton_2d.h"
#endif
#include "core/config/engine.h"
#include "core/config/project_settings.h"
#include "core/containers/pool_vector.h"
@ -62,7 +68,7 @@
#include "scene/2d/light_2d.h"
#include "scene/2d/node_2d.h"
#include "scene/2d/polygon_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "scene/2d/sprite.h"
#include "scene/2d/touch_screen_button.h"
#include "scene/gui/base_button.h"
@ -3749,6 +3755,7 @@ void CanvasItemEditor::_notification(int p_what) {
anchor_mode_button->set_visible(false);
}
#ifdef MODULE_SKELETON_2D_ENABLED
// Update the viewport if bones changes
for (Map<BoneKey, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
Object *b = ObjectDB::get_instance(E->key().from);
@ -3775,6 +3782,7 @@ void CanvasItemEditor::_notification(int p_what) {
viewport->update();
}
}
#endif
}
if (p_what == NOTIFICATION_ENTER_TREE) {
@ -4520,6 +4528,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
snap_dialog->popup_centered(Size2(220, 160) * EDSCALE);
} break;
case SKELETON_SHOW_BONES: {
#ifdef MODULE_SKELETON_2D_ENABLED
List<Node *> selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
// Add children nodes so they are processed
@ -4533,6 +4542,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
}
bone_2d->_editor_set_show_bone_gizmo(!bone_2d->_editor_get_show_bone_gizmo());
}
#endif
} break;
case SHOW_HELPERS: {
show_helpers = !show_helpers;
@ -4876,6 +4886,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
} break;
case SKELETON_MAKE_BONES: {
#ifdef MODULE_SKELETON_2D_ENABLED
Map<Node *, Object *> &selection = editor_selection->get_selection();
Node *editor_root = EditorNode::get_singleton()->get_edited_scene()->get_tree()->get_edited_scene_root();
@ -4908,7 +4919,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
}
undo_redo->commit_action();
#endif
} break;
}
}

View File

@ -30,27 +30,31 @@
#include "polygon_2d_editor_plugin.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_2D_ENABLED
#include "modules/skeleton_2d/nodes/skeleton_2d.h"
#endif
#include "canvas_item_editor_plugin.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/2d/skeleton_2d.h"
#include "scene/gui/panel.h"
#include "core/object/class_db.h"
#include "core/input/input_event.h"
#include "core/math/geometry.h"
#include "core/math/math_defs.h"
#include "core/math/math_funcs.h"
#include "core/math/rect2.h"
#include "core/math/transform_2d.h"
#include "core/string/node_path.h"
#include "core/input/input_event.h"
#include "core/os/memory.h"
#include "core/string/string_name.h"
#include "core/typedefs.h"
#include "core/object/class_db.h"
#include "core/object/undo_redo.h"
#include "core/os/keyboard.h"
#include "core/os/memory.h"
#include "core/string/node_path.h"
#include "core/string/string_name.h"
#include "core/string/ustring.h"
#include "core/typedefs.h"
#include "core/variant/variant.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/2d/canvas_item.h"
#include "scene/2d/polygon_2d.h"
#include "scene/gui/box_container.h"
@ -60,6 +64,7 @@
#include "scene/gui/dialogs.h"
#include "scene/gui/label.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/panel.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/scroll_bar.h"
#include "scene/gui/scroll_container.h"
@ -135,6 +140,7 @@ void Polygon2DEditor::_notification(int p_what) {
}
void Polygon2DEditor::_sync_bones() {
#ifdef MODULE_SKELETON_2D_ENABLED
Skeleton2D *skeleton = nullptr;
if (!node->has_node(node->get_skeleton())) {
error->set_text(TTR("The skeleton property of the Polygon2D does not point to a Skeleton2D node"));
@ -186,6 +192,7 @@ void Polygon2DEditor::_sync_bones() {
undo_redo->add_do_method(uv_edit_draw, "update");
undo_redo->add_undo_method(uv_edit_draw, "update");
undo_redo->commit_action();
#endif
}
void Polygon2DEditor::_update_bone_list() {
@ -1139,6 +1146,7 @@ void Polygon2DEditor::_uv_draw() {
}
}
#ifdef MODULE_SKELETON_2D_ENABLED
if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
NodePath bone_path;
for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) {
@ -1196,6 +1204,7 @@ void Polygon2DEditor::_uv_draw() {
//draw paint circle
uv_edit_draw->draw_circle(bone_paint_pos, bone_paint_radius->get_value() * EDSCALE, Color(1, 1, 1, 0.1));
}
#endif
rect.position -= uv_edit_draw->get_size();
rect.size += uv_edit_draw->get_size() * 2.0;

7
modules/skeleton_2d/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.import
*.d
*.o
*.meta
*.obj
*.pyc
*.bc

24
modules/skeleton_2d/SCsub Normal file
View File

@ -0,0 +1,24 @@
import os
Import('env')
module_env = env.Clone()
module_env.add_source_files(env.modules_sources,"register_types.cpp")
module_env.add_source_files(env.modules_sources,"nodes/skeleton_2d.cpp")
module_env.add_source_files(env.modules_sources,"nodes/physical_bone_2d.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_ccdik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_fabrik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_jiggle.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_lookat.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_physicalbones.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_stackholder.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_2d_twoboneik.cpp")
module_env.add_source_files(env.modules_sources,"resources/skeleton_modification_stack_2d.cpp")
if env["tools"]:
module_env.add_source_files(env.modules_sources,"editor/skeleton_2d_editor_plugin.cpp")

View File

@ -0,0 +1,18 @@
def can_build(env, platform):
return True
def configure(env):
pass
def get_doc_classes():
return [
"Skeleton2D",
"PhysicalBone2D",
]
def get_doc_path():
return "doc_classes"

View File

@ -30,12 +30,12 @@
#include "skeleton_2d_editor_plugin.h"
#include "canvas_item_editor_plugin.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "core/object/class_db.h"
#include "core/os/memory.h"
#include "core/object/undo_redo.h"
#include "editor/editor_node.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/popup_menu.h"

View File

@ -1,5 +1,6 @@
#ifndef SKELETON_2D_EDITOR_PLUGIN_H
#define SKELETON_2D_EDITOR_PLUGIN_H
/*************************************************************************/
/* skeleton_2d_editor_plugin.h */
/*************************************************************************/

View File

Before

Width:  |  Height:  |  Size: 524 B

After

Width:  |  Height:  |  Size: 524 B

View File

@ -32,7 +32,7 @@
#define PHYSICAL_BONE_2D_H
#include "scene/2d/physics_body_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "skeleton_2d.h"
class Joint2D;

View File

@ -30,8 +30,8 @@
#include "skeleton_2d.h"
#include "scene/resources/skeleton_modification_2d.h"
#include "scene/resources/skeleton_modification_stack_2d.h"
#include "../resources/skeleton_modification_2d.h"
#include "../resources/skeleton_modification_stack_2d.h"
#include "core/config/engine.h"
#ifdef TOOLS_ENABLED

View File

@ -1,5 +1,6 @@
#ifndef SKELETON_2D_H
#define SKELETON_2D_H
/*************************************************************************/
/* skeleton_2d.h */
/*************************************************************************/
@ -31,7 +32,7 @@
/*************************************************************************/
#include "scene/2d/node_2d.h"
#include "scene/resources/skeleton_modification_2d.h"
#include "../resources/skeleton_modification_2d.h"
class Skeleton2D;

View File

@ -0,0 +1,44 @@
#include "register_types.h"
#include "nodes/physical_bone_2d.h"
#include "nodes/skeleton_2d.h"
#include "resources/skeleton_modification_2d.h"
#include "resources/skeleton_modification_2d_ccdik.h"
#include "resources/skeleton_modification_2d_fabrik.h"
#include "resources/skeleton_modification_2d_jiggle.h"
#include "resources/skeleton_modification_2d_lookat.h"
#include "resources/skeleton_modification_2d_physicalbones.h"
#include "resources/skeleton_modification_2d_stackholder.h"
#include "resources/skeleton_modification_2d_twoboneik.h"
#include "resources/skeleton_modification_stack_2d.h"
#ifdef TOOLS_ENABLED
#include "editor/skeleton_2d_editor_plugin.h"
#endif
void register_skeleton_2d_types() {
ClassDB::register_class<Skeleton2D>();
ClassDB::register_class<Bone2D>();
ClassDB::register_class<PhysicalBone2D>();
ClassDB::register_class<SkeletonModificationStack2D>();
ClassDB::register_class<SkeletonModification2D>();
ClassDB::register_class<SkeletonModification2DLookAt>();
ClassDB::register_class<SkeletonModification2DCCDIK>();
ClassDB::register_class<SkeletonModification2DFABRIK>();
ClassDB::register_class<SkeletonModification2DJiggle>();
ClassDB::register_class<SkeletonModification2DTwoBoneIK>();
ClassDB::register_class<SkeletonModification2DStackHolder>();
ClassDB::register_class<PhysicalBone2D>();
ClassDB::register_class<SkeletonModification2DPhysicalBones>();
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<Skeleton2DEditorPlugin>();
#endif
}
void unregister_skeleton_2d_types() {
}

View File

@ -0,0 +1,3 @@
void register_skeleton_2d_types();
void unregister_skeleton_2d_types();

View File

@ -29,12 +29,12 @@
/*************************************************************************/
#include "skeleton_modification_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "core/config/engine.h"
#include "scene/2d/collision_object_2d.h"
#include "scene/2d/collision_shape_2d.h"
#include "scene/2d/physical_bone_2d.h"
#include "../nodes/physical_bone_2d.h"
#include "skeleton_modification_stack_2d.h"

View File

@ -29,7 +29,7 @@
/*************************************************************************/
#include "skeleton_modification_2d_ccdik.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "skeleton_modification_stack_2d.h"
#include "scene/2d/node_2d.h"
#include "core/config/engine.h"

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_2d.h"
#include "skeleton_modification_2d.h"
///////////////////////////////////////
// SkeletonModification2DCCDIK

View File

@ -29,7 +29,7 @@
/*************************************************************************/
#include "skeleton_modification_2d_fabrik.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "skeleton_modification_stack_2d.h"
#ifdef TOOLS_ENABLED

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_2d.h"
#include "skeleton_modification_2d.h"
///////////////////////////////////////
// SkeletonModification2DFABRIK

View File

@ -31,7 +31,7 @@
#include "skeleton_modification_2d_jiggle.h"
#include "scene/2d/node_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "scene/resources/world_2d.h"
#include "skeleton_modification_stack_2d.h"

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_2d.h"
#include "skeleton_modification_2d.h"
///////////////////////////////////////
// SkeletonModification2DJIGGLE

View File

@ -29,7 +29,7 @@
/*************************************************************************/
#include "skeleton_modification_2d_lookat.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "skeleton_modification_stack_2d.h"
#include "core/config/engine.h"

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_2d.h"
#include "skeleton_modification_2d.h"
///////////////////////////////////////
// SkeletonModification2DLookAt

View File

@ -29,8 +29,8 @@
/*************************************************************************/
#include "skeleton_modification_2d_physicalbones.h"
#include "scene/2d/physical_bone_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/physical_bone_2d.h"
#include "../nodes/skeleton_2d.h"
#include "skeleton_modification_stack_2d.h"
#include "core/config/engine.h"

View File

@ -35,7 +35,7 @@
#include "core/containers/vector.h"
#include "core/object/object_id.h"
#include "scene/resources/skeleton_modification_2d.h"
#include "skeleton_modification_2d.h"
///////////////////////////////////////
// SkeletonModification2DJIGGLE

View File

@ -29,7 +29,7 @@
/*************************************************************************/
#include "skeleton_modification_2d_stackholder.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "skeleton_modification_stack_2d.h"
#include "core/config/engine.h"

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_2d.h"
#include "skeleton_modification_2d.h"
///////////////////////////////////////
// SkeletonModification2DJIGGLE

View File

@ -29,7 +29,7 @@
/*************************************************************************/
#include "skeleton_modification_2d_twoboneik.h"
#include "scene/2d/skeleton_2d.h"
#include "../nodes/skeleton_2d.h"
#include "skeleton_modification_stack_2d.h"
#include "core/config/engine.h"

View File

@ -31,7 +31,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/resources/skeleton_modification_2d.h"
#include "skeleton_modification_2d.h"
///////////////////////////////////////
// SkeletonModification2DJIGGLE

View File

@ -29,8 +29,8 @@
/*************************************************************************/
#include "skeleton_modification_stack_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/skeleton_modification_2d.h"
#include "../nodes/skeleton_2d.h"
#include "skeleton_modification_2d.h"
void SkeletonModificationStack2D::_get_property_list(List<PropertyInfo> *p_list) const {
for (int i = 0; i < modifications.size(); i++) {

View File

@ -1,5 +1,6 @@
#ifndef JOINTS_2D_H
#define JOINTS_2D_H
/*************************************************************************/
/* joints_2d.h */
/*************************************************************************/

View File

@ -31,7 +31,12 @@
#include "polygon_2d.h"
#include "core/math/geometry.h"
#include "skeleton_2d.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_2D_ENABLED
#include "modules/skeleton_2d/nodes/skeleton_2d.h"
#endif
#ifdef TOOLS_ENABLED
Dictionary Polygon2D::_edit_get_state() const {
@ -101,6 +106,7 @@ void Polygon2D::_notification(int p_what) {
return;
}
#ifdef MODULE_SKELETON_2D_ENABLED
Skeleton2D *skeleton_node = nullptr;
if (has_node(skeleton)) {
skeleton_node = Object::cast_to<Skeleton2D>(get_node(skeleton));
@ -127,6 +133,7 @@ void Polygon2D::_notification(int p_what) {
current_skeleton_id = new_skeleton_id;
}
#endif
Vector<Vector2> points;
Vector<Vector2> uvs;
@ -223,6 +230,7 @@ void Polygon2D::_notification(int p_what) {
}
}
#ifdef MODULE_SKELETON_2D_ENABLED
if (skeleton_node && !invert && bone_weights.size()) {
//a skeleton is set! fill indices and weights
int vc = len;
@ -287,6 +295,7 @@ void Polygon2D::_notification(int p_what) {
}
}
}
#endif
Vector<Color> colors;
if (vertex_colors.size() == points.size()) {

View File

@ -1,5 +1,6 @@
#ifndef POLYGON_2D_H
#define POLYGON_2D_H
/*************************************************************************/
/* polygon_2d.h */
/*************************************************************************/

View File

@ -42,7 +42,12 @@
#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "scene/2d/skeleton_2d.h"
#include "modules/modules_enabled.gen.h"
#ifdef MODULE_SKELETON_2D_ENABLED
#include "modules/skeleton_2d/nodes/skeleton_2d.h"
#endif
void AnimatedValuesBackup::update_skeletons() {
for (int i = 0; i < entries.size(); i++) {
@ -50,11 +55,13 @@ void AnimatedValuesBackup::update_skeletons() {
// 3D bone
Object::cast_to<Skeleton>(entries[i].object)->notification(Skeleton::NOTIFICATION_UPDATE_SKELETON);
} else {
#ifdef MODULE_SKELETON_2D_ENABLED
Bone2D *bone = Object::cast_to<Bone2D>(entries[i].object);
if (bone && bone->skeleton) {
// 2D bone
bone->skeleton->_update_transform();
}
#endif
}
}
}

View File

@ -58,14 +58,12 @@
#include "scene/2d/parallax_background.h"
#include "scene/2d/parallax_layer.h"
#include "scene/2d/path_2d.h"
#include "scene/2d/physical_bone_2d.h"
#include "scene/2d/physics_body_2d.h"
#include "scene/2d/polygon_2d.h"
#include "scene/2d/position_2d.h"
#include "scene/2d/ray_cast_2d.h"
#include "scene/2d/remote_transform_2d.h"
#include "scene/2d/shape_cast_2d.h"
#include "scene/2d/skeleton_2d.h"
#include "scene/2d/sprite.h"
#include "scene/2d/touch_screen_button.h"
#include "scene/2d/visibility_notifier_2d.h"
@ -167,15 +165,7 @@
#include "scene/resources/rectangle_shape_2d.h"
#include "scene/resources/resource_format_text.h"
#include "scene/resources/segment_shape_2d.h"
#include "scene/resources/skeleton_modification_2d.h"
#include "scene/resources/skeleton_modification_2d_ccdik.h"
#include "scene/resources/skeleton_modification_2d_fabrik.h"
#include "scene/resources/skeleton_modification_2d_jiggle.h"
#include "scene/resources/skeleton_modification_2d_lookat.h"
#include "scene/resources/skeleton_modification_2d_physicalbones.h"
#include "scene/resources/skeleton_modification_2d_stackholder.h"
#include "scene/resources/skeleton_modification_2d_twoboneik.h"
#include "scene/resources/skeleton_modification_stack_2d.h"
#include "scene/resources/skin.h"
#include "scene/resources/sky.h"
#include "scene/resources/sphere_shape.h"
@ -558,8 +548,6 @@ void register_scene_types() {
ClassDB::register_class<VisibilityNotifier2D>();
ClassDB::register_class<VisibilityEnabler2D>();
ClassDB::register_class<Polygon2D>();
ClassDB::register_class<Skeleton2D>();
ClassDB::register_class<Bone2D>();
ClassDB::register_class<Light2D>();
ClassDB::register_class<LightOccluder2D>();
ClassDB::register_class<OccluderPolygon2D>();
@ -579,18 +567,6 @@ void register_scene_types() {
ClassDB::register_class<TouchScreenButton>();
ClassDB::register_class<RemoteTransform2D>();
ClassDB::register_class<SkeletonModificationStack2D>();
ClassDB::register_class<SkeletonModification2D>();
ClassDB::register_class<SkeletonModification2DLookAt>();
ClassDB::register_class<SkeletonModification2DCCDIK>();
ClassDB::register_class<SkeletonModification2DFABRIK>();
ClassDB::register_class<SkeletonModification2DJiggle>();
ClassDB::register_class<SkeletonModification2DTwoBoneIK>();
ClassDB::register_class<SkeletonModification2DStackHolder>();
ClassDB::register_class<PhysicalBone2D>();
ClassDB::register_class<SkeletonModification2DPhysicalBones>();
OS::get_singleton()->yield(); //may take time to init
/* REGISTER RESOURCES */