summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp94
-rw-r--r--editor/plugins/spatial_editor_plugin.h3
2 files changed, 52 insertions, 45 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index b269f29036..e2c8caae1f 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -63,17 +63,45 @@
#define MIN_FOV 0.01
#define MAX_FOV 179
-void SpatialEditorViewport::_update_camera() {
+void SpatialEditorViewport::_update_camera(float p_interp_delta) {
if (orthogonal) {
//camera->set_orthogonal(size.width*cursor.distance,get_znear(),get_zfar());
camera->set_orthogonal(2 * cursor.distance, 0.1, 8192);
} else
camera->set_perspective(get_fov(), get_znear(), get_zfar());
- Transform camera_transform = to_camera_transform(cursor);
+ Transform new_transform = to_camera_transform(cursor);
+ Transform old_transform = camera->get_global_transform();
+ Transform transform;
- if (camera->get_global_transform() != camera_transform) {
- camera->set_global_transform(camera_transform);
+ if (p_interp_delta && Input::get_singleton()->get_mouse_button_mask() == 0) {
+ //interpolate
+ float interp_speed = 14; //maybe should be made configuration
+ transform = old_transform.interpolate_with(new_transform, MIN(1.0, p_interp_delta * interp_speed));
+ } else {
+ transform = new_transform;
+ }
+
+ float tolerance = 0.0001;
+ bool equal = true;
+ for (int i = 0; i < 3; i++) {
+ if (transform.basis[i].distance_to(old_transform.basis[i]) > tolerance) {
+ equal = false;
+ break;
+ }
+ }
+
+ if (equal && transform.origin.distance_to(old_transform.origin) > tolerance) {
+ equal = false;
+ }
+
+ if (equal) {
+ transform = new_transform;
+ }
+
+ if (!equal || p_interp_delta == 0) {
+ //print_line(transform);
+ camera->set_global_transform(transform);
update_transform_gizmo_view();
}
}
@@ -257,14 +285,12 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario());
Set<Ref<SpatialEditorGizmo> > found_gizmos;
+ Node *edited_scene = get_tree()->get_edited_scene_root();
ObjectID closest = 0;
Spatial *item = NULL;
float closest_dist = 1e20;
int selected_handle = -1;
- Vector<Spatial *> subscenes = Vector<Spatial *>();
- Vector<Vector3> subscenes_positions = Vector<Vector3>();
-
for (int i = 0; i < instances.size(); i++) {
Spatial *spat = Object::cast_to<Spatial>(ObjectDB::get_instance(instances[i]));
@@ -275,19 +301,6 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
Ref<SpatialEditorGizmo> seg = spat->get_gizmo();
if ((!seg.is_valid()) || found_gizmos.has(seg)) {
-
- Node *subscene_candidate = spat;
- Vector3 source_click_spatial_pos = spat->get_global_transform().origin;
-
- while ((subscene_candidate->get_owner() != NULL) && (subscene_candidate->get_owner() != editor->get_edited_scene()))
- subscene_candidate = subscene_candidate->get_owner();
-
- spat = Object::cast_to<Spatial>(subscene_candidate);
- if (spat && (spat->get_filename() != "") && (subscene_candidate->get_owner() != NULL)) {
- subscenes.push_back(spat);
- subscenes_positions.push_back(source_click_spatial_pos);
- }
-
continue;
}
@@ -307,32 +320,26 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
continue;
if (dist < closest_dist) {
- closest = instances[i];
- closest_dist = dist;
- selected_handle = handle;
- item = spat;
+ //make sure that whathever is selected is editable
+ while (spat && spat != edited_scene && spat->get_owner() != edited_scene && !edited_scene->is_editable_instance(spat->get_owner())) {
+
+ spat = Object::cast_to<Spatial>(spat->get_owner());
+ }
+
+ if (spat) {
+ item = spat;
+ closest = spat->get_instance_id();
+ closest_dist = dist;
+ selected_handle = handle;
+ } else {
+ ERR_PRINT("Bug?");
+ }
}
// if (editor_selection->is_selected(spat))
// r_includes_current=true;
}
- for (int idx_subscene = 0; idx_subscene < subscenes.size(); idx_subscene++) {
-
- Spatial *subscene = subscenes.get(idx_subscene);
- float dist = ray.cross(subscenes_positions.get(idx_subscene) - pos).length();
-
- if ((dist < 0) || (dist > 1.2))
- continue;
-
- if (dist < closest_dist) {
- closest = subscene->get_instance_id();
- closest_dist = dist;
- item = subscene;
- selected_handle = -1;
- }
- }
-
if (!item)
return 0;
@@ -1678,7 +1685,7 @@ void SpatialEditorViewport::_notification(int p_what) {
set_process(visible);
if (visible)
- _update_camera();
+ _update_camera(0);
call_deferred("update_transform_gizmo_view");
}
@@ -1710,7 +1717,7 @@ void SpatialEditorViewport::_notification(int p_what) {
_update_freelook(delta);
- _update_camera();
+ _update_camera(get_process_delta_time());
Map<Node *, Object *> &selection = editor_selection->get_selection();
@@ -3677,7 +3684,7 @@ void SpatialEditor::_request_gizmo(Object *p_obj) {
Spatial *sp = Object::cast_to<Spatial>(p_obj);
if (!sp)
return;
- if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || sp->get_owner() == editor->get_edited_scene() || editor->get_edited_scene()->is_editable_instance(sp->get_owner()))) {
+ if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) {
Ref<SpatialEditorGizmo> seg;
@@ -3691,7 +3698,6 @@ void SpatialEditor::_request_gizmo(Object *p_obj) {
if (!seg.is_valid()) {
seg = gizmos->get_gizmo(sp);
}
-
if (seg.is_valid()) {
sp->set_gizmo(seg);
}
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 2fd72739df..7797a657c0 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -49,6 +49,7 @@ class SpatialEditorGizmo : public SpatialGizmo {
GDCLASS(SpatialEditorGizmo, SpatialGizmo);
bool selected;
+ bool instanced;
public:
void set_selected(bool p_selected) { selected = p_selected; }
@@ -240,7 +241,7 @@ private:
void set_message(String p_message, float p_time = 5);
//
- void _update_camera();
+ void _update_camera(float p_interp_delta);
Transform to_camera_transform(const Cursor &p_cursor) const;
void _draw();