2018-08-30 04:38:13 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* cpu_particles_2d.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-01-02 03:13:46 +08:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2018-08-30 04:38:13 +08: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-30 03:48:32 +08:00
|
|
|
#include "cpu_particles_2d.h"
|
2020-02-22 06:26:13 +08:00
|
|
|
|
2019-10-02 23:49:52 +08:00
|
|
|
#include "core/core_string_names.h"
|
2020-03-27 15:44:44 +08:00
|
|
|
#include "scene/2d/gpu_particles_2d.h"
|
|
|
|
#include "scene/main/canvas_item.h"
|
2018-09-27 19:05:57 +08:00
|
|
|
#include "scene/resources/particles_material.h"
|
2020-03-28 02:21:27 +08:00
|
|
|
#include "servers/rendering_server.h"
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
void CPUParticles2D::set_emitting(bool p_emitting) {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (emitting == p_emitting) {
|
2019-10-19 23:30:13 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2019-10-19 23:30:13 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
emitting = p_emitting;
|
2020-05-14 22:41:43 +08:00
|
|
|
if (emitting) {
|
2019-03-20 17:50:56 +08:00
|
|
|
set_process_internal(true);
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_amount(int p_amount) {
|
2019-09-25 16:28:50 +08:00
|
|
|
ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0.");
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
particles.resize(p_amount);
|
|
|
|
{
|
2020-02-18 05:06:54 +08:00
|
|
|
Particle *w = particles.ptrw();
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < p_amount; i++) {
|
|
|
|
w[i].active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 22:35:10 +08:00
|
|
|
particle_data.resize((8 + 4 + 4) * p_amount);
|
2021-02-10 00:19:03 +08:00
|
|
|
RS::get_singleton()->multimesh_allocate_data(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_2D, true, true);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
particle_order.resize(p_amount);
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
void CPUParticles2D::set_lifetime(float p_lifetime) {
|
2019-09-25 16:28:50 +08:00
|
|
|
ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0.");
|
2018-08-30 03:48:32 +08:00
|
|
|
lifetime = p_lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_one_shot(bool p_one_shot) {
|
|
|
|
one_shot = p_one_shot;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_pre_process_time(float p_time) {
|
|
|
|
pre_process_time = p_time;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
void CPUParticles2D::set_explosiveness_ratio(real_t p_ratio) {
|
2018-08-30 03:48:32 +08:00
|
|
|
explosiveness_ratio = p_ratio;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
void CPUParticles2D::set_randomness_ratio(real_t p_ratio) {
|
2018-08-30 03:48:32 +08:00
|
|
|
randomness_ratio = p_ratio;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2019-07-15 12:48:20 +08:00
|
|
|
void CPUParticles2D::set_lifetime_randomness(float p_random) {
|
|
|
|
lifetime_randomness = p_random;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
void CPUParticles2D::set_use_local_coordinates(bool p_enable) {
|
|
|
|
local_coords = p_enable;
|
2019-06-15 04:22:19 +08:00
|
|
|
set_notify_transform(!p_enable);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
2019-06-15 04:22:19 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
void CPUParticles2D::set_speed_scale(real_t p_scale) {
|
2018-08-30 03:48:32 +08:00
|
|
|
speed_scale = p_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPUParticles2D::is_emitting() const {
|
|
|
|
return emitting;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
int CPUParticles2D::get_amount() const {
|
|
|
|
return particles.size();
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
float CPUParticles2D::get_lifetime() const {
|
|
|
|
return lifetime;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
bool CPUParticles2D::get_one_shot() const {
|
|
|
|
return one_shot;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CPUParticles2D::get_pre_process_time() const {
|
|
|
|
return pre_process_time;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t CPUParticles2D::get_explosiveness_ratio() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return explosiveness_ratio;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t CPUParticles2D::get_randomness_ratio() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return randomness_ratio;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2019-07-15 12:48:20 +08:00
|
|
|
float CPUParticles2D::get_lifetime_randomness() const {
|
|
|
|
return lifetime_randomness;
|
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
bool CPUParticles2D::get_use_local_coordinates() const {
|
|
|
|
return local_coords;
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t CPUParticles2D::get_speed_scale() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return speed_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_draw_order(DrawOrder p_order) {
|
|
|
|
draw_order = p_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPUParticles2D::DrawOrder CPUParticles2D::get_draw_order() const {
|
|
|
|
return draw_order;
|
|
|
|
}
|
|
|
|
|
2018-11-14 01:19:16 +08:00
|
|
|
void CPUParticles2D::_update_mesh_texture() {
|
|
|
|
Size2 tex_size;
|
|
|
|
if (texture.is_valid()) {
|
|
|
|
tex_size = texture->get_size();
|
|
|
|
} else {
|
|
|
|
tex_size = Size2(1, 1);
|
|
|
|
}
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Vector2> vertices;
|
2018-11-14 01:19:16 +08:00
|
|
|
vertices.push_back(-tex_size * 0.5);
|
|
|
|
vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, 0));
|
|
|
|
vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, tex_size.y));
|
|
|
|
vertices.push_back(-tex_size * 0.5 + Vector2(0, tex_size.y));
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Vector2> uvs;
|
2019-10-02 23:49:52 +08:00
|
|
|
AtlasTexture *atlas_texure = Object::cast_to<AtlasTexture>(*texture);
|
|
|
|
if (atlas_texure && atlas_texure->get_atlas().is_valid()) {
|
|
|
|
Rect2 region_rect = atlas_texure->get_region();
|
|
|
|
Size2 atlas_size = atlas_texure->get_atlas()->get_size();
|
|
|
|
uvs.push_back(Vector2(region_rect.position.x / atlas_size.x, region_rect.position.y / atlas_size.y));
|
|
|
|
uvs.push_back(Vector2((region_rect.position.x + region_rect.size.x) / atlas_size.x, region_rect.position.y / atlas_size.y));
|
|
|
|
uvs.push_back(Vector2((region_rect.position.x + region_rect.size.x) / atlas_size.x, (region_rect.position.y + region_rect.size.y) / atlas_size.y));
|
|
|
|
uvs.push_back(Vector2(region_rect.position.x / atlas_size.x, (region_rect.position.y + region_rect.size.y) / atlas_size.y));
|
|
|
|
} else {
|
|
|
|
uvs.push_back(Vector2(0, 0));
|
|
|
|
uvs.push_back(Vector2(1, 0));
|
|
|
|
uvs.push_back(Vector2(1, 1));
|
|
|
|
uvs.push_back(Vector2(0, 1));
|
|
|
|
}
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Color> colors;
|
2018-08-30 03:48:32 +08:00
|
|
|
colors.push_back(Color(1, 1, 1, 1));
|
|
|
|
colors.push_back(Color(1, 1, 1, 1));
|
|
|
|
colors.push_back(Color(1, 1, 1, 1));
|
|
|
|
colors.push_back(Color(1, 1, 1, 1));
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<int> indices;
|
2018-08-30 03:48:32 +08:00
|
|
|
indices.push_back(0);
|
|
|
|
indices.push_back(1);
|
|
|
|
indices.push_back(2);
|
|
|
|
indices.push_back(2);
|
|
|
|
indices.push_back(3);
|
|
|
|
indices.push_back(0);
|
|
|
|
|
|
|
|
Array arr;
|
2020-03-28 02:21:27 +08:00
|
|
|
arr.resize(RS::ARRAY_MAX);
|
|
|
|
arr[RS::ARRAY_VERTEX] = vertices;
|
|
|
|
arr[RS::ARRAY_TEX_UV] = uvs;
|
|
|
|
arr[RS::ARRAY_COLOR] = colors;
|
|
|
|
arr[RS::ARRAY_INDEX] = indices;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->mesh_clear(mesh);
|
|
|
|
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:43:37 +08:00
|
|
|
void CPUParticles2D::set_texture(const Ref<Texture2D> &p_texture) {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (p_texture == texture) {
|
2019-10-02 23:49:52 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2019-10-02 23:49:52 +08:00
|
|
|
|
2020-05-14 22:41:43 +08:00
|
|
|
if (texture.is_valid()) {
|
2020-02-22 06:26:13 +08:00
|
|
|
texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed));
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
texture = p_texture;
|
2019-10-02 23:49:52 +08:00
|
|
|
|
2020-05-14 22:41:43 +08:00
|
|
|
if (texture.is_valid()) {
|
2020-02-22 06:26:13 +08:00
|
|
|
texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed));
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2019-10-02 23:49:52 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
update();
|
2018-11-14 01:19:16 +08:00
|
|
|
_update_mesh_texture();
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2019-10-02 23:49:52 +08:00
|
|
|
void CPUParticles2D::_texture_changed() {
|
|
|
|
if (texture.is_valid()) {
|
|
|
|
update();
|
|
|
|
_update_mesh_texture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 02:43:37 +08:00
|
|
|
Ref<Texture2D> CPUParticles2D::get_texture() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_fixed_fps(int p_count) {
|
|
|
|
fixed_fps = p_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPUParticles2D::get_fixed_fps() const {
|
|
|
|
return fixed_fps;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_fractional_delta(bool p_enable) {
|
|
|
|
fractional_delta = p_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPUParticles2D::get_fractional_delta() const {
|
|
|
|
return fractional_delta;
|
|
|
|
}
|
|
|
|
|
2020-10-29 18:01:28 +08:00
|
|
|
TypedArray<String> CPUParticles2D::get_configuration_warnings() const {
|
|
|
|
TypedArray<String> warnings = Node::get_configuration_warnings();
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2018-09-27 19:05:57 +08:00
|
|
|
CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr());
|
|
|
|
|
|
|
|
if (get_material().is_null() || (mat && !mat->get_particles_animation())) {
|
2018-11-14 01:19:16 +08:00
|
|
|
if (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 ||
|
|
|
|
get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) {
|
2020-10-29 18:01:28 +08:00
|
|
|
warnings.push_back(TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."));
|
2018-11-14 01:19:16 +08:00
|
|
|
}
|
2018-09-27 19:05:57 +08:00
|
|
|
}
|
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
return warnings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::restart() {
|
|
|
|
time = 0;
|
|
|
|
inactive_time = 0;
|
|
|
|
frame_remainder = 0;
|
|
|
|
cycle = 0;
|
2019-10-25 03:38:01 +08:00
|
|
|
emitting = false;
|
2019-06-22 13:33:11 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
{
|
|
|
|
int pc = particles.size();
|
2020-02-18 05:06:54 +08:00
|
|
|
Particle *w = particles.ptrw();
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < pc; i++) {
|
|
|
|
w[i].active = false;
|
|
|
|
}
|
|
|
|
}
|
2019-10-25 03:38:01 +08:00
|
|
|
|
|
|
|
set_emitting(true);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2019-03-05 06:45:53 +08:00
|
|
|
void CPUParticles2D::set_direction(Vector2 p_direction) {
|
|
|
|
direction = p_direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 CPUParticles2D::get_direction() const {
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
void CPUParticles2D::set_spread(real_t p_spread) {
|
2018-08-30 03:48:32 +08:00
|
|
|
spread = p_spread;
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t CPUParticles2D::get_spread() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return spread;
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
void CPUParticles2D::set_param(Parameter p_param, real_t p_value) {
|
2018-08-30 03:48:32 +08:00
|
|
|
ERR_FAIL_INDEX(p_param, PARAM_MAX);
|
|
|
|
|
|
|
|
parameters[p_param] = p_value;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t CPUParticles2D::get_param(Parameter p_param) const {
|
2018-08-30 03:48:32 +08:00
|
|
|
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
|
|
|
|
|
|
|
|
return parameters[p_param];
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
void CPUParticles2D::set_param_randomness(Parameter p_param, real_t p_value) {
|
2018-08-30 03:48:32 +08:00
|
|
|
ERR_FAIL_INDEX(p_param, PARAM_MAX);
|
|
|
|
|
|
|
|
randomness[p_param] = p_value;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t CPUParticles2D::get_param_randomness(Parameter p_param) const {
|
2018-08-30 03:48:32 +08:00
|
|
|
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
|
|
|
|
|
|
|
|
return randomness[p_param];
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
static void _adjust_curve_range(const Ref<Curve> &p_curve, real_t p_min, real_t p_max) {
|
2018-08-30 03:48:32 +08:00
|
|
|
Ref<Curve> curve = p_curve;
|
2020-05-14 22:41:43 +08:00
|
|
|
if (!curve.is_valid()) {
|
2018-08-30 03:48:32 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
curve->ensure_default_setup(p_min, p_max);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) {
|
|
|
|
ERR_FAIL_INDEX(p_param, PARAM_MAX);
|
|
|
|
|
|
|
|
curve_parameters[p_param] = p_curve;
|
|
|
|
|
|
|
|
switch (p_param) {
|
|
|
|
case PARAM_INITIAL_LINEAR_VELOCITY: {
|
|
|
|
//do none for this one
|
|
|
|
} break;
|
|
|
|
case PARAM_ANGULAR_VELOCITY: {
|
|
|
|
_adjust_curve_range(p_curve, -360, 360);
|
|
|
|
} break;
|
2019-06-11 23:47:24 +08:00
|
|
|
case PARAM_ORBIT_VELOCITY: {
|
2018-08-30 03:48:32 +08:00
|
|
|
_adjust_curve_range(p_curve, -500, 500);
|
2019-06-11 23:47:24 +08:00
|
|
|
} break;
|
2018-08-30 03:48:32 +08:00
|
|
|
case PARAM_LINEAR_ACCEL: {
|
|
|
|
_adjust_curve_range(p_curve, -200, 200);
|
|
|
|
} break;
|
|
|
|
case PARAM_RADIAL_ACCEL: {
|
|
|
|
_adjust_curve_range(p_curve, -200, 200);
|
|
|
|
} break;
|
|
|
|
case PARAM_TANGENTIAL_ACCEL: {
|
|
|
|
_adjust_curve_range(p_curve, -200, 200);
|
|
|
|
} break;
|
|
|
|
case PARAM_DAMPING: {
|
|
|
|
_adjust_curve_range(p_curve, 0, 100);
|
|
|
|
} break;
|
|
|
|
case PARAM_ANGLE: {
|
|
|
|
_adjust_curve_range(p_curve, -360, 360);
|
|
|
|
} break;
|
|
|
|
case PARAM_SCALE: {
|
|
|
|
} break;
|
|
|
|
case PARAM_HUE_VARIATION: {
|
|
|
|
_adjust_curve_range(p_curve, -1, 1);
|
|
|
|
} break;
|
|
|
|
case PARAM_ANIM_SPEED: {
|
|
|
|
_adjust_curve_range(p_curve, 0, 200);
|
|
|
|
} break;
|
|
|
|
case PARAM_ANIM_OFFSET: {
|
|
|
|
} break;
|
2019-03-08 15:00:00 +08:00
|
|
|
default: {
|
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
Ref<Curve> CPUParticles2D::get_param_curve(Parameter p_param) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Curve>());
|
|
|
|
|
|
|
|
return curve_parameters[p_param];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_color(const Color &p_color) {
|
|
|
|
color = p_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color CPUParticles2D::get_color() const {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_color_ramp(const Ref<Gradient> &p_ramp) {
|
|
|
|
color_ramp = p_ramp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Gradient> CPUParticles2D::get_color_ramp() const {
|
|
|
|
return color_ramp;
|
|
|
|
}
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
void CPUParticles2D::set_particle_flag(ParticleFlags p_particle_flag, bool p_enable) {
|
|
|
|
ERR_FAIL_INDEX(p_particle_flag, PARTICLE_FLAG_MAX);
|
|
|
|
particle_flags[p_particle_flag] = p_enable;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
bool CPUParticles2D::get_particle_flag(ParticleFlags p_particle_flag) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_particle_flag, PARTICLE_FLAG_MAX, false);
|
|
|
|
return particle_flags[p_particle_flag];
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_emission_shape(EmissionShape p_shape) {
|
2020-01-16 17:59:01 +08:00
|
|
|
ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX);
|
2018-08-30 03:48:32 +08:00
|
|
|
emission_shape = p_shape;
|
2021-02-11 04:18:45 +08:00
|
|
|
notify_property_list_changed();
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
void CPUParticles2D::set_emission_sphere_radius(real_t p_radius) {
|
2018-08-30 03:48:32 +08:00
|
|
|
emission_sphere_radius = p_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::set_emission_rect_extents(Vector2 p_extents) {
|
|
|
|
emission_rect_extents = p_extents;
|
|
|
|
}
|
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
void CPUParticles2D::set_emission_points(const Vector<Vector2> &p_points) {
|
2018-08-30 03:48:32 +08:00
|
|
|
emission_points = p_points;
|
|
|
|
}
|
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
void CPUParticles2D::set_emission_normals(const Vector<Vector2> &p_normals) {
|
2018-08-30 03:48:32 +08:00
|
|
|
emission_normals = p_normals;
|
|
|
|
}
|
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
void CPUParticles2D::set_emission_colors(const Vector<Color> &p_colors) {
|
2018-08-30 03:48:32 +08:00
|
|
|
emission_colors = p_colors;
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t CPUParticles2D::get_emission_sphere_radius() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return emission_sphere_radius;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
Vector2 CPUParticles2D::get_emission_rect_extents() const {
|
|
|
|
return emission_rect_extents;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Vector2> CPUParticles2D::get_emission_points() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return emission_points;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Vector2> CPUParticles2D::get_emission_normals() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return emission_normals;
|
|
|
|
}
|
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
Vector<Color> CPUParticles2D::get_emission_colors() const {
|
2018-08-30 03:48:32 +08:00
|
|
|
return emission_colors;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPUParticles2D::EmissionShape CPUParticles2D::get_emission_shape() const {
|
|
|
|
return emission_shape;
|
|
|
|
}
|
2020-05-14 20:29:06 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
void CPUParticles2D::set_gravity(const Vector2 &p_gravity) {
|
|
|
|
gravity = p_gravity;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 CPUParticles2D::get_gravity() const {
|
|
|
|
return gravity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::_validate_property(PropertyInfo &property) const {
|
2019-06-18 02:59:31 +08:00
|
|
|
if (property.name == "emission_sphere_radius" && emission_shape != EMISSION_SHAPE_SPHERE) {
|
2021-07-01 09:24:34 +08:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property.name == "emission_rect_extents" && emission_shape != EMISSION_SHAPE_RECTANGLE) {
|
2021-07-01 09:24:34 +08:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((property.name == "emission_point_texture" || property.name == "emission_color_texture") && (emission_shape < EMISSION_SHAPE_POINTS)) {
|
2021-07-01 09:24:34 +08:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property.name == "emission_normals" && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) {
|
2021-07-01 09:24:34 +08:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
2018-09-27 19:05:57 +08:00
|
|
|
|
|
|
|
if (property.name == "emission_points" && emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) {
|
2021-07-01 09:24:34 +08:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2018-09-27 19:05:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (property.name == "emission_colors" && emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) {
|
2021-07-01 09:24:34 +08:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2018-09-27 19:05:57 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t idhash(uint32_t x) {
|
|
|
|
x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b);
|
|
|
|
x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b);
|
|
|
|
x = (x >> uint32_t(16)) ^ x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
static real_t rand_from_seed(uint32_t &seed) {
|
2018-08-30 03:48:32 +08:00
|
|
|
int k;
|
|
|
|
int s = int(seed);
|
2020-05-14 22:41:43 +08:00
|
|
|
if (s == 0) {
|
2018-08-30 03:48:32 +08:00
|
|
|
s = 305420679;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
k = s / 127773;
|
|
|
|
s = 16807 * (s - k * 127773) - 2836 * k;
|
2020-05-14 22:41:43 +08:00
|
|
|
if (s < 0) {
|
2018-08-30 03:48:32 +08:00
|
|
|
s += 2147483647;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
seed = uint32_t(s);
|
2021-01-30 12:10:32 +08:00
|
|
|
return (seed % uint32_t(65536)) / 65535.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2019-10-19 23:30:13 +08:00
|
|
|
void CPUParticles2D::_update_internal() {
|
|
|
|
if (particles.size() == 0 || !is_visible_in_tree()) {
|
|
|
|
_set_redraw(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float delta = get_process_delta_time();
|
|
|
|
if (emitting) {
|
|
|
|
inactive_time = 0;
|
|
|
|
} else {
|
|
|
|
inactive_time += delta;
|
|
|
|
if (inactive_time > lifetime * 1.2) {
|
|
|
|
set_process_internal(false);
|
|
|
|
_set_redraw(false);
|
|
|
|
|
|
|
|
//reset variables
|
|
|
|
time = 0;
|
|
|
|
inactive_time = 0;
|
|
|
|
frame_remainder = 0;
|
|
|
|
cycle = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_set_redraw(true);
|
|
|
|
|
|
|
|
if (time == 0 && pre_process_time > 0.0) {
|
|
|
|
float frame_time;
|
2020-05-14 22:41:43 +08:00
|
|
|
if (fixed_fps > 0) {
|
2019-10-19 23:30:13 +08:00
|
|
|
frame_time = 1.0 / fixed_fps;
|
2020-05-14 22:41:43 +08:00
|
|
|
} else {
|
2019-10-19 23:30:13 +08:00
|
|
|
frame_time = 1.0 / 30.0;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2019-10-19 23:30:13 +08:00
|
|
|
|
|
|
|
float todo = pre_process_time;
|
|
|
|
|
|
|
|
while (todo >= 0) {
|
|
|
|
_particles_process(frame_time);
|
|
|
|
todo -= frame_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fixed_fps > 0) {
|
|
|
|
float frame_time = 1.0 / fixed_fps;
|
|
|
|
float decr = frame_time;
|
|
|
|
|
|
|
|
float ldelta = delta;
|
|
|
|
if (ldelta > 0.1) { //avoid recursive stalls if fps goes below 10
|
|
|
|
ldelta = 0.1;
|
|
|
|
} else if (ldelta <= 0.0) { //unlikely but..
|
|
|
|
ldelta = 0.001;
|
|
|
|
}
|
|
|
|
float todo = frame_remainder + ldelta;
|
|
|
|
|
|
|
|
while (todo >= frame_time) {
|
|
|
|
_particles_process(frame_time);
|
|
|
|
todo -= decr;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_remainder = todo;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
_particles_process(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
_update_particle_data_buffer();
|
|
|
|
}
|
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
void CPUParticles2D::_particles_process(float p_delta) {
|
|
|
|
p_delta *= speed_scale;
|
|
|
|
|
|
|
|
int pcount = particles.size();
|
2020-02-18 05:06:54 +08:00
|
|
|
Particle *w = particles.ptrw();
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-18 05:06:54 +08:00
|
|
|
Particle *parray = w;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
float prev_time = time;
|
|
|
|
time += p_delta;
|
|
|
|
if (time > lifetime) {
|
|
|
|
time = Math::fmod(time, lifetime);
|
|
|
|
cycle++;
|
|
|
|
if (one_shot && cycle > 0) {
|
2019-06-21 02:20:27 +08:00
|
|
|
set_emitting(false);
|
2021-02-11 04:18:45 +08:00
|
|
|
notify_property_list_changed();
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform2D emission_xform;
|
|
|
|
Transform2D velocity_xform;
|
|
|
|
if (!local_coords) {
|
|
|
|
emission_xform = get_global_transform();
|
|
|
|
velocity_xform = emission_xform;
|
2018-09-27 19:05:57 +08:00
|
|
|
velocity_xform[2] = Vector2();
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 05:38:10 +08:00
|
|
|
float system_phase = time / lifetime;
|
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
for (int i = 0; i < pcount; i++) {
|
|
|
|
Particle &p = parray[i];
|
|
|
|
|
2020-05-14 22:41:43 +08:00
|
|
|
if (!emitting && !p.active) {
|
2018-08-30 03:48:32 +08:00
|
|
|
continue;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
float local_delta = p_delta;
|
|
|
|
|
2019-06-12 05:38:10 +08:00
|
|
|
// The phase is a ratio between 0 (birth) and 1 (end of life) for each particle.
|
|
|
|
// While we use time in tests later on, for randomness we use the phase as done in the
|
|
|
|
// original shader code, and we later multiply by lifetime to get the time.
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t restart_phase = real_t(i) / real_t(pcount);
|
2019-06-12 05:38:10 +08:00
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
if (randomness_ratio > 0.0) {
|
|
|
|
uint32_t seed = cycle;
|
2019-06-12 05:38:10 +08:00
|
|
|
if (restart_phase >= system_phase) {
|
2018-08-30 03:48:32 +08:00
|
|
|
seed -= uint32_t(1);
|
|
|
|
}
|
|
|
|
seed *= uint32_t(pcount);
|
|
|
|
seed += uint32_t(i);
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t random = (idhash(seed) % uint32_t(65536)) / 65536.0;
|
|
|
|
restart_phase += randomness_ratio * random * 1.0 / pcount;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2019-06-12 05:38:10 +08:00
|
|
|
restart_phase *= (1.0 - explosiveness_ratio);
|
|
|
|
float restart_time = restart_phase * lifetime;
|
2018-08-30 03:48:32 +08:00
|
|
|
bool restart = false;
|
|
|
|
|
|
|
|
if (time > prev_time) {
|
|
|
|
// restart_time >= prev_time is used so particles emit in the first frame they are processed
|
|
|
|
|
|
|
|
if (restart_time >= prev_time && restart_time < time) {
|
|
|
|
restart = true;
|
|
|
|
if (fractional_delta) {
|
2019-03-10 07:33:08 +08:00
|
|
|
local_delta = time - restart_time;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (local_delta > 0.0) {
|
|
|
|
if (restart_time >= prev_time) {
|
|
|
|
restart = true;
|
|
|
|
if (fractional_delta) {
|
2019-03-10 07:33:08 +08:00
|
|
|
local_delta = lifetime - restart_time + time;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (restart_time < time) {
|
|
|
|
restart = true;
|
|
|
|
if (fractional_delta) {
|
2019-03-10 07:33:08 +08:00
|
|
|
local_delta = time - restart_time;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 12:48:20 +08:00
|
|
|
if (p.time * (1.0 - explosiveness_ratio) > p.lifetime) {
|
|
|
|
restart = true;
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:18:07 +08:00
|
|
|
float tv = 0.0;
|
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
if (restart) {
|
|
|
|
if (!emitting) {
|
|
|
|
p.active = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
p.active = true;
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
/*real_t tex_linear_velocity = 0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
|
|
|
|
tex_linear_velocity = curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY]->interpolate(0);
|
|
|
|
}*/
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_angle = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_ANGLE].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_angle = curve_parameters[PARAM_ANGLE]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_anim_offset = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_ANGLE].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_anim_offset = curve_parameters[PARAM_ANGLE]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
p.seed = Math::rand();
|
|
|
|
|
|
|
|
p.angle_rand = Math::randf();
|
|
|
|
p.scale_rand = Math::randf();
|
|
|
|
p.hue_rot_rand = Math::randf();
|
|
|
|
p.anim_offset_rand = Math::randf();
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t angle1_rad = Math::atan2(direction.y, direction.x) + Math::deg2rad((Math::randf() * 2.0 - 1.0) * spread);
|
2018-08-30 03:48:32 +08:00
|
|
|
Vector2 rot = Vector2(Math::cos(angle1_rad), Math::sin(angle1_rad));
|
2021-01-30 12:10:32 +08:00
|
|
|
p.velocity = rot * parameters[PARAM_INITIAL_LINEAR_VELOCITY] * Math::lerp((real_t)1.0, real_t(Math::randf()), randomness[PARAM_INITIAL_LINEAR_VELOCITY]);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t base_angle = (parameters[PARAM_ANGLE] + tex_angle) * Math::lerp((real_t)1.0, p.angle_rand, randomness[PARAM_ANGLE]);
|
2018-09-27 19:05:57 +08:00
|
|
|
p.rotation = Math::deg2rad(base_angle);
|
|
|
|
|
|
|
|
p.custom[0] = 0.0; // unused
|
|
|
|
p.custom[1] = 0.0; // phase [0..1]
|
2021-01-30 12:10:32 +08:00
|
|
|
p.custom[2] = (parameters[PARAM_ANIM_OFFSET] + tex_anim_offset) * Math::lerp((real_t)1.0, p.anim_offset_rand, randomness[PARAM_ANIM_OFFSET]); //animation phase [0..1]
|
2018-09-27 19:05:57 +08:00
|
|
|
p.custom[3] = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
p.transform = Transform2D();
|
|
|
|
p.time = 0;
|
2019-07-15 12:48:20 +08:00
|
|
|
p.lifetime = lifetime * (1.0 - Math::randf() * lifetime_randomness);
|
2018-08-30 03:48:32 +08:00
|
|
|
p.base_color = Color(1, 1, 1, 1);
|
|
|
|
|
|
|
|
switch (emission_shape) {
|
|
|
|
case EMISSION_SHAPE_POINT: {
|
|
|
|
//do none
|
|
|
|
} break;
|
2019-06-18 02:59:31 +08:00
|
|
|
case EMISSION_SHAPE_SPHERE: {
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t s = Math::randf(), t = Math_TAU * Math::randf();
|
|
|
|
real_t radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
|
2019-07-06 06:13:03 +08:00
|
|
|
p.transform[2] = Vector2(Math::cos(t), Math::sin(t)) * radius;
|
2018-08-30 03:48:32 +08:00
|
|
|
} break;
|
|
|
|
case EMISSION_SHAPE_RECTANGLE: {
|
|
|
|
p.transform[2] = Vector2(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_rect_extents;
|
|
|
|
} break;
|
|
|
|
case EMISSION_SHAPE_POINTS:
|
|
|
|
case EMISSION_SHAPE_DIRECTED_POINTS: {
|
|
|
|
int pc = emission_points.size();
|
2020-05-14 22:41:43 +08:00
|
|
|
if (pc == 0) {
|
2018-08-30 03:48:32 +08:00
|
|
|
break;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
int random_idx = Math::rand() % pc;
|
|
|
|
|
|
|
|
p.transform[2] = emission_points.get(random_idx);
|
|
|
|
|
|
|
|
if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS && emission_normals.size() == pc) {
|
2020-08-10 00:16:53 +08:00
|
|
|
Vector2 normal = emission_normals.get(random_idx);
|
|
|
|
Transform2D m2;
|
|
|
|
m2.set_axis(0, normal);
|
2020-12-07 02:16:06 +08:00
|
|
|
m2.set_axis(1, normal.orthogonal());
|
2020-08-10 00:16:53 +08:00
|
|
|
p.velocity = m2.basis_xform(p.velocity);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (emission_colors.size() == pc) {
|
|
|
|
p.base_color = emission_colors.get(random_idx);
|
|
|
|
}
|
|
|
|
} break;
|
2020-01-16 17:59:01 +08:00
|
|
|
case EMISSION_SHAPE_MAX: { // Max value for validity check.
|
|
|
|
break;
|
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!local_coords) {
|
|
|
|
p.velocity = velocity_xform.xform(p.velocity);
|
|
|
|
p.transform = emission_xform * p.transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!p.active) {
|
|
|
|
continue;
|
2019-07-15 12:48:20 +08:00
|
|
|
} else if (p.time > p.lifetime) {
|
|
|
|
p.active = false;
|
2021-01-27 19:18:07 +08:00
|
|
|
tv = 1.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
} else {
|
|
|
|
uint32_t alt_seed = p.seed;
|
|
|
|
|
|
|
|
p.time += local_delta;
|
|
|
|
p.custom[1] = p.time / lifetime;
|
2021-01-27 19:18:07 +08:00
|
|
|
tv = p.time / p.lifetime;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_linear_velocity = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_linear_velocity = curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_orbit_velocity = 0.0;
|
2019-06-11 23:47:24 +08:00
|
|
|
if (curve_parameters[PARAM_ORBIT_VELOCITY].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_orbit_velocity = curve_parameters[PARAM_ORBIT_VELOCITY]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
2019-06-11 23:47:24 +08:00
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_angular_velocity = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_angular_velocity = curve_parameters[PARAM_ANGULAR_VELOCITY]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_linear_accel = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_LINEAR_ACCEL].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_linear_accel = curve_parameters[PARAM_LINEAR_ACCEL]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_tangential_accel = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_tangential_accel = curve_parameters[PARAM_TANGENTIAL_ACCEL]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_radial_accel = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_RADIAL_ACCEL].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_radial_accel = curve_parameters[PARAM_RADIAL_ACCEL]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_damping = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_DAMPING].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_damping = curve_parameters[PARAM_DAMPING]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_angle = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_ANGLE].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_angle = curve_parameters[PARAM_ANGLE]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_anim_speed = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_ANIM_SPEED].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_anim_speed = curve_parameters[PARAM_ANIM_SPEED]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_anim_offset = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_ANIM_OFFSET].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_anim_offset = curve_parameters[PARAM_ANIM_OFFSET]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 force = gravity;
|
|
|
|
Vector2 pos = p.transform[2];
|
|
|
|
|
|
|
|
//apply linear acceleration
|
2021-01-30 12:10:32 +08:00
|
|
|
force += p.velocity.length() > 0.0 ? p.velocity.normalized() * (parameters[PARAM_LINEAR_ACCEL] + tex_linear_accel) * Math::lerp((real_t)1.0, rand_from_seed(alt_seed), randomness[PARAM_LINEAR_ACCEL]) : Vector2();
|
2018-08-30 03:48:32 +08:00
|
|
|
//apply radial acceleration
|
|
|
|
Vector2 org = emission_xform[2];
|
|
|
|
Vector2 diff = pos - org;
|
2021-01-30 12:10:32 +08:00
|
|
|
force += diff.length() > 0.0 ? diff.normalized() * (parameters[PARAM_RADIAL_ACCEL] + tex_radial_accel) * Math::lerp((real_t)1.0, rand_from_seed(alt_seed), randomness[PARAM_RADIAL_ACCEL]) : Vector2();
|
2018-08-30 03:48:32 +08:00
|
|
|
//apply tangential acceleration;
|
|
|
|
Vector2 yx = Vector2(diff.y, diff.x);
|
2021-01-30 12:10:32 +08:00
|
|
|
force += yx.length() > 0.0 ? (yx * Vector2(-1.0, 1.0)).normalized() * ((parameters[PARAM_TANGENTIAL_ACCEL] + tex_tangential_accel) * Math::lerp((real_t)1.0, rand_from_seed(alt_seed), randomness[PARAM_TANGENTIAL_ACCEL])) : Vector2();
|
2018-08-30 03:48:32 +08:00
|
|
|
//apply attractor forces
|
|
|
|
p.velocity += force * local_delta;
|
|
|
|
//orbit velocity
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t orbit_amount = (parameters[PARAM_ORBIT_VELOCITY] + tex_orbit_velocity) * Math::lerp((real_t)1.0, rand_from_seed(alt_seed), randomness[PARAM_ORBIT_VELOCITY]);
|
2019-06-11 23:47:24 +08:00
|
|
|
if (orbit_amount != 0.0) {
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t ang = orbit_amount * local_delta * Math_TAU;
|
2019-06-11 23:47:24 +08:00
|
|
|
// Not sure why the ParticlesMaterial code uses a clockwise rotation matrix,
|
|
|
|
// but we use -ang here to reproduce its behavior.
|
|
|
|
Transform2D rot = Transform2D(-ang, Vector2());
|
|
|
|
p.transform[2] -= diff;
|
|
|
|
p.transform[2] += rot.basis_xform(diff);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
|
|
|
|
p.velocity = p.velocity.normalized() * tex_linear_velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters[PARAM_DAMPING] + tex_damping > 0.0) {
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t v = p.velocity.length();
|
|
|
|
real_t damp = (parameters[PARAM_DAMPING] + tex_damping) * Math::lerp((real_t)1.0, rand_from_seed(alt_seed), randomness[PARAM_DAMPING]);
|
2018-08-30 03:48:32 +08:00
|
|
|
v -= damp * local_delta;
|
|
|
|
if (v < 0.0) {
|
|
|
|
p.velocity = Vector2();
|
|
|
|
} else {
|
|
|
|
p.velocity = p.velocity.normalized() * v;
|
|
|
|
}
|
|
|
|
}
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t base_angle = (parameters[PARAM_ANGLE] + tex_angle) * Math::lerp((real_t)1.0, p.angle_rand, randomness[PARAM_ANGLE]);
|
|
|
|
base_angle += p.custom[1] * lifetime * (parameters[PARAM_ANGULAR_VELOCITY] + tex_angular_velocity) * Math::lerp((real_t)1.0, rand_from_seed(alt_seed) * 2.0f - 1.0f, randomness[PARAM_ANGULAR_VELOCITY]);
|
2018-09-27 19:05:57 +08:00
|
|
|
p.rotation = Math::deg2rad(base_angle); //angle
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t animation_phase = (parameters[PARAM_ANIM_OFFSET] + tex_anim_offset) * Math::lerp((real_t)1.0, p.anim_offset_rand, randomness[PARAM_ANIM_OFFSET]) + p.custom[1] * (parameters[PARAM_ANIM_SPEED] + tex_anim_speed) * Math::lerp((real_t)1.0, rand_from_seed(alt_seed), randomness[PARAM_ANIM_SPEED]);
|
2018-09-27 19:05:57 +08:00
|
|
|
p.custom[2] = animation_phase;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
//apply color
|
|
|
|
//apply hue rotation
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_scale = 1.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_SCALE].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_scale = curve_parameters[PARAM_SCALE]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t tex_hue_variation = 0.0;
|
2018-08-30 03:48:32 +08:00
|
|
|
if (curve_parameters[PARAM_HUE_VARIATION].is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
tex_hue_variation = curve_parameters[PARAM_HUE_VARIATION]->interpolate(tv);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t hue_rot_angle = (parameters[PARAM_HUE_VARIATION] + tex_hue_variation) * Math_TAU * Math::lerp(1.0f, p.hue_rot_rand * 2.0f - 1.0f, randomness[PARAM_HUE_VARIATION]);
|
|
|
|
real_t hue_rot_c = Math::cos(hue_rot_angle);
|
|
|
|
real_t hue_rot_s = Math::sin(hue_rot_angle);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
Basis hue_rot_mat;
|
|
|
|
{
|
|
|
|
Basis mat1(0.299, 0.587, 0.114, 0.299, 0.587, 0.114, 0.299, 0.587, 0.114);
|
|
|
|
Basis mat2(0.701, -0.587, -0.114, -0.299, 0.413, -0.114, -0.300, -0.588, 0.886);
|
|
|
|
Basis mat3(0.168, 0.330, -0.497, -0.328, 0.035, 0.292, 1.250, -1.050, -0.203);
|
|
|
|
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
hue_rot_mat[j] = mat1[j] + mat2[j] * hue_rot_c + mat3[j] * hue_rot_s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color_ramp.is_valid()) {
|
2021-01-27 19:18:07 +08:00
|
|
|
p.color = color_ramp->get_color_at_offset(tv) * color;
|
2018-08-30 03:48:32 +08:00
|
|
|
} else {
|
|
|
|
p.color = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 color_rgb = hue_rot_mat.xform_inv(Vector3(p.color.r, p.color.g, p.color.b));
|
|
|
|
p.color.r = color_rgb.x;
|
|
|
|
p.color.g = color_rgb.y;
|
|
|
|
p.color.b = color_rgb.z;
|
|
|
|
|
|
|
|
p.color *= p.base_color;
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
|
2018-08-30 03:48:32 +08:00
|
|
|
if (p.velocity.length() > 0.0) {
|
2019-01-22 12:11:48 +08:00
|
|
|
p.transform.elements[1] = p.velocity.normalized();
|
2020-12-07 02:16:06 +08:00
|
|
|
p.transform.elements[0] = p.transform.elements[1].orthogonal();
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-09-27 19:05:57 +08:00
|
|
|
p.transform.elements[0] = Vector2(Math::cos(p.rotation), -Math::sin(p.rotation));
|
|
|
|
p.transform.elements[1] = Vector2(Math::sin(p.rotation), Math::cos(p.rotation));
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//scale by scale
|
2021-01-30 12:10:32 +08:00
|
|
|
real_t base_scale = tex_scale * Math::lerp(parameters[PARAM_SCALE], (real_t)1.0, p.scale_rand * randomness[PARAM_SCALE]);
|
2020-05-14 22:41:43 +08:00
|
|
|
if (base_scale < 0.000001) {
|
2020-05-10 18:56:01 +08:00
|
|
|
base_scale = 0.000001;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
p.transform.elements[0] *= base_scale;
|
|
|
|
p.transform.elements[1] *= base_scale;
|
|
|
|
|
|
|
|
p.transform[2] += p.velocity * local_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::_update_particle_data_buffer() {
|
2020-02-26 18:28:13 +08:00
|
|
|
MutexLock lock(update_mutex);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
int pc = particles.size();
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
int *ow;
|
2020-04-02 07:20:12 +08:00
|
|
|
int *order = nullptr;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
float *w = particle_data.ptrw();
|
|
|
|
const Particle *r = particles.ptr();
|
|
|
|
float *ptr = w;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
if (draw_order != DRAW_ORDER_INDEX) {
|
|
|
|
ow = particle_order.ptrw();
|
|
|
|
order = ow;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
for (int i = 0; i < pc; i++) {
|
|
|
|
order[i] = i;
|
|
|
|
}
|
|
|
|
if (draw_order == DRAW_ORDER_LIFETIME) {
|
|
|
|
SortArray<int, SortLifetime> sorter;
|
|
|
|
sorter.compare.particles = r;
|
|
|
|
sorter.sort(order, pc);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
2020-02-26 18:28:13 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
for (int i = 0; i < pc; i++) {
|
|
|
|
int idx = order ? order[i] : i;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
Transform2D t = r[idx].transform;
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
if (!local_coords) {
|
|
|
|
t = inv_emission_transform * t;
|
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
if (r[idx].active) {
|
|
|
|
ptr[0] = t.elements[0][0];
|
|
|
|
ptr[1] = t.elements[1][0];
|
|
|
|
ptr[2] = 0;
|
|
|
|
ptr[3] = t.elements[2][0];
|
|
|
|
ptr[4] = t.elements[0][1];
|
|
|
|
ptr[5] = t.elements[1][1];
|
|
|
|
ptr[6] = 0;
|
|
|
|
ptr[7] = t.elements[2][1];
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
} else {
|
2021-04-27 22:19:21 +08:00
|
|
|
memset(ptr, 0, sizeof(float) * 8);
|
2020-02-26 18:28:13 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
Color c = r[idx].color;
|
2019-10-05 22:35:10 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
ptr[8] = c.r;
|
|
|
|
ptr[9] = c.g;
|
|
|
|
ptr[10] = c.b;
|
|
|
|
ptr[11] = c.a;
|
2019-10-05 22:35:10 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
ptr[12] = r[idx].custom[0];
|
|
|
|
ptr[13] = r[idx].custom[1];
|
|
|
|
ptr[14] = r[idx].custom[2];
|
|
|
|
ptr[15] = r[idx].custom[3];
|
2019-10-05 22:35:10 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
ptr += 16;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-08 15:00:00 +08:00
|
|
|
void CPUParticles2D::_set_redraw(bool p_redraw) {
|
2020-05-14 22:41:43 +08:00
|
|
|
if (redraw == p_redraw) {
|
2019-03-08 15:00:00 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2019-03-08 15:00:00 +08:00
|
|
|
redraw = p_redraw;
|
2019-07-29 09:31:52 +08:00
|
|
|
|
2020-02-26 18:28:13 +08:00
|
|
|
{
|
|
|
|
MutexLock lock(update_mutex);
|
|
|
|
|
|
|
|
if (redraw) {
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread));
|
|
|
|
RS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), true);
|
2020-02-26 18:28:13 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1);
|
2020-02-26 18:28:13 +08:00
|
|
|
} else {
|
2020-03-28 02:21:27 +08:00
|
|
|
if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread))) {
|
|
|
|
RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread));
|
2020-02-26 18:28:13 +08:00
|
|
|
}
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), false);
|
2020-02-26 18:28:13 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->multimesh_set_visible_instances(multimesh, 0);
|
2020-02-26 18:28:13 +08:00
|
|
|
}
|
2019-03-08 15:00:00 +08:00
|
|
|
}
|
2020-02-26 18:28:13 +08:00
|
|
|
|
2019-03-08 15:00:00 +08:00
|
|
|
update(); // redraw to update render list
|
|
|
|
}
|
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
void CPUParticles2D::_update_render_thread() {
|
2020-02-26 18:28:13 +08:00
|
|
|
MutexLock lock(update_mutex);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::_notification(int p_what) {
|
2021-03-01 10:11:24 +08:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
set_process_internal(emitting);
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
_set_redraw(false);
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
// first update before rendering to avoid one frame delay after emitting starts
|
|
|
|
if (emitting && (time == 0)) {
|
|
|
|
_update_internal();
|
|
|
|
}
|
2019-06-15 04:22:19 +08:00
|
|
|
|
2021-03-01 10:11:24 +08:00
|
|
|
if (!redraw) {
|
|
|
|
return; // don't add to render list
|
|
|
|
}
|
2019-06-15 04:22:19 +08:00
|
|
|
|
2021-03-01 10:11:24 +08:00
|
|
|
RID texrid;
|
|
|
|
if (texture.is_valid()) {
|
|
|
|
texrid = texture->get_rid();
|
|
|
|
}
|
2019-06-15 04:22:19 +08:00
|
|
|
|
2021-03-01 10:11:24 +08:00
|
|
|
RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
|
|
|
_update_internal();
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
|
|
|
inv_emission_transform = get_global_transform().affine_inverse();
|
2019-06-15 04:22:19 +08:00
|
|
|
|
2021-03-01 10:11:24 +08:00
|
|
|
if (!local_coords) {
|
|
|
|
int pc = particles.size();
|
|
|
|
|
|
|
|
float *w = particle_data.ptrw();
|
|
|
|
const Particle *r = particles.ptr();
|
|
|
|
float *ptr = w;
|
|
|
|
|
|
|
|
for (int i = 0; i < pc; i++) {
|
|
|
|
Transform2D t = inv_emission_transform * r[i].transform;
|
|
|
|
|
|
|
|
if (r[i].active) {
|
|
|
|
ptr[0] = t.elements[0][0];
|
|
|
|
ptr[1] = t.elements[1][0];
|
|
|
|
ptr[2] = 0;
|
|
|
|
ptr[3] = t.elements[2][0];
|
|
|
|
ptr[4] = t.elements[0][1];
|
|
|
|
ptr[5] = t.elements[1][1];
|
|
|
|
ptr[6] = 0;
|
|
|
|
ptr[7] = t.elements[2][1];
|
|
|
|
|
|
|
|
} else {
|
2021-04-27 22:19:21 +08:00
|
|
|
memset(ptr, 0, sizeof(float) * 8);
|
2021-03-01 10:11:24 +08:00
|
|
|
}
|
2019-06-15 04:22:19 +08:00
|
|
|
|
2021-03-01 10:11:24 +08:00
|
|
|
ptr += 16;
|
2019-06-15 04:22:19 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-01 10:11:24 +08:00
|
|
|
} break;
|
2019-06-15 04:22:19 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::convert_from_particles(Node *p_particles) {
|
2020-03-27 15:44:44 +08:00
|
|
|
GPUParticles2D *particles = Object::cast_to<GPUParticles2D>(p_particles);
|
2020-03-31 00:22:57 +08:00
|
|
|
ERR_FAIL_COND_MSG(!particles, "Only GPUParticles2D nodes can be converted to CPUParticles2D.");
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
set_emitting(particles->is_emitting());
|
|
|
|
set_amount(particles->get_amount());
|
|
|
|
set_lifetime(particles->get_lifetime());
|
|
|
|
set_one_shot(particles->get_one_shot());
|
|
|
|
set_pre_process_time(particles->get_pre_process_time());
|
|
|
|
set_explosiveness_ratio(particles->get_explosiveness_ratio());
|
|
|
|
set_randomness_ratio(particles->get_randomness_ratio());
|
|
|
|
set_use_local_coordinates(particles->get_use_local_coordinates());
|
|
|
|
set_fixed_fps(particles->get_fixed_fps());
|
|
|
|
set_fractional_delta(particles->get_fractional_delta());
|
|
|
|
set_speed_scale(particles->get_speed_scale());
|
|
|
|
set_draw_order(DrawOrder(particles->get_draw_order()));
|
2018-09-27 19:05:57 +08:00
|
|
|
set_texture(particles->get_texture());
|
|
|
|
|
|
|
|
Ref<Material> mat = particles->get_material();
|
|
|
|
if (mat.is_valid()) {
|
|
|
|
set_material(mat);
|
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
Ref<ParticlesMaterial> material = particles->get_process_material();
|
2020-05-14 22:41:43 +08:00
|
|
|
if (material.is_null()) {
|
2018-08-30 03:48:32 +08:00
|
|
|
return;
|
2020-05-14 22:41:43 +08:00
|
|
|
}
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2019-03-05 06:45:53 +08:00
|
|
|
Vector3 dir = material->get_direction();
|
|
|
|
set_direction(Vector2(dir.x, dir.y));
|
2018-08-30 03:48:32 +08:00
|
|
|
set_spread(material->get_spread());
|
|
|
|
|
|
|
|
set_color(material->get_color());
|
|
|
|
|
|
|
|
Ref<GradientTexture> gt = material->get_color_ramp();
|
|
|
|
if (gt.is_valid()) {
|
|
|
|
set_color_ramp(gt->get_gradient());
|
|
|
|
}
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
set_particle_flag(PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY, material->get_particle_flag(ParticlesMaterial::PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY));
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
set_emission_shape(EmissionShape(material->get_emission_shape()));
|
|
|
|
set_emission_sphere_radius(material->get_emission_sphere_radius());
|
2018-09-27 19:05:57 +08:00
|
|
|
Vector2 rect_extents = Vector2(material->get_emission_box_extents().x, material->get_emission_box_extents().y);
|
|
|
|
set_emission_rect_extents(rect_extents);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
2018-09-27 19:05:57 +08:00
|
|
|
Vector2 gravity = Vector2(material->get_gravity().x, material->get_gravity().y);
|
|
|
|
set_gravity(gravity);
|
2019-07-15 12:48:20 +08:00
|
|
|
set_lifetime_randomness(material->get_lifetime_randomness());
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
#define CONVERT_PARAM(m_param) \
|
|
|
|
set_param(m_param, material->get_param(ParticlesMaterial::m_param)); \
|
|
|
|
{ \
|
|
|
|
Ref<CurveTexture> ctex = material->get_param_texture(ParticlesMaterial::m_param); \
|
2020-05-10 18:56:01 +08:00
|
|
|
if (ctex.is_valid()) \
|
|
|
|
set_param_curve(m_param, ctex->get_curve()); \
|
2018-08-30 03:48:32 +08:00
|
|
|
} \
|
|
|
|
set_param_randomness(m_param, material->get_param_randomness(ParticlesMaterial::m_param));
|
|
|
|
|
|
|
|
CONVERT_PARAM(PARAM_INITIAL_LINEAR_VELOCITY);
|
|
|
|
CONVERT_PARAM(PARAM_ANGULAR_VELOCITY);
|
|
|
|
CONVERT_PARAM(PARAM_ORBIT_VELOCITY);
|
|
|
|
CONVERT_PARAM(PARAM_LINEAR_ACCEL);
|
|
|
|
CONVERT_PARAM(PARAM_RADIAL_ACCEL);
|
|
|
|
CONVERT_PARAM(PARAM_TANGENTIAL_ACCEL);
|
|
|
|
CONVERT_PARAM(PARAM_DAMPING);
|
|
|
|
CONVERT_PARAM(PARAM_ANGLE);
|
|
|
|
CONVERT_PARAM(PARAM_SCALE);
|
|
|
|
CONVERT_PARAM(PARAM_HUE_VARIATION);
|
|
|
|
CONVERT_PARAM(PARAM_ANIM_SPEED);
|
|
|
|
CONVERT_PARAM(PARAM_ANIM_OFFSET);
|
|
|
|
|
|
|
|
#undef CONVERT_PARAM
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUParticles2D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles2D::set_emitting);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles2D::set_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles2D::set_lifetime);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles2D::set_one_shot);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles2D::set_pre_process_time);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles2D::set_explosiveness_ratio);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles2D::set_randomness_ratio);
|
2019-07-15 12:48:20 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles2D::set_lifetime_randomness);
|
2018-08-30 03:48:32 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles2D::set_use_local_coordinates);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles2D::set_fixed_fps);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles2D::set_fractional_delta);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &CPUParticles2D::set_speed_scale);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles2D::is_emitting);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles2D::get_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles2D::get_lifetime);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles2D::get_one_shot);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles2D::get_pre_process_time);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles2D::get_explosiveness_ratio);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles2D::get_randomness_ratio);
|
2019-07-15 12:48:20 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles2D::get_lifetime_randomness);
|
2018-08-30 03:48:32 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles2D::get_use_local_coordinates);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles2D::get_fixed_fps);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles2D::get_fractional_delta);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_speed_scale"), &CPUParticles2D::get_speed_scale);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &CPUParticles2D::set_draw_order);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_draw_order"), &CPUParticles2D::get_draw_order);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &CPUParticles2D::set_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture"), &CPUParticles2D::get_texture);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("restart"), &CPUParticles2D::restart);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting");
|
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-30 03:42:12 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount");
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_GROUP("Time", "");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater"), "set_lifetime", "get_lifetime");
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
|
|
|
|
ADD_GROUP("Drawing", "");
|
2019-06-12 00:56:07 +08:00
|
|
|
// No visibility_rect property contrarily to Particles2D, it's updated automatically.
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime"), "set_draw_order", "get_draw_order");
|
2019-06-12 02:43:37 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
|
|
|
|
BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2019-03-05 06:45:53 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles2D::set_direction);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles2D::get_direction);
|
|
|
|
|
2018-08-30 03:48:32 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles2D::set_spread);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles2D::get_spread);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &CPUParticles2D::set_param);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_param", "param"), &CPUParticles2D::get_param);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_param_randomness", "param", "randomness"), &CPUParticles2D::set_param_randomness);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_param_randomness", "param"), &CPUParticles2D::get_param_randomness);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_param_curve", "param", "curve"), &CPUParticles2D::set_param_curve);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_param_curve", "param"), &CPUParticles2D::get_param_curve);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "color"), &CPUParticles2D::set_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &CPUParticles2D::get_color);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &CPUParticles2D::set_color_ramp);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color_ramp"), &CPUParticles2D::get_color_ramp);
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
ClassDB::bind_method(D_METHOD("set_particle_flag", "particle_flag", "enable"), &CPUParticles2D::set_particle_flag);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_particle_flag", "particle_flag"), &CPUParticles2D::get_particle_flag);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &CPUParticles2D::set_emission_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_shape"), &CPUParticles2D::get_emission_shape);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &CPUParticles2D::set_emission_sphere_radius);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &CPUParticles2D::get_emission_sphere_radius);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_rect_extents", "extents"), &CPUParticles2D::set_emission_rect_extents);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_rect_extents"), &CPUParticles2D::get_emission_rect_extents);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_points", "array"), &CPUParticles2D::set_emission_points);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_points"), &CPUParticles2D::get_emission_points);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_normals", "array"), &CPUParticles2D::set_emission_normals);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_normals"), &CPUParticles2D::get_emission_normals);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles2D::set_emission_colors);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles2D::get_emission_colors);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles2D::get_gravity);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles2D::set_gravity);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles2D::convert_from_particles);
|
|
|
|
|
|
|
|
ADD_GROUP("Emission Shape", "emission_");
|
2020-09-23 14:24:17 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Box,Points,Directed Points", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_emission_shape", "get_emission_shape");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01"), "set_emission_sphere_radius", "get_emission_sphere_radius");
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "emission_rect_extents"), "set_emission_rect_extents", "get_emission_rect_extents");
|
2020-02-18 05:06:54 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "emission_points"), "set_emission_points", "get_emission_points");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "emission_normals"), "set_emission_normals", "get_emission_normals");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "emission_colors"), "set_emission_colors", "get_emission_colors");
|
2020-12-05 07:35:57 +08:00
|
|
|
ADD_GROUP("Particle Flags", "particle_flag_");
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_align_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
|
2019-03-05 06:45:53 +08:00
|
|
|
ADD_GROUP("Direction", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "direction"), "set_direction", "get_direction");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spread", PROPERTY_HINT_RANGE, "0,180,0.01"), "set_spread", "get_spread");
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_GROUP("Gravity", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity"), "set_gravity", "get_gravity");
|
|
|
|
ADD_GROUP("Initial Velocity", "initial_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "initial_velocity", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param", "get_param", PARAM_INITIAL_LINEAR_VELOCITY);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "initial_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_INITIAL_LINEAR_VELOCITY);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_GROUP("Angular Velocity", "angular_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_velocity", PROPERTY_HINT_RANGE, "-720,720,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_ANGULAR_VELOCITY);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGULAR_VELOCITY);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angular_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGULAR_VELOCITY);
|
|
|
|
ADD_GROUP("Orbit Velocity", "orbit_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "orbit_velocity", PROPERTY_HINT_RANGE, "-1000,1000,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_ORBIT_VELOCITY);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "orbit_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ORBIT_VELOCITY);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "orbit_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ORBIT_VELOCITY);
|
|
|
|
ADD_GROUP("Linear Accel", "linear_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_accel", PROPERTY_HINT_RANGE, "-100,100,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_LINEAR_ACCEL);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_accel_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_LINEAR_ACCEL);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "linear_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_LINEAR_ACCEL);
|
|
|
|
ADD_GROUP("Radial Accel", "radial_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "radial_accel", PROPERTY_HINT_RANGE, "-100,100,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_RADIAL_ACCEL);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "radial_accel_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_RADIAL_ACCEL);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "radial_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_RADIAL_ACCEL);
|
|
|
|
ADD_GROUP("Tangential Accel", "tangential_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "tangential_accel", PROPERTY_HINT_RANGE, "-100,100,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_TANGENTIAL_ACCEL);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "tangential_accel_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_TANGENTIAL_ACCEL);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "tangential_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_TANGENTIAL_ACCEL);
|
|
|
|
ADD_GROUP("Damping", "");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_param", "get_param", PARAM_DAMPING);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_DAMPING);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_DAMPING);
|
|
|
|
ADD_GROUP("Angle", "");
|
Fix editor suffixes and degrees conversion
* Functions to convert to/from degrees are all gone. Conversion is done by the editor.
* Use PROPERTY_HINT_ANGLE instead of PROPERTY_HINT_RANGE to edit radian angles in degrees.
* Added possibility to add suffixes to range properties, use "min,max[,step][,suffix:<something>]" example "0,100,1,suffix:m"
* In general, can add suffixes for EditorSpinSlider
Not covered by this PR, will have to be addressed by future ones:
* Ability to switch radians/degrees in the inspector for angle properties (if actually wanted).
* Animations previously made will most likely break, need to add a way to make old ones compatible.
* Only added a "px" suffix to 2D position and a "m" one to 3D position, someone needs to go through the rest of the engine and add all remaining suffixes.
* Likely also need to track down usage of EditorSpinSlider outside properties to add suffixes to it too.
2021-06-30 03:42:12 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater,degrees"), "set_param", "get_param", PARAM_ANGLE);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGLE);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGLE);
|
|
|
|
ADD_GROUP("Scale", "");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "scale_amount", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param", "get_param", PARAM_SCALE);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "scale_amount_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_SCALE);
|
2018-11-27 18:07:58 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "scale_amount_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_SCALE);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_GROUP("Color", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
|
2018-11-11 07:07:22 +08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_color_ramp", "get_color_ramp");
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
ADD_GROUP("Hue Variation", "hue_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "hue_variation", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_param", "get_param", PARAM_HUE_VARIATION);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "hue_variation_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_HUE_VARIATION);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "hue_variation_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_HUE_VARIATION);
|
|
|
|
ADD_GROUP("Animation", "anim_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater"), "set_param", "get_param", PARAM_ANIM_SPEED);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANIM_SPEED);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_speed_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANIM_SPEED);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 02:20:53 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_ANIM_OFFSET);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANIM_OFFSET);
|
2018-08-30 03:48:32 +08:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_offset_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANIM_OFFSET);
|
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_ORBIT_VELOCITY);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_LINEAR_ACCEL);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_RADIAL_ACCEL);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_TANGENTIAL_ACCEL);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_DAMPING);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_ANGLE);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_SCALE);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_HUE_VARIATION);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_ANIM_SPEED);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_ANIM_OFFSET);
|
|
|
|
BIND_ENUM_CONSTANT(PARAM_MAX);
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
BIND_ENUM_CONSTANT(PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
|
|
|
|
BIND_ENUM_CONSTANT(PARTICLE_FLAG_ROTATE_Y); // Unused, but exposed for consistency with 3D.
|
|
|
|
BIND_ENUM_CONSTANT(PARTICLE_FLAG_DISABLE_Z); // Unused, but exposed for consistency with 3D.
|
|
|
|
BIND_ENUM_CONSTANT(PARTICLE_FLAG_MAX);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINT);
|
2019-06-18 02:59:31 +08:00
|
|
|
BIND_ENUM_CONSTANT(EMISSION_SHAPE_SPHERE);
|
2018-08-30 03:48:32 +08:00
|
|
|
BIND_ENUM_CONSTANT(EMISSION_SHAPE_RECTANGLE);
|
|
|
|
BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINTS);
|
|
|
|
BIND_ENUM_CONSTANT(EMISSION_SHAPE_DIRECTED_POINTS);
|
2020-01-16 17:59:01 +08:00
|
|
|
BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CPUParticles2D::CPUParticles2D() {
|
2020-03-28 02:21:27 +08:00
|
|
|
mesh = RenderingServer::get_singleton()->mesh_create();
|
|
|
|
multimesh = RenderingServer::get_singleton()->multimesh_create();
|
|
|
|
RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh);
|
2018-08-30 03:48:32 +08:00
|
|
|
|
|
|
|
set_emitting(true);
|
|
|
|
set_amount(8);
|
|
|
|
set_use_local_coordinates(true);
|
|
|
|
|
2019-06-21 21:23:48 +08:00
|
|
|
set_param(PARAM_INITIAL_LINEAR_VELOCITY, 0);
|
2019-06-21 21:23:10 +08:00
|
|
|
set_param(PARAM_ANGULAR_VELOCITY, 0);
|
2019-06-11 23:47:24 +08:00
|
|
|
set_param(PARAM_ORBIT_VELOCITY, 0);
|
2018-08-30 03:48:32 +08:00
|
|
|
set_param(PARAM_LINEAR_ACCEL, 0);
|
|
|
|
set_param(PARAM_RADIAL_ACCEL, 0);
|
|
|
|
set_param(PARAM_TANGENTIAL_ACCEL, 0);
|
|
|
|
set_param(PARAM_DAMPING, 0);
|
|
|
|
set_param(PARAM_ANGLE, 0);
|
|
|
|
set_param(PARAM_SCALE, 1);
|
|
|
|
set_param(PARAM_HUE_VARIATION, 0);
|
|
|
|
set_param(PARAM_ANIM_SPEED, 0);
|
|
|
|
set_param(PARAM_ANIM_OFFSET, 0);
|
|
|
|
|
|
|
|
for (int i = 0; i < PARAM_MAX; i++) {
|
|
|
|
set_param_randomness(Parameter(i), 0);
|
|
|
|
}
|
|
|
|
|
2020-12-05 07:35:57 +08:00
|
|
|
for (int i = 0; i < PARTICLE_FLAG_MAX; i++) {
|
|
|
|
particle_flags[i] = false;
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set_color(Color(1, 1, 1, 1));
|
|
|
|
|
2018-11-14 01:19:16 +08:00
|
|
|
_update_mesh_texture();
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CPUParticles2D::~CPUParticles2D() {
|
2020-03-28 02:21:27 +08:00
|
|
|
RS::get_singleton()->free(multimesh);
|
|
|
|
RS::get_singleton()->free(mesh);
|
2018-08-30 03:48:32 +08:00
|
|
|
}
|