[Bf-blender-cvs] [941159fba57] functions: emitter can decide which attributes it initializes
Jacques Lucke
noreply at git.blender.org
Sat Jun 8 14:21:55 CEST 2019
Commit: 941159fba573461659fe7b9322a3b9842843fd22
Author: Jacques Lucke
Date: Sat Jun 8 12:59:04 2019 +0200
Branches: functions
https://developer.blender.org/rB941159fba573461659fe7b9322a3b9842843fd22
emitter can decide which attributes it initializes
===================================================================
M source/blender/blenlib/BLI_small_set_vector.hpp
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/particles_container.cpp
M source/blender/simulations/bparticles/particles_container.hpp
M source/blender/simulations/bparticles/playground_solver.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_small_set_vector.hpp b/source/blender/blenlib/BLI_small_set_vector.hpp
index 4027735fca7..7dfc4bc5ee4 100644
--- a/source/blender/blenlib/BLI_small_set_vector.hpp
+++ b/source/blender/blenlib/BLI_small_set_vector.hpp
@@ -28,6 +28,11 @@ template<typename T> class SmallSetVector : public SmallSet<T> {
return this->m_lookup.find(this->m_elements.begin(), value);
}
+ ArrayRef<T> values() const
+ {
+ return ArrayRef<T>(this->begin(), this->size());
+ }
+
T operator[](const int index) const
{
BLI_assert(index >= 0 && index < this->size());
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 2598d0056e4..f0d28cda988 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -13,6 +13,7 @@
return (T2)value; \
}
+using BParticles::AttributeType;
using BParticles::Description;
using BParticles::EmitterDestination;
using BParticles::NamedBuffers;
@@ -22,6 +23,7 @@ using BParticles::StateBase;
using BParticles::WrappedState;
using BLI::ArrayRef;
+using BLI::StringRef;
using BLI::Vec3;
WRAPPERS(BParticles::Description *, BParticlesDescription);
@@ -48,6 +50,14 @@ class TestForce : public BParticles::Force {
class TestEmitter : public BParticles::Emitter {
public:
+ void attributes(std::function<void(AttributeType type, StringRef attribute_name)>
+ register_attribute) override
+ {
+ register_attribute(AttributeType::Vector3, "Position");
+ register_attribute(AttributeType::Vector3, "Velocity");
+ register_attribute(AttributeType::Float, "Age");
+ }
+
void emit(std::function<EmitterDestination &()> request_destination) override
{
EmitterDestination &dst = request_destination();
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index b22050c65ae..ecd9c6f483c 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -20,6 +20,11 @@ using BLI::StringRef;
using BLI::Vec3;
using std::unique_ptr;
+enum AttributeType {
+ Float = 1,
+ Vector3 = 2,
+};
+
class NamedBuffers {
public:
virtual ~NamedBuffers();
@@ -74,6 +79,8 @@ class EmitterDestination {
class Emitter {
public:
virtual ~Emitter();
+ virtual void attributes(
+ std::function<void(AttributeType type, StringRef name)> register_attribute) = 0;
virtual void emit(std::function<EmitterDestination &()> request_destination) = 0;
};
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index 3e59b4cfe0a..b15bc27fc09 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -16,11 +16,11 @@ ParticlesBlock::ParticlesBlock(ParticlesContainer &container,
}
ParticlesContainer::ParticlesContainer(uint block_size,
- const SmallVector<std::string> &float_attribute_names,
- const SmallVector<std::string> &vec3_attribute_names)
+ ArrayRef<std::string> float_attribute_names,
+ ArrayRef<std::string> vec3_attribute_names)
: m_block_size(block_size),
- m_float_attribute_names(float_attribute_names),
- m_vec3_attribute_names(vec3_attribute_names)
+ m_float_attribute_names(float_attribute_names.to_small_vector()),
+ m_vec3_attribute_names(vec3_attribute_names.to_small_vector())
{
BLI_assert(
SmallSetVector<std::string>::Disjoint(m_float_attribute_names, m_vec3_attribute_names));
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 85b86727169..11d2a014412 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -30,8 +30,8 @@ class ParticlesContainer {
public:
ParticlesContainer(uint block_size,
- const SmallVector<std::string> &float_attribute_names,
- const SmallVector<std::string> &vec3_attribute_names);
+ ArrayRef<std::string> float_attribute_names,
+ ArrayRef<std::string> vec3_attribute_names);
~ParticlesContainer();
diff --git a/source/blender/simulations/bparticles/playground_solver.cpp b/source/blender/simulations/bparticles/playground_solver.cpp
index 3c01d332a1d..03a28aab011 100644
--- a/source/blender/simulations/bparticles/playground_solver.cpp
+++ b/source/blender/simulations/bparticles/playground_solver.cpp
@@ -25,8 +25,28 @@ class SimpleSolver : public Solver {
StateBase *init() override
{
+ SmallSetVector<std::string> float_attributes;
+ SmallSetVector<std::string> vec3_attributes;
+
+ for (Emitter *emitter : m_description.emitters()) {
+ emitter->attributes(
+ [&float_attributes, &vec3_attributes](AttributeType type, StringRef name) -> void {
+ switch (type) {
+ case AttributeType::Float:
+ float_attributes.add(name.to_std_string());
+ break;
+ case AttributeType::Vector3:
+ vec3_attributes.add(name.to_std_string());
+ break;
+ default:
+ BLI_assert(false);
+ }
+ });
+ }
+
MyState *state = new MyState();
- state->particles = new ParticlesContainer(10, {"Age"}, {"Position", "Velocity"});
+ state->particles = new ParticlesContainer(
+ 10, float_attributes.values(), vec3_attributes.values());
return state;
}
More information about the Bf-blender-cvs
mailing list