Skip to content

Commit 06f0c3f

Browse files
committed
Move Material3D conversion editor plugins to their own folder
1 parent d705613 commit 06f0c3f

File tree

5 files changed

+278
-208
lines changed

5 files changed

+278
-208
lines changed

editor/editor_node.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
#include "editor/run/editor_run.h"
144144
#include "editor/run/editor_run_bar.h"
145145
#include "editor/run/game_view_plugin.h"
146+
#include "editor/scene/3d/material_3d_conversion_plugins.h"
146147
#include "editor/scene/3d/mesh_library_editor_plugin.h"
147148
#include "editor/scene/3d/node_3d_editor_plugin.h"
148149
#include "editor/scene/3d/root_motion_editor_plugin.h"
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**************************************************************************/
2+
/* material_3d_conversion_plugins.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "material_3d_conversion_plugins.h"
32+
33+
#include "editor/scene/material_editor_plugin.h"
34+
#include "scene/resources/3d/fog_material.h"
35+
#include "scene/resources/3d/sky_material.h"
36+
37+
String StandardMaterial3DConversionPlugin::converts_to() const {
38+
return "ShaderMaterial";
39+
}
40+
41+
bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
42+
Ref<StandardMaterial3D> mat = p_resource;
43+
return mat.is_valid();
44+
}
45+
46+
Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
47+
Ref<StandardMaterial3D> mat = p_resource;
48+
Ref<ShaderMaterial> smat = MaterialEditor::make_shader_material(mat, false);
49+
if (smat.is_null()) {
50+
return smat;
51+
}
52+
53+
List<PropertyInfo> params;
54+
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), &params);
55+
56+
for (const PropertyInfo &E : params) {
57+
// Texture parameter has to be treated specially since StandardMaterial3D saved it
58+
// as RID but ShaderMaterial needs Texture itself
59+
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
60+
if (texture.is_valid()) {
61+
smat->set_shader_parameter(E.name, texture);
62+
} else {
63+
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
64+
smat->set_shader_parameter(E.name, value);
65+
}
66+
}
67+
return smat;
68+
}
69+
70+
String ORMMaterial3DConversionPlugin::converts_to() const {
71+
return "ShaderMaterial";
72+
}
73+
74+
bool ORMMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) const {
75+
Ref<ORMMaterial3D> mat = p_resource;
76+
return mat.is_valid();
77+
}
78+
79+
Ref<Resource> ORMMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
80+
Ref<ORMMaterial3D> mat = p_resource;
81+
Ref<ShaderMaterial> smat = MaterialEditor::make_shader_material(mat, false);
82+
if (smat.is_null()) {
83+
return smat;
84+
}
85+
86+
List<PropertyInfo> params;
87+
RS::get_singleton()->get_shader_parameter_list(mat->get_shader_rid(), &params);
88+
89+
for (const PropertyInfo &E : params) {
90+
// Texture parameter has to be treated specially since ORMMaterial3D saved it
91+
// as RID but ShaderMaterial needs Texture itself
92+
Ref<Texture2D> texture = mat->get_texture_by_name(E.name);
93+
if (texture.is_valid()) {
94+
smat->set_shader_parameter(E.name, texture);
95+
} else {
96+
Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name);
97+
smat->set_shader_parameter(E.name, value);
98+
}
99+
}
100+
return smat;
101+
}
102+
103+
String ProceduralSkyMaterialConversionPlugin::converts_to() const {
104+
return "ShaderMaterial";
105+
}
106+
107+
bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
108+
Ref<ProceduralSkyMaterial> mat = p_resource;
109+
return mat.is_valid();
110+
}
111+
112+
Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
113+
return MaterialEditor::make_shader_material(p_resource);
114+
}
115+
116+
String PanoramaSkyMaterialConversionPlugin::converts_to() const {
117+
return "ShaderMaterial";
118+
}
119+
120+
bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
121+
Ref<PanoramaSkyMaterial> mat = p_resource;
122+
return mat.is_valid();
123+
}
124+
125+
Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
126+
return MaterialEditor::make_shader_material(p_resource);
127+
}
128+
129+
String PhysicalSkyMaterialConversionPlugin::converts_to() const {
130+
return "ShaderMaterial";
131+
}
132+
133+
bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
134+
Ref<PhysicalSkyMaterial> mat = p_resource;
135+
return mat.is_valid();
136+
}
137+
138+
Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
139+
return MaterialEditor::make_shader_material(p_resource);
140+
}
141+
142+
String FogMaterialConversionPlugin::converts_to() const {
143+
return "ShaderMaterial";
144+
}
145+
146+
bool FogMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
147+
Ref<FogMaterial> mat = p_resource;
148+
return mat.is_valid();
149+
}
150+
151+
Ref<Resource> FogMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
152+
return MaterialEditor::make_shader_material(p_resource);
153+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**************************************************************************/
2+
/* material_3d_conversion_plugins.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
#include "editor/plugins/editor_resource_conversion_plugin.h"
34+
35+
class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
36+
GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin);
37+
38+
public:
39+
virtual String converts_to() const override;
40+
virtual bool handles(const Ref<Resource> &p_resource) const override;
41+
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
42+
};
43+
44+
class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
45+
GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin);
46+
47+
public:
48+
virtual String converts_to() const override;
49+
virtual bool handles(const Ref<Resource> &p_resource) const override;
50+
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
51+
};
52+
53+
class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
54+
GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
55+
56+
public:
57+
virtual String converts_to() const override;
58+
virtual bool handles(const Ref<Resource> &p_resource) const override;
59+
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
60+
};
61+
62+
class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
63+
GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
64+
65+
public:
66+
virtual String converts_to() const override;
67+
virtual bool handles(const Ref<Resource> &p_resource) const override;
68+
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
69+
};
70+
71+
class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
72+
GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
73+
74+
public:
75+
virtual String converts_to() const override;
76+
virtual bool handles(const Ref<Resource> &p_resource) const override;
77+
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
78+
};
79+
80+
class FogMaterialConversionPlugin : public EditorResourceConversionPlugin {
81+
GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin);
82+
83+
public:
84+
virtual String converts_to() const override;
85+
virtual bool handles(const Ref<Resource> &p_resource) const override;
86+
virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
87+
};

0 commit comments

Comments
 (0)