22 PStatCollector GeomParticleRenderer::_render_collector(
"App:Particles:Geom:Render");
31 _geom_node(geom_node),
34 _initial_x_scale(1.0f),
36 _initial_y_scale(1.0f),
38 _initial_z_scale(1.0f),
40 _animate_x_ratio(false),
41 _animate_y_ratio(false),
42 _animate_z_ratio(false)
44 if (_geom_node.is_null())
56 _initial_x_scale(copy._initial_x_scale),
57 _final_x_scale(copy._final_x_scale),
58 _initial_y_scale(copy._initial_y_scale),
59 _final_y_scale(copy._final_y_scale),
60 _initial_z_scale(copy._initial_z_scale),
61 _final_z_scale(copy._final_z_scale),
62 _animate_x_ratio(copy._animate_x_ratio),
63 _animate_y_ratio(copy._animate_y_ratio),
64 _animate_z_ratio(copy._animate_z_ratio)
66 _geom_node = copy._geom_node;
90 void GeomParticleRenderer::
99 void GeomParticleRenderer::
100 resize_pool(
int new_size) {
107 for (i = 0; i < new_size; i++) {
108 _node_vector.push_back(
nullptr);
111 _pool_size = new_size;
118 void GeomParticleRenderer::
123 for (; vec_iter != _node_vector.end(); vec_iter++) {
125 if (node !=
nullptr) {
130 _node_vector.erase(_node_vector.begin(), _node_vector.end());
137 void GeomParticleRenderer::
138 birth_particle(
int index) {
139 if (_node_vector[index] ==
nullptr) {
142 node->add_child(_geom_node);
143 _node_vector[index] = node;
151 void GeomParticleRenderer::
152 kill_particle(
int index) {
153 if (_node_vector[index] !=
nullptr) {
155 _node_vector[index] =
nullptr;
163 void GeomParticleRenderer::
168 int i, remaining_particles = ttl_particles;
174 for (i = 0; i < (int)po_vector.size(); i++) {
178 cur_node = *cur_node_iter;
180 if (cur_particle->get_alive()) {
182 if (cur_node ==
nullptr) {
184 cur_node = *cur_node_iter;
186 nassertv(cur_node !=
nullptr);
190 PN_stdfloat t = cur_particle->get_parameterized_age();
191 LColor c = _color_interpolation_manager->generateColor(t);
193 if ((_alpha_mode != PR_ALPHA_NONE)) {
194 PN_stdfloat alpha_scalar;
196 if(_alpha_mode == PR_ALPHA_USER) {
200 if (_alpha_mode == PR_ALPHA_OUT)
201 alpha_scalar = 1.0f - alpha_scalar;
202 else if (_alpha_mode == PR_ALPHA_IN_OUT)
203 alpha_scalar = 2.0f * std::min(alpha_scalar, 1.0f - alpha_scalar);
207 c[3] *= alpha_scalar;
209 (LColor(1.0f, 1.0f, 1.0f, c[3])));
212 cur_node->
set_attrib(ColorAttrib::make_flat(c), 0);
215 PN_stdfloat current_x_scale = _initial_x_scale;
216 PN_stdfloat current_y_scale = _initial_y_scale;
217 PN_stdfloat current_z_scale = _initial_z_scale;
219 if (_animate_x_ratio || _animate_y_ratio || _animate_z_ratio) {
220 if (_animate_x_ratio) {
221 current_x_scale = (_initial_x_scale +
222 (t * (_final_x_scale - _initial_x_scale)));
224 if (_animate_y_ratio) {
225 current_y_scale = (_initial_y_scale +
226 (t * (_final_y_scale - _initial_y_scale)));
228 if (_animate_z_ratio) {
229 current_z_scale = (_initial_z_scale +
230 (t * (_final_z_scale - _initial_z_scale)));
237 LVecBase3(current_x_scale, current_y_scale, current_z_scale)));
241 remaining_particles--;
243 if (remaining_particles == 0)
257 out<<
"GeomParticleRenderer";
268 out<<
""<<
"_node_vector ("<<_node_vector.size()<<
" forces)\n";
270 i != _node_vector.end();
272 (*i)->write(out,
indent+2);
283 out.width(
indent); out<<
""; out<<
"GeomParticleRenderer:\n";
284 out.width(
indent+2); out<<
""; out<<
"_geom_node "<<_geom_node<<
"\n";
285 out.width(
indent+2); out<<
""; out<<
"_pool_size "<<_pool_size<<
"\n";
287 out.width(
indent+2); out<<
""; out<<
"_initial_x_scale "<<_initial_x_scale<<
"\n";
288 out.width(
indent+2); out<<
""; out<<
"_final_x_scale "<<_final_x_scale<<
"\n";
289 out.width(
indent+2); out<<
""; out<<
"_initial_y_scale "<<_initial_y_scale<<
"\n";
290 out.width(
indent+2); out<<
""; out<<
"_final_y_scale "<<_final_y_scale<<
"\n";
291 out.width(
indent+2); out<<
""; out<<
"_initial_z_scale "<<_initial_z_scale<<
"\n";
292 out.width(
indent+2); out<<
""; out<<
"_final_z_scale "<<_final_z_scale<<
"\n";
293 out.width(
indent+2); out<<
""; out<<
"_animate_x_ratio "<<_animate_x_ratio<<
"\n";
294 out.width(
indent+2); out<<
""; out<<
"_animate_y_ratio "<<_animate_y_ratio<<
"\n";
295 out.width(
indent+2); out<<
""; out<<
"_animate_z_ratio "<<_animate_z_ratio<<
"\n";