2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-03-27 07:44:44 +00:00
|
|
|
/* node_3d_editor_plugin.h */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00: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-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef SPATIAL_EDITOR_PLUGIN_H
|
|
|
|
#define SPATIAL_EDITOR_PLUGIN_H
|
|
|
|
|
2017-03-05 13:21:25 +00:00
|
|
|
#include "editor/editor_node.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor/editor_plugin.h"
|
2019-10-23 09:46:26 +00:00
|
|
|
#include "editor/editor_scale.h"
|
2020-03-26 21:49:16 +00:00
|
|
|
#include "scene/3d/immediate_geometry_3d.h"
|
|
|
|
#include "scene/3d/light_3d.h"
|
|
|
|
#include "scene/3d/visual_instance_3d.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/gui/panel_container.h"
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class Camera3D;
|
|
|
|
class Node3DEditor;
|
|
|
|
class EditorNode3DGizmoPlugin;
|
|
|
|
class Node3DEditorViewport;
|
2020-04-01 18:28:09 +00:00
|
|
|
class SubViewportContainer;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class EditorNode3DGizmo : public Node3DGizmo {
|
|
|
|
GDCLASS(EditorNode3DGizmo, Node3DGizmo);
|
2014-05-05 01:50:23 +00:00
|
|
|
|
|
|
|
bool selected;
|
2017-08-26 03:40:45 +00:00
|
|
|
bool instanced;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
|
|
|
void set_selected(bool p_selected) { selected = p_selected; }
|
2014-05-05 01:50:23 +00:00
|
|
|
bool is_selected() const { return selected; }
|
|
|
|
|
2018-07-24 22:08:49 +00:00
|
|
|
struct Instance {
|
|
|
|
RID instance;
|
|
|
|
Ref<ArrayMesh> mesh;
|
2019-02-23 23:20:54 +00:00
|
|
|
Ref<Material> material;
|
2019-09-18 22:46:32 +00:00
|
|
|
Ref<SkinReference> skin_reference;
|
2018-07-24 22:08:49 +00:00
|
|
|
RID skeleton;
|
|
|
|
bool billboard;
|
|
|
|
bool unscaled;
|
|
|
|
bool can_intersect;
|
|
|
|
bool extra_margin;
|
|
|
|
Instance() {
|
|
|
|
billboard = false;
|
|
|
|
unscaled = false;
|
|
|
|
can_intersect = false;
|
|
|
|
extra_margin = false;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void create_instance(Node3D *p_base, bool p_hidden = false);
|
2018-07-24 22:08:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Vector3> collision_segments;
|
|
|
|
Ref<TriangleMesh> collision_mesh;
|
|
|
|
|
|
|
|
struct Handle {
|
|
|
|
Vector3 pos;
|
|
|
|
bool billboard;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Vector3> handles;
|
|
|
|
Vector<Vector3> secondary_handles;
|
2018-09-26 09:22:59 +00:00
|
|
|
float selectable_icon_size;
|
2018-07-24 22:08:49 +00:00
|
|
|
bool billboard_handle;
|
|
|
|
|
|
|
|
bool valid;
|
|
|
|
bool hidden;
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *base;
|
2018-07-24 22:08:49 +00:00
|
|
|
Vector<Instance> instances;
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *spatial_node;
|
|
|
|
EditorNode3DGizmoPlugin *gizmo_plugin;
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Node3D>(p_node)); }
|
2018-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2019-12-31 23:52:20 +00:00
|
|
|
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
|
2019-09-18 22:46:32 +00:00
|
|
|
void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const Ref<SkinReference> &p_skin_reference = Ref<SkinReference>(), const Ref<Material> &p_material = Ref<Material>());
|
2018-07-24 22:08:49 +00:00
|
|
|
void add_collision_segments(const Vector<Vector3> &p_lines);
|
|
|
|
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
|
2019-12-31 23:52:20 +00:00
|
|
|
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1, const Color &p_modulate = Color(1, 1, 1));
|
2018-07-24 22:08:49 +00:00
|
|
|
void add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard = false, bool p_secondary = false);
|
|
|
|
void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3());
|
|
|
|
|
2019-01-25 11:57:32 +00:00
|
|
|
virtual bool is_handle_highlighted(int p_idx) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual String get_handle_name(int p_idx) const;
|
2018-07-24 22:08:49 +00:00
|
|
|
virtual Variant get_handle_value(int p_idx);
|
2020-03-26 21:49:16 +00:00
|
|
|
virtual void set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point);
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void set_spatial_node(Node3D *p_node);
|
|
|
|
Node3D *get_spatial_node() const { return spatial_node; }
|
|
|
|
Ref<EditorNode3DGizmoPlugin> get_plugin() const { return gizmo_plugin; }
|
2018-07-24 22:08:49 +00:00
|
|
|
Vector3 get_handle_pos(int p_idx) const;
|
2020-03-26 21:49:16 +00:00
|
|
|
bool intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum);
|
2020-04-01 23:20:12 +00:00
|
|
|
bool intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = nullptr, bool p_sec_first = false);
|
2018-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
virtual void clear();
|
|
|
|
virtual void create();
|
|
|
|
virtual void transform();
|
|
|
|
virtual void redraw();
|
|
|
|
virtual void free();
|
|
|
|
|
|
|
|
virtual bool is_editable() const;
|
|
|
|
|
|
|
|
void set_hidden(bool p_hidden);
|
2020-03-26 21:49:16 +00:00
|
|
|
void set_plugin(EditorNode3DGizmoPlugin *p_plugin);
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
EditorNode3DGizmo();
|
|
|
|
~EditorNode3DGizmo();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2019-10-23 09:46:26 +00: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 21:49:16 +00:00
|
|
|
Node3DEditorViewport *viewport = nullptr;
|
2019-10-23 09:46:26 +00:00
|
|
|
Vector<Color> axis_colors;
|
|
|
|
Vector<int> axis_menu_options;
|
2020-04-28 14:41:01 +00:00
|
|
|
Vector2i orbiting_mouse_start;
|
2019-10-23 09:46:26 +00:00
|
|
|
bool orbiting = false;
|
|
|
|
int focused_axis = -2;
|
|
|
|
|
|
|
|
const float AXIS_CIRCLE_RADIUS = 8.0f * EDSCALE;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
|
|
|
void _gui_input(Ref<InputEvent> p_event);
|
|
|
|
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 21:49:16 +00:00
|
|
|
void set_viewport(Node3DEditorViewport *p_viewport);
|
2019-10-23 09:46:26 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class Node3DEditorViewport : public Control {
|
|
|
|
GDCLASS(Node3DEditorViewport, Control);
|
|
|
|
friend class Node3DEditor;
|
2019-10-23 09:46:26 +00:00
|
|
|
friend class ViewportRotationControl;
|
2014-02-10 01:10:30 +00:00
|
|
|
enum {
|
|
|
|
|
|
|
|
VIEW_TOP,
|
|
|
|
VIEW_BOTTOM,
|
|
|
|
VIEW_LEFT,
|
|
|
|
VIEW_RIGHT,
|
|
|
|
VIEW_FRONT,
|
|
|
|
VIEW_REAR,
|
2016-10-04 18:39:38 +00:00
|
|
|
VIEW_CENTER_TO_ORIGIN,
|
2014-02-10 01:10:30 +00:00
|
|
|
VIEW_CENTER_TO_SELECTION,
|
2018-10-27 21:43:19 +00:00
|
|
|
VIEW_ALIGN_TRANSFORM_WITH_VIEW,
|
|
|
|
VIEW_ALIGN_ROTATION_WITH_VIEW,
|
2014-02-10 01:10:30 +00:00
|
|
|
VIEW_PERSPECTIVE,
|
|
|
|
VIEW_ENVIRONMENT,
|
2014-10-03 03:10:51 +00:00
|
|
|
VIEW_ORTHOGONAL,
|
2017-10-31 17:23:25 +00:00
|
|
|
VIEW_HALF_RESOLUTION,
|
2014-10-03 03:10:51 +00:00
|
|
|
VIEW_AUDIO_LISTENER,
|
2017-07-15 04:23:10 +00:00
|
|
|
VIEW_AUDIO_DOPPLER,
|
2014-10-12 05:13:22 +00:00
|
|
|
VIEW_GIZMOS,
|
2017-06-11 18:52:03 +00:00
|
|
|
VIEW_INFORMATION,
|
2020-04-10 17:18:42 +00:00
|
|
|
VIEW_FRAME_TIME,
|
2017-06-11 18:52:03 +00:00
|
|
|
VIEW_DISPLAY_NORMAL,
|
|
|
|
VIEW_DISPLAY_WIREFRAME,
|
|
|
|
VIEW_DISPLAY_OVERDRAW,
|
2018-06-25 01:24:31 +00:00
|
|
|
VIEW_DISPLAY_SHADELESS,
|
2019-10-03 20:39:08 +00:00
|
|
|
VIEW_DISPLAY_LIGHTING,
|
2020-03-08 18:23:04 +00:00
|
|
|
VIEW_DISPLAY_ADVANCED,
|
2020-01-26 23:09:40 +00:00
|
|
|
VIEW_DISPLAY_NORMAL_BUFFER,
|
2019-10-03 20:39:08 +00:00
|
|
|
VIEW_DISPLAY_DEBUG_SHADOW_ATLAS,
|
|
|
|
VIEW_DISPLAY_DEBUG_DIRECTIONAL_SHADOW_ATLAS,
|
|
|
|
VIEW_DISPLAY_DEBUG_GIPROBE_ALBEDO,
|
|
|
|
VIEW_DISPLAY_DEBUG_GIPROBE_LIGHTING,
|
2019-10-05 13:27:43 +00:00
|
|
|
VIEW_DISPLAY_DEBUG_GIPROBE_EMISSION,
|
2020-01-12 01:26:52 +00:00
|
|
|
VIEW_DISPLAY_DEBUG_SCENE_LUMINANCE,
|
2020-01-25 10:18:55 +00:00
|
|
|
VIEW_DISPLAY_DEBUG_SSAO,
|
2020-04-08 01:51:52 +00:00
|
|
|
VIEW_DISPLAY_DEBUG_PSSM_SPLITS,
|
2020-04-14 03:05:21 +00:00
|
|
|
VIEW_DISPLAY_DEBUG_DECAL_ATLAS,
|
2020-06-25 13:33:28 +00:00
|
|
|
VIEW_DISPLAY_DEBUG_SDFGI,
|
|
|
|
VIEW_DISPLAY_DEBUG_SDFGI_PROBES,
|
|
|
|
VIEW_DISPLAY_DEBUG_GI_BUFFER,
|
2018-07-26 22:36:05 +00:00
|
|
|
VIEW_LOCK_ROTATION,
|
2019-10-03 20:39:08 +00:00
|
|
|
VIEW_CINEMATIC_PREVIEW,
|
2019-10-23 09:46:26 +00:00
|
|
|
VIEW_AUTO_ORTHOGONAL,
|
2019-10-03 20:39:08 +00:00
|
|
|
VIEW_MAX
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2014-10-12 05:13:22 +00:00
|
|
|
public:
|
2014-05-05 01:50:23 +00:00
|
|
|
enum {
|
2017-03-05 15:44:50 +00:00
|
|
|
GIZMO_BASE_LAYER = 27,
|
|
|
|
GIZMO_EDIT_LAYER = 26,
|
2020-04-10 17:18:42 +00:00
|
|
|
GIZMO_GRID_LAYER = 25,
|
|
|
|
|
|
|
|
FRAME_TIME_HISTORY = 20,
|
2014-05-05 01:50:23 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2019-04-22 05:41:17 +00:00
|
|
|
enum NavigationScheme {
|
|
|
|
NAVIGATION_GODOT,
|
|
|
|
NAVIGATION_MAYA,
|
|
|
|
NAVIGATION_MODO,
|
|
|
|
};
|
|
|
|
|
2020-04-18 14:20:35 +00:00
|
|
|
enum FreelookNavigationScheme {
|
|
|
|
FREELOOK_DEFAULT,
|
|
|
|
FREELOOK_PARTIALLY_AXIS_LOCKED,
|
|
|
|
FREELOOK_FULLY_AXIS_LOCKED,
|
|
|
|
};
|
|
|
|
|
2014-10-12 05:13:22 +00:00
|
|
|
private:
|
2020-04-10 17:18:42 +00:00
|
|
|
float cpu_time_history[FRAME_TIME_HISTORY];
|
|
|
|
int cpu_time_history_index;
|
|
|
|
float gpu_time_history[FRAME_TIME_HISTORY];
|
|
|
|
int gpu_time_history_index;
|
|
|
|
|
2014-05-05 01:50:23 +00:00
|
|
|
int index;
|
2015-03-21 20:47:21 +00:00
|
|
|
String name;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _menu_option(int p_option);
|
2019-10-23 09:46:26 +00:00
|
|
|
void _set_auto_orthogonal();
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *preview_node;
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB *preview_bounds;
|
2017-09-02 19:47:16 +00:00
|
|
|
Vector<String> selected_files;
|
|
|
|
AcceptDialog *accept;
|
|
|
|
|
|
|
|
Node *target_node;
|
|
|
|
Point2 drop_pos;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorNode *editor;
|
2017-09-02 19:47:16 +00:00
|
|
|
EditorData *editor_data;
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorSelection *editor_selection;
|
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
2018-10-10 07:25:59 +00:00
|
|
|
CheckBox *preview_camera;
|
2020-04-01 18:28:09 +00:00
|
|
|
SubViewportContainer *subviewport_container;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
MenuButton *view_menu;
|
2019-10-03 20:39:08 +00:00
|
|
|
PopupMenu *display_submenu;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Control *surface;
|
2020-03-04 01:51:12 +00:00
|
|
|
SubViewport *viewport;
|
2020-03-26 21:49:16 +00:00
|
|
|
Camera3D *camera;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool transforming;
|
|
|
|
bool orthogonal;
|
2019-10-23 09:46:26 +00:00
|
|
|
bool auto_orthogonal;
|
2018-06-25 01:24:31 +00:00
|
|
|
bool lock_rotation;
|
2014-05-05 01:50:23 +00:00
|
|
|
float gizmo_scale;
|
2017-05-07 20:59:05 +00:00
|
|
|
|
|
|
|
bool freelook_active;
|
2017-10-08 00:43:57 +00:00
|
|
|
real_t freelook_speed;
|
2020-06-17 18:02:46 +00:00
|
|
|
Vector2 previous_mouse_position;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-11 21:13:04 +00:00
|
|
|
Label *info_label;
|
2018-07-26 22:36:05 +00:00
|
|
|
Label *cinema_label;
|
2018-10-10 07:25:59 +00:00
|
|
|
Label *locked_label;
|
2017-11-19 20:00:16 +00:00
|
|
|
|
2019-10-23 09:46:26 +00:00
|
|
|
VBoxContainer *top_right_vbox;
|
|
|
|
ViewportRotationControl *rotation_control;
|
|
|
|
Label *fps_label;
|
|
|
|
|
2015-11-04 21:39:07 +00:00
|
|
|
struct _RayResult {
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *item;
|
2015-11-04 21:39:07 +00:00
|
|
|
float depth;
|
|
|
|
int handle;
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ bool operator<(const _RayResult &p_rr) const { return depth < p_rr.depth; }
|
2015-11-04 21:39:07 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 20:47:21 +00:00
|
|
|
void _update_name();
|
2017-03-05 15:44:50 +00:00
|
|
|
void _compute_edit(const Point2 &p_point);
|
2014-02-10 01:10:30 +00:00
|
|
|
void _clear_selected();
|
2020-02-10 12:59:24 +00:00
|
|
|
void _select_clicked(bool p_append, bool p_single, bool p_allow_locked = false);
|
2018-09-02 20:31:03 +00:00
|
|
|
void _select(Node *p_node, bool p_append, bool p_single);
|
2020-04-01 23:20:12 +00:00
|
|
|
ObjectID _select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle = nullptr, bool p_alt_select = false);
|
2017-03-05 15:44:50 +00:00
|
|
|
void _find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select = false);
|
|
|
|
Vector3 _get_ray_pos(const Vector2 &p_pos) const;
|
2017-09-02 19:47:16 +00:00
|
|
|
Vector3 _get_ray(const Vector2 &p_pos) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 _point_to_screen(const Vector3 &p_point);
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform _get_camera_transform() const;
|
|
|
|
int get_selected_count() const;
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector3 _get_camera_position() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 _get_camera_normal() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 _get_screen_to_space(const Vector3 &p_vector3);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _select_region();
|
2017-05-02 20:13:12 +00:00
|
|
|
bool _gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only = false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-01 20:49:39 +00: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 01:10:30 +00:00
|
|
|
float get_znear() const;
|
|
|
|
float get_zfar() const;
|
|
|
|
float get_fov() const;
|
|
|
|
|
|
|
|
ObjectID clicked;
|
2015-11-04 21:39:07 +00:00
|
|
|
Vector<_RayResult> selection_results;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool clicked_includes_current;
|
|
|
|
bool clicked_wants_append;
|
|
|
|
|
2015-11-04 21:39:07 +00:00
|
|
|
PopupMenu *selection_menu;
|
|
|
|
|
2014-12-28 13:01:08 +00:00
|
|
|
enum NavigationZoomStyle {
|
|
|
|
NAVIGATION_ZOOM_VERTICAL,
|
|
|
|
NAVIGATION_ZOOM_HORIZONTAL
|
|
|
|
};
|
|
|
|
|
2014-03-31 03:07:21 +00:00
|
|
|
enum NavigationMode {
|
|
|
|
NAVIGATION_NONE,
|
|
|
|
NAVIGATION_PAN,
|
|
|
|
NAVIGATION_ZOOM,
|
2017-05-01 18:57:35 +00:00
|
|
|
NAVIGATION_ORBIT,
|
|
|
|
NAVIGATION_LOOK
|
2014-03-31 03:07:21 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00: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 01:39:45 +00:00
|
|
|
TRANSFORM_YZ,
|
|
|
|
TRANSFORM_XZ,
|
|
|
|
TRANSFORM_XY,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EditData {
|
|
|
|
TransformMode mode;
|
|
|
|
TransformPlane plane;
|
|
|
|
Transform original;
|
|
|
|
Vector3 click_ray;
|
|
|
|
Vector3 click_ray_pos;
|
|
|
|
Vector3 center;
|
|
|
|
Vector3 orig_gizmo_pos;
|
|
|
|
int edited_gizmo;
|
|
|
|
Point2 mouse_pos;
|
|
|
|
bool snap;
|
2020-03-26 21:49:16 +00:00
|
|
|
Ref<EditorNode3DGizmo> gizmo;
|
2014-02-10 01:10:30 +00:00
|
|
|
int gizmo_handle;
|
|
|
|
Variant gizmo_initial_value;
|
|
|
|
Vector3 gizmo_initial_pos;
|
|
|
|
} _edit;
|
|
|
|
|
|
|
|
struct Cursor {
|
|
|
|
Vector3 pos;
|
2017-03-05 15:44:50 +00:00
|
|
|
float x_rot, y_rot, distance;
|
2017-10-08 00:43:57 +00:00
|
|
|
Vector3 eye_pos; // Used in freelook mode
|
2014-02-10 01:10:30 +00:00
|
|
|
bool region_select;
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 region_begin, region_end;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Cursor() {
|
2020-06-07 17:21:29 +00: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-03-05 15:44:50 +00:00
|
|
|
distance = 4;
|
|
|
|
region_select = false;
|
|
|
|
}
|
2017-10-08 00:43:57 +00: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 01:10:30 +00:00
|
|
|
|
2017-05-07 20:59:05 +00:00
|
|
|
void scale_cursor_distance(real_t scale);
|
|
|
|
|
2017-10-08 00:43:57 +00:00
|
|
|
void set_freelook_active(bool active_now);
|
|
|
|
void scale_freelook_speed(real_t scale);
|
|
|
|
|
2017-05-07 20:59:05 +00:00
|
|
|
real_t zoom_indicator_delay;
|
|
|
|
|
2017-11-14 22:50:19 +00:00
|
|
|
RID move_gizmo_instance[3], move_plane_gizmo_instance[3], rotate_gizmo_instance[3], scale_gizmo_instance[3], scale_plane_gizmo_instance[3];
|
2014-05-05 01:50:23 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String last_message;
|
|
|
|
String message;
|
|
|
|
float message_time;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_message(String p_message, float p_time = 5);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//
|
2017-08-26 03:40:45 +00:00
|
|
|
void _update_camera(float p_interp_delta);
|
2017-05-01 18:57:35 +00:00
|
|
|
Transform to_camera_transform(const Cursor &p_cursor) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _draw();
|
|
|
|
|
2017-12-19 14:29:55 +00:00
|
|
|
void _surface_mouse_enter();
|
|
|
|
void _surface_mouse_exit();
|
|
|
|
void _surface_focus_enter();
|
|
|
|
void _surface_focus_exit();
|
|
|
|
|
2017-08-12 16:52:50 +00:00
|
|
|
void _sinput(const Ref<InputEvent> &p_event);
|
2017-05-01 18:57:35 +00:00
|
|
|
void _update_freelook(real_t delta);
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditor *spatial_editor;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Camera3D *previewing;
|
|
|
|
Camera3D *preview;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-26 22:36:05 +00:00
|
|
|
bool previewing_cinema;
|
2019-07-15 19:50:00 +00:00
|
|
|
bool _is_node_locked(const Node *p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
void _preview_exited_scene();
|
|
|
|
void _toggle_camera_preview(bool);
|
2018-07-26 22:36:05 +00:00
|
|
|
void _toggle_cinema_preview(bool);
|
2014-05-05 01:50:23 +00:00
|
|
|
void _init_gizmo_instance(int p_idx);
|
2015-04-20 22:38:02 +00:00
|
|
|
void _finish_gizmo_instances();
|
2015-11-04 21:39:07 +00:00
|
|
|
void _selection_result_pressed(int);
|
|
|
|
void _selection_menu_hide();
|
2017-05-20 15:38:03 +00:00
|
|
|
void _list_select(Ref<InputEventMouseButton> b);
|
|
|
|
Point2i _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const;
|
2014-05-05 01:50:23 +00:00
|
|
|
|
2017-09-02 19:47:16 +00:00
|
|
|
Vector3 _get_instance_position(const Point2 &p_pos) const;
|
2020-03-26 21:49:16 +00:00
|
|
|
static AABB _calculate_spatial_bounds(const Node3D *p_parent, bool p_exclude_toplevel_transform = true);
|
2017-09-02 19:47:16 +00:00
|
|
|
void _create_preview(const Vector<String> &files) const;
|
|
|
|
void _remove_preview();
|
|
|
|
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);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2017-10-29 19:32:09 +00:00
|
|
|
void update_surface() { surface->update(); }
|
2014-05-05 01:50:23 +00:00
|
|
|
void update_transform_gizmo_view();
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void set_can_preview(Camera3D *p_preview);
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_state(const Dictionary &p_state);
|
2014-02-10 01:10:30 +00:00
|
|
|
Dictionary get_state() const;
|
2014-09-19 21:39:50 +00:00
|
|
|
void reset();
|
2017-05-07 20:59:05 +00:00
|
|
|
bool is_freelook_active() const { return freelook_active; }
|
2016-07-28 19:37:52 +00:00
|
|
|
|
|
|
|
void focus_selection();
|
|
|
|
|
2017-09-02 19:47:16 +00:00
|
|
|
void assign_pending_data_pointers(
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *p_preview_node,
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB *p_preview_bounds,
|
2017-09-02 19:47:16 +00:00
|
|
|
AcceptDialog *p_accept);
|
|
|
|
|
2020-03-04 01:51:12 +00:00
|
|
|
SubViewport *get_viewport_node() { return viewport; }
|
2020-03-26 21:49:16 +00:00
|
|
|
Camera3D *get_camera() { return camera; } // return the default camera object.
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditorViewport(Node3DEditor *p_spatial_editor, EditorNode *p_editor, int p_index);
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class Node3DEditorSelectedItem : public Object {
|
|
|
|
GDCLASS(Node3DEditorSelectedItem, Object);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
public:
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB aabb;
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform original; // original location when moving
|
2017-09-21 21:11:56 +00:00
|
|
|
Transform original_local;
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform last_xform; // last transform
|
2020-03-19 06:43:25 +00:00
|
|
|
bool last_xform_dirty;
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *sp;
|
2014-02-10 01:10:30 +00:00
|
|
|
RID sbox_instance;
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditorSelectedItem() {
|
2020-04-01 23:20:12 +00:00
|
|
|
sp = nullptr;
|
2020-03-19 06:43:25 +00:00
|
|
|
last_xform_dirty = true;
|
|
|
|
}
|
2020-03-26 21:49:16 +00:00
|
|
|
~Node3DEditorSelectedItem();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class Node3DEditorViewportContainer : public Container {
|
|
|
|
GDCLASS(Node3DEditorViewportContainer, Container);
|
2019-03-19 18:35:57 +00:00
|
|
|
|
2017-06-11 14:29:27 +00: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;
|
|
|
|
float ratio_h;
|
|
|
|
float ratio_v;
|
|
|
|
|
2018-08-25 06:47:04 +00:00
|
|
|
bool hovering_v;
|
|
|
|
bool hovering_h;
|
|
|
|
|
2017-06-11 14:29:27 +00:00
|
|
|
bool dragging_v;
|
|
|
|
bool dragging_h;
|
|
|
|
Vector2 drag_begin_pos;
|
|
|
|
Vector2 drag_begin_ratio;
|
|
|
|
|
|
|
|
void _gui_input(const Ref<InputEvent> &p_event);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_view(View p_view);
|
|
|
|
View get_view();
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditorViewportContainer();
|
2017-06-11 14:29:27 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class Node3DEditor : public VBoxContainer {
|
|
|
|
GDCLASS(Node3DEditor, VBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2017-10-29 19:32:09 +00:00
|
|
|
static const unsigned int VIEWPORTS_COUNT = 4;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
enum ToolMode {
|
|
|
|
|
|
|
|
TOOL_MODE_SELECT,
|
|
|
|
TOOL_MODE_MOVE,
|
|
|
|
TOOL_MODE_ROTATE,
|
2015-12-13 20:16:13 +00:00
|
|
|
TOOL_MODE_SCALE,
|
|
|
|
TOOL_MODE_LIST_SELECT,
|
2017-10-23 19:21:15 +00:00
|
|
|
TOOL_LOCK_SELECTED,
|
|
|
|
TOOL_UNLOCK_SELECTED,
|
2019-04-17 16:24:28 +00:00
|
|
|
TOOL_GROUP_SELECTED,
|
|
|
|
TOOL_UNGROUP_SELECTED,
|
2015-12-13 20:16:13 +00:00
|
|
|
TOOL_MAX
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-11-18 18:51:37 +00:00
|
|
|
enum ToolOptions {
|
|
|
|
|
|
|
|
TOOL_OPT_LOCAL_COORDS,
|
|
|
|
TOOL_OPT_USE_SNAP,
|
2019-04-06 20:55:01 +00:00
|
|
|
TOOL_OPT_OVERRIDE_CAMERA,
|
2017-11-18 18:51:37 +00:00
|
|
|
TOOL_OPT_MAX
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
private:
|
|
|
|
EditorNode *editor;
|
|
|
|
EditorSelection *editor_selection;
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditorViewportContainer *viewport_base;
|
|
|
|
Node3DEditorViewport *viewports[VIEWPORTS_COUNT];
|
2014-02-10 01:10:30 +00:00
|
|
|
VSplitContainer *shader_split;
|
|
|
|
HSplitContainer *palette_split;
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
|
|
|
ToolMode tool_mode;
|
|
|
|
bool orthogonal;
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RenderingServer::ScenarioDebugMode scenario_debug;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
RID origin;
|
|
|
|
RID origin_instance;
|
2018-08-17 21:21:08 +00:00
|
|
|
bool origin_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
RID grid[3];
|
|
|
|
RID grid_instance[3];
|
|
|
|
bool grid_visible[3]; //currently visible
|
|
|
|
bool grid_enable[3]; //should be always visible if true
|
|
|
|
bool grid_enabled;
|
|
|
|
|
2017-11-14 22:50:19 +00:00
|
|
|
Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3], scale_gizmo[3], scale_plane_gizmo[3];
|
2019-09-15 04:01:52 +00:00
|
|
|
Ref<StandardMaterial3D> gizmo_color[3];
|
|
|
|
Ref<StandardMaterial3D> plane_gizmo_color[3];
|
|
|
|
Ref<StandardMaterial3D> gizmo_color_hl[3];
|
|
|
|
Ref<StandardMaterial3D> plane_gizmo_color_hl[3];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-05 01:50:23 +00:00
|
|
|
int over_gizmo_handle;
|
2020-03-08 19:31:11 +00:00
|
|
|
float snap_translate_value;
|
|
|
|
float snap_rotate_value;
|
|
|
|
float snap_scale_value;
|
2014-05-05 01:50:23 +00:00
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
Ref<ArrayMesh> selection_box;
|
2014-02-10 01:10:30 +00:00
|
|
|
RID indicators;
|
2016-03-08 23:00:52 +00:00
|
|
|
RID indicators_instance;
|
2014-02-10 01:10:30 +00:00
|
|
|
RID cursor_mesh;
|
|
|
|
RID cursor_instance;
|
2019-09-15 04:01:52 +00:00
|
|
|
Ref<StandardMaterial3D> indicator_mat;
|
|
|
|
Ref<StandardMaterial3D> cursor_material;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-02 19:47:16 +00:00
|
|
|
// Scene drag and drop support
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *preview_node;
|
2017-11-17 02:09:00 +00:00
|
|
|
AABB preview_bounds;
|
2017-09-02 19:47:16 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct Gizmo {
|
|
|
|
bool visible;
|
|
|
|
float scale;
|
|
|
|
Transform transform;
|
|
|
|
} gizmo;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
enum MenuOption {
|
|
|
|
|
|
|
|
MENU_TOOL_SELECT,
|
|
|
|
MENU_TOOL_MOVE,
|
|
|
|
MENU_TOOL_ROTATE,
|
|
|
|
MENU_TOOL_SCALE,
|
2015-12-13 20:16:13 +00:00
|
|
|
MENU_TOOL_LIST_SELECT,
|
2017-11-18 18:51:37 +00:00
|
|
|
MENU_TOOL_LOCAL_COORDS,
|
|
|
|
MENU_TOOL_USE_SNAP,
|
2019-04-06 20:55:01 +00:00
|
|
|
MENU_TOOL_OVERRIDE_CAMERA,
|
2014-02-10 01:10:30 +00:00
|
|
|
MENU_TRANSFORM_CONFIGURE_SNAP,
|
|
|
|
MENU_TRANSFORM_DIALOG,
|
|
|
|
MENU_VIEW_USE_1_VIEWPORT,
|
|
|
|
MENU_VIEW_USE_2_VIEWPORTS,
|
2014-10-09 03:06:51 +00:00
|
|
|
MENU_VIEW_USE_2_VIEWPORTS_ALT,
|
2014-02-10 01:10:30 +00:00
|
|
|
MENU_VIEW_USE_3_VIEWPORTS,
|
2014-10-09 03:06:51 +00:00
|
|
|
MENU_VIEW_USE_3_VIEWPORTS_ALT,
|
2014-02-10 01:10:30 +00:00
|
|
|
MENU_VIEW_USE_4_VIEWPORTS,
|
|
|
|
MENU_VIEW_ORIGIN,
|
|
|
|
MENU_VIEW_GRID,
|
2018-08-11 21:07:00 +00:00
|
|
|
MENU_VIEW_GIZMOS_3D_ICONS,
|
2014-02-10 01:10:30 +00:00
|
|
|
MENU_VIEW_CAMERA_SETTINGS,
|
2017-10-23 19:21:15 +00:00
|
|
|
MENU_LOCK_SELECTED,
|
2017-11-22 21:29:27 +00:00
|
|
|
MENU_UNLOCK_SELECTED,
|
2019-04-17 16:24:28 +00:00
|
|
|
MENU_GROUP_SELECTED,
|
|
|
|
MENU_UNGROUP_SELECTED,
|
2018-07-26 06:34:40 +00:00
|
|
|
MENU_SNAP_TO_FLOOR
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2015-12-13 20:16:13 +00:00
|
|
|
Button *tool_button[TOOL_MAX];
|
2017-11-18 18:51:37 +00:00
|
|
|
Button *tool_option_button[TOOL_OPT_MAX];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
MenuButton *transform_menu;
|
2018-08-11 21:07:00 +00:00
|
|
|
PopupMenu *gizmos_menu;
|
2017-03-05 15:44:50 +00:00
|
|
|
MenuButton *view_menu;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-02 19:47:16 +00:00
|
|
|
AcceptDialog *accept;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
ConfirmationDialog *snap_dialog;
|
|
|
|
ConfirmationDialog *xform_dialog;
|
|
|
|
ConfirmationDialog *settings_dialog;
|
|
|
|
|
|
|
|
bool snap_enabled;
|
2018-02-21 14:14:26 +00:00
|
|
|
bool snap_key_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
LineEdit *snap_translate;
|
|
|
|
LineEdit *snap_rotate;
|
|
|
|
LineEdit *snap_scale;
|
2017-03-05 15:44:50 +00:00
|
|
|
PanelContainer *menu_panel;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
LineEdit *xform_translate[3];
|
|
|
|
LineEdit *xform_rotate[3];
|
|
|
|
LineEdit *xform_scale[3];
|
|
|
|
OptionButton *xform_type;
|
|
|
|
|
2014-10-12 05:13:22 +00:00
|
|
|
VBoxContainer *settings_vbc;
|
|
|
|
SpinBox *settings_fov;
|
|
|
|
SpinBox *settings_znear;
|
|
|
|
SpinBox *settings_zfar;
|
|
|
|
|
2020-03-08 19:31:11 +00:00
|
|
|
void _snap_changed();
|
|
|
|
void _snap_update();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _xform_dialog_action();
|
|
|
|
void _menu_item_pressed(int p_option);
|
2017-11-18 18:51:37 +00:00
|
|
|
void _menu_item_toggled(bool pressed, int p_option);
|
2018-07-24 22:08:49 +00:00
|
|
|
void _menu_gizmo_toggled(int p_option);
|
2019-04-06 20:55:01 +00:00
|
|
|
void _update_camera_override_button(bool p_game_running);
|
|
|
|
void _update_camera_override_viewport(Object *p_viewport);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
HBoxContainer *hbc_menu;
|
|
|
|
|
|
|
|
void _generate_selection_box();
|
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
2019-04-06 20:55:01 +00:00
|
|
|
int camera_override_viewport_id;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _init_indicators();
|
2018-10-29 10:30:28 +00:00
|
|
|
void _update_gizmos_menu();
|
2019-02-15 17:32:38 +00:00
|
|
|
void _update_gizmos_menu_theme();
|
2017-12-08 22:45:33 +00:00
|
|
|
void _init_grid();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _finish_indicators();
|
2017-12-08 22:45:33 +00:00
|
|
|
void _finish_grid();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _toggle_maximize_view(Object *p_viewport);
|
2014-04-01 10:45:48 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *custom_camera;
|
|
|
|
|
|
|
|
Object *_get_editor_data(Object *p_what);
|
|
|
|
|
|
|
|
Ref<Environment> viewport_environment;
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *selected;
|
2014-05-05 01:50:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _request_gizmo(Object *p_obj);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
static Node3DEditor *singleton;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _node_removed(Node *p_node);
|
2020-03-26 21:49:16 +00:00
|
|
|
Vector<Ref<EditorNode3DGizmoPlugin>> gizmo_plugins_by_priority;
|
|
|
|
Vector<Ref<EditorNode3DGizmoPlugin>> gizmo_plugins_by_name;
|
2018-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
void _register_all_gizmos();
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditor();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-07 20:59:05 +00:00
|
|
|
bool is_any_freelook_active() const;
|
|
|
|
|
2017-10-23 19:21:15 +00:00
|
|
|
void _refresh_menu_icons();
|
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
protected:
|
2014-02-10 01:10:30 +00:00
|
|
|
void _notification(int p_what);
|
2017-01-08 19:28:12 +00:00
|
|
|
//void _gui_input(InputEvent p_event);
|
2017-05-20 15:38:03 +00:00
|
|
|
void _unhandled_key_input(Ref<InputEvent> p_event);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2020-03-26 21:49:16 +00:00
|
|
|
static Node3DEditor *get_singleton() { return singleton; }
|
2017-03-05 15:44:50 +00:00
|
|
|
void snap_cursor_to_plane(const Plane &p_plane);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-18 21:44:04 +00:00
|
|
|
Vector3 snap_point(Vector3 p_target, Vector3 p_start = Vector3(0, 0, 0)) const;
|
|
|
|
|
2017-01-04 04:16:14 +00: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 01:10:30 +00:00
|
|
|
|
|
|
|
Transform get_gizmo_transform() const { return gizmo.transform; }
|
|
|
|
bool is_gizmo_visible() const { return gizmo.visible; }
|
|
|
|
|
|
|
|
ToolMode get_tool_mode() const { return tool_mode; }
|
2020-03-26 21:49:16 +00:00
|
|
|
bool are_local_coords_enabled() const { return tool_option_button[Node3DEditor::TOOL_OPT_LOCAL_COORDS]->is_pressed(); }
|
2018-02-21 14:14:26 +00:00
|
|
|
bool is_snap_enabled() const { return snap_enabled ^ snap_key_enabled; }
|
2019-04-09 15:55:44 +00:00
|
|
|
float get_translate_snap() const;
|
|
|
|
float get_rotate_snap() const;
|
|
|
|
float get_scale_snap() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-07 21:18:55 +00:00
|
|
|
Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; }
|
2017-08-29 01:39:45 +00:00
|
|
|
Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; }
|
2017-06-07 21:18:55 +00:00
|
|
|
Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; }
|
2017-09-21 21:11:56 +00:00
|
|
|
Ref<ArrayMesh> get_scale_gizmo(int idx) const { return scale_gizmo[idx]; }
|
2017-11-14 22:50:19 +00:00
|
|
|
Ref<ArrayMesh> get_scale_plane_gizmo(int idx) const { return scale_plane_gizmo[idx]; }
|
2014-05-05 01:50:23 +00:00
|
|
|
|
2019-04-21 10:15:45 +00:00
|
|
|
void update_grid();
|
2014-02-10 01:10:30 +00:00
|
|
|
void update_transform_gizmo();
|
2020-04-01 23:20:12 +00:00
|
|
|
void update_all_gizmos(Node *p_node = nullptr);
|
2018-07-26 06:34:40 +00:00
|
|
|
void snap_selected_nodes_to_floor();
|
2017-04-06 15:35:08 +00:00
|
|
|
void select_gizmo_highlight_axis(int p_axis);
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_custom_camera(Node *p_camera) { custom_camera = p_camera; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
|
2014-02-10 01:10:30 +00:00
|
|
|
Dictionary get_state() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_state(const Dictionary &p_state);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Ref<Environment> get_viewport_environment() { return viewport_environment; }
|
|
|
|
|
|
|
|
UndoRedo *get_undo_redo() { return undo_redo; }
|
|
|
|
|
|
|
|
void add_control_to_menu_panel(Control *p_control);
|
2018-02-13 21:21:19 +00:00
|
|
|
void remove_control_from_menu_panel(Control *p_control);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
VSplitContainer *get_shader_split();
|
2017-12-01 00:50:09 +00:00
|
|
|
HSplitContainer *get_palette_split();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3D *get_selected() { return selected; }
|
2014-05-05 01:50:23 +00:00
|
|
|
|
|
|
|
int get_over_gizmo_handle() const { return over_gizmo_handle; }
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_over_gizmo_handle(int idx) { over_gizmo_handle = idx; }
|
2014-05-05 01:50:23 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void set_can_preview(Camera3D *p_preview);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditorViewport *get_editor_viewport(int p_idx) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, static_cast<int>(VIEWPORTS_COUNT), nullptr);
|
2015-05-31 04:59:42 +00:00
|
|
|
return viewports[p_idx];
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void add_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin);
|
|
|
|
void remove_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin);
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void edit(Node3D *p_spatial);
|
2014-09-19 21:39:50 +00:00
|
|
|
void clear();
|
2017-09-02 19:47:16 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditor(EditorNode *p_editor);
|
|
|
|
~Node3DEditor();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class Node3DEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(Node3DEditorPlugin, EditorPlugin);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditor *spatial_editor;
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorNode *editor;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
|
|
|
void snap_cursor_to_plane(const Plane &p_plane);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditor *get_spatial_editor() { return spatial_editor; }
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual String get_name() const { return "3D"; }
|
|
|
|
bool has_main_screen() const { return true; }
|
2016-03-08 23:00:52 +00:00
|
|
|
virtual void make_visible(bool p_visible);
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual void edit(Object *p_object);
|
|
|
|
virtual bool handles(Object *p_object) const;
|
|
|
|
|
|
|
|
virtual Dictionary get_state() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void set_state(const Dictionary &p_state);
|
2014-09-19 21:39:50 +00:00
|
|
|
virtual void clear() { spatial_editor->clear(); }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-14 21:13:48 +00:00
|
|
|
virtual void edited_scene_changed();
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Node3DEditorPlugin(EditorNode *p_node);
|
|
|
|
~Node3DEditorPlugin();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class EditorNode3DGizmoPlugin : public Resource {
|
|
|
|
GDCLASS(EditorNode3DGizmoPlugin, Resource);
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2018-08-11 21:07:00 +00:00
|
|
|
public:
|
2018-11-18 21:01:09 +00:00
|
|
|
static const int VISIBLE = 0;
|
|
|
|
static const int HIDDEN = 1;
|
|
|
|
static const int ON_TOP = 2;
|
2018-08-11 21:07:00 +00:00
|
|
|
|
2020-03-20 11:41:07 +00:00
|
|
|
protected:
|
2018-08-11 21:07:00 +00:00
|
|
|
int current_state;
|
2020-03-26 21:49:16 +00:00
|
|
|
List<EditorNode3DGizmo *> current_gizmos;
|
2020-03-17 06:33:00 +00:00
|
|
|
HashMap<String, Vector<Ref<StandardMaterial3D>>> materials;
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2018-10-29 10:30:28 +00:00
|
|
|
static void _bind_methods();
|
2020-03-26 21:49:16 +00:00
|
|
|
virtual bool has_gizmo(Node3D *p_spatial);
|
|
|
|
virtual Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial);
|
2018-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false);
|
2019-06-11 18:43:37 +00:00
|
|
|
void create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1));
|
2018-07-24 22:08:49 +00:00
|
|
|
void create_handle_material(const String &p_name, bool p_billboard = false);
|
2019-09-15 04:01:52 +00:00
|
|
|
void add_material(const String &p_name, Ref<StandardMaterial3D> p_material);
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Ref<StandardMaterial3D> get_material(const String &p_name, const Ref<EditorNode3DGizmo> &p_gizmo = Ref<EditorNode3DGizmo>());
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2018-10-29 10:30:28 +00:00
|
|
|
virtual String get_name() const;
|
2019-03-11 23:30:50 +00:00
|
|
|
virtual int get_priority() const;
|
2018-07-24 22:08:49 +00:00
|
|
|
virtual bool can_be_hidden() const;
|
|
|
|
virtual bool is_selectable_when_hidden() const;
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
virtual void redraw(EditorNode3DGizmo *p_gizmo);
|
|
|
|
virtual String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const;
|
|
|
|
virtual Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const;
|
|
|
|
virtual void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point);
|
|
|
|
virtual void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
|
|
|
|
virtual bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_idx) const;
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Ref<EditorNode3DGizmo> get_gizmo(Node3D *p_spatial);
|
2018-08-11 21:07:00 +00:00
|
|
|
void set_state(int p_state);
|
2019-03-11 23:30:50 +00:00
|
|
|
int get_state() const;
|
2020-03-26 21:49:16 +00:00
|
|
|
void unregister_gizmo(EditorNode3DGizmo *p_gizmo);
|
2018-07-24 22:08:49 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
EditorNode3DGizmoPlugin();
|
|
|
|
virtual ~EditorNode3DGizmoPlugin();
|
2018-07-24 22:08:49 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|