summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-05-28 21:46:48 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-05-28 21:48:05 -0300
commitbb20f230ad307a2a5f18c03bece3793d29ae208a (patch)
treeb217d7c10054e23b0f456acee41bc208dc12bfdf /editor
parent06fc9637966dafe8e06e1d4f823bf9e8b3475c97 (diff)
-Added .hdr format support
-Added default environment editor setting -Added environment created by default in new projects -Removed default light and ambient from spatial editor, to make the editor more PBR compliant
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_node.cpp32
-rw-r--r--editor/editor_node.h1
-rw-r--r--editor/plugins/color_ramp_editor_plugin.cpp4
-rw-r--r--editor/plugins/color_ramp_editor_plugin.h2
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp151
-rw-r--r--editor/plugins/spatial_editor_plugin.h20
-rw-r--r--editor/project_manager.cpp15
7 files changed, 46 insertions, 179 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index f00ad97ee8..245b350790 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -889,6 +889,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
}
editor_data.apply_changes_in_editors();
+ _save_default_environment();
_set_scene_metadata(p_file, idx);
@@ -950,7 +951,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
_dialog_display_file_error(p_file, err);
}
-};
+}
void EditorNode::_import_action(const String &p_action) {
#if 0
@@ -1113,6 +1114,7 @@ void EditorNode::_dialog_action(String p_file) {
if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
//_save_scene(p_file);
+ _save_default_environment();
_save_scene_with_preview(p_file);
}
@@ -1122,6 +1124,7 @@ void EditorNode::_dialog_action(String p_file) {
if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
//_save_scene(p_file);
+ _save_default_environment();
_save_scene_with_preview(p_file);
_call_build();
_run(true);
@@ -1375,6 +1378,17 @@ void EditorNode::_property_editor_back() {
_edit_current();
}
+void EditorNode::_save_default_environment() {
+
+ Ref<Environment> fallback = get_scene_root()->get_world()->get_fallback_environment();
+
+ if (fallback.is_valid() && fallback->get_path().is_resource_file()) {
+ Map<RES, bool> processed;
+ _find_and_save_edited_subresources(fallback.ptr(), processed, 0);
+ save_resource_in_path(fallback, fallback->get_path());
+ }
+}
+
void EditorNode::_imported(Node *p_node) {
/*
@@ -1453,11 +1467,16 @@ void EditorNode::_edit_current() {
Node *current_node = current_obj->cast_to<Node>();
ERR_FAIL_COND(!current_node);
- ERR_FAIL_COND(!current_node->is_inside_tree());
+ // ERR_FAIL_COND(!current_node->is_inside_tree());
property_editor->edit(current_node);
- node_dock->set_node(current_node);
- scene_tree_dock->set_selected(current_node);
+ if (current_node->is_inside_tree()) {
+ node_dock->set_node(current_node);
+ scene_tree_dock->set_selected(current_node);
+ } else {
+ node_dock->set_node(NULL);
+ scene_tree_dock->set_selected(NULL);
+ }
object_menu->get_popup()->clear();
//top_pallete->set_current_tab(0);
@@ -1951,6 +1970,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
}
} // else: ignore new scenes
}
+
+ _save_default_environment();
} break;
case FILE_SAVE_BEFORE_RUN: {
if (!p_confirmed) {
@@ -2384,6 +2405,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} break;
case RUN_PLAY_SCENE: {
+
+ _save_default_environment();
_menu_option_confirm(RUN_STOP, true);
_call_build();
_run(true);
@@ -5237,6 +5260,7 @@ EditorNode::EditorNode() {
p->add_separator();
p->add_item(TTR("Project Settings"), RUN_SETTINGS);
p->add_separator();
+
#ifdef OSX_ENABLED
p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q);
#else
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 55b3aa94d3..bb5b57a454 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -593,6 +593,7 @@ private:
static int plugin_init_callback_count;
static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
+ void _save_default_environment();
void _call_build();
static int build_callback_count;
diff --git a/editor/plugins/color_ramp_editor_plugin.cpp b/editor/plugins/color_ramp_editor_plugin.cpp
index 63369e5475..e4172db415 100644
--- a/editor/plugins/color_ramp_editor_plugin.cpp
+++ b/editor/plugins/color_ramp_editor_plugin.cpp
@@ -46,10 +46,10 @@ ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) {
void ColorRampEditorPlugin::edit(Object *p_object) {
- ColorRamp *color_ramp = p_object->cast_to<ColorRamp>();
+ Gradient *color_ramp = p_object->cast_to<Gradient>();
if (!color_ramp)
return;
- color_ramp_ref = Ref<ColorRamp>(color_ramp);
+ color_ramp_ref = Ref<Gradient>(color_ramp);
ramp_editor->set_points(color_ramp_ref->get_points());
}
diff --git a/editor/plugins/color_ramp_editor_plugin.h b/editor/plugins/color_ramp_editor_plugin.h
index 73b15b85a1..35446062b5 100644
--- a/editor/plugins/color_ramp_editor_plugin.h
+++ b/editor/plugins/color_ramp_editor_plugin.h
@@ -39,7 +39,7 @@ class ColorRampEditorPlugin : public EditorPlugin {
GDCLASS(ColorRampEditorPlugin, EditorPlugin);
bool _2d;
- Ref<ColorRamp> color_ramp_ref;
+ Ref<Gradient> color_ramp_ref;
ColorRampEdit *ramp_editor;
EditorNode *editor;
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index c4595b477e..ff4b5e430e 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -2493,17 +2493,11 @@ Dictionary SpatialEditor::get_state() const {
d["viewports"] = vpdata;
- d["default_light"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT));
- d["ambient_light_color"] = settings_ambient_color->get_pick_color();
-
- d["default_srgb"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB));
d["show_grid"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID));
d["show_origin"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN));
d["fov"] = get_fov();
d["znear"] = get_znear();
d["zfar"] = get_zfar();
- d["deflight_rot_x"] = settings_default_light_rot_x;
- d["deflight_rot_y"] = settings_default_light_rot_y;
return d;
}
@@ -2565,26 +2559,6 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
if (d.has("fov"))
settings_fov->set_value(float(d["fov"]));
- if (d.has("default_light")) {
- bool use = d["default_light"];
-
- bool existing = light_instance.is_valid();
- if (use != existing) {
- if (existing) {
- VisualServer::get_singleton()->free(light_instance);
- light_instance = RID();
- } else {
- light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform);
- }
- view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), light_instance.is_valid());
- }
- }
- if (d.has("ambient_light_color")) {
- settings_ambient_color->set_pick_color(d["ambient_light_color"]);
- //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,d["ambient_light_color"]);
- }
-
if (d.has("default_srgb")) {
bool use = d["default_srgb"];
@@ -2607,13 +2581,6 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
VisualServer::get_singleton()->instance_set_visible(origin_instance, use);
}
}
-
- if (d.has("deflight_rot_x"))
- settings_default_light_rot_x = d["deflight_rot_x"];
- if (d.has("deflight_rot_y"))
- settings_default_light_rot_y = d["deflight_rot_y"];
-
- _update_default_light_angle();
}
void SpatialEditor::edit(Spatial *p_spatial) {
@@ -2750,38 +2717,6 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
xform_dialog->popup_centered(Size2(200, 200));
} break;
- case MENU_VIEW_USE_DEFAULT_LIGHT: {
-
- bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option));
-
- if (is_checked) {
- VisualServer::get_singleton()->free(light_instance);
- light_instance = RID();
- } else {
- light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario());
- VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform);
-
- _update_default_light_angle();
- }
-
- view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), light_instance.is_valid());
-
- } break;
- case MENU_VIEW_USE_DEFAULT_SRGB: {
-
- bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option));
-
- if (is_checked) {
- //viewport_environment->set_enable_fx(Environment::FX_SRGB,false);
- } else {
- //viewport_environment->set_enable_fx(Environment::FX_SRGB,true);
- }
-
- is_checked = !is_checked;
-
- view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), is_checked);
-
- } break;
case MENU_VIEW_USE_1_VIEWPORT: {
for (int i = 1; i < 4; i++) {
@@ -2993,14 +2928,6 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
void SpatialEditor::_init_indicators() {
- //make sure that the camera indicator is not selectable
- light = VisualServer::get_singleton()->light_create(VisualServer::LIGHT_DIRECTIONAL);
- //VisualServer::get_singleton()->light_set_shadow( light, true );
- light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario());
-
- light_transform.rotate(Vector3(1, 0, 0), -Math_PI / 5.0);
- VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform);
-
//RID mat = VisualServer::get_singleton()->fixed_material_create();
///VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA,true);
//VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);
@@ -3258,8 +3185,6 @@ void SpatialEditor::_finish_indicators() {
VisualServer::get_singleton()->free(grid_instance[i]);
VisualServer::get_singleton()->free(grid[i]);
}
- VisualServer::get_singleton()->free(light_instance);
- VisualServer::get_singleton()->free(light);
//VisualServer::get_singleton()->free(poly);
//VisualServer::get_singleton()->free(indicators_instance);
//VisualServer::get_singleton()->free(indicators);
@@ -3351,14 +3276,12 @@ void SpatialEditor::_notification(int p_what) {
_menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT);
get_tree()->connect("node_removed", this, "_node_removed");
- VS::get_singleton()->scenario_set_fallback_environment(get_viewport()->find_world()->get_scenario(), viewport_environment->get_rid());
}
if (p_what == NOTIFICATION_ENTER_TREE) {
gizmos = memnew(SpatialEditorGizmos);
_init_indicators();
- _update_default_light_angle();
}
if (p_what == NOTIFICATION_EXIT_TREE) {
@@ -3481,8 +3404,6 @@ void SpatialEditor::_bind_methods() {
ClassDB::bind_method("_xform_dialog_action", &SpatialEditor::_xform_dialog_action);
ClassDB::bind_method("_get_editor_data", &SpatialEditor::_get_editor_data);
ClassDB::bind_method("_request_gizmo", &SpatialEditor::_request_gizmo);
- ClassDB::bind_method("_default_light_angle_input", &SpatialEditor::_default_light_angle_input);
- ClassDB::bind_method("_update_ambient_light_color", &SpatialEditor::_update_ambient_light_color);
ClassDB::bind_method("_toggle_maximize_view", &SpatialEditor::_toggle_maximize_view);
ADD_SIGNAL(MethodInfo("transform_key_request"));
@@ -3517,43 +3438,6 @@ void SpatialEditor::clear() {
}
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID), true);
-
- settings_default_light_rot_x = Math_PI * 0.3;
- settings_default_light_rot_y = Math_PI * 0.2;
-
- //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15));
- settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15));
- if (!light_instance.is_valid())
- _menu_item_pressed(MENU_VIEW_USE_DEFAULT_LIGHT);
-
- _update_default_light_angle();
-}
-
-void SpatialEditor::_update_ambient_light_color(const Color &p_color) {
-
- //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,settings_ambient_color->get_color());
-}
-
-void SpatialEditor::_update_default_light_angle() {
-
- Transform t;
- t.basis.rotate(Vector3(1, 0, 0), -settings_default_light_rot_x);
- t.basis.rotate(Vector3(0, 1, 0), -settings_default_light_rot_y);
- settings_dlight->set_transform(t);
- if (light_instance.is_valid()) {
- VS::get_singleton()->instance_set_transform(light_instance, t);
- }
-}
-
-void SpatialEditor::_default_light_angle_input(const Ref<InputEvent> &p_event) {
-
- Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && mm->get_button_mask() & (0x1 | 0x2 | 0x4)) {
-
- settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - mm->get_relative().x * 0.01, Math_PI * 2.0);
- settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - mm->get_relative().y * 0.01, Math_PI * 2.0);
- _update_default_light_angle();
- }
}
SpatialEditor::SpatialEditor(EditorNode *p_editor) {
@@ -3674,10 +3558,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
p = view_menu->get_popup();
- p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_default_light", TTR("Use Default Light")), MENU_VIEW_USE_DEFAULT_LIGHT);
- p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_default_srgb", TTR("Use Default sRGB")), MENU_VIEW_USE_DEFAULT_SRGB);
- p->add_separator();
-
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/1_viewport", TTR("1 Viewport"), KEY_MASK_CMD + KEY_1), MENU_VIEW_USE_1_VIEWPORT);
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports", TTR("2 Viewports"), KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS);
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports_alt", TTR("2 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS_ALT);
@@ -3696,7 +3576,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
p->add_separator();
p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS);
- p->set_item_checked(p->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), true);
p->set_item_checked(p->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true);
p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true);
p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true);
@@ -3755,36 +3634,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
settings_dialog->add_child(settings_vbc);
//settings_dialog->set_child_rect(settings_vbc);
- settings_light_base = memnew(ViewportContainer);
- settings_light_base->set_custom_minimum_size(Size2(128, 128));
- settings_light_base->connect("gui_input", this, "_default_light_angle_input");
- settings_vbc->add_margin_child(TTR("Default Light Normal:"), settings_light_base);
- settings_light_vp = memnew(Viewport);
- settings_light_vp->set_disable_input(true);
- settings_light_vp->set_use_own_world(true);
- settings_light_base->add_child(settings_light_vp);
-
- settings_dlight = memnew(DirectionalLight);
- settings_light_vp->add_child(settings_dlight);
- settings_sphere = memnew(ImmediateGeometry);
- settings_sphere->begin(Mesh::PRIMITIVE_TRIANGLES, Ref<Texture>());
- settings_sphere->set_color(Color(1, 1, 1));
- settings_sphere->add_sphere(32, 16, 1);
- settings_sphere->end();
- settings_light_vp->add_child(settings_sphere);
- settings_camera = memnew(Camera);
- settings_light_vp->add_child(settings_camera);
- settings_camera->set_translation(Vector3(0, 0, 2));
- settings_camera->set_orthogonal(2.1, 0.1, 5);
-
- settings_default_light_rot_x = Math_PI * 0.3;
- settings_default_light_rot_y = Math_PI * 0.2;
-
- settings_ambient_color = memnew(ColorPickerButton);
- settings_vbc->add_margin_child(TTR("Ambient Light Color:"), settings_ambient_color);
- settings_ambient_color->connect("color_changed", this, "_update_ambient_light_color");
- settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15));
-
settings_fov = memnew(SpinBox);
settings_fov->set_max(179);
settings_fov->set_min(1);
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 1f76d9bfb8..88245ad0dc 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -321,10 +321,6 @@ private:
VisualServer::ScenarioDebugMode scenario_debug;
- RID light;
- RID light_instance;
- Transform light_transform;
-
RID origin;
RID origin_instance;
RID grid[3];
@@ -383,8 +379,6 @@ private:
MENU_VIEW_USE_3_VIEWPORTS,
MENU_VIEW_USE_3_VIEWPORTS_ALT,
MENU_VIEW_USE_4_VIEWPORTS,
- MENU_VIEW_USE_DEFAULT_LIGHT,
- MENU_VIEW_USE_DEFAULT_SRGB,
MENU_VIEW_DISPLAY_NORMAL,
MENU_VIEW_DISPLAY_WIREFRAME,
MENU_VIEW_DISPLAY_OVERDRAW,
@@ -419,16 +413,6 @@ private:
SpinBox *settings_fov;
SpinBox *settings_znear;
SpinBox *settings_zfar;
- DirectionalLight *settings_dlight;
- ImmediateGeometry *settings_sphere;
- Camera *settings_camera;
- float settings_default_light_rot_x;
- float settings_default_light_rot_y;
-
- ViewportContainer *settings_light_base;
- Viewport *settings_light_vp;
- ColorPickerButton *settings_ambient_color;
- Ref<Image> settings_light_dir_image;
void _xform_dialog_action();
void _menu_item_pressed(int p_option);
@@ -462,10 +446,6 @@ private:
SpatialEditorGizmos *gizmos;
SpatialEditor();
- void _update_ambient_light_color(const Color &p_color);
- void _update_default_light_angle();
- void _default_light_angle_input(const Ref<InputEvent> &p_event);
-
bool is_any_freelook_active() const;
protected:
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 50b518afba..a4e8ef70ce 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -203,10 +203,23 @@ private:
f->store_line("\n");
f->store_line("name=\"" + project_name->get_text() + "\"");
f->store_line("icon=\"res://icon.png\"");
-
+ f->store_line("[rendering]");
+ f->store_line("viewport/default_environment=\"res://default_env.tres\"");
memdelete(f);
ResourceSaver::save(dir.plus_file("/icon.png"), get_icon("DefaultProjectIcon", "EditorIcons"));
+
+ f = FileAccess::open(dir.plus_file("/default_env.tres"), FileAccess::WRITE);
+ if (!f) {
+ error->set_text(TTR("Couldn't create project.godot in project path."));
+ } else {
+ f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]");
+ f->store_line("[sub_resource type=\"ProceduralSky\" id=1]");
+ f->store_line("[resource]");
+ f->store_line("background_mode = 2");
+ f->store_line("background_sky = SubResource( 1 )");
+ memdelete(f);
+ }
}
} else if (mode == MODE_INSTALL) {