material_editor_plugin.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**************************************************************************/
  2. /* material_editor_plugin.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. #ifndef MATERIAL_EDITOR_PLUGIN_H
  31. #define MATERIAL_EDITOR_PLUGIN_H
  32. #include "editor/editor_inspector.h"
  33. #include "editor/plugins/editor_plugin.h"
  34. #include "editor/plugins/editor_resource_conversion_plugin.h"
  35. #include "scene/resources/3d/primitive_meshes.h"
  36. #include "scene/resources/material.h"
  37. class Camera3D;
  38. class ColorRect;
  39. class DirectionalLight3D;
  40. class HBoxContainer;
  41. class MeshInstance3D;
  42. class SubViewport;
  43. class SubViewportContainer;
  44. class Button;
  45. class Label;
  46. class MaterialEditor : public Control {
  47. GDCLASS(MaterialEditor, Control);
  48. Vector2 rot;
  49. SubViewportContainer *vc_2d = nullptr;
  50. SubViewport *viewport_2d = nullptr;
  51. HBoxContainer *layout_2d = nullptr;
  52. ColorRect *rect_instance = nullptr;
  53. SubViewportContainer *vc = nullptr;
  54. SubViewport *viewport = nullptr;
  55. Node3D *rotation = nullptr;
  56. MeshInstance3D *sphere_instance = nullptr;
  57. MeshInstance3D *box_instance = nullptr;
  58. MeshInstance3D *quad_instance = nullptr;
  59. DirectionalLight3D *light1 = nullptr;
  60. DirectionalLight3D *light2 = nullptr;
  61. Camera3D *camera = nullptr;
  62. Ref<CameraAttributesPractical> camera_attributes;
  63. Ref<SphereMesh> sphere_mesh;
  64. Ref<BoxMesh> box_mesh;
  65. Ref<QuadMesh> quad_mesh;
  66. VBoxContainer *layout_error = nullptr;
  67. Label *error_label = nullptr;
  68. bool is_unsupported_shader_mode = false;
  69. HBoxContainer *layout_3d = nullptr;
  70. Ref<Material> material;
  71. Button *sphere_switch = nullptr;
  72. Button *box_switch = nullptr;
  73. Button *quad_switch = nullptr;
  74. Button *light_1_switch = nullptr;
  75. Button *light_2_switch = nullptr;
  76. struct ThemeCache {
  77. Ref<Texture2D> light_1_icon;
  78. Ref<Texture2D> light_2_icon;
  79. Ref<Texture2D> sphere_icon;
  80. Ref<Texture2D> box_icon;
  81. Ref<Texture2D> quad_icon;
  82. Ref<Texture2D> checkerboard;
  83. } theme_cache;
  84. void _on_light_1_switch_pressed();
  85. void _on_light_2_switch_pressed();
  86. void _on_sphere_switch_pressed();
  87. void _on_box_switch_pressed();
  88. void _on_quad_switch_pressed();
  89. protected:
  90. virtual void _update_theme_item_cache() override;
  91. void _notification(int p_what);
  92. void gui_input(const Ref<InputEvent> &p_event) override;
  93. void _set_rotation(real_t p_x_degrees, real_t p_y_degrees);
  94. void _store_rotation_metadata();
  95. void _update_rotation();
  96. public:
  97. void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
  98. MaterialEditor();
  99. };
  100. class EditorInspectorPluginMaterial : public EditorInspectorPlugin {
  101. GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin);
  102. Ref<Environment> env;
  103. public:
  104. virtual bool can_handle(Object *p_object) override;
  105. virtual void parse_begin(Object *p_object) override;
  106. void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value);
  107. EditorInspectorPluginMaterial();
  108. };
  109. class MaterialEditorPlugin : public EditorPlugin {
  110. GDCLASS(MaterialEditorPlugin, EditorPlugin);
  111. public:
  112. virtual String get_plugin_name() const override { return "Material"; }
  113. MaterialEditorPlugin();
  114. };
  115. class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
  116. GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin);
  117. public:
  118. virtual String converts_to() const override;
  119. virtual bool handles(const Ref<Resource> &p_resource) const override;
  120. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  121. };
  122. class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
  123. GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin);
  124. public:
  125. virtual String converts_to() const override;
  126. virtual bool handles(const Ref<Resource> &p_resource) const override;
  127. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  128. };
  129. class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {
  130. GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);
  131. public:
  132. virtual String converts_to() const override;
  133. virtual bool handles(const Ref<Resource> &p_resource) const override;
  134. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  135. };
  136. class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {
  137. GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin);
  138. public:
  139. virtual String converts_to() const override;
  140. virtual bool handles(const Ref<Resource> &p_resource) const override;
  141. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  142. };
  143. class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
  144. GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
  145. public:
  146. virtual String converts_to() const override;
  147. virtual bool handles(const Ref<Resource> &p_resource) const override;
  148. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  149. };
  150. class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
  151. GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
  152. public:
  153. virtual String converts_to() const override;
  154. virtual bool handles(const Ref<Resource> &p_resource) const override;
  155. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  156. };
  157. class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
  158. GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
  159. public:
  160. virtual String converts_to() const override;
  161. virtual bool handles(const Ref<Resource> &p_resource) const override;
  162. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  163. };
  164. class FogMaterialConversionPlugin : public EditorResourceConversionPlugin {
  165. GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin);
  166. public:
  167. virtual String converts_to() const override;
  168. virtual bool handles(const Ref<Resource> &p_resource) const override;
  169. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  170. };
  171. #endif // MATERIAL_EDITOR_PLUGIN_H