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-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 "cpu_particles_editor_plugin.h"
32
33 #include "editor/plugins/spatial_editor_plugin.h"
34
_node_removed(Node * p_node)35 void CPUParticlesEditor::_node_removed(Node *p_node) {
36
37 if (p_node == node) {
38 node = NULL;
39 hide();
40 }
41 }
42
_notification(int p_notification)43 void CPUParticlesEditor::_notification(int p_notification) {
44
45 if (p_notification == NOTIFICATION_ENTER_TREE) {
46 options->set_icon(options->get_popup()->get_icon("CPUParticles", "EditorIcons"));
47 }
48 }
49
_menu_option(int p_option)50 void CPUParticlesEditor::_menu_option(int p_option) {
51
52 switch (p_option) {
53
54 case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH: {
55
56 emission_file_dialog->popup_centered_ratio();
57
58 } break;
59
60 case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: {
61
62 emission_tree_dialog->popup_centered_ratio();
63
64 } break;
65
66 case MENU_OPTION_RESTART: {
67
68 node->restart();
69
70 } break;
71 }
72 }
73
edit(CPUParticles * p_particles)74 void CPUParticlesEditor::edit(CPUParticles *p_particles) {
75
76 base_node = p_particles;
77 node = p_particles;
78 }
79
_generate_emission_points()80 void CPUParticlesEditor::_generate_emission_points() {
81
82 /// hacer codigo aca
83 PoolVector<Vector3> points;
84 PoolVector<Vector3> normals;
85
86 if (!_generate(points, normals)) {
87 return;
88 }
89
90 if (normals.size() == 0) {
91 node->set_emission_shape(CPUParticles::EMISSION_SHAPE_POINTS);
92 node->set_emission_points(points);
93 } else {
94 node->set_emission_shape(CPUParticles::EMISSION_SHAPE_DIRECTED_POINTS);
95 node->set_emission_points(points);
96 node->set_emission_normals(normals);
97 }
98 }
99
_bind_methods()100 void CPUParticlesEditor::_bind_methods() {
101
102 ClassDB::bind_method("_menu_option", &CPUParticlesEditor::_menu_option);
103 }
104
CPUParticlesEditor()105 CPUParticlesEditor::CPUParticlesEditor() {
106
107 particles_editor_hb = memnew(HBoxContainer);
108 SpatialEditor::get_singleton()->add_control_to_menu_panel(particles_editor_hb);
109 options = memnew(MenuButton);
110 options->set_switch_on_hover(true);
111 particles_editor_hb->add_child(options);
112 particles_editor_hb->hide();
113
114 options->set_text(TTR("CPUParticles"));
115 options->get_popup()->add_item(TTR("Create Emission Points From Mesh"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH);
116 options->get_popup()->add_item(TTR("Create Emission Points From Node"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE);
117 options->get_popup()->add_separator();
118 options->get_popup()->add_item(TTR("Restart"), MENU_OPTION_RESTART);
119 options->get_popup()->connect("id_pressed", this, "_menu_option");
120 }
121
edit(Object * p_object)122 void CPUParticlesEditorPlugin::edit(Object *p_object) {
123
124 particles_editor->edit(Object::cast_to<CPUParticles>(p_object));
125 }
126
handles(Object * p_object) const127 bool CPUParticlesEditorPlugin::handles(Object *p_object) const {
128
129 return p_object->is_class("CPUParticles");
130 }
131
make_visible(bool p_visible)132 void CPUParticlesEditorPlugin::make_visible(bool p_visible) {
133
134 if (p_visible) {
135 particles_editor->show();
136 particles_editor->particles_editor_hb->show();
137 } else {
138 particles_editor->particles_editor_hb->hide();
139 particles_editor->hide();
140 particles_editor->edit(NULL);
141 }
142 }
143
CPUParticlesEditorPlugin(EditorNode * p_node)144 CPUParticlesEditorPlugin::CPUParticlesEditorPlugin(EditorNode *p_node) {
145
146 editor = p_node;
147 particles_editor = memnew(CPUParticlesEditor);
148 editor->get_viewport()->add_child(particles_editor);
149
150 particles_editor->hide();
151 }
152
~CPUParticlesEditorPlugin()153 CPUParticlesEditorPlugin::~CPUParticlesEditorPlugin() {
154 }
155