gi_probe_editor_plugin.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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) 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. #include "gi_probe_editor_plugin.h"
  31. void GIProbeEditorPlugin::_bake() {
  32. if (gi_probe) {
  33. gi_probe->bake();
  34. }
  35. }
  36. void GIProbeEditorPlugin::edit(Object *p_object) {
  37. GIProbe *s = Object::cast_to<GIProbe>(p_object);
  38. if (!s) {
  39. return;
  40. }
  41. gi_probe = s;
  42. }
  43. bool GIProbeEditorPlugin::handles(Object *p_object) const {
  44. return p_object->is_class("GIProbe");
  45. }
  46. void GIProbeEditorPlugin::make_visible(bool p_visible) {
  47. if (p_visible) {
  48. bake->show();
  49. } else {
  50. bake->hide();
  51. }
  52. }
  53. EditorProgress *GIProbeEditorPlugin::tmp_progress = nullptr;
  54. void GIProbeEditorPlugin::bake_func_begin(int p_steps) {
  55. ERR_FAIL_COND(tmp_progress != nullptr);
  56. tmp_progress = memnew(EditorProgress("bake_gi", TTR("Bake GI Probe"), p_steps));
  57. }
  58. void GIProbeEditorPlugin::bake_func_step(int p_step, const String &p_description) {
  59. ERR_FAIL_COND(tmp_progress == nullptr);
  60. tmp_progress->step(p_description, p_step, false);
  61. }
  62. void GIProbeEditorPlugin::bake_func_end() {
  63. ERR_FAIL_COND(tmp_progress == nullptr);
  64. memdelete(tmp_progress);
  65. tmp_progress = nullptr;
  66. }
  67. void GIProbeEditorPlugin::_bind_methods() {
  68. ClassDB::bind_method("_bake", &GIProbeEditorPlugin::_bake);
  69. }
  70. GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) {
  71. editor = p_node;
  72. bake = memnew(ToolButton);
  73. bake->set_icon(editor->get_gui_base()->get_icon("Bake", "EditorIcons"));
  74. bake->set_text(TTR("Bake GI Probe"));
  75. bake->hide();
  76. bake->connect("pressed", this, "_bake");
  77. add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake);
  78. gi_probe = nullptr;
  79. GIProbe::bake_begin_function = bake_func_begin;
  80. GIProbe::bake_step_function = bake_func_step;
  81. GIProbe::bake_end_function = bake_func_end;
  82. }
  83. GIProbeEditorPlugin::~GIProbeEditorPlugin() {
  84. }