cpu_particles_3d_editor_plugin.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**************************************************************************/
  2. /* cpu_particles_3d_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 "cpu_particles_3d_editor_plugin.h"
  31. #include "editor/editor_node.h"
  32. #include "editor/plugins/node_3d_editor_plugin.h"
  33. #include "editor/scene_tree_editor.h"
  34. #include "scene/gui/menu_button.h"
  35. void CPUParticles3DEditor::_node_removed(Node *p_node) {
  36. if (p_node == node) {
  37. node = nullptr;
  38. hide();
  39. }
  40. }
  41. void CPUParticles3DEditor::_notification(int p_notification) {
  42. switch (p_notification) {
  43. case NOTIFICATION_ENTER_TREE: {
  44. options->set_icon(get_theme_icon(SNAME("CPUParticles3D"), SNAME("EditorIcons")));
  45. } break;
  46. }
  47. }
  48. void CPUParticles3DEditor::_menu_option(int p_option) {
  49. switch (p_option) {
  50. case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: {
  51. emission_tree_dialog->popup_scenetree_dialog();
  52. } break;
  53. case MENU_OPTION_RESTART: {
  54. node->restart();
  55. } break;
  56. }
  57. }
  58. void CPUParticles3DEditor::edit(CPUParticles3D *p_particles) {
  59. base_node = p_particles;
  60. node = p_particles;
  61. }
  62. void CPUParticles3DEditor::_generate_emission_points() {
  63. /// hacer codigo aca
  64. Vector<Vector3> points;
  65. Vector<Vector3> normals;
  66. if (!_generate(points, normals)) {
  67. return;
  68. }
  69. if (normals.size() == 0) {
  70. node->set_emission_shape(CPUParticles3D::EMISSION_SHAPE_POINTS);
  71. node->set_emission_points(points);
  72. } else {
  73. node->set_emission_shape(CPUParticles3D::EMISSION_SHAPE_DIRECTED_POINTS);
  74. node->set_emission_points(points);
  75. node->set_emission_normals(normals);
  76. }
  77. }
  78. void CPUParticles3DEditor::_bind_methods() {
  79. }
  80. CPUParticles3DEditor::CPUParticles3DEditor() {
  81. particles_editor_hb = memnew(HBoxContainer);
  82. Node3DEditor::get_singleton()->add_control_to_menu_panel(particles_editor_hb);
  83. options = memnew(MenuButton);
  84. options->set_switch_on_hover(true);
  85. particles_editor_hb->add_child(options);
  86. particles_editor_hb->hide();
  87. options->set_text(TTR("CPUParticles3D"));
  88. options->get_popup()->add_item(TTR("Restart"), MENU_OPTION_RESTART);
  89. options->get_popup()->add_item(TTR("Create Emission Points From Node"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE);
  90. options->get_popup()->connect("id_pressed", callable_mp(this, &CPUParticles3DEditor::_menu_option));
  91. }
  92. void CPUParticles3DEditorPlugin::edit(Object *p_object) {
  93. particles_editor->edit(Object::cast_to<CPUParticles3D>(p_object));
  94. }
  95. bool CPUParticles3DEditorPlugin::handles(Object *p_object) const {
  96. return p_object->is_class("CPUParticles3D");
  97. }
  98. void CPUParticles3DEditorPlugin::make_visible(bool p_visible) {
  99. if (p_visible) {
  100. particles_editor->show();
  101. particles_editor->particles_editor_hb->show();
  102. } else {
  103. particles_editor->particles_editor_hb->hide();
  104. particles_editor->hide();
  105. particles_editor->edit(nullptr);
  106. }
  107. }
  108. CPUParticles3DEditorPlugin::CPUParticles3DEditorPlugin() {
  109. particles_editor = memnew(CPUParticles3DEditor);
  110. EditorNode::get_singleton()->get_main_screen_control()->add_child(particles_editor);
  111. particles_editor->hide();
  112. }
  113. CPUParticles3DEditorPlugin::~CPUParticles3DEditorPlugin() {
  114. }