[Bf-blender-cvs] [eb2da8bc5ab] functions: improve attribute interface
Jacques Lucke
noreply at git.blender.org
Mon Jul 1 13:44:14 CEST 2019
Commit: eb2da8bc5ab72e4c895097a7c75c6fffb3991048
Author: Jacques Lucke
Date: Mon Jul 1 12:39:02 2019 +0200
Branches: functions
https://developer.blender.org/rBeb2da8bc5ab72e4c895097a7c75c6fffb3991048
improve attribute interface
===================================================================
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 45d22955a66..b229efae25e 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -174,10 +174,10 @@ class ModifierParticleType : public ParticleType {
return *m_integrator;
}
- ArrayRef<std::string> float3_attributes() override
+ void attributes(TypeAttributeInterface &interface) override
{
- static std::array<std::string, 2> attributes = {"Position", "Velocity"};
- return attributes;
+ interface.use(AttributeType::Float3, "Position");
+ interface.use(AttributeType::Float3, "Velocity");
}
};
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index d9ca1a9ac29..c29945d090c 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -21,6 +21,7 @@ class EventFilterInterface;
class EventExecuteInterface;
class EmitterInterface;
class IntegratorInterface;
+class TypeAttributeInterface;
/* Main API for the particle simulation. These classes have to be subclassed to define how the
* particles should behave.
@@ -126,20 +127,11 @@ class ParticleType {
*/
virtual ArrayRef<Event *> events() = 0;
- virtual ArrayRef<std::string> byte_attributes()
- {
- return {};
- }
-
- virtual ArrayRef<std::string> float_attributes()
- {
- return {};
- }
-
- virtual ArrayRef<std::string> float3_attributes()
- {
- return {};
- }
+ /**
+ * Determines which attributes have to be stored for particles of this type. The actual number of
+ * attributes might be larger.
+ */
+ virtual void attributes(TypeAttributeInterface &interface) = 0;
};
/**
@@ -414,6 +406,17 @@ class IntegratorInterface {
AttributeArrays offset_targets();
};
+class TypeAttributeInterface {
+ SmallVector<std::string> m_names;
+ SmallVector<AttributeType> m_types;
+
+ public:
+ void use(AttributeType type, StringRef attribute_name);
+
+ ArrayRef<std::string> names();
+ ArrayRef<AttributeType> types();
+};
+
/* ParticlesState inline functions
********************************************/
@@ -664,4 +667,23 @@ inline AttributeArrays IntegratorInterface::offset_targets()
return m_offsets;
}
+/* TypeAttributeInterface
+ ********************************************/
+
+inline void TypeAttributeInterface::use(AttributeType type, StringRef attribute_name)
+{
+ m_types.append(type);
+ m_names.append(attribute_name.to_std_string());
+}
+
+inline ArrayRef<std::string> TypeAttributeInterface::names()
+{
+ return m_names;
+}
+
+inline ArrayRef<AttributeType> TypeAttributeInterface::types()
+{
+ return m_types;
+}
+
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index d3228752907..6e8572e8d48 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -679,13 +679,27 @@ BLI_NOINLINE static void ensure_required_containers_exist(ParticlesState &state,
BLI_NOINLINE static AttributesInfo build_attribute_info_for_type(ParticleType &type,
AttributesInfo &UNUSED(last_info))
{
+ TypeAttributeInterface interface;
+ type.attributes(interface);
+
SmallSetVector<std::string> byte_attributes = {"Kill State"};
SmallSetVector<std::string> float_attributes = {"Birth Time"};
SmallSetVector<std::string> float3_attributes = {};
- byte_attributes.add_multiple(type.byte_attributes());
- float_attributes.add_multiple(type.float_attributes());
- float3_attributes.add_multiple(type.float3_attributes());
+ for (uint i = 0; i < interface.names().size(); i++) {
+ std::string &name = interface.names()[i];
+ switch (interface.types()[i]) {
+ case AttributeType::Byte:
+ byte_attributes.add(name);
+ break;
+ case AttributeType::Float:
+ float_attributes.add(name);
+ break;
+ case AttributeType::Float3:
+ float3_attributes.add(name);
+ break;
+ }
+ }
return AttributesInfo(byte_attributes, float_attributes, float3_attributes);
}
More information about the Bf-blender-cvs
mailing list