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