1 /*************************************************************************/
2 /*  material_editor_plugin.h                                             */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
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 #ifndef MATERIAL_EDITOR_PLUGIN_H
32 #define MATERIAL_EDITOR_PLUGIN_H
33 
34 #include "editor/property_editor.h"
35 #include "scene/resources/primitive_meshes.h"
36 
37 #include "editor/editor_node.h"
38 #include "editor/editor_plugin.h"
39 #include "scene/3d/camera.h"
40 #include "scene/3d/light.h"
41 #include "scene/3d/mesh_instance.h"
42 #include "scene/resources/material.h"
43 
44 class ViewportContainer;
45 
46 class MaterialEditor : public Control {
47 
48 	GDCLASS(MaterialEditor, Control);
49 
50 	ViewportContainer *vc;
51 	Viewport *viewport;
52 	MeshInstance *sphere_instance;
53 	MeshInstance *box_instance;
54 	DirectionalLight *light1;
55 	DirectionalLight *light2;
56 	Camera *camera;
57 
58 	Ref<SphereMesh> sphere_mesh;
59 	Ref<CubeMesh> box_mesh;
60 
61 	TextureButton *sphere_switch;
62 	TextureButton *box_switch;
63 
64 	TextureButton *light_1_switch;
65 	TextureButton *light_2_switch;
66 
67 	Ref<Material> material;
68 
69 	void _button_pressed(Node *p_button);
70 	bool first_enter;
71 
72 protected:
73 	void _notification(int p_what);
74 
75 	static void _bind_methods();
76 
77 public:
78 	void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
79 	MaterialEditor();
80 };
81 
82 class EditorInspectorPluginMaterial : public EditorInspectorPlugin {
83 	GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin);
84 	Ref<Environment> env;
85 
86 public:
87 	virtual bool can_handle(Object *p_object);
88 	virtual void parse_begin(Object *p_object);
89 
90 	EditorInspectorPluginMaterial();
91 };
92 
93 class MaterialEditorPlugin : public EditorPlugin {
94 
95 	GDCLASS(MaterialEditorPlugin, EditorPlugin);
96 
97 public:
get_name()98 	virtual String get_name() const { return "Material"; }
99 
100 	MaterialEditorPlugin(EditorNode *p_node);
101 };
102 
103 class SpatialMaterialConversionPlugin : public EditorResourceConversionPlugin {
104 	GDCLASS(SpatialMaterialConversionPlugin, EditorResourceConversionPlugin);
105 
106 public:
107 	virtual String converts_to() const;
108 	virtual bool handles(const Ref<Resource> &p_resource) const;
109 	virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const;
110 };
111 
112 class ParticlesMaterialConversionPlugin : public EditorResourceConversionPlugin {
113 	GDCLASS(ParticlesMaterialConversionPlugin, EditorResourceConversionPlugin);
114 
115 public:
116 	virtual String converts_to() const;
117 	virtual bool handles(const Ref<Resource> &p_resource) const;
118 	virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const;
119 };
120 
121 class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {
122 	GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin);
123 
124 public:
125 	virtual String converts_to() const;
126 	virtual bool handles(const Ref<Resource> &p_resource) const;
127 	virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const;
128 };
129 
130 #endif // MATERIAL_EDITOR_PLUGIN_H
131