Added camera controls
This commit is contained in:
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -71,7 +71,10 @@ unique_name_in_owner = true
|
|||||||
[node name="DirectionalLight" type="DirectionalLight" parent="."]
|
[node name="DirectionalLight" type="DirectionalLight" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 100, 0 )
|
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 100, 0 )
|
||||||
|
|
||||||
[node name="Camera" type="Camera" parent="."]
|
[node name="camera_rot" type="Spatial" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
|
[node name="Camera" type="Camera" parent="camera_rot"]
|
||||||
transform = Transform( 0.707107, 0.5, -0.5, 0, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -16, 23, 30 )
|
transform = Transform( 0.707107, 0.5, -0.5, 0, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -16, 23, 30 )
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
@@ -111,11 +114,17 @@ rect_min_size = Vector2( 100, 0 )
|
|||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[node name="socket_editor" type="PanelContainer" parent="VBoxContainer"]
|
[node name="NavPanel" type="NavPanel" parent="VBoxContainer"]
|
||||||
unique_name_in_owner = true
|
|
||||||
margin_top = 138.0
|
margin_top = 138.0
|
||||||
margin_right = 314.0
|
margin_right = 314.0
|
||||||
margin_bottom = 444.0
|
margin_bottom = 186.0
|
||||||
|
flags = 12
|
||||||
|
|
||||||
|
[node name="socket_editor" type="PanelContainer" parent="VBoxContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
margin_top = 190.0
|
||||||
|
margin_right = 314.0
|
||||||
|
margin_bottom = 496.0
|
||||||
|
|
||||||
[node name="v" type="VBoxContainer" parent="VBoxContainer/socket_editor"]
|
[node name="v" type="VBoxContainer" parent="VBoxContainer/socket_editor"]
|
||||||
margin_left = 7.0
|
margin_left = 7.0
|
||||||
@@ -276,9 +285,9 @@ margin_bottom = 292.0
|
|||||||
|
|
||||||
[node name="element_editor" type="PanelContainer" parent="VBoxContainer"]
|
[node name="element_editor" type="PanelContainer" parent="VBoxContainer"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
margin_top = 448.0
|
margin_top = 500.0
|
||||||
margin_right = 314.0
|
margin_right = 314.0
|
||||||
margin_bottom = 715.0
|
margin_bottom = 767.0
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/element_editor"]
|
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/element_editor"]
|
||||||
margin_left = 7.0
|
margin_left = 7.0
|
||||||
@@ -328,9 +337,9 @@ columns = 2
|
|||||||
|
|
||||||
[node name="layout_editor" type="PanelContainer" parent="VBoxContainer"]
|
[node name="layout_editor" type="PanelContainer" parent="VBoxContainer"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
margin_top = 719.0
|
margin_top = 771.0
|
||||||
margin_right = 314.0
|
margin_right = 314.0
|
||||||
margin_bottom = 1055.0
|
margin_bottom = 1107.0
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/layout_editor"]
|
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/layout_editor"]
|
||||||
margin_left = 7.0
|
margin_left = 7.0
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <main/main.h>
|
#include <main/main.h>
|
||||||
#include <core/engine.h>
|
#include <core/engine.h>
|
||||||
|
#include <core/os/input.h>
|
||||||
#include <scene/resources/packed_scene.h>
|
#include <scene/resources/packed_scene.h>
|
||||||
#include <scene/resources/surface_tool.h>
|
#include <scene/resources/surface_tool.h>
|
||||||
#include <scene/3d/mesh_instance.h>
|
#include <scene/3d/mesh_instance.h>
|
||||||
@@ -58,8 +59,21 @@ public:
|
|||||||
virtual ~LayoutEditor()
|
virtual ~LayoutEditor()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
float delta =
|
||||||
|
SceneTree::get_singleton()->get_idle_process_time();
|
||||||
|
// print_line("update: " + String::num(delta));
|
||||||
|
float rot =
|
||||||
|
Input::get_singleton()->get_axis("action2", "action") *
|
||||||
|
delta * 10.0f;
|
||||||
|
rot = Math::stepify(rot, Math_PI / 8.0);
|
||||||
|
get_as_node<Spatial>("%camera_rot")->rotate_y(rot);
|
||||||
|
}
|
||||||
void activate()
|
void activate()
|
||||||
{
|
{
|
||||||
|
SceneTree::get_singleton()->connect("idle_frame", this,
|
||||||
|
"update");
|
||||||
editor->update_element_meshes();
|
editor->update_element_meshes();
|
||||||
get_as_node<Control>("%layout_editor")->show();
|
get_as_node<Control>("%layout_editor")->show();
|
||||||
get_as_node<Spatial>("%bg_floor")->show();
|
get_as_node<Spatial>("%bg_floor")->show();
|
||||||
@@ -97,6 +111,8 @@ public:
|
|||||||
get_as_node<Control>("%layout_editor")->hide();
|
get_as_node<Control>("%layout_editor")->hide();
|
||||||
EditorEvent::get_singleton()->event.remove_listener(
|
EditorEvent::get_singleton()->event.remove_listener(
|
||||||
this, &LayoutEditor::event_signal_handler);
|
this, &LayoutEditor::event_signal_handler);
|
||||||
|
SceneTree::get_singleton()->disconnect("idle_frame", this,
|
||||||
|
"update");
|
||||||
}
|
}
|
||||||
void event_signal_handler(const String &event,
|
void event_signal_handler(const String &event,
|
||||||
const Vector<Variant> &args)
|
const Vector<Variant> &args)
|
||||||
@@ -198,6 +214,12 @@ public:
|
|||||||
current_layout, is_exterior, current_floor);
|
current_layout, is_exterior, current_floor);
|
||||||
print_line("visualize: " + itos(current_floor));
|
print_line("visualize: " + itos(current_floor));
|
||||||
visualize_below_and_current(current_layout, is_exterior);
|
visualize_below_and_current(current_layout, is_exterior);
|
||||||
|
Transform xform = editor->get_viewport()
|
||||||
|
->get_camera()
|
||||||
|
->get_global_transform();
|
||||||
|
xform.origin.y = 23 + current_floor * 5;
|
||||||
|
editor->get_viewport()->get_camera()->set_global_transform(
|
||||||
|
xform);
|
||||||
}
|
}
|
||||||
void select_grid_element(int index)
|
void select_grid_element(int index)
|
||||||
{
|
{
|
||||||
@@ -263,6 +285,7 @@ public:
|
|||||||
&LayoutEditor::select_grid_rotation);
|
&LayoutEditor::select_grid_rotation);
|
||||||
ClassDB::bind_method(D_METHOD("grow_cell"),
|
ClassDB::bind_method(D_METHOD("grow_cell"),
|
||||||
&LayoutEditor::grow_cell);
|
&LayoutEditor::grow_cell);
|
||||||
|
ClassDB::bind_method(D_METHOD("update"), &LayoutEditor::update);
|
||||||
}
|
}
|
||||||
void clear_vis(const String &key, bool exterior)
|
void clear_vis(const String &key, bool exterior)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,9 +9,11 @@
|
|||||||
|
|
||||||
NavPanel::NavPanel()
|
NavPanel::NavPanel()
|
||||||
: HBoxContainer()
|
: HBoxContainer()
|
||||||
|
, flags(0x7)
|
||||||
, h(nullptr)
|
, h(nullptr)
|
||||||
, v(nullptr)
|
, v(nullptr)
|
||||||
, r(nullptr)
|
, r(nullptr)
|
||||||
|
, yr(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +21,8 @@ NavPanel::~NavPanel()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool h_active = false, v_active = false, r_active = false;
|
static bool h_active = false, v_active = false, r_active = false,
|
||||||
|
yr_active = false;
|
||||||
static Transform camera_xform;
|
static Transform camera_xform;
|
||||||
static bool transform_changhed = false;
|
static bool transform_changhed = false;
|
||||||
|
|
||||||
@@ -27,22 +30,9 @@ void NavPanel::_notification(int which)
|
|||||||
{
|
{
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case NOTIFICATION_ENTER_TREE: {
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
h = memnew(ColorRect);
|
} break;
|
||||||
v = memnew(ColorRect);
|
case NOTIFICATION_READY: {
|
||||||
r = memnew(ColorRect);
|
update_flags();
|
||||||
h->set_custom_minimum_size(Vector2(48, 48));
|
|
||||||
v->set_custom_minimum_size(Vector2(48, 48));
|
|
||||||
r->set_custom_minimum_size(Vector2(48, 48));
|
|
||||||
add_child(h);
|
|
||||||
add_child(v);
|
|
||||||
add_child(r);
|
|
||||||
h->set_focus_mode(Control::FOCUS_CLICK);
|
|
||||||
v->set_focus_mode(Control::FOCUS_CLICK);
|
|
||||||
r->set_focus_mode(Control::FOCUS_CLICK);
|
|
||||||
h->connect("gui_input", this, "gui_input_handler_h");
|
|
||||||
v->connect("gui_input", this, "gui_input_handler_v");
|
|
||||||
r->connect("gui_input", this, "gui_input_handler_r");
|
|
||||||
set_process(true);
|
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
if (h) {
|
if (h) {
|
||||||
@@ -110,6 +100,14 @@ void NavPanel::_bind_methods()
|
|||||||
&NavPanel::gui_input_handler_v);
|
&NavPanel::gui_input_handler_v);
|
||||||
ClassDB::bind_method(D_METHOD("gui_input_handler_r", "e"),
|
ClassDB::bind_method(D_METHOD("gui_input_handler_r", "e"),
|
||||||
&NavPanel::gui_input_handler_r);
|
&NavPanel::gui_input_handler_r);
|
||||||
|
ClassDB::bind_method(D_METHOD("gui_input_handler_yr", "e"),
|
||||||
|
&NavPanel::gui_input_handler_yr);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_flags", "flags"),
|
||||||
|
&NavPanel::set_flags);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_flags"), &NavPanel::get_flags);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "flags", PROPERTY_HINT_FLAGS,
|
||||||
|
"XZ,XY,RotMove,YRotOrigin"),
|
||||||
|
"set_flags", "get_flags");
|
||||||
}
|
}
|
||||||
void NavPanel::gui_input_handler_h(const Ref<InputEvent> &e)
|
void NavPanel::gui_input_handler_h(const Ref<InputEvent> &e)
|
||||||
{
|
{
|
||||||
@@ -195,11 +193,113 @@ void NavPanel::gui_input_handler_r(const Ref<InputEvent> &e)
|
|||||||
camera_xform.basis.rotated(axis, rotations.x);
|
camera_xform.basis.rotated(axis, rotations.x);
|
||||||
transform_changhed = true;
|
transform_changhed = true;
|
||||||
get_viewport()->set_input_as_handled();
|
get_viewport()->set_input_as_handled();
|
||||||
#if 0
|
|
||||||
camera_xform.basis = camera_xform.basis.rotated(
|
|
||||||
Vector3(0, 1, 0), rel.x * 0.1);
|
|
||||||
camera_xform.basis = camera_xform.basis.rotated(
|
|
||||||
Vector3(1, 0, 0), rel.y * 0.1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void NavPanel::gui_input_handler_yr(const Ref<InputEvent> &e)
|
||||||
|
{
|
||||||
|
Camera *cam = get_viewport()->get_camera();
|
||||||
|
Ref<InputEventMouseButton> mb = e;
|
||||||
|
if (Input::get_singleton()->is_action_just_pressed("mouse1")) {
|
||||||
|
yr_active = true;
|
||||||
|
Input::get_singleton()->set_mouse_mode(
|
||||||
|
Input::MOUSE_MODE_CAPTURED);
|
||||||
|
yr->grab_focus();
|
||||||
|
origin_rotation = Transform();
|
||||||
|
y_rotation = Transform();
|
||||||
|
transform_backup = cam->get_global_transform();
|
||||||
|
} else if (Input::get_singleton()->is_action_just_released("mouse1")) {
|
||||||
|
yr_active = false;
|
||||||
|
Input::get_singleton()->set_mouse_mode(
|
||||||
|
Input::MOUSE_MODE_VISIBLE);
|
||||||
|
origin_rotation = Transform();
|
||||||
|
y_rotation = Transform();
|
||||||
|
cam->set_global_transform(transform_backup);
|
||||||
|
}
|
||||||
|
if (mb.is_valid())
|
||||||
|
get_viewport()->set_input_as_handled();
|
||||||
|
Ref<InputEventMouseMotion> mm = e;
|
||||||
|
Vector2 sensivity(0.06f, 0.05f);
|
||||||
|
if (mm.is_valid() && yr_active) {
|
||||||
|
Vector2 rel = mm->get_relative() * sensivity;
|
||||||
|
origin_rotation.basis = origin_rotation.basis.rotated(
|
||||||
|
Vector3(0, 1, 0), rel.x * 0.1f);
|
||||||
|
origin_rotation.orthonormalize();
|
||||||
|
y_rotation.basis = y_rotation.basis.rotated(Vector3(1, 0, 0),
|
||||||
|
rel.y * 0.1f);
|
||||||
|
camera_xform = origin_rotation * y_rotation * transform_backup;
|
||||||
|
cam->set_global_transform(camera_xform);
|
||||||
|
get_viewport()->set_input_as_handled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t NavPanel::get_flags() const
|
||||||
|
{
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavPanel::set_flags(uint32_t flags)
|
||||||
|
{
|
||||||
|
if (this->flags != flags) {
|
||||||
|
this->flags = flags;
|
||||||
|
if (is_inside_tree())
|
||||||
|
update_flags();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavPanel::update_flags()
|
||||||
|
{
|
||||||
|
set_process(false);
|
||||||
|
bool h_on = !!(flags & (1 << 0));
|
||||||
|
bool v_on = !!(flags & (1 << 1));
|
||||||
|
bool r_on = !!(flags & (1 << 2));
|
||||||
|
bool yr_on = !!(flags & (1 << 3));
|
||||||
|
if (h && !h_on) {
|
||||||
|
h->disconnect("gui_input", this, "gui_input_handler_h");
|
||||||
|
h->queue_delete();
|
||||||
|
h = nullptr;
|
||||||
|
}
|
||||||
|
if (v && !v_on) {
|
||||||
|
v->disconnect("gui_input", this, "gui_input_handler_v");
|
||||||
|
v->queue_delete();
|
||||||
|
v = nullptr;
|
||||||
|
}
|
||||||
|
if (r && !r_on) {
|
||||||
|
r->disconnect("gui_input", this, "gui_input_handler_r");
|
||||||
|
r->queue_delete();
|
||||||
|
r = nullptr;
|
||||||
|
}
|
||||||
|
if (yr && !yr_on) {
|
||||||
|
yr->disconnect("gui_input", this, "gui_input_handler_yr");
|
||||||
|
yr->queue_delete();
|
||||||
|
yr = nullptr;
|
||||||
|
}
|
||||||
|
if (!h && h_on) {
|
||||||
|
h = memnew(ColorRect);
|
||||||
|
h->set_custom_minimum_size(Vector2(48, 48));
|
||||||
|
add_child(h);
|
||||||
|
h->set_focus_mode(Control::FOCUS_CLICK);
|
||||||
|
h->connect("gui_input", this, "gui_input_handler_h");
|
||||||
|
}
|
||||||
|
if (!v && v_on) {
|
||||||
|
v = memnew(ColorRect);
|
||||||
|
v->set_custom_minimum_size(Vector2(48, 48));
|
||||||
|
add_child(v);
|
||||||
|
v->set_focus_mode(Control::FOCUS_CLICK);
|
||||||
|
v->connect("gui_input", this, "gui_input_handler_v");
|
||||||
|
}
|
||||||
|
if (!r && r_on) {
|
||||||
|
r = memnew(ColorRect);
|
||||||
|
r->set_custom_minimum_size(Vector2(48, 48));
|
||||||
|
add_child(r);
|
||||||
|
r->set_focus_mode(Control::FOCUS_CLICK);
|
||||||
|
r->connect("gui_input", this, "gui_input_handler_r");
|
||||||
|
}
|
||||||
|
if (!yr && yr_on) {
|
||||||
|
yr = memnew(ColorRect);
|
||||||
|
yr->set_custom_minimum_size(Vector2(48, 48));
|
||||||
|
add_child(yr);
|
||||||
|
yr->set_focus_mode(Control::FOCUS_CLICK);
|
||||||
|
yr->connect("gui_input", this, "gui_input_handler_yr");
|
||||||
|
}
|
||||||
|
set_process(true);
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,12 +9,18 @@ public:
|
|||||||
virtual ~NavPanel();
|
virtual ~NavPanel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ColorRect *h, *v, *r;
|
uint32_t flags;
|
||||||
|
ColorRect *h, *v, *r, *yr;
|
||||||
Vector3 rotations;
|
Vector3 rotations;
|
||||||
|
Transform origin_rotation, y_rotation, transform_backup;
|
||||||
void _notification(int which);
|
void _notification(int which);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
void gui_input_handler_h(const Ref<InputEvent> &e);
|
void gui_input_handler_h(const Ref<InputEvent> &e);
|
||||||
void gui_input_handler_v(const Ref<InputEvent> &e);
|
void gui_input_handler_v(const Ref<InputEvent> &e);
|
||||||
void gui_input_handler_r(const Ref<InputEvent> &e);
|
void gui_input_handler_r(const Ref<InputEvent> &e);
|
||||||
|
void gui_input_handler_yr(const Ref<InputEvent> &e);
|
||||||
|
uint32_t get_flags() const;
|
||||||
|
void set_flags(uint32_t flags);
|
||||||
|
void update_flags();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user