cpu_particles_3d.cpp 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  1. /**************************************************************************/
  2. /* cpu_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 "cpu_particles_3d.h"
  31. #include "scene/3d/camera_3d.h"
  32. #include "scene/3d/gpu_particles_3d.h"
  33. #include "scene/main/viewport.h"
  34. #include "scene/resources/curve_texture.h"
  35. #include "scene/resources/gradient_texture.h"
  36. #include "scene/resources/image_texture.h"
  37. #include "scene/resources/particle_process_material.h"
  38. AABB CPUParticles3D::get_aabb() const {
  39. return AABB();
  40. }
  41. void CPUParticles3D::set_emitting(bool p_emitting) {
  42. if (emitting == p_emitting) {
  43. return;
  44. }
  45. emitting = p_emitting;
  46. if (emitting) {
  47. active = true;
  48. set_process_internal(true);
  49. // first update before rendering to avoid one frame delay after emitting starts
  50. if (time == 0) {
  51. _update_internal();
  52. }
  53. }
  54. }
  55. void CPUParticles3D::set_amount(int p_amount) {
  56. ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0.");
  57. particles.resize(p_amount);
  58. {
  59. Particle *w = particles.ptrw();
  60. for (int i = 0; i < p_amount; i++) {
  61. w[i].active = false;
  62. w[i].custom[3] = 1.0; // Make sure w component isn't garbage data and doesn't break shaders with CUSTOM.y/Custom.w
  63. }
  64. }
  65. particle_data.resize((12 + 4 + 4) * p_amount);
  66. RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1);
  67. RS::get_singleton()->multimesh_allocate_data(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_3D, true, true);
  68. particle_order.resize(p_amount);
  69. }
  70. void CPUParticles3D::set_lifetime(double p_lifetime) {
  71. ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0.");
  72. lifetime = p_lifetime;
  73. }
  74. void CPUParticles3D::set_one_shot(bool p_one_shot) {
  75. one_shot = p_one_shot;
  76. }
  77. void CPUParticles3D::set_pre_process_time(double p_time) {
  78. pre_process_time = p_time;
  79. }
  80. void CPUParticles3D::set_explosiveness_ratio(real_t p_ratio) {
  81. explosiveness_ratio = p_ratio;
  82. }
  83. void CPUParticles3D::set_randomness_ratio(real_t p_ratio) {
  84. randomness_ratio = p_ratio;
  85. }
  86. void CPUParticles3D::set_visibility_aabb(const AABB &p_aabb) {
  87. RS::get_singleton()->multimesh_set_custom_aabb(multimesh, p_aabb);
  88. visibility_aabb = p_aabb;
  89. update_gizmos();
  90. }
  91. void CPUParticles3D::set_lifetime_randomness(double p_random) {
  92. lifetime_randomness = p_random;
  93. }
  94. void CPUParticles3D::set_use_local_coordinates(bool p_enable) {
  95. local_coords = p_enable;
  96. }
  97. void CPUParticles3D::set_speed_scale(double p_scale) {
  98. speed_scale = p_scale;
  99. }
  100. bool CPUParticles3D::is_emitting() const {
  101. return emitting;
  102. }
  103. int CPUParticles3D::get_amount() const {
  104. return particles.size();
  105. }
  106. double CPUParticles3D::get_lifetime() const {
  107. return lifetime;
  108. }
  109. bool CPUParticles3D::get_one_shot() const {
  110. return one_shot;
  111. }
  112. double CPUParticles3D::get_pre_process_time() const {
  113. return pre_process_time;
  114. }
  115. real_t CPUParticles3D::get_explosiveness_ratio() const {
  116. return explosiveness_ratio;
  117. }
  118. real_t CPUParticles3D::get_randomness_ratio() const {
  119. return randomness_ratio;
  120. }
  121. AABB CPUParticles3D::get_visibility_aabb() const {
  122. return visibility_aabb;
  123. }
  124. double CPUParticles3D::get_lifetime_randomness() const {
  125. return lifetime_randomness;
  126. }
  127. bool CPUParticles3D::get_use_local_coordinates() const {
  128. return local_coords;
  129. }
  130. double CPUParticles3D::get_speed_scale() const {
  131. return speed_scale;
  132. }
  133. void CPUParticles3D::set_draw_order(DrawOrder p_order) {
  134. ERR_FAIL_INDEX(p_order, DRAW_ORDER_MAX);
  135. draw_order = p_order;
  136. }
  137. CPUParticles3D::DrawOrder CPUParticles3D::get_draw_order() const {
  138. return draw_order;
  139. }
  140. void CPUParticles3D::set_mesh(const Ref<Mesh> &p_mesh) {
  141. mesh = p_mesh;
  142. if (mesh.is_valid()) {
  143. RS::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid());
  144. } else {
  145. RS::get_singleton()->multimesh_set_mesh(multimesh, RID());
  146. }
  147. update_configuration_warnings();
  148. }
  149. Ref<Mesh> CPUParticles3D::get_mesh() const {
  150. return mesh;
  151. }
  152. void CPUParticles3D::set_fixed_fps(int p_count) {
  153. fixed_fps = p_count;
  154. }
  155. int CPUParticles3D::get_fixed_fps() const {
  156. return fixed_fps;
  157. }
  158. void CPUParticles3D::set_fractional_delta(bool p_enable) {
  159. fractional_delta = p_enable;
  160. }
  161. bool CPUParticles3D::get_fractional_delta() const {
  162. return fractional_delta;
  163. }
  164. PackedStringArray CPUParticles3D::get_configuration_warnings() const {
  165. PackedStringArray warnings = GeometryInstance3D::get_configuration_warnings();
  166. bool mesh_found = false;
  167. bool anim_material_found = false;
  168. if (get_mesh().is_valid()) {
  169. mesh_found = true;
  170. for (int j = 0; j < get_mesh()->get_surface_count(); j++) {
  171. anim_material_found = Object::cast_to<ShaderMaterial>(get_mesh()->surface_get_material(j).ptr()) != nullptr;
  172. StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_mesh()->surface_get_material(j).ptr());
  173. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
  174. }
  175. }
  176. anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr;
  177. StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_material_override().ptr());
  178. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
  179. if (!mesh_found) {
  180. warnings.push_back(RTR("Nothing is visible because no mesh has been assigned."));
  181. }
  182. if (!anim_material_found && (get_param_max(PARAM_ANIM_SPEED) != 0.0 || get_param_max(PARAM_ANIM_OFFSET) != 0.0 || get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid())) {
  183. warnings.push_back(RTR("CPUParticles3D animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."));
  184. }
  185. return warnings;
  186. }
  187. void CPUParticles3D::restart() {
  188. time = 0;
  189. frame_remainder = 0;
  190. cycle = 0;
  191. emitting = false;
  192. {
  193. int pc = particles.size();
  194. Particle *w = particles.ptrw();
  195. for (int i = 0; i < pc; i++) {
  196. w[i].active = false;
  197. }
  198. }
  199. set_emitting(true);
  200. }
  201. void CPUParticles3D::set_direction(Vector3 p_direction) {
  202. direction = p_direction;
  203. }
  204. Vector3 CPUParticles3D::get_direction() const {
  205. return direction;
  206. }
  207. void CPUParticles3D::set_spread(real_t p_spread) {
  208. spread = p_spread;
  209. }
  210. real_t CPUParticles3D::get_spread() const {
  211. return spread;
  212. }
  213. void CPUParticles3D::set_flatness(real_t p_flatness) {
  214. flatness = p_flatness;
  215. }
  216. real_t CPUParticles3D::get_flatness() const {
  217. return flatness;
  218. }
  219. void CPUParticles3D::set_param_min(Parameter p_param, real_t p_value) {
  220. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  221. parameters_min[p_param] = p_value;
  222. if (parameters_min[p_param] > parameters_max[p_param]) {
  223. set_param_max(p_param, p_value);
  224. }
  225. update_configuration_warnings();
  226. }
  227. real_t CPUParticles3D::get_param_min(Parameter p_param) const {
  228. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  229. return parameters_min[p_param];
  230. }
  231. void CPUParticles3D::set_param_max(Parameter p_param, real_t p_value) {
  232. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  233. parameters_max[p_param] = p_value;
  234. if (parameters_min[p_param] > parameters_max[p_param]) {
  235. set_param_min(p_param, p_value);
  236. }
  237. update_configuration_warnings();
  238. }
  239. real_t CPUParticles3D::get_param_max(Parameter p_param) const {
  240. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  241. return parameters_max[p_param];
  242. }
  243. static void _adjust_curve_range(const Ref<Curve> &p_curve, real_t p_min, real_t p_max) {
  244. Ref<Curve> curve = p_curve;
  245. if (!curve.is_valid()) {
  246. return;
  247. }
  248. curve->ensure_default_setup(p_min, p_max);
  249. }
  250. void CPUParticles3D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) {
  251. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  252. curve_parameters[p_param] = p_curve;
  253. switch (p_param) {
  254. case PARAM_INITIAL_LINEAR_VELOCITY: {
  255. //do none for this one
  256. } break;
  257. case PARAM_ANGULAR_VELOCITY: {
  258. _adjust_curve_range(p_curve, -360, 360);
  259. } break;
  260. case PARAM_ORBIT_VELOCITY: {
  261. _adjust_curve_range(p_curve, -500, 500);
  262. } break;
  263. case PARAM_LINEAR_ACCEL: {
  264. _adjust_curve_range(p_curve, -200, 200);
  265. } break;
  266. case PARAM_RADIAL_ACCEL: {
  267. _adjust_curve_range(p_curve, -200, 200);
  268. } break;
  269. case PARAM_TANGENTIAL_ACCEL: {
  270. _adjust_curve_range(p_curve, -200, 200);
  271. } break;
  272. case PARAM_DAMPING: {
  273. _adjust_curve_range(p_curve, 0, 100);
  274. } break;
  275. case PARAM_ANGLE: {
  276. _adjust_curve_range(p_curve, -360, 360);
  277. } break;
  278. case PARAM_SCALE: {
  279. } break;
  280. case PARAM_HUE_VARIATION: {
  281. _adjust_curve_range(p_curve, -1, 1);
  282. } break;
  283. case PARAM_ANIM_SPEED: {
  284. _adjust_curve_range(p_curve, 0, 200);
  285. } break;
  286. case PARAM_ANIM_OFFSET: {
  287. } break;
  288. default: {
  289. }
  290. }
  291. update_configuration_warnings();
  292. }
  293. Ref<Curve> CPUParticles3D::get_param_curve(Parameter p_param) const {
  294. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Curve>());
  295. return curve_parameters[p_param];
  296. }
  297. void CPUParticles3D::set_color(const Color &p_color) {
  298. color = p_color;
  299. }
  300. Color CPUParticles3D::get_color() const {
  301. return color;
  302. }
  303. void CPUParticles3D::set_color_ramp(const Ref<Gradient> &p_ramp) {
  304. color_ramp = p_ramp;
  305. }
  306. Ref<Gradient> CPUParticles3D::get_color_ramp() const {
  307. return color_ramp;
  308. }
  309. void CPUParticles3D::set_color_initial_ramp(const Ref<Gradient> &p_ramp) {
  310. color_initial_ramp = p_ramp;
  311. }
  312. Ref<Gradient> CPUParticles3D::get_color_initial_ramp() const {
  313. return color_initial_ramp;
  314. }
  315. void CPUParticles3D::set_particle_flag(ParticleFlags p_particle_flag, bool p_enable) {
  316. ERR_FAIL_INDEX(p_particle_flag, PARTICLE_FLAG_MAX);
  317. particle_flags[p_particle_flag] = p_enable;
  318. if (p_particle_flag == PARTICLE_FLAG_DISABLE_Z) {
  319. notify_property_list_changed();
  320. }
  321. }
  322. bool CPUParticles3D::get_particle_flag(ParticleFlags p_particle_flag) const {
  323. ERR_FAIL_INDEX_V(p_particle_flag, PARTICLE_FLAG_MAX, false);
  324. return particle_flags[p_particle_flag];
  325. }
  326. void CPUParticles3D::set_emission_shape(EmissionShape p_shape) {
  327. ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX);
  328. emission_shape = p_shape;
  329. }
  330. void CPUParticles3D::set_emission_sphere_radius(real_t p_radius) {
  331. emission_sphere_radius = p_radius;
  332. }
  333. void CPUParticles3D::set_emission_box_extents(Vector3 p_extents) {
  334. emission_box_extents = p_extents;
  335. }
  336. void CPUParticles3D::set_emission_points(const Vector<Vector3> &p_points) {
  337. emission_points = p_points;
  338. }
  339. void CPUParticles3D::set_emission_normals(const Vector<Vector3> &p_normals) {
  340. emission_normals = p_normals;
  341. }
  342. void CPUParticles3D::set_emission_colors(const Vector<Color> &p_colors) {
  343. emission_colors = p_colors;
  344. }
  345. void CPUParticles3D::set_emission_ring_axis(Vector3 p_axis) {
  346. emission_ring_axis = p_axis;
  347. }
  348. void CPUParticles3D::set_emission_ring_height(real_t p_height) {
  349. emission_ring_height = p_height;
  350. }
  351. void CPUParticles3D::set_emission_ring_radius(real_t p_radius) {
  352. emission_ring_radius = p_radius;
  353. }
  354. void CPUParticles3D::set_emission_ring_inner_radius(real_t p_radius) {
  355. emission_ring_inner_radius = p_radius;
  356. }
  357. void CPUParticles3D::set_emission_ring_cone_angle(real_t p_angle) {
  358. emission_ring_cone_angle = p_angle;
  359. }
  360. void CPUParticles3D::set_scale_curve_x(Ref<Curve> p_scale_curve) {
  361. scale_curve_x = p_scale_curve;
  362. }
  363. void CPUParticles3D::set_scale_curve_y(Ref<Curve> p_scale_curve) {
  364. scale_curve_y = p_scale_curve;
  365. }
  366. void CPUParticles3D::set_scale_curve_z(Ref<Curve> p_scale_curve) {
  367. scale_curve_z = p_scale_curve;
  368. }
  369. void CPUParticles3D::set_split_scale(bool p_split_scale) {
  370. split_scale = p_split_scale;
  371. notify_property_list_changed();
  372. }
  373. real_t CPUParticles3D::get_emission_sphere_radius() const {
  374. return emission_sphere_radius;
  375. }
  376. Vector3 CPUParticles3D::get_emission_box_extents() const {
  377. return emission_box_extents;
  378. }
  379. Vector<Vector3> CPUParticles3D::get_emission_points() const {
  380. return emission_points;
  381. }
  382. Vector<Vector3> CPUParticles3D::get_emission_normals() const {
  383. return emission_normals;
  384. }
  385. Vector<Color> CPUParticles3D::get_emission_colors() const {
  386. return emission_colors;
  387. }
  388. Vector3 CPUParticles3D::get_emission_ring_axis() const {
  389. return emission_ring_axis;
  390. }
  391. real_t CPUParticles3D::get_emission_ring_height() const {
  392. return emission_ring_height;
  393. }
  394. real_t CPUParticles3D::get_emission_ring_radius() const {
  395. return emission_ring_radius;
  396. }
  397. real_t CPUParticles3D::get_emission_ring_inner_radius() const {
  398. return emission_ring_inner_radius;
  399. }
  400. real_t CPUParticles3D::get_emission_ring_cone_angle() const {
  401. return emission_ring_cone_angle;
  402. }
  403. CPUParticles3D::EmissionShape CPUParticles3D::get_emission_shape() const {
  404. return emission_shape;
  405. }
  406. void CPUParticles3D::set_gravity(const Vector3 &p_gravity) {
  407. gravity = p_gravity;
  408. }
  409. Vector3 CPUParticles3D::get_gravity() const {
  410. return gravity;
  411. }
  412. Ref<Curve> CPUParticles3D::get_scale_curve_x() const {
  413. return scale_curve_x;
  414. }
  415. Ref<Curve> CPUParticles3D::get_scale_curve_y() const {
  416. return scale_curve_y;
  417. }
  418. Ref<Curve> CPUParticles3D::get_scale_curve_z() const {
  419. return scale_curve_z;
  420. }
  421. bool CPUParticles3D::get_split_scale() {
  422. return split_scale;
  423. }
  424. AABB CPUParticles3D::capture_aabb() const {
  425. RS::get_singleton()->multimesh_set_custom_aabb(multimesh, AABB());
  426. return RS::get_singleton()->multimesh_get_aabb(multimesh);
  427. }
  428. void CPUParticles3D::_validate_property(PropertyInfo &p_property) const {
  429. if (p_property.name == "emitting") {
  430. p_property.hint = one_shot ? PROPERTY_HINT_ONESHOT : PROPERTY_HINT_NONE;
  431. }
  432. if (p_property.name == "emission_sphere_radius" && (emission_shape != EMISSION_SHAPE_SPHERE && emission_shape != EMISSION_SHAPE_SPHERE_SURFACE)) {
  433. p_property.usage = PROPERTY_USAGE_NONE;
  434. }
  435. if (p_property.name == "emission_box_extents" && emission_shape != EMISSION_SHAPE_BOX) {
  436. p_property.usage = PROPERTY_USAGE_NONE;
  437. }
  438. if ((p_property.name == "emission_point_texture" || p_property.name == "emission_color_texture" || p_property.name == "emission_points") && (emission_shape != EMISSION_SHAPE_POINTS && (emission_shape != EMISSION_SHAPE_DIRECTED_POINTS))) {
  439. p_property.usage = PROPERTY_USAGE_NONE;
  440. }
  441. if (p_property.name == "emission_normals" && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) {
  442. p_property.usage = PROPERTY_USAGE_NONE;
  443. }
  444. if (p_property.name.begins_with("emission_ring_") && emission_shape != EMISSION_SHAPE_RING) {
  445. p_property.usage = PROPERTY_USAGE_NONE;
  446. }
  447. if (p_property.name.begins_with("orbit_") && !particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  448. p_property.usage = PROPERTY_USAGE_NONE;
  449. }
  450. if (p_property.name.begins_with("scale_curve_") && !split_scale) {
  451. p_property.usage = PROPERTY_USAGE_NONE;
  452. }
  453. }
  454. static uint32_t idhash(uint32_t x) {
  455. x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b);
  456. x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b);
  457. x = (x >> uint32_t(16)) ^ x;
  458. return x;
  459. }
  460. static real_t rand_from_seed(uint32_t &seed) {
  461. int k;
  462. int s = int(seed);
  463. if (s == 0) {
  464. s = 305420679;
  465. }
  466. k = s / 127773;
  467. s = 16807 * (s - k * 127773) - 2836 * k;
  468. if (s < 0) {
  469. s += 2147483647;
  470. }
  471. seed = uint32_t(s);
  472. return (seed % uint32_t(65536)) / 65535.0;
  473. }
  474. void CPUParticles3D::_update_internal() {
  475. if (particles.size() == 0 || !is_visible_in_tree()) {
  476. _set_redraw(false);
  477. return;
  478. }
  479. double delta = get_process_delta_time();
  480. if (!active && !emitting) {
  481. set_process_internal(false);
  482. _set_redraw(false);
  483. //reset variables
  484. time = 0;
  485. frame_remainder = 0;
  486. cycle = 0;
  487. return;
  488. }
  489. _set_redraw(true);
  490. bool processed = false;
  491. if (time == 0 && pre_process_time > 0.0) {
  492. double frame_time;
  493. if (fixed_fps > 0) {
  494. frame_time = 1.0 / fixed_fps;
  495. } else {
  496. frame_time = 1.0 / 30.0;
  497. }
  498. double todo = pre_process_time;
  499. while (todo >= 0) {
  500. _particles_process(frame_time);
  501. processed = true;
  502. todo -= frame_time;
  503. }
  504. }
  505. if (fixed_fps > 0) {
  506. double frame_time = 1.0 / fixed_fps;
  507. double decr = frame_time;
  508. double ldelta = delta;
  509. if (ldelta > 0.1) { //avoid recursive stalls if fps goes below 10
  510. ldelta = 0.1;
  511. } else if (ldelta <= 0.0) { //unlikely but..
  512. ldelta = 0.001;
  513. }
  514. double todo = frame_remainder + ldelta;
  515. while (todo >= frame_time) {
  516. _particles_process(frame_time);
  517. processed = true;
  518. todo -= decr;
  519. }
  520. frame_remainder = todo;
  521. } else {
  522. _particles_process(delta);
  523. processed = true;
  524. }
  525. if (processed) {
  526. _update_particle_data_buffer();
  527. }
  528. }
  529. void CPUParticles3D::_particles_process(double p_delta) {
  530. p_delta *= speed_scale;
  531. int pcount = particles.size();
  532. Particle *w = particles.ptrw();
  533. Particle *parray = w;
  534. double prev_time = time;
  535. time += p_delta;
  536. if (time > lifetime) {
  537. time = Math::fmod(time, lifetime);
  538. cycle++;
  539. if (one_shot && cycle > 0) {
  540. set_emitting(false);
  541. notify_property_list_changed();
  542. }
  543. }
  544. Transform3D emission_xform;
  545. Basis velocity_xform;
  546. if (!local_coords) {
  547. emission_xform = get_global_transform();
  548. velocity_xform = emission_xform.basis;
  549. }
  550. double system_phase = time / lifetime;
  551. bool should_be_active = false;
  552. for (int i = 0; i < pcount; i++) {
  553. Particle &p = parray[i];
  554. if (!emitting && !p.active) {
  555. continue;
  556. }
  557. double local_delta = p_delta;
  558. // The phase is a ratio between 0 (birth) and 1 (end of life) for each particle.
  559. // While we use time in tests later on, for randomness we use the phase as done in the
  560. // original shader code, and we later multiply by lifetime to get the time.
  561. double restart_phase = double(i) / double(pcount);
  562. if (randomness_ratio > 0.0) {
  563. uint32_t seed = cycle;
  564. if (restart_phase >= system_phase) {
  565. seed -= uint32_t(1);
  566. }
  567. seed *= uint32_t(pcount);
  568. seed += uint32_t(i);
  569. double random = double(idhash(seed) % uint32_t(65536)) / 65536.0;
  570. restart_phase += randomness_ratio * random * 1.0 / double(pcount);
  571. }
  572. restart_phase *= (1.0 - explosiveness_ratio);
  573. double restart_time = restart_phase * lifetime;
  574. bool restart = false;
  575. if (time > prev_time) {
  576. // restart_time >= prev_time is used so particles emit in the first frame they are processed
  577. if (restart_time >= prev_time && restart_time < time) {
  578. restart = true;
  579. if (fractional_delta) {
  580. local_delta = time - restart_time;
  581. }
  582. }
  583. } else if (local_delta > 0.0) {
  584. if (restart_time >= prev_time) {
  585. restart = true;
  586. if (fractional_delta) {
  587. local_delta = lifetime - restart_time + time;
  588. }
  589. } else if (restart_time < time) {
  590. restart = true;
  591. if (fractional_delta) {
  592. local_delta = time - restart_time;
  593. }
  594. }
  595. }
  596. if (p.time * (1.0 - explosiveness_ratio) > p.lifetime) {
  597. restart = true;
  598. }
  599. float tv = 0.0;
  600. if (restart) {
  601. if (!emitting) {
  602. p.active = false;
  603. continue;
  604. }
  605. p.active = true;
  606. /*real_t tex_linear_velocity = 0;
  607. if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
  608. tex_linear_velocity = curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY]->sample(0);
  609. }*/
  610. real_t tex_angle = 1.0;
  611. if (curve_parameters[PARAM_ANGLE].is_valid()) {
  612. tex_angle = curve_parameters[PARAM_ANGLE]->sample(tv);
  613. }
  614. real_t tex_anim_offset = 1.0;
  615. if (curve_parameters[PARAM_ANGLE].is_valid()) {
  616. tex_anim_offset = curve_parameters[PARAM_ANGLE]->sample(tv);
  617. }
  618. p.seed = Math::rand();
  619. p.angle_rand = Math::randf();
  620. p.scale_rand = Math::randf();
  621. p.hue_rot_rand = Math::randf();
  622. p.anim_offset_rand = Math::randf();
  623. if (color_initial_ramp.is_valid()) {
  624. p.start_color_rand = color_initial_ramp->get_color_at_offset(Math::randf());
  625. } else {
  626. p.start_color_rand = Color(1, 1, 1, 1);
  627. }
  628. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  629. real_t angle1_rad = Math::atan2(direction.y, direction.x) + Math::deg_to_rad((Math::randf() * 2.0 - 1.0) * spread);
  630. Vector3 rot = Vector3(Math::cos(angle1_rad), Math::sin(angle1_rad), 0.0);
  631. p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], (real_t)Math::randf());
  632. } else {
  633. //initiate velocity spread in 3D
  634. real_t angle1_rad = Math::deg_to_rad((Math::randf() * (real_t)2.0 - (real_t)1.0) * spread);
  635. real_t angle2_rad = Math::deg_to_rad((Math::randf() * (real_t)2.0 - (real_t)1.0) * ((real_t)1.0 - flatness) * spread);
  636. Vector3 direction_xz = Vector3(Math::sin(angle1_rad), 0, Math::cos(angle1_rad));
  637. Vector3 direction_yz = Vector3(0, Math::sin(angle2_rad), Math::cos(angle2_rad));
  638. Vector3 spread_direction = Vector3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);
  639. Vector3 direction_nrm = direction;
  640. if (direction_nrm.length_squared() > 0) {
  641. direction_nrm.normalize();
  642. } else {
  643. direction_nrm = Vector3(0, 0, 1);
  644. }
  645. // rotate spread to direction
  646. Vector3 binormal = Vector3(0.0, 1.0, 0.0).cross(direction_nrm);
  647. if (binormal.length_squared() < 0.00000001) {
  648. // direction is parallel to Y. Choose Z as the binormal.
  649. binormal = Vector3(0.0, 0.0, 1.0);
  650. }
  651. binormal.normalize();
  652. Vector3 normal = binormal.cross(direction_nrm);
  653. spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z;
  654. p.velocity = spread_direction * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], (real_t)Math::randf());
  655. }
  656. real_t base_angle = tex_angle * Math::lerp(parameters_min[PARAM_ANGLE], parameters_max[PARAM_ANGLE], p.angle_rand);
  657. p.custom[0] = Math::deg_to_rad(base_angle); //angle
  658. p.custom[1] = 0.0; //phase
  659. p.custom[2] = tex_anim_offset * Math::lerp(parameters_min[PARAM_ANIM_OFFSET], parameters_max[PARAM_ANIM_OFFSET], p.anim_offset_rand); //animation offset (0-1)
  660. p.custom[3] = (1.0 - Math::randf() * lifetime_randomness);
  661. p.transform = Transform3D();
  662. p.time = 0;
  663. p.lifetime = lifetime * p.custom[3];
  664. p.base_color = Color(1, 1, 1, 1);
  665. switch (emission_shape) {
  666. case EMISSION_SHAPE_POINT: {
  667. //do none
  668. } break;
  669. case EMISSION_SHAPE_SPHERE: {
  670. real_t s = 2.0 * Math::randf() - 1.0;
  671. real_t t = Math_TAU * Math::randf();
  672. real_t x = Math::randf();
  673. real_t radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
  674. p.transform.origin = Vector3(0, 0, 0).lerp(Vector3(radius * Math::cos(t), radius * Math::sin(t), emission_sphere_radius * s), x);
  675. } break;
  676. case EMISSION_SHAPE_SPHERE_SURFACE: {
  677. real_t s = 2.0 * Math::randf() - 1.0;
  678. real_t t = Math_TAU * Math::randf();
  679. real_t radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
  680. p.transform.origin = Vector3(radius * Math::cos(t), radius * Math::sin(t), emission_sphere_radius * s);
  681. } break;
  682. case EMISSION_SHAPE_BOX: {
  683. p.transform.origin = Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_box_extents;
  684. } break;
  685. case EMISSION_SHAPE_POINTS:
  686. case EMISSION_SHAPE_DIRECTED_POINTS: {
  687. int pc = emission_points.size();
  688. if (pc == 0) {
  689. break;
  690. }
  691. int random_idx = Math::rand() % pc;
  692. p.transform.origin = emission_points.get(random_idx);
  693. if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS && emission_normals.size() == pc) {
  694. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  695. Vector3 normal = emission_normals.get(random_idx);
  696. Vector2 normal_2d(normal.x, normal.y);
  697. Transform2D m2;
  698. m2.columns[0] = normal_2d;
  699. m2.columns[1] = normal_2d.orthogonal();
  700. Vector2 velocity_2d(p.velocity.x, p.velocity.y);
  701. velocity_2d = m2.basis_xform(velocity_2d);
  702. p.velocity.x = velocity_2d.x;
  703. p.velocity.y = velocity_2d.y;
  704. } else {
  705. Vector3 normal = emission_normals.get(random_idx);
  706. Vector3 v0 = Math::abs(normal.z) < 0.999 ? Vector3(0.0, 0.0, 1.0) : Vector3(0, 1.0, 0.0);
  707. Vector3 tangent = v0.cross(normal).normalized();
  708. Vector3 bitangent = tangent.cross(normal).normalized();
  709. Basis m3;
  710. m3.set_column(0, tangent);
  711. m3.set_column(1, bitangent);
  712. m3.set_column(2, normal);
  713. p.velocity = m3.xform(p.velocity);
  714. }
  715. }
  716. if (emission_colors.size() == pc) {
  717. p.base_color = emission_colors.get(random_idx);
  718. }
  719. } break;
  720. case EMISSION_SHAPE_RING: {
  721. real_t radius_clamped = MAX(0.001, emission_ring_radius);
  722. real_t top_radius = MAX(radius_clamped - Math::tan(Math::deg_to_rad(90.0 - emission_ring_cone_angle)) * emission_ring_height, 0.0);
  723. real_t y_pos = Math::randf();
  724. real_t skew = MAX(MIN(radius_clamped, top_radius) / MAX(radius_clamped, top_radius), 0.5);
  725. y_pos = radius_clamped < top_radius ? Math::pow(y_pos, skew) : 1.0 - Math::pow(y_pos, skew);
  726. real_t ring_random_angle = Math::randf() * Math_TAU;
  727. real_t ring_random_radius = Math::sqrt(Math::randf() * (radius_clamped * radius_clamped - emission_ring_inner_radius * emission_ring_inner_radius) + emission_ring_inner_radius * emission_ring_inner_radius);
  728. ring_random_radius = Math::lerp(ring_random_radius, ring_random_radius * (top_radius / radius_clamped), y_pos);
  729. Vector3 axis = emission_ring_axis == Vector3(0.0, 0.0, 0.0) ? Vector3(0.0, 0.0, 1.0) : emission_ring_axis.normalized();
  730. Vector3 ortho_axis;
  731. if (axis.abs() == Vector3(1.0, 0.0, 0.0)) {
  732. ortho_axis = Vector3(0.0, 1.0, 0.0).cross(axis);
  733. } else {
  734. ortho_axis = Vector3(1.0, 0.0, 0.0).cross(axis);
  735. }
  736. ortho_axis = ortho_axis.normalized();
  737. ortho_axis.rotate(axis, ring_random_angle);
  738. ortho_axis = ortho_axis.normalized();
  739. p.transform.origin = ortho_axis * ring_random_radius + (y_pos * emission_ring_height - emission_ring_height / 2.0) * axis;
  740. } break;
  741. case EMISSION_SHAPE_MAX: { // Max value for validity check.
  742. break;
  743. }
  744. }
  745. if (!local_coords) {
  746. p.velocity = velocity_xform.xform(p.velocity);
  747. p.transform = emission_xform * p.transform;
  748. }
  749. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  750. p.velocity.z = 0.0;
  751. p.transform.origin.z = 0.0;
  752. }
  753. } else if (!p.active) {
  754. continue;
  755. } else if (p.time > p.lifetime) {
  756. p.active = false;
  757. tv = 1.0;
  758. } else {
  759. uint32_t alt_seed = p.seed;
  760. p.time += local_delta;
  761. p.custom[1] = p.time / lifetime;
  762. tv = p.time / p.lifetime;
  763. real_t tex_linear_velocity = 1.0;
  764. if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
  765. tex_linear_velocity = curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY]->sample(tv);
  766. }
  767. real_t tex_orbit_velocity = 1.0;
  768. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  769. if (curve_parameters[PARAM_ORBIT_VELOCITY].is_valid()) {
  770. tex_orbit_velocity = curve_parameters[PARAM_ORBIT_VELOCITY]->sample(tv);
  771. }
  772. }
  773. real_t tex_angular_velocity = 1.0;
  774. if (curve_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) {
  775. tex_angular_velocity = curve_parameters[PARAM_ANGULAR_VELOCITY]->sample(tv);
  776. }
  777. real_t tex_linear_accel = 1.0;
  778. if (curve_parameters[PARAM_LINEAR_ACCEL].is_valid()) {
  779. tex_linear_accel = curve_parameters[PARAM_LINEAR_ACCEL]->sample(tv);
  780. }
  781. real_t tex_tangential_accel = 1.0;
  782. if (curve_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) {
  783. tex_tangential_accel = curve_parameters[PARAM_TANGENTIAL_ACCEL]->sample(tv);
  784. }
  785. real_t tex_radial_accel = 1.0;
  786. if (curve_parameters[PARAM_RADIAL_ACCEL].is_valid()) {
  787. tex_radial_accel = curve_parameters[PARAM_RADIAL_ACCEL]->sample(tv);
  788. }
  789. real_t tex_damping = 1.0;
  790. if (curve_parameters[PARAM_DAMPING].is_valid()) {
  791. tex_damping = curve_parameters[PARAM_DAMPING]->sample(tv);
  792. }
  793. real_t tex_angle = 1.0;
  794. if (curve_parameters[PARAM_ANGLE].is_valid()) {
  795. tex_angle = curve_parameters[PARAM_ANGLE]->sample(tv);
  796. }
  797. real_t tex_anim_speed = 1.0;
  798. if (curve_parameters[PARAM_ANIM_SPEED].is_valid()) {
  799. tex_anim_speed = curve_parameters[PARAM_ANIM_SPEED]->sample(tv);
  800. }
  801. real_t tex_anim_offset = 1.0;
  802. if (curve_parameters[PARAM_ANIM_OFFSET].is_valid()) {
  803. tex_anim_offset = curve_parameters[PARAM_ANIM_OFFSET]->sample(tv);
  804. }
  805. Vector3 force = gravity;
  806. Vector3 position = p.transform.origin;
  807. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  808. position.z = 0.0;
  809. }
  810. //apply linear acceleration
  811. force += p.velocity.length() > 0.0 ? p.velocity.normalized() * tex_linear_accel * Math::lerp(parameters_min[PARAM_LINEAR_ACCEL], parameters_max[PARAM_LINEAR_ACCEL], rand_from_seed(alt_seed)) : Vector3();
  812. //apply radial acceleration
  813. Vector3 org = emission_xform.origin;
  814. Vector3 diff = position - org;
  815. force += diff.length() > 0.0 ? diff.normalized() * (tex_radial_accel)*Math::lerp(parameters_min[PARAM_RADIAL_ACCEL], parameters_max[PARAM_RADIAL_ACCEL], rand_from_seed(alt_seed)) : Vector3();
  816. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  817. Vector2 yx = Vector2(diff.y, diff.x);
  818. Vector2 yx2 = (yx * Vector2(-1.0, 1.0)).normalized();
  819. force += yx.length() > 0.0 ? Vector3(yx2.x, yx2.y, 0.0) * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
  820. } else {
  821. Vector3 crossDiff = diff.normalized().cross(gravity.normalized());
  822. force += crossDiff.length() > 0.0 ? crossDiff.normalized() * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
  823. }
  824. //apply attractor forces
  825. p.velocity += force * local_delta;
  826. //orbit velocity
  827. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  828. real_t orbit_amount = tex_orbit_velocity * Math::lerp(parameters_min[PARAM_ORBIT_VELOCITY], parameters_max[PARAM_ORBIT_VELOCITY], rand_from_seed(alt_seed));
  829. if (orbit_amount != 0.0) {
  830. real_t ang = orbit_amount * local_delta * Math_TAU;
  831. // Not sure why the ParticleProcessMaterial code uses a clockwise rotation matrix,
  832. // but we use -ang here to reproduce its behavior.
  833. Transform2D rot = Transform2D(-ang, Vector2());
  834. Vector2 rotv = rot.basis_xform(Vector2(diff.x, diff.y));
  835. p.transform.origin -= Vector3(diff.x, diff.y, 0);
  836. p.transform.origin += Vector3(rotv.x, rotv.y, 0);
  837. }
  838. }
  839. if (curve_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
  840. p.velocity = p.velocity.normalized() * tex_linear_velocity;
  841. }
  842. if (parameters_max[PARAM_DAMPING] + tex_damping > 0.0) {
  843. real_t v = p.velocity.length();
  844. real_t damp = tex_damping * Math::lerp(parameters_min[PARAM_DAMPING], parameters_max[PARAM_DAMPING], rand_from_seed(alt_seed));
  845. v -= damp * local_delta;
  846. if (v < 0.0) {
  847. p.velocity = Vector3();
  848. } else {
  849. p.velocity = p.velocity.normalized() * v;
  850. }
  851. }
  852. real_t base_angle = (tex_angle)*Math::lerp(parameters_min[PARAM_ANGLE], parameters_max[PARAM_ANGLE], p.angle_rand);
  853. base_angle += p.custom[1] * lifetime * tex_angular_velocity * Math::lerp(parameters_min[PARAM_ANGULAR_VELOCITY], parameters_max[PARAM_ANGULAR_VELOCITY], rand_from_seed(alt_seed));
  854. p.custom[0] = Math::deg_to_rad(base_angle); //angle
  855. p.custom[2] = tex_anim_offset * Math::lerp(parameters_min[PARAM_ANIM_OFFSET], parameters_max[PARAM_ANIM_OFFSET], p.anim_offset_rand) + tv * tex_anim_speed * Math::lerp(parameters_min[PARAM_ANIM_SPEED], parameters_max[PARAM_ANIM_SPEED], rand_from_seed(alt_seed)); //angle
  856. }
  857. //apply color
  858. //apply hue rotation
  859. Vector3 tex_scale = Vector3(1.0, 1.0, 1.0);
  860. if (split_scale) {
  861. if (scale_curve_x.is_valid()) {
  862. tex_scale.x = scale_curve_x->sample(tv);
  863. } else {
  864. tex_scale.x = 1.0;
  865. }
  866. if (scale_curve_y.is_valid()) {
  867. tex_scale.y = scale_curve_y->sample(tv);
  868. } else {
  869. tex_scale.y = 1.0;
  870. }
  871. if (scale_curve_z.is_valid()) {
  872. tex_scale.z = scale_curve_z->sample(tv);
  873. } else {
  874. tex_scale.z = 1.0;
  875. }
  876. } else {
  877. if (curve_parameters[PARAM_SCALE].is_valid()) {
  878. float tmp_scale = curve_parameters[PARAM_SCALE]->sample(tv);
  879. tex_scale.x = tmp_scale;
  880. tex_scale.y = tmp_scale;
  881. tex_scale.z = tmp_scale;
  882. }
  883. }
  884. real_t tex_hue_variation = 0.0;
  885. if (curve_parameters[PARAM_HUE_VARIATION].is_valid()) {
  886. tex_hue_variation = curve_parameters[PARAM_HUE_VARIATION]->sample(tv);
  887. }
  888. real_t hue_rot_angle = (tex_hue_variation)*Math_TAU * Math::lerp(parameters_min[PARAM_HUE_VARIATION], parameters_max[PARAM_HUE_VARIATION], p.hue_rot_rand);
  889. real_t hue_rot_c = Math::cos(hue_rot_angle);
  890. real_t hue_rot_s = Math::sin(hue_rot_angle);
  891. Basis hue_rot_mat;
  892. {
  893. Basis mat1(0.299, 0.587, 0.114, 0.299, 0.587, 0.114, 0.299, 0.587, 0.114);
  894. Basis mat2(0.701, -0.587, -0.114, -0.299, 0.413, -0.114, -0.300, -0.588, 0.886);
  895. Basis mat3(0.168, 0.330, -0.497, -0.328, 0.035, 0.292, 1.250, -1.050, -0.203);
  896. for (int j = 0; j < 3; j++) {
  897. hue_rot_mat[j] = mat1[j] + mat2[j] * hue_rot_c + mat3[j] * hue_rot_s;
  898. }
  899. }
  900. if (color_ramp.is_valid()) {
  901. p.color = color_ramp->get_color_at_offset(tv) * color;
  902. } else {
  903. p.color = color;
  904. }
  905. Vector3 color_rgb = hue_rot_mat.xform_inv(Vector3(p.color.r, p.color.g, p.color.b));
  906. p.color.r = color_rgb.x;
  907. p.color.g = color_rgb.y;
  908. p.color.b = color_rgb.z;
  909. p.color *= p.base_color * p.start_color_rand;
  910. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  911. if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
  912. if (p.velocity.length() > 0.0) {
  913. p.transform.basis.set_column(1, p.velocity.normalized());
  914. } else {
  915. p.transform.basis.set_column(1, p.transform.basis.get_column(1));
  916. }
  917. p.transform.basis.set_column(0, p.transform.basis.get_column(1).cross(p.transform.basis.get_column(2)).normalized());
  918. p.transform.basis.set_column(2, Vector3(0, 0, 1));
  919. } else {
  920. p.transform.basis.set_column(0, Vector3(Math::cos(p.custom[0]), -Math::sin(p.custom[0]), 0.0));
  921. p.transform.basis.set_column(1, Vector3(Math::sin(p.custom[0]), Math::cos(p.custom[0]), 0.0));
  922. p.transform.basis.set_column(2, Vector3(0, 0, 1));
  923. }
  924. } else {
  925. //orient particle Y towards velocity
  926. if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
  927. if (p.velocity.length() > 0.0) {
  928. p.transform.basis.set_column(1, p.velocity.normalized());
  929. } else {
  930. p.transform.basis.set_column(1, p.transform.basis.get_column(1).normalized());
  931. }
  932. if (p.transform.basis.get_column(1) == p.transform.basis.get_column(0)) {
  933. p.transform.basis.set_column(0, p.transform.basis.get_column(1).cross(p.transform.basis.get_column(2)).normalized());
  934. p.transform.basis.set_column(2, p.transform.basis.get_column(0).cross(p.transform.basis.get_column(1)).normalized());
  935. } else {
  936. p.transform.basis.set_column(2, p.transform.basis.get_column(0).cross(p.transform.basis.get_column(1)).normalized());
  937. p.transform.basis.set_column(0, p.transform.basis.get_column(1).cross(p.transform.basis.get_column(2)).normalized());
  938. }
  939. } else {
  940. p.transform.basis.orthonormalize();
  941. }
  942. //turn particle by rotation in Y
  943. if (particle_flags[PARTICLE_FLAG_ROTATE_Y]) {
  944. Basis rot_y(Vector3(0, 1, 0), p.custom[0]);
  945. p.transform.basis = rot_y;
  946. }
  947. }
  948. p.transform.basis = p.transform.basis.orthonormalized();
  949. //scale by scale
  950. Vector3 base_scale = tex_scale * Math::lerp(parameters_min[PARAM_SCALE], parameters_max[PARAM_SCALE], p.scale_rand);
  951. if (base_scale.x < CMP_EPSILON) {
  952. base_scale.x = CMP_EPSILON;
  953. }
  954. if (base_scale.y < CMP_EPSILON) {
  955. base_scale.y = CMP_EPSILON;
  956. }
  957. if (base_scale.z < CMP_EPSILON) {
  958. base_scale.z = CMP_EPSILON;
  959. }
  960. p.transform.basis.scale(base_scale);
  961. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  962. p.velocity.z = 0.0;
  963. p.transform.origin.z = 0.0;
  964. }
  965. p.transform.origin += p.velocity * local_delta;
  966. should_be_active = true;
  967. }
  968. if (!Math::is_equal_approx(time, 0.0) && active && !should_be_active) {
  969. active = false;
  970. emit_signal(SceneStringName(finished));
  971. }
  972. }
  973. void CPUParticles3D::_update_particle_data_buffer() {
  974. MutexLock lock(update_mutex);
  975. int pc = particles.size();
  976. int *ow;
  977. int *order = nullptr;
  978. float *w = particle_data.ptrw();
  979. const Particle *r = particles.ptr();
  980. float *ptr = w;
  981. if (draw_order != DRAW_ORDER_INDEX) {
  982. ow = particle_order.ptrw();
  983. order = ow;
  984. for (int i = 0; i < pc; i++) {
  985. order[i] = i;
  986. }
  987. if (draw_order == DRAW_ORDER_LIFETIME) {
  988. SortArray<int, SortLifetime> sorter;
  989. sorter.compare.particles = r;
  990. sorter.sort(order, pc);
  991. } else if (draw_order == DRAW_ORDER_VIEW_DEPTH) {
  992. ERR_FAIL_NULL(get_viewport());
  993. Camera3D *c = get_viewport()->get_camera_3d();
  994. if (c) {
  995. Vector3 dir = c->get_global_transform().basis.get_column(2); //far away to close
  996. if (local_coords) {
  997. // will look different from Particles in editor as this is based on the camera in the scenetree
  998. // and not the editor camera
  999. dir = inv_emission_transform.xform(dir).normalized();
  1000. } else {
  1001. dir = dir.normalized();
  1002. }
  1003. SortArray<int, SortAxis> sorter;
  1004. sorter.compare.particles = r;
  1005. sorter.compare.axis = dir;
  1006. sorter.sort(order, pc);
  1007. }
  1008. }
  1009. }
  1010. for (int i = 0; i < pc; i++) {
  1011. int idx = order ? order[i] : i;
  1012. Transform3D t = r[idx].transform;
  1013. if (!local_coords) {
  1014. t = inv_emission_transform * t;
  1015. }
  1016. if (r[idx].active) {
  1017. ptr[0] = t.basis.rows[0][0];
  1018. ptr[1] = t.basis.rows[0][1];
  1019. ptr[2] = t.basis.rows[0][2];
  1020. ptr[3] = t.origin.x;
  1021. ptr[4] = t.basis.rows[1][0];
  1022. ptr[5] = t.basis.rows[1][1];
  1023. ptr[6] = t.basis.rows[1][2];
  1024. ptr[7] = t.origin.y;
  1025. ptr[8] = t.basis.rows[2][0];
  1026. ptr[9] = t.basis.rows[2][1];
  1027. ptr[10] = t.basis.rows[2][2];
  1028. ptr[11] = t.origin.z;
  1029. } else {
  1030. memset(ptr, 0, sizeof(float) * 12);
  1031. }
  1032. Color c = r[idx].color;
  1033. ptr[12] = c.r;
  1034. ptr[13] = c.g;
  1035. ptr[14] = c.b;
  1036. ptr[15] = c.a;
  1037. ptr[16] = r[idx].custom[0];
  1038. ptr[17] = r[idx].custom[1];
  1039. ptr[18] = r[idx].custom[2];
  1040. ptr[19] = r[idx].custom[3];
  1041. ptr += 20;
  1042. }
  1043. can_update.set();
  1044. }
  1045. void CPUParticles3D::_set_redraw(bool p_redraw) {
  1046. if (redraw == p_redraw) {
  1047. return;
  1048. }
  1049. redraw = p_redraw;
  1050. {
  1051. MutexLock lock(update_mutex);
  1052. if (redraw) {
  1053. RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread));
  1054. RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true);
  1055. RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1);
  1056. } else {
  1057. if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread))) {
  1058. RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread));
  1059. }
  1060. RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false);
  1061. RS::get_singleton()->multimesh_set_visible_instances(multimesh, 0);
  1062. }
  1063. }
  1064. }
  1065. void CPUParticles3D::_update_render_thread() {
  1066. MutexLock lock(update_mutex);
  1067. if (can_update.is_set()) {
  1068. RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data);
  1069. can_update.clear(); //wait for next time
  1070. }
  1071. }
  1072. void CPUParticles3D::_notification(int p_what) {
  1073. switch (p_what) {
  1074. case NOTIFICATION_ENTER_TREE: {
  1075. set_process_internal(emitting);
  1076. // first update before rendering to avoid one frame delay after emitting starts
  1077. if (emitting && (time == 0)) {
  1078. _update_internal();
  1079. }
  1080. } break;
  1081. case NOTIFICATION_EXIT_TREE: {
  1082. _set_redraw(false);
  1083. } break;
  1084. case NOTIFICATION_VISIBILITY_CHANGED: {
  1085. // first update before rendering to avoid one frame delay after emitting starts
  1086. if (emitting && (time == 0)) {
  1087. _update_internal();
  1088. }
  1089. } break;
  1090. case NOTIFICATION_INTERNAL_PROCESS: {
  1091. _update_internal();
  1092. } break;
  1093. case NOTIFICATION_TRANSFORM_CHANGED: {
  1094. inv_emission_transform = get_global_transform().affine_inverse();
  1095. if (!local_coords) {
  1096. int pc = particles.size();
  1097. float *w = particle_data.ptrw();
  1098. const Particle *r = particles.ptr();
  1099. float *ptr = w;
  1100. for (int i = 0; i < pc; i++) {
  1101. Transform3D t = inv_emission_transform * r[i].transform;
  1102. if (r[i].active) {
  1103. ptr[0] = t.basis.rows[0][0];
  1104. ptr[1] = t.basis.rows[0][1];
  1105. ptr[2] = t.basis.rows[0][2];
  1106. ptr[3] = t.origin.x;
  1107. ptr[4] = t.basis.rows[1][0];
  1108. ptr[5] = t.basis.rows[1][1];
  1109. ptr[6] = t.basis.rows[1][2];
  1110. ptr[7] = t.origin.y;
  1111. ptr[8] = t.basis.rows[2][0];
  1112. ptr[9] = t.basis.rows[2][1];
  1113. ptr[10] = t.basis.rows[2][2];
  1114. ptr[11] = t.origin.z;
  1115. } else {
  1116. memset(ptr, 0, sizeof(float) * 12);
  1117. }
  1118. ptr += 20;
  1119. }
  1120. can_update.set();
  1121. }
  1122. } break;
  1123. }
  1124. }
  1125. void CPUParticles3D::convert_from_particles(Node *p_particles) {
  1126. GPUParticles3D *gpu_particles = Object::cast_to<GPUParticles3D>(p_particles);
  1127. ERR_FAIL_NULL_MSG(gpu_particles, "Only GPUParticles3D nodes can be converted to CPUParticles3D.");
  1128. set_emitting(gpu_particles->is_emitting());
  1129. set_amount(gpu_particles->get_amount());
  1130. set_lifetime(gpu_particles->get_lifetime());
  1131. set_one_shot(gpu_particles->get_one_shot());
  1132. set_pre_process_time(gpu_particles->get_pre_process_time());
  1133. set_explosiveness_ratio(gpu_particles->get_explosiveness_ratio());
  1134. set_randomness_ratio(gpu_particles->get_randomness_ratio());
  1135. set_visibility_aabb(gpu_particles->get_visibility_aabb());
  1136. set_use_local_coordinates(gpu_particles->get_use_local_coordinates());
  1137. set_fixed_fps(gpu_particles->get_fixed_fps());
  1138. set_fractional_delta(gpu_particles->get_fractional_delta());
  1139. set_speed_scale(gpu_particles->get_speed_scale());
  1140. set_draw_order(DrawOrder(gpu_particles->get_draw_order()));
  1141. set_mesh(gpu_particles->get_draw_pass_mesh(0));
  1142. Ref<ParticleProcessMaterial> material = gpu_particles->get_process_material();
  1143. if (material.is_null()) {
  1144. return;
  1145. }
  1146. set_direction(material->get_direction());
  1147. set_spread(material->get_spread());
  1148. set_flatness(material->get_flatness());
  1149. set_color(material->get_color());
  1150. Ref<GradientTexture1D> gt = material->get_color_ramp();
  1151. if (gt.is_valid()) {
  1152. set_color_ramp(gt->get_gradient());
  1153. }
  1154. Ref<GradientTexture1D> gti = material->get_color_initial_ramp();
  1155. if (gti.is_valid()) {
  1156. set_color_initial_ramp(gti->get_gradient());
  1157. }
  1158. set_particle_flag(PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY, material->get_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY));
  1159. set_particle_flag(PARTICLE_FLAG_ROTATE_Y, material->get_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ROTATE_Y));
  1160. set_particle_flag(PARTICLE_FLAG_DISABLE_Z, material->get_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_DISABLE_Z));
  1161. set_emission_shape(EmissionShape(material->get_emission_shape()));
  1162. set_emission_sphere_radius(material->get_emission_sphere_radius());
  1163. set_emission_box_extents(material->get_emission_box_extents());
  1164. Ref<CurveXYZTexture> scale3D = material->get_param_texture(ParticleProcessMaterial::PARAM_SCALE);
  1165. if (scale3D.is_valid()) {
  1166. split_scale = true;
  1167. scale_curve_x = scale3D->get_curve_x();
  1168. scale_curve_y = scale3D->get_curve_y();
  1169. scale_curve_z = scale3D->get_curve_z();
  1170. }
  1171. set_gravity(material->get_gravity());
  1172. set_lifetime_randomness(material->get_lifetime_randomness());
  1173. #define CONVERT_PARAM(m_param) \
  1174. set_param_min(m_param, material->get_param_min(ParticleProcessMaterial::m_param)); \
  1175. { \
  1176. Ref<CurveTexture> ctex = material->get_param_texture(ParticleProcessMaterial::m_param); \
  1177. if (ctex.is_valid()) \
  1178. set_param_curve(m_param, ctex->get_curve()); \
  1179. } \
  1180. set_param_max(m_param, material->get_param_max(ParticleProcessMaterial::m_param));
  1181. CONVERT_PARAM(PARAM_INITIAL_LINEAR_VELOCITY);
  1182. CONVERT_PARAM(PARAM_ANGULAR_VELOCITY);
  1183. CONVERT_PARAM(PARAM_ORBIT_VELOCITY);
  1184. CONVERT_PARAM(PARAM_LINEAR_ACCEL);
  1185. CONVERT_PARAM(PARAM_RADIAL_ACCEL);
  1186. CONVERT_PARAM(PARAM_TANGENTIAL_ACCEL);
  1187. CONVERT_PARAM(PARAM_DAMPING);
  1188. CONVERT_PARAM(PARAM_ANGLE);
  1189. CONVERT_PARAM(PARAM_SCALE);
  1190. CONVERT_PARAM(PARAM_HUE_VARIATION);
  1191. CONVERT_PARAM(PARAM_ANIM_SPEED);
  1192. CONVERT_PARAM(PARAM_ANIM_OFFSET);
  1193. #undef CONVERT_PARAM
  1194. }
  1195. void CPUParticles3D::_bind_methods() {
  1196. ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles3D::set_emitting);
  1197. ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles3D::set_amount);
  1198. ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles3D::set_lifetime);
  1199. ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles3D::set_one_shot);
  1200. ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles3D::set_pre_process_time);
  1201. ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles3D::set_explosiveness_ratio);
  1202. ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles3D::set_randomness_ratio);
  1203. ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &CPUParticles3D::set_visibility_aabb);
  1204. ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles3D::set_lifetime_randomness);
  1205. ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles3D::set_use_local_coordinates);
  1206. ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles3D::set_fixed_fps);
  1207. ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles3D::set_fractional_delta);
  1208. ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &CPUParticles3D::set_speed_scale);
  1209. ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles3D::is_emitting);
  1210. ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles3D::get_amount);
  1211. ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles3D::get_lifetime);
  1212. ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles3D::get_one_shot);
  1213. ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles3D::get_pre_process_time);
  1214. ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles3D::get_explosiveness_ratio);
  1215. ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles3D::get_randomness_ratio);
  1216. ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &CPUParticles3D::get_visibility_aabb);
  1217. ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles3D::get_lifetime_randomness);
  1218. ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles3D::get_use_local_coordinates);
  1219. ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles3D::get_fixed_fps);
  1220. ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles3D::get_fractional_delta);
  1221. ClassDB::bind_method(D_METHOD("get_speed_scale"), &CPUParticles3D::get_speed_scale);
  1222. ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &CPUParticles3D::set_draw_order);
  1223. ClassDB::bind_method(D_METHOD("get_draw_order"), &CPUParticles3D::get_draw_order);
  1224. ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CPUParticles3D::set_mesh);
  1225. ClassDB::bind_method(D_METHOD("get_mesh"), &CPUParticles3D::get_mesh);
  1226. ClassDB::bind_method(D_METHOD("restart"), &CPUParticles3D::restart);
  1227. ClassDB::bind_method(D_METHOD("capture_aabb"), &CPUParticles3D::capture_aabb);
  1228. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting", PROPERTY_HINT_ONESHOT), "set_emitting", "is_emitting");
  1229. 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.
  1230. ADD_GROUP("Time", "");
  1231. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp,suffix:s"), "set_lifetime", "get_lifetime");
  1232. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
  1233. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_RANGE, "0.00,600.0,0.01,exp,suffix:s"), "set_pre_process_time", "get_pre_process_time");
  1234. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
  1235. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
  1236. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
  1237. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
  1238. ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1,suffix:FPS"), "set_fixed_fps", "get_fixed_fps");
  1239. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
  1240. ADD_GROUP("Drawing", "");
  1241. ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_aabb", PROPERTY_HINT_NONE, "suffix:m"), "set_visibility_aabb", "get_visibility_aabb");
  1242. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
  1243. ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime,View Depth"), "set_draw_order", "get_draw_order");
  1244. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
  1245. BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
  1246. BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
  1247. BIND_ENUM_CONSTANT(DRAW_ORDER_VIEW_DEPTH);
  1248. ////////////////////////////////
  1249. ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles3D::set_direction);
  1250. ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles3D::get_direction);
  1251. ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles3D::set_spread);
  1252. ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles3D::get_spread);
  1253. ClassDB::bind_method(D_METHOD("set_flatness", "amount"), &CPUParticles3D::set_flatness);
  1254. ClassDB::bind_method(D_METHOD("get_flatness"), &CPUParticles3D::get_flatness);
  1255. ClassDB::bind_method(D_METHOD("set_param_min", "param", "value"), &CPUParticles3D::set_param_min);
  1256. ClassDB::bind_method(D_METHOD("get_param_min", "param"), &CPUParticles3D::get_param_min);
  1257. ClassDB::bind_method(D_METHOD("set_param_max", "param", "value"), &CPUParticles3D::set_param_max);
  1258. ClassDB::bind_method(D_METHOD("get_param_max", "param"), &CPUParticles3D::get_param_max);
  1259. ClassDB::bind_method(D_METHOD("set_param_curve", "param", "curve"), &CPUParticles3D::set_param_curve);
  1260. ClassDB::bind_method(D_METHOD("get_param_curve", "param"), &CPUParticles3D::get_param_curve);
  1261. ClassDB::bind_method(D_METHOD("set_color", "color"), &CPUParticles3D::set_color);
  1262. ClassDB::bind_method(D_METHOD("get_color"), &CPUParticles3D::get_color);
  1263. ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &CPUParticles3D::set_color_ramp);
  1264. ClassDB::bind_method(D_METHOD("get_color_ramp"), &CPUParticles3D::get_color_ramp);
  1265. ClassDB::bind_method(D_METHOD("set_color_initial_ramp", "ramp"), &CPUParticles3D::set_color_initial_ramp);
  1266. ClassDB::bind_method(D_METHOD("get_color_initial_ramp"), &CPUParticles3D::get_color_initial_ramp);
  1267. ClassDB::bind_method(D_METHOD("set_particle_flag", "particle_flag", "enable"), &CPUParticles3D::set_particle_flag);
  1268. ClassDB::bind_method(D_METHOD("get_particle_flag", "particle_flag"), &CPUParticles3D::get_particle_flag);
  1269. ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &CPUParticles3D::set_emission_shape);
  1270. ClassDB::bind_method(D_METHOD("get_emission_shape"), &CPUParticles3D::get_emission_shape);
  1271. ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &CPUParticles3D::set_emission_sphere_radius);
  1272. ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &CPUParticles3D::get_emission_sphere_radius);
  1273. ClassDB::bind_method(D_METHOD("set_emission_box_extents", "extents"), &CPUParticles3D::set_emission_box_extents);
  1274. ClassDB::bind_method(D_METHOD("get_emission_box_extents"), &CPUParticles3D::get_emission_box_extents);
  1275. ClassDB::bind_method(D_METHOD("set_emission_points", "array"), &CPUParticles3D::set_emission_points);
  1276. ClassDB::bind_method(D_METHOD("get_emission_points"), &CPUParticles3D::get_emission_points);
  1277. ClassDB::bind_method(D_METHOD("set_emission_normals", "array"), &CPUParticles3D::set_emission_normals);
  1278. ClassDB::bind_method(D_METHOD("get_emission_normals"), &CPUParticles3D::get_emission_normals);
  1279. ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles3D::set_emission_colors);
  1280. ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles3D::get_emission_colors);
  1281. ClassDB::bind_method(D_METHOD("set_emission_ring_axis", "axis"), &CPUParticles3D::set_emission_ring_axis);
  1282. ClassDB::bind_method(D_METHOD("get_emission_ring_axis"), &CPUParticles3D::get_emission_ring_axis);
  1283. ClassDB::bind_method(D_METHOD("set_emission_ring_height", "height"), &CPUParticles3D::set_emission_ring_height);
  1284. ClassDB::bind_method(D_METHOD("get_emission_ring_height"), &CPUParticles3D::get_emission_ring_height);
  1285. ClassDB::bind_method(D_METHOD("set_emission_ring_radius", "radius"), &CPUParticles3D::set_emission_ring_radius);
  1286. ClassDB::bind_method(D_METHOD("get_emission_ring_radius"), &CPUParticles3D::get_emission_ring_radius);
  1287. ClassDB::bind_method(D_METHOD("set_emission_ring_inner_radius", "inner_radius"), &CPUParticles3D::set_emission_ring_inner_radius);
  1288. ClassDB::bind_method(D_METHOD("get_emission_ring_inner_radius"), &CPUParticles3D::get_emission_ring_inner_radius);
  1289. ClassDB::bind_method(D_METHOD("set_emission_ring_cone_angle", "cone_angle"), &CPUParticles3D::set_emission_ring_cone_angle);
  1290. ClassDB::bind_method(D_METHOD("get_emission_ring_cone_angle"), &CPUParticles3D::get_emission_ring_cone_angle);
  1291. ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles3D::get_gravity);
  1292. ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles3D::set_gravity);
  1293. ClassDB::bind_method(D_METHOD("get_split_scale"), &CPUParticles3D::get_split_scale);
  1294. ClassDB::bind_method(D_METHOD("set_split_scale", "split_scale"), &CPUParticles3D::set_split_scale);
  1295. ClassDB::bind_method(D_METHOD("get_scale_curve_x"), &CPUParticles3D::get_scale_curve_x);
  1296. ClassDB::bind_method(D_METHOD("set_scale_curve_x", "scale_curve"), &CPUParticles3D::set_scale_curve_x);
  1297. ClassDB::bind_method(D_METHOD("get_scale_curve_y"), &CPUParticles3D::get_scale_curve_y);
  1298. ClassDB::bind_method(D_METHOD("set_scale_curve_y", "scale_curve"), &CPUParticles3D::set_scale_curve_y);
  1299. ClassDB::bind_method(D_METHOD("get_scale_curve_z"), &CPUParticles3D::get_scale_curve_z);
  1300. ClassDB::bind_method(D_METHOD("set_scale_curve_z", "scale_curve"), &CPUParticles3D::set_scale_curve_z);
  1301. ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles3D::convert_from_particles);
  1302. ADD_SIGNAL(MethodInfo("finished"));
  1303. ADD_GROUP("Emission Shape", "emission_");
  1304. ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Sphere Surface,Box,Points,Directed Points,Ring", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_emission_shape", "get_emission_shape");
  1305. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01"), "set_emission_sphere_radius", "get_emission_sphere_radius");
  1306. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_box_extents"), "set_emission_box_extents", "get_emission_box_extents");
  1307. ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "emission_points"), "set_emission_points", "get_emission_points");
  1308. ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "emission_normals"), "set_emission_normals", "get_emission_normals");
  1309. ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "emission_colors"), "set_emission_colors", "get_emission_colors");
  1310. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_ring_axis"), "set_emission_ring_axis", "get_emission_ring_axis");
  1311. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_height", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_height", "get_emission_ring_height");
  1312. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_radius", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_radius", "get_emission_ring_radius");
  1313. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_inner_radius", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_inner_radius", "get_emission_ring_inner_radius");
  1314. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_cone_angle", PROPERTY_HINT_RANGE, "0,90,0.01,degrees"), "set_emission_ring_cone_angle", "get_emission_ring_cone_angle");
  1315. ADD_GROUP("Particle Flags", "particle_flag_");
  1316. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_align_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
  1317. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_rotate_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ROTATE_Y);
  1318. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_disable_z"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_DISABLE_Z);
  1319. ADD_GROUP("Direction", "");
  1320. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "direction"), "set_direction", "get_direction");
  1321. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spread", PROPERTY_HINT_RANGE, "0,180,0.01"), "set_spread", "get_spread");
  1322. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "flatness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_flatness", "get_flatness");
  1323. ADD_GROUP("Gravity", "");
  1324. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity"), "set_gravity", "get_gravity");
  1325. ADD_GROUP("Initial Velocity", "initial_");
  1326. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "initial_velocity_min", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_min", "get_param_min", PARAM_INITIAL_LINEAR_VELOCITY);
  1327. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "initial_velocity_max", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_max", "get_param_max", PARAM_INITIAL_LINEAR_VELOCITY);
  1328. ADD_GROUP("Angular Velocity", "angular_");
  1329. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_velocity_min", PROPERTY_HINT_RANGE, "-720,720,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_ANGULAR_VELOCITY);
  1330. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_velocity_max", PROPERTY_HINT_RANGE, "-720,720,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_ANGULAR_VELOCITY);
  1331. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angular_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGULAR_VELOCITY);
  1332. ADD_GROUP("Orbit Velocity", "orbit_");
  1333. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "orbit_velocity_min", PROPERTY_HINT_RANGE, "-1000,1000,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_ORBIT_VELOCITY);
  1334. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "orbit_velocity_max", PROPERTY_HINT_RANGE, "-1000,1000,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_ORBIT_VELOCITY);
  1335. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "orbit_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ORBIT_VELOCITY);
  1336. ADD_GROUP("Linear Accel", "linear_");
  1337. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_accel_min", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_LINEAR_ACCEL);
  1338. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_accel_max", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_LINEAR_ACCEL);
  1339. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "linear_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_LINEAR_ACCEL);
  1340. ADD_GROUP("Radial Accel", "radial_");
  1341. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "radial_accel_min", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_RADIAL_ACCEL);
  1342. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "radial_accel_max", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_RADIAL_ACCEL);
  1343. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "radial_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_RADIAL_ACCEL);
  1344. ADD_GROUP("Tangential Accel", "tangential_");
  1345. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "tangential_accel_min", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_min", "get_param_min", PARAM_TANGENTIAL_ACCEL);
  1346. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "tangential_accel_max", PROPERTY_HINT_RANGE, "-100,100,0.01,or_less,or_greater"), "set_param_max", "get_param_max", PARAM_TANGENTIAL_ACCEL);
  1347. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "tangential_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_TANGENTIAL_ACCEL);
  1348. ADD_GROUP("Damping", "");
  1349. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_min", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_param_min", "get_param_min", PARAM_DAMPING);
  1350. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_max", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_param_max", "get_param_max", PARAM_DAMPING);
  1351. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_DAMPING);
  1352. ADD_GROUP("Angle", "");
  1353. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_min", PROPERTY_HINT_RANGE, "-720,720,0.1,or_less,or_greater,degrees"), "set_param_min", "get_param_min", PARAM_ANGLE);
  1354. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_max", PROPERTY_HINT_RANGE, "-720,720,0.1,or_less,or_greater,degrees"), "set_param_max", "get_param_max", PARAM_ANGLE);
  1355. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGLE);
  1356. ADD_GROUP("Scale", "");
  1357. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "scale_amount_min", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_min", "get_param_min", PARAM_SCALE);
  1358. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "scale_amount_max", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param_max", "get_param_max", PARAM_SCALE);
  1359. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "scale_amount_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_SCALE);
  1360. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "split_scale"), "set_split_scale", "get_split_scale");
  1361. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_curve_x", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_scale_curve_x", "get_scale_curve_x");
  1362. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_curve_y", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_scale_curve_y", "get_scale_curve_y");
  1363. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_curve_z", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_scale_curve_z", "get_scale_curve_z");
  1364. ADD_GROUP("Color", "");
  1365. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
  1366. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_color_ramp", "get_color_ramp");
  1367. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_initial_ramp", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_color_initial_ramp", "get_color_initial_ramp");
  1368. ADD_GROUP("Hue Variation", "hue_");
  1369. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "hue_variation_min", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_param_min", "get_param_min", PARAM_HUE_VARIATION);
  1370. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "hue_variation_max", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_param_max", "get_param_max", PARAM_HUE_VARIATION);
  1371. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "hue_variation_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_HUE_VARIATION);
  1372. ADD_GROUP("Animation", "anim_");
  1373. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed_min", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater,or_less"), "set_param_min", "get_param_min", PARAM_ANIM_SPEED);
  1374. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_speed_max", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater,or_less"), "set_param_max", "get_param_max", PARAM_ANIM_SPEED);
  1375. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_speed_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANIM_SPEED);
  1376. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_min", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_param_min", "get_param_min", PARAM_ANIM_OFFSET);
  1377. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anim_offset_max", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_param_max", "get_param_max", PARAM_ANIM_OFFSET);
  1378. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_offset_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANIM_OFFSET);
  1379. BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY);
  1380. BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY);
  1381. BIND_ENUM_CONSTANT(PARAM_ORBIT_VELOCITY);
  1382. BIND_ENUM_CONSTANT(PARAM_LINEAR_ACCEL);
  1383. BIND_ENUM_CONSTANT(PARAM_RADIAL_ACCEL);
  1384. BIND_ENUM_CONSTANT(PARAM_TANGENTIAL_ACCEL);
  1385. BIND_ENUM_CONSTANT(PARAM_DAMPING);
  1386. BIND_ENUM_CONSTANT(PARAM_ANGLE);
  1387. BIND_ENUM_CONSTANT(PARAM_SCALE);
  1388. BIND_ENUM_CONSTANT(PARAM_HUE_VARIATION);
  1389. BIND_ENUM_CONSTANT(PARAM_ANIM_SPEED);
  1390. BIND_ENUM_CONSTANT(PARAM_ANIM_OFFSET);
  1391. BIND_ENUM_CONSTANT(PARAM_MAX);
  1392. BIND_ENUM_CONSTANT(PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
  1393. BIND_ENUM_CONSTANT(PARTICLE_FLAG_ROTATE_Y);
  1394. BIND_ENUM_CONSTANT(PARTICLE_FLAG_DISABLE_Z);
  1395. BIND_ENUM_CONSTANT(PARTICLE_FLAG_MAX);
  1396. BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINT);
  1397. BIND_ENUM_CONSTANT(EMISSION_SHAPE_SPHERE);
  1398. BIND_ENUM_CONSTANT(EMISSION_SHAPE_SPHERE_SURFACE);
  1399. BIND_ENUM_CONSTANT(EMISSION_SHAPE_BOX);
  1400. BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINTS);
  1401. BIND_ENUM_CONSTANT(EMISSION_SHAPE_DIRECTED_POINTS);
  1402. BIND_ENUM_CONSTANT(EMISSION_SHAPE_RING);
  1403. BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX);
  1404. }
  1405. CPUParticles3D::CPUParticles3D() {
  1406. set_notify_transform(true);
  1407. multimesh = RenderingServer::get_singleton()->multimesh_create();
  1408. RenderingServer::get_singleton()->multimesh_set_visible_instances(multimesh, 0);
  1409. set_base(multimesh);
  1410. set_emitting(true);
  1411. set_amount(8);
  1412. set_param_min(PARAM_INITIAL_LINEAR_VELOCITY, 0);
  1413. set_param_min(PARAM_ANGULAR_VELOCITY, 0);
  1414. set_param_min(PARAM_ORBIT_VELOCITY, 0);
  1415. set_param_min(PARAM_LINEAR_ACCEL, 0);
  1416. set_param_min(PARAM_RADIAL_ACCEL, 0);
  1417. set_param_min(PARAM_TANGENTIAL_ACCEL, 0);
  1418. set_param_min(PARAM_DAMPING, 0);
  1419. set_param_min(PARAM_ANGLE, 0);
  1420. set_param_min(PARAM_SCALE, 1);
  1421. set_param_min(PARAM_HUE_VARIATION, 0);
  1422. set_param_min(PARAM_ANIM_SPEED, 0);
  1423. set_param_min(PARAM_ANIM_OFFSET, 0);
  1424. set_param_max(PARAM_INITIAL_LINEAR_VELOCITY, 0);
  1425. set_param_max(PARAM_ANGULAR_VELOCITY, 0);
  1426. set_param_max(PARAM_ORBIT_VELOCITY, 0);
  1427. set_param_max(PARAM_LINEAR_ACCEL, 0);
  1428. set_param_max(PARAM_RADIAL_ACCEL, 0);
  1429. set_param_max(PARAM_TANGENTIAL_ACCEL, 0);
  1430. set_param_max(PARAM_DAMPING, 0);
  1431. set_param_max(PARAM_ANGLE, 0);
  1432. set_param_max(PARAM_SCALE, 1);
  1433. set_param_max(PARAM_HUE_VARIATION, 0);
  1434. set_param_max(PARAM_ANIM_SPEED, 0);
  1435. set_param_max(PARAM_ANIM_OFFSET, 0);
  1436. set_emission_shape(EMISSION_SHAPE_POINT);
  1437. set_emission_sphere_radius(1);
  1438. set_emission_box_extents(Vector3(1, 1, 1));
  1439. set_emission_ring_axis(Vector3(0, 0, 1.0));
  1440. set_emission_ring_height(1);
  1441. set_emission_ring_radius(1);
  1442. set_emission_ring_inner_radius(0);
  1443. set_emission_ring_cone_angle(90);
  1444. set_gravity(Vector3(0, -9.8, 0));
  1445. for (int i = 0; i < PARTICLE_FLAG_MAX; i++) {
  1446. particle_flags[i] = false;
  1447. }
  1448. set_color(Color(1, 1, 1, 1));
  1449. }
  1450. CPUParticles3D::~CPUParticles3D() {
  1451. ERR_FAIL_NULL(RenderingServer::get_singleton());
  1452. RS::get_singleton()->free(multimesh);
  1453. }