Welcome to mirror list, hosted at ThFree Co, Russian Federation.

particle_action.cpp « bparticles « simulations « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 83dd7dc1ec5d762f439589d2b9c11ce942811614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "particle_action.hpp"

BLI_CREATE_CLASS_ID(BParticles::ParticleCurrentTimesContext)
BLI_CREATE_CLASS_ID(BParticles::ParticleIntegratedOffsets)
BLI_CREATE_CLASS_ID(BParticles::ParticleRemainingTimeInStep)

namespace BParticles {

ParticleAction::~ParticleAction()
{
}

void ParticleAction::execute_from_emitter(AttributesRefGroup &new_particles,
                                          EmitterInterface &emitter_interface)
{
  BufferCache buffer_cache;
  std::array<BLI::class_id_t, 1> context_ids = {BLI::get_class_id<ParticleCurrentTimesContext>()};

  for (MutableAttributesRef attributes : new_particles) {
    ParticleCurrentTimesContext current_times_context;
    current_times_context.current_times = attributes.get<float>("Birth Time");

    ParticleActionContext context(emitter_interface.particle_allocator(),
                                  IndexMask(attributes.size()),
                                  attributes,
                                  buffer_cache,
                                  context_ids,
                                  {(void *)&current_times_context});
    this->execute(context);
  }
}

void ParticleAction::execute_for_new_particles(AttributesRefGroup &new_particles,
                                               ParticleActionContext &parent_context)
{
  std::array<BLI::class_id_t, 1> context_ids = {BLI::get_class_id<ParticleCurrentTimesContext>()};

  for (MutableAttributesRef attributes : new_particles) {
    ParticleCurrentTimesContext current_times_context;
    current_times_context.current_times = attributes.get<float>("Birth Time");

    ParticleActionContext context(parent_context.particle_allocator(),
                                  IndexMask(attributes.size()),
                                  attributes,
                                  parent_context.buffer_cache(),
                                  context_ids,
                                  {(void *)&current_times_context});
    this->execute(context);
  }
}

void ParticleAction::execute_for_new_particles(AttributesRefGroup &new_particles,
                                               OffsetHandlerInterface &offset_handler_interface)
{
  std::array<BLI::class_id_t, 1> context_ids = {BLI::get_class_id<ParticleCurrentTimesContext>()};

  for (MutableAttributesRef attributes : new_particles) {
    ParticleCurrentTimesContext current_times_context;
    current_times_context.current_times = attributes.get<float>("Birth Time");

    ParticleActionContext context(offset_handler_interface.particle_allocator(),
                                  IndexMask(attributes.size()),
                                  attributes,
                                  offset_handler_interface.buffer_cache(),
                                  context_ids,
                                  {(void *)&current_times_context});
    this->execute(context);
  }
}

void ParticleAction::execute_from_event(EventExecuteInterface &event_interface)
{
  ParticleCurrentTimesContext current_times_context;
  current_times_context.current_times = event_interface.current_times();
  ParticleIntegratedOffsets offsets_context = {event_interface.attribute_offsets()};
  ParticleRemainingTimeInStep remaining_time_context;
  remaining_time_context.remaining_times = event_interface.remaining_durations();

  std::array<BLI::class_id_t, 3> context_ids = {BLI::get_class_id<ParticleCurrentTimesContext>(),
                                                BLI::get_class_id<ParticleIntegratedOffsets>(),
                                                BLI::get_class_id<ParticleRemainingTimeInStep>()};
  std::array<void *, 3> contexts = {
      (void *)&current_times_context, (void *)&offsets_context, (void *)&remaining_time_context};

  ParticleActionContext context(event_interface.particle_allocator(),
                                event_interface.pindices(),
                                event_interface.attributes(),
                                event_interface.buffer_cache(),
                                context_ids,
                                contexts);
  this->execute(context);
}

void ParticleAction::execute_for_subset(IndexMask mask, ParticleActionContext &parent_context)
{
  ParticleActionContext context(parent_context.particle_allocator(),
                                mask,
                                parent_context.attributes(),
                                parent_context.buffer_cache(),
                                parent_context.custom_context_ids(),
                                parent_context.custom_contexts());
  this->execute(context);
}

void ParticleAction::execute_from_offset_handler(OffsetHandlerInterface &offset_handler_interface)
{
  Array<float> current_times(offset_handler_interface.array_size());
  for (uint pindex : offset_handler_interface.mask()) {
    current_times[pindex] = offset_handler_interface.time_span(pindex).start();
  }

  ParticleCurrentTimesContext current_times_context;
  current_times_context.current_times = current_times;
  ParticleIntegratedOffsets offsets_context = {offset_handler_interface.attribute_offsets()};
  ParticleRemainingTimeInStep remaining_time_context;
  remaining_time_context.remaining_times = offset_handler_interface.remaining_durations();

  std::array<BLI::class_id_t, 3> context_ids = {BLI::get_class_id<ParticleCurrentTimesContext>(),
                                                BLI::get_class_id<ParticleIntegratedOffsets>(),
                                                BLI::get_class_id<ParticleRemainingTimeInStep>()};
  std::array<void *, 3> contexts = {
      (void *)&current_times_context, (void *)&offsets_context, (void *)&remaining_time_context};

  ParticleActionContext context(offset_handler_interface.particle_allocator(),
                                offset_handler_interface.mask(),
                                offset_handler_interface.attributes(),
                                offset_handler_interface.buffer_cache(),
                                context_ids,
                                contexts);
  this->execute(context);
}

}  // namespace BParticles