material_editor_plugin.h 7.9 KB

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