[Bf-blender-cvs] [5063820c9b7] master: Particles: Emit particles over time
Jacques Lucke
noreply at git.blender.org
Sun Jul 19 13:59:05 CEST 2020
Commit: 5063820c9b7fdc499c0aa16ca850541101ffda09
Author: Jacques Lucke
Date: Sun Jul 19 13:58:49 2020 +0200
Branches: master
https://developer.blender.org/rB5063820c9b7fdc499c0aa16ca850541101ffda09
Particles: Emit particles over time
This adds a basic internal emitter for every particle simulation.
The emitter cannot be controlled by the user yet. That will
come next.
===================================================================
M source/blender/makesdna/DNA_simulation_types.h
M source/blender/modifiers/intern/MOD_simulation.cc
M source/blender/simulation/CMakeLists.txt
A source/blender/simulation/intern/particle_allocator.cc
A source/blender/simulation/intern/particle_allocator.hh
M source/blender/simulation/intern/particle_function.cc
R094 source/blender/simulation/SIM_particle_function.hh source/blender/simulation/intern/particle_function.hh
M source/blender/simulation/intern/simulation_collect_influences.cc
M source/blender/simulation/intern/simulation_solver.cc
M source/blender/simulation/intern/simulation_solver.hh
M source/blender/simulation/intern/simulation_update.cc
A source/blender/simulation/intern/time_interval.hh
===================================================================
diff --git a/source/blender/makesdna/DNA_simulation_types.h b/source/blender/makesdna/DNA_simulation_types.h
index a2b81b731d3..c4ff51a107e 100644
--- a/source/blender/makesdna/DNA_simulation_types.h
+++ b/source/blender/makesdna/DNA_simulation_types.h
@@ -32,6 +32,8 @@ typedef struct Simulation {
int flag;
float current_frame;
+ float current_simulation_time;
+ char _pad[4];
/** List containing SimulationState objects. */
struct ListBase states;
@@ -53,7 +55,7 @@ typedef struct ParticleSimulationState {
/** Contains the state of the particles at time Simulation->current_frame. */
int tot_particles;
- int _pad;
+ int next_particle_id;
struct CustomData attributes;
/** Caches the state of the particles over time. The cache only exists on the original data
diff --git a/source/blender/modifiers/intern/MOD_simulation.cc b/source/blender/modifiers/intern/MOD_simulation.cc
index 38dc1546763..819ed320255 100644
--- a/source/blender/modifiers/intern/MOD_simulation.cc
+++ b/source/blender/modifiers/intern/MOD_simulation.cc
@@ -129,7 +129,7 @@ static PointCloud *modifyPointCloud(ModifierData *md,
memcpy(pointcloud->co, positions, sizeof(float3) * state->tot_particles);
for (int i = 0; i < state->tot_particles; i++) {
- pointcloud->radius[i] = 0.1f;
+ pointcloud->radius[i] = 0.03f;
}
return pointcloud;
diff --git a/source/blender/simulation/CMakeLists.txt b/source/blender/simulation/CMakeLists.txt
index a19e96e1a91..243b056db74 100644
--- a/source/blender/simulation/CMakeLists.txt
+++ b/source/blender/simulation/CMakeLists.txt
@@ -41,6 +41,7 @@ set(SRC
intern/hair_volume.cpp
intern/implicit_blender.c
intern/implicit_eigen.cpp
+ intern/particle_allocator.cc
intern/particle_function.cc
intern/simulation_collect_influences.cc
intern/simulation_solver.cc
@@ -49,11 +50,13 @@ set(SRC
intern/ConstrainedConjugateGradient.h
intern/eigen_utils.h
intern/implicit.h
+ intern/particle_allocator.hh
+ intern/particle_function.hh
intern/simulation_collect_influences.hh
intern/simulation_solver.hh
+ intern/time_interval.hh
SIM_mass_spring.h
- SIM_particle_function.hh
SIM_simulation_update.hh
)
diff --git a/source/blender/simulation/intern/particle_allocator.cc b/source/blender/simulation/intern/particle_allocator.cc
new file mode 100644
index 00000000000..b65c0197c76
--- /dev/null
+++ b/source/blender/simulation/intern/particle_allocator.cc
@@ -0,0 +1,77 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "particle_allocator.hh"
+
+namespace blender::sim {
+
+AttributesAllocator::~AttributesAllocator()
+{
+ for (std::unique_ptr<AttributesBlock> &block : allocated_blocks_) {
+ for (uint i : attributes_info_.index_range()) {
+ const fn::CPPType &type = attributes_info_.type_of(i);
+ type.destruct_n(block->buffers[i], block->size);
+ MEM_freeN(block->buffers[i]);
+ }
+ }
+}
+
+fn::MutableAttributesRef AttributesAllocator::allocate_uninitialized(uint size)
+{
+ std::unique_ptr<AttributesBlock> block = std::make_unique<AttributesBlock>();
+ block->buffers = Array<void *>(attributes_info_.size(), nullptr);
+ block->size = size;
+
+ for (uint i : attributes_info_.index_range()) {
+ const fn::CPPType &type = attributes_info_.type_of(i);
+ void *buffer = MEM_mallocN_aligned(size * type.size(), type.alignment(), AT);
+ block->buffers[i] = buffer;
+ }
+
+ fn::MutableAttributesRef attributes{attributes_info_, block->buffers, size};
+
+ {
+ std::lock_guard lock{mutex_};
+ allocated_blocks_.append(std::move(block));
+ allocated_attributes_.append(attributes);
+ total_allocated_ += size;
+ }
+
+ return attributes;
+}
+
+fn::MutableAttributesRef ParticleAllocator::allocate(uint size)
+{
+ const fn::AttributesInfo &info = attributes_allocator_.attributes_info();
+ fn::MutableAttributesRef attributes = attributes_allocator_.allocate_uninitialized(size);
+ for (uint i : info.index_range()) {
+ const fn::CPPType &type = info.type_of(i);
+ StringRef name = info.name_of(i);
+ if (name == "ID") {
+ uint start_id = next_id_.fetch_add(size);
+ MutableSpan<int> ids = attributes.get<int>("ID");
+ for (uint pindex : IndexRange(size)) {
+ ids[pindex] = start_id + pindex;
+ }
+ }
+ else {
+ type.fill_uninitialized(info.default_of(i), attributes.get(i).buffer(), size);
+ }
+ }
+ return attributes;
+}
+
+} // namespace blender::sim
diff --git a/source/blender/simulation/intern/particle_allocator.hh b/source/blender/simulation/intern/particle_allocator.hh
new file mode 100644
index 00000000000..f854413c9aa
--- /dev/null
+++ b/source/blender/simulation/intern/particle_allocator.hh
@@ -0,0 +1,95 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __SIM_PARTICLE_ALLOCATOR_HH__
+#define __SIM_PARTICLE_ALLOCATOR_HH__
+
+#include "BLI_array.hh"
+#include "BLI_vector.hh"
+
+#include "FN_attributes_ref.hh"
+
+#include <atomic>
+#include <mutex>
+
+namespace blender::sim {
+
+class AttributesAllocator : NonCopyable, NonMovable {
+ private:
+ struct AttributesBlock {
+ Array<void *> buffers;
+ uint size;
+ };
+
+ const fn::AttributesInfo &attributes_info_;
+ Vector<std::unique_ptr<AttributesBlock>> allocated_blocks_;
+ Vector<fn::MutableAttributesRef> allocated_attributes_;
+ uint total_allocated_ = 0;
+ std::mutex mutex_;
+
+ public:
+ AttributesAllocator(const fn::AttributesInfo &attributes_info)
+ : attributes_info_(attributes_info)
+ {
+ }
+
+ ~AttributesAllocator();
+
+ Span<fn::MutableAttributesRef> get_allocations() const
+ {
+ return allocated_attributes_;
+ }
+
+ uint total_allocated() const
+ {
+ return total_allocated_;
+ }
+
+ const fn::AttributesInfo &attributes_info() const
+ {
+ return attributes_info_;
+ }
+
+ fn::MutableAttributesRef allocate_uninitialized(uint size);
+};
+
+class ParticleAllocator : NonCopyable, NonMovable {
+ private:
+ AttributesAllocator attributes_allocator_;
+ std::atomic<uint> next_id_;
+
+ public:
+ ParticleAllocator(const fn::AttributesInfo &attributes_info, uint next_id)
+ : attributes_allocator_(attributes_info), next_id_(next_id)
+ {
+ }
+
+ Span<fn::MutableAttributesRef> get_allocations() const
+ {
+ return attributes_allocator_.get_allocations();
+ }
+
+ uint total_allocated() const
+ {
+ return attributes_allocator_.total_allocated();
+ }
+
+ fn::MutableAttributesRef allocate(uint size);
+};
+
+} // namespace blender::sim
+
+#endif /* __SIM_PARTICLE_ALLOCATOR_HH__ */
diff --git a/source/blender/simulation/intern/particle_function.cc b/source/blender/simulation/intern/particle_function.cc
index 7a0c9ccdb13..3788fd17e36 100644
--- a/source/blender/simulation/intern/particle_function.cc
+++ b/source/blender/simulation/intern/particle_function.cc
@@ -14,7 +14,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "SIM_particle_function.hh"
+#include "particle_function.hh"
namespace blender::sim {
@@ -49,12 +49,11 @@ ParticleFunction::ParticleFunction(const fn::MultiFunction *global_fn,
}
}
-ParticleFunctionEvaluator::ParticleFunctionEvaluator(const ParticleFunction &particle_fn,
- IndexMask mask,
- fn::AttributesRef particle_attributes)
+ParticleFunctionEvaluator::ParticleFunctionEvaluator(
+ const ParticleFunction &particle_fn, const ParticleChunkContext &particle_chunk_context)
: particle_fn_(particle_fn),
- mask_(mask),
- particle_attributes_(particle_attributes),
+ particle_chunk_context_(particle_chunk_context),
+ mask_(particle_chunk_context_.index_mask()),
outputs_(particle_fn_.output_types_.size(), nullptr)
{
}
@@ -112,7 +111,7 @@ void ParticleFunctionEvaluator::compute_globals()
/* Add input parameters. */
for (const ParticleFunctionInput *input : particle_fn_.global_inputs_) {
- input->add_input(particle_attributes_, params, resources_);
+ input->add_input(particle_chunk_context_.attributes(), params, resources_);
}
/* Add output parameters. */
@@ -139,7 +138,7 @@ void ParticleFunctionEvaluator::compute_per_particle()
/* Add input parameters. */
for (const ParticleFunctionInput *input : particle_fn_.per_particle_inputs_) {
- input->add_input(particle_attributes_, params, resources_);
+ input->add_input(particle_chunk_context_.attributes(), params, resources_);
}
/* Add output parameters. */
diff --git a/source/blender/simulation/SIM_particle_function.hh b/source/blender/simulation/intern/particle_function.hh
similarity index 94%
rename from source/blender/simulation/SIM_particle_function.hh
rename to source/blender/simulation/intern/particle_function.hh
index eae61b1ae11..abed90
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list