diff options
-rw-r--r-- | core/core_constants.cpp | 18 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 60 | ||||
-rw-r--r-- | doc/classes/@GlobalScope.xml | 18 | ||||
-rw-r--r-- | doc/classes/BaseMaterial3D.xml | 3 | ||||
-rw-r--r-- | doc/classes/Node3D.xml | 14 | ||||
-rw-r--r-- | editor/plugins/material_editor_plugin.cpp | 39 | ||||
-rw-r--r-- | editor/plugins/material_editor_plugin.h | 2 | ||||
-rw-r--r-- | editor/scene_tree_dock.cpp | 12 | ||||
-rw-r--r-- | scene/3d/node_3d.cpp | 64 | ||||
-rw-r--r-- | scene/3d/node_3d.h | 3 | ||||
-rw-r--r-- | scene/resources/material.cpp | 12 |
11 files changed, 181 insertions, 64 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp index cd56233c58..6f26288eb7 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -669,15 +669,15 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_SIGNAL", Variant::SIGNAL); BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_DICTIONARY", Variant::DICTIONARY); BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_ARRAY", Variant::ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_RAW_ARRAY", Variant::PACKED_BYTE_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_INT32_ARRAY", Variant::PACKED_INT32_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_INT64_ARRAY", Variant::PACKED_INT64_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT32_ARRAY", Variant::PACKED_FLOAT32_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT64_ARRAY", Variant::PACKED_FLOAT64_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_STRING_ARRAY", Variant::PACKED_STRING_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2_ARRAY", Variant::PACKED_VECTOR2_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3_ARRAY", Variant::PACKED_VECTOR3_ARRAY); - BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::PACKED_COLOR_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_BYTE_ARRAY", Variant::PACKED_BYTE_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_INT32_ARRAY", Variant::PACKED_INT32_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_INT64_ARRAY", Variant::PACKED_INT64_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_FLOAT32_ARRAY", Variant::PACKED_FLOAT32_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_FLOAT64_ARRAY", Variant::PACKED_FLOAT64_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_STRING_ARRAY", Variant::PACKED_STRING_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_VECTOR2_ARRAY", Variant::PACKED_VECTOR2_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_VECTOR3_ARRAY", Variant::PACKED_VECTOR3_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_COLOR_ARRAY", Variant::PACKED_COLOR_ARRAY); BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX); //comparison diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 65eb27ef4e..9753ac2c4e 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -54,7 +54,7 @@ enum { VARIANT_QUATERNION = 14, VARIANT_AABB = 15, VARIANT_MATRIX3 = 16, - VARIANT_TRANSFORM = 17, + VARIANT_TRANSFORM3D = 17, VARIANT_MATRIX32 = 18, VARIANT_COLOR = 20, VARIANT_NODE_PATH = 22, @@ -63,13 +63,13 @@ enum { VARIANT_INPUT_EVENT = 25, VARIANT_DICTIONARY = 26, VARIANT_ARRAY = 30, - VARIANT_RAW_ARRAY = 31, - VARIANT_INT32_ARRAY = 32, - VARIANT_FLOAT32_ARRAY = 33, - VARIANT_STRING_ARRAY = 34, - VARIANT_VECTOR3_ARRAY = 35, - VARIANT_COLOR_ARRAY = 36, - VARIANT_VECTOR2_ARRAY = 37, + VARIANT_PACKED_BYTE_ARRAY = 31, + VARIANT_PACKED_INT32_ARRAY = 32, + VARIANT_PACKED_FLOAT32_ARRAY = 33, + VARIANT_PACKED_STRING_ARRAY = 34, + VARIANT_PACKED_VECTOR3_ARRAY = 35, + VARIANT_PACKED_COLOR_ARRAY = 36, + VARIANT_PACKED_VECTOR2_ARRAY = 37, VARIANT_INT64 = 40, VARIANT_DOUBLE = 41, VARIANT_CALLABLE = 42, @@ -78,8 +78,8 @@ enum { VARIANT_VECTOR2I = 45, VARIANT_RECT2I = 46, VARIANT_VECTOR3I = 47, - VARIANT_INT64_ARRAY = 48, - VARIANT_FLOAT64_ARRAY = 49, + VARIANT_PACKED_INT64_ARRAY = 48, + VARIANT_PACKED_FLOAT64_ARRAY = 49, OBJECT_EMPTY = 0, OBJECT_EXTERNAL_RESOURCE = 1, OBJECT_INTERNAL_RESOURCE = 2, @@ -245,7 +245,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; - case VARIANT_TRANSFORM: { + case VARIANT_TRANSFORM3D: { Transform3D v; v.basis.elements[0].x = f->get_real(); v.basis.elements[0].y = f->get_real(); @@ -422,7 +422,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = a; } break; - case VARIANT_RAW_ARRAY: { + case VARIANT_PACKED_BYTE_ARRAY: { uint32_t len = f->get_32(); Vector<uint8_t> array; @@ -434,7 +434,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_INT32_ARRAY: { + case VARIANT_PACKED_INT32_ARRAY: { uint32_t len = f->get_32(); Vector<int32_t> array; @@ -453,7 +453,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_INT64_ARRAY: { + case VARIANT_PACKED_INT64_ARRAY: { uint32_t len = f->get_32(); Vector<int64_t> array; @@ -472,7 +472,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_FLOAT32_ARRAY: { + case VARIANT_PACKED_FLOAT32_ARRAY: { uint32_t len = f->get_32(); Vector<float> array; @@ -491,7 +491,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_FLOAT64_ARRAY: { + case VARIANT_PACKED_FLOAT64_ARRAY: { uint32_t len = f->get_32(); Vector<double> array; @@ -510,7 +510,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_STRING_ARRAY: { + case VARIANT_PACKED_STRING_ARRAY: { uint32_t len = f->get_32(); Vector<String> array; array.resize(len); @@ -522,7 +522,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_VECTOR2_ARRAY: { + case VARIANT_PACKED_VECTOR2_ARRAY: { uint32_t len = f->get_32(); Vector<Vector2> array; @@ -547,7 +547,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_VECTOR3_ARRAY: { + case VARIANT_PACKED_VECTOR3_ARRAY: { uint32_t len = f->get_32(); Vector<Vector3> array; @@ -572,7 +572,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_COLOR_ARRAY: { + case VARIANT_PACKED_COLOR_ARRAY: { uint32_t len = f->get_32(); Vector<Color> array; @@ -1501,7 +1501,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::TRANSFORM3D: { - f->store_32(VARIANT_TRANSFORM); + f->store_32(VARIANT_TRANSFORM3D); Transform3D val = p_property; f->store_real(val.basis.elements[0].x); f->store_real(val.basis.elements[0].y); @@ -1625,7 +1625,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_BYTE_ARRAY: { - f->store_32(VARIANT_RAW_ARRAY); + f->store_32(VARIANT_PACKED_BYTE_ARRAY); Vector<uint8_t> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1635,7 +1635,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_INT32_ARRAY: { - f->store_32(VARIANT_INT32_ARRAY); + f->store_32(VARIANT_PACKED_INT32_ARRAY); Vector<int32_t> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1646,7 +1646,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_INT64_ARRAY: { - f->store_32(VARIANT_INT64_ARRAY); + f->store_32(VARIANT_PACKED_INT64_ARRAY); Vector<int64_t> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1657,7 +1657,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_FLOAT32_ARRAY: { - f->store_32(VARIANT_FLOAT32_ARRAY); + f->store_32(VARIANT_PACKED_FLOAT32_ARRAY); Vector<float> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1668,7 +1668,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_FLOAT64_ARRAY: { - f->store_32(VARIANT_FLOAT64_ARRAY); + f->store_32(VARIANT_PACKED_FLOAT64_ARRAY); Vector<double> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1679,7 +1679,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_STRING_ARRAY: { - f->store_32(VARIANT_STRING_ARRAY); + f->store_32(VARIANT_PACKED_STRING_ARRAY); Vector<String> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1690,7 +1690,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_VECTOR3_ARRAY: { - f->store_32(VARIANT_VECTOR3_ARRAY); + f->store_32(VARIANT_PACKED_VECTOR3_ARRAY); Vector<Vector3> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1703,7 +1703,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_VECTOR2_ARRAY: { - f->store_32(VARIANT_VECTOR2_ARRAY); + f->store_32(VARIANT_PACKED_VECTOR2_ARRAY); Vector<Vector2> arr = p_property; int len = arr.size(); f->store_32(len); @@ -1715,7 +1715,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PACKED_COLOR_ARRAY: { - f->store_32(VARIANT_COLOR_ARRAY); + f->store_32(VARIANT_PACKED_COLOR_ARRAY); Vector<Color> arr = p_property; int len = arr.size(); f->store_32(len); diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 7f794fef6e..20a371c3d0 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -2699,31 +2699,31 @@ <constant name="TYPE_ARRAY" value="25" enum="Variant.Type"> Variable is of type [Array]. </constant> - <constant name="TYPE_RAW_ARRAY" value="26" enum="Variant.Type"> + <constant name="TYPE_PACKED_BYTE_ARRAY" value="26" enum="Variant.Type"> Variable is of type [PackedByteArray]. </constant> - <constant name="TYPE_INT32_ARRAY" value="27" enum="Variant.Type"> + <constant name="TYPE_PACKED_INT32_ARRAY" value="27" enum="Variant.Type"> Variable is of type [PackedInt32Array]. </constant> - <constant name="TYPE_INT64_ARRAY" value="28" enum="Variant.Type"> + <constant name="TYPE_PACKED_INT64_ARRAY" value="28" enum="Variant.Type"> Variable is of type [PackedInt64Array]. </constant> - <constant name="TYPE_FLOAT32_ARRAY" value="29" enum="Variant.Type"> + <constant name="TYPE_PACKED_FLOAT32_ARRAY" value="29" enum="Variant.Type"> Variable is of type [PackedFloat32Array]. </constant> - <constant name="TYPE_FLOAT64_ARRAY" value="30" enum="Variant.Type"> + <constant name="TYPE_PACKED_FLOAT64_ARRAY" value="30" enum="Variant.Type"> Variable is of type [PackedFloat64Array]. </constant> - <constant name="TYPE_STRING_ARRAY" value="31" enum="Variant.Type"> + <constant name="TYPE_PACKED_STRING_ARRAY" value="31" enum="Variant.Type"> Variable is of type [PackedStringArray]. </constant> - <constant name="TYPE_VECTOR2_ARRAY" value="32" enum="Variant.Type"> + <constant name="TYPE_PACKED_VECTOR2_ARRAY" value="32" enum="Variant.Type"> Variable is of type [PackedVector2Array]. </constant> - <constant name="TYPE_VECTOR3_ARRAY" value="33" enum="Variant.Type"> + <constant name="TYPE_PACKED_VECTOR3_ARRAY" value="33" enum="Variant.Type"> Variable is of type [PackedVector3Array]. </constant> - <constant name="TYPE_COLOR_ARRAY" value="34" enum="Variant.Type"> + <constant name="TYPE_PACKED_COLOR_ARRAY" value="34" enum="Variant.Type"> Variable is of type [PackedColorArray]. </constant> <constant name="TYPE_MAX" value="35" enum="Variant.Type"> diff --git a/doc/classes/BaseMaterial3D.xml b/doc/classes/BaseMaterial3D.xml index 768006ebe4..7a2120379f 100644 --- a/doc/classes/BaseMaterial3D.xml +++ b/doc/classes/BaseMaterial3D.xml @@ -53,7 +53,6 @@ <argument index="1" name="texture" type="Texture2D" /> <description> Sets the texture for the slot specified by [code]param[/code]. See [enum TextureParam] for available slots. - [b]Note:[/b] When setting a roughness or metallic texture on a material that has no texture assigned to those slots, [member roughness] or [member metallic] will automatically be set to [code]1.0[/code] to ensure correct appearance. </description> </method> </methods> @@ -233,7 +232,6 @@ </member> <member name="metallic" type="float" setter="set_metallic" getter="get_metallic" default="0.0"> A high value makes the material appear more like a metal. Non-metals use their albedo as the diffuse color and add diffuse to the specular reflection. With non-metals, the reflection appears on top of the albedo color. Metals use their albedo as a multiplier to the specular reflection and set the diffuse color to black resulting in a tinted reflection. Materials work better when fully metal or fully non-metal, values between [code]0[/code] and [code]1[/code] should only be used for blending between metal and non-metal sections. To alter the amount of reflection use [member roughness]. - [b]Note:[/b] [member metallic] is automatically set to [code]1.0[/code] when assigning a metallic texture using [method set_texture]. </member> <member name="metallic_specular" type="float" setter="set_specular" getter="get_specular" default="0.5"> Sets the size of the specular lobe. The specular lobe is the bright spot that is reflected from light sources. @@ -306,7 +304,6 @@ </member> <member name="roughness" type="float" setter="set_roughness" getter="get_roughness" default="1.0"> Surface reflection. A value of [code]0[/code] represents a perfect mirror while a value of [code]1[/code] completely blurs the reflection. See also [member metallic]. - [b]Note:[/b] [member roughness] is automatically set to [code]1.0[/code] when assigning a roughness texture using [method set_texture]. </member> <member name="roughness_texture" type="Texture2D" setter="set_texture" getter="get_texture"> Texture used to control the roughness per-pixel. Multiplied by [member roughness]. diff --git a/doc/classes/Node3D.xml b/doc/classes/Node3D.xml index 1036c1fbcf..6b5a627575 100644 --- a/doc/classes/Node3D.xml +++ b/doc/classes/Node3D.xml @@ -134,6 +134,20 @@ Resets this node's transformations (like scale, skew and taper) preserving its rotation and translation by performing Gram-Schmidt orthonormalization on this node's [Transform3D]. </description> </method> + <method name="property_can_revert"> + <return type="bool" /> + <argument index="0" name="name" type="String" /> + <description> + Returns [code]true[/code] if the property identified by [code]name[/code] can be reverted to a default value. + </description> + </method> + <method name="property_get_revert"> + <return type="Variant" /> + <argument index="0" name="name" type="String" /> + <description> + Returns the default value of the Node3D property with given [code]name[/code]. + </description> + </method> <method name="rotate"> <return type="void" /> <argument index="0" name="axis" type="Vector3" /> 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; diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index 4426a646f4..a992d2aaf2 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -33,6 +33,7 @@ #include "core/object/message_queue.h" #include "scene/3d/visual_instance_3d.h" #include "scene/main/viewport.h" +#include "scene/property_utils.h" #include "scene/scene_string_names.h" /* @@ -837,6 +838,64 @@ void Node3D::_validate_property(PropertyInfo &property) const { } } +bool Node3D::property_can_revert(const String &p_name) { + if (p_name == "basis") { + return true; + } else if (p_name == "scale") { + return true; + } else if (p_name == "quaternion") { + return true; + } else if (p_name == "rotation") { + return true; + } else if (p_name == "position") { + return true; + } + return false; +} + +Variant Node3D::property_get_revert(const String &p_name) { + Variant r_ret; + bool valid = false; + + if (p_name == "basis") { + Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); + if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { + r_ret = Transform3D(variant).get_basis(); + } else { + r_ret = Basis(); + } + } else if (p_name == "scale") { + Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); + if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { + r_ret = Transform3D(variant).get_basis().get_scale(); + } else { + return Vector3(1.0, 1.0, 1.0); + } + } else if (p_name == "quaternion") { + Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); + if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { + r_ret = Quaternion(Transform3D(variant).get_basis()); + } else { + return Quaternion(); + } + } else if (p_name == "rotation") { + Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); + if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) { + r_ret = Transform3D(variant).get_basis().get_euler_normalized(data.rotation_order); + } else { + return Vector3(); + } + } else if (p_name == "position") { + Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid); + if (valid) { + r_ret = Transform3D(variant).get_origin(); + } else { + return Vector3(); + } + } + return r_ret; +} + void Node3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transform", "local"), &Node3D::set_transform); ClassDB::bind_method(D_METHOD("get_transform"), &Node3D::get_transform); @@ -908,6 +967,9 @@ void Node3D::_bind_methods() { ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Node3D::to_local); ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Node3D::to_global); + ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &Node3D::property_can_revert); + ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &Node3D::property_get_revert); + BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED); BIND_CONSTANT(NOTIFICATION_ENTER_WORLD); BIND_CONSTANT(NOTIFICATION_EXIT_WORLD); @@ -926,6 +988,7 @@ void Node3D::_bind_methods() { //ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM3D,"transform/global",PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR ), "set_global_transform", "get_global_transform") ; ADD_GROUP("Transform", ""); + ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_transform", "get_transform"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "global_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_transform", "get_global_transform"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position", PROPERTY_HINT_RANGE, "-99999,99999,0,or_greater,or_lesser,noslider,suffix:m", PROPERTY_USAGE_EDITOR), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians", PROPERTY_USAGE_EDITOR), "set_rotation", "get_rotation"); @@ -935,7 +998,6 @@ void Node3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_edit_mode", PROPERTY_HINT_ENUM, "Euler,Quaternion,Basis"), "set_rotation_edit_mode", "get_rotation_edit_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_order", PROPERTY_HINT_ENUM, "XYZ,XZY,YXZ,YZX,ZXY,ZYX"), "set_rotation_order", "get_rotation_order"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level"); - ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_transform", "get_transform"); ADD_GROUP("Visibility", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "visibility_parent", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GeometryInstance3D"), "set_visibility_parent", "get_visibility_parent"); diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h index ec62291d41..4abda66187 100644 --- a/scene/3d/node_3d.h +++ b/scene/3d/node_3d.h @@ -137,6 +137,9 @@ protected: virtual void _validate_property(PropertyInfo &property) const override; + bool property_can_revert(const String &p_name); + Variant property_get_revert(const String &p_name); + public: enum { NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index b36204241a..f3e5ece1f9 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -1659,18 +1659,6 @@ bool BaseMaterial3D::get_feature(Feature p_feature) const { void BaseMaterial3D::set_texture(TextureParam p_param, const Ref<Texture2D> &p_texture) { ERR_FAIL_INDEX(p_param, TEXTURE_MAX); - if (get_texture(TEXTURE_ROUGHNESS).is_null() && p_texture.is_valid() && p_param == TEXTURE_ROUGHNESS) { - // If no roughness texture is currently set, automatically set the recommended value - // for roughness when using a roughness map. - set_roughness(1.0); - } - - if (get_texture(TEXTURE_METALLIC).is_null() && p_texture.is_valid() && p_param == TEXTURE_METALLIC) { - // If no metallic texture is currently set, automatically set the recommended value - // for metallic when using a metallic map. - set_metallic(1.0); - } - textures[p_param] = p_texture; RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); RS::get_singleton()->material_set_param(_get_material(), shader_names->texture_names[p_param], rid); |