diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_export.cpp | 20 | ||||
-rw-r--r-- | editor/editor_properties.cpp | 12 | ||||
-rw-r--r-- | editor/editor_properties.h | 4 | ||||
-rw-r--r-- | editor/import/scene_importer_mesh.cpp | 46 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 61 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.h | 9 | ||||
-rw-r--r-- | editor/project_settings_editor.cpp | 9 |
7 files changed, 137 insertions, 24 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index fd4423646f..dd3e81c8c0 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -732,6 +732,26 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & _export_find_dependencies(files[i], paths); } + + // Add autoload resources and their dependencies + List<PropertyInfo> props; + ProjectSettings::get_singleton()->get_property_list(&props); + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + const PropertyInfo &pi = E->get(); + + if (!pi.name.begins_with("autoload/")) { + continue; + } + + String autoload_path = ProjectSettings::get_singleton()->get(pi.name); + + if (autoload_path.begins_with("*")) { + autoload_path = autoload_path.substr(1); + } + + _export_find_dependencies(autoload_path, paths); + } } //add native icons to non-resource include list diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 3fa183e10c..4d8a4f46b2 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2148,6 +2148,12 @@ void EditorPropertyColor::_color_changed(const Color &p_color) { emit_changed(get_edited_property(), p_color, "", true); } +void EditorPropertyColor::_popup_closed() { + if (picker->get_pick_color() != last_color) { + emit_changed(get_edited_property(), picker->get_pick_color(), "", false); + } +} + void EditorPropertyColor::_picker_created() { // get default color picker mode from editor settings int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode"); @@ -2158,6 +2164,10 @@ void EditorPropertyColor::_picker_created() { } } +void EditorPropertyColor::_picker_opening() { + last_color = picker->get_pick_color(); +} + void EditorPropertyColor::_bind_methods() { } @@ -2191,7 +2201,9 @@ EditorPropertyColor::EditorPropertyColor() { add_child(picker); picker->set_flat(true); picker->connect("color_changed", callable_mp(this, &EditorPropertyColor::_color_changed)); + picker->connect("popup_closed", callable_mp(this, &EditorPropertyColor::_popup_closed)); picker->connect("picker_created", callable_mp(this, &EditorPropertyColor::_picker_created)); + picker->get_popup()->connect("about_to_popup", callable_mp(this, &EditorPropertyColor::_picker_opening)); } ////////////// NODE PATH ////////////////////// diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 856a406e62..4775259111 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -547,7 +547,11 @@ class EditorPropertyColor : public EditorProperty { GDCLASS(EditorPropertyColor, EditorProperty); ColorPickerButton *picker; void _color_changed(const Color &p_color); + void _popup_closed(); void _picker_created(); + void _picker_opening(); + + Color last_color; protected: static void _bind_methods(); diff --git a/editor/import/scene_importer_mesh.cpp b/editor/import/scene_importer_mesh.cpp index cd7d58c6f6..620437af0e 100644 --- a/editor/import/scene_importer_mesh.cpp +++ b/editor/import/scene_importer_mesh.cpp @@ -140,6 +140,12 @@ void EditorSceneImporterMesh::generate_lods() { if (!SurfaceTool::simplify_func) { return; } + if (!SurfaceTool::simplify_scale_func) { + return; + } + if (!SurfaceTool::simplify_sloppy_func) { + return; + } for (int i = 0; i < surfaces.size(); i++) { if (surfaces[i].primitive != Mesh::PRIMITIVE_TRIANGLES) { @@ -157,20 +163,52 @@ void EditorSceneImporterMesh::generate_lods() { int min_indices = 10; int index_target = indices.size() / 2; - print_line("total: " + itos(indices.size())); + print_line("Total indices: " + itos(indices.size())); + float mesh_scale = SurfaceTool::simplify_scale_func((const float *)vertices_ptr, vertex_count, sizeof(Vector3)); + const float target_error = 1e-3f; + float abs_target_error = target_error / mesh_scale; while (index_target > min_indices) { float error; Vector<int> new_indices; new_indices.resize(indices.size()); - size_t new_len = SurfaceTool::simplify_func((unsigned int *)new_indices.ptrw(), (const unsigned int *)indices.ptr(), indices.size(), (const float *)vertices_ptr, vertex_count, sizeof(Vector3), index_target, 1e20, &error); - print_line("shoot for " + itos(index_target) + ", got " + itos(new_len) + " distance " + rtos(error)); + size_t new_len = SurfaceTool::simplify_func((unsigned int *)new_indices.ptrw(), (const unsigned int *)indices.ptr(), indices.size(), (const float *)vertices_ptr, vertex_count, sizeof(Vector3), index_target, abs_target_error, &error); if ((int)new_len > (index_target * 120 / 100)) { + // Attribute discontinuities break normals. + bool is_sloppy = false; + if (is_sloppy) { + abs_target_error = target_error / mesh_scale; + index_target = new_len; + while (index_target > min_indices) { + Vector<int> sloppy_new_indices; + sloppy_new_indices.resize(indices.size()); + new_len = SurfaceTool::simplify_sloppy_func((unsigned int *)sloppy_new_indices.ptrw(), (const unsigned int *)indices.ptr(), indices.size(), (const float *)vertices_ptr, vertex_count, sizeof(Vector3), index_target, abs_target_error, &error); + if ((int)new_len > (index_target * 120 / 100)) { + break; // 20 percent tolerance + } + sloppy_new_indices.resize(new_len); + Surface::LOD lod; + lod.distance = error * mesh_scale; + abs_target_error = lod.distance; + if (Math::is_equal_approx(abs_target_error, 0.0f)) { + return; + } + lod.indices = sloppy_new_indices; + print_line("Lod " + itos(surfaces.write[i].lods.size()) + " shoot for " + itos(index_target / 3) + " triangles, got " + itos(new_len / 3) + " triangles. Distance " + rtos(lod.distance) + ". Use simplify sloppy."); + surfaces.write[i].lods.push_back(lod); + index_target /= 2; + } + } break; // 20 percent tolerance } new_indices.resize(new_len); Surface::LOD lod; - lod.distance = error; + lod.distance = error * mesh_scale; + abs_target_error = lod.distance; + if (Math::is_equal_approx(abs_target_error, 0.0f)) { + return; + } lod.indices = new_indices; + print_line("Lod " + itos(surfaces.write[i].lods.size()) + " shoot for " + itos(index_target / 3) + " triangles, got " + itos(new_len / 3) + " triangles. Distance " + rtos(lod.distance)); surfaces.write[i].lods.push_back(lod); index_target /= 2; } diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 056562a7a7..58ae115b26 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2799,15 +2799,35 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da void VisualShaderEditor::_show_preview_text() { preview_showed = !preview_showed; - preview_vbox->set_visible(preview_showed); if (preview_showed) { + if (preview_first) { + preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE)); + preview_window->popup_centered(); + preview_first = false; + } else { + preview_window->popup(); + } + _preview_size_changed(); + if (pending_update_preview) { _update_preview(); pending_update_preview = false; } + } else { + preview_window->hide(); } } +void VisualShaderEditor::_preview_close_requested() { + preview_showed = false; + preview_window->hide(); + preview_shader->set_pressed(false); +} + +void VisualShaderEditor::_preview_size_changed() { + preview_vbox->set_custom_minimum_size(preview_window->get_size()); +} + static ShaderLanguage::DataType _get_global_variable_type(const StringName &p_variable) { RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_variable); return RS::global_variable_type_get_shader_datatype(gvt); @@ -2843,6 +2863,16 @@ void VisualShaderEditor::_update_preview() { } } +void VisualShaderEditor::_visibility_changed() { + if (!is_visible()) { + if (preview_window->is_visible()) { + preview_shader->set_pressed(false); + preview_window->hide(); + preview_showed = false; + } + } +} + void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph); ClassDB::bind_method("_update_options_menu", &VisualShaderEditor::_update_options_menu); @@ -2873,7 +2903,6 @@ VisualShaderEditor::VisualShaderEditor() { saved_node_pos = Point2(0, 0); ShaderLanguage::get_keyword_list(&keyword_list); - preview_showed = false; pending_update_preview = false; shader_error = false; @@ -2882,16 +2911,11 @@ VisualShaderEditor::VisualShaderEditor() { from_node = -1; from_slot = -1; - main_box = memnew(HSplitContainer); - main_box->set_v_size_flags(SIZE_EXPAND_FILL); - main_box->set_h_size_flags(SIZE_EXPAND_FILL); - add_child(main_box); - graph = memnew(GraphEdit); graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL); graph->set_v_size_flags(SIZE_EXPAND_FILL); graph->set_h_size_flags(SIZE_EXPAND_FILL); - main_box->add_child(graph); + add_child(graph); graph->set_drag_forwarding(this); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT); @@ -2912,6 +2936,7 @@ VisualShaderEditor::VisualShaderEditor() { graph->connect("gui_input", callable_mp(this, &VisualShaderEditor::_graph_gui_input)); graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty)); graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty)); + graph->connect("visibility_changed", callable_mp(this, &VisualShaderEditor::_visibility_changed)); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR); @@ -2966,29 +2991,35 @@ VisualShaderEditor::VisualShaderEditor() { preview_shader = memnew(Button); preview_shader->set_flat(true); preview_shader->set_toggle_mode(true); - preview_shader->set_tooltip(TTR("Show resulted shader code.")); + preview_shader->set_tooltip(TTR("Show generated shader code.")); graph->get_zoom_hbox()->add_child(preview_shader); preview_shader->connect("pressed", callable_mp(this, &VisualShaderEditor::_show_preview_text)); /////////////////////////////////////// - // PREVIEW PANEL + // PREVIEW WINDOW /////////////////////////////////////// + preview_window = memnew(Window); + preview_window->set_title(TTR("Generated shader code")); + preview_window->set_visible(preview_showed); + preview_window->connect("close_requested", callable_mp(this, &VisualShaderEditor::_preview_close_requested)); + preview_window->connect("size_changed", callable_mp(this, &VisualShaderEditor::_preview_size_changed)); + add_child(preview_window); + preview_vbox = memnew(VBoxContainer); - preview_vbox->set_visible(preview_showed); - main_box->add_child(preview_vbox); + preview_window->add_child(preview_vbox); + preview_text = memnew(CodeEdit); syntax_highlighter.instance(); preview_vbox->add_child(preview_text); - preview_text->set_h_size_flags(SIZE_EXPAND_FILL); - preview_text->set_v_size_flags(SIZE_EXPAND_FILL); - preview_text->set_custom_minimum_size(Size2(400 * EDSCALE, 0)); + preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); preview_text->set_syntax_highlighter(syntax_highlighter); preview_text->set_draw_line_numbers(true); preview_text->set_readonly(true); error_text = memnew(Label); preview_vbox->add_child(error_text); + error_text->set_autowrap(true); error_text->set_visible(false); /////////////////////////////////////// diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 6e8ac92dc2..1c3296a10b 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -134,7 +134,6 @@ class VisualShaderEditor : public VBoxContainer { int editing_port; Ref<VisualShader> visual_shader; - HSplitContainer *main_box; GraphEdit *graph; Button *add_node; Button *preview_shader; @@ -148,6 +147,7 @@ class VisualShaderEditor : public VBoxContainer { bool pending_update_preview; bool shader_error; + Window *preview_window; VBoxContainer *preview_vbox; CodeEdit *preview_text; Ref<CodeHighlighter> syntax_highlighter; @@ -161,7 +161,8 @@ class VisualShaderEditor : public VBoxContainer { PopupMenu *popup_menu; MenuButton *tools; - bool preview_showed; + bool preview_first = true; + bool preview_showed = false; bool particles_mode; enum TypeFlags { @@ -277,6 +278,8 @@ class VisualShaderEditor : public VBoxContainer { void _set_mode(int p_which); void _show_preview_text(); + void _preview_close_requested(); + void _preview_size_changed(); void _update_preview(); String _get_description(int p_idx); @@ -388,6 +391,8 @@ class VisualShaderEditor : public VBoxContainer { void _update_uniforms(bool p_update_refs); void _update_uniform_refs(Set<String> &p_names); + void _visibility_changed(); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 98cdab0b70..4516180fa5 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -381,9 +381,12 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { type->set_custom_minimum_size(Size2(100, 0) * EDSCALE); hbc->add_child(type); - // Start at 1 to avoid adding "Nil" as an option - for (int i = 1; i < Variant::VARIANT_MAX; i++) { - type->add_item(Variant::get_type_name(Variant::Type(i))); + for (int i = 0; i < Variant::VARIANT_MAX; i++) { + // There's no point in adding Nil types, and Object types + // can't be serialized correctly in the project settings. + if (i != Variant::NIL && i != Variant::OBJECT) { + type->add_item(Variant::get_type_name(Variant::Type(i))); + } } l = memnew(Label); |