1 /*************************************************************************/
2 /* gi_probe_editor_plugin.cpp */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
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
31 #include "gi_probe_editor_plugin.h"
32
_bake()33 void GIProbeEditorPlugin::_bake() {
34
35 if (gi_probe) {
36 gi_probe->bake();
37 }
38 }
39
edit(Object * p_object)40 void GIProbeEditorPlugin::edit(Object *p_object) {
41
42 GIProbe *s = Object::cast_to<GIProbe>(p_object);
43 if (!s)
44 return;
45
46 gi_probe = s;
47 }
48
handles(Object * p_object) const49 bool GIProbeEditorPlugin::handles(Object *p_object) const {
50
51 return p_object->is_class("GIProbe");
52 }
53
make_visible(bool p_visible)54 void GIProbeEditorPlugin::make_visible(bool p_visible) {
55
56 if (p_visible) {
57 bake->show();
58 } else {
59
60 bake->hide();
61 }
62 }
63
64 EditorProgress *GIProbeEditorPlugin::tmp_progress = NULL;
65
bake_func_begin(int p_steps)66 void GIProbeEditorPlugin::bake_func_begin(int p_steps) {
67
68 ERR_FAIL_COND(tmp_progress != NULL);
69
70 tmp_progress = memnew(EditorProgress("bake_gi", TTR("Bake GI Probe"), p_steps));
71 }
72
bake_func_step(int p_step,const String & p_description)73 void GIProbeEditorPlugin::bake_func_step(int p_step, const String &p_description) {
74
75 ERR_FAIL_COND(tmp_progress == NULL);
76 tmp_progress->step(p_description, p_step, false);
77 }
78
bake_func_end()79 void GIProbeEditorPlugin::bake_func_end() {
80 ERR_FAIL_COND(tmp_progress == NULL);
81 memdelete(tmp_progress);
82 tmp_progress = NULL;
83 }
84
_bind_methods()85 void GIProbeEditorPlugin::_bind_methods() {
86
87 ClassDB::bind_method("_bake", &GIProbeEditorPlugin::_bake);
88 }
89
GIProbeEditorPlugin(EditorNode * p_node)90 GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) {
91
92 editor = p_node;
93 bake = memnew(ToolButton);
94 bake->set_icon(editor->get_gui_base()->get_icon("Bake", "EditorIcons"));
95 bake->set_text(TTR("Bake GI Probe"));
96 bake->hide();
97 bake->connect("pressed", this, "_bake");
98 add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake);
99 gi_probe = NULL;
100
101 GIProbe::bake_begin_function = bake_func_begin;
102 GIProbe::bake_step_function = bake_func_step;
103 GIProbe::bake_end_function = bake_func_end;
104 }
105
~GIProbeEditorPlugin()106 GIProbeEditorPlugin::~GIProbeEditorPlugin() {
107 }
108