gpu_particles_3d.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. /**************************************************************************/
  2. /* gpu_particles_3d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "gpu_particles_3d.h"
  31. #include "gpu_particles_3d.compat.inc"
  32. #include "scene/3d/cpu_particles_3d.h"
  33. #include "scene/resources/curve_texture.h"
  34. #include "scene/resources/gradient_texture.h"
  35. #include "scene/resources/mesh.h"
  36. #include "scene/resources/particle_process_material.h"
  37. AABB GPUParticles3D::get_aabb() const {
  38. return AABB();
  39. }
  40. void GPUParticles3D::set_emitting(bool p_emitting) {
  41. // Do not return even if `p_emitting == emitting` because `emitting` is just an approximation.
  42. if (p_emitting && p_emitting != emitting && !use_fixed_seed && one_shot) {
  43. set_seed(Math::rand());
  44. }
  45. if (p_emitting && one_shot) {
  46. if (!active && !emitting) {
  47. // Last cycle ended.
  48. active = true;
  49. time = 0;
  50. signal_canceled = false;
  51. emission_time = lifetime;
  52. active_time = lifetime * (2 - explosiveness_ratio);
  53. } else {
  54. signal_canceled = true;
  55. }
  56. set_process_internal(true);
  57. } else if (!p_emitting) {
  58. if (one_shot) {
  59. set_process_internal(true);
  60. } else {
  61. set_process_internal(false);
  62. }
  63. } else {
  64. set_process_internal(true);
  65. }
  66. emitting = p_emitting;
  67. RS::get_singleton()->particles_set_emitting(particles, p_emitting);
  68. }
  69. void GPUParticles3D::set_amount(int p_amount) {
  70. ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1.");
  71. amount = p_amount;
  72. RS::get_singleton()->particles_set_amount(particles, amount);
  73. }
  74. void GPUParticles3D::set_lifetime(double p_lifetime) {
  75. ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0.");
  76. lifetime = p_lifetime;
  77. RS::get_singleton()->particles_set_lifetime(particles, lifetime);
  78. }
  79. void GPUParticles3D::set_interp_to_end(float p_interp) {
  80. interp_to_end_factor = CLAMP(p_interp, 0.0, 1.0);
  81. RS::get_singleton()->particles_set_interp_to_end(particles, interp_to_end_factor);
  82. }
  83. void GPUParticles3D::set_one_shot(bool p_one_shot) {
  84. one_shot = p_one_shot;
  85. RS::get_singleton()->particles_set_one_shot(particles, one_shot);
  86. if (is_emitting()) {
  87. if (!one_shot) {
  88. RenderingServer::get_singleton()->particles_restart(particles);
  89. }
  90. }
  91. }
  92. void GPUParticles3D::set_use_fixed_seed(bool p_use_fixed_seed) {
  93. if (p_use_fixed_seed == use_fixed_seed) {
  94. return;
  95. }
  96. use_fixed_seed = p_use_fixed_seed;
  97. notify_property_list_changed();
  98. }
  99. bool GPUParticles3D::get_use_fixed_seed() const {
  100. return use_fixed_seed;
  101. }
  102. void GPUParticles3D::set_seed(uint32_t p_seed) {
  103. seed = p_seed;
  104. RS::get_singleton()->particles_set_seed(particles, p_seed);
  105. }
  106. uint32_t GPUParticles3D::get_seed() const {
  107. return seed;
  108. }
  109. void GPUParticles3D::set_pre_process_time(double p_time) {
  110. pre_process_time = p_time;
  111. RS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time);
  112. }
  113. void GPUParticles3D::set_explosiveness_ratio(real_t p_ratio) {
  114. explosiveness_ratio = p_ratio;
  115. RS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio);
  116. }
  117. void GPUParticles3D::set_randomness_ratio(real_t p_ratio) {
  118. randomness_ratio = p_ratio;
  119. RS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio);
  120. }
  121. void GPUParticles3D::set_visibility_aabb(const AABB &p_aabb) {
  122. visibility_aabb = p_aabb;
  123. RS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb);
  124. update_gizmos();
  125. }
  126. void GPUParticles3D::set_use_local_coordinates(bool p_enable) {
  127. local_coords = p_enable;
  128. RS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords);
  129. }
  130. void GPUParticles3D::set_process_material(const Ref<Material> &p_material) {
  131. #ifdef TOOLS_ENABLED
  132. if (process_material.is_valid()) {
  133. if (Ref<ParticleProcessMaterial>(process_material).is_valid()) {
  134. process_material->disconnect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
  135. }
  136. }
  137. #endif
  138. process_material = p_material;
  139. RID material_rid;
  140. if (process_material.is_valid()) {
  141. material_rid = process_material->get_rid();
  142. #ifdef TOOLS_ENABLED
  143. if (Ref<ParticleProcessMaterial>(process_material).is_valid()) {
  144. process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
  145. }
  146. #endif
  147. }
  148. RS::get_singleton()->particles_set_process_material(particles, material_rid);
  149. update_configuration_warnings();
  150. }
  151. void GPUParticles3D::set_speed_scale(double p_scale) {
  152. speed_scale = p_scale;
  153. RS::get_singleton()->particles_set_speed_scale(particles, p_scale);
  154. }
  155. void GPUParticles3D::set_collision_base_size(real_t p_size) {
  156. collision_base_size = p_size;
  157. RS::get_singleton()->particles_set_collision_base_size(particles, p_size);
  158. }
  159. bool GPUParticles3D::is_emitting() const {
  160. return emitting;
  161. }
  162. int GPUParticles3D::get_amount() const {
  163. return amount;
  164. }
  165. double GPUParticles3D::get_lifetime() const {
  166. return lifetime;
  167. }
  168. float GPUParticles3D::get_interp_to_end() const {
  169. return interp_to_end_factor;
  170. }
  171. bool GPUParticles3D::get_one_shot() const {
  172. return one_shot;
  173. }
  174. double GPUParticles3D::get_pre_process_time() const {
  175. return pre_process_time;
  176. }
  177. real_t GPUParticles3D::get_explosiveness_ratio() const {
  178. return explosiveness_ratio;
  179. }
  180. real_t GPUParticles3D::get_randomness_ratio() const {
  181. return randomness_ratio;
  182. }
  183. AABB GPUParticles3D::get_visibility_aabb() const {
  184. return visibility_aabb;
  185. }
  186. bool GPUParticles3D::get_use_local_coordinates() const {
  187. return local_coords;
  188. }
  189. Ref<Material> GPUParticles3D::get_process_material() const {
  190. return process_material;
  191. }
  192. double GPUParticles3D::get_speed_scale() const {
  193. return speed_scale;
  194. }
  195. real_t GPUParticles3D::get_collision_base_size() const {
  196. return collision_base_size;
  197. }
  198. void GPUParticles3D::set_draw_order(DrawOrder p_order) {
  199. draw_order = p_order;
  200. RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order));
  201. }
  202. void GPUParticles3D::set_trail_enabled(bool p_enabled) {
  203. trail_enabled = p_enabled;
  204. RS::get_singleton()->particles_set_trails(particles, trail_enabled, trail_lifetime);
  205. update_configuration_warnings();
  206. }
  207. void GPUParticles3D::set_trail_lifetime(double p_seconds) {
  208. ERR_FAIL_COND(p_seconds < 0.01 - CMP_EPSILON);
  209. trail_lifetime = p_seconds;
  210. RS::get_singleton()->particles_set_trails(particles, trail_enabled, trail_lifetime);
  211. }
  212. bool GPUParticles3D::is_trail_enabled() const {
  213. return trail_enabled;
  214. }
  215. double GPUParticles3D::get_trail_lifetime() const {
  216. return trail_lifetime;
  217. }
  218. GPUParticles3D::DrawOrder GPUParticles3D::get_draw_order() const {
  219. return draw_order;
  220. }
  221. void GPUParticles3D::set_draw_passes(int p_count) {
  222. ERR_FAIL_COND(p_count < 1);
  223. for (int i = p_count; i < draw_passes.size(); i++) {
  224. set_draw_pass_mesh(i, Ref<Mesh>());
  225. }
  226. draw_passes.resize(p_count);
  227. RS::get_singleton()->particles_set_draw_passes(particles, p_count);
  228. notify_property_list_changed();
  229. }
  230. int GPUParticles3D::get_draw_passes() const {
  231. return draw_passes.size();
  232. }
  233. void GPUParticles3D::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) {
  234. ERR_FAIL_INDEX(p_pass, draw_passes.size());
  235. if (Engine::get_singleton()->is_editor_hint() && draw_passes.write[p_pass].is_valid()) {
  236. draw_passes.write[p_pass]->disconnect_changed(callable_mp((Node *)this, &Node::update_configuration_warnings));
  237. }
  238. draw_passes.write[p_pass] = p_mesh;
  239. if (Engine::get_singleton()->is_editor_hint() && draw_passes.write[p_pass].is_valid()) {
  240. draw_passes.write[p_pass]->connect_changed(callable_mp((Node *)this, &Node::update_configuration_warnings), CONNECT_DEFERRED);
  241. }
  242. RID mesh_rid;
  243. if (p_mesh.is_valid()) {
  244. mesh_rid = p_mesh->get_rid();
  245. }
  246. RS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid);
  247. _skinning_changed();
  248. update_configuration_warnings();
  249. }
  250. Ref<Mesh> GPUParticles3D::get_draw_pass_mesh(int p_pass) const {
  251. ERR_FAIL_INDEX_V(p_pass, draw_passes.size(), Ref<Mesh>());
  252. return draw_passes[p_pass];
  253. }
  254. void GPUParticles3D::set_fixed_fps(int p_count) {
  255. fixed_fps = p_count;
  256. RS::get_singleton()->particles_set_fixed_fps(particles, p_count);
  257. }
  258. int GPUParticles3D::get_fixed_fps() const {
  259. return fixed_fps;
  260. }
  261. void GPUParticles3D::set_fractional_delta(bool p_enable) {
  262. fractional_delta = p_enable;
  263. RS::get_singleton()->particles_set_fractional_delta(particles, p_enable);
  264. }
  265. bool GPUParticles3D::get_fractional_delta() const {
  266. return fractional_delta;
  267. }
  268. void GPUParticles3D::set_interpolate(bool p_enable) {
  269. interpolate = p_enable;
  270. RS::get_singleton()->particles_set_interpolate(particles, p_enable);
  271. }
  272. bool GPUParticles3D::get_interpolate() const {
  273. return interpolate;
  274. }
  275. PackedStringArray GPUParticles3D::get_configuration_warnings() const {
  276. PackedStringArray warnings = GeometryInstance3D::get_configuration_warnings();
  277. bool meshes_found = false;
  278. bool anim_material_found = false;
  279. for (int i = 0; i < draw_passes.size(); i++) {
  280. if (draw_passes[i].is_valid()) {
  281. meshes_found = true;
  282. for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) {
  283. anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != nullptr;
  284. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(draw_passes[i]->surface_get_material(j).ptr());
  285. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
  286. }
  287. if (anim_material_found) {
  288. break;
  289. }
  290. }
  291. }
  292. anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr;
  293. {
  294. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(get_material_override().ptr());
  295. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == BaseMaterial3D::BILLBOARD_PARTICLES);
  296. }
  297. if (!meshes_found) {
  298. warnings.push_back(RTR("Nothing is visible because meshes have not been assigned to draw passes."));
  299. }
  300. if (process_material.is_null()) {
  301. warnings.push_back(RTR("A material to process the particles is not assigned, so no behavior is imprinted."));
  302. } else {
  303. const ParticleProcessMaterial *process = Object::cast_to<ParticleProcessMaterial>(process_material.ptr());
  304. if (!anim_material_found && process &&
  305. (process->get_param_max(ParticleProcessMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param_max(ParticleProcessMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
  306. process->get_param_texture(ParticleProcessMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticleProcessMaterial::PARAM_ANIM_OFFSET).is_valid())) {
  307. warnings.push_back(RTR("Particles animation requires the usage of a BaseMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."));
  308. }
  309. }
  310. if (trail_enabled) {
  311. int dp_count = 0;
  312. bool missing_trails = false;
  313. bool no_materials = false;
  314. for (int i = 0; i < draw_passes.size(); i++) {
  315. Ref<Mesh> draw_pass = draw_passes[i];
  316. if (draw_pass.is_valid() && draw_pass->get_builtin_bind_pose_count() > 0) {
  317. dp_count++;
  318. }
  319. if (draw_pass.is_valid()) {
  320. int mats_found = 0;
  321. for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) {
  322. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(draw_passes[i]->surface_get_material(j).ptr());
  323. if (spat) {
  324. mats_found++;
  325. }
  326. if (spat && !spat->get_flag(BaseMaterial3D::FLAG_PARTICLE_TRAILS_MODE)) {
  327. missing_trails = true;
  328. }
  329. }
  330. if (mats_found != draw_passes[i]->get_surface_count()) {
  331. no_materials = true;
  332. }
  333. }
  334. }
  335. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(get_material_override().ptr());
  336. if (spat) {
  337. no_materials = false;
  338. }
  339. if (spat && !spat->get_flag(BaseMaterial3D::FLAG_PARTICLE_TRAILS_MODE)) {
  340. missing_trails = true;
  341. }
  342. if (dp_count && skin.is_valid()) {
  343. warnings.push_back(RTR("Using Trail meshes with a skin causes Skin to override Trail poses. Suggest removing the Skin."));
  344. } else if (dp_count == 0 && skin.is_null()) {
  345. warnings.push_back(RTR("Trails active, but neither Trail meshes or a Skin were found."));
  346. } else if (dp_count > 1) {
  347. warnings.push_back(RTR("Only one Trail mesh is supported. If you want to use more than a single mesh, a Skin is needed (see documentation)."));
  348. }
  349. if ((dp_count || skin.is_valid()) && (missing_trails || no_materials)) {
  350. warnings.push_back(RTR("Trails enabled, but one or more mesh materials are either missing or not set for trails rendering."));
  351. }
  352. if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" || OS::get_singleton()->get_current_rendering_method() == "dummy") {
  353. warnings.push_back(RTR("Particle trails are only available when using the Forward+ or Mobile renderer."));
  354. }
  355. }
  356. if (sub_emitter != NodePath() && (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" || OS::get_singleton()->get_current_rendering_method() == "dummy")) {
  357. warnings.push_back(RTR("Particle sub-emitters are only available when using the Forward+ or Mobile renderer."));
  358. }
  359. return warnings;
  360. }
  361. void GPUParticles3D::restart(bool p_keep_seed) {
  362. if (!p_keep_seed && !use_fixed_seed) {
  363. set_seed(Math::rand());
  364. }
  365. RenderingServer::get_singleton()->particles_restart(particles);
  366. RenderingServer::get_singleton()->particles_set_emitting(particles, true);
  367. emitting = true;
  368. active = true;
  369. signal_canceled = false;
  370. time = 0;
  371. emission_time = lifetime * (1 - explosiveness_ratio);
  372. active_time = lifetime * (2 - explosiveness_ratio);
  373. set_process_internal(true);
  374. }
  375. AABB GPUParticles3D::capture_aabb() const {
  376. return RS::get_singleton()->particles_get_current_aabb(particles);
  377. }
  378. void GPUParticles3D::_validate_property(PropertyInfo &p_property) const {
  379. if (Engine::get_singleton()->is_editor_hint() && p_property.name == "emitting") {
  380. p_property.hint = one_shot ? PROPERTY_HINT_ONESHOT : PROPERTY_HINT_NONE;
  381. }
  382. if (p_property.name.begins_with("draw_pass_")) {
  383. int index = p_property.name.get_slicec('_', 2).to_int() - 1;
  384. if (index >= draw_passes.size()) {
  385. p_property.usage = PROPERTY_USAGE_NONE;
  386. return;
  387. }
  388. }
  389. if (p_property.name == "seed" && !use_fixed_seed) {
  390. p_property.usage = PROPERTY_USAGE_NONE;
  391. }
  392. }
  393. void GPUParticles3D::request_particles_process(real_t p_requested_process_time) {
  394. RS::get_singleton()->particles_request_process_time(particles, p_requested_process_time);
  395. }
  396. void GPUParticles3D::emit_particle(const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) {
  397. RS::get_singleton()->particles_emit(particles, p_transform, p_velocity, p_color, p_custom, p_emit_flags);
  398. }
  399. void GPUParticles3D::_attach_sub_emitter() {
  400. Node *n = get_node_or_null(sub_emitter);
  401. if (n) {
  402. GPUParticles3D *sen = Object::cast_to<GPUParticles3D>(n);
  403. if (sen && sen != this) {
  404. RS::get_singleton()->particles_set_subemitter(particles, sen->particles);
  405. }
  406. }
  407. }
  408. void GPUParticles3D::set_sub_emitter(const NodePath &p_path) {
  409. if (is_inside_tree()) {
  410. RS::get_singleton()->particles_set_subemitter(particles, RID());
  411. }
  412. sub_emitter = p_path;
  413. if (is_inside_tree() && sub_emitter != NodePath()) {
  414. _attach_sub_emitter();
  415. }
  416. update_configuration_warnings();
  417. }
  418. NodePath GPUParticles3D::get_sub_emitter() const {
  419. return sub_emitter;
  420. }
  421. void GPUParticles3D::_notification(int p_what) {
  422. switch (p_what) {
  423. // Use internal process when emitting and one_shot is on so that when
  424. // the shot ends the editor can properly update.
  425. case NOTIFICATION_INTERNAL_PROCESS: {
  426. const Vector3 velocity = (get_global_position() - previous_position) / get_process_delta_time();
  427. if (velocity != previous_velocity) {
  428. RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
  429. previous_velocity = velocity;
  430. }
  431. previous_position = get_global_position();
  432. if (one_shot) {
  433. time += get_process_delta_time();
  434. if (time > emission_time) {
  435. emitting = false;
  436. if (!active) {
  437. set_process_internal(false);
  438. }
  439. }
  440. if (time > active_time) {
  441. if (active && !signal_canceled) {
  442. emit_signal(SceneStringName(finished));
  443. }
  444. active = false;
  445. if (!emitting) {
  446. set_process_internal(false);
  447. }
  448. }
  449. }
  450. } break;
  451. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  452. // Update velocity in physics process, so that velocity calculations remain correct
  453. // if the physics tick rate is lower than the rendered framerate (especially without physics interpolation).
  454. const Vector3 velocity = (get_global_position() - previous_position) / get_physics_process_delta_time();
  455. if (velocity != previous_velocity) {
  456. RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
  457. previous_velocity = velocity;
  458. }
  459. previous_position = get_global_position();
  460. } break;
  461. case NOTIFICATION_ENTER_TREE: {
  462. set_process_internal(false);
  463. set_physics_process_internal(false);
  464. if (sub_emitter != NodePath()) {
  465. _attach_sub_emitter();
  466. }
  467. if (can_process()) {
  468. RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
  469. } else {
  470. RS::get_singleton()->particles_set_speed_scale(particles, 0);
  471. }
  472. previous_position = get_global_transform().origin;
  473. set_process_internal(true);
  474. set_physics_process_internal(true);
  475. } break;
  476. case NOTIFICATION_EXIT_TREE: {
  477. RS::get_singleton()->particles_set_subemitter(particles, RID());
  478. } break;
  479. case NOTIFICATION_SUSPENDED:
  480. case NOTIFICATION_UNSUSPENDED:
  481. case NOTIFICATION_PAUSED:
  482. case NOTIFICATION_UNPAUSED: {
  483. if (is_inside_tree()) {
  484. if (can_process()) {
  485. RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
  486. } else {
  487. RS::get_singleton()->particles_set_speed_scale(particles, 0);
  488. }
  489. }
  490. } break;
  491. case NOTIFICATION_VISIBILITY_CHANGED: {
  492. // Make sure particles are updated before rendering occurs if they were active before.
  493. if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {
  494. RS::get_singleton()->particles_request_process(particles);
  495. }
  496. } break;
  497. }
  498. }
  499. void GPUParticles3D::_skinning_changed() {
  500. Vector<Transform3D> xforms;
  501. if (skin.is_valid()) {
  502. xforms.resize(skin->get_bind_count());
  503. for (int i = 0; i < skin->get_bind_count(); i++) {
  504. xforms.write[i] = skin->get_bind_pose(i);
  505. }
  506. } else {
  507. for (int i = 0; i < draw_passes.size(); i++) {
  508. Ref<Mesh> draw_pass = draw_passes[i];
  509. if (draw_pass.is_valid() && draw_pass->get_builtin_bind_pose_count() > 0) {
  510. xforms.resize(draw_pass->get_builtin_bind_pose_count());
  511. for (int j = 0; j < draw_pass->get_builtin_bind_pose_count(); j++) {
  512. xforms.write[j] = draw_pass->get_builtin_bind_pose(j);
  513. }
  514. break;
  515. }
  516. }
  517. }
  518. RS::get_singleton()->particles_set_trail_bind_poses(particles, xforms);
  519. update_configuration_warnings();
  520. }
  521. void GPUParticles3D::set_skin(const Ref<Skin> &p_skin) {
  522. skin = p_skin;
  523. _skinning_changed();
  524. }
  525. Ref<Skin> GPUParticles3D::get_skin() const {
  526. return skin;
  527. }
  528. void GPUParticles3D::set_transform_align(TransformAlign p_align) {
  529. ERR_FAIL_INDEX(uint32_t(p_align), 4);
  530. transform_align = p_align;
  531. RS::get_singleton()->particles_set_transform_align(particles, RS::ParticlesTransformAlign(transform_align));
  532. }
  533. GPUParticles3D::TransformAlign GPUParticles3D::get_transform_align() const {
  534. return transform_align;
  535. }
  536. void GPUParticles3D::convert_from_particles(Node *p_particles) {
  537. CPUParticles3D *cpu_particles = Object::cast_to<CPUParticles3D>(p_particles);
  538. ERR_FAIL_NULL_MSG(cpu_particles, "Only CPUParticles3D nodes can be converted to GPUParticles3D.");
  539. set_emitting(cpu_particles->is_emitting());
  540. set_amount(cpu_particles->get_amount());
  541. set_lifetime(cpu_particles->get_lifetime());
  542. set_one_shot(cpu_particles->get_one_shot());
  543. set_pre_process_time(cpu_particles->get_pre_process_time());
  544. set_explosiveness_ratio(cpu_particles->get_explosiveness_ratio());
  545. set_randomness_ratio(cpu_particles->get_randomness_ratio());
  546. set_use_local_coordinates(cpu_particles->get_use_local_coordinates());
  547. set_fixed_fps(cpu_particles->get_fixed_fps());
  548. set_fractional_delta(cpu_particles->get_fractional_delta());
  549. set_speed_scale(cpu_particles->get_speed_scale());
  550. set_draw_order(DrawOrder(cpu_particles->get_draw_order()));
  551. set_draw_pass_mesh(0, cpu_particles->get_mesh());
  552. Ref<ParticleProcessMaterial> proc_mat = memnew(ParticleProcessMaterial);
  553. set_process_material(proc_mat);
  554. proc_mat->set_direction(cpu_particles->get_direction());
  555. proc_mat->set_spread(cpu_particles->get_spread());
  556. proc_mat->set_flatness(cpu_particles->get_flatness());
  557. proc_mat->set_color(cpu_particles->get_color());
  558. Ref<Gradient> grad = cpu_particles->get_color_ramp();
  559. if (grad.is_valid()) {
  560. Ref<GradientTexture1D> tex = memnew(GradientTexture1D);
  561. tex->set_gradient(grad);
  562. proc_mat->set_color_ramp(tex);
  563. }
  564. Ref<Gradient> grad_init = cpu_particles->get_color_initial_ramp();
  565. if (grad_init.is_valid()) {
  566. Ref<GradientTexture1D> tex = memnew(GradientTexture1D);
  567. tex->set_gradient(grad_init);
  568. proc_mat->set_color_initial_ramp(tex);
  569. }
  570. proc_mat->set_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY, cpu_particles->get_particle_flag(CPUParticles3D::PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY));
  571. proc_mat->set_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ROTATE_Y, cpu_particles->get_particle_flag(CPUParticles3D::PARTICLE_FLAG_ROTATE_Y));
  572. proc_mat->set_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_DISABLE_Z, cpu_particles->get_particle_flag(CPUParticles3D::PARTICLE_FLAG_DISABLE_Z));
  573. proc_mat->set_emission_shape(ParticleProcessMaterial::EmissionShape(cpu_particles->get_emission_shape()));
  574. proc_mat->set_emission_sphere_radius(cpu_particles->get_emission_sphere_radius());
  575. proc_mat->set_emission_box_extents(cpu_particles->get_emission_box_extents());
  576. proc_mat->set_emission_ring_height(cpu_particles->get_emission_ring_height());
  577. proc_mat->set_emission_ring_radius(cpu_particles->get_emission_ring_radius());
  578. proc_mat->set_emission_ring_inner_radius(cpu_particles->get_emission_ring_inner_radius());
  579. proc_mat->set_emission_ring_cone_angle(cpu_particles->get_emission_ring_cone_angle());
  580. if (cpu_particles->get_split_scale()) {
  581. Ref<CurveXYZTexture> scale3D = memnew(CurveXYZTexture);
  582. scale3D->set_curve_x(cpu_particles->get_scale_curve_x());
  583. scale3D->set_curve_y(cpu_particles->get_scale_curve_y());
  584. scale3D->set_curve_z(cpu_particles->get_scale_curve_z());
  585. proc_mat->set_param_texture(ParticleProcessMaterial::PARAM_SCALE, scale3D);
  586. }
  587. proc_mat->set_gravity(cpu_particles->get_gravity());
  588. proc_mat->set_lifetime_randomness(cpu_particles->get_lifetime_randomness());
  589. #define CONVERT_PARAM(m_param) \
  590. proc_mat->set_param_min(ParticleProcessMaterial::m_param, cpu_particles->get_param_min(CPUParticles3D::m_param)); \
  591. { \
  592. Ref<Curve> curve = cpu_particles->get_param_curve(CPUParticles3D::m_param); \
  593. if (curve.is_valid()) { \
  594. Ref<CurveTexture> tex = memnew(CurveTexture); \
  595. tex->set_curve(curve); \
  596. proc_mat->set_param_texture(ParticleProcessMaterial::m_param, tex); \
  597. } \
  598. } \
  599. proc_mat->set_param_max(ParticleProcessMaterial::m_param, cpu_particles->get_param_max(CPUParticles3D::m_param));
  600. CONVERT_PARAM(PARAM_INITIAL_LINEAR_VELOCITY);
  601. CONVERT_PARAM(PARAM_ANGULAR_VELOCITY);
  602. CONVERT_PARAM(PARAM_ORBIT_VELOCITY);
  603. CONVERT_PARAM(PARAM_LINEAR_ACCEL);
  604. CONVERT_PARAM(PARAM_RADIAL_ACCEL);
  605. CONVERT_PARAM(PARAM_TANGENTIAL_ACCEL);
  606. CONVERT_PARAM(PARAM_DAMPING);
  607. CONVERT_PARAM(PARAM_ANGLE);
  608. CONVERT_PARAM(PARAM_SCALE);
  609. CONVERT_PARAM(PARAM_HUE_VARIATION);
  610. CONVERT_PARAM(PARAM_ANIM_SPEED);
  611. CONVERT_PARAM(PARAM_ANIM_OFFSET);
  612. #undef CONVERT_PARAM
  613. }
  614. void GPUParticles3D::set_amount_ratio(float p_ratio) {
  615. amount_ratio = p_ratio;
  616. RS::get_singleton()->particles_set_amount_ratio(particles, p_ratio);
  617. }
  618. float GPUParticles3D::get_amount_ratio() const {
  619. return amount_ratio;
  620. }
  621. void GPUParticles3D::_bind_methods() {
  622. ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles3D::set_emitting);
  623. ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles3D::set_amount);
  624. ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &GPUParticles3D::set_lifetime);
  625. ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &GPUParticles3D::set_one_shot);
  626. ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &GPUParticles3D::set_pre_process_time);
  627. ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &GPUParticles3D::set_explosiveness_ratio);
  628. ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &GPUParticles3D::set_randomness_ratio);
  629. ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &GPUParticles3D::set_visibility_aabb);
  630. ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &GPUParticles3D::set_use_local_coordinates);
  631. ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &GPUParticles3D::set_fixed_fps);
  632. ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles3D::set_fractional_delta);
  633. ClassDB::bind_method(D_METHOD("set_interpolate", "enable"), &GPUParticles3D::set_interpolate);
  634. ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles3D::set_process_material);
  635. ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles3D::set_speed_scale);
  636. ClassDB::bind_method(D_METHOD("set_collision_base_size", "size"), &GPUParticles3D::set_collision_base_size);
  637. ClassDB::bind_method(D_METHOD("set_interp_to_end", "interp"), &GPUParticles3D::set_interp_to_end);
  638. ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles3D::is_emitting);
  639. ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles3D::get_amount);
  640. ClassDB::bind_method(D_METHOD("get_lifetime"), &GPUParticles3D::get_lifetime);
  641. ClassDB::bind_method(D_METHOD("get_one_shot"), &GPUParticles3D::get_one_shot);
  642. ClassDB::bind_method(D_METHOD("get_pre_process_time"), &GPUParticles3D::get_pre_process_time);
  643. ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &GPUParticles3D::get_explosiveness_ratio);
  644. ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &GPUParticles3D::get_randomness_ratio);
  645. ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &GPUParticles3D::get_visibility_aabb);
  646. ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &GPUParticles3D::get_use_local_coordinates);
  647. ClassDB::bind_method(D_METHOD("get_fixed_fps"), &GPUParticles3D::get_fixed_fps);
  648. ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles3D::get_fractional_delta);
  649. ClassDB::bind_method(D_METHOD("get_interpolate"), &GPUParticles3D::get_interpolate);
  650. ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles3D::get_process_material);
  651. ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles3D::get_speed_scale);
  652. ClassDB::bind_method(D_METHOD("get_collision_base_size"), &GPUParticles3D::get_collision_base_size);
  653. ClassDB::bind_method(D_METHOD("get_interp_to_end"), &GPUParticles3D::get_interp_to_end);
  654. ClassDB::bind_method(D_METHOD("set_use_fixed_seed", "use_fixed_seed"), &GPUParticles3D::set_use_fixed_seed);
  655. ClassDB::bind_method(D_METHOD("get_use_fixed_seed"), &GPUParticles3D::get_use_fixed_seed);
  656. ClassDB::bind_method(D_METHOD("set_seed", "seed"), &GPUParticles3D::set_seed);
  657. ClassDB::bind_method(D_METHOD("get_seed"), &GPUParticles3D::get_seed);
  658. ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &GPUParticles3D::set_draw_order);
  659. ClassDB::bind_method(D_METHOD("get_draw_order"), &GPUParticles3D::get_draw_order);
  660. ClassDB::bind_method(D_METHOD("set_draw_passes", "passes"), &GPUParticles3D::set_draw_passes);
  661. ClassDB::bind_method(D_METHOD("set_draw_pass_mesh", "pass", "mesh"), &GPUParticles3D::set_draw_pass_mesh);
  662. ClassDB::bind_method(D_METHOD("get_draw_passes"), &GPUParticles3D::get_draw_passes);
  663. ClassDB::bind_method(D_METHOD("get_draw_pass_mesh", "pass"), &GPUParticles3D::get_draw_pass_mesh);
  664. ClassDB::bind_method(D_METHOD("set_skin", "skin"), &GPUParticles3D::set_skin);
  665. ClassDB::bind_method(D_METHOD("get_skin"), &GPUParticles3D::get_skin);
  666. ClassDB::bind_method(D_METHOD("restart", "keep_seed"), &GPUParticles3D::restart, DEFVAL(false));
  667. ClassDB::bind_method(D_METHOD("capture_aabb"), &GPUParticles3D::capture_aabb);
  668. ClassDB::bind_method(D_METHOD("set_sub_emitter", "path"), &GPUParticles3D::set_sub_emitter);
  669. ClassDB::bind_method(D_METHOD("get_sub_emitter"), &GPUParticles3D::get_sub_emitter);
  670. ClassDB::bind_method(D_METHOD("emit_particle", "xform", "velocity", "color", "custom", "flags"), &GPUParticles3D::emit_particle);
  671. ClassDB::bind_method(D_METHOD("set_trail_enabled", "enabled"), &GPUParticles3D::set_trail_enabled);
  672. ClassDB::bind_method(D_METHOD("set_trail_lifetime", "secs"), &GPUParticles3D::set_trail_lifetime);
  673. ClassDB::bind_method(D_METHOD("is_trail_enabled"), &GPUParticles3D::is_trail_enabled);
  674. ClassDB::bind_method(D_METHOD("get_trail_lifetime"), &GPUParticles3D::get_trail_lifetime);
  675. ClassDB::bind_method(D_METHOD("set_transform_align", "align"), &GPUParticles3D::set_transform_align);
  676. ClassDB::bind_method(D_METHOD("get_transform_align"), &GPUParticles3D::get_transform_align);
  677. ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &GPUParticles3D::convert_from_particles);
  678. ClassDB::bind_method(D_METHOD("set_amount_ratio", "ratio"), &GPUParticles3D::set_amount_ratio);
  679. ClassDB::bind_method(D_METHOD("get_amount_ratio"), &GPUParticles3D::get_amount_ratio);
  680. ClassDB::bind_method(D_METHOD("request_particles_process", "process_time"), &GPUParticles3D::request_particles_process);
  681. ADD_SIGNAL(MethodInfo("finished"));
  682. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting", PROPERTY_HINT_ONESHOT), "set_emitting", "is_emitting");
  683. ADD_PROPERTY_DEFAULT("emitting", true); // Workaround for doctool in headless mode, as dummy rasterizer always returns false.
  684. ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); // FIXME: Evaluate support for `exp` in integer properties, or remove this.
  685. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "amount_ratio", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_amount_ratio", "get_amount_ratio");
  686. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "sub_emitter", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GPUParticles3D"), "set_sub_emitter", "get_sub_emitter");
  687. ADD_GROUP("Time", "");
  688. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp,suffix:s"), "set_lifetime", "get_lifetime");
  689. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "interp_to_end", PROPERTY_HINT_RANGE, "0.00,1.0,0.01"), "set_interp_to_end", "get_interp_to_end");
  690. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
  691. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_RANGE, "0.00,10.0,0.01,or_greater,exp,suffix:s"), "set_pre_process_time", "get_pre_process_time");
  692. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
  693. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
  694. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
  695. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_fixed_seed"), "set_use_fixed_seed", "get_use_fixed_seed");
  696. ADD_PROPERTY(PropertyInfo(Variant::INT, "seed", PROPERTY_HINT_RANGE, "0," + itos(UINT32_MAX) + ",1"), "set_seed", "get_seed");
  697. ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1,suffix:FPS"), "set_fixed_fps", "get_fixed_fps");
  698. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interpolate"), "set_interpolate", "get_interpolate");
  699. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
  700. ADD_GROUP("Collision", "collision_");
  701. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_base_size", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater,suffix:m"), "set_collision_base_size", "get_collision_base_size");
  702. ADD_GROUP("Drawing", "");
  703. ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_aabb", PROPERTY_HINT_NONE, "suffix:m"), "set_visibility_aabb", "get_visibility_aabb");
  704. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
  705. ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime,Reverse Lifetime,View Depth"), "set_draw_order", "get_draw_order");
  706. ADD_PROPERTY(PropertyInfo(Variant::INT, "transform_align", PROPERTY_HINT_ENUM, "Disabled,Z-Billboard,Y to Velocity,Z-Billboard + Y to Velocity"), "set_transform_align", "get_transform_align");
  707. ADD_GROUP("Trails", "trail_");
  708. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "trail_enabled", PROPERTY_HINT_GROUP_ENABLE), "set_trail_enabled", "is_trail_enabled");
  709. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "trail_lifetime", PROPERTY_HINT_RANGE, "0.01,10,0.01,or_greater,suffix:s"), "set_trail_lifetime", "get_trail_lifetime");
  710. ADD_GROUP("Process Material", "");
  711. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ParticleProcessMaterial,ShaderMaterial"), "set_process_material", "get_process_material");
  712. ADD_GROUP("Draw Passes", "draw_");
  713. ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_passes", PROPERTY_HINT_RANGE, "0," + itos(MAX_DRAW_PASSES) + ",1"), "set_draw_passes", "get_draw_passes");
  714. for (int i = 0; i < MAX_DRAW_PASSES; i++) {
  715. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "draw_pass_" + itos(i + 1), PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_draw_pass_mesh", "get_draw_pass_mesh", i);
  716. }
  717. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "draw_skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
  718. BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
  719. BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
  720. BIND_ENUM_CONSTANT(DRAW_ORDER_REVERSE_LIFETIME);
  721. BIND_ENUM_CONSTANT(DRAW_ORDER_VIEW_DEPTH);
  722. BIND_ENUM_CONSTANT(EMIT_FLAG_POSITION);
  723. BIND_ENUM_CONSTANT(EMIT_FLAG_ROTATION_SCALE);
  724. BIND_ENUM_CONSTANT(EMIT_FLAG_VELOCITY);
  725. BIND_ENUM_CONSTANT(EMIT_FLAG_COLOR);
  726. BIND_ENUM_CONSTANT(EMIT_FLAG_CUSTOM);
  727. BIND_CONSTANT(MAX_DRAW_PASSES);
  728. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_DISABLED);
  729. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Z_BILLBOARD);
  730. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Y_TO_VELOCITY);
  731. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY);
  732. ADD_PROPERTY_DEFAULT("seed", 0);
  733. }
  734. GPUParticles3D::GPUParticles3D() {
  735. particles = RS::get_singleton()->particles_create();
  736. RS::get_singleton()->particles_set_mode(particles, RS::PARTICLES_MODE_3D);
  737. set_base(particles);
  738. one_shot = false; // Needed so that set_emitting doesn't access uninitialized values
  739. set_emitting(true);
  740. set_one_shot(false);
  741. set_seed(Math::rand());
  742. set_amount_ratio(1.0);
  743. set_amount(8);
  744. set_lifetime(1);
  745. set_fixed_fps(30);
  746. set_fractional_delta(true);
  747. set_interpolate(true);
  748. set_pre_process_time(0);
  749. set_explosiveness_ratio(0);
  750. set_randomness_ratio(0);
  751. set_trail_lifetime(0.3);
  752. set_visibility_aabb(AABB(Vector3(-4, -4, -4), Vector3(8, 8, 8)));
  753. set_use_local_coordinates(false);
  754. set_draw_passes(1);
  755. set_draw_order(DRAW_ORDER_INDEX);
  756. set_speed_scale(1);
  757. set_collision_base_size(collision_base_size);
  758. set_transform_align(TRANSFORM_ALIGN_DISABLED);
  759. set_use_fixed_seed(false);
  760. }
  761. GPUParticles3D::~GPUParticles3D() {
  762. ERR_FAIL_NULL(RenderingServer::get_singleton());
  763. RS::get_singleton()->free_rid(particles);
  764. }