Path: blob/master/editor/scene/material_editor_plugin.h
21019 views
/**************************************************************************/1/* material_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/inspector/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"3738class Camera3D;39class ColorRect;40class DirectionalLight3D;41class HBoxContainer;42class MeshInstance3D;43class SubViewport;44class SubViewportContainer;45class Button;46class Label;4748class MaterialEditor : public Control {49GDCLASS(MaterialEditor, Control);5051// Both 2D and 3D materials.52Ref<Material> material;53SubViewportContainer *vc = nullptr;54SubViewport *viewport = nullptr;55VBoxContainer *layout_error = nullptr;56Label *error_label = nullptr;57bool is_unsupported_shader_mode = false;5859struct ThemeCache {60Ref<Texture2D> light_1_icon;61Ref<Texture2D> light_2_icon;62Ref<Texture2D> sphere_icon;63Ref<Texture2D> box_icon;64Ref<Texture2D> quad_icon;65Ref<Texture2D> checkerboard;66} theme_cache;6768// 2D canvas materials.69SubViewportContainer *vc_2d = nullptr;70SubViewport *viewport_2d = nullptr;71HBoxContainer *layout_2d = nullptr;72ColorRect *rect_instance = nullptr;7374// 3D spatial materials.75Vector2 rot;76Node3D *rotation = nullptr;77MeshInstance3D *sphere_instance = nullptr;78MeshInstance3D *box_instance = nullptr;79MeshInstance3D *quad_instance = nullptr;80DirectionalLight3D *light1 = nullptr;81DirectionalLight3D *light2 = nullptr;82Camera3D *camera = nullptr;83Ref<CameraAttributesPractical> camera_attributes;84Ref<SphereMesh> sphere_mesh;85Ref<BoxMesh> box_mesh;86Ref<QuadMesh> quad_mesh;87HBoxContainer *layout_3d = nullptr;8889Button *sphere_switch = nullptr;90Button *box_switch = nullptr;91Button *quad_switch = nullptr;92Button *light_1_switch = nullptr;93Button *light_2_switch = nullptr;9495void _on_light_1_switch_pressed();96void _on_light_2_switch_pressed();97void _on_sphere_switch_pressed();98void _on_box_switch_pressed();99void _on_quad_switch_pressed();100101void _set_rotation(real_t p_x_degrees, real_t p_y_degrees);102void _store_rotation_metadata();103void _update_rotation();104105protected:106virtual void _update_theme_item_cache() override;107void _notification(int p_what);108void gui_input(const Ref<InputEvent> &p_event) override;109110public:111static Ref<ShaderMaterial> make_shader_material(const Ref<Material> &p_from, bool p_copy_params = true);112void edit(Ref<Material> p_material, const Ref<Environment> &p_env);113MaterialEditor();114};115116class EditorInspectorPluginMaterial : public EditorInspectorPlugin {117GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin);118Ref<Environment> env;119120public:121virtual bool can_handle(Object *p_object) override;122virtual void parse_begin(Object *p_object) override;123124void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value);125126EditorInspectorPluginMaterial();127};128129class MaterialEditorPlugin : public EditorPlugin {130GDCLASS(MaterialEditorPlugin, EditorPlugin);131132public:133virtual String get_plugin_name() const override { return "Material"; }134135MaterialEditorPlugin();136};137138class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {139GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);140141public:142virtual String converts_to() const override;143virtual bool handles(const Ref<Resource> &p_resource) const override;144virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;145};146147class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {148GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin);149150public:151virtual String converts_to() const override;152virtual bool handles(const Ref<Resource> &p_resource) const override;153virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;154};155156class BlitMaterialConversionPlugin : public EditorResourceConversionPlugin {157GDCLASS(BlitMaterialConversionPlugin, EditorResourceConversionPlugin);158159public:160virtual String converts_to() const override;161virtual bool handles(const Ref<Resource> &p_resource) const override;162virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;163};164165166