cpu_particles_editor_plugin.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*************************************************************************/
  2. /* cpu_particles_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 "cpu_particles_editor_plugin.h"
  31. #include "editor/plugins/spatial_editor_plugin.h"
  32. void CPUParticlesEditor::_node_removed(Node *p_node) {
  33. if (p_node == node) {
  34. node = NULL;
  35. hide();
  36. }
  37. }
  38. void CPUParticlesEditor::_notification(int p_notification) {
  39. if (p_notification == NOTIFICATION_ENTER_TREE) {
  40. options->set_icon(options->get_popup()->get_icon("CPUParticles", "EditorIcons"));
  41. }
  42. }
  43. void CPUParticlesEditor::_menu_option(int p_option) {
  44. switch (p_option) {
  45. case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH: {
  46. emission_file_dialog->popup_centered_ratio();
  47. } break;
  48. case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: {
  49. emission_tree_dialog->popup_centered_ratio();
  50. } break;
  51. }
  52. }
  53. void CPUParticlesEditor::edit(CPUParticles *p_particles) {
  54. base_node = p_particles;
  55. node = p_particles;
  56. }
  57. void CPUParticlesEditor::_generate_emission_points() {
  58. /// hacer codigo aca
  59. PoolVector<Vector3> points;
  60. PoolVector<Vector3> normals;
  61. if (!_generate(points, normals)) {
  62. return;
  63. }
  64. if (normals.size() == 0) {
  65. node->set_emission_shape(CPUParticles::EMISSION_SHAPE_POINTS);
  66. node->set_emission_points(points);
  67. } else {
  68. node->set_emission_shape(CPUParticles::EMISSION_SHAPE_DIRECTED_POINTS);
  69. node->set_emission_points(points);
  70. node->set_emission_normals(normals);
  71. }
  72. }
  73. void CPUParticlesEditor::_bind_methods() {
  74. ClassDB::bind_method("_menu_option", &CPUParticlesEditor::_menu_option);
  75. }
  76. CPUParticlesEditor::CPUParticlesEditor() {
  77. particles_editor_hb = memnew(HBoxContainer);
  78. SpatialEditor::get_singleton()->add_control_to_menu_panel(particles_editor_hb);
  79. options = memnew(MenuButton);
  80. particles_editor_hb->add_child(options);
  81. particles_editor_hb->hide();
  82. options->set_text(TTR("CPUParticles"));
  83. options->get_popup()->add_item(TTR("Create Emission Points From Mesh"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH);
  84. options->get_popup()->add_item(TTR("Create Emission Points From Node"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE);
  85. options->get_popup()->connect("id_pressed", this, "_menu_option");
  86. }
  87. void CPUParticlesEditorPlugin::edit(Object *p_object) {
  88. particles_editor->edit(Object::cast_to<CPUParticles>(p_object));
  89. }
  90. bool CPUParticlesEditorPlugin::handles(Object *p_object) const {
  91. return p_object->is_class("CPUParticles");
  92. }
  93. void CPUParticlesEditorPlugin::make_visible(bool p_visible) {
  94. if (p_visible) {
  95. particles_editor->show();
  96. particles_editor->particles_editor_hb->show();
  97. } else {
  98. particles_editor->particles_editor_hb->hide();
  99. particles_editor->hide();
  100. particles_editor->edit(NULL);
  101. }
  102. }
  103. CPUParticlesEditorPlugin::CPUParticlesEditorPlugin(EditorNode *p_node) {
  104. editor = p_node;
  105. particles_editor = memnew(CPUParticlesEditor);
  106. editor->get_viewport()->add_child(particles_editor);
  107. particles_editor->hide();
  108. }
  109. CPUParticlesEditorPlugin::~CPUParticlesEditorPlugin() {
  110. }