[Bf-blender-cvs] [c2e63d660b7] functions: add color attribute type
Jacques Lucke
noreply at git.blender.org
Tue Jul 30 13:45:48 CEST 2019
Commit: c2e63d660b7df00b0576920029b473556b019215
Author: Jacques Lucke
Date: Tue Jul 30 13:44:39 2019 +0200
Branches: functions
https://developer.blender.org/rBc2e63d660b7df00b0576920029b473556b019215
add color attribute type
===================================================================
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/attributes.hpp
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/node_frontend.cpp
M source/blender/simulations/bparticles/particles_container.cpp
M source/blender/simulations/bparticles/particles_container.hpp
===================================================================
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 6734e46b159..a898f50cf96 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -38,14 +38,12 @@ void ChangeDirectionAction::execute(ActionInterface &interface)
void ChangeColorAction::execute(ActionInterface &interface)
{
ParticleSet particles = interface.particles();
- auto colors = particles.attributes().get<float3>("Color");
+ auto colors = particles.attributes().get<rgba_f>("Color");
auto inputs = m_compute_inputs->compute(interface);
for (uint pindex : particles.pindices()) {
rgba_f color = inputs->get<rgba_f>("Color", 0, pindex);
- colors[pindex].x = color.r;
- colors[pindex].y = color.g;
- colors[pindex].z = color.b;
+ colors[pindex] = color;
}
m_post_action->execute(interface);
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 9ea8b6fcb60..1cbd2c6332c 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -18,6 +18,7 @@ using BLI::ArrayRef;
using BLI::float3;
using BLI::Optional;
using BLI::Range;
+using BLI::rgba_f;
using BLI::SetVector;
using BLI::StringRef;
using BLI::StringRefNull;
@@ -32,6 +33,7 @@ enum AttributeType {
Integer,
Float,
Float3,
+ RGBA_f,
};
template<typename T> struct attribute_type_by_type {
@@ -46,6 +48,7 @@ ATTRIBUTE_TYPE_BY_TYPE(uint8_t, Byte);
ATTRIBUTE_TYPE_BY_TYPE(int32_t, Integer);
ATTRIBUTE_TYPE_BY_TYPE(float, Float);
ATTRIBUTE_TYPE_BY_TYPE(float3, Float3);
+ATTRIBUTE_TYPE_BY_TYPE(rgba_f, RGBA_f);
#undef ATTRIBUTE_TYPE_BY_TYPE
@@ -65,13 +68,15 @@ inline uint size_of_attribute_type(AttributeType type)
return sizeof(float);
case AttributeType::Float3:
return sizeof(float3);
+ case AttributeType::RGBA_f:
+ return sizeof(rgba_f);
default:
BLI_assert(false);
return 0;
};
}
-#define MAX_ATTRIBUTE_SIZE sizeof(float3)
+#define MAX_ATTRIBUTE_SIZE sizeof(rgba_f)
struct AnyAttributeValue {
char storage[MAX_ATTRIBUTE_SIZE];
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index dfb3962a55c..26e082912f4 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -35,8 +35,8 @@ using BKE::IndexedNodeTree;
using BKE::SocketWithNode;
using BLI::ArrayRef;
using BLI::float3;
-using BLI::Vector;
using BLI::StringRef;
+using BLI::Vector;
WRAPPERS(ParticlesState *, BParticlesState);
@@ -138,7 +138,7 @@ static void distribute_tetrahedons_range(Mesh *mesh,
Range<uint> range,
ArrayRef<float3> centers,
ArrayRef<float> scales,
- ArrayRef<float3> colors)
+ ArrayRef<rgba_f> colors)
{
for (uint instance : range) {
uint vertex_offset = instance * ARRAY_SIZE(tetrahedon_vertices);
@@ -157,9 +157,9 @@ static void distribute_tetrahedons_range(Mesh *mesh,
mesh->mpoly[face_offset + i].totloop = tetrahedon_loop_lengths[i];
}
- float3 color_f = colors[instance];
+ rgba_f color_f = colors[instance];
MLoopCol color_b = {
- (uchar)(color_f.x * 255.0f), (uchar)(color_f.y * 255.0f), (uchar)(color_f.z * 255.0f)};
+ (uchar)(color_f.r * 255.0f), (uchar)(color_f.g * 255.0f), (uchar)(color_f.b * 255.0f)};
for (uint i = 0; i < ARRAY_SIZE(tetrahedon_loop_vertices); i++) {
mesh->mloop[loop_offset + i].v = vertex_offset + tetrahedon_loop_vertices[i];
loop_colors[loop_offset + i] = color_b;
@@ -174,7 +174,7 @@ static void distribute_tetrahedons_range(Mesh *mesh,
static Mesh *distribute_tetrahedons(ArrayRef<float3> centers,
ArrayRef<float> scales,
- ArrayRef<float3> colors)
+ ArrayRef<rgba_f> colors)
{
SCOPED_TIMER(__func__);
@@ -237,7 +237,7 @@ Mesh *BParticles_modifier_point_mesh_from_state(BParticlesState state_c)
Vector<float3> positions;
for (ParticlesContainer *container : state.particle_containers().values()) {
- positions.extend(container->flatten_attribute_float3("Position"));
+ positions.extend(container->flatten_attribute<float3>("Position"));
}
Mesh *mesh = BKE_mesh_new_nomain(positions.size(), 0, 0, 0, 0);
@@ -257,12 +257,12 @@ Mesh *BParticles_modifier_mesh_from_state(BParticlesState state_c)
Vector<float3> positions;
Vector<float> sizes;
- Vector<float3> colors;
+ Vector<rgba_f> colors;
for (ParticlesContainer *container : state.particle_containers().values()) {
- positions.extend(container->flatten_attribute_float3("Position"));
- colors.extend(container->flatten_attribute_float3("Color"));
- sizes.extend(container->flatten_attribute_float("Size"));
+ positions.extend(container->flatten_attribute<float3>("Position"));
+ colors.extend(container->flatten_attribute<rgba_f>("Color"));
+ sizes.extend(container->flatten_attribute<float>("Size"));
}
Mesh *mesh = distribute_tetrahedons(positions, sizes, colors);
@@ -275,7 +275,7 @@ Mesh *BParticles_modifier_mesh_from_cache(BParticlesFrameCache *cached_frame)
Vector<float3> positions;
Vector<float> sizes;
- Vector<float3> colors;
+ Vector<rgba_f> colors;
for (uint i = 0; i < cached_frame->num_particle_types; i++) {
BParticlesTypeCache &type = cached_frame->particle_types[i];
@@ -283,7 +283,7 @@ Mesh *BParticles_modifier_mesh_from_cache(BParticlesFrameCache *cached_frame)
ArrayRef<float3>((float3 *)type.attributes_float[0].values, type.particle_amount));
sizes.extend(ArrayRef<float>(type.attributes_float[1].values, type.particle_amount));
colors.extend(
- ArrayRef<float3>((float3 *)type.attributes_float[2].values, type.particle_amount));
+ ArrayRef<rgba_f>((rgba_f *)type.attributes_float[2].values, type.particle_amount));
}
Mesh *mesh = distribute_tetrahedons(positions, sizes, colors);
@@ -331,10 +331,10 @@ void BParticles_modifier_cache_state(BParticlesModifierData *bpmd,
container.flatten_attribute_data("Size", size_attribute.values);
BParticlesAttributeCacheFloat &color_attribute = cached_type.attributes_float[2];
- color_attribute.floats_per_particle = 3;
+ color_attribute.floats_per_particle = 4;
strncpy(color_attribute.name, "Color", sizeof(color_attribute.name));
color_attribute.values = (float *)MEM_malloc_arrayN(
- cached_type.particle_amount, sizeof(float3), __func__);
+ cached_type.particle_amount, sizeof(rgba_f), __func__);
container.flatten_attribute_data("Color", color_attribute.values);
}
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 972469f6620..dca665621e2 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -51,7 +51,7 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualNodeTree
attributes.add<float3>("Position", {0, 0, 0});
attributes.add<float3>("Velocity", {0, 0, 0});
attributes.add<float>("Size", 0.01f);
- attributes.add<float3>("Color", {1.0f, 1.0f, 1.0f});
+ attributes.add<rgba_f>("Color", {1.0f, 1.0f, 1.0f, 1.0f});
declarations.add_new(particle_type_node->name(), attributes);
particle_type_names.add_new(particle_type_node->name());
}
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index 639733626a2..8ea0d0e363e 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -168,22 +168,6 @@ void ParticlesContainer::flatten_attribute_data(StringRef attribute_name, void *
}
}
-Vector<float> ParticlesContainer::flatten_attribute_float(StringRef attribute_name)
-{
- BLI_assert(m_attributes_info.type_of(attribute_name) == AttributeType::Float);
- Vector<float> result(this->count_active());
- this->flatten_attribute_data(attribute_name, (void *)result.begin());
- return result;
-}
-
-Vector<float3> ParticlesContainer::flatten_attribute_float3(StringRef attribute_name)
-{
- BLI_assert(m_attributes_info.type_of(attribute_name) == AttributeType::Float3);
- Vector<float3> result(this->count_active());
- this->flatten_attribute_data(attribute_name, (void *)result.begin());
- return result;
-}
-
void ParticlesBlock::MoveUntilFull(ParticlesBlock &from, ParticlesBlock &to)
{
BLI_assert(&from.container() == &to.container());
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 04f38544814..aa6f66998bc 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -92,8 +92,7 @@ class ParticlesContainer {
/**
* Get a vector containing an attribute value from every particle.
*/
- Vector<float> flatten_attribute_float(StringRef attribute_name);
- Vector<float3> flatten_attribute_float3(StringRef attribute_name);
+ template<typename T> Vector<T> flatten_attribute(StringRef attribute_name);
friend bool operator==(const ParticlesContainer &a, const ParticlesContainer &b);
@@ -243,6 +242,14 @@ inline bool operator==(const ParticlesContainer &a, const ParticlesContainer &b)
return &a == &b;
}
+template<typename T> Vector<T> ParticlesContainer::flatten_attribute(StringRef attribute_name)
+{
+ BLI_assert(m_attributes_info.type_of(attribute_name) == attribute_type_by_type<T>::value);
+ Vector<T> result(this->count_active());
+ this->flatten_attribute_data(attribute_name, (void *)result.begin());
+ return result;
+}
+
/* Particles Block
***
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list