Blender  V2.93
blender_particles.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "render/mesh.h"
18 #include "render/object.h"
19 #include "render/particles.h"
20 
21 #include "blender/blender_sync.h"
22 #include "blender/blender_util.h"
23 
24 #include "util/util_foreach.h"
25 
27 
28 /* Utilities */
29 
30 bool BlenderSync::sync_dupli_particle(BL::Object &b_ob,
31  BL::DepsgraphObjectInstance &b_instance,
32  Object *object)
33 {
34  /* Test if this dupli was generated from a particle system. */
35  BL::ParticleSystem b_psys = b_instance.particle_system();
36  if (!b_psys)
37  return false;
38 
39  object->set_hide_on_missing_motion(true);
40 
41  /* test if we need particle data */
42  if (!object->get_geometry()->need_attribute(scene, ATTR_STD_PARTICLE))
43  return false;
44 
45  /* don't handle child particles yet */
46  BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_instance.persistent_id();
47 
48  if (persistent_id[0] >= b_psys.particles.length())
49  return false;
50 
51  /* find particle system */
52  ParticleSystemKey key(b_ob, persistent_id);
53  ParticleSystem *psys;
54 
55  bool first_use = !particle_system_map.is_used(key);
56  bool need_update = particle_system_map.add_or_update(&psys, b_ob, b_instance.object(), key);
57 
58  /* no update needed? */
59  if (!need_update && !object->get_geometry()->is_modified() &&
60  !scene->object_manager->need_update())
61  return true;
62 
63  /* first time used in this sync loop? clear and tag update */
64  if (first_use) {
65  psys->particles.clear();
66  psys->tag_update(scene);
67  }
68 
69  /* add particle */
70  BL::Particle b_pa = b_psys.particles[persistent_id[0]];
71  Particle pa;
72 
73  pa.index = persistent_id[0];
74  pa.age = b_scene.frame_current() - b_pa.birth_time();
75  pa.lifetime = b_pa.lifetime();
76  pa.location = get_float3(b_pa.location());
77  pa.rotation = get_float4(b_pa.rotation());
78  pa.size = b_pa.size();
79  pa.velocity = get_float3(b_pa.velocity());
80  pa.angular_velocity = get_float3(b_pa.angular_velocity());
81 
82  psys->particles.push_back_slow(pa);
83 
84  object->set_particle_system(psys);
85  object->set_particle_index(psys->particles.size() - 1);
86 
87  if (object->particle_index_is_modified())
89 
90  /* return that this object has particle data */
91  return true;
92 }
93 
struct Particle Particle
struct Object Object
struct ParticleSystem ParticleSystem
static float4 get_float4(const BL::Array< float, 4 > &array)
Definition: blender_util.h:310
static float3 get_float3(const BL::Array< float, 2 > &array)
Definition: blender_util.h:295
void tag_update(Scene *scene, uint32_t flag)
Definition: object.cpp:903
@ PARTICLE_MODIFIED
Definition: object.h:129
bool need_update() const
Definition: object.cpp:931
bool add_or_update(T **r_data, const BL::ID &id)
bool is_used(const K &key)
#define CCL_NAMESPACE_END
@ ATTR_STD_PARTICLE
Definition: kernel_types.h:758
bool is_modified()
Definition: node.cpp:781
ParticleData * particles
void tag_update(Scene *scene)
Definition: particles.cpp:47
float age
Definition: particles.h:36
float lifetime
float3 location
Definition: particles.h:38
float size
Definition: particles.h:40
float4 rotation
Definition: particles.h:39
float3 velocity
Definition: particles.h:41
float3 angular_velocity
Definition: particles.h:42
int index
Definition: particles.h:35
ObjectManager * object_manager
Definition: scene.h:247