gpu_particles_3d.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*************************************************************************/
  2. /* gpu_particles_3d.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "core/os/os.h"
  32. #include "scene/resources/particles_material.h"
  33. #include "servers/rendering_server.h"
  34. AABB GPUParticles3D::get_aabb() const {
  35. return AABB();
  36. }
  37. Vector<Face3> GPUParticles3D::get_faces(uint32_t p_usage_flags) const {
  38. return Vector<Face3>();
  39. }
  40. void GPUParticles3D::set_emitting(bool p_emitting) {
  41. RS::get_singleton()->particles_set_emitting(particles, p_emitting);
  42. if (p_emitting && one_shot) {
  43. set_process_internal(true);
  44. } else if (!p_emitting) {
  45. set_process_internal(false);
  46. }
  47. }
  48. void GPUParticles3D::set_amount(int p_amount) {
  49. ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1.");
  50. amount = p_amount;
  51. RS::get_singleton()->particles_set_amount(particles, amount);
  52. }
  53. void GPUParticles3D::set_lifetime(float p_lifetime) {
  54. ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0.");
  55. lifetime = p_lifetime;
  56. RS::get_singleton()->particles_set_lifetime(particles, lifetime);
  57. }
  58. void GPUParticles3D::set_one_shot(bool p_one_shot) {
  59. one_shot = p_one_shot;
  60. RS::get_singleton()->particles_set_one_shot(particles, one_shot);
  61. if (is_emitting()) {
  62. set_process_internal(true);
  63. if (!one_shot) {
  64. RenderingServer::get_singleton()->particles_restart(particles);
  65. }
  66. }
  67. if (!one_shot) {
  68. set_process_internal(false);
  69. }
  70. }
  71. void GPUParticles3D::set_pre_process_time(float p_time) {
  72. pre_process_time = p_time;
  73. RS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time);
  74. }
  75. void GPUParticles3D::set_explosiveness_ratio(float p_ratio) {
  76. explosiveness_ratio = p_ratio;
  77. RS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio);
  78. }
  79. void GPUParticles3D::set_randomness_ratio(float p_ratio) {
  80. randomness_ratio = p_ratio;
  81. RS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio);
  82. }
  83. void GPUParticles3D::set_visibility_aabb(const AABB &p_aabb) {
  84. visibility_aabb = p_aabb;
  85. RS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb);
  86. update_gizmo();
  87. }
  88. void GPUParticles3D::set_use_local_coordinates(bool p_enable) {
  89. local_coords = p_enable;
  90. RS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords);
  91. }
  92. void GPUParticles3D::set_process_material(const Ref<Material> &p_material) {
  93. process_material = p_material;
  94. RID material_rid;
  95. if (process_material.is_valid()) {
  96. material_rid = process_material->get_rid();
  97. }
  98. RS::get_singleton()->particles_set_process_material(particles, material_rid);
  99. update_configuration_warnings();
  100. }
  101. void GPUParticles3D::set_speed_scale(float p_scale) {
  102. speed_scale = p_scale;
  103. RS::get_singleton()->particles_set_speed_scale(particles, p_scale);
  104. }
  105. void GPUParticles3D::set_collision_base_size(float p_size) {
  106. collision_base_size = p_size;
  107. RS::get_singleton()->particles_set_collision_base_size(particles, p_size);
  108. }
  109. bool GPUParticles3D::is_emitting() const {
  110. return RS::get_singleton()->particles_get_emitting(particles);
  111. }
  112. int GPUParticles3D::get_amount() const {
  113. return amount;
  114. }
  115. float GPUParticles3D::get_lifetime() const {
  116. return lifetime;
  117. }
  118. bool GPUParticles3D::get_one_shot() const {
  119. return one_shot;
  120. }
  121. float GPUParticles3D::get_pre_process_time() const {
  122. return pre_process_time;
  123. }
  124. float GPUParticles3D::get_explosiveness_ratio() const {
  125. return explosiveness_ratio;
  126. }
  127. float GPUParticles3D::get_randomness_ratio() const {
  128. return randomness_ratio;
  129. }
  130. AABB GPUParticles3D::get_visibility_aabb() const {
  131. return visibility_aabb;
  132. }
  133. bool GPUParticles3D::get_use_local_coordinates() const {
  134. return local_coords;
  135. }
  136. Ref<Material> GPUParticles3D::get_process_material() const {
  137. return process_material;
  138. }
  139. float GPUParticles3D::get_speed_scale() const {
  140. return speed_scale;
  141. }
  142. float GPUParticles3D::get_collision_base_size() const {
  143. return collision_base_size;
  144. }
  145. void GPUParticles3D::set_draw_order(DrawOrder p_order) {
  146. draw_order = p_order;
  147. RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order));
  148. }
  149. GPUParticles3D::DrawOrder GPUParticles3D::get_draw_order() const {
  150. return draw_order;
  151. }
  152. void GPUParticles3D::set_draw_passes(int p_count) {
  153. ERR_FAIL_COND(p_count < 1);
  154. draw_passes.resize(p_count);
  155. RS::get_singleton()->particles_set_draw_passes(particles, p_count);
  156. notify_property_list_changed();
  157. }
  158. int GPUParticles3D::get_draw_passes() const {
  159. return draw_passes.size();
  160. }
  161. void GPUParticles3D::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) {
  162. ERR_FAIL_INDEX(p_pass, draw_passes.size());
  163. draw_passes.write[p_pass] = p_mesh;
  164. RID mesh_rid;
  165. if (p_mesh.is_valid()) {
  166. mesh_rid = p_mesh->get_rid();
  167. }
  168. RS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid);
  169. update_configuration_warnings();
  170. }
  171. Ref<Mesh> GPUParticles3D::get_draw_pass_mesh(int p_pass) const {
  172. ERR_FAIL_INDEX_V(p_pass, draw_passes.size(), Ref<Mesh>());
  173. return draw_passes[p_pass];
  174. }
  175. void GPUParticles3D::set_fixed_fps(int p_count) {
  176. fixed_fps = p_count;
  177. RS::get_singleton()->particles_set_fixed_fps(particles, p_count);
  178. }
  179. int GPUParticles3D::get_fixed_fps() const {
  180. return fixed_fps;
  181. }
  182. void GPUParticles3D::set_fractional_delta(bool p_enable) {
  183. fractional_delta = p_enable;
  184. RS::get_singleton()->particles_set_fractional_delta(particles, p_enable);
  185. }
  186. bool GPUParticles3D::get_fractional_delta() const {
  187. return fractional_delta;
  188. }
  189. TypedArray<String> GPUParticles3D::get_configuration_warnings() const {
  190. TypedArray<String> warnings = Node::get_configuration_warnings();
  191. if (RenderingServer::get_singleton()->is_low_end()) {
  192. warnings.push_back(TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles3D node instead. You can use the \"Convert to CPUParticles3D\" option for this purpose."));
  193. }
  194. bool meshes_found = false;
  195. bool anim_material_found = false;
  196. for (int i = 0; i < draw_passes.size(); i++) {
  197. if (draw_passes[i].is_valid()) {
  198. meshes_found = true;
  199. for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) {
  200. anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != nullptr;
  201. StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(draw_passes[i]->surface_get_material(j).ptr());
  202. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
  203. }
  204. if (anim_material_found) {
  205. break;
  206. }
  207. }
  208. }
  209. anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr;
  210. StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_material_override().ptr());
  211. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
  212. if (!meshes_found) {
  213. warnings.push_back(TTR("Nothing is visible because meshes have not been assigned to draw passes."));
  214. }
  215. if (process_material.is_null()) {
  216. warnings.push_back(TTR("A material to process the particles is not assigned, so no behavior is imprinted."));
  217. } else {
  218. const ParticlesMaterial *process = Object::cast_to<ParticlesMaterial>(process_material.ptr());
  219. if (!anim_material_found && process &&
  220. (process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
  221. process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) {
  222. warnings.push_back(TTR("Particles animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."));
  223. }
  224. }
  225. return warnings;
  226. }
  227. void GPUParticles3D::restart() {
  228. RenderingServer::get_singleton()->particles_restart(particles);
  229. RenderingServer::get_singleton()->particles_set_emitting(particles, true);
  230. }
  231. AABB GPUParticles3D::capture_aabb() const {
  232. return RS::get_singleton()->particles_get_current_aabb(particles);
  233. }
  234. void GPUParticles3D::_validate_property(PropertyInfo &property) const {
  235. if (property.name.begins_with("draw_pass_")) {
  236. int index = property.name.get_slicec('_', 2).to_int() - 1;
  237. if (index >= draw_passes.size()) {
  238. property.usage = 0;
  239. return;
  240. }
  241. }
  242. }
  243. void GPUParticles3D::emit_particle(const Transform &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) {
  244. RS::get_singleton()->particles_emit(particles, p_transform, p_velocity, p_color, p_custom, p_emit_flags);
  245. }
  246. void GPUParticles3D::_attach_sub_emitter() {
  247. Node *n = get_node_or_null(sub_emitter);
  248. if (n) {
  249. GPUParticles3D *sen = Object::cast_to<GPUParticles3D>(n);
  250. if (sen && sen != this) {
  251. RS::get_singleton()->particles_set_subemitter(particles, sen->particles);
  252. }
  253. }
  254. }
  255. void GPUParticles3D::set_sub_emitter(const NodePath &p_path) {
  256. if (is_inside_tree()) {
  257. RS::get_singleton()->particles_set_subemitter(particles, RID());
  258. }
  259. sub_emitter = p_path;
  260. if (is_inside_tree() && sub_emitter != NodePath()) {
  261. _attach_sub_emitter();
  262. }
  263. }
  264. NodePath GPUParticles3D::get_sub_emitter() const {
  265. return sub_emitter;
  266. }
  267. void GPUParticles3D::_notification(int p_what) {
  268. if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
  269. if (can_process()) {
  270. RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
  271. } else {
  272. RS::get_singleton()->particles_set_speed_scale(particles, 0);
  273. }
  274. }
  275. // Use internal process when emitting and one_shot is on so that when
  276. // the shot ends the editor can properly update
  277. if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
  278. if (one_shot && !is_emitting()) {
  279. notify_property_list_changed();
  280. set_process_internal(false);
  281. }
  282. }
  283. if (p_what == NOTIFICATION_ENTER_TREE) {
  284. if (sub_emitter != NodePath()) {
  285. _attach_sub_emitter();
  286. }
  287. }
  288. if (p_what == NOTIFICATION_EXIT_TREE) {
  289. RS::get_singleton()->particles_set_subemitter(particles, RID());
  290. }
  291. if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
  292. // make sure particles are updated before rendering occurs if they were active before
  293. if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {
  294. RS::get_singleton()->particles_request_process(particles);
  295. }
  296. }
  297. }
  298. void GPUParticles3D::_bind_methods() {
  299. ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles3D::set_emitting);
  300. ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles3D::set_amount);
  301. ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &GPUParticles3D::set_lifetime);
  302. ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &GPUParticles3D::set_one_shot);
  303. ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &GPUParticles3D::set_pre_process_time);
  304. ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &GPUParticles3D::set_explosiveness_ratio);
  305. ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &GPUParticles3D::set_randomness_ratio);
  306. ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &GPUParticles3D::set_visibility_aabb);
  307. ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &GPUParticles3D::set_use_local_coordinates);
  308. ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &GPUParticles3D::set_fixed_fps);
  309. ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles3D::set_fractional_delta);
  310. ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles3D::set_process_material);
  311. ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles3D::set_speed_scale);
  312. ClassDB::bind_method(D_METHOD("set_collision_base_size", "size"), &GPUParticles3D::set_collision_base_size);
  313. ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles3D::is_emitting);
  314. ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles3D::get_amount);
  315. ClassDB::bind_method(D_METHOD("get_lifetime"), &GPUParticles3D::get_lifetime);
  316. ClassDB::bind_method(D_METHOD("get_one_shot"), &GPUParticles3D::get_one_shot);
  317. ClassDB::bind_method(D_METHOD("get_pre_process_time"), &GPUParticles3D::get_pre_process_time);
  318. ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &GPUParticles3D::get_explosiveness_ratio);
  319. ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &GPUParticles3D::get_randomness_ratio);
  320. ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &GPUParticles3D::get_visibility_aabb);
  321. ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &GPUParticles3D::get_use_local_coordinates);
  322. ClassDB::bind_method(D_METHOD("get_fixed_fps"), &GPUParticles3D::get_fixed_fps);
  323. ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles3D::get_fractional_delta);
  324. ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles3D::get_process_material);
  325. ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles3D::get_speed_scale);
  326. ClassDB::bind_method(D_METHOD("get_collision_base_size"), &GPUParticles3D::get_collision_base_size);
  327. ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &GPUParticles3D::set_draw_order);
  328. ClassDB::bind_method(D_METHOD("get_draw_order"), &GPUParticles3D::get_draw_order);
  329. ClassDB::bind_method(D_METHOD("set_draw_passes", "passes"), &GPUParticles3D::set_draw_passes);
  330. ClassDB::bind_method(D_METHOD("set_draw_pass_mesh", "pass", "mesh"), &GPUParticles3D::set_draw_pass_mesh);
  331. ClassDB::bind_method(D_METHOD("get_draw_passes"), &GPUParticles3D::get_draw_passes);
  332. ClassDB::bind_method(D_METHOD("get_draw_pass_mesh", "pass"), &GPUParticles3D::get_draw_pass_mesh);
  333. ClassDB::bind_method(D_METHOD("restart"), &GPUParticles3D::restart);
  334. ClassDB::bind_method(D_METHOD("capture_aabb"), &GPUParticles3D::capture_aabb);
  335. ClassDB::bind_method(D_METHOD("set_sub_emitter", "path"), &GPUParticles3D::set_sub_emitter);
  336. ClassDB::bind_method(D_METHOD("get_sub_emitter"), &GPUParticles3D::get_sub_emitter);
  337. ClassDB::bind_method(D_METHOD("emit_particle", "xform", "velocity", "color", "custom", "flags"), &GPUParticles3D::emit_particle);
  338. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting");
  339. ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount");
  340. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "sub_emitter", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GPUParticles3D"), "set_sub_emitter", "get_sub_emitter");
  341. ADD_GROUP("Time", "");
  342. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_EXP_RANGE, "0.01,600.0,0.01,or_greater"), "set_lifetime", "get_lifetime");
  343. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
  344. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_EXP_RANGE, "0.00,600.0,0.01"), "set_pre_process_time", "get_pre_process_time");
  345. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
  346. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
  347. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
  348. ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
  349. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
  350. ADD_GROUP("Collision", "collision_");
  351. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_base_size", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater"), "set_collision_base_size", "get_collision_base_size");
  352. ADD_GROUP("Drawing", "");
  353. ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_aabb"), "set_visibility_aabb", "get_visibility_aabb");
  354. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
  355. ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime,View Depth"), "set_draw_order", "get_draw_order");
  356. ADD_GROUP("Process Material", "");
  357. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,ParticlesMaterial"), "set_process_material", "get_process_material");
  358. ADD_GROUP("Draw Passes", "draw_");
  359. ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_passes", PROPERTY_HINT_RANGE, "0," + itos(MAX_DRAW_PASSES) + ",1"), "set_draw_passes", "get_draw_passes");
  360. for (int i = 0; i < MAX_DRAW_PASSES; i++) {
  361. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "draw_pass_" + itos(i + 1), PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_draw_pass_mesh", "get_draw_pass_mesh", i);
  362. }
  363. BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
  364. BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
  365. BIND_ENUM_CONSTANT(DRAW_ORDER_VIEW_DEPTH);
  366. BIND_ENUM_CONSTANT(EMIT_FLAG_POSITION);
  367. BIND_ENUM_CONSTANT(EMIT_FLAG_ROTATION_SCALE);
  368. BIND_ENUM_CONSTANT(EMIT_FLAG_VELOCITY);
  369. BIND_ENUM_CONSTANT(EMIT_FLAG_COLOR);
  370. BIND_ENUM_CONSTANT(EMIT_FLAG_CUSTOM);
  371. BIND_CONSTANT(MAX_DRAW_PASSES);
  372. }
  373. GPUParticles3D::GPUParticles3D() {
  374. particles = RS::get_singleton()->particles_create();
  375. set_base(particles);
  376. one_shot = false; // Needed so that set_emitting doesn't access uninitialized values
  377. set_emitting(true);
  378. set_one_shot(false);
  379. set_amount(8);
  380. set_lifetime(1);
  381. set_fixed_fps(0);
  382. set_fractional_delta(true);
  383. set_pre_process_time(0);
  384. set_explosiveness_ratio(0);
  385. set_randomness_ratio(0);
  386. set_visibility_aabb(AABB(Vector3(-4, -4, -4), Vector3(8, 8, 8)));
  387. set_use_local_coordinates(true);
  388. set_draw_passes(1);
  389. set_draw_order(DRAW_ORDER_INDEX);
  390. set_speed_scale(1);
  391. set_collision_base_size(0.01);
  392. }
  393. GPUParticles3D::~GPUParticles3D() {
  394. RS::get_singleton()->free(particles);
  395. }