summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/code_editor.cpp4
-rw-r--r--editor/editor_node.cpp14
-rw-r--r--editor/plugins/mesh_instance_3d_editor_plugin.cpp78
-rw-r--r--editor/script_create_dialog.cpp2
-rw-r--r--editor/shader_create_dialog.cpp2
5 files changed, 65 insertions, 35 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 7e6a49d6c0..1842e8c1c4 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -1514,8 +1514,8 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
// Empty lines should not be counted.
bool is_empty = text_editor->get_line(line).strip_edges().is_empty();
is_all_empty = is_all_empty && is_empty;
- // `.left(1)` here because get_delimiter_start_key will return `##` instead of `#` when there is multiple comment delimiter in a line.
- if (!is_empty && (delimiter_idx == -1 || text_editor->get_delimiter_start_key(delimiter_idx).left(1) != delimiter)) {
+ // get_delimiter_start_key will return `##` instead of `#` when there is multiple comment delimiter in a line.
+ if (!is_empty && (delimiter_idx == -1 || !text_editor->get_delimiter_start_key(delimiter_idx).begins_with(delimiter))) {
is_commented = false;
break;
}
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 4f87838014..f73eb81473 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1279,11 +1279,9 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String
return;
}
}
- } else {
- if (FileAccess::exists(path + ".import")) {
- show_warning(TTR("This resource can't be saved because it was imported from another file. Make it unique first."));
- return;
- }
+ } else if (FileAccess::exists(path + ".import")) {
+ show_warning(TTR("This resource can't be saved because it was imported from another file. Make it unique first."));
+ return;
}
}
@@ -4063,11 +4061,9 @@ bool EditorNode::is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_
}
}
}
- } else {
+ } else if (FileAccess::exists(path + ".import")) {
// The resource is not a subresource, but if it has an .import file, it's imported so treat it as read only.
- if (FileAccess::exists(path + ".import")) {
- return true;
- }
+ return true;
}
return false;
diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
index eec375cbea..fc220c56a8 100644
--- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
@@ -301,7 +301,40 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
ur->commit_action();
} break;
case MENU_OPTION_CREATE_UV2: {
- Ref<PrimitiveMesh> primitive_mesh = Object::cast_to<PrimitiveMesh>(*node->get_mesh());
+ Ref<Mesh> mesh2 = node->get_mesh();
+ if (!mesh.is_valid()) {
+ err_dialog->set_text(TTR("No mesh to unwrap."));
+ err_dialog->popup_centered();
+ return;
+ }
+
+ // Test if we are allowed to unwrap this mesh resource.
+ String path = mesh2->get_path();
+ int srpos = path.find("::");
+ if (srpos != -1) {
+ String base = path.substr(0, srpos);
+ if (ResourceLoader::get_resource_type(base) == "PackedScene") {
+ if (!get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->get_scene_file_path() != base) {
+ err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it does not belong to the edited scene. Make it unique first."));
+ err_dialog->popup_centered();
+ return;
+ }
+ } else {
+ if (FileAccess::exists(path + ".import")) {
+ err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it belongs to another resource which was imported from another file type. Make it unique first."));
+ err_dialog->popup_centered();
+ return;
+ }
+ }
+ } else {
+ if (FileAccess::exists(path + ".import")) {
+ err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it was imported from another file type. Make it unique first."));
+ err_dialog->popup_centered();
+ return;
+ }
+ }
+
+ Ref<PrimitiveMesh> primitive_mesh = mesh2;
if (primitive_mesh.is_valid()) {
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
ur->create_action(TTR("Unwrap UV2"));
@@ -309,39 +342,40 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
ur->add_undo_method(*primitive_mesh, "set_add_uv2", primitive_mesh->get_add_uv2());
ur->commit_action();
} else {
- Ref<ArrayMesh> mesh2 = node->get_mesh();
- if (!mesh2.is_valid()) {
+ Ref<ArrayMesh> array_mesh = mesh2;
+ if (!array_mesh.is_valid()) {
err_dialog->set_text(TTR("Contained Mesh is not of type ArrayMesh."));
err_dialog->popup_centered();
return;
}
- String path = mesh2->get_path();
- int srpos = path.find("::");
- if (srpos != -1) {
- String base = path.substr(0, srpos);
- if (ResourceLoader::get_resource_type(base) == "PackedScene") {
- if (!get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->get_scene_file_path() != base) {
- err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it does not belong to the edited scene. Make it unique first."));
+ // Preemptively evaluate common fail cases for lightmap unwrapping.
+ {
+ if (array_mesh->get_blend_shape_count() > 0) {
+ err_dialog->set_text(TTR("Can't unwrap mesh with blend shapes."));
+ err_dialog->popup_centered();
+ return;
+ }
+
+ for (int i = 0; i < array_mesh->get_surface_count(); i++) {
+ Mesh::PrimitiveType primitive = array_mesh->surface_get_primitive_type(i);
+
+ if (primitive != Mesh::PRIMITIVE_TRIANGLES) {
+ err_dialog->set_text(TTR("Only triangles are supported for lightmap unwrap."));
err_dialog->popup_centered();
return;
}
- } else {
- if (FileAccess::exists(path + ".import")) {
- err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it belongs to another resource which was imported from another file type. Make it unique first."));
+
+ uint64_t format = array_mesh->surface_get_format(i);
+ if (format & Mesh::ArrayFormat::ARRAY_FORMAT_NORMAL) {
+ err_dialog->set_text(TTR("Normals are required for lightmap unwrap."));
err_dialog->popup_centered();
return;
}
}
- } else {
- if (FileAccess::exists(path + ".import")) {
- err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it was imported from another file type. Make it unique first."));
- err_dialog->popup_centered();
- return;
- }
}
- Ref<ArrayMesh> unwrapped_mesh = mesh2->duplicate(false);
+ Ref<ArrayMesh> unwrapped_mesh = array_mesh->duplicate(false);
Error err = unwrapped_mesh->lightmap_unwrap(node->get_global_transform());
if (err != OK) {
@@ -355,9 +389,9 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
ur->add_do_method(node, "set_mesh", unwrapped_mesh);
ur->add_do_reference(node);
- ur->add_do_reference(mesh2.ptr());
+ ur->add_do_reference(array_mesh.ptr());
- ur->add_undo_method(node, "set_mesh", mesh2);
+ ur->add_undo_method(node, "set_mesh", array_mesh);
ur->add_undo_reference(unwrapped_mesh.ptr());
ur->commit_action();
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 0472f48c62..25e17ccd2a 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -633,7 +633,7 @@ void ScriptCreateDialog::_update_dialog() {
validation_panel->set_message(MSG_ID_SCRIPT, TTR("File exists, it will be reused."), EditorValidationPanel::MSG_OK);
}
- if (!path_error.is_empty()) {
+ if (!is_built_in && !path_error.is_empty()) {
validation_panel->set_message(MSG_ID_PATH, path_error, EditorValidationPanel::MSG_ERROR);
}
diff --git a/editor/shader_create_dialog.cpp b/editor/shader_create_dialog.cpp
index 53ec1180a3..63e7077d3f 100644
--- a/editor/shader_create_dialog.cpp
+++ b/editor/shader_create_dialog.cpp
@@ -494,7 +494,7 @@ void ShaderCreateDialog::_update_dialog() {
if (!is_built_in && !is_path_valid) {
validation_panel->set_message(MSG_ID_SHADER, TTR("Invalid path."), EditorValidationPanel::MSG_ERROR);
}
- if (!path_error.is_empty()) {
+ if (!is_built_in && !path_error.is_empty()) {
validation_panel->set_message(MSG_ID_PATH, path_error, EditorValidationPanel::MSG_ERROR);
} else if (validation_panel->is_valid() && !is_new_shader_created) {
validation_panel->set_message(MSG_ID_SHADER, TTR("File exists, it will be reused."), EditorValidationPanel::MSG_OK);