1
0
mirror of https://github.com/godotengine/godot.git synced 2026-01-06 19:41:11 +00:00

Implement conversion from CPUParticles to GPUParticles (3D/2D)

This commit is contained in:
Yuri Roubinski
2023-08-19 11:55:49 +03:00
parent b51ee8b029
commit 7fcb91f077
10 changed files with 246 additions and 5 deletions

View File

@@ -33,8 +33,11 @@
#include "canvas_item_editor_plugin.h"
#include "core/io/image_loader.h"
#include "editor/editor_node.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/scene_tree_dock.h"
#include "scene/2d/cpu_particles_2d.h"
#include "scene/2d/gpu_particles_2d.h"
#include "scene/gui/check_box.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/option_button.h"
@@ -67,14 +70,26 @@ void CPUParticles2DEditorPlugin::_menu_callback(int p_idx) {
switch (p_idx) {
case MENU_LOAD_EMISSION_MASK: {
file->popup_file_dialog();
} break;
case MENU_CLEAR_EMISSION_MASK: {
emission_mask->popup_centered();
} break;
case MENU_RESTART: {
particles->restart();
}
} break;
case MENU_CONVERT_TO_GPU_PARTICLES: {
GPUParticles2D *gpu_particles = memnew(GPUParticles2D);
gpu_particles->convert_from_particles(particles);
gpu_particles->set_name(particles->get_name());
gpu_particles->set_transform(particles->get_transform());
gpu_particles->set_visible(particles->is_visible());
gpu_particles->set_process_mode(particles->get_process_mode());
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
ur->create_action(TTR("Convert to GPUParticles3D"));
SceneTreeDock::get_singleton()->replace_node(particles, gpu_particles);
ur->commit_action(false);
} break;
}
}
@@ -257,6 +272,7 @@ CPUParticles2DEditorPlugin::CPUParticles2DEditorPlugin() {
menu = memnew(MenuButton);
menu->get_popup()->add_item(TTR("Restart"), MENU_RESTART);
menu->get_popup()->add_item(TTR("Load Emission Mask"), MENU_LOAD_EMISSION_MASK);
menu->get_popup()->add_item(TTR("Convert to GPUParticles2D"), MENU_CONVERT_TO_GPU_PARTICLES);
menu->set_text(TTR("CPUParticles2D"));
menu->set_switch_on_hover(true);
toolbar->add_child(menu);

View File

@@ -49,7 +49,8 @@ class CPUParticles2DEditorPlugin : public EditorPlugin {
enum {
MENU_LOAD_EMISSION_MASK,
MENU_CLEAR_EMISSION_MASK,
MENU_RESTART
MENU_RESTART,
MENU_CONVERT_TO_GPU_PARTICLES,
};
enum EmissionMode {

View File

@@ -31,8 +31,10 @@
#include "cpu_particles_3d_editor_plugin.h"
#include "editor/editor_node.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/scene_tree_editor.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "editor/scene_tree_dock.h"
#include "scene/gui/menu_button.h"
void CPUParticles3DEditor::_node_removed(Node *p_node) {
@@ -59,6 +61,20 @@ void CPUParticles3DEditor::_menu_option(int p_option) {
case MENU_OPTION_RESTART: {
node->restart();
} break;
case MENU_OPTION_CONVERT_TO_GPU_PARTICLES: {
GPUParticles3D *gpu_particles = memnew(GPUParticles3D);
gpu_particles->convert_from_particles(node);
gpu_particles->set_name(node->get_name());
gpu_particles->set_transform(node->get_transform());
gpu_particles->set_visible(node->is_visible());
gpu_particles->set_process_mode(node->get_process_mode());
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
ur->create_action(TTR("Convert to GPUParticles3D"));
SceneTreeDock::get_singleton()->replace_node(node, gpu_particles);
ur->commit_action(false);
} break;
}
@@ -102,6 +118,7 @@ CPUParticles3DEditor::CPUParticles3DEditor() {
options->set_text(TTR("CPUParticles3D"));
options->get_popup()->add_item(TTR("Restart"), MENU_OPTION_RESTART);
options->get_popup()->add_item(TTR("Create Emission Points From Node"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE);
options->get_popup()->add_item(TTR("Convert to GPUParticles3D"), MENU_OPTION_CONVERT_TO_GPU_PARTICLES);
options->get_popup()->connect("id_pressed", callable_mp(this, &CPUParticles3DEditor::_menu_option));
}

View File

@@ -40,8 +40,8 @@ class CPUParticles3DEditor : public GPUParticles3DEditorBase {
enum Menu {
MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE,
MENU_OPTION_CLEAR_EMISSION_VOLUME,
MENU_OPTION_RESTART
MENU_OPTION_RESTART,
MENU_OPTION_CONVERT_TO_GPU_PARTICLES,
};
CPUParticles3D *node = nullptr;