2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-03-27 08:44:44 +01:00
|
|
|
/* node_3d_editor_plugin.h */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2020-10-17 17:52:17 +02:00
|
|
|
#ifndef NODE_3D_EDITOR_PLUGIN_H
|
|
|
|
#define NODE_3D_EDITOR_PLUGIN_H
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#include "editor/editor_plugin.h"
|
2019-10-23 11:46:26 +02:00
|
|
|
#include "editor/editor_scale.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "editor/editor_spin_slider.h"
|
2021-06-23 16:49:50 +02:00
|
|
|
#include "editor/plugins/node_3d_editor_gizmos.h"
|
2021-08-08 17:08:37 +02:00
|
|
|
#include "scene/3d/camera_3d.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/light_3d.h"
|
|
|
|
#include "scene/3d/visual_instance_3d.h"
|
2021-02-22 14:54:12 +01:00
|
|
|
#include "scene/3d/world_environment.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "scene/gui/color_picker.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/gui/panel_container.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "scene/gui/spin_box.h"
|
|
|
|
#include "scene/gui/split_container.h"
|
2021-02-22 14:54:12 +01:00
|
|
|
#include "scene/resources/environment.h"
|
2021-10-03 13:28:55 +02:00
|
|
|
#include "scene/resources/fog_material.h"
|
2021-02-22 14:54:12 +01:00
|
|
|
#include "scene/resources/sky_material.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-02-12 02:46:22 +01:00
|
|
|
class EditorData;
|
2020-03-26 22:49:16 +01:00
|
|
|
class Node3DEditor;
|
|
|
|
class Node3DEditorViewport;
|
2020-04-01 20:28:09 +02:00
|
|
|
class SubViewportContainer;
|
2021-06-23 16:49:50 +02:00
|
|
|
class DirectionalLight3D;
|
|
|
|
class WorldEnvironment;
|
2022-03-25 18:06:46 +01:00
|
|
|
class EditorUndoRedoManager;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-10-23 11:46:26 +02:00
|
|
|
class ViewportRotationControl : public Control {
|
|
|
|
GDCLASS(ViewportRotationControl, Control);
|
|
|
|
|
|
|
|
struct Axis2D {
|
|
|
|
Vector2i screen_point;
|
|
|
|
float z_axis = -99.0;
|
|
|
|
int axis = -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Axis2DCompare {
|
|
|
|
_FORCE_INLINE_ bool operator()(const Axis2D &l, const Axis2D &r) const {
|
|
|
|
return l.z_axis < r.z_axis;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditorViewport *viewport = nullptr;
|
2019-10-23 11:46:26 +02:00
|
|
|
Vector<Color> axis_colors;
|
|
|
|
Vector<int> axis_menu_options;
|
2020-04-28 16:41:01 +02:00
|
|
|
Vector2i orbiting_mouse_start;
|
2019-10-23 11:46:26 +02:00
|
|
|
bool orbiting = false;
|
|
|
|
int focused_axis = -2;
|
|
|
|
|
|
|
|
const float AXIS_CIRCLE_RADIUS = 8.0f * EDSCALE;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
2021-08-22 17:37:22 +02:00
|
|
|
virtual void gui_input(const Ref<InputEvent> &p_event) override;
|
2019-10-23 11:46:26 +02:00
|
|
|
void _draw();
|
|
|
|
void _draw_axis(const Axis2D &p_axis);
|
|
|
|
void _get_sorted_axis(Vector<Axis2D> &r_axis);
|
|
|
|
void _update_focus();
|
|
|
|
void _on_mouse_exited();
|
|
|
|
|
|
|
|
public:
|
2020-03-26 22:49:16 +01:00
|
|
|
void set_viewport(Node3DEditorViewport *p_viewport);
|
2019-10-23 11:46:26 +02:00
|
|
|
};
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
class Node3DEditorViewport : public Control {
|
|
|
|
GDCLASS(Node3DEditorViewport, Control);
|
|
|
|
friend class Node3DEditor;
|
2019-10-23 11:46:26 +02:00
|
|
|
friend class ViewportRotationControl;
|
2014-02-10 02:10:30 +01:00
|
|
|
enum {
|
|
|
|
VIEW_TOP,
|
|
|
|
VIEW_BOTTOM,
|
|
|
|
VIEW_LEFT,
|
|
|
|
VIEW_RIGHT,
|
|
|
|
VIEW_FRONT,
|
|
|
|
VIEW_REAR,
|
2016-10-04 20:39:38 +02:00
|
|
|
VIEW_CENTER_TO_ORIGIN,
|
2014-02-10 02:10:30 +01:00
|
|
|
VIEW_CENTER_TO_SELECTION,
|
2018-10-27 23:43:19 +02:00
|
|
|
VIEW_ALIGN_TRANSFORM_WITH_VIEW,
|
|
|
|
VIEW_ALIGN_ROTATION_WITH_VIEW,
|
2014-02-10 02:10:30 +01:00
|
|
|
VIEW_PERSPECTIVE,
|
|
|
|
VIEW_ENVIRONMENT,
|
2014-10-03 05:10:51 +02:00
|
|
|
VIEW_ORTHOGONAL,
|
2017-10-31 18:23:25 +01:00
|
|
|
VIEW_HALF_RESOLUTION,
|
2014-10-03 05:10:51 +02:00
|
|
|
VIEW_AUDIO_LISTENER,
|
2017-07-15 06:23:10 +02:00
|
|
|
VIEW_AUDIO_DOPPLER,
|
2014-10-12 07:13:22 +02:00
|
|
|
VIEW_GIZMOS,
|
2017-06-11 20:52:03 +02:00
|
|
|
VIEW_INFORMATION,
|
2020-04-10 19:18:42 +02:00
|
|
|
VIEW_FRAME_TIME,
|
2017-06-11 20:52:03 +02:00
|
|
|
VIEW_DISPLAY_NORMAL,
|
|
|
|
VIEW_DISPLAY_WIREFRAME,
|
|
|
|
VIEW_DISPLAY_OVERDRAW,
|
2018-06-25 03:24:31 +02:00
|
|
|
VIEW_DISPLAY_SHADELESS,
|
2019-10-03 22:39:08 +02:00
|
|
|
VIEW_DISPLAY_LIGHTING,
|
2020-03-08 19:23:04 +01:00
|
|
|
VIEW_DISPLAY_ADVANCED,
|
2020-01-27 00:09:40 +01:00
|
|
|
VIEW_DISPLAY_NORMAL_BUFFER,
|
2019-10-03 22:39:08 +02:00
|
|
|
VIEW_DISPLAY_DEBUG_SHADOW_ATLAS,
|
|
|
|
VIEW_DISPLAY_DEBUG_DIRECTIONAL_SHADOW_ATLAS,
|
2021-06-05 00:47:26 +02:00
|
|
|
VIEW_DISPLAY_DEBUG_VOXEL_GI_ALBEDO,
|
|
|
|
VIEW_DISPLAY_DEBUG_VOXEL_GI_LIGHTING,
|
|
|
|
VIEW_DISPLAY_DEBUG_VOXEL_GI_EMISSION,
|
2020-01-12 02:26:52 +01:00
|
|
|
VIEW_DISPLAY_DEBUG_SCENE_LUMINANCE,
|
2020-01-25 11:18:55 +01:00
|
|
|
VIEW_DISPLAY_DEBUG_SSAO,
|
2021-08-03 09:07:32 +02:00
|
|
|
VIEW_DISPLAY_DEBUG_SSIL,
|
2020-04-08 03:51:52 +02:00
|
|
|
VIEW_DISPLAY_DEBUG_PSSM_SPLITS,
|
2020-04-14 05:05:21 +02:00
|
|
|
VIEW_DISPLAY_DEBUG_DECAL_ATLAS,
|
2020-06-25 15:33:28 +02:00
|
|
|
VIEW_DISPLAY_DEBUG_SDFGI,
|
|
|
|
VIEW_DISPLAY_DEBUG_SDFGI_PROBES,
|
|
|
|
VIEW_DISPLAY_DEBUG_GI_BUFFER,
|
2020-12-17 19:56:59 +01:00
|
|
|
VIEW_DISPLAY_DEBUG_DISABLE_LOD,
|
2021-01-17 17:25:38 +01:00
|
|
|
VIEW_DISPLAY_DEBUG_CLUSTER_OMNI_LIGHTS,
|
|
|
|
VIEW_DISPLAY_DEBUG_CLUSTER_SPOT_LIGHTS,
|
|
|
|
VIEW_DISPLAY_DEBUG_CLUSTER_DECALS,
|
|
|
|
VIEW_DISPLAY_DEBUG_CLUSTER_REFLECTION_PROBES,
|
2021-04-20 18:40:24 +02:00
|
|
|
VIEW_DISPLAY_DEBUG_OCCLUDERS,
|
2022-04-04 16:10:22 +02:00
|
|
|
VIEW_DISPLAY_MOTION_VECTORS,
|
2021-01-17 17:25:38 +01:00
|
|
|
|
2018-07-27 00:36:05 +02:00
|
|
|
VIEW_LOCK_ROTATION,
|
2019-10-03 22:39:08 +02:00
|
|
|
VIEW_CINEMATIC_PREVIEW,
|
2019-10-23 11:46:26 +02:00
|
|
|
VIEW_AUTO_ORTHOGONAL,
|
2019-10-03 22:39:08 +02:00
|
|
|
VIEW_MAX
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2021-08-14 09:24:02 +02:00
|
|
|
enum ViewType {
|
|
|
|
VIEW_TYPE_USER,
|
|
|
|
VIEW_TYPE_TOP,
|
|
|
|
VIEW_TYPE_BOTTOM,
|
|
|
|
VIEW_TYPE_LEFT,
|
|
|
|
VIEW_TYPE_RIGHT,
|
|
|
|
VIEW_TYPE_FRONT,
|
|
|
|
VIEW_TYPE_REAR,
|
|
|
|
};
|
|
|
|
|
2014-10-12 07:13:22 +02:00
|
|
|
public:
|
2014-05-05 03:50:23 +02:00
|
|
|
enum {
|
2014-10-12 07:13:22 +02:00
|
|
|
GIZMO_BASE_LAYER = 27,
|
2014-10-16 05:06:34 +02:00
|
|
|
GIZMO_EDIT_LAYER = 26,
|
2020-04-10 19:18:42 +02:00
|
|
|
GIZMO_GRID_LAYER = 25,
|
2020-11-26 20:00:03 +01:00
|
|
|
MISC_TOOL_LAYER = 24,
|
2020-04-10 19:18:42 +02:00
|
|
|
|
|
|
|
FRAME_TIME_HISTORY = 20,
|
2014-05-05 03:50:23 +02:00
|
|
|
};
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2019-04-22 07:41:17 +02:00
|
|
|
enum NavigationScheme {
|
|
|
|
NAVIGATION_GODOT,
|
|
|
|
NAVIGATION_MAYA,
|
|
|
|
NAVIGATION_MODO,
|
|
|
|
};
|
|
|
|
|
2020-04-18 16:20:35 +02:00
|
|
|
enum FreelookNavigationScheme {
|
|
|
|
FREELOOK_DEFAULT,
|
|
|
|
FREELOOK_PARTIALLY_AXIS_LOCKED,
|
|
|
|
FREELOOK_FULLY_AXIS_LOCKED,
|
|
|
|
};
|
|
|
|
|
2014-10-12 07:13:22 +02:00
|
|
|
private:
|
2021-02-02 03:16:37 +01:00
|
|
|
double cpu_time_history[FRAME_TIME_HISTORY];
|
2020-04-10 19:18:42 +02:00
|
|
|
int cpu_time_history_index;
|
2021-02-02 03:16:37 +01:00
|
|
|
double gpu_time_history[FRAME_TIME_HISTORY];
|
2020-04-10 19:18:42 +02:00
|
|
|
int gpu_time_history_index;
|
|
|
|
|
2014-05-05 03:50:23 +02:00
|
|
|
int index;
|
2021-08-14 09:24:02 +02:00
|
|
|
ViewType view_type;
|
2014-02-10 02:10:30 +01:00
|
|
|
void _menu_option(int p_option);
|
2019-10-23 11:46:26 +02:00
|
|
|
void _set_auto_orthogonal();
|
2022-04-04 15:06:57 +02:00
|
|
|
Node3D *preview_node = nullptr;
|
|
|
|
AABB *preview_bounds = nullptr;
|
2017-09-02 21:47:16 +02:00
|
|
|
Vector<String> selected_files;
|
2022-04-04 15:06:57 +02:00
|
|
|
AcceptDialog *accept = nullptr;
|
2017-09-02 21:47:16 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Node *target_node = nullptr;
|
2017-09-02 21:47:16 +02:00
|
|
|
Point2 drop_pos;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
EditorData *editor_data = nullptr;
|
|
|
|
EditorSelection *editor_selection = nullptr;
|
2022-03-25 18:06:46 +01:00
|
|
|
Ref<EditorUndoRedoManager> undo_redo;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
CheckBox *preview_camera = nullptr;
|
|
|
|
SubViewportContainer *subviewport_container = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
MenuButton *view_menu = nullptr;
|
|
|
|
PopupMenu *display_submenu = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Control *surface = nullptr;
|
|
|
|
SubViewport *viewport = nullptr;
|
|
|
|
Camera3D *camera = nullptr;
|
2022-05-02 16:28:25 +02:00
|
|
|
bool transforming = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
bool orthogonal;
|
2019-10-23 11:46:26 +02:00
|
|
|
bool auto_orthogonal;
|
2018-06-25 03:24:31 +02:00
|
|
|
bool lock_rotation;
|
2021-06-21 05:30:19 +02:00
|
|
|
real_t gizmo_scale;
|
2017-05-07 22:59:05 +02:00
|
|
|
|
|
|
|
bool freelook_active;
|
2017-10-08 02:43:57 +02:00
|
|
|
real_t freelook_speed;
|
2020-06-17 20:02:46 +02:00
|
|
|
Vector2 previous_mouse_position;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Label *info_label = nullptr;
|
|
|
|
Label *cinema_label = nullptr;
|
|
|
|
Label *locked_label = nullptr;
|
|
|
|
Label *zoom_limit_label = nullptr;
|
2017-11-19 21:00:16 +01:00
|
|
|
|
2022-04-23 14:32:55 +02:00
|
|
|
Label *preview_material_label = nullptr;
|
|
|
|
Label *preview_material_label_desc = nullptr;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
VBoxContainer *top_right_vbox = nullptr;
|
|
|
|
ViewportRotationControl *rotation_control = nullptr;
|
|
|
|
Gradient *frame_time_gradient = nullptr;
|
|
|
|
Label *cpu_time_label = nullptr;
|
|
|
|
Label *gpu_time_label = nullptr;
|
|
|
|
Label *fps_label = nullptr;
|
2019-10-23 11:46:26 +02:00
|
|
|
|
2015-11-04 22:39:07 +01:00
|
|
|
struct _RayResult {
|
2020-11-24 10:12:55 +01:00
|
|
|
Node3D *item = nullptr;
|
2021-06-21 05:30:19 +02:00
|
|
|
real_t depth = 0;
|
2015-11-04 22:39:07 +01:00
|
|
|
_FORCE_INLINE_ bool operator<(const _RayResult &p_rr) const { return depth < p_rr.depth; }
|
|
|
|
};
|
|
|
|
|
2015-03-21 21:47:21 +01:00
|
|
|
void _update_name();
|
2022-02-09 09:39:28 +01:00
|
|
|
void _compute_edit(const Point2 &p_point);
|
2014-02-10 02:10:30 +01:00
|
|
|
void _clear_selected();
|
2021-06-23 16:49:50 +02:00
|
|
|
void _select_clicked(bool p_allow_locked);
|
2022-04-23 14:32:55 +02:00
|
|
|
ObjectID _select_ray(const Point2 &p_pos) const;
|
2021-06-23 16:49:50 +02:00
|
|
|
void _find_items_at_pos(const Point2 &p_pos, Vector<_RayResult> &r_results, bool p_include_locked);
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 _get_ray_pos(const Vector2 &p_pos) const;
|
2017-09-02 21:47:16 +02:00
|
|
|
Vector3 _get_ray(const Vector2 &p_pos) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
Point2 _point_to_screen(const Vector3 &p_point);
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D _get_camera_transform() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_selected_count() const;
|
2020-07-18 21:03:08 +02:00
|
|
|
void cancel_transform();
|
2022-06-03 02:12:41 +02:00
|
|
|
void _update_shrink();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
Vector3 _get_camera_position() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 _get_camera_normal() const;
|
|
|
|
Vector3 _get_screen_to_space(const Vector3 &p_vector3);
|
|
|
|
|
|
|
|
void _select_region();
|
2021-06-23 16:49:50 +02:00
|
|
|
bool _transform_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only = false);
|
|
|
|
void _transform_gizmo_apply(Node3D *p_node, const Transform3D &p_transform, bool p_local);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-01 21:49:39 +01:00
|
|
|
void _nav_pan(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative);
|
|
|
|
void _nav_zoom(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative);
|
|
|
|
void _nav_orbit(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative);
|
|
|
|
void _nav_look(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
float get_znear() const;
|
|
|
|
float get_zfar() const;
|
|
|
|
float get_fov() const;
|
|
|
|
|
|
|
|
ObjectID clicked;
|
2022-04-23 14:32:55 +02:00
|
|
|
ObjectID material_target;
|
2015-11-04 22:39:07 +01:00
|
|
|
Vector<_RayResult> selection_results;
|
2022-05-02 16:28:25 +02:00
|
|
|
bool clicked_wants_append = false;
|
2022-02-10 00:24:52 +01:00
|
|
|
bool selection_in_progress = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
PopupMenu *selection_menu = nullptr;
|
2015-11-04 22:39:07 +01:00
|
|
|
|
2014-12-28 14:01:08 +01:00
|
|
|
enum NavigationZoomStyle {
|
|
|
|
NAVIGATION_ZOOM_VERTICAL,
|
|
|
|
NAVIGATION_ZOOM_HORIZONTAL
|
|
|
|
};
|
|
|
|
|
2014-03-31 05:07:21 +02:00
|
|
|
enum NavigationMode {
|
|
|
|
NAVIGATION_NONE,
|
|
|
|
NAVIGATION_PAN,
|
|
|
|
NAVIGATION_ZOOM,
|
2017-05-01 20:57:35 +02:00
|
|
|
NAVIGATION_ORBIT,
|
|
|
|
NAVIGATION_LOOK
|
2014-03-31 05:07:21 +02:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
enum TransformMode {
|
|
|
|
TRANSFORM_NONE,
|
|
|
|
TRANSFORM_ROTATE,
|
|
|
|
TRANSFORM_TRANSLATE,
|
|
|
|
TRANSFORM_SCALE
|
|
|
|
|
|
|
|
};
|
|
|
|
enum TransformPlane {
|
|
|
|
TRANSFORM_VIEW,
|
|
|
|
TRANSFORM_X_AXIS,
|
|
|
|
TRANSFORM_Y_AXIS,
|
|
|
|
TRANSFORM_Z_AXIS,
|
2017-08-29 03:39:45 +02:00
|
|
|
TRANSFORM_YZ,
|
|
|
|
TRANSFORM_XZ,
|
|
|
|
TRANSFORM_XY,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EditData {
|
|
|
|
TransformMode mode;
|
|
|
|
TransformPlane plane;
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D original;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 click_ray;
|
|
|
|
Vector3 click_ray_pos;
|
|
|
|
Vector3 center;
|
|
|
|
Point2 mouse_pos;
|
2021-06-04 17:39:46 +02:00
|
|
|
Point2 original_mouse_pos;
|
2020-11-24 10:12:55 +01:00
|
|
|
bool snap = false;
|
2022-01-17 15:48:21 +01:00
|
|
|
bool show_rotation_line = false;
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<EditorNode3DGizmo> gizmo;
|
2020-11-24 10:12:55 +01:00
|
|
|
int gizmo_handle = 0;
|
2022-01-11 12:33:37 +01:00
|
|
|
bool gizmo_handle_secondary = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant gizmo_initial_value;
|
2020-07-18 21:03:08 +02:00
|
|
|
bool original_local;
|
|
|
|
bool instant;
|
2014-02-10 02:10:30 +01:00
|
|
|
} _edit;
|
|
|
|
|
|
|
|
struct Cursor {
|
|
|
|
Vector3 pos;
|
2021-10-15 00:00:27 +02:00
|
|
|
real_t x_rot, y_rot, distance, fov_scale;
|
2017-10-08 02:43:57 +02:00
|
|
|
Vector3 eye_pos; // Used in freelook mode
|
2014-02-10 02:10:30 +01:00
|
|
|
bool region_select;
|
|
|
|
Point2 region_begin, region_end;
|
|
|
|
|
2017-01-15 15:28:34 +01:00
|
|
|
Cursor() {
|
2020-06-07 19:21:29 +02:00
|
|
|
// These rotations place the camera in +X +Y +Z, aka south east, facing north west.
|
|
|
|
x_rot = 0.5;
|
|
|
|
y_rot = -0.5;
|
2017-01-15 15:28:34 +01:00
|
|
|
distance = 4;
|
2021-10-15 00:00:27 +02:00
|
|
|
fov_scale = 1.0;
|
2017-01-15 15:28:34 +01:00
|
|
|
region_select = false;
|
|
|
|
}
|
2017-10-08 02:43:57 +02:00
|
|
|
};
|
|
|
|
// Viewport camera supports movement smoothing,
|
|
|
|
// so one cursor is the real cursor, while the other can be an interpolated version.
|
|
|
|
Cursor cursor; // Immediate cursor
|
|
|
|
Cursor camera_cursor; // That one may be interpolated (don't modify this one except for smoothing purposes)
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-10-15 00:00:27 +02:00
|
|
|
void scale_fov(real_t p_fov_offset);
|
|
|
|
void reset_fov();
|
2017-05-07 22:59:05 +02:00
|
|
|
void scale_cursor_distance(real_t scale);
|
|
|
|
|
2017-10-08 02:43:57 +02:00
|
|
|
void set_freelook_active(bool active_now);
|
|
|
|
void scale_freelook_speed(real_t scale);
|
|
|
|
|
2017-05-07 22:59:05 +02:00
|
|
|
real_t zoom_indicator_delay;
|
2021-04-09 14:52:10 +02:00
|
|
|
int zoom_failed_attempts_count = 0;
|
2017-05-07 22:59:05 +02:00
|
|
|
|
2020-07-18 21:03:08 +02:00
|
|
|
RID move_gizmo_instance[3], move_plane_gizmo_instance[3], rotate_gizmo_instance[4], scale_gizmo_instance[3], scale_plane_gizmo_instance[3], axis_gizmo_instance[3];
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String last_message;
|
|
|
|
String message;
|
2021-02-02 03:16:37 +01:00
|
|
|
double message_time;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void set_message(String p_message, float p_time = 5);
|
|
|
|
|
2021-10-15 00:00:27 +02:00
|
|
|
void _view_settings_confirmed(real_t p_interp_delta);
|
2021-06-21 05:30:19 +02:00
|
|
|
void _update_camera(real_t p_interp_delta);
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D to_camera_transform(const Cursor &p_cursor) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
void _draw();
|
|
|
|
|
2017-12-19 15:29:55 +01:00
|
|
|
void _surface_mouse_enter();
|
|
|
|
void _surface_mouse_exit();
|
|
|
|
void _surface_focus_enter();
|
|
|
|
void _surface_focus_exit();
|
|
|
|
|
2017-08-12 18:52:50 +02:00
|
|
|
void _sinput(const Ref<InputEvent> &p_event);
|
2017-05-01 20:57:35 +02:00
|
|
|
void _update_freelook(real_t delta);
|
2022-04-04 15:06:57 +02:00
|
|
|
Node3DEditor *spatial_editor = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Camera3D *previewing = nullptr;
|
2022-02-28 15:47:35 +01:00
|
|
|
Camera3D *preview = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-27 00:36:05 +02:00
|
|
|
bool previewing_cinema;
|
2019-07-15 21:50:00 +02:00
|
|
|
bool _is_node_locked(const Node *p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
void _preview_exited_scene();
|
|
|
|
void _toggle_camera_preview(bool);
|
2018-07-27 00:36:05 +02:00
|
|
|
void _toggle_cinema_preview(bool);
|
2014-05-05 03:50:23 +02:00
|
|
|
void _init_gizmo_instance(int p_idx);
|
2015-04-21 00:38:02 +02:00
|
|
|
void _finish_gizmo_instances();
|
2015-11-04 22:39:07 +01:00
|
|
|
void _selection_result_pressed(int);
|
|
|
|
void _selection_menu_hide();
|
2017-05-20 17:38:03 +02:00
|
|
|
void _list_select(Ref<InputEventMouseButton> b);
|
|
|
|
Point2i _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const;
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2017-09-02 21:47:16 +02:00
|
|
|
Vector3 _get_instance_position(const Point2 &p_pos) const;
|
2020-10-02 23:03:52 +02:00
|
|
|
static AABB _calculate_spatial_bounds(const Node3D *p_parent, bool p_exclude_top_level_transform = true);
|
2021-12-30 15:07:56 +01:00
|
|
|
|
|
|
|
Node *_sanitize_preview_node(Node *p_node) const;
|
|
|
|
|
2022-04-23 14:32:55 +02:00
|
|
|
void _create_preview_node(const Vector<String> &files) const;
|
|
|
|
void _remove_preview_node();
|
|
|
|
bool _apply_preview_material(ObjectID p_target, const Point2 &p_point) const;
|
|
|
|
void _reset_preview_material() const;
|
|
|
|
void _remove_preview_material();
|
2017-09-02 21:47:16 +02:00
|
|
|
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
|
|
|
|
bool _create_instance(Node *parent, String &path, const Point2 &p_point);
|
|
|
|
void _perform_drop_data();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-02-13 15:06:56 +01:00
|
|
|
void _project_settings_changed();
|
|
|
|
|
2021-10-09 12:24:26 +02:00
|
|
|
Transform3D _compute_transform(TransformMode p_mode, const Transform3D &p_original, const Transform3D &p_original_local, Vector3 p_motion, double p_extra, bool p_local, bool p_orthogonal);
|
2021-06-23 16:49:50 +02:00
|
|
|
|
2020-07-18 21:03:08 +02:00
|
|
|
void begin_transform(TransformMode p_mode, bool instant);
|
|
|
|
void commit_transform();
|
|
|
|
void update_transform(Point2 p_mousepos, bool p_shift);
|
2022-02-10 14:23:10 +01:00
|
|
|
void finish_transform();
|
2020-07-18 21:03:08 +02:00
|
|
|
|
2021-11-02 16:02:31 +01:00
|
|
|
void register_shortcut_action(const String &p_path, const String &p_name, Key p_keycode);
|
|
|
|
void shortcut_changed_callback(const Ref<Shortcut> p_shortcut, const String &p_shortcut_path);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2022-08-13 23:21:24 +02:00
|
|
|
void update_surface() { surface->queue_redraw(); }
|
2014-05-05 03:50:23 +02:00
|
|
|
void update_transform_gizmo_view();
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void set_can_preview(Camera3D *p_preview);
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_state(const Dictionary &p_state);
|
|
|
|
Dictionary get_state() const;
|
2014-09-19 23:39:50 +02:00
|
|
|
void reset();
|
2017-05-07 22:59:05 +02:00
|
|
|
bool is_freelook_active() const { return freelook_active; }
|
2016-07-28 21:37:52 +02:00
|
|
|
|
|
|
|
void focus_selection();
|
|
|
|
|
2017-09-02 21:47:16 +02:00
|
|
|
void assign_pending_data_pointers(
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3D *p_preview_node,
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB *p_preview_bounds,
|
2017-09-02 21:47:16 +02:00
|
|
|
AcceptDialog *p_accept);
|
|
|
|
|
2020-03-04 02:51:12 +01:00
|
|
|
SubViewport *get_viewport_node() { return viewport; }
|
2020-04-28 17:04:07 +02:00
|
|
|
Camera3D *get_camera_3d() { return camera; } // return the default camera object.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p_index);
|
2021-01-04 10:06:46 +01:00
|
|
|
~Node3DEditorViewport();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
class Node3DEditorSelectedItem : public Object {
|
|
|
|
GDCLASS(Node3DEditorSelectedItem, Object);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
public:
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D original; // original location when moving
|
|
|
|
Transform3D original_local;
|
|
|
|
Transform3D last_xform; // last transform
|
2020-03-19 07:43:25 +01:00
|
|
|
bool last_xform_dirty;
|
2022-04-04 15:06:57 +02:00
|
|
|
Node3D *sp = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
RID sbox_instance;
|
2021-08-09 16:51:30 +02:00
|
|
|
RID sbox_instance_offset;
|
2020-07-04 00:11:56 +02:00
|
|
|
RID sbox_instance_xray;
|
2021-08-09 16:51:30 +02:00
|
|
|
RID sbox_instance_xray_offset;
|
2021-06-23 16:49:50 +02:00
|
|
|
Ref<EditorNode3DGizmo> gizmo;
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<int, Transform3D> subgizmos; // map ID -> initial transform
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditorSelectedItem() {
|
2020-04-02 01:20:12 +02:00
|
|
|
sp = nullptr;
|
2020-03-19 07:43:25 +01:00
|
|
|
last_xform_dirty = true;
|
|
|
|
}
|
2020-03-26 22:49:16 +01:00
|
|
|
~Node3DEditorSelectedItem();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
class Node3DEditorViewportContainer : public Container {
|
|
|
|
GDCLASS(Node3DEditorViewportContainer, Container);
|
2019-03-19 19:35:57 +01:00
|
|
|
|
2017-06-11 16:29:27 +02:00
|
|
|
public:
|
|
|
|
enum View {
|
|
|
|
VIEW_USE_1_VIEWPORT,
|
|
|
|
VIEW_USE_2_VIEWPORTS,
|
|
|
|
VIEW_USE_2_VIEWPORTS_ALT,
|
|
|
|
VIEW_USE_3_VIEWPORTS,
|
|
|
|
VIEW_USE_3_VIEWPORTS_ALT,
|
|
|
|
VIEW_USE_4_VIEWPORTS,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
View view;
|
|
|
|
bool mouseover;
|
2021-06-21 05:30:19 +02:00
|
|
|
real_t ratio_h;
|
|
|
|
real_t ratio_v;
|
2017-06-11 16:29:27 +02:00
|
|
|
|
2018-08-25 08:47:04 +02:00
|
|
|
bool hovering_v;
|
|
|
|
bool hovering_h;
|
|
|
|
|
2017-06-11 16:29:27 +02:00
|
|
|
bool dragging_v;
|
|
|
|
bool dragging_h;
|
|
|
|
Vector2 drag_begin_pos;
|
|
|
|
Vector2 drag_begin_ratio;
|
|
|
|
|
2021-08-22 17:37:22 +02:00
|
|
|
virtual void gui_input(const Ref<InputEvent> &p_event) override;
|
2017-06-11 16:29:27 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_view(View p_view);
|
|
|
|
View get_view();
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditorViewportContainer();
|
2017-06-11 16:29:27 +02:00
|
|
|
};
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
class Node3DEditor : public VBoxContainer {
|
|
|
|
GDCLASS(Node3DEditor, VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-10-29 20:32:09 +01:00
|
|
|
static const unsigned int VIEWPORTS_COUNT = 4;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
enum ToolMode {
|
|
|
|
TOOL_MODE_SELECT,
|
|
|
|
TOOL_MODE_MOVE,
|
|
|
|
TOOL_MODE_ROTATE,
|
2015-12-13 21:16:13 +01:00
|
|
|
TOOL_MODE_SCALE,
|
|
|
|
TOOL_MODE_LIST_SELECT,
|
2017-10-23 21:21:15 +02:00
|
|
|
TOOL_LOCK_SELECTED,
|
|
|
|
TOOL_UNLOCK_SELECTED,
|
2019-04-17 18:24:28 +02:00
|
|
|
TOOL_GROUP_SELECTED,
|
|
|
|
TOOL_UNGROUP_SELECTED,
|
2015-12-13 21:16:13 +01:00
|
|
|
TOOL_MAX
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-11-18 19:51:37 +01:00
|
|
|
enum ToolOptions {
|
|
|
|
TOOL_OPT_LOCAL_COORDS,
|
|
|
|
TOOL_OPT_USE_SNAP,
|
2019-04-06 22:55:01 +02:00
|
|
|
TOOL_OPT_OVERRIDE_CAMERA,
|
2017-11-18 19:51:37 +01:00
|
|
|
TOOL_OPT_MAX
|
2022-02-09 09:39:28 +01:00
|
|
|
|
2017-11-18 19:51:37 +01:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
private:
|
2022-04-04 15:06:57 +02:00
|
|
|
EditorSelection *editor_selection = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Node3DEditorViewportContainer *viewport_base = nullptr;
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditorViewport *viewports[VIEWPORTS_COUNT];
|
2022-04-04 15:06:57 +02:00
|
|
|
VSplitContainer *shader_split = nullptr;
|
|
|
|
HSplitContainer *left_panel_split = nullptr;
|
|
|
|
HSplitContainer *right_panel_split = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/////
|
|
|
|
|
|
|
|
ToolMode tool_mode;
|
|
|
|
|
|
|
|
RID origin;
|
|
|
|
RID origin_instance;
|
2022-05-02 16:28:25 +02:00
|
|
|
bool origin_enabled = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
RID grid[3];
|
|
|
|
RID grid_instance[3];
|
|
|
|
bool grid_visible[3]; //currently visible
|
|
|
|
bool grid_enable[3]; //should be always visible if true
|
2022-05-02 16:28:25 +02:00
|
|
|
bool grid_enabled = false;
|
2021-08-08 17:08:37 +02:00
|
|
|
bool grid_init_draw = false;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 01:11:13 +02:00
|
|
|
Camera3D::ProjectionType grid_camera_last_update_perspective = Camera3D::PROJECTION_PERSPECTIVE;
|
2021-08-08 17:08:37 +02:00
|
|
|
Vector3 grid_camera_last_update_position = Vector3();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-07-18 21:03:08 +02:00
|
|
|
Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[4], scale_gizmo[3], scale_plane_gizmo[3], axis_gizmo[3];
|
2019-09-15 06:01:52 +02:00
|
|
|
Ref<StandardMaterial3D> gizmo_color[3];
|
|
|
|
Ref<StandardMaterial3D> plane_gizmo_color[3];
|
2020-09-13 18:22:51 +02:00
|
|
|
Ref<ShaderMaterial> rotate_gizmo_color[3];
|
2019-09-15 06:01:52 +02:00
|
|
|
Ref<StandardMaterial3D> gizmo_color_hl[3];
|
|
|
|
Ref<StandardMaterial3D> plane_gizmo_color_hl[3];
|
2020-09-13 18:22:51 +02:00
|
|
|
Ref<ShaderMaterial> rotate_gizmo_color_hl[3];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
Ref<Node3DGizmo> current_hover_gizmo;
|
|
|
|
int current_hover_gizmo_handle;
|
2022-01-11 12:33:37 +01:00
|
|
|
bool current_hover_gizmo_handle_secondary;
|
2021-06-23 16:49:50 +02:00
|
|
|
|
2021-06-21 05:30:19 +02:00
|
|
|
real_t snap_translate_value;
|
|
|
|
real_t snap_rotate_value;
|
|
|
|
real_t snap_scale_value;
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2020-07-04 00:11:56 +02:00
|
|
|
Ref<ArrayMesh> selection_box_xray;
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> selection_box;
|
2014-02-10 02:10:30 +01:00
|
|
|
RID indicators;
|
2016-03-09 00:00:52 +01:00
|
|
|
RID indicators_instance;
|
2014-02-10 02:10:30 +01:00
|
|
|
RID cursor_mesh;
|
|
|
|
RID cursor_instance;
|
2019-09-15 06:01:52 +02:00
|
|
|
Ref<StandardMaterial3D> indicator_mat;
|
2021-01-29 16:12:50 +01:00
|
|
|
Ref<ShaderMaterial> grid_mat[3];
|
2019-09-15 06:01:52 +02:00
|
|
|
Ref<StandardMaterial3D> cursor_material;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-02 21:47:16 +02:00
|
|
|
// Scene drag and drop support
|
2022-04-04 15:06:57 +02:00
|
|
|
Node3D *preview_node = nullptr;
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB preview_bounds;
|
2017-09-02 21:47:16 +02:00
|
|
|
|
2022-04-23 14:32:55 +02:00
|
|
|
Ref<Material> preview_material;
|
|
|
|
Ref<Material> preview_reset_material;
|
|
|
|
ObjectID preview_material_target;
|
|
|
|
int preview_material_surface = -1;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct Gizmo {
|
2020-11-24 10:12:55 +01:00
|
|
|
bool visible = false;
|
2021-06-21 05:30:19 +02:00
|
|
|
real_t scale = 0;
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D transform;
|
2014-02-10 02:10:30 +01:00
|
|
|
} gizmo;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-02-09 09:39:28 +01:00
|
|
|
enum MenuOption {
|
|
|
|
MENU_TOOL_SELECT,
|
|
|
|
MENU_TOOL_MOVE,
|
|
|
|
MENU_TOOL_ROTATE,
|
|
|
|
MENU_TOOL_SCALE,
|
|
|
|
MENU_TOOL_LIST_SELECT,
|
|
|
|
MENU_TOOL_LOCAL_COORDS,
|
|
|
|
MENU_TOOL_USE_SNAP,
|
|
|
|
MENU_TOOL_OVERRIDE_CAMERA,
|
|
|
|
MENU_TRANSFORM_CONFIGURE_SNAP,
|
|
|
|
MENU_TRANSFORM_DIALOG,
|
|
|
|
MENU_VIEW_USE_1_VIEWPORT,
|
|
|
|
MENU_VIEW_USE_2_VIEWPORTS,
|
|
|
|
MENU_VIEW_USE_2_VIEWPORTS_ALT,
|
|
|
|
MENU_VIEW_USE_3_VIEWPORTS,
|
|
|
|
MENU_VIEW_USE_3_VIEWPORTS_ALT,
|
|
|
|
MENU_VIEW_USE_4_VIEWPORTS,
|
|
|
|
MENU_VIEW_ORIGIN,
|
|
|
|
MENU_VIEW_GRID,
|
|
|
|
MENU_VIEW_GIZMOS_3D_ICONS,
|
|
|
|
MENU_VIEW_CAMERA_SETTINGS,
|
|
|
|
MENU_LOCK_SELECTED,
|
|
|
|
MENU_UNLOCK_SELECTED,
|
|
|
|
MENU_GROUP_SELECTED,
|
|
|
|
MENU_UNGROUP_SELECTED,
|
|
|
|
MENU_SNAP_TO_FLOOR
|
|
|
|
};
|
|
|
|
|
2015-12-13 21:16:13 +01:00
|
|
|
Button *tool_button[TOOL_MAX];
|
2017-11-18 19:51:37 +01:00
|
|
|
Button *tool_option_button[TOOL_OPT_MAX];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
MenuButton *transform_menu = nullptr;
|
|
|
|
PopupMenu *gizmos_menu = nullptr;
|
|
|
|
MenuButton *view_menu = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
AcceptDialog *accept = nullptr;
|
2017-09-02 21:47:16 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
ConfirmationDialog *snap_dialog = nullptr;
|
|
|
|
ConfirmationDialog *xform_dialog = nullptr;
|
|
|
|
ConfirmationDialog *settings_dialog = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
bool snap_enabled;
|
2018-02-21 15:14:26 +01:00
|
|
|
bool snap_key_enabled;
|
2022-04-04 15:06:57 +02:00
|
|
|
LineEdit *snap_translate = nullptr;
|
|
|
|
LineEdit *snap_rotate = nullptr;
|
|
|
|
LineEdit *snap_scale = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
LineEdit *xform_translate[3];
|
|
|
|
LineEdit *xform_rotate[3];
|
|
|
|
LineEdit *xform_scale[3];
|
2022-04-04 15:06:57 +02:00
|
|
|
OptionButton *xform_type = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
VBoxContainer *settings_vbc = nullptr;
|
|
|
|
SpinBox *settings_fov = nullptr;
|
|
|
|
SpinBox *settings_znear = nullptr;
|
|
|
|
SpinBox *settings_zfar = nullptr;
|
2014-10-12 07:13:22 +02:00
|
|
|
|
2020-03-08 20:31:11 +01:00
|
|
|
void _snap_changed();
|
|
|
|
void _snap_update();
|
2014-02-10 02:10:30 +01:00
|
|
|
void _xform_dialog_action();
|
|
|
|
void _menu_item_pressed(int p_option);
|
2017-11-18 19:51:37 +01:00
|
|
|
void _menu_item_toggled(bool pressed, int p_option);
|
2018-07-25 00:08:49 +02:00
|
|
|
void _menu_gizmo_toggled(int p_option);
|
2019-04-06 22:55:01 +02:00
|
|
|
void _update_camera_override_button(bool p_game_running);
|
|
|
|
void _update_camera_override_viewport(Object *p_viewport);
|
2020-02-03 20:07:21 +01:00
|
|
|
// Used for secondary menu items which are displayed depending on the currently selected node
|
|
|
|
// (such as MeshInstance's "Mesh" menu).
|
2022-07-20 03:00:25 +02:00
|
|
|
PanelContainer *context_menu_panel = nullptr;
|
|
|
|
HBoxContainer *context_menu_hbox = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-07-04 00:11:56 +02:00
|
|
|
void _generate_selection_boxes();
|
2022-03-25 18:06:46 +01:00
|
|
|
Ref<EditorUndoRedoManager> undo_redo;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-06 22:55:01 +02:00
|
|
|
int camera_override_viewport_id;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _init_indicators();
|
2018-10-29 11:30:28 +01:00
|
|
|
void _update_gizmos_menu();
|
2019-02-15 18:32:38 +01:00
|
|
|
void _update_gizmos_menu_theme();
|
2017-12-08 23:45:33 +01:00
|
|
|
void _init_grid();
|
2014-02-10 02:10:30 +01:00
|
|
|
void _finish_indicators();
|
2017-12-08 23:45:33 +01:00
|
|
|
void _finish_grid();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-04-01 12:45:48 +02:00
|
|
|
void _toggle_maximize_view(Object *p_viewport);
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Node *custom_camera = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Object *_get_editor_data(Object *p_what);
|
|
|
|
|
|
|
|
Ref<Environment> viewport_environment;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Node3D *selected = nullptr;
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _request_gizmo(Object *p_obj);
|
2021-02-04 09:20:26 +01:00
|
|
|
void _set_subgizmo_selection(Object *p_obj, Ref<Node3DGizmo> p_gizmo, int p_id, Transform3D p_transform = Transform3D());
|
2021-06-23 16:49:50 +02:00
|
|
|
void _clear_subgizmo_selection(Object *p_obj = nullptr);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
static Node3DEditor *singleton;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-02-22 14:54:12 +01:00
|
|
|
void _node_added(Node *p_node);
|
2014-05-05 03:50:23 +02:00
|
|
|
void _node_removed(Node *p_node);
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector<Ref<EditorNode3DGizmoPlugin>> gizmo_plugins_by_priority;
|
|
|
|
Vector<Ref<EditorNode3DGizmoPlugin>> gizmo_plugins_by_name;
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
void _register_all_gizmos();
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
void _selection_changed();
|
2017-10-23 21:21:15 +02:00
|
|
|
void _refresh_menu_icons();
|
|
|
|
|
2021-02-22 14:54:12 +01:00
|
|
|
// Preview Sun and Environment
|
|
|
|
|
|
|
|
uint32_t world_env_count = 0;
|
|
|
|
uint32_t directional_light_count = 0;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Button *sun_button = nullptr;
|
|
|
|
Label *sun_state = nullptr;
|
|
|
|
Label *sun_title = nullptr;
|
|
|
|
VBoxContainer *sun_vb = nullptr;
|
|
|
|
Popup *sun_environ_popup = nullptr;
|
|
|
|
Control *sun_direction = nullptr;
|
|
|
|
EditorSpinSlider *sun_angle_altitude = nullptr;
|
|
|
|
EditorSpinSlider *sun_angle_azimuth = nullptr;
|
|
|
|
ColorPickerButton *sun_color = nullptr;
|
|
|
|
EditorSpinSlider *sun_energy = nullptr;
|
|
|
|
EditorSpinSlider *sun_max_distance = nullptr;
|
|
|
|
Button *sun_add_to_scene = nullptr;
|
2021-02-22 14:54:12 +01:00
|
|
|
|
|
|
|
void _sun_direction_draw();
|
|
|
|
void _sun_direction_input(const Ref<InputEvent> &p_event);
|
2021-02-22 22:20:44 +01:00
|
|
|
void _sun_direction_angle_set();
|
2021-02-22 14:54:12 +01:00
|
|
|
|
2021-02-22 22:20:44 +01:00
|
|
|
Vector2 sun_rotation;
|
2021-02-22 14:54:12 +01:00
|
|
|
|
|
|
|
Ref<Shader> sun_direction_shader;
|
|
|
|
Ref<ShaderMaterial> sun_direction_material;
|
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Button *environ_button = nullptr;
|
|
|
|
Label *environ_state = nullptr;
|
|
|
|
Label *environ_title = nullptr;
|
|
|
|
VBoxContainer *environ_vb = nullptr;
|
|
|
|
ColorPickerButton *environ_sky_color = nullptr;
|
|
|
|
ColorPickerButton *environ_ground_color = nullptr;
|
|
|
|
EditorSpinSlider *environ_energy = nullptr;
|
|
|
|
Button *environ_ao_button = nullptr;
|
|
|
|
Button *environ_glow_button = nullptr;
|
|
|
|
Button *environ_tonemap_button = nullptr;
|
|
|
|
Button *environ_gi_button = nullptr;
|
|
|
|
Button *environ_add_to_scene = nullptr;
|
|
|
|
|
|
|
|
Button *sun_environ_settings = nullptr;
|
|
|
|
|
|
|
|
DirectionalLight3D *preview_sun = nullptr;
|
|
|
|
WorldEnvironment *preview_environment = nullptr;
|
2021-02-22 14:54:12 +01:00
|
|
|
Ref<Environment> environment;
|
2022-08-01 01:20:24 +02:00
|
|
|
Ref<CameraAttributesPhysical> camera_attributes;
|
2021-02-22 14:54:12 +01:00
|
|
|
Ref<ProceduralSkyMaterial> sky_material;
|
|
|
|
|
|
|
|
bool sun_environ_updating = false;
|
|
|
|
|
|
|
|
void _load_default_preview_settings();
|
|
|
|
void _update_preview_environment();
|
|
|
|
|
|
|
|
void _preview_settings_changed();
|
|
|
|
void _sun_environ_settings_pressed();
|
|
|
|
|
2021-07-07 00:41:37 +02:00
|
|
|
void _add_sun_to_scene(bool p_already_added_environment = false);
|
|
|
|
void _add_environment_to_scene(bool p_already_added_sun = false);
|
2021-02-22 14:54:12 +01:00
|
|
|
|
2022-08-29 11:04:31 +02:00
|
|
|
void _update_theme();
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
void _notification(int p_what);
|
2017-01-08 20:28:12 +01:00
|
|
|
//void _gui_input(InputEvent p_event);
|
2022-01-11 14:59:52 +01:00
|
|
|
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-03-26 22:49:16 +01:00
|
|
|
static Node3DEditor *get_singleton() { return singleton; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-18 23:44:04 +02:00
|
|
|
Vector3 snap_point(Vector3 p_target, Vector3 p_start = Vector3(0, 0, 0)) const;
|
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
float get_znear() const { return settings_znear->get_value(); }
|
|
|
|
float get_zfar() const { return settings_zfar->get_value(); }
|
|
|
|
float get_fov() const { return settings_fov->get_value(); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D get_gizmo_transform() const { return gizmo.transform; }
|
2021-02-04 09:20:26 +01:00
|
|
|
bool is_gizmo_visible() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ToolMode get_tool_mode() const { return tool_mode; }
|
2020-03-26 22:49:16 +01:00
|
|
|
bool are_local_coords_enabled() const { return tool_option_button[Node3DEditor::TOOL_OPT_LOCAL_COORDS]->is_pressed(); }
|
2020-07-18 21:03:08 +02:00
|
|
|
void set_local_coords_enabled(bool on) const { tool_option_button[Node3DEditor::TOOL_OPT_LOCAL_COORDS]->set_pressed(on); }
|
2018-02-21 15:14:26 +01:00
|
|
|
bool is_snap_enabled() const { return snap_enabled ^ snap_key_enabled; }
|
2021-06-21 05:30:19 +02:00
|
|
|
double get_translate_snap() const;
|
|
|
|
double get_rotate_snap() const;
|
|
|
|
double get_scale_snap() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; }
|
2020-07-18 21:03:08 +02:00
|
|
|
Ref<ArrayMesh> get_axis_gizmo(int idx) const { return axis_gizmo[idx]; }
|
2017-08-29 03:39:45 +02:00
|
|
|
Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; }
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; }
|
2017-09-21 23:11:56 +02:00
|
|
|
Ref<ArrayMesh> get_scale_gizmo(int idx) const { return scale_gizmo[idx]; }
|
2017-11-14 23:50:19 +01:00
|
|
|
Ref<ArrayMesh> get_scale_plane_gizmo(int idx) const { return scale_plane_gizmo[idx]; }
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2019-04-21 12:15:45 +02:00
|
|
|
void update_grid();
|
2014-02-10 02:10:30 +01:00
|
|
|
void update_transform_gizmo();
|
2020-04-02 01:20:12 +02:00
|
|
|
void update_all_gizmos(Node *p_node = nullptr);
|
2018-07-26 08:34:40 +02:00
|
|
|
void snap_selected_nodes_to_floor();
|
2017-04-06 17:35:08 +02:00
|
|
|
void select_gizmo_highlight_axis(int p_axis);
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_custom_camera(Node *p_camera) { custom_camera = p_camera; }
|
|
|
|
|
|
|
|
Dictionary get_state() const;
|
|
|
|
void set_state(const Dictionary &p_state);
|
|
|
|
|
|
|
|
Ref<Environment> get_viewport_environment() { return viewport_environment; }
|
|
|
|
|
2022-03-25 18:06:46 +01:00
|
|
|
void set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo);
|
|
|
|
Ref<EditorUndoRedoManager> get_undo_redo();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void add_control_to_menu_panel(Control *p_control);
|
2018-02-13 22:21:19 +01:00
|
|
|
void remove_control_from_menu_panel(Control *p_control);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-01-08 13:31:22 +01:00
|
|
|
void add_control_to_left_panel(Control *p_control);
|
|
|
|
void remove_control_from_left_panel(Control *p_control);
|
|
|
|
|
|
|
|
void add_control_to_right_panel(Control *p_control);
|
|
|
|
void remove_control_from_right_panel(Control *p_control);
|
|
|
|
|
|
|
|
void move_control_to_left_panel(Control *p_control);
|
|
|
|
void move_control_to_right_panel(Control *p_control);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
VSplitContainer *get_shader_split();
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
Node3D *get_single_selected_node() { return selected; }
|
|
|
|
bool is_current_selected_gizmo(const EditorNode3DGizmo *p_gizmo);
|
|
|
|
bool is_subgizmo_selected(int p_id);
|
|
|
|
Vector<int> get_subgizmo_selection();
|
|
|
|
|
|
|
|
Ref<EditorNode3DGizmo> get_current_hover_gizmo() const { return current_hover_gizmo; }
|
|
|
|
void set_current_hover_gizmo(Ref<EditorNode3DGizmo> p_gizmo) { current_hover_gizmo = p_gizmo; }
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2022-01-11 12:33:37 +01:00
|
|
|
void set_current_hover_gizmo_handle(int p_id, bool p_secondary) {
|
|
|
|
current_hover_gizmo_handle = p_id;
|
|
|
|
current_hover_gizmo_handle_secondary = p_secondary;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_current_hover_gizmo_handle(bool &r_secondary) const {
|
|
|
|
r_secondary = current_hover_gizmo_handle_secondary;
|
|
|
|
return current_hover_gizmo_handle;
|
|
|
|
}
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void set_can_preview(Camera3D *p_preview);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-23 14:32:55 +02:00
|
|
|
void set_preview_material(Ref<Material> p_material) { preview_material = p_material; }
|
|
|
|
Ref<Material> get_preview_material() { return preview_material; }
|
|
|
|
void set_preview_reset_material(Ref<Material> p_material) { preview_reset_material = p_material; }
|
|
|
|
Ref<Material> get_preview_reset_material() const { return preview_reset_material; }
|
|
|
|
void set_preview_material_target(ObjectID p_object_id) { preview_material_target = p_object_id; }
|
|
|
|
ObjectID get_preview_material_target() const { return preview_material_target; }
|
|
|
|
void set_preview_material_surface(int p_surface) { preview_material_surface = p_surface; }
|
|
|
|
int get_preview_material_surface() const { return preview_material_surface; }
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditorViewport *get_editor_viewport(int p_idx) {
|
2020-04-02 01:20:12 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, static_cast<int>(VIEWPORTS_COUNT), nullptr);
|
2015-05-31 06:59:42 +02:00
|
|
|
return viewports[p_idx];
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void add_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin);
|
|
|
|
void remove_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void edit(Node3D *p_spatial);
|
2014-09-19 23:39:50 +02:00
|
|
|
void clear();
|
2017-09-02 21:47:16 +02:00
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
Node3DEditor();
|
2020-03-26 22:49:16 +01:00
|
|
|
~Node3DEditor();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
class Node3DEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(Node3DEditorPlugin, EditorPlugin);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Node3DEditor *spatial_editor = nullptr;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditor *get_spatial_editor() { return spatial_editor; }
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual String get_name() const override { return "3D"; }
|
|
|
|
bool has_main_screen() const override { return true; }
|
|
|
|
virtual void make_visible(bool p_visible) override;
|
|
|
|
virtual void edit(Object *p_object) override;
|
|
|
|
virtual bool handles(Object *p_object) const override;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Dictionary get_state() const override;
|
|
|
|
virtual void set_state(const Dictionary &p_state) override;
|
|
|
|
virtual void clear() override { spatial_editor->clear(); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void edited_scene_changed() override;
|
2018-08-14 23:13:48 +02:00
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
Node3DEditorPlugin();
|
2020-03-26 22:49:16 +01:00
|
|
|
~Node3DEditorPlugin();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-10-17 17:52:17 +02:00
|
|
|
#endif // NODE_3D_EDITOR_PLUGIN_H
|