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 | |
31 | #include "cpu_particles_3d_editor_plugin.h" |
32 | |
33 | #include "editor/editor_node.h" |
34 | #include "editor/editor_undo_redo_manager.h" |
35 | #include "editor/gui/scene_tree_editor.h" |
36 | #include "editor/plugins/node_3d_editor_plugin.h" |
37 | #include "editor/scene_tree_dock.h" |
38 | #include "scene/gui/menu_button.h" |
39 | |
40 | void CPUParticles3DEditor::_node_removed(Node *p_node) { |
41 | if (p_node == node) { |
42 | node = nullptr; |
43 | hide(); |
44 | } |
45 | } |
46 | |
47 | void CPUParticles3DEditor::_notification(int p_notification) { |
48 | switch (p_notification) { |
49 | case NOTIFICATION_ENTER_TREE: { |
50 | options->set_icon(get_editor_theme_icon(SNAME("CPUParticles3D" ))); |
51 | } break; |
52 | } |
53 | } |
54 | |
55 | void CPUParticles3DEditor::_menu_option(int p_option) { |
56 | switch (p_option) { |
57 | case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: { |
58 | emission_tree_dialog->popup_scenetree_dialog(); |
59 | |
60 | } break; |
61 | |
62 | case MENU_OPTION_RESTART: { |
63 | node->restart(); |
64 | } break; |
65 | |
66 | case MENU_OPTION_CONVERT_TO_GPU_PARTICLES: { |
67 | GPUParticles3D *gpu_particles = memnew(GPUParticles3D); |
68 | gpu_particles->convert_from_particles(node); |
69 | gpu_particles->set_name(node->get_name()); |
70 | gpu_particles->set_transform(node->get_transform()); |
71 | gpu_particles->set_visible(node->is_visible()); |
72 | gpu_particles->set_process_mode(node->get_process_mode()); |
73 | |
74 | EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); |
75 | ur->create_action(TTR("Convert to GPUParticles3D" )); |
76 | SceneTreeDock::get_singleton()->replace_node(node, gpu_particles); |
77 | ur->commit_action(false); |
78 | |
79 | } break; |
80 | } |
81 | } |
82 | |
83 | void CPUParticles3DEditor::edit(CPUParticles3D *p_particles) { |
84 | base_node = p_particles; |
85 | node = p_particles; |
86 | } |
87 | |
88 | void CPUParticles3DEditor::_generate_emission_points() { |
89 | /// hacer codigo aca |
90 | Vector<Vector3> points; |
91 | Vector<Vector3> normals; |
92 | |
93 | if (!_generate(points, normals)) { |
94 | return; |
95 | } |
96 | |
97 | if (normals.size() == 0) { |
98 | node->set_emission_shape(CPUParticles3D::EMISSION_SHAPE_POINTS); |
99 | node->set_emission_points(points); |
100 | } else { |
101 | node->set_emission_shape(CPUParticles3D::EMISSION_SHAPE_DIRECTED_POINTS); |
102 | node->set_emission_points(points); |
103 | node->set_emission_normals(normals); |
104 | } |
105 | } |
106 | |
107 | void CPUParticles3DEditor::_bind_methods() { |
108 | } |
109 | |
110 | CPUParticles3DEditor::CPUParticles3DEditor() { |
111 | particles_editor_hb = memnew(HBoxContainer); |
112 | Node3DEditor::get_singleton()->add_control_to_menu_panel(particles_editor_hb); |
113 | options = memnew(MenuButton); |
114 | options->set_switch_on_hover(true); |
115 | particles_editor_hb->add_child(options); |
116 | particles_editor_hb->hide(); |
117 | |
118 | options->set_text(TTR("CPUParticles3D" )); |
119 | options->get_popup()->add_item(TTR("Restart" ), MENU_OPTION_RESTART); |
120 | options->get_popup()->add_item(TTR("Create Emission Points From Node" ), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE); |
121 | options->get_popup()->add_item(TTR("Convert to GPUParticles3D" ), MENU_OPTION_CONVERT_TO_GPU_PARTICLES); |
122 | options->get_popup()->connect("id_pressed" , callable_mp(this, &CPUParticles3DEditor::_menu_option)); |
123 | } |
124 | |
125 | void CPUParticles3DEditorPlugin::edit(Object *p_object) { |
126 | particles_editor->edit(Object::cast_to<CPUParticles3D>(p_object)); |
127 | } |
128 | |
129 | bool CPUParticles3DEditorPlugin::handles(Object *p_object) const { |
130 | return p_object->is_class("CPUParticles3D" ); |
131 | } |
132 | |
133 | void CPUParticles3DEditorPlugin::make_visible(bool p_visible) { |
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(nullptr); |
141 | } |
142 | } |
143 | |
144 | CPUParticles3DEditorPlugin::CPUParticles3DEditorPlugin() { |
145 | particles_editor = memnew(CPUParticles3DEditor); |
146 | EditorNode::get_singleton()->get_main_screen_control()->add_child(particles_editor); |
147 | |
148 | particles_editor->hide(); |
149 | } |
150 | |
151 | CPUParticles3DEditorPlugin::~CPUParticles3DEditorPlugin() { |
152 | } |
153 | |