gi_probe_editor_plugin.cpp 3.8 KB

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