You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
Custom ("visiblity") AABB support for CPUParticles
- Improves performance by reducing time spent on AABB generation. - Also adds an option to generate the AABB manually in the CPUParticles3D dropdown.
This commit is contained in:
@@ -77,9 +77,62 @@ void CPUParticles3DEditor::_menu_option(int p_option) {
|
||||
ur->commit_action(false);
|
||||
|
||||
} break;
|
||||
case MENU_OPTION_GENERATE_AABB: {
|
||||
// Add one second to the default generation lifetime, since the progress is updated every second.
|
||||
generate_seconds->set_value(MAX(1.0, trunc(node->get_lifetime()) + 1.0));
|
||||
|
||||
if (generate_seconds->get_value() >= 11.0 + CMP_EPSILON) {
|
||||
// Only pop up the time dialog if the particle's lifetime is long enough to warrant shortening it.
|
||||
generate_aabb->popup_centered();
|
||||
} else {
|
||||
// Generate the visibility AABB immediately.
|
||||
_generate_aabb();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void CPUParticles3DEditor::_generate_aabb() {
|
||||
double time = generate_seconds->get_value();
|
||||
|
||||
double running = 0.0;
|
||||
|
||||
EditorProgress ep("gen_aabb", TTR("Generating Visibility AABB (Waiting for Particle Simulation)"), int(time));
|
||||
|
||||
bool was_emitting = node->is_emitting();
|
||||
if (!was_emitting) {
|
||||
node->set_emitting(true);
|
||||
OS::get_singleton()->delay_usec(1000);
|
||||
}
|
||||
|
||||
AABB rect;
|
||||
|
||||
while (running < time) {
|
||||
uint64_t ticks = OS::get_singleton()->get_ticks_usec();
|
||||
ep.step("Generating...", int(running), true);
|
||||
OS::get_singleton()->delay_usec(1000);
|
||||
|
||||
AABB capture = node->capture_aabb();
|
||||
if (rect == AABB()) {
|
||||
rect = capture;
|
||||
} else {
|
||||
rect.merge_with(capture);
|
||||
}
|
||||
|
||||
running += (OS::get_singleton()->get_ticks_usec() - ticks) / 1000000.0;
|
||||
}
|
||||
|
||||
if (!was_emitting) {
|
||||
node->set_emitting(false);
|
||||
}
|
||||
|
||||
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
||||
ur->create_action(TTR("Generate Visibility AABB"));
|
||||
ur->add_do_method(node, "set_visibility_aabb", rect);
|
||||
ur->add_undo_method(node, "set_visibility_aabb", node->get_visibility_aabb());
|
||||
ur->commit_action();
|
||||
}
|
||||
|
||||
void CPUParticles3DEditor::edit(CPUParticles3D *p_particles) {
|
||||
base_node = p_particles;
|
||||
node = p_particles;
|
||||
@@ -117,9 +170,24 @@ CPUParticles3DEditor::CPUParticles3DEditor() {
|
||||
|
||||
options->set_text(TTR("CPUParticles3D"));
|
||||
options->get_popup()->add_item(TTR("Restart"), MENU_OPTION_RESTART);
|
||||
options->get_popup()->add_item(TTR("Generate AABB"), MENU_OPTION_GENERATE_AABB);
|
||||
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));
|
||||
|
||||
generate_aabb = memnew(ConfirmationDialog);
|
||||
generate_aabb->set_title(TTR("Generate Visibility AABB"));
|
||||
VBoxContainer *genvb = memnew(VBoxContainer);
|
||||
generate_aabb->add_child(genvb);
|
||||
generate_seconds = memnew(SpinBox);
|
||||
genvb->add_margin_child(TTR("Generation Time (sec):"), generate_seconds);
|
||||
generate_seconds->set_min(0.1);
|
||||
generate_seconds->set_max(25);
|
||||
generate_seconds->set_value(2);
|
||||
|
||||
add_child(generate_aabb);
|
||||
|
||||
generate_aabb->connect("confirmed", callable_mp(this, &CPUParticles3DEditor::_generate_aabb));
|
||||
}
|
||||
|
||||
void CPUParticles3DEditorPlugin::edit(Object *p_object) {
|
||||
|
||||
Reference in New Issue
Block a user