#ifndef MODULE_SKELETON_EDITOR_PLUGIN_H #define MODULE_SKELETON_EDITOR_PLUGIN_H /*************************************************************************/ /* 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" #include "editor/editor_inspector.h" #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "editor/spatial_editor_gizmos.h" #include "scene/3d/camera.h" #include "scene/3d/mesh_instance.h" #include "scene/3d/skeleton.h" #include "scene/resources/immediate_mesh.h" class EditorInspectorPluginSkeleton; class Joint; class PhysicalBone; class SkeletonEditorPlugin; class Button; class CheckBox; class EditorSpinSlider; class EditorInspectorSection; class GridContainer; class Tree; class Label; class PopupMenu; class CheckBox; class VSeparator; class EditorPropertyTransform; class EditorPropertyVector3; class BoneTransformEditor : public VBoxContainer { GDCLASS(BoneTransformEditor, VBoxContainer); EditorInspectorSection *section; EditorPropertyVector3 *translation_property; EditorPropertyVector3 *rotation_property; EditorPropertyVector3 *scale_property; EditorInspectorSection *transform_section; EditorPropertyTransform *transform_property; 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(); // 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); // Update it is truely keyable then. void _update_key_button(const bool p_keyable); // Creates a Transform using the EditorPropertyVector3 properties. Transform compute_transform_from_vector3s() const; void update_enabled_checkbox(); protected: void _notification(int p_what); static void _bind_methods(); public: BoneTransformEditor(Skeleton *p_skeleton); // 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); // 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); // 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); }; class SkeletonEditor : public VBoxContainer { GDCLASS(SkeletonEditor, VBoxContainer); friend class SkeletonEditorPlugin; 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 }; enum RestOption { REST_OPTION_POSE_TO_REST }; struct BoneInfo { PhysicalBone *physical_bone; Transform relative_rest; // Relative to skeleton node BoneInfo() { physical_bone = NULL; } }; EditorNode *editor; EditorInspectorPluginSkeleton *editor_plugin; Skeleton *skeleton; Tree *joint_tree; BoneTransformEditor *rest_editor; BoneTransformEditor *pose_editor; VSeparator *separator; MenuButton *skeleton_options; MenuButton *rest_options; Button *edit_mode_button; bool edit_mode; EditorFileDialog *file_dialog; bool keyable; static SkeletonEditor *singleton; void _on_click_skeleton_option(int p_skeleton_option); void _on_click_rest_option(int p_rest_option); void _file_selected(const String &p_file); TreeItem *_find(TreeItem *p_node, const NodePath &p_path); void edit_mode_toggled(const bool pressed); 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(); void create_physical_skeleton(); PhysicalBone *create_physical_bone(int bone_id, int bone_child_id, const Vector &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); void set_keyable(const bool p_keyable); void set_rest_options_enabled(const bool p_rest_options_enabled); MeshInstance *handles_mesh_instance; Ref handles_mesh; Ref handle_material; Ref handle_shader; Transform bone_original; void _update_pose_enabled(int p_bone = -1); void _update_show_rest_only(); void _update_gizmo_transform(); void _update_gizmo_visible(); void _hide_handles(); void _draw_gizmo(); void _draw_handles(); void _joint_tree_selection_changed(); void _joint_tree_rmb_select(const Vector2 &p_pos); void _update_properties(); void _subgizmo_selection_change(); int selected_bone; protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); public: static SkeletonEditor *get_singleton() { return singleton; } void select_bone(int p_idx); int get_selected_bone() const; void move_skeleton_bone(NodePath p_skeleton_path, int32_t p_selected_boneidx, int32_t p_target_boneidx); Skeleton *get_skeleton() const { return skeleton; }; bool is_edit_mode() const { return edit_mode; } void update_bone_original(); Transform get_bone_original() { return bone_original; }; SkeletonEditor(EditorInspectorPluginSkeleton *e_plugin, EditorNode *p_editor, Skeleton *skeleton); ~SkeletonEditor(); 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; }; class EditorInspectorPluginSkeleton : public EditorInspectorPlugin { GDCLASS(EditorInspectorPluginSkeleton, EditorInspectorPlugin); friend class SkeletonEditorPlugin; SkeletonEditor *skel_editor; EditorNode *editor; protected: static void _bind_methods(); public: virtual bool can_handle(Object *p_object); virtual void parse_begin(Object *p_object); }; class SkeletonEditorPlugin : public EditorPlugin { GDCLASS(SkeletonEditorPlugin, EditorPlugin); EditorInspectorPluginSkeleton *skeleton_plugin; EditorNode *editor; public: virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera *p_camera, const Ref &p_event); bool has_main_screen() const { return false; } virtual bool handles(Object *p_object) const; virtual String get_name() const { return "Skeleton"; } SkeletonEditorPlugin(EditorNode *p_node); protected: void _notification(int p_what); }; class SkeletonGizmoPlugin : public EditorSpatialGizmoPlugin { GDCLASS(SkeletonGizmoPlugin, EditorSpatialGizmoPlugin); Ref unselected_mat; Ref selected_mat; Ref 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 &p_ids, const Vector &p_restore, bool p_cancel); void redraw(EditorSpatialGizmo *p_gizmo); SkeletonGizmoPlugin(); }; #endif // SKELETON_EDITOR_PLUGIN_H