2018-08-29 22:38:13 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* cpu_particles_2d.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2018-08-29 22:38:13 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2018-08-29 21:48:32 +02:00
|
|
|
#ifndef CPU_PARTICLES_2D_H
|
|
|
|
#define CPU_PARTICLES_2D_H
|
2018-09-04 11:30:04 +02:00
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/rid.h"
|
2018-08-29 21:48:32 +02:00
|
|
|
#include "scene/2d/node_2d.h"
|
2018-09-04 11:30:04 +02:00
|
|
|
#include "scene/resources/texture.h"
|
2018-08-29 21:48:32 +02:00
|
|
|
|
|
|
|
class CPUParticles2D : public Node2D {
|
|
|
|
private:
|
|
|
|
GDCLASS(CPUParticles2D, Node2D);
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum DrawOrder {
|
|
|
|
DRAW_ORDER_INDEX,
|
|
|
|
DRAW_ORDER_LIFETIME,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Parameter {
|
|
|
|
|
|
|
|
PARAM_INITIAL_LINEAR_VELOCITY,
|
|
|
|
PARAM_ANGULAR_VELOCITY,
|
|
|
|
PARAM_ORBIT_VELOCITY,
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Flags {
|
|
|
|
FLAG_ALIGN_Y_TO_VELOCITY,
|
2019-06-11 17:47:24 +02:00
|
|
|
FLAG_ROTATE_Y, // Unused, but exposed for consistency with 3D.
|
|
|
|
FLAG_DISABLE_Z, // Unused, but exposed for consistency with 3D.
|
2018-08-29 21:48:32 +02:00
|
|
|
FLAG_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EmissionShape {
|
|
|
|
EMISSION_SHAPE_POINT,
|
2019-06-17 20:59:31 +02:00
|
|
|
EMISSION_SHAPE_SPHERE,
|
2018-08-29 21:48:32 +02:00
|
|
|
EMISSION_SHAPE_RECTANGLE,
|
|
|
|
EMISSION_SHAPE_POINTS,
|
|
|
|
EMISSION_SHAPE_DIRECTED_POINTS,
|
2020-01-16 10:59:01 +01:00
|
|
|
EMISSION_SHAPE_MAX
|
2018-08-29 21:48:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool emitting;
|
|
|
|
|
|
|
|
struct Particle {
|
|
|
|
Transform2D transform;
|
|
|
|
Color color;
|
|
|
|
float custom[4];
|
2018-09-27 13:05:57 +02:00
|
|
|
float rotation;
|
2018-08-29 21:48:32 +02:00
|
|
|
Vector2 velocity;
|
|
|
|
bool active;
|
|
|
|
float angle_rand;
|
|
|
|
float scale_rand;
|
|
|
|
float hue_rot_rand;
|
|
|
|
float anim_offset_rand;
|
|
|
|
float time;
|
2019-07-15 06:48:20 +02:00
|
|
|
float lifetime;
|
2018-08-29 21:48:32 +02:00
|
|
|
Color base_color;
|
|
|
|
|
|
|
|
uint32_t seed;
|
|
|
|
};
|
|
|
|
|
|
|
|
float time;
|
|
|
|
float inactive_time;
|
|
|
|
float frame_remainder;
|
|
|
|
int cycle;
|
2019-03-08 08:00:00 +01:00
|
|
|
bool redraw;
|
2018-08-29 21:48:32 +02:00
|
|
|
|
|
|
|
RID mesh;
|
|
|
|
RID multimesh;
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Particle> particles;
|
|
|
|
Vector<float> particle_data;
|
|
|
|
Vector<int> particle_order;
|
2018-08-29 21:48:32 +02:00
|
|
|
|
|
|
|
struct SortLifetime {
|
|
|
|
const Particle *particles;
|
|
|
|
|
|
|
|
bool operator()(int p_a, int p_b) const {
|
2019-06-06 21:49:48 +02:00
|
|
|
return particles[p_a].time > particles[p_b].time;
|
2018-08-29 21:48:32 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SortAxis {
|
|
|
|
const Particle *particles;
|
|
|
|
Vector2 axis;
|
|
|
|
bool operator()(int p_a, int p_b) const {
|
|
|
|
return axis.dot(particles[p_a].transform[2]) < axis.dot(particles[p_b].transform[2]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
bool one_shot;
|
|
|
|
|
|
|
|
float lifetime;
|
|
|
|
float pre_process_time;
|
|
|
|
float explosiveness_ratio;
|
|
|
|
float randomness_ratio;
|
2019-07-15 06:48:20 +02:00
|
|
|
float lifetime_randomness;
|
2018-08-29 21:48:32 +02:00
|
|
|
float speed_scale;
|
|
|
|
bool local_coords;
|
|
|
|
int fixed_fps;
|
|
|
|
bool fractional_delta;
|
|
|
|
|
2019-06-14 22:22:19 +02:00
|
|
|
Transform2D inv_emission_transform;
|
|
|
|
|
2018-08-29 21:48:32 +02:00
|
|
|
DrawOrder draw_order;
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> texture;
|
|
|
|
Ref<Texture2D> normalmap;
|
2018-08-29 21:48:32 +02:00
|
|
|
|
|
|
|
////////
|
|
|
|
|
2019-03-04 23:45:53 +01:00
|
|
|
Vector2 direction;
|
2018-08-29 21:48:32 +02:00
|
|
|
float spread;
|
|
|
|
|
|
|
|
float parameters[PARAM_MAX];
|
|
|
|
float randomness[PARAM_MAX];
|
|
|
|
|
|
|
|
Ref<Curve> curve_parameters[PARAM_MAX];
|
|
|
|
Color color;
|
|
|
|
Ref<Gradient> color_ramp;
|
|
|
|
|
|
|
|
bool flags[FLAG_MAX];
|
|
|
|
|
|
|
|
EmissionShape emission_shape;
|
|
|
|
float emission_sphere_radius;
|
|
|
|
Vector2 emission_rect_extents;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector2> emission_points;
|
|
|
|
Vector<Vector2> emission_normals;
|
|
|
|
Vector<Color> emission_colors;
|
2018-08-29 21:48:32 +02:00
|
|
|
int emission_point_count;
|
|
|
|
|
|
|
|
Vector2 gravity;
|
|
|
|
|
2019-10-19 17:30:13 +02:00
|
|
|
void _update_internal();
|
2018-08-29 21:48:32 +02:00
|
|
|
void _particles_process(float p_delta);
|
|
|
|
void _update_particle_data_buffer();
|
|
|
|
|
2020-02-26 11:28:13 +01:00
|
|
|
Mutex update_mutex;
|
2018-08-29 21:48:32 +02:00
|
|
|
|
|
|
|
void _update_render_thread();
|
|
|
|
|
2018-11-13 18:19:16 +01:00
|
|
|
void _update_mesh_texture();
|
2018-08-29 21:48:32 +02:00
|
|
|
|
2019-03-08 08:00:00 +01:00
|
|
|
void _set_redraw(bool p_redraw);
|
|
|
|
|
2019-10-02 17:49:52 +02:00
|
|
|
void _texture_changed();
|
|
|
|
|
2018-08-29 21:48:32 +02:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
|
|
|
virtual void _validate_property(PropertyInfo &property) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_emitting(bool p_emitting);
|
|
|
|
void set_amount(int p_amount);
|
|
|
|
void set_lifetime(float p_lifetime);
|
|
|
|
void set_one_shot(bool p_one_shot);
|
|
|
|
void set_pre_process_time(float p_time);
|
|
|
|
void set_explosiveness_ratio(float p_ratio);
|
|
|
|
void set_randomness_ratio(float p_ratio);
|
2019-07-15 06:48:20 +02:00
|
|
|
void set_lifetime_randomness(float p_random);
|
2018-08-29 21:48:32 +02:00
|
|
|
void set_visibility_aabb(const Rect2 &p_aabb);
|
|
|
|
void set_use_local_coordinates(bool p_enable);
|
|
|
|
void set_speed_scale(float p_scale);
|
|
|
|
|
|
|
|
bool is_emitting() const;
|
|
|
|
int get_amount() const;
|
|
|
|
float get_lifetime() const;
|
|
|
|
bool get_one_shot() const;
|
|
|
|
float get_pre_process_time() const;
|
|
|
|
float get_explosiveness_ratio() const;
|
|
|
|
float get_randomness_ratio() const;
|
2019-07-15 06:48:20 +02:00
|
|
|
float get_lifetime_randomness() const;
|
2018-08-29 21:48:32 +02:00
|
|
|
Rect2 get_visibility_aabb() const;
|
|
|
|
bool get_use_local_coordinates() const;
|
|
|
|
float get_speed_scale() const;
|
|
|
|
|
|
|
|
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_draw_passes(int p_count);
|
|
|
|
int get_draw_passes() const;
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
void set_texture(const Ref<Texture2D> &p_texture);
|
|
|
|
Ref<Texture2D> get_texture() const;
|
2018-08-29 21:48:32 +02:00
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
void set_normalmap(const Ref<Texture2D> &p_normalmap);
|
|
|
|
Ref<Texture2D> get_normalmap() const;
|
2018-08-29 21:48:32 +02:00
|
|
|
|
|
|
|
///////////////////
|
|
|
|
|
2019-03-04 23:45:53 +01:00
|
|
|
void set_direction(Vector2 p_direction);
|
|
|
|
Vector2 get_direction() const;
|
|
|
|
|
2018-08-29 21:48:32 +02:00
|
|
|
void set_spread(float p_spread);
|
|
|
|
float get_spread() const;
|
|
|
|
|
|
|
|
void set_param(Parameter p_param, float p_value);
|
|
|
|
float get_param(Parameter p_param) const;
|
|
|
|
|
|
|
|
void set_param_randomness(Parameter p_param, float p_value);
|
|
|
|
float get_param_randomness(Parameter p_param) const;
|
|
|
|
|
|
|
|
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 15:08:25 +02:00
|
|
|
void set_color_ramp(const Ref<Gradient> &p_ramp);
|
2018-08-29 21:48:32 +02:00
|
|
|
Ref<Gradient> get_color_ramp() const;
|
|
|
|
|
|
|
|
void set_particle_flag(Flags p_flag, bool p_enable);
|
|
|
|
bool get_particle_flag(Flags p_flag) const;
|
|
|
|
|
|
|
|
void set_emission_shape(EmissionShape p_shape);
|
|
|
|
void set_emission_sphere_radius(float p_radius);
|
|
|
|
void set_emission_rect_extents(Vector2 p_extents);
|
2020-02-17 22:06:54 +01:00
|
|
|
void set_emission_points(const Vector<Vector2> &p_points);
|
|
|
|
void set_emission_normals(const Vector<Vector2> &p_normals);
|
|
|
|
void set_emission_colors(const Vector<Color> &p_colors);
|
2018-08-29 21:48:32 +02:00
|
|
|
void set_emission_point_count(int p_count);
|
|
|
|
|
|
|
|
EmissionShape get_emission_shape() const;
|
|
|
|
float get_emission_sphere_radius() const;
|
|
|
|
Vector2 get_emission_rect_extents() const;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector2> get_emission_points() const;
|
|
|
|
Vector<Vector2> get_emission_normals() const;
|
|
|
|
Vector<Color> get_emission_colors() const;
|
2018-08-29 21:48:32 +02:00
|
|
|
int get_emission_point_count() const;
|
|
|
|
|
|
|
|
void set_gravity(const Vector2 &p_gravity);
|
|
|
|
Vector2 get_gravity() const;
|
|
|
|
|
|
|
|
virtual String get_configuration_warning() const;
|
|
|
|
|
|
|
|
void restart();
|
|
|
|
|
|
|
|
void convert_from_particles(Node *p_particles);
|
|
|
|
|
|
|
|
CPUParticles2D();
|
|
|
|
~CPUParticles2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(CPUParticles2D::DrawOrder)
|
|
|
|
VARIANT_ENUM_CAST(CPUParticles2D::Parameter)
|
|
|
|
VARIANT_ENUM_CAST(CPUParticles2D::Flags)
|
|
|
|
VARIANT_ENUM_CAST(CPUParticles2D::EmissionShape)
|
|
|
|
|
|
|
|
#endif // CPU_PARTICLES_2D_H
|