material_editor_plugin.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/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 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. DirectionalLight3D *light1 = nullptr;
  58. DirectionalLight3D *light2 = nullptr;
  59. Camera3D *camera = nullptr;
  60. Ref<CameraAttributesPractical> camera_attributes;
  61. Ref<SphereMesh> sphere_mesh;
  62. Ref<BoxMesh> box_mesh;
  63. HBoxContainer *layout_3d = nullptr;
  64. Ref<Material> material;
  65. Button *sphere_switch = nullptr;
  66. Button *box_switch = nullptr;
  67. Button *light_1_switch = nullptr;
  68. Button *light_2_switch = nullptr;
  69. struct ThemeCache {
  70. Ref<Texture2D> light_1_icon;
  71. Ref<Texture2D> light_2_icon;
  72. Ref<Texture2D> sphere_icon;
  73. Ref<Texture2D> box_icon;
  74. Ref<Texture2D> checkerboard;
  75. } theme_cache;
  76. void _on_light_1_switch_pressed();
  77. void _on_light_2_switch_pressed();
  78. void _on_sphere_switch_pressed();
  79. void _on_box_switch_pressed();
  80. protected:
  81. virtual void _update_theme_item_cache() override;
  82. void _notification(int p_what);
  83. void gui_input(const Ref<InputEvent> &p_event) override;
  84. void _update_rotation();
  85. public:
  86. void edit(Ref<Material> p_material, const Ref<Environment> &p_env);
  87. MaterialEditor();
  88. };
  89. class EditorInspectorPluginMaterial : public EditorInspectorPlugin {
  90. GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin);
  91. Ref<Environment> env;
  92. public:
  93. virtual bool can_handle(Object *p_object) override;
  94. virtual void parse_begin(Object *p_object) override;
  95. void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, String p_property, Variant p_new_value);
  96. EditorInspectorPluginMaterial();
  97. };
  98. class MaterialEditorPlugin : public EditorPlugin {
  99. GDCLASS(MaterialEditorPlugin, EditorPlugin);
  100. public:
  101. virtual String get_name() const override { return "Material"; }
  102. MaterialEditorPlugin();
  103. };
  104. class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
  105. GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin);
  106. public:
  107. virtual String converts_to() const override;
  108. virtual bool handles(const Ref<Resource> &p_resource) const override;
  109. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  110. };
  111. class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin {
  112. GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin);
  113. public:
  114. virtual String converts_to() const override;
  115. virtual bool handles(const Ref<Resource> &p_resource) const override;
  116. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  117. };
  118. class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {
  119. GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);
  120. public:
  121. virtual String converts_to() const override;
  122. virtual bool handles(const Ref<Resource> &p_resource) const override;
  123. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  124. };
  125. class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {
  126. GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin);
  127. public:
  128. virtual String converts_to() const override;
  129. virtual bool handles(const Ref<Resource> &p_resource) const override;
  130. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  131. };
  132. class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
  133. GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
  134. public:
  135. virtual String converts_to() const override;
  136. virtual bool handles(const Ref<Resource> &p_resource) const override;
  137. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  138. };
  139. class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
  140. GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
  141. public:
  142. virtual String converts_to() const override;
  143. virtual bool handles(const Ref<Resource> &p_resource) const override;
  144. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  145. };
  146. class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {
  147. GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin);
  148. public:
  149. virtual String converts_to() const override;
  150. virtual bool handles(const Ref<Resource> &p_resource) const override;
  151. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  152. };
  153. class FogMaterialConversionPlugin : public EditorResourceConversionPlugin {
  154. GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin);
  155. public:
  156. virtual String converts_to() const override;
  157. virtual bool handles(const Ref<Resource> &p_resource) const override;
  158. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;
  159. };
  160. #endif // MATERIAL_EDITOR_PLUGIN_H