2 * Copyright 2011, Blender Foundation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "blender_sync.h"
23 #include "blender_util.h"
25 #include "util_foreach.h"
34 bool BlenderSync::object_use_particles(BL::Object b_ob)
36 /* Particle data is only needed for
37 * a) Billboard render mode if object's own material uses particle info
38 * b) object/group render mode if any dupli object's material uses particle info
40 * Note: Meshes have to be synced at this point!
42 bool use_particles = false;
44 BL::Object::particle_systems_iterator b_psys;
45 for (b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) {
46 switch (b_psys->settings().render_type()) {
47 /* XXX not implemented yet!
48 * billboards/strands would become part of the mesh data (?),
49 * so the mesh attributes would store whether particle info is required.
52 case BL::ParticleSettings::render_type_BILLBOARD:
53 case BL::ParticleSettings::render_type_PATH: { /* for strand rendering */
54 BL::ID key = (BKE_object_is_modified(b_ob))? b_ob: b_ob.data();
55 Mesh *mesh = mesh_map.find(key);
57 use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE);
63 case BL::ParticleSettings::render_type_OBJECT: {
64 BL::Object b_dupli_ob = b_psys->settings().dupli_object();
66 BL::ID key = (BKE_object_is_modified(b_dupli_ob))? b_dupli_ob: b_dupli_ob.data();
67 Mesh *mesh = mesh_map.find(key);
69 use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE);
75 case BL::ParticleSettings::render_type_GROUP: {
76 BL::Group b_dupli_group = b_psys->settings().dupli_group();
78 BL::Group::objects_iterator b_gob;
79 for (b_dupli_group.objects.begin(b_gob); b_gob != b_dupli_group.objects.end(); ++b_gob) {
80 BL::ID key = (BKE_object_is_modified(*b_gob))? *b_gob: b_gob->data();
81 Mesh *mesh = mesh_map.find(key);
83 use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE);
91 /* avoid compiler warning */
99 static bool use_particle_system(BL::ParticleSystem b_psys)
101 /* only use duplicator particles? disabled particle info for
102 * halo and billboard to reduce particle count.
103 * Probably not necessary since particles don't contain a huge amount
104 * of data compared to other textures.
107 int render_type = b_psys->settings().render_type();
108 return (render_type == BL::ParticleSettings::render_type_OBJECT
109 || render_type == BL::ParticleSettings::render_type_GROUP);
115 static bool use_particle(BL::Particle b_pa)
117 return b_pa.is_exist() && b_pa.is_visible() && b_pa.alive_state()==BL::Particle::alive_state_ALIVE;
120 int BlenderSync::object_count_particles(BL::Object b_ob)
123 BL::Object::particle_systems_iterator b_psys;
124 for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) {
125 if (use_particle_system(*b_psys)) {
126 BL::ParticleSystem::particles_iterator b_pa;
127 for(b_psys->particles.begin(b_pa); b_pa != b_psys->particles.end(); ++b_pa) {
128 if(use_particle(*b_pa))
136 void BlenderSync::sync_particles(Object *ob, BL::Object b_ob)
138 int tot = object_count_particles(b_ob);
140 ob->particles.clear();
141 ob->particles.reserve(tot);
144 BL::Object::particle_systems_iterator b_psys;
145 for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) {
146 if (use_particle_system(*b_psys)) {
147 BL::ParticleSystem::particles_iterator b_pa;
148 for(b_psys->particles.begin(b_pa), index = 0; b_pa != b_psys->particles.end(); ++b_pa, ++index) {
149 if(use_particle(*b_pa)) {
152 pa.age = b_scene.frame_current() - b_pa->birth_time();
153 pa.lifetime = b_pa->lifetime();
155 ob->particles.push_back(pa);