/**************************************************************************/ /* material_3d_conversion_plugins.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "material_3d_conversion_plugins.h" #include "editor/scene/material_editor_plugin.h" #include "scene/resources/3d/fog_material.h" #include "scene/resources/3d/sky_material.h" String StandardMaterial3DConversionPlugin::converts_to() const { return "ShaderMaterial"; } bool StandardMaterial3DConversionPlugin::handles(const Ref &p_resource) const { Ref mat = p_resource; return mat.is_valid(); } Ref StandardMaterial3DConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; Ref smat = MaterialEditor::make_shader_material(mat, false); if (smat.is_null()) { return smat; } List params; RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms); for (const PropertyInfo &E : params) { // Texture parameter has to be treated specially since StandardMaterial3D saved it // as RID but ShaderMaterial needs Texture itself Ref texture = mat->get_texture_by_name(E.name); if (texture.is_valid()) { smat->set_shader_parameter(E.name, texture); } else { Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); smat->set_shader_parameter(E.name, value); } } return smat; } String ORMMaterial3DConversionPlugin::converts_to() const { return "ShaderMaterial"; } bool ORMMaterial3DConversionPlugin::handles(const Ref &p_resource) const { Ref mat = p_resource; return mat.is_valid(); } Ref ORMMaterial3DConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; Ref smat = MaterialEditor::make_shader_material(mat, false); if (smat.is_null()) { return smat; } List params; RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms); for (const PropertyInfo &E : params) { // Texture parameter has to be treated specially since ORMMaterial3D saved it // as RID but ShaderMaterial needs Texture itself Ref texture = mat->get_texture_by_name(E.name); if (texture.is_valid()) { smat->set_shader_parameter(E.name, texture); } else { Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); smat->set_shader_parameter(E.name, value); } } return smat; } String ProceduralSkyMaterialConversionPlugin::converts_to() const { return "ShaderMaterial"; } bool ProceduralSkyMaterialConversionPlugin::handles(const Ref &p_resource) const { Ref mat = p_resource; return mat.is_valid(); } Ref ProceduralSkyMaterialConversionPlugin::convert(const Ref &p_resource) const { return MaterialEditor::make_shader_material(p_resource); } String PanoramaSkyMaterialConversionPlugin::converts_to() const { return "ShaderMaterial"; } bool PanoramaSkyMaterialConversionPlugin::handles(const Ref &p_resource) const { Ref mat = p_resource; return mat.is_valid(); } Ref PanoramaSkyMaterialConversionPlugin::convert(const Ref &p_resource) const { return MaterialEditor::make_shader_material(p_resource); } String PhysicalSkyMaterialConversionPlugin::converts_to() const { return "ShaderMaterial"; } bool PhysicalSkyMaterialConversionPlugin::handles(const Ref &p_resource) const { Ref mat = p_resource; return mat.is_valid(); } Ref PhysicalSkyMaterialConversionPlugin::convert(const Ref &p_resource) const { return MaterialEditor::make_shader_material(p_resource); } String FogMaterialConversionPlugin::converts_to() const { return "ShaderMaterial"; } bool FogMaterialConversionPlugin::handles(const Ref &p_resource) const { Ref mat = p_resource; return mat.is_valid(); } Ref FogMaterialConversionPlugin::convert(const Ref &p_resource) const { return MaterialEditor::make_shader_material(p_resource); }