Path: blob/master/editor/scene/material_editor_plugin.h
9896 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);5051Vector2 rot;5253SubViewportContainer *vc_2d = nullptr;54SubViewport *viewport_2d = nullptr;55HBoxContainer *layout_2d = nullptr;56ColorRect *rect_instance = nullptr;5758SubViewportContainer *vc = nullptr;59SubViewport *viewport = nullptr;60Node3D *rotation = nullptr;61MeshInstance3D *sphere_instance = nullptr;62MeshInstance3D *box_instance = nullptr;63MeshInstance3D *quad_instance = nullptr;64DirectionalLight3D *light1 = nullptr;65DirectionalLight3D *light2 = nullptr;66Camera3D *camera = nullptr;67Ref<CameraAttributesPractical> camera_attributes;6869Ref<SphereMesh> sphere_mesh;70Ref<BoxMesh> box_mesh;71Ref<QuadMesh> quad_mesh;7273VBoxContainer *layout_error = nullptr;74Label *error_label = nullptr;75bool is_unsupported_shader_mode = false;7677HBoxContainer *layout_3d = nullptr;7879Ref<Material> material;8081Button *sphere_switch = nullptr;82Button *box_switch = nullptr;83Button *quad_switch = nullptr;84Button *light_1_switch = nullptr;85Button *light_2_switch = nullptr;8687struct ThemeCache {88Ref<Texture2D> light_1_icon;89Ref<Texture2D> light_2_icon;90Ref<Texture2D> sphere_icon;91Ref<Texture2D> box_icon;92Ref<Texture2D> quad_icon;93Ref<Texture2D> checkerboard;94} theme_cache;9596void _on_light_1_switch_pressed();97void _on_light_2_switch_pressed();98void _on_sphere_switch_pressed();99void _on_box_switch_pressed();100void _on_quad_switch_pressed();101102protected:103virtual void _update_theme_item_cache() override;104void _notification(int p_what);105void gui_input(const Ref<InputEvent> &p_event) override;106void _set_rotation(real_t p_x_degrees, real_t p_y_degrees);107void _store_rotation_metadata();108void _update_rotation();109110public:111void edit(Ref<Material> p_material, const Ref<Environment> &p_env);112MaterialEditor();113};114115class EditorInspectorPluginMaterial : public EditorInspectorPlugin {116GDCLASS(EditorInspectorPluginMaterial, EditorInspectorPlugin);117Ref<Environment> env;118119public:120virtual bool can_handle(Object *p_object) override;121virtual void parse_begin(Object *p_object) override;122123void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value);124125EditorInspectorPluginMaterial();126};127128class MaterialEditorPlugin : public EditorPlugin {129GDCLASS(MaterialEditorPlugin, EditorPlugin);130131public:132virtual String get_plugin_name() const override { return "Material"; }133134MaterialEditorPlugin();135};136137class StandardMaterial3DConversionPlugin : public EditorResourceConversionPlugin {138GDCLASS(StandardMaterial3DConversionPlugin, EditorResourceConversionPlugin);139140public:141virtual String converts_to() const override;142virtual bool handles(const Ref<Resource> &p_resource) const override;143virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;144};145146class ORMMaterial3DConversionPlugin : public EditorResourceConversionPlugin {147GDCLASS(ORMMaterial3DConversionPlugin, EditorResourceConversionPlugin);148149public:150virtual String converts_to() const override;151virtual bool handles(const Ref<Resource> &p_resource) const override;152virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;153};154155class ParticleProcessMaterialConversionPlugin : public EditorResourceConversionPlugin {156GDCLASS(ParticleProcessMaterialConversionPlugin, EditorResourceConversionPlugin);157158public:159virtual String converts_to() const override;160virtual bool handles(const Ref<Resource> &p_resource) const override;161virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;162};163164class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {165GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin);166167public:168virtual String converts_to() const override;169virtual bool handles(const Ref<Resource> &p_resource) const override;170virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;171};172173class ProceduralSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {174GDCLASS(ProceduralSkyMaterialConversionPlugin, EditorResourceConversionPlugin);175176public:177virtual String converts_to() const override;178virtual bool handles(const Ref<Resource> &p_resource) const override;179virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;180};181182class PanoramaSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {183GDCLASS(PanoramaSkyMaterialConversionPlugin, EditorResourceConversionPlugin);184185public:186virtual String converts_to() const override;187virtual bool handles(const Ref<Resource> &p_resource) const override;188virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;189};190191class PhysicalSkyMaterialConversionPlugin : public EditorResourceConversionPlugin {192GDCLASS(PhysicalSkyMaterialConversionPlugin, EditorResourceConversionPlugin);193194public:195virtual String converts_to() const override;196virtual bool handles(const Ref<Resource> &p_resource) const override;197virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;198};199200class FogMaterialConversionPlugin : public EditorResourceConversionPlugin {201GDCLASS(FogMaterialConversionPlugin, EditorResourceConversionPlugin);202203public:204virtual String converts_to() const override;205virtual bool handles(const Ref<Resource> &p_resource) const override;206virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const override;207};208209210