[Bf-blender-cvs] [38e223e392e] functions: initialize attributes by repeating a given array
Jacques Lucke
noreply at git.blender.org
Tue Jul 16 11:38:08 CEST 2019
Commit: 38e223e392ebd98b84cddf5d2bdf64b8a8deba75
Author: Jacques Lucke
Date: Tue Jul 16 10:00:57 2019 +0200
Branches: functions
https://developer.blender.org/rB38e223e392ebd98b84cddf5d2bdf64b8a8deba75
initialize attributes by repeating a given array
===================================================================
M source/blender/simulations/bparticles/core.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/emitters.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index e7ca5598d38..e04e0b1bf3b 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -155,6 +155,34 @@ void ParticleSets::set_elements(uint index, void *data)
}
}
+void ParticleSets::set_repeated_elements(uint index,
+ void *data,
+ uint data_element_amount,
+ void *default_value)
+{
+ if (data_element_amount == 0) {
+ this->fill_elements(index, default_value);
+ return;
+ }
+
+ AttributeType type = m_attributes_info.type_of(index);
+ uint element_size = size_of_attribute_type(type);
+ uint offset = 0;
+ for (ParticleSet particles : m_sets) {
+ AttributeArrays attributes = particles.attributes();
+ void *dst = attributes.get_ptr(index);
+ for (uint pindex : particles.pindices()) {
+ memcpy(POINTER_OFFSET(dst, element_size * pindex),
+ POINTER_OFFSET(data, element_size * offset),
+ element_size);
+ offset++;
+ if (offset == data_element_amount) {
+ offset = 0;
+ }
+ }
+ }
+}
+
void ParticleSets::fill_elements(uint index, void *value)
{
AttributeType type = m_attributes_info.type_of(index);
@@ -205,6 +233,41 @@ void ParticleSets::set_float3(StringRef name, ArrayRef<float3> data)
this->set_float3(index, data);
}
+void ParticleSets::set_repeated_byte(uint index, ArrayRef<uint8_t> data)
+{
+ BLI_assert(m_attributes_info.type_of(index) == AttributeType::Byte);
+ this->set_repeated_elements(
+ index, (void *)data.begin(), data.size(), m_attributes_info.default_value_ptr(index));
+}
+void ParticleSets::set_repeated_float(uint index, ArrayRef<float> data)
+{
+ BLI_assert(m_attributes_info.type_of(index) == AttributeType::Float);
+ this->set_repeated_elements(
+ index, (void *)data.begin(), data.size(), m_attributes_info.default_value_ptr(index));
+}
+void ParticleSets::set_repeated_float3(uint index, ArrayRef<float3> data)
+{
+ BLI_assert(m_attributes_info.type_of(index) == AttributeType::Float3);
+ this->set_repeated_elements(
+ index, (void *)data.begin(), data.size(), m_attributes_info.default_value_ptr(index));
+}
+
+void ParticleSets::set_repeated_byte(StringRef name, ArrayRef<uint8_t> data)
+{
+ uint index = m_attributes_info.attribute_index(name);
+ this->set_repeated_byte(index, data);
+}
+void ParticleSets::set_repeated_float(StringRef name, ArrayRef<float> data)
+{
+ uint index = m_attributes_info.attribute_index(name);
+ this->set_repeated_float(index, data);
+}
+void ParticleSets::set_repeated_float3(StringRef name, ArrayRef<float3> data)
+{
+ uint index = m_attributes_info.attribute_index(name);
+ this->set_repeated_float3(index, data);
+}
+
void ParticleSets::fill_byte(uint index, uint8_t value)
{
this->fill_elements(index, (void *)&value);
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 7d319387d80..5c45a99595e 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -275,6 +275,13 @@ class ParticleSets {
void set_float3(uint index, ArrayRef<float3> data);
void set_float3(StringRef name, ArrayRef<float3> data);
+ void set_repeated_byte(uint index, ArrayRef<uint8_t> data);
+ void set_repeated_byte(StringRef name, ArrayRef<uint8_t> data);
+ void set_repeated_float(uint index, ArrayRef<float> data);
+ void set_repeated_float(StringRef name, ArrayRef<float> data);
+ void set_repeated_float3(uint index, ArrayRef<float3> data);
+ void set_repeated_float3(StringRef name, ArrayRef<float3> data);
+
void fill_byte(uint index, uint8_t value);
void fill_byte(StringRef name, uint8_t value);
void fill_float(uint index, float value);
@@ -286,6 +293,10 @@ class ParticleSets {
private:
void set_elements(uint index, void *data);
+ void set_repeated_elements(uint index,
+ void *data,
+ uint data_element_amount,
+ void *default_value);
void fill_elements(uint index, void *value);
};
diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index ef0b0aa17c8..d747e9960a5 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -138,6 +138,7 @@ void CustomFunctionEmitter::emit(EmitterInterface &interface)
new_positions->size());
target.set_float3("Position", *new_positions.ptr());
target.fill_float("Birth Time", interface.time_span().end());
+ target.set_repeated_float("Size", {0.05f, 0.05f, 0.1f});
}
} // namespace BParticles
More information about the Bf-blender-cvs
mailing list