summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/material_editor_plugin.cpp39
-rw-r--r--editor/plugins/material_editor_plugin.h2
-rw-r--r--editor/scene_tree_dock.cpp12
3 files changed, 53 insertions, 0 deletions
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index 576e91e544..490605e9ed 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/editor/plugins/material_editor_plugin.cpp
@@ -254,6 +254,43 @@ void EditorInspectorPluginMaterial::parse_begin(Object *p_object) {
add_custom_control(editor);
}
+void EditorInspectorPluginMaterial::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, String p_property, Variant p_new_value) {
+ UndoRedo *undo_redo = Object::cast_to<UndoRedo>(p_undo_redo);
+ if (!undo_redo) {
+ return;
+ }
+
+ // For BaseMaterial3D, if a roughness or metallic textures is being assigned to an empty slot,
+ // set the respective metallic or roughness factor to 1.0 as a convinence feature
+ BaseMaterial3D *base_material = Object::cast_to<StandardMaterial3D>(p_edited);
+ if (base_material) {
+ Texture2D *texture = Object::cast_to<Texture2D>(p_new_value);
+ if (texture) {
+ if (p_property == "roughness_texture") {
+ if (base_material->get_texture(StandardMaterial3D::TEXTURE_ROUGHNESS).is_null() && texture) {
+ undo_redo->add_do_property(p_edited, "roughness", 1.0);
+
+ bool valid = false;
+ Variant value = p_edited->get("roughness", &valid);
+ if (valid) {
+ undo_redo->add_undo_property(p_edited, "roughness", value);
+ }
+ }
+ } else if (p_property == "metallic_texture") {
+ if (base_material->get_texture(StandardMaterial3D::TEXTURE_METALLIC).is_null() && texture) {
+ undo_redo->add_do_property(p_edited, "metallic", 1.0);
+
+ bool valid = false;
+ Variant value = p_edited->get("metallic", &valid);
+ if (valid) {
+ undo_redo->add_undo_property(p_edited, "metallic", value);
+ }
+ }
+ }
+ }
+ }
+}
+
EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() {
env.instantiate();
Ref<Sky> sky = memnew(Sky());
@@ -261,6 +298,8 @@ EditorInspectorPluginMaterial::EditorInspectorPluginMaterial() {
env->set_background(Environment::BG_COLOR);
env->set_ambient_source(Environment::AMBIENT_SOURCE_SKY);
env->set_reflection_source(Environment::REFLECTION_SOURCE_SKY);
+
+ EditorNode::get_singleton()->get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &EditorInspectorPluginMaterial::_undo_redo_inspector_callback));
}
MaterialEditorPlugin::MaterialEditorPlugin(EditorNode *p_node) {
diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h
index 36c2df191d..53f4513396 100644
--- a/editor/plugins/material_editor_plugin.h
+++ b/editor/plugins/material_editor_plugin.h
@@ -92,6 +92,8 @@ public:
virtual bool can_handle(Object *p_object) override;
virtual void parse_begin(Object *p_object) override;
+ void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, String p_property, Variant p_new_value);
+
EditorInspectorPluginMaterial();
};
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 8d4e7b444b..2d21caeac0 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -942,6 +942,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
+ if (tocopy->get_owner() != scene) {
+ accept->set_text(TTR("Can't save a branch which is a child of an already instantiated scene.\nTo save this branch into its own scene, open the original scene, right click on this branch, and select \"Save Branch as Scene\"."));
+ accept->popup_centered();
+ break;
+ }
+
+ if (scene->get_scene_inherited_state().is_valid() && scene->get_scene_inherited_state()->find_node_by_path(scene->get_path_to(tocopy)) >= 0) {
+ accept->set_text(TTR("Can't save a branch which is part of an inherited scene.\nTo save this branch into its own scene, open the original scene, right click on this branch, and select \"Save Branch as Scene\"."));
+ accept->popup_centered();
+ break;
+ }
+
new_scene_from_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
List<String> extensions;