Blender V5.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 "DNA_particle_types.h"
13
14#include "BKE_scene.hh"
15
17
19
20/* Utilities */
21
22bool BlenderSync::sync_dupli_particle(blender::Object &b_parent,
23 blender::DEGObjectIterData &b_deg_iter_data,
24 blender::Object &b_ob,
25 Object *object)
26{
27 /* Test if this dupli was generated from a particle system. */
28 blender::ParticleSystem *b_psys = b_deg_iter_data.dupli_object_current->particle_system;
29 if (!b_psys) {
30 return false;
31 }
32
33 object->set_hide_on_missing_motion(true);
34
35 /* test if we need particle data */
36 if (!object->get_geometry()->need_attribute(scene, ATTR_STD_PARTICLE)) {
37 return false;
38 }
39
40 /* don't handle child particles yet */
41 const int *persistent_id = b_deg_iter_data.dupli_object_current->persistent_id;
42
43 if (persistent_id[0] >= b_psys->totpart) {
44 return false;
45 }
46
47 /* find particle system */
48 const ParticleSystemKey key(&b_parent, persistent_id);
49 ParticleSystem *psys;
50
51 const bool first_use = !particle_system_map.is_used(key);
52 const bool need_update = particle_system_map.add_or_update(&psys, &b_parent.id, &b_ob.id, key);
53
54 /* no update needed? */
55 if (!need_update && !object->get_geometry()->is_modified() &&
56 !scene->object_manager->need_update())
57 {
58 return true;
59 }
60
61 /* first time used in this sync loop? clear and tag update */
62 if (first_use) {
63 psys->particles.clear();
64 psys->tag_update(scene);
65 }
66
67 /* add particle */
68 blender::ParticleData &b_pa = b_psys->particles[persistent_id[0]];
69 Particle pa;
70
71 pa.index = persistent_id[0];
72 pa.age = BKE_scene_frame_to_ctime(b_scene, b_scene->r.cfra) - b_pa.time;
73 pa.lifetime = b_pa.lifetime;
74 pa.location = make_float3(b_pa.state.co[0], b_pa.state.co[1], b_pa.state.co[2]);
76 b_pa.state.rot[0], b_pa.state.rot[1], b_pa.state.rot[2], b_pa.state.rot[3]);
77 pa.size = b_pa.size;
78 pa.velocity = make_float3(b_pa.state.vel[0], b_pa.state.vel[1], b_pa.state.vel[2]);
79 pa.angular_velocity = make_float3(b_pa.state.ave[0], b_pa.state.ave[1], b_pa.state.ave[2]);
80
81 psys->particles.push_back_slow(pa);
82
83 object->set_particle_system(psys);
84 object->set_particle_index(psys->particles.size() - 1);
85
86 if (object->particle_index_is_modified()) {
87 scene->object_manager->tag_update(scene, ObjectManager::PARTICLE_MODIFIED);
88 }
89
90 /* return that this object has particle data */
91 return true;
92}
93
array< Particle > particles
Definition particles.h:41
void tag_update(Scene *scene)
size_t size() const
void push_back_slow(const T &t)
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
@ ATTR_STD_PARTICLE
float BKE_scene_frame_to_ctime(const Scene *scene, int frame)
Definition scene.cc:2586
#define make_float4
bool is_modified() const
float age
Definition particles.h:23
float lifetime
Definition particles.h:24
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
int persistent_id[MAX_DUPLI_RECUR]
ParticleSystem * particle_system