2022-03-17 22:33:22 +01:00
|
|
|
#ifndef MODULE_SKELETON_EDITOR_PLUGIN_H
|
|
|
|
#define MODULE_SKELETON_EDITOR_PLUGIN_H
|
2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* skeleton_editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 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 "core/os/input_event.h"
|
2022-08-09 21:57:46 +02:00
|
|
|
#include "editor/editor_inspector.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/editor_plugin.h"
|
2022-08-11 01:24:29 +02:00
|
|
|
#include "editor/spatial_editor_gizmos.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
#include "scene/3d/camera.h"
|
|
|
|
#include "scene/3d/mesh_instance.h"
|
|
|
|
#include "scene/3d/skeleton.h"
|
2022-08-11 17:31:02 +02:00
|
|
|
#include "scene/resources/immediate_mesh.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class EditorInspectorPluginSkeleton;
|
2022-03-15 13:29:32 +01:00
|
|
|
class Joint;
|
|
|
|
class PhysicalBone;
|
2022-08-11 10:59:22 +02:00
|
|
|
class SkeletonEditorPlugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
class Button;
|
|
|
|
class CheckBox;
|
2022-03-19 03:10:01 +01:00
|
|
|
class EditorSpinSlider;
|
|
|
|
class EditorInspectorSection;
|
2022-03-19 04:08:34 +01:00
|
|
|
class GridContainer;
|
|
|
|
class Tree;
|
|
|
|
class Label;
|
|
|
|
class PopupMenu;
|
|
|
|
class CheckBox;
|
|
|
|
class VSeparator;
|
2022-08-09 21:57:46 +02:00
|
|
|
class EditorPropertyTransform;
|
|
|
|
class EditorPropertyVector3;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class BoneTransformEditor : public VBoxContainer {
|
|
|
|
GDCLASS(BoneTransformEditor, VBoxContainer);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
EditorInspectorSection *section;
|
|
|
|
|
2022-08-09 21:57:46 +02:00
|
|
|
EditorPropertyVector3 *translation_property;
|
|
|
|
EditorPropertyVector3 *rotation_property;
|
|
|
|
EditorPropertyVector3 *scale_property;
|
|
|
|
EditorInspectorSection *transform_section;
|
|
|
|
EditorPropertyTransform *transform_property;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Rect2 background_rects[5];
|
|
|
|
|
|
|
|
Skeleton *skeleton;
|
|
|
|
String property;
|
|
|
|
|
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
|
|
|
Button *key_button;
|
|
|
|
CheckBox *enabled_checkbox;
|
|
|
|
|
|
|
|
bool keyable;
|
|
|
|
bool toggle_enabled;
|
|
|
|
bool updating;
|
|
|
|
|
|
|
|
String label;
|
|
|
|
|
|
|
|
void create_editors();
|
|
|
|
|
2022-08-09 21:57:46 +02:00
|
|
|
// Called when one of the EditorSpinSliders are changed.
|
|
|
|
void _value_changed(const double p_value);
|
|
|
|
// Called when the one of the EditorPropertyVector3 are updated.
|
|
|
|
void _value_changed_vector3(const String &p_path, const Variant &p_value, const String &p_name = "", bool changing = false);
|
|
|
|
// Called when the transform_property is updated.
|
|
|
|
void _value_changed_transform(const String &p_path, const Variant &p_value, const String &p_name = "", bool changing = false);
|
|
|
|
// Changes the transform to the given transform and updates the UI accordingly.
|
|
|
|
void _change_transform(Transform p_new_transform);
|
2022-08-11 17:31:02 +02:00
|
|
|
// Update it is truely keyable then.
|
|
|
|
void _update_key_button(const bool p_keyable);
|
2022-08-09 21:57:46 +02:00
|
|
|
// Creates a Transform using the EditorPropertyVector3 properties.
|
|
|
|
Transform compute_transform_from_vector3s() const;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
void update_enabled_checkbox();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2022-08-11 10:59:22 +02:00
|
|
|
BoneTransformEditor(Skeleton *p_skeleton);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
// Which transform target to modify
|
|
|
|
void set_target(const String &p_prop);
|
|
|
|
void set_label(const String &p_label) { label = p_label; }
|
|
|
|
|
|
|
|
void _update_properties();
|
|
|
|
void _update_transform_properties(Transform p_transform);
|
|
|
|
|
|
|
|
// Transform can be keyed, whether or not to show the button
|
|
|
|
void set_keyable(const bool p_keyable);
|
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
// When rest mode, pose and custom_pose editor are diasbled.
|
|
|
|
void set_properties_read_only(const bool p_readonly);
|
|
|
|
void set_transform_read_only(const bool p_readonly);
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
// Bone can be toggled enabled or disabled, whether or not to show the checkbox
|
|
|
|
void set_toggle_enabled(const bool p_enabled);
|
|
|
|
|
|
|
|
// Key Transform Button pressed
|
|
|
|
void _key_button_pressed();
|
|
|
|
|
|
|
|
// Bone Enabled Checkbox toggled
|
|
|
|
void _checkbox_toggled(const bool p_toggled);
|
|
|
|
};
|
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
class SkeletonEditor : public VBoxContainer {
|
|
|
|
GDCLASS(SkeletonEditor, VBoxContainer);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
friend class SkeletonEditorPlugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
enum SkeletonOption {
|
|
|
|
SKELETON_OPTION_INIT_POSE,
|
|
|
|
SKELETON_OPTION_INSERT_KEYS,
|
|
|
|
SKELETON_OPTION_INSERT_KEYS_EXISTED,
|
|
|
|
SKELETON_OPTION_CREATE_PHYSICAL_SKELETON,
|
|
|
|
SKELETON_OPTION_ADD_BONE,
|
|
|
|
SKELETON_OPTION_REMOVE_BONE,
|
|
|
|
SKELETON_OPTION_RENAME_BONE
|
2022-03-15 13:29:32 +01:00
|
|
|
};
|
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
enum RestOption {
|
|
|
|
REST_OPTION_POSE_TO_REST
|
2022-03-15 13:29:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BoneInfo {
|
|
|
|
PhysicalBone *physical_bone;
|
|
|
|
Transform relative_rest; // Relative to skeleton node
|
2022-08-11 17:31:02 +02:00
|
|
|
|
|
|
|
BoneInfo() {
|
|
|
|
physical_bone = NULL;
|
|
|
|
}
|
2022-03-15 13:29:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
EditorNode *editor;
|
2022-08-11 10:59:22 +02:00
|
|
|
EditorInspectorPluginSkeleton *editor_plugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
Skeleton *skeleton;
|
|
|
|
|
|
|
|
Tree *joint_tree;
|
2022-08-11 10:59:22 +02:00
|
|
|
BoneTransformEditor *rest_editor;
|
|
|
|
BoneTransformEditor *pose_editor;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
VSeparator *separator;
|
|
|
|
MenuButton *skeleton_options;
|
|
|
|
MenuButton *rest_options;
|
|
|
|
Button *edit_mode_button;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
bool edit_mode;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
EditorFileDialog *file_dialog;
|
|
|
|
|
|
|
|
bool keyable;
|
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
static SkeletonEditor *singleton;
|
|
|
|
|
|
|
|
void _on_click_skeleton_option(int p_skeleton_option);
|
|
|
|
void _on_click_rest_option(int p_rest_option);
|
2022-03-15 13:29:32 +01:00
|
|
|
void _file_selected(const String &p_file);
|
2022-08-11 17:31:02 +02:00
|
|
|
TreeItem *_find(TreeItem *p_node, const NodePath &p_path);
|
|
|
|
void edit_mode_toggled(const bool pressed);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
EditorFileDialog *file_export_lib;
|
|
|
|
|
|
|
|
void update_joint_tree();
|
|
|
|
void update_editors();
|
|
|
|
|
|
|
|
void create_editors();
|
|
|
|
|
|
|
|
void init_pose();
|
|
|
|
void insert_keys(bool p_all_bones);
|
|
|
|
void pose_to_rest();
|
2022-08-11 17:31:02 +02:00
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
void create_physical_skeleton();
|
|
|
|
PhysicalBone *create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &bones_infos);
|
|
|
|
|
|
|
|
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
|
|
|
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
|
|
|
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
void set_keyable(const bool p_keyable);
|
|
|
|
void set_rest_options_enabled(const bool p_rest_options_enabled);
|
|
|
|
|
|
|
|
MeshInstance *handles_mesh_instance;
|
|
|
|
Ref<ImmediateMesh> handles_mesh;
|
2022-03-15 13:29:32 +01:00
|
|
|
Ref<ShaderMaterial> handle_material;
|
|
|
|
Ref<Shader> handle_shader;
|
2022-08-11 17:31:02 +02:00
|
|
|
|
|
|
|
Transform bone_original;
|
|
|
|
|
|
|
|
void _update_pose_enabled(int p_bone = -1);
|
|
|
|
void _update_show_rest_only();
|
|
|
|
|
|
|
|
void _update_gizmo_transform();
|
|
|
|
void _update_gizmo_visible();
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
void _hide_handles();
|
2022-08-11 17:31:02 +02:00
|
|
|
|
|
|
|
void _draw_gizmo();
|
2022-03-15 13:29:32 +01:00
|
|
|
void _draw_handles();
|
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
void _joint_tree_selection_changed();
|
|
|
|
void _joint_tree_rmb_select(const Vector2 &p_pos);
|
|
|
|
void _update_properties();
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
void _subgizmo_selection_change();
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
int selected_bone;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
void _node_removed(Node *p_node);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2022-08-11 17:31:02 +02:00
|
|
|
static SkeletonEditor *get_singleton() { return singleton; }
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
void select_bone(int p_idx);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
int get_selected_bone() const;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
void move_skeleton_bone(NodePath p_skeleton_path, int32_t p_selected_boneidx, int32_t p_target_boneidx);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
Skeleton *get_skeleton() const { return skeleton; };
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
bool is_edit_mode() const { return edit_mode; }
|
|
|
|
|
|
|
|
void update_bone_original();
|
|
|
|
Transform get_bone_original() { return bone_original; };
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
SkeletonEditor(EditorInspectorPluginSkeleton *e_plugin, EditorNode *p_editor, Skeleton *skeleton);
|
|
|
|
~SkeletonEditor();
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
void add_bone();
|
|
|
|
void remove_bone();
|
|
|
|
void rename_bone();
|
|
|
|
|
|
|
|
void _add_bone_callback();
|
|
|
|
void _remove_bone_callback();
|
|
|
|
void _rename_bone_callback();
|
|
|
|
|
|
|
|
void create_bone_tool_popups();
|
|
|
|
static void _bind_tool_popup_methods();
|
|
|
|
|
|
|
|
ConfirmationDialog *_bone_add_dialog;
|
|
|
|
LineEdit *_bone_add_line_edit;
|
|
|
|
ConfirmationDialog *_bone_rename_dialog;
|
|
|
|
LineEdit *_bone_rename_line_edit;
|
|
|
|
ConfirmationDialog *_bone_remove_dialog;
|
|
|
|
};
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class EditorInspectorPluginSkeleton : public EditorInspectorPlugin {
|
|
|
|
GDCLASS(EditorInspectorPluginSkeleton, EditorInspectorPlugin);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
friend class SkeletonEditorPlugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
SkeletonEditor *skel_editor;
|
2022-03-15 13:29:32 +01:00
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-03-18 19:00:13 +01:00
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
public:
|
|
|
|
virtual bool can_handle(Object *p_object);
|
|
|
|
virtual void parse_begin(Object *p_object);
|
|
|
|
};
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
class SkeletonEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(SkeletonEditorPlugin, EditorPlugin);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
EditorInspectorPluginSkeleton *skeleton_plugin;
|
2022-03-15 13:29:32 +01:00
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
public:
|
2022-08-11 17:31:02 +02:00
|
|
|
virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
bool has_main_screen() const { return false; }
|
|
|
|
virtual bool handles(Object *p_object) const;
|
|
|
|
|
|
|
|
virtual String get_name() const { return "Skeleton"; }
|
|
|
|
|
2022-08-11 10:59:22 +02:00
|
|
|
SkeletonEditorPlugin(EditorNode *p_node);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
2022-03-15 13:29:32 +01:00
|
|
|
};
|
|
|
|
|
2022-08-11 17:31:02 +02:00
|
|
|
class SkeletonGizmoPlugin : public EditorSpatialGizmoPlugin {
|
|
|
|
GDCLASS(SkeletonGizmoPlugin, EditorSpatialGizmoPlugin);
|
|
|
|
|
|
|
|
Ref<SpatialMaterial> unselected_mat;
|
|
|
|
Ref<ShaderMaterial> selected_mat;
|
|
|
|
Ref<Shader> selected_sh;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool has_gizmo(Spatial *p_spatial);
|
|
|
|
String get_gizmo_name() const;
|
|
|
|
int get_priority() const;
|
|
|
|
|
|
|
|
int subgizmos_intersect_ray(const EditorSpatialGizmo *p_gizmo, Camera *p_camera, const Vector2 &p_point) const;
|
|
|
|
Transform get_subgizmo_transform(const EditorSpatialGizmo *p_gizmo, int p_id) const;
|
|
|
|
void set_subgizmo_transform(const EditorSpatialGizmo *p_gizmo, int p_id, Transform p_transform);
|
|
|
|
void commit_subgizmos(const EditorSpatialGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform> &p_restore, bool p_cancel);
|
|
|
|
|
|
|
|
void redraw(EditorSpatialGizmo *p_gizmo);
|
|
|
|
|
|
|
|
SkeletonGizmoPlugin();
|
|
|
|
};
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
#endif // SKELETON_EDITOR_PLUGIN_H
|