Panda3D
Loading...
Searching...
No Matches
spriteParticleRenderer.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file spriteParticleRenderer.h
10 * @author charles
11 * @date 2000-07-13
12 */
13
14#ifndef SPRITEPARTICLERENDERER_H
15#define SPRITEPARTICLERENDERER_H
16
17#include "pandabase.h"
18#include "pvector.h"
20#include "baseParticle.h"
21#include "texture.h"
22#include "pointerTo.h"
23#include "geom.h"
24#include "geomVertexData.h"
25#include "geomPoints.h"
27#include "geomVertexWriter.h"
28#include "textureCollection.h"
29#include "nodePathCollection.h"
30#include "vector_int.h"
31#include "pStatCollector.h"
32
33class NodePath;
34
35/**
36 * Helper class used by SpriteParticleRenderer to keep track of the various
37 * GeomVertexWriters associated with each geom created in
38 * SpriteParticleRenderer::init_geoms().
39 */
41public:
42 SpriteWriter() {
43 }
44 SpriteWriter(const SpriteWriter &copy):
45 vertex(copy.vertex),
46 color(copy.color),
47 rotate(copy.rotate),
48 size(copy.size),
49 aspect_ratio(copy.aspect_ratio) {
50 };
51
52 void clear() {
53 vertex.clear();
54 color.clear();
55 rotate.clear();
56 size.clear();
57 aspect_ratio.clear();
58 }
59
60 GeomVertexWriter vertex;
61 GeomVertexWriter color;
62 GeomVertexWriter rotate;
64 GeomVertexWriter aspect_ratio;
65};
66
67/**
68 * Helper class used by SpriteParticleRenderer to keep track of its textures
69 * and their respective UVs and source types.
70 */
72PUBLISHED:
73 enum SourceType {
74 ST_texture,
75 ST_from_node,
76 };
77
78 void set_source_info(const std::string &tex) {
79 _source_type = ST_texture;
80 _source_tex = tex;
81 }
82
83 void set_source_info(const std::string &model, const std::string &node) {
84 _source_type = ST_from_node;
85 _source_model = model;
86 _source_node = node;
87 }
88
89 SourceType get_source_type() const {
90 return _source_type;
91 }
92
93 std::string get_tex_source() const {
94 return _source_tex;
95 }
96
97 std::string get_model_source() const {
98 return _source_model;
99 }
100
101 std::string get_node_source() const {
102 return _source_node;
103 }
104
105 int get_num_frames() const {
106 return textures.size();
107 }
108
109public:
110 SpriteAnim(Texture* t, LTexCoord ll, LTexCoord ur) {
111 textures.push_back(t);
112 this->ll.push_back(ll);
113 this->ur.push_back(ur);
114 };
115
117 ll(lls),
118 ur(urs) {
119 for (int i = 0; i < t.get_num_textures(); ++i) {
120 textures.push_back(t.get_texture(i));
121 }
122 };
123
124 void set_ll(const int n, LTexCoord c) {
125 ll[n] = c;
126 }
127
128 void set_ur(const int n, LTexCoord c) {
129 ur[n] = c;
130 }
131
132 Texture *get_frame(const int n) const {
133 return textures[n];
134 };
135
136 LTexCoord get_ll(const int n) const {
137 return ll[n];
138 }
139
140 LTexCoord get_ur(const int n) const {
141 return ur[n];
142 }
143
144private:
145 pvector< PT(Texture) > textures;
147 SourceType _source_type;
148 std::string _source_tex,_source_model,_source_node;
149};
150
151/**
152 * Renders a particle system with high-speed nasty trick sprites.
153 */
154class EXPCL_PANDA_PARTICLESYSTEM SpriteParticleRenderer : public BaseParticleRenderer {
155PUBLISHED:
156 explicit SpriteParticleRenderer(Texture *tex = nullptr);
158 virtual ~SpriteParticleRenderer();
159
160public:
161 virtual BaseParticleRenderer *make_copy();
162
163PUBLISHED:
164 void set_from_node(const NodePath &node_path, bool size_from_texels = false);
165 void set_from_node(const NodePath &node_path, const std::string &model, const std::string &node, bool size_from_texels = false);
166 void add_from_node(const NodePath &node_path, bool size_from_texels = false, bool resize = false);
167 void add_from_node(const NodePath &node_path, const std::string &model, const std::string &node, bool size_from_texels = false, bool resize = false);
168
169 INLINE void set_texture(Texture *tex, PN_stdfloat texels_per_unit = 1.0f);
170 INLINE void add_texture(Texture *tex, PN_stdfloat texels_per_unit = 1.0f, bool resize = false);
171 INLINE void remove_animation(const int n);
172 INLINE void set_ll_uv(const LTexCoord &ll_uv);
173 INLINE void set_ll_uv(const LTexCoord &ll_uv, const int anim, const int frame);
174 INLINE void set_ur_uv(const LTexCoord &ur_uv);
175 INLINE void set_ur_uv(const LTexCoord &ur_uv, const int anim, const int frame);
176 INLINE void set_size(PN_stdfloat width, PN_stdfloat height);
177 INLINE void set_color(const LColor &color);
178 INLINE void set_x_scale_flag(bool animate_x_ratio);
179 INLINE void set_y_scale_flag(bool animate_y_ratio);
180 INLINE void set_anim_angle_flag(bool animate_theta);
181 INLINE void set_initial_x_scale(PN_stdfloat initial_x_scale);
182 INLINE void set_final_x_scale(PN_stdfloat final_x_scale);
183 INLINE void set_initial_y_scale(PN_stdfloat initial_y_scale);
184 INLINE void set_final_y_scale(PN_stdfloat final_y_scale);
185 INLINE void set_nonanimated_theta(PN_stdfloat theta);
186 INLINE void set_alpha_blend_method(ParticleRendererBlendMethod bm);
187 INLINE void set_alpha_disable(bool ad);
188 INLINE void set_animate_frames_enable(bool an);
189 INLINE void set_animate_frames_rate(PN_stdfloat r);
190 INLINE void set_animate_frames_index(int i);
191
192 INLINE Texture *get_texture() const;
193 INLINE Texture *get_texture(const int anim, const int frame) const;
194 INLINE int get_num_anims() const;
195 INLINE SpriteAnim *get_anim(const int n) const;
196 MAKE_SEQ(get_anims, get_num_anims, get_anim);
197 INLINE SpriteAnim *get_last_anim() const;
198 INLINE ColorInterpolationManager* get_color_interpolation_manager() const;
199 INLINE LTexCoord get_ll_uv() const;
200 INLINE LTexCoord get_ll_uv(const int anim, const int frame) const;
201 INLINE LTexCoord get_ur_uv() const;
202 INLINE LTexCoord get_ur_uv(const int anim, const int frame) const;
203 INLINE PN_stdfloat get_width() const;
204 INLINE PN_stdfloat get_height() const;
205 INLINE LColor get_color() const;
206 INLINE bool get_x_scale_flag() const;
207 INLINE bool get_y_scale_flag() const;
208 INLINE bool get_anim_angle_flag() const;
209 INLINE PN_stdfloat get_initial_x_scale() const;
210 INLINE PN_stdfloat get_final_x_scale() const;
211 INLINE PN_stdfloat get_initial_y_scale() const;
212 INLINE PN_stdfloat get_final_y_scale() const;
213 INLINE PN_stdfloat get_nonanimated_theta() const;
214 INLINE ParticleRendererBlendMethod get_alpha_blend_method() const;
215 INLINE bool get_alpha_disable() const;
216 INLINE bool get_animate_frames_enable() const;
217 INLINE PN_stdfloat get_animate_frames_rate() const;
218 INLINE int get_animate_frames_index() const;
219
220 virtual void output(std::ostream &out) const;
221 virtual void write(std::ostream &out, int indent_level = 0) const;
222
223private:
224 pvector< pvector< PT(Geom) > > _sprite_primitive;
225 pvector< pvector< PT(GeomPoints) > > _sprites;
226 pvector< pvector< SpriteWriter > > _sprite_writer;
227 pvector< pvector< PT(GeomVertexData) > > _vdata;
228
229 pvector< PT(SpriteAnim) > _anims; // Stores texture references and UV info for each geom.
230
231 LColor _color;
232
233 PN_stdfloat _height;
234 PN_stdfloat _width;
235 PN_stdfloat _initial_x_scale;
236 PN_stdfloat _final_x_scale;
237 PN_stdfloat _initial_y_scale;
238 PN_stdfloat _final_y_scale;
239 PN_stdfloat _theta;
240 PN_stdfloat _base_y_scale;
241 PN_stdfloat _aspect_ratio;
242 PN_stdfloat _animate_frames_rate;
243 int _animate_frames_index;
244
245 bool _animate_x_ratio;
246 bool _animate_y_ratio;
247 bool _animate_theta;
248 bool _alpha_disable;
249 bool _animate_frames;
250 bool _animation_removed;
251
252 ParticleRendererBlendMethod _blend_method;
253 PT(ColorInterpolationManager) _color_interpolation_manager;
254
255 LVertex _aabb_min;
256 LVertex _aabb_max;
257
258 int _pool_size;
259
260 virtual void birth_particle(int index);
261 virtual void kill_particle(int index);
262 virtual void init_geoms();
263 virtual void render(pvector< PT(PhysicsObject) > &po_vector,
264 int ttl_particles);
265 virtual void resize_pool(int new_size);
266 int extract_textures_from_node(const NodePath &node_path, NodePathCollection &np_col, TextureCollection &tex_col);
267
268 vector_int _anim_size; // Holds the number of frames in each animation.
269 pvector<int*> _ttl_count; // _ttl_count[i][j] holds the number of particles attached to animation 'i' at frame 'j'.
270 vector_int _birth_list; // Holds the list of particles that need a new random animation to start on.
271
272 static PStatCollector _render_collector;
273};
274
276
277#endif // SPRITEPARTICLERENDERER_H
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Pure virtual particle renderer base class.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
High level class for color interpolation.
Defines a series of disconnected points.
Definition geomPoints.h:23
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
void clear()
Resets the GeomVertexWriter to the initial state.
A container for geometry primitives.
Definition geom.h:54
This is a set of zero or more NodePaths.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
A lightweight class that represents a single element that may be timed and/or counted via stats.
A body on which physics will be applied.
A base class for all things that want to be reference-counted.
Helper class used by SpriteParticleRenderer to keep track of its textures and their respective UVs an...
Renders a particle system with high-speed nasty trick sprites.
Helper class used by SpriteParticleRenderer to keep track of the various GeomVertexWriters associated...
Manages a list of Texture objects, as returned by TexturePool::find_all_textures().
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition texture.h:72
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.