Blender V5.0
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
13
14/* Utilities */
15
16bool BlenderSync::sync_dupli_particle(BL::Object &b_ob,
17 BL::DepsgraphObjectInstance &b_instance,
18 Object *object)
19{
20 /* Test if this dupli was generated from a particle system. */
21 BL::ParticleSystem b_psys = b_instance.particle_system();
22 if (!b_psys) {
23 return false;
24 }
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
33 /* don't handle child particles yet */
34 BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_instance.persistent_id();
35
36 if (persistent_id[0] >= b_psys.particles.length()) {
37 return false;
38 }
39
40 /* find particle system */
41 const ParticleSystemKey key(b_ob, persistent_id);
42 ParticleSystem *psys;
43
44 const bool first_use = !particle_system_map.is_used(key);
45 const bool need_update = particle_system_map.add_or_update(
46 &psys, b_ob, b_instance.object(), key);
47
48 /* no update needed? */
49 if (!need_update && !object->get_geometry()->is_modified() &&
50 !scene->object_manager->need_update())
51 {
52 return true;
53 }
54
55 /* first time used in this sync loop? clear and tag update */
56 if (first_use) {
57 psys->particles.clear();
58 psys->tag_update(scene);
59 }
60
61 /* add particle */
62 BL::Particle b_pa = b_psys.particles[persistent_id[0]];
63 Particle pa;
64
65 pa.index = persistent_id[0];
66 pa.age = b_scene.frame_current_final() - b_pa.birth_time();
67 pa.lifetime = b_pa.lifetime();
68 pa.location = get_float3(b_pa.location());
69 pa.rotation = get_float4(b_pa.rotation());
70 pa.size = b_pa.size();
71 pa.velocity = get_float3(b_pa.velocity());
72 pa.angular_velocity = get_float3(b_pa.angular_velocity());
73
74 psys->particles.push_back_slow(pa);
75
76 object->set_particle_system(psys);
77 object->set_particle_index(psys->particles.size() - 1);
78
79 if (object->particle_index_is_modified()) {
80 scene->object_manager->tag_update(scene, ObjectManager::PARTICLE_MODIFIED);
81 }
82
83 /* return that this object has particle data */
84 return true;
85}
86
struct Particle Particle
struct ParticleSystem ParticleSystem
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
bool is_modified() const
ParticleData * particles
void tag_update(Scene *scene)
float age
Definition particles.h:23
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