1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Added convertor from ORMMaterial3D to ShaderMaterial

This commit is contained in:
Yuri Roubinsky
2021-10-29 17:49:12 +03:00
parent dae626ad64
commit 7528c204d3
3 changed files with 59 additions and 0 deletions

View File

@@ -284,6 +284,52 @@ Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p
return smat;
}
String ORMMaterial3DConversionPlugin::converts_to() const {
return "ShaderMaterial";
}
bool ORMMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
Ref<ORMMaterial3D> mat = p_resource;
return mat.is_valid();
}
Ref<Resource> ORMMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
Ref<ORMMaterial3D> mat = p_resource;
ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
Ref<ShaderMaterial> smat;
smat.instantiate();
Ref<Shader> shader;
shader.instantiate();
String code = RS::get_singleton()->shader_get_code(mat->get_shader_rid());
shader->set_code(code);
smat->set_shader(shader);
List<PropertyInfo> params;
RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), &params);
for (const PropertyInfo &E : params) {
// Texture parameter has to be treated specially since ORMMaterial3D saved it
// as RID but ShaderMaterial needs Texture itself
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
if (texture.is_valid()) {
smat->set_shader_param(E.name, texture);
} else {
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
smat->set_shader_param(E.name, value);
}
}
smat->set_render_priority(mat->get_render_priority());
smat->set_local_to_scene(mat->is_local_to_scene());
smat->set_name(mat->get_name());
return smat;
}
String ParticlesMaterialConversionPlugin::converts_to() const {
return "ShaderMaterial";
}