diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-09-13 18:12:58 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-13 18:12:58 -0300 |
commit | 909c06ee0f0ab5feced1c9c99a725f7a423ff9f8 (patch) | |
tree | cc86065674317ca4042639b28d01260152cfd97b /scene | |
parent | 06c8b5a4ffb0ab6787edf071463f17df522b3e79 (diff) | |
parent | 3cedec5f754b08d04095d5ebe0cd9532de011268 (diff) |
Merge pull request #21806 from JFonS/inspector_uniform_defaults
Set uniform default values in inspector
Diffstat (limited to 'scene')
-rw-r--r-- | scene/resources/material.cpp | 27 | ||||
-rw-r--r-- | scene/resources/material.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 4727526b68..2cf802a2da 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -145,6 +145,31 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const { } } +bool ShaderMaterial::property_can_revert(const String &p_name) { + if (shader.is_valid()) { + + StringName pr = shader->remap_param(p_name); + if (pr) { + Variant default_value = VisualServer::get_singleton()->material_get_param_default(_get_material(), pr); + Variant current_value; + _get(p_name, current_value); + return default_value.get_type() != Variant::NIL && default_value != current_value; + } + } + return false; +} + +Variant ShaderMaterial::property_get_revert(const String &p_name) { + Variant r_ret; + if (shader.is_valid()) { + StringName pr = shader->remap_param(p_name); + if (pr) { + r_ret = VisualServer::get_singleton()->material_get_param_default(_get_material(), pr); + } + } + return r_ret; +} + void ShaderMaterial::set_shader(const Ref<Shader> &p_shader) { if (shader.is_valid()) { @@ -190,6 +215,8 @@ void ShaderMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shader_param", "param", "value"), &ShaderMaterial::set_shader_param); ClassDB::bind_method(D_METHOD("get_shader_param", "param"), &ShaderMaterial::get_shader_param); ClassDB::bind_method(D_METHOD("_shader_changed"), &ShaderMaterial::_shader_changed); + ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ShaderMaterial::property_can_revert); + ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ShaderMaterial::property_get_revert); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shader", PROPERTY_HINT_RESOURCE_TYPE, "Shader"), "set_shader", "get_shader"); } diff --git a/scene/resources/material.h b/scene/resources/material.h index 078649e7b0..4a2a813341 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -85,6 +85,8 @@ protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; + bool property_can_revert(const String &p_name); + Variant property_get_revert(const String &p_name); static void _bind_methods(); |