1 /*************************************************************************/
2 /*  particles.h                                                          */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 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 
31 #ifndef PARTICLES_H
32 #define PARTICLES_H
33 
34 #include "core/rid.h"
35 #include "scene/3d/visual_instance.h"
36 #include "scene/resources/material.h"
37 
38 class Particles : public GeometryInstance {
39 private:
40 	GDCLASS(Particles, GeometryInstance);
41 
42 public:
43 	enum DrawOrder {
44 		DRAW_ORDER_INDEX,
45 		DRAW_ORDER_LIFETIME,
46 		DRAW_ORDER_VIEW_DEPTH,
47 	};
48 
49 	enum {
50 		MAX_DRAW_PASSES = 4
51 	};
52 
53 private:
54 	RID particles;
55 
56 	bool one_shot;
57 	int amount;
58 	float lifetime;
59 	float pre_process_time;
60 	float explosiveness_ratio;
61 	float randomness_ratio;
62 	float speed_scale;
63 	AABB visibility_aabb;
64 	bool local_coords;
65 	int fixed_fps;
66 	bool fractional_delta;
67 
68 	Ref<Material> process_material;
69 
70 	DrawOrder draw_order;
71 
72 	Vector<Ref<Mesh> > draw_passes;
73 
74 protected:
75 	static void _bind_methods();
76 	void _notification(int p_what);
77 	virtual void _validate_property(PropertyInfo &property) const;
78 
79 public:
80 	AABB get_aabb() const;
81 	PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
82 
83 	void set_emitting(bool p_emitting);
84 	void set_amount(int p_amount);
85 	void set_lifetime(float p_lifetime);
86 	void set_one_shot(bool p_one_shot);
87 	void set_pre_process_time(float p_time);
88 	void set_explosiveness_ratio(float p_ratio);
89 	void set_randomness_ratio(float p_ratio);
90 	void set_visibility_aabb(const AABB &p_aabb);
91 	void set_use_local_coordinates(bool p_enable);
92 	void set_process_material(const Ref<Material> &p_material);
93 	void set_speed_scale(float p_scale);
94 
95 	bool is_emitting() const;
96 	int get_amount() const;
97 	float get_lifetime() const;
98 	bool get_one_shot() const;
99 	float get_pre_process_time() const;
100 	float get_explosiveness_ratio() const;
101 	float get_randomness_ratio() const;
102 	AABB get_visibility_aabb() const;
103 	bool get_use_local_coordinates() const;
104 	Ref<Material> get_process_material() const;
105 	float get_speed_scale() const;
106 
107 	void set_fixed_fps(int p_count);
108 	int get_fixed_fps() const;
109 
110 	void set_fractional_delta(bool p_enable);
111 	bool get_fractional_delta() const;
112 
113 	void set_draw_order(DrawOrder p_order);
114 	DrawOrder get_draw_order() const;
115 
116 	void set_draw_passes(int p_count);
117 	int get_draw_passes() const;
118 
119 	void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh);
120 	Ref<Mesh> get_draw_pass_mesh(int p_pass) const;
121 
122 	virtual String get_configuration_warning() const;
123 
124 	void restart();
125 
126 	AABB capture_aabb() const;
127 	Particles();
128 	~Particles();
129 };
130 
131 VARIANT_ENUM_CAST(Particles::DrawOrder)
132 
133 #endif // PARTICLES_H
134