Path: blob/master/editor/scene/3d/material_3d_conversion_plugins.cpp
11323 views
/**************************************************************************/1/* material_3d_conversion_plugins.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "material_3d_conversion_plugins.h"3132#include "editor/scene/material_editor_plugin.h"33#include "scene/resources/3d/fog_material.h"34#include "scene/resources/3d/sky_material.h"3536String StandardMaterial3DConversionPlugin::converts_to() const {37return "ShaderMaterial";38}3940bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {41Ref<StandardMaterial3D> mat = p_resource;42return mat.is_valid();43}4445Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {46Ref<StandardMaterial3D> mat = p_resource;47Ref<ShaderMaterial> smat = MaterialEditor::make_shader_material(mat, false);48if (smat.is_null()) {49return smat;50}5152List<PropertyInfo> params;53RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);5455for (const PropertyInfo &E : params) {56// Texture parameter has to be treated specially since StandardMaterial3D saved it57// as RID but ShaderMaterial needs Texture itself58Ref<Texture2D> texture = mat->get_texture_by_name(E.name);59if (texture.is_valid()) {60smat->set_shader_parameter(E.name, texture);61} else {62Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);63smat->set_shader_parameter(E.name, value);64}65}66return smat;67}6869String ORMMaterial3DConversionPlugin::converts_to() const {70return "ShaderMaterial";71}7273bool ORMMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {74Ref<ORMMaterial3D> mat = p_resource;75return mat.is_valid();76}7778Ref<Resource> ORMMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {79Ref<ORMMaterial3D> mat = p_resource;80Ref<ShaderMaterial> smat = MaterialEditor::make_shader_material(mat, false);81if (smat.is_null()) {82return smat;83}8485List<PropertyInfo> params;86RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), ¶ms);8788for (const PropertyInfo &E : params) {89// Texture parameter has to be treated specially since ORMMaterial3D saved it90// as RID but ShaderMaterial needs Texture itself91Ref<Texture2D> texture = mat->get_texture_by_name(E.name);92if (texture.is_valid()) {93smat->set_shader_parameter(E.name, texture);94} else {95Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);96smat->set_shader_parameter(E.name, value);97}98}99return smat;100}101102String ProceduralSkyMaterialConversionPlugin::converts_to() const {103return "ShaderMaterial";104}105106bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {107Ref<ProceduralSkyMaterial> mat = p_resource;108return mat.is_valid();109}110111Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {112return MaterialEditor::make_shader_material(p_resource);113}114115String PanoramaSkyMaterialConversionPlugin::converts_to() const {116return "ShaderMaterial";117}118119bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {120Ref<PanoramaSkyMaterial> mat = p_resource;121return mat.is_valid();122}123124Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {125return MaterialEditor::make_shader_material(p_resource);126}127128String PhysicalSkyMaterialConversionPlugin::converts_to() const {129return "ShaderMaterial";130}131132bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {133Ref<PhysicalSkyMaterial> mat = p_resource;134return mat.is_valid();135}136137Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {138return MaterialEditor::make_shader_material(p_resource);139}140141String FogMaterialConversionPlugin::converts_to() const {142return "ShaderMaterial";143}144145bool FogMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {146Ref<FogMaterial> mat = p_resource;147return mat.is_valid();148}149150Ref<Resource> FogMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {151return MaterialEditor::make_shader_material(p_resource);152}153154155