Blender  V3.3
blender/particles.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #include "scene/particles.h"
5 #include "scene/mesh.h"
6 #include "scene/object.h"
7 
8 #include "blender/sync.h"
9 #include "blender/util.h"
10 
11 #include "util/foreach.h"
12 
14 
15 /* Utilities */
16 
17 bool BlenderSync::sync_dupli_particle(BL::Object &b_ob,
18  BL::DepsgraphObjectInstance &b_instance,
19  Object *object)
20 {
21  /* Test if this dupli was generated from a particle system. */
22  BL::ParticleSystem b_psys = b_instance.particle_system();
23  if (!b_psys)
24  return false;
25 
26  object->set_hide_on_missing_motion(true);
27 
28  /* test if we need particle data */
29  if (!object->get_geometry()->need_attribute(scene, ATTR_STD_PARTICLE))
30  return false;
31 
32  /* don't handle child particles yet */
33  BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_instance.persistent_id();
34 
35  if (persistent_id[0] >= b_psys.particles.length())
36  return false;
37 
38  /* find particle system */
39  ParticleSystemKey key(b_ob, persistent_id);
40  ParticleSystem *psys;
41 
42  bool first_use = !particle_system_map.is_used(key);
43  bool need_update = particle_system_map.add_or_update(&psys, b_ob, b_instance.object(), key);
44 
45  /* no update needed? */
46  if (!need_update && !object->get_geometry()->is_modified() &&
47  !scene->object_manager->need_update())
48  return true;
49 
50  /* first time used in this sync loop? clear and tag update */
51  if (first_use) {
52  psys->particles.clear();
53  psys->tag_update(scene);
54  }
55 
56  /* add particle */
57  BL::Particle b_pa = b_psys.particles[persistent_id[0]];
58  Particle pa;
59 
60  pa.index = persistent_id[0];
61  pa.age = b_scene.frame_current_final() - b_pa.birth_time();
62  pa.lifetime = b_pa.lifetime();
63  pa.location = get_float3(b_pa.location());
64  pa.rotation = get_float4(b_pa.rotation());
65  pa.size = b_pa.size();
66  pa.velocity = get_float3(b_pa.velocity());
67  pa.angular_velocity = get_float3(b_pa.angular_velocity());
68 
69  psys->particles.push_back_slow(pa);
70 
71  object->set_particle_system(psys);
72  object->set_particle_index(psys->particles.size() - 1);
73 
74  if (object->particle_index_is_modified())
76 
77  /* return that this object has particle data */
78  return true;
79 }
80 
struct Particle Particle
struct Object Object
struct ParticleSystem ParticleSystem
void tag_update(Scene *scene, uint32_t flag)
bool need_update() const
bool add_or_update(T **r_data, const BL::ID &id)
Definition: id_map.h:100
bool is_used(const K &key)
Definition: id_map.h:130
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
static float4 get_float4(const BL::Array< float, 4 > &array)
static float3 get_float3(const BL::Array< float, 2 > &array)
@ ATTR_STD_PARTICLE
Definition: kernel/types.h:626
bool is_modified() const
Definition: graph/node.cpp:804
ParticleData * particles
void tag_update(Scene *scene)
float age
Definition: particles.h:23
float lifetime
float3 location
Definition: particles.h:25
float size
Definition: particles.h:27
float4 rotation
Definition: particles.h:26
float3 velocity
Definition: particles.h:28
float3 angular_velocity
Definition: particles.h:29
int index
Definition: particles.h:22
ObjectManager * object_manager
Definition: scene.h:226