Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Particle System emission shapes gizmo #86902

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/classes/ParticleProcessMaterial.xml
Original file line number Diff line number Diff line change
@@ -409,6 +409,13 @@
A pivot point used to calculate radial and orbital velocity of particles.
</member>
</members>
<signals>
<signal name="emission_shape_changed">
<description>
Emitted when this material's emission shape is changed in any way. This includes changes to [member emission_shape], [member emission_shape_scale], or [member emission_sphere_radius], and any other property that affects the emission shape's offset, size, scale, or orientation.
</description>
</signal>
</signals>
<constants>
<constant name="PARAM_INITIAL_LINEAR_VELOCITY" value="0" enum="Parameter">
Use with [method set_param_min], [method set_param_max], and [method set_param_texture] to set initial velocity properties.
765 changes: 765 additions & 0 deletions editor/plugins/gizmos/particles_3d_emission_shape_gizmo_plugin.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**************************************************************************/
/* particles_3d_emission_shape_gizmo_plugin.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef PARTICLES_3D_EMISSION_SHAPE_GIZMO_PLUGIN_H
#define PARTICLES_3D_EMISSION_SHAPE_GIZMO_PLUGIN_H

#include "editor/plugins/gizmos/gizmo_3d_helper.h"
#include "editor/plugins/node_3d_editor_gizmos.h"

class Particles3DEmissionShapeGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(Particles3DEmissionShapeGizmoPlugin, EditorNode3DGizmoPlugin);

Ref<Gizmo3DHelper> helper;

public:
bool has_gizmo(Node3D *p_spatial) override;
String get_gizmo_name() const override;
int get_priority() const override;
bool is_selectable_when_hidden() const override;
void redraw(EditorNode3DGizmo *p_gizmo) override;

String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;

Particles3DEmissionShapeGizmoPlugin();
};

#endif // PARTICLES_3D_EMISSION_SHAPE_GIZMO_PLUGIN_H
2 changes: 2 additions & 0 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@
#include "editor/plugins/gizmos/navigation_link_3d_gizmo_plugin.h"
#include "editor/plugins/gizmos/navigation_region_3d_gizmo_plugin.h"
#include "editor/plugins/gizmos/occluder_instance_3d_gizmo_plugin.h"
#include "editor/plugins/gizmos/particles_3d_emission_shape_gizmo_plugin.h"
#include "editor/plugins/gizmos/physics_bone_3d_gizmo_plugin.h"
#include "editor/plugins/gizmos/ray_cast_3d_gizmo_plugin.h"
#include "editor/plugins/gizmos/reflection_probe_gizmo_plugin.h"
@@ -8367,6 +8368,7 @@ void Node3DEditor::_register_all_gizmos() {
add_gizmo_plugin(Ref<VisibleOnScreenNotifier3DGizmoPlugin>(memnew(VisibleOnScreenNotifier3DGizmoPlugin)));
add_gizmo_plugin(Ref<GPUParticles3DGizmoPlugin>(memnew(GPUParticles3DGizmoPlugin)));
add_gizmo_plugin(Ref<GPUParticlesCollision3DGizmoPlugin>(memnew(GPUParticlesCollision3DGizmoPlugin)));
add_gizmo_plugin(Ref<Particles3DEmissionShapeGizmoPlugin>(memnew(Particles3DEmissionShapeGizmoPlugin)));
add_gizmo_plugin(Ref<CPUParticles3DGizmoPlugin>(memnew(CPUParticles3DGizmoPlugin)));
add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin)));
add_gizmo_plugin(Ref<DecalGizmoPlugin>(memnew(DecalGizmoPlugin)));
7 changes: 7 additions & 0 deletions scene/3d/cpu_particles_3d.cpp
Original file line number Diff line number Diff line change
@@ -410,14 +410,17 @@ bool CPUParticles3D::get_particle_flag(ParticleFlags p_particle_flag) const {
void CPUParticles3D::set_emission_shape(EmissionShape p_shape) {
ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX);
emission_shape = p_shape;
update_gizmos();
}

void CPUParticles3D::set_emission_sphere_radius(real_t p_radius) {
emission_sphere_radius = p_radius;
update_gizmos();
}

void CPUParticles3D::set_emission_box_extents(Vector3 p_extents) {
emission_box_extents = p_extents;
update_gizmos();
}

void CPUParticles3D::set_emission_points(const Vector<Vector3> &p_points) {
@@ -434,18 +437,22 @@ void CPUParticles3D::set_emission_colors(const Vector<Color> &p_colors) {

void CPUParticles3D::set_emission_ring_axis(Vector3 p_axis) {
emission_ring_axis = p_axis;
update_gizmos();
}

void CPUParticles3D::set_emission_ring_height(real_t p_height) {
emission_ring_height = p_height;
update_gizmos();
}

void CPUParticles3D::set_emission_ring_radius(real_t p_radius) {
emission_ring_radius = p_radius;
update_gizmos();
}

void CPUParticles3D::set_emission_ring_inner_radius(real_t p_radius) {
emission_ring_inner_radius = p_radius;
update_gizmos();
}

void CPUParticles3D::set_emission_ring_cone_angle(real_t p_angle) {
16 changes: 15 additions & 1 deletion scene/3d/gpu_particles_3d.cpp
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
#include "scene/resources/curve_texture.h"
#include "scene/resources/gradient_texture.h"
#include "scene/resources/particle_process_material.h"
#include "scene/scene_string_names.h"

AABB GPUParticles3D::get_aabb() const {
return AABB();
@@ -127,6 +128,7 @@ void GPUParticles3D::set_process_material(const Ref<Material> &p_material) {
RID material_rid;
if (process_material.is_valid()) {
material_rid = process_material->get_rid();
process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
}
RS::get_singleton()->particles_set_process_material(particles, material_rid);

@@ -459,6 +461,14 @@ void GPUParticles3D::_notification(int p_what) {
// Use internal process when emitting and one_shot is on so that when
// the shot ends the editor can properly update.
case NOTIFICATION_INTERNAL_PROCESS: {
const Vector3 velocity = (get_global_position() - previous_position) / get_process_delta_time();

if (velocity != previous_velocity) {
RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
previous_velocity = velocity;
}
previous_position = get_global_position();

if (one_shot) {
time += get_process_delta_time();
if (time > emission_time) {
@@ -469,7 +479,7 @@ void GPUParticles3D::_notification(int p_what) {
}
if (time > active_time) {
if (active && !signal_canceled) {
emit_signal(SceneStringName(finished));
emit_signal(SceneStringNames::get_singleton()->finished);
}
active = false;
if (!emitting) {
@@ -509,6 +519,10 @@ void GPUParticles3D::_notification(int p_what) {

case NOTIFICATION_EXIT_TREE: {
RS::get_singleton()->particles_set_subemitter(particles, RID());

Ref<ParticleProcessMaterial> material = get_process_material();
ERR_FAIL_COND(material.is_null());
material->disconnect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
} break;

case NOTIFICATION_PAUSED:
11 changes: 11 additions & 0 deletions scene/resources/particle_process_material.cpp
Original file line number Diff line number Diff line change
@@ -1565,18 +1565,21 @@ bool ParticleProcessMaterial::get_particle_flag(ParticleFlags p_particle_flag) c
void ParticleProcessMaterial::set_emission_shape(EmissionShape p_shape) {
ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX);
emission_shape = p_shape;
emit_signal("emission_shape_changed");
notify_property_list_changed();
_queue_shader_change();
}

void ParticleProcessMaterial::set_emission_sphere_radius(real_t p_radius) {
emission_sphere_radius = p_radius;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_sphere_radius, p_radius);
emit_signal("emission_shape_changed");
}

void ParticleProcessMaterial::set_emission_box_extents(Vector3 p_extents) {
emission_box_extents = p_extents;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_box_extents, p_extents);
emit_signal("emission_shape_changed");
}

void ParticleProcessMaterial::set_emission_point_texture(const Ref<Texture2D> &p_points) {
@@ -1606,21 +1609,25 @@ void ParticleProcessMaterial::set_emission_point_count(int p_count) {
void ParticleProcessMaterial::set_emission_ring_axis(Vector3 p_axis) {
emission_ring_axis = p_axis;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_axis, p_axis);
emit_signal("emission_shape_changed");
}

void ParticleProcessMaterial::set_emission_ring_height(real_t p_height) {
emission_ring_height = p_height;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_height, p_height);
emit_signal("emission_shape_changed");
}

void ParticleProcessMaterial::set_emission_ring_radius(real_t p_radius) {
emission_ring_radius = p_radius;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_radius, p_radius);
emit_signal("emission_shape_changed");
}

void ParticleProcessMaterial::set_emission_ring_inner_radius(real_t p_radius) {
emission_ring_inner_radius = p_radius;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_inner_radius, p_radius);
emit_signal("emission_shape_changed");
}

void ParticleProcessMaterial::set_emission_ring_cone_angle(real_t p_angle) {
@@ -1684,6 +1691,7 @@ real_t ParticleProcessMaterial::get_emission_ring_cone_angle() const {
void ParticleProcessMaterial::set_emission_shape_offset(const Vector3 &p_emission_shape_offset) {
emission_shape_offset = p_emission_shape_offset;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_shape_offset, p_emission_shape_offset);
emit_signal("emission_shape_changed");
}

Vector3 ParticleProcessMaterial::get_emission_shape_offset() const {
@@ -1693,6 +1701,7 @@ Vector3 ParticleProcessMaterial::get_emission_shape_offset() const {
void ParticleProcessMaterial::set_emission_shape_scale(const Vector3 &p_emission_shape_scale) {
emission_shape_scale = p_emission_shape_scale;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_shape_scale, p_emission_shape_scale);
emit_signal("emission_shape_changed");
}

Vector3 ParticleProcessMaterial::get_emission_shape_scale() const {
@@ -2209,6 +2218,8 @@ void ParticleProcessMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "sub_emitter_amount_at_collision", PROPERTY_HINT_RANGE, "1,32,1"), "set_sub_emitter_amount_at_collision", "get_sub_emitter_amount_at_collision");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sub_emitter_keep_velocity"), "set_sub_emitter_keep_velocity", "get_sub_emitter_keep_velocity");

ADD_SIGNAL(MethodInfo("emission_shape_changed"));

BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY);
BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY);
BIND_ENUM_CONSTANT(PARAM_ORBIT_VELOCITY);
Loading