mirror of
https://github.com/godotengine/godot.git
synced 2024-11-13 23:52:41 +00:00
Ability to shrink 3D viewport by half
This commit is contained in:
parent
157fa55e34
commit
a4ea63737c
@ -267,12 +267,12 @@ Vector3 SpatialEditorViewport::_get_camera_position() const {
|
||||
|
||||
Point2 SpatialEditorViewport::_point_to_screen(const Vector3 &p_point) {
|
||||
|
||||
return camera->unproject_position(p_point);
|
||||
return camera->unproject_position(p_point) * viewport_container->get_stretch_shrink();
|
||||
}
|
||||
|
||||
Vector3 SpatialEditorViewport::_get_ray_pos(const Vector2 &p_pos) const {
|
||||
|
||||
return camera->project_ray_origin(p_pos);
|
||||
return camera->project_ray_origin(p_pos / viewport_container->get_stretch_shrink());
|
||||
}
|
||||
|
||||
Vector3 SpatialEditorViewport::_get_camera_normal() const {
|
||||
@ -282,7 +282,7 @@ Vector3 SpatialEditorViewport::_get_camera_normal() const {
|
||||
|
||||
Vector3 SpatialEditorViewport::_get_ray(const Vector2 &p_pos) const {
|
||||
|
||||
return camera->project_ray_normal(p_pos);
|
||||
return camera->project_ray_normal(p_pos / viewport_container->get_stretch_shrink());
|
||||
}
|
||||
/*
|
||||
void SpatialEditorViewport::_clear_id(Spatial *p_node) {
|
||||
@ -2050,6 +2050,12 @@ void SpatialEditorViewport::_notification(int p_what) {
|
||||
viewport->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2));
|
||||
viewport->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3));
|
||||
|
||||
bool shrink = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION));
|
||||
|
||||
if (shrink != viewport_container->get_stretch_shrink() > 1) {
|
||||
viewport_container->set_stretch_shrink(shrink ? 2 : 1);
|
||||
}
|
||||
|
||||
//update msaa if changed
|
||||
|
||||
int msaa_mode = ProjectSettings::get_singleton()->get("rendering/quality/filters/msaa");
|
||||
@ -2401,6 +2407,13 @@ void SpatialEditorViewport::_menu_option(int p_option) {
|
||||
view_menu->get_popup()->set_item_checked(idx, current);
|
||||
|
||||
} break;
|
||||
case VIEW_HALF_RESOLUTION: {
|
||||
|
||||
int idx = view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION);
|
||||
bool current = view_menu->get_popup()->is_item_checked(idx);
|
||||
current = !current;
|
||||
view_menu->get_popup()->set_item_checked(idx, current);
|
||||
} break;
|
||||
case VIEW_INFORMATION: {
|
||||
|
||||
int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION);
|
||||
@ -2630,6 +2643,12 @@ void SpatialEditorViewport::set_state(const Dictionary &p_state) {
|
||||
camera->set_doppler_tracking(doppler ? Camera::DOPPLER_TRACKING_IDLE_STEP : Camera::DOPPLER_TRACKING_DISABLED);
|
||||
view_menu->get_popup()->set_item_checked(idx, doppler);
|
||||
}
|
||||
if (p_state.has("half_res")) {
|
||||
bool half_res = p_state["half_res"];
|
||||
|
||||
int idx = view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION);
|
||||
view_menu->get_popup()->set_item_checked(idx, half_res);
|
||||
}
|
||||
|
||||
if (p_state.has("previewing")) {
|
||||
Node *pv = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["previewing"]);
|
||||
@ -2655,6 +2674,7 @@ Dictionary SpatialEditorViewport::get_state() const {
|
||||
d["use_environment"] = camera->get_environment().is_valid();
|
||||
d["use_orthogonal"] = camera->get_projection() == Camera::PROJECTION_ORTHOGONAL;
|
||||
d["listener"] = viewport->is_audio_listener();
|
||||
d["half_res"] = viewport_container->get_stretch_shrink() > 1;
|
||||
if (previewing) {
|
||||
d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing);
|
||||
}
|
||||
@ -3072,6 +3092,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
|
||||
|
||||
spatial_editor = p_spatial_editor;
|
||||
ViewportContainer *c = memnew(ViewportContainer);
|
||||
viewport_container = c;
|
||||
c->set_stretch(true);
|
||||
add_child(c);
|
||||
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
||||
@ -3118,6 +3139,8 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION);
|
||||
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT), true);
|
||||
view_menu->get_popup()->add_separator();
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_half_resolution", TTR("Half Resolution")), VIEW_HALF_RESOLUTION);
|
||||
view_menu->get_popup()->add_separator();
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER);
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Doppler Enable")), VIEW_AUDIO_DOPPLER);
|
||||
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true);
|
||||
|
@ -83,6 +83,7 @@ class SpatialEditorViewport : public Control {
|
||||
VIEW_PERSPECTIVE,
|
||||
VIEW_ENVIRONMENT,
|
||||
VIEW_ORTHOGONAL,
|
||||
VIEW_HALF_RESOLUTION,
|
||||
VIEW_AUDIO_LISTENER,
|
||||
VIEW_AUDIO_DOPPLER,
|
||||
VIEW_GIZMOS,
|
||||
@ -120,6 +121,7 @@ private:
|
||||
UndoRedo *undo_redo;
|
||||
|
||||
Button *preview_camera;
|
||||
ViewportContainer *viewport_container;
|
||||
|
||||
MenuButton *view_menu;
|
||||
|
||||
|
@ -62,6 +62,34 @@ bool ViewportContainer::is_stretch_enabled() const {
|
||||
return stretch;
|
||||
}
|
||||
|
||||
void ViewportContainer::set_stretch_shrink(int p_shrink) {
|
||||
|
||||
ERR_FAIL_COND(p_shrink < 1);
|
||||
if (shrink == p_shrink)
|
||||
return;
|
||||
|
||||
shrink = p_shrink;
|
||||
|
||||
if (!stretch)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Viewport *c = Object::cast_to<Viewport>(get_child(i));
|
||||
if (!c)
|
||||
continue;
|
||||
|
||||
c->set_size(get_size() / shrink);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
int ViewportContainer::get_stretch_shrink() const {
|
||||
|
||||
return shrink;
|
||||
}
|
||||
|
||||
void ViewportContainer::_notification(int p_what) {
|
||||
|
||||
if (p_what == NOTIFICATION_RESIZED) {
|
||||
@ -75,7 +103,7 @@ void ViewportContainer::_notification(int p_what) {
|
||||
if (!c)
|
||||
continue;
|
||||
|
||||
c->set_size(get_size());
|
||||
c->set_size(get_size() / shrink);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,10 +143,15 @@ void ViewportContainer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch);
|
||||
ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &ViewportContainer::set_stretch_shrink);
|
||||
ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &ViewportContainer::get_stretch_shrink);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink");
|
||||
}
|
||||
|
||||
ViewportContainer::ViewportContainer() {
|
||||
|
||||
stretch = false;
|
||||
shrink = 1;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class ViewportContainer : public Container {
|
||||
GDCLASS(ViewportContainer, Container);
|
||||
|
||||
bool stretch;
|
||||
int shrink;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
@ -46,6 +47,9 @@ public:
|
||||
void set_stretch(bool p_enable);
|
||||
bool is_stretch_enabled() const;
|
||||
|
||||
void set_stretch_shrink(int p_shrink);
|
||||
int get_stretch_shrink() const;
|
||||
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
ViewportContainer();
|
||||
|
Loading…
Reference in New Issue
Block a user