2018-08-30 04:38:13 +08:00
|
|
|
/**************************************************************************/
|
2020-03-27 05:49:16 +08:00
|
|
|
/* cpu_particles_3d.h */
|
2018-08-30 04:38:13 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2022-07-24 05:41:51 +08:00
|
|
|
#ifndef CPU_PARTICLES_3D_H
|
|
|
|
#define CPU_PARTICLES_3D_H
|
2018-09-04 17:30:04 +08:00
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
#include "scene/3d/visual_instance_3d.h"
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
class CPUParticles3D : public GeometryInstance3D {
|
2018-07-07 07:21:13 +08:00
|
|
|
private:
|
2020-03-27 05:49:16 +08:00
|
|
|
GDCLASS(CPUParticles3D, GeometryInstance3D);
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum DrawOrder {
|
|
|
|
DRAW_ORDER_INDEX,
|
|
|
|
DRAW_ORDER_LIFETIME,
|
|
|
|
DRAW_ORDER_VIEW_DEPTH,
|
2021-02-17 22:30:03 +08:00
|
|
|
DRAW_ORDER_MAX
|
2018-07-07 07:21:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Parameter {
|
|
|
|
PARAM_INITIAL_LINEAR_VELOCITY,
|
|
|
|
PARAM_ANGULAR_VELOCITY,
|
2019-06-11 23:47:24 +08:00
|
|
|
PARAM_ORBIT_VELOCITY,
|
2018-07-07 07:21:13 +08:00
|
|
|
PARAM_LINEAR_ACCEL,
|
|
|
|
PARAM_RADIAL_ACCEL,
|
|
|
|
PARAM_TANGENTIAL_ACCEL,
|
|
|
|
PARAM_DAMPING,
|
|
|
|
PARAM_ANGLE,
|
|
|
|
PARAM_SCALE,
|
|
|
|
PARAM_HUE_VARIATION,
|
|
|
|
PARAM_ANIM_SPEED,
|
|
|
|
PARAM_ANIM_OFFSET,
|
|
|
|
PARAM_MAX
|
|
|
|
};
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
enum ParticleFlags {
|
|
|
|
PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY,
|
|
|
|
PARTICLE_FLAG_ROTATE_Y,
|
|
|
|
PARTICLE_FLAG_DISABLE_Z,
|
|
|
|
PARTICLE_FLAG_MAX
|
2018-07-07 07:21:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum EmissionShape {
|
|
|
|
EMISSION_SHAPE_POINT,
|
|
|
|
EMISSION_SHAPE_SPHERE,
|
2021-11-28 06:28:53 +08:00
|
|
|
EMISSION_SHAPE_SPHERE_SURFACE,
|
2018-07-07 07:21:13 +08:00
|
|
|
EMISSION_SHAPE_BOX,
|
|
|
|
EMISSION_SHAPE_POINTS,
|
|
|
|
EMISSION_SHAPE_DIRECTED_POINTS,
|
2021-07-11 21:45:21 +08:00
|
|
|
EMISSION_SHAPE_RING,
|
2020-01-16 17:59:01 +08:00
|
|
|
EMISSION_SHAPE_MAX
|
2018-07-07 07:21:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2021-02-08 05:29:31 +08:00
|
|
|
bool emitting = false;
|
2023-05-09 16:18:08 +08:00
|
|
|
bool active = false;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
struct Particle {
|
2020-10-17 13:08:21 +08:00
|
|
|
Transform3D transform;
|
2018-07-07 07:21:13 +08:00
|
|
|
Color color;
|
2021-08-10 06:15:17 +08:00
|
|
|
real_t custom[4] = {};
|
2018-07-07 07:21:13 +08:00
|
|
|
Vector3 velocity;
|
2021-02-08 05:29:31 +08:00
|
|
|
bool active = false;
|
2021-01-30 08:55:54 +08:00
|
|
|
real_t angle_rand = 0.0;
|
|
|
|
real_t scale_rand = 0.0;
|
|
|
|
real_t hue_rot_rand = 0.0;
|
|
|
|
real_t anim_offset_rand = 0.0;
|
2021-11-23 20:50:35 +08:00
|
|
|
Color start_color_rand;
|
2021-02-02 10:16:37 +08:00
|
|
|
double time = 0.0;
|
|
|
|
double lifetime = 0.0;
|
2018-07-07 07:21:13 +08:00
|
|
|
Color base_color;
|
|
|
|
|
2021-02-08 05:29:31 +08:00
|
|
|
uint32_t seed = 0;
|
2018-07-07 07:21:13 +08:00
|
|
|
};
|
|
|
|
|
2021-02-02 10:16:37 +08:00
|
|
|
double time = 0.0;
|
|
|
|
double frame_remainder = 0.0;
|
2021-02-08 05:29:31 +08:00
|
|
|
int cycle = 0;
|
|
|
|
bool redraw = false;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
RID multimesh;
|
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Particle> particles;
|
|
|
|
Vector<float> particle_data;
|
|
|
|
Vector<int> particle_order;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
struct SortLifetime {
|
2021-02-08 05:29:31 +08:00
|
|
|
const Particle *particles = nullptr;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
bool operator()(int p_a, int p_b) const {
|
2019-06-15 04:22:19 +08:00
|
|
|
return particles[p_a].time > particles[p_b].time;
|
2018-07-07 07:21:13 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SortAxis {
|
2021-02-08 05:29:31 +08:00
|
|
|
const Particle *particles = nullptr;
|
2018-07-07 07:21:13 +08:00
|
|
|
Vector3 axis;
|
|
|
|
bool operator()(int p_a, int p_b) const {
|
|
|
|
return axis.dot(particles[p_a].transform.origin) < axis.dot(particles[p_b].transform.origin);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2021-02-08 05:29:31 +08:00
|
|
|
bool one_shot = false;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2021-02-02 10:16:37 +08:00
|
|
|
double lifetime = 1.0;
|
|
|
|
double pre_process_time = 0.0;
|
2021-01-30 08:55:54 +08:00
|
|
|
real_t explosiveness_ratio = 0.0;
|
|
|
|
real_t randomness_ratio = 0.0;
|
2021-02-02 10:16:37 +08:00
|
|
|
double lifetime_randomness = 0.0;
|
|
|
|
double speed_scale = 1.0;
|
2022-06-09 23:38:07 +08:00
|
|
|
bool local_coords = false;
|
2021-02-08 05:29:31 +08:00
|
|
|
int fixed_fps = 0;
|
|
|
|
bool fractional_delta = true;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2020-10-17 13:08:21 +08:00
|
|
|
Transform3D inv_emission_transform;
|
2019-06-15 04:22:19 +08:00
|
|
|
|
2021-02-11 02:22:13 +08:00
|
|
|
SafeFlag can_update;
|
2018-10-08 11:51:48 +08:00
|
|
|
|
2021-02-08 05:29:31 +08:00
|
|
|
DrawOrder draw_order = DRAW_ORDER_INDEX;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
Ref<Mesh> mesh;
|
|
|
|
|
|
|
|
////////
|
|
|
|
|
2021-02-08 05:29:31 +08:00
|
|
|
Vector3 direction = Vector3(1, 0, 0);
|
2021-01-30 08:55:54 +08:00
|
|
|
real_t spread = 45.0;
|
|
|
|
real_t flatness = 0.0;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2022-10-02 03:09:22 +08:00
|
|
|
real_t parameters_min[PARAM_MAX] = {};
|
2021-07-14 01:46:27 +08:00
|
|
|
real_t parameters_max[PARAM_MAX] = {};
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
Ref<Curve> curve_parameters[PARAM_MAX];
|
2021-02-08 05:29:31 +08:00
|
|
|
Color color = Color(1, 1, 1, 1);
|
2018-07-07 07:21:13 +08:00
|
|
|
Ref<Gradient> color_ramp;
|
2021-11-23 20:50:35 +08:00
|
|
|
Ref<Gradient> color_initial_ramp;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2021-02-08 05:29:31 +08:00
|
|
|
bool particle_flags[PARTICLE_FLAG_MAX] = {};
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2021-02-08 05:29:31 +08:00
|
|
|
EmissionShape emission_shape = EMISSION_SHAPE_POINT;
|
2021-01-30 08:55:54 +08:00
|
|
|
real_t emission_sphere_radius = 1.0;
|
2021-02-08 05:29:31 +08:00
|
|
|
Vector3 emission_box_extents = Vector3(1, 1, 1);
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Vector3> emission_points;
|
|
|
|
Vector<Vector3> emission_normals;
|
|
|
|
Vector<Color> emission_colors;
|
2021-02-08 05:29:31 +08:00
|
|
|
int emission_point_count = 0;
|
2021-07-11 21:45:21 +08:00
|
|
|
Vector3 emission_ring_axis;
|
2022-05-02 22:28:25 +08:00
|
|
|
real_t emission_ring_height = 0.0;
|
|
|
|
real_t emission_ring_radius = 0.0;
|
|
|
|
real_t emission_ring_inner_radius = 0.0;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2021-07-14 01:46:27 +08:00
|
|
|
Ref<Curve> scale_curve_x;
|
|
|
|
Ref<Curve> scale_curve_y;
|
|
|
|
Ref<Curve> scale_curve_z;
|
|
|
|
bool split_scale = false;
|
|
|
|
|
2021-02-08 05:29:31 +08:00
|
|
|
Vector3 gravity = Vector3(0, -9.8, 0);
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2019-10-19 23:30:13 +08:00
|
|
|
void _update_internal();
|
2021-02-02 10:16:37 +08:00
|
|
|
void _particles_process(double p_delta);
|
2018-07-07 07:21:13 +08:00
|
|
|
void _update_particle_data_buffer();
|
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
Mutex update_mutex;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
void _update_render_thread();
|
|
|
|
|
2019-03-09 09:50:44 +08:00
|
|
|
void _set_redraw(bool p_redraw);
|
|
|
|
|
2018-07-07 07:21:13 +08:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
2022-08-13 04:57:11 +08:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
public:
|
2020-07-10 18:34:39 +08:00
|
|
|
AABB get_aabb() const override;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
void set_emitting(bool p_emitting);
|
|
|
|
void set_amount(int p_amount);
|
2021-02-02 10:16:37 +08:00
|
|
|
void set_lifetime(double p_lifetime);
|
2018-07-07 07:21:13 +08:00
|
|
|
void set_one_shot(bool p_one_shot);
|
2021-02-02 10:16:37 +08:00
|
|
|
void set_pre_process_time(double p_time);
|
2021-01-30 08:55:54 +08:00
|
|
|
void set_explosiveness_ratio(real_t p_ratio);
|
|
|
|
void set_randomness_ratio(real_t p_ratio);
|
2021-02-02 10:16:37 +08:00
|
|
|
void set_lifetime_randomness(double p_random);
|
2018-07-07 07:21:13 +08:00
|
|
|
void set_use_local_coordinates(bool p_enable);
|
2021-02-02 10:16:37 +08:00
|
|
|
void set_speed_scale(double p_scale);
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
bool is_emitting() const;
|
|
|
|
int get_amount() const;
|
2021-02-02 10:16:37 +08:00
|
|
|
double get_lifetime() const;
|
2018-07-07 07:21:13 +08:00
|
|
|
bool get_one_shot() const;
|
2021-02-02 10:16:37 +08:00
|
|
|
double get_pre_process_time() const;
|
2021-01-30 08:55:54 +08:00
|
|
|
real_t get_explosiveness_ratio() const;
|
|
|
|
real_t get_randomness_ratio() const;
|
2021-02-02 10:16:37 +08:00
|
|
|
double get_lifetime_randomness() const;
|
2018-07-07 07:21:13 +08:00
|
|
|
bool get_use_local_coordinates() const;
|
2021-02-02 10:16:37 +08:00
|
|
|
double get_speed_scale() const;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
void set_fixed_fps(int p_count);
|
|
|
|
int get_fixed_fps() const;
|
|
|
|
|
|
|
|
void set_fractional_delta(bool p_enable);
|
|
|
|
bool get_fractional_delta() const;
|
|
|
|
|
|
|
|
void set_draw_order(DrawOrder p_order);
|
|
|
|
DrawOrder get_draw_order() const;
|
|
|
|
|
|
|
|
void set_mesh(const Ref<Mesh> &p_mesh);
|
|
|
|
Ref<Mesh> get_mesh() const;
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
|
2019-03-05 06:45:53 +08:00
|
|
|
void set_direction(Vector3 p_direction);
|
|
|
|
Vector3 get_direction() const;
|
|
|
|
|
2021-01-30 08:55:54 +08:00
|
|
|
void set_spread(real_t p_spread);
|
|
|
|
real_t get_spread() const;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2021-01-30 08:55:54 +08:00
|
|
|
void set_flatness(real_t p_flatness);
|
|
|
|
real_t get_flatness() const;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2021-07-14 01:46:27 +08:00
|
|
|
void set_param_min(Parameter p_param, real_t p_value);
|
|
|
|
real_t get_param_min(Parameter p_param) const;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2021-07-14 01:46:27 +08:00
|
|
|
void set_param_max(Parameter p_param, real_t p_value);
|
|
|
|
real_t get_param_max(Parameter p_param) const;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
void set_param_curve(Parameter p_param, const Ref<Curve> &p_curve);
|
|
|
|
Ref<Curve> get_param_curve(Parameter p_param) const;
|
|
|
|
|
|
|
|
void set_color(const Color &p_color);
|
|
|
|
Color get_color() const;
|
|
|
|
|
2019-06-26 21:08:25 +08:00
|
|
|
void set_color_ramp(const Ref<Gradient> &p_ramp);
|
2018-07-07 07:21:13 +08:00
|
|
|
Ref<Gradient> get_color_ramp() const;
|
|
|
|
|
2021-11-23 20:50:35 +08:00
|
|
|
void set_color_initial_ramp(const Ref<Gradient> &p_ramp);
|
|
|
|
Ref<Gradient> get_color_initial_ramp() const;
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
void set_particle_flag(ParticleFlags p_particle_flag, bool p_enable);
|
|
|
|
bool get_particle_flag(ParticleFlags p_particle_flag) const;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
void set_emission_shape(EmissionShape p_shape);
|
2021-01-30 08:55:54 +08:00
|
|
|
void set_emission_sphere_radius(real_t p_radius);
|
2018-07-07 07:21:13 +08:00
|
|
|
void set_emission_box_extents(Vector3 p_extents);
|
2020-02-18 05:06:54 +08:00
|
|
|
void set_emission_points(const Vector<Vector3> &p_points);
|
|
|
|
void set_emission_normals(const Vector<Vector3> &p_normals);
|
|
|
|
void set_emission_colors(const Vector<Color> &p_colors);
|
2021-07-11 21:45:21 +08:00
|
|
|
void set_emission_ring_axis(Vector3 p_axis);
|
2021-01-30 08:55:54 +08:00
|
|
|
void set_emission_ring_height(real_t p_height);
|
|
|
|
void set_emission_ring_radius(real_t p_radius);
|
|
|
|
void set_emission_ring_inner_radius(real_t p_radius);
|
2021-07-14 01:46:27 +08:00
|
|
|
void set_scale_curve_x(Ref<Curve> p_scale_curve);
|
|
|
|
void set_scale_curve_y(Ref<Curve> p_scale_curve);
|
|
|
|
void set_scale_curve_z(Ref<Curve> p_scale_curve);
|
|
|
|
void set_split_scale(bool p_split_scale);
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
EmissionShape get_emission_shape() const;
|
2021-01-30 08:55:54 +08:00
|
|
|
real_t get_emission_sphere_radius() const;
|
2018-07-07 07:21:13 +08:00
|
|
|
Vector3 get_emission_box_extents() const;
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Vector3> get_emission_points() const;
|
|
|
|
Vector<Vector3> get_emission_normals() const;
|
|
|
|
Vector<Color> get_emission_colors() const;
|
2021-07-11 21:45:21 +08:00
|
|
|
Vector3 get_emission_ring_axis() const;
|
2021-01-30 08:55:54 +08:00
|
|
|
real_t get_emission_ring_height() const;
|
|
|
|
real_t get_emission_ring_radius() const;
|
|
|
|
real_t get_emission_ring_inner_radius() const;
|
2021-07-14 01:46:27 +08:00
|
|
|
Ref<Curve> get_scale_curve_x() const;
|
|
|
|
Ref<Curve> get_scale_curve_y() const;
|
|
|
|
Ref<Curve> get_scale_curve_z() const;
|
|
|
|
bool get_split_scale();
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
void set_gravity(const Vector3 &p_gravity);
|
|
|
|
Vector3 get_gravity() const;
|
|
|
|
|
2022-09-19 23:43:15 +08:00
|
|
|
PackedStringArray get_configuration_warnings() const override;
|
2018-07-07 07:21:13 +08:00
|
|
|
|
|
|
|
void restart();
|
|
|
|
|
2018-07-07 20:04:22 +08:00
|
|
|
void convert_from_particles(Node *p_particles);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
CPUParticles3D();
|
|
|
|
~CPUParticles3D();
|
2018-07-07 07:21:13 +08:00
|
|
|
};
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
VARIANT_ENUM_CAST(CPUParticles3D::DrawOrder)
|
|
|
|
VARIANT_ENUM_CAST(CPUParticles3D::Parameter)
|
2020-12-05 07:35:57 +08:00
|
|
|
VARIANT_ENUM_CAST(CPUParticles3D::ParticleFlags)
|
2020-03-27 05:49:16 +08:00
|
|
|
VARIANT_ENUM_CAST(CPUParticles3D::EmissionShape)
|
2018-07-07 07:21:13 +08:00
|
|
|
|
2022-07-24 05:41:51 +08:00
|
|
|
#endif // CPU_PARTICLES_3D_H
|