2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* particles.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 12:16:55 +00:00
/* https://godotengine.org */
2014-02-10 01:10:30 +00:00
/*************************************************************************/
2020-01-01 10:16:22 +00:00
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 01:10:30 +00: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-01-04 23:50:27 +00:00
2014-02-10 01:10:30 +00:00
# include "particles.h"
2019-02-09 19:49:58 +00:00
# include "core/os/os.h"
2018-11-13 17:19:16 +00:00
# include "scene/resources/particles_material.h"
2018-09-04 09:30:04 +00:00
2017-03-05 15:44:50 +00:00
# include "servers/visual_server.h"
2014-02-10 01:10:30 +00:00
2017-11-17 02:09:00 +00:00
AABB Particles : : get_aabb ( ) const {
2017-04-07 02:36:37 +00:00
2017-11-17 02:09:00 +00:00
return AABB ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-01-07 21:25:37 +00:00
PoolVector < Face3 > Particles : : get_faces ( uint32_t p_usage_flags ) const {
2014-02-10 01:10:30 +00:00
2017-01-07 21:25:37 +00:00
return PoolVector < Face3 > ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_emitting ( bool p_emitting ) {
2017-12-23 04:08:50 +00:00
VS : : get_singleton ( ) - > particles_set_emitting ( particles , p_emitting ) ;
2019-06-20 18:20:27 +00:00
if ( p_emitting & & one_shot ) {
set_process_internal ( true ) ;
} else if ( ! p_emitting ) {
set_process_internal ( false ) ;
}
2017-04-07 02:36:37 +00:00
}
2014-02-10 01:10:30 +00:00
void Particles : : set_amount ( int p_amount ) {
2019-09-25 08:28:50 +00:00
ERR_FAIL_COND_MSG ( p_amount < 1 , " Amount of particles cannot be smaller than 1. " ) ;
2017-04-07 02:36:37 +00:00
amount = p_amount ;
VS : : get_singleton ( ) - > particles_set_amount ( particles , amount ) ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_lifetime ( float p_lifetime ) {
2016-03-08 23:00:52 +00:00
2019-09-25 08:28:50 +00:00
ERR_FAIL_COND_MSG ( p_lifetime < = 0 , " Particles lifetime must be greater than 0. " ) ;
2017-04-07 02:36:37 +00:00
lifetime = p_lifetime ;
VS : : get_singleton ( ) - > particles_set_lifetime ( particles , lifetime ) ;
2014-02-10 01:10:30 +00:00
}
2017-06-25 11:01:15 +00:00
void Particles : : set_one_shot ( bool p_one_shot ) {
one_shot = p_one_shot ;
VS : : get_singleton ( ) - > particles_set_one_shot ( particles , one_shot ) ;
2019-06-20 18:20:27 +00:00
if ( is_emitting ( ) ) {
set_process_internal ( true ) ;
if ( ! one_shot )
VisualServer : : get_singleton ( ) - > particles_restart ( particles ) ;
}
if ( ! one_shot )
set_process_internal ( false ) ;
2017-06-25 11:01:15 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_pre_process_time ( float p_time ) {
2016-03-08 23:00:52 +00:00
2017-04-07 02:36:37 +00:00
pre_process_time = p_time ;
VS : : get_singleton ( ) - > particles_set_pre_process_time ( particles , pre_process_time ) ;
}
void Particles : : set_explosiveness_ratio ( float p_ratio ) {
explosiveness_ratio = p_ratio ;
VS : : get_singleton ( ) - > particles_set_explosiveness_ratio ( particles , explosiveness_ratio ) ;
}
void Particles : : set_randomness_ratio ( float p_ratio ) {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
randomness_ratio = p_ratio ;
VS : : get_singleton ( ) - > particles_set_randomness_ratio ( particles , randomness_ratio ) ;
}
2017-11-17 02:09:00 +00:00
void Particles : : set_visibility_aabb ( const AABB & p_aabb ) {
2017-04-07 02:36:37 +00:00
2017-04-09 01:38:11 +00:00
visibility_aabb = p_aabb ;
VS : : get_singleton ( ) - > particles_set_custom_aabb ( particles , visibility_aabb ) ;
update_gizmo ( ) ;
_change_notify ( " visibility_aabb " ) ;
2017-04-07 02:36:37 +00:00
}
void Particles : : set_use_local_coordinates ( bool p_enable ) {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
local_coords = p_enable ;
VS : : get_singleton ( ) - > particles_set_use_local_coordinates ( particles , local_coords ) ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_process_material ( const Ref < Material > & p_material ) {
process_material = p_material ;
RID material_rid ;
if ( process_material . is_valid ( ) )
material_rid = process_material - > get_rid ( ) ;
VS : : get_singleton ( ) - > particles_set_process_material ( particles , material_rid ) ;
2017-04-09 01:38:11 +00:00
update_configuration_warning ( ) ;
}
void Particles : : set_speed_scale ( float p_scale ) {
speed_scale = p_scale ;
VS : : get_singleton ( ) - > particles_set_speed_scale ( particles , p_scale ) ;
2017-04-07 02:36:37 +00:00
}
2014-02-10 01:10:30 +00:00
bool Particles : : is_emitting ( ) const {
2017-12-23 04:08:50 +00:00
return VS : : get_singleton ( ) - > particles_get_emitting ( particles ) ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
int Particles : : get_amount ( ) const {
2016-03-08 23:00:52 +00:00
2017-04-07 02:36:37 +00:00
return amount ;
}
float Particles : : get_lifetime ( ) const {
return lifetime ;
}
2017-06-25 11:01:15 +00:00
bool Particles : : get_one_shot ( ) const {
return one_shot ;
}
2017-04-07 02:36:37 +00:00
float Particles : : get_pre_process_time ( ) const {
return pre_process_time ;
}
float Particles : : get_explosiveness_ratio ( ) const {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
return explosiveness_ratio ;
}
float Particles : : get_randomness_ratio ( ) const {
2016-03-08 23:00:52 +00:00
2017-04-07 02:36:37 +00:00
return randomness_ratio ;
2014-02-10 01:10:30 +00:00
}
2017-11-17 02:09:00 +00:00
AABB Particles : : get_visibility_aabb ( ) const {
2016-03-08 23:00:52 +00:00
2017-04-09 01:38:11 +00:00
return visibility_aabb ;
2017-04-07 02:36:37 +00:00
}
bool Particles : : get_use_local_coordinates ( ) const {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
return local_coords ;
}
Ref < Material > Particles : : get_process_material ( ) const {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
return process_material ;
2014-02-10 01:10:30 +00:00
}
2017-04-09 01:38:11 +00:00
float Particles : : get_speed_scale ( ) const {
return speed_scale ;
}
2017-04-07 02:36:37 +00:00
void Particles : : set_draw_order ( DrawOrder p_order ) {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
draw_order = p_order ;
VS : : get_singleton ( ) - > particles_set_draw_order ( particles , VS : : ParticlesDrawOrder ( p_order ) ) ;
}
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
Particles : : DrawOrder Particles : : get_draw_order ( ) const {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
return draw_order ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_draw_passes ( int p_count ) {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
ERR_FAIL_COND ( p_count < 1 ) ;
draw_passes . resize ( p_count ) ;
VS : : get_singleton ( ) - > particles_set_draw_passes ( particles , p_count ) ;
_change_notify ( ) ;
}
int Particles : : get_draw_passes ( ) const {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
return draw_passes . size ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_draw_pass_mesh ( int p_pass , const Ref < Mesh > & p_mesh ) {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
ERR_FAIL_INDEX ( p_pass , draw_passes . size ( ) ) ;
2018-07-25 01:11:03 +00:00
draw_passes . write [ p_pass ] = p_mesh ;
2017-04-07 02:36:37 +00:00
RID mesh_rid ;
if ( p_mesh . is_valid ( ) )
mesh_rid = p_mesh - > get_rid ( ) ;
VS : : get_singleton ( ) - > particles_set_draw_pass_mesh ( particles , p_pass , mesh_rid ) ;
2017-04-09 01:38:11 +00:00
update_configuration_warning ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
Ref < Mesh > Particles : : get_draw_pass_mesh ( int p_pass ) const {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
ERR_FAIL_INDEX_V ( p_pass , draw_passes . size ( ) , Ref < Mesh > ( ) ) ;
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
return draw_passes [ p_pass ] ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_fixed_fps ( int p_count ) {
fixed_fps = p_count ;
VS : : get_singleton ( ) - > particles_set_fixed_fps ( particles , p_count ) ;
}
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
int Particles : : get_fixed_fps ( ) const {
return fixed_fps ;
2014-02-10 01:10:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : set_fractional_delta ( bool p_enable ) {
fractional_delta = p_enable ;
VS : : get_singleton ( ) - > particles_set_fractional_delta ( particles , p_enable ) ;
}
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
bool Particles : : get_fractional_delta ( ) const {
return fractional_delta ;
}
2017-04-09 01:38:11 +00:00
String Particles : : get_configuration_warning ( ) const {
2019-02-09 19:49:58 +00:00
if ( OS : : get_singleton ( ) - > get_current_video_driver ( ) = = OS : : VIDEO_DRIVER_GLES2 ) {
return TTR ( " GPU-based particles are not supported by the GLES2 video driver. \n Use the CPUParticles node instead. You can use the \" Convert to CPUParticles \" option for this purpose. " ) ;
}
2017-04-09 01:38:11 +00:00
String warnings ;
bool meshes_found = false ;
2018-11-13 17:19:16 +00:00
bool anim_material_found = false ;
2017-04-09 01:38:11 +00:00
for ( int i = 0 ; i < draw_passes . size ( ) ; i + + ) {
if ( draw_passes [ i ] . is_valid ( ) ) {
meshes_found = true ;
2018-11-13 17:19:16 +00:00
for ( int j = 0 ; j < draw_passes [ i ] - > get_surface_count ( ) ; j + + ) {
anim_material_found = Object : : cast_to < ShaderMaterial > ( draw_passes [ i ] - > surface_get_material ( j ) . ptr ( ) ) ! = NULL ;
2019-09-15 04:01:52 +00:00
StandardMaterial3D * spat = Object : : cast_to < StandardMaterial3D > ( draw_passes [ i ] - > surface_get_material ( j ) . ptr ( ) ) ;
anim_material_found = anim_material_found | | ( spat & & spat - > get_billboard_mode ( ) = = StandardMaterial3D : : BILLBOARD_PARTICLES ) ;
2018-11-13 17:19:16 +00:00
}
2019-07-07 21:08:51 +00:00
if ( anim_material_found ) break ;
2017-04-09 01:38:11 +00:00
}
}
2018-11-13 17:19:16 +00:00
anim_material_found = anim_material_found | | Object : : cast_to < ShaderMaterial > ( get_material_override ( ) . ptr ( ) ) ! = NULL ;
2019-09-15 04:01:52 +00:00
StandardMaterial3D * spat = Object : : cast_to < StandardMaterial3D > ( get_material_override ( ) . ptr ( ) ) ;
anim_material_found = anim_material_found | | ( spat & & spat - > get_billboard_mode ( ) = = StandardMaterial3D : : BILLBOARD_PARTICLES ) ;
2018-11-13 17:19:16 +00:00
2017-04-09 01:38:11 +00:00
if ( ! meshes_found ) {
2018-11-13 17:19:16 +00:00
if ( warnings ! = String ( ) )
warnings + = " \n " ;
2017-04-09 01:38:11 +00:00
warnings + = " - " + TTR ( " Nothing is visible because meshes have not been assigned to draw passes. " ) ;
}
if ( process_material . is_null ( ) ) {
if ( warnings ! = String ( ) )
warnings + = " \n " ;
warnings + = " - " + TTR ( " A material to process the particles is not assigned, so no behavior is imprinted. " ) ;
2018-11-13 17:19:16 +00:00
} else {
const ParticlesMaterial * process = Object : : cast_to < ParticlesMaterial > ( process_material . ptr ( ) ) ;
if ( ! anim_material_found & & process & &
( process - > get_param ( ParticlesMaterial : : PARAM_ANIM_SPEED ) ! = 0.0 | | process - > get_param ( ParticlesMaterial : : PARAM_ANIM_OFFSET ) ! = 0.0 | |
process - > get_param_texture ( ParticlesMaterial : : PARAM_ANIM_SPEED ) . is_valid ( ) | | process - > get_param_texture ( ParticlesMaterial : : PARAM_ANIM_OFFSET ) . is_valid ( ) ) ) {
if ( warnings ! = String ( ) )
warnings + = " \n " ;
2019-09-15 04:01:52 +00:00
warnings + = " - " + TTR ( " Particles animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \" Particle Billboard \" . " ) ;
2018-11-13 17:19:16 +00:00
}
2017-04-09 01:38:11 +00:00
}
return warnings ;
}
2017-06-25 11:01:15 +00:00
void Particles : : restart ( ) {
VisualServer : : get_singleton ( ) - > particles_restart ( particles ) ;
2019-06-22 05:33:11 +00:00
VisualServer : : get_singleton ( ) - > particles_set_emitting ( particles , true ) ;
2017-06-25 11:01:15 +00:00
}
2017-11-17 02:09:00 +00:00
AABB Particles : : capture_aabb ( ) const {
2017-04-09 01:38:11 +00:00
return VS : : get_singleton ( ) - > particles_get_current_aabb ( particles ) ;
}
2017-04-07 02:36:37 +00:00
void Particles : : _validate_property ( PropertyInfo & property ) const {
if ( property . name . begins_with ( " draw_pass_ " ) ) {
int index = property . name . get_slicec ( ' _ ' , 2 ) . to_int ( ) - 1 ;
if ( index > = draw_passes . size ( ) ) {
property . usage = 0 ;
return ;
}
}
2014-02-10 01:10:30 +00:00
}
2017-08-07 22:01:30 +00:00
void Particles : : _notification ( int p_what ) {
if ( p_what = = NOTIFICATION_PAUSED | | p_what = = NOTIFICATION_UNPAUSED ) {
if ( can_process ( ) ) {
VS : : get_singleton ( ) - > particles_set_speed_scale ( particles , speed_scale ) ;
} else {
VS : : get_singleton ( ) - > particles_set_speed_scale ( particles , 0 ) ;
}
}
2019-06-20 18:20:27 +00:00
// Use internal process when emitting and one_shot are on so that when
// the shot ends the editor can properly update
if ( p_what = = NOTIFICATION_INTERNAL_PROCESS ) {
if ( one_shot & & ! is_emitting ( ) ) {
_change_notify ( ) ;
set_process_internal ( false ) ;
}
}
2019-11-09 08:51:17 +00:00
if ( p_what = = NOTIFICATION_VISIBILITY_CHANGED ) {
// make sure particles are updated before rendering occurs if they were active before
if ( is_visible_in_tree ( ) & & ! VS : : get_singleton ( ) - > particles_is_inactive ( particles ) ) {
VS : : get_singleton ( ) - > particles_request_process ( particles ) ;
}
}
2017-08-07 22:01:30 +00:00
}
2017-04-07 02:36:37 +00:00
void Particles : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_emitting " , " emitting " ) , & Particles : : set_emitting ) ;
ClassDB : : bind_method ( D_METHOD ( " set_amount " , " amount " ) , & Particles : : set_amount ) ;
ClassDB : : bind_method ( D_METHOD ( " set_lifetime " , " secs " ) , & Particles : : set_lifetime ) ;
2017-06-25 11:01:15 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_one_shot " , " enable " ) , & Particles : : set_one_shot ) ;
2017-04-07 02:36:37 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_pre_process_time " , " secs " ) , & Particles : : set_pre_process_time ) ;
ClassDB : : bind_method ( D_METHOD ( " set_explosiveness_ratio " , " ratio " ) , & Particles : : set_explosiveness_ratio ) ;
ClassDB : : bind_method ( D_METHOD ( " set_randomness_ratio " , " ratio " ) , & Particles : : set_randomness_ratio ) ;
2017-04-09 01:38:11 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_visibility_aabb " , " aabb " ) , & Particles : : set_visibility_aabb ) ;
2017-04-07 02:36:37 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_use_local_coordinates " , " enable " ) , & Particles : : set_use_local_coordinates ) ;
ClassDB : : bind_method ( D_METHOD ( " set_fixed_fps " , " fps " ) , & Particles : : set_fixed_fps ) ;
ClassDB : : bind_method ( D_METHOD ( " set_fractional_delta " , " enable " ) , & Particles : : set_fractional_delta ) ;
2017-08-09 11:19:41 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_process_material " , " material " ) , & Particles : : set_process_material ) ;
2017-04-09 01:38:11 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_speed_scale " , " scale " ) , & Particles : : set_speed_scale ) ;
2017-04-07 02:36:37 +00:00
ClassDB : : bind_method ( D_METHOD ( " is_emitting " ) , & Particles : : is_emitting ) ;
ClassDB : : bind_method ( D_METHOD ( " get_amount " ) , & Particles : : get_amount ) ;
ClassDB : : bind_method ( D_METHOD ( " get_lifetime " ) , & Particles : : get_lifetime ) ;
2017-06-25 11:01:15 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_one_shot " ) , & Particles : : get_one_shot ) ;
2017-04-07 02:36:37 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_pre_process_time " ) , & Particles : : get_pre_process_time ) ;
ClassDB : : bind_method ( D_METHOD ( " get_explosiveness_ratio " ) , & Particles : : get_explosiveness_ratio ) ;
ClassDB : : bind_method ( D_METHOD ( " get_randomness_ratio " ) , & Particles : : get_randomness_ratio ) ;
2017-04-09 01:38:11 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_visibility_aabb " ) , & Particles : : get_visibility_aabb ) ;
2017-04-07 02:36:37 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_use_local_coordinates " ) , & Particles : : get_use_local_coordinates ) ;
ClassDB : : bind_method ( D_METHOD ( " get_fixed_fps " ) , & Particles : : get_fixed_fps ) ;
ClassDB : : bind_method ( D_METHOD ( " get_fractional_delta " ) , & Particles : : get_fractional_delta ) ;
2017-08-09 11:19:41 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_process_material " ) , & Particles : : get_process_material ) ;
2017-04-09 01:38:11 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_speed_scale " ) , & Particles : : get_speed_scale ) ;
2017-04-07 02:36:37 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_draw_order " , " order " ) , & Particles : : set_draw_order ) ;
ClassDB : : bind_method ( D_METHOD ( " get_draw_order " ) , & Particles : : get_draw_order ) ;
ClassDB : : bind_method ( D_METHOD ( " set_draw_passes " , " passes " ) , & Particles : : set_draw_passes ) ;
2017-08-09 11:19:41 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_draw_pass_mesh " , " pass " , " mesh " ) , & Particles : : set_draw_pass_mesh ) ;
2017-04-07 02:36:37 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_draw_passes " ) , & Particles : : get_draw_passes ) ;
2017-08-09 11:19:41 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_draw_pass_mesh " , " pass " ) , & Particles : : get_draw_pass_mesh ) ;
2017-04-07 02:36:37 +00:00
2017-06-25 11:01:15 +00:00
ClassDB : : bind_method ( D_METHOD ( " restart " ) , & Particles : : restart ) ;
2017-04-09 01:38:11 +00:00
ClassDB : : bind_method ( D_METHOD ( " capture_aabb " ) , & Particles : : capture_aabb ) ;
2017-04-07 02:36:37 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " emitting " ) , " set_emitting " , " is_emitting " ) ;
2018-05-16 12:13:41 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " amount " , PROPERTY_HINT_EXP_RANGE , " 1,1000000,1 " ) , " set_amount " , " get_amount " ) ;
2017-06-25 21:57:28 +00:00
ADD_GROUP ( " Time " , " " ) ;
2019-02-18 18:46:41 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " lifetime " , PROPERTY_HINT_EXP_RANGE , " 0.01,600.0,0.01,or_greater " ) , " set_lifetime " , " get_lifetime " ) ;
2017-06-25 11:01:15 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " one_shot " ) , " set_one_shot " , " get_one_shot " ) ;
2018-05-16 12:13:41 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " preprocess " , PROPERTY_HINT_EXP_RANGE , " 0.00,600.0,0.01 " ) , " set_pre_process_time " , " get_pre_process_time " ) ;
2018-08-24 16:10:47 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " speed_scale " , PROPERTY_HINT_RANGE , " 0,64,0.01 " ) , " set_speed_scale " , " get_speed_scale " ) ;
2017-04-07 02:36:37 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " explosiveness " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_explosiveness_ratio " , " get_explosiveness_ratio " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " randomness " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_randomness_ratio " , " get_randomness_ratio " ) ;
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 " ) ;
2017-06-25 21:57:28 +00:00
ADD_GROUP ( " Drawing " , " " ) ;
2017-11-17 02:09:00 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : AABB , " visibility_aabb " ) , " set_visibility_aabb " , " get_visibility_aabb " ) ;
2017-06-25 21:57:28 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " local_coords " ) , " set_use_local_coordinates " , " get_use_local_coordinates " ) ;
2017-04-07 02:36:37 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " draw_order " , PROPERTY_HINT_ENUM , " Index,Lifetime,View Depth " ) , " set_draw_order " , " get_draw_order " ) ;
2017-04-09 01:38:11 +00:00
ADD_GROUP ( " Process Material " , " " ) ;
2017-06-22 12:17:06 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " process_material " , PROPERTY_HINT_RESOURCE_TYPE , " ShaderMaterial,ParticlesMaterial " ) , " set_process_material " , " get_process_material " ) ;
2017-04-07 02:36:37 +00:00
ADD_GROUP ( " Draw Passes " , " draw_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " draw_passes " , PROPERTY_HINT_RANGE , " 0, " + itos ( MAX_DRAW_PASSES ) + " ,1 " ) , " set_draw_passes " , " get_draw_passes " ) ;
for ( int i = 0 ; i < MAX_DRAW_PASSES ; i + + ) {
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " draw_pass_ " + itos ( i + 1 ) , PROPERTY_HINT_RESOURCE_TYPE , " Mesh " ) , " set_draw_pass_mesh " , " get_draw_pass_mesh " , i ) ;
}
2017-08-20 15:45:01 +00:00
BIND_ENUM_CONSTANT ( DRAW_ORDER_INDEX ) ;
BIND_ENUM_CONSTANT ( DRAW_ORDER_LIFETIME ) ;
BIND_ENUM_CONSTANT ( DRAW_ORDER_VIEW_DEPTH ) ;
2017-04-07 02:36:37 +00:00
BIND_CONSTANT ( MAX_DRAW_PASSES ) ;
}
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
Particles : : Particles ( ) {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
particles = VS : : get_singleton ( ) - > particles_create ( ) ;
set_base ( particles ) ;
2019-07-02 14:23:54 +00:00
one_shot = false ; // Needed so that set_emitting doesn't access uninitialized values
2017-04-07 02:36:37 +00:00
set_emitting ( true ) ;
2017-06-25 11:01:15 +00:00
set_one_shot ( false ) ;
2017-04-09 01:38:11 +00:00
set_amount ( 8 ) ;
2017-04-07 02:36:37 +00:00
set_lifetime ( 1 ) ;
set_fixed_fps ( 0 ) ;
set_fractional_delta ( true ) ;
set_pre_process_time ( 0 ) ;
set_explosiveness_ratio ( 0 ) ;
set_randomness_ratio ( 0 ) ;
2017-11-17 02:09:00 +00:00
set_visibility_aabb ( AABB ( Vector3 ( - 4 , - 4 , - 4 ) , Vector3 ( 8 , 8 , 8 ) ) ) ;
2017-04-07 02:36:37 +00:00
set_use_local_coordinates ( true ) ;
set_draw_passes ( 1 ) ;
2017-04-09 01:38:11 +00:00
set_draw_order ( DRAW_ORDER_INDEX ) ;
set_speed_scale ( 1 ) ;
2014-02-10 01:10:30 +00:00
}
2016-03-08 23:00:52 +00:00
2017-04-07 02:36:37 +00:00
Particles : : ~ Particles ( ) {
2014-02-10 01:10:30 +00:00
2017-04-07 02:36:37 +00:00
VS : : get_singleton ( ) - > free ( particles ) ;
2014-02-10 01:10:30 +00:00
}