[Bf-blender-cvs] [03d7ba7055c] functions: Make Particle Info node a normal function
Jacques Lucke
noreply at git.blender.org
Wed Nov 13 14:23:39 CET 2019
Commit: 03d7ba7055c6798d6a122705afc33005f9f32af0
Author: Jacques Lucke
Date: Wed Nov 13 12:40:12 2019 +0100
Branches: functions
https://developer.blender.org/rB03d7ba7055c6798d6a122705afc33005f9f32af0
Make Particle Info node a normal function
===================================================================
M release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
M source/blender/functions/FN_attributes_ref.h
M source/blender/functions/FN_multi_function_common_contexts.h
M source/blender/functions/FN_multi_function_context.h
M source/blender/functions/intern/attributes_ref.cc
M source/blender/functions/intern/multi_functions/mixed.cc
M source/blender/functions/intern/multi_functions/mixed.h
M source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
M source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
M source/blender/modifiers/intern/MOD_functionpoints_cxx.cc
M source/blender/simulations/bparticles/particle_function.cpp
M source/blender/simulations/bparticles/particle_function_builder.cpp
M source/blender/simulations/bparticles/particle_function_input_providers.cpp
M source/blender/simulations/bparticles/particle_function_input_providers.hpp
===================================================================
diff --git a/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py b/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
index 5578c590868..d55dbb9603d 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/particle_inputs.py
@@ -13,7 +13,6 @@ class ParticleInfoNode(bpy.types.Node, SimulationNode):
builder.fixed_output("position", "Position", "Vector")
builder.fixed_output("velocity", "Velocity", "Vector")
builder.fixed_output("birth_time", "Birth Time", "Float")
- builder.fixed_output("age", "Age", "Float")
class SurfaceInfoNode(bpy.types.Node, SimulationNode):
diff --git a/source/blender/functions/FN_attributes_ref.h b/source/blender/functions/FN_attributes_ref.h
index 82870f9f15e..43a950ef6e4 100644
--- a/source/blender/functions/FN_attributes_ref.h
+++ b/source/blender/functions/FN_attributes_ref.h
@@ -116,9 +116,9 @@ class AttributesInfo : BLI::NonCopyable, BLI::NonMovable {
return this->default_of(this->index_of(name));
}
- int index_of_try(StringRef name, const CPPType &type) const
+ int try_index_of(StringRef name, const CPPType &type) const
{
- int index = this->index_of_try(name);
+ int index = this->try_index_of(name);
if (index == -1) {
return -1;
}
@@ -130,12 +130,12 @@ class AttributesInfo : BLI::NonCopyable, BLI::NonMovable {
}
}
- template<typename T> int index_of_try(StringRef name) const
+ template<typename T> int try_index_of(StringRef name) const
{
- return this->index_of_try(name, CPP_TYPE<T>());
+ return this->try_index_of(name, CPP_TYPE<T>());
}
- int index_of_try(StringRef name) const
+ int try_index_of(StringRef name) const
{
return m_index_by_name.lookup_default(name, -1);
}
@@ -183,7 +183,7 @@ class AttributesRef {
return m_range.size();
}
- const AttributesInfo &info()
+ const AttributesInfo &info() const
{
return *m_info;
}
@@ -211,9 +211,20 @@ class AttributesRef {
return this->get<T>(m_info->index_of(name));
}
+ Optional<GenericMutableArrayRef> try_get(StringRef name, const CPPType &type) const
+ {
+ int index = m_info->try_index_of(name, type);
+ if (index == -1) {
+ return {};
+ }
+ else {
+ return this->get((uint)index);
+ }
+ }
+
template<typename T> Optional<MutableArrayRef<T>> try_get(StringRef name)
{
- int index = m_info->index_of_try<T>(name);
+ int index = m_info->try_index_of<T>(name);
if (index == -1) {
return {};
}
diff --git a/source/blender/functions/FN_multi_function_common_contexts.h b/source/blender/functions/FN_multi_function_common_contexts.h
index 7f253295eec..ed66ae64d36 100644
--- a/source/blender/functions/FN_multi_function_common_contexts.h
+++ b/source/blender/functions/FN_multi_function_common_contexts.h
@@ -2,6 +2,7 @@
#define __FN_MULTI_FUNCTION_COMMON_CONTEXTS_H__
#include "FN_multi_function_context.h"
+#include "FN_attributes_ref.h"
#include "BLI_math_cxx.h"
@@ -20,6 +21,15 @@ class SceneTimeContext : public MFElementContext {
float time;
};
+class ParticleAttributesContext : public MFElementContext {
+ public:
+ AttributesRef attributes;
+
+ ParticleAttributesContext(AttributesRef attributes) : attributes(attributes)
+ {
+ }
+};
+
} // namespace FN
#endif /* __FN_MULTI_FUNCTION_COMMON_CONTEXTS_H__ */
diff --git a/source/blender/functions/FN_multi_function_context.h b/source/blender/functions/FN_multi_function_context.h
index dbcfbf8d50d..a7ae9e813f8 100644
--- a/source/blender/functions/FN_multi_function_context.h
+++ b/source/blender/functions/FN_multi_function_context.h
@@ -6,10 +6,12 @@
#include "BLI_virtual_list_ref.h"
#include "BLI_vector.h"
#include "BLI_utility_mixins.h"
+#include "BLI_index_range.h"
namespace FN {
using BLI::ArrayRef;
+using BLI::IndexRange;
using BLI::Optional;
using BLI::Vector;
using BLI::VirtualListRef;
@@ -58,13 +60,19 @@ class MFContextBuilder : BLI::NonCopyable, BLI::NonMovable {
{
}
- void add_element_context(const MFElementContext *context, VirtualListRef<uint> indices)
+ void add_element_context(const MFElementContext &context, VirtualListRef<uint> indices)
{
- m_element_contexts.m_contexts.append(context);
+ m_element_contexts.m_contexts.append(&context);
m_element_contexts.m_indices.append(indices);
}
- void add_element_context(const MFElementContext *context)
+ void add_element_context(const MFElementContext &context, IndexRange indices)
+ {
+ this->add_element_context(context,
+ VirtualListRef<uint>::FromFullArray(indices.as_array_ref()));
+ }
+
+ void add_element_context(const MFElementContext &context)
{
static uint dummy_index = 0;
this->add_element_context(context, VirtualListRef<uint>::FromSingle_MaxSize(&dummy_index));
diff --git a/source/blender/functions/intern/attributes_ref.cc b/source/blender/functions/intern/attributes_ref.cc
index 7460b9730c9..13c1df1f2f6 100644
--- a/source/blender/functions/intern/attributes_ref.cc
+++ b/source/blender/functions/intern/attributes_ref.cc
@@ -110,7 +110,7 @@ static Array<int> map_attribute_indices(const AttributesInfo &from_info,
StringRef name = from_info.name_of(from_index);
const CPPType &type = from_info.type_of(from_index);
- int to_index = to_info.index_of_try(name, type);
+ int to_index = to_info.try_index_of(name, type);
mapping[from_index] = to_index;
}
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index 5ac88cdbdc1..a6b27bb7253 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -566,4 +566,36 @@ void MF_PerlinNoise_3D_to_3D::call(MFMask mask, MFParams params, MFContext UNUSE
}
}
+MF_ParticleAttribute::MF_ParticleAttribute(StringRef attribute_name, const CPPType &attribute_type)
+ : m_attribute_name(attribute_name), m_attribute_type(attribute_type)
+{
+ MFSignatureBuilder signature("Particle Attribute");
+ signature.single_output(attribute_name, attribute_type);
+ this->set_signature(signature);
+}
+
+void MF_ParticleAttribute::call(MFMask mask, MFParams params, MFContext context) const
+{
+ auto context_data = context.element_contexts().find_first<ParticleAttributesContext>();
+ GenericMutableArrayRef r_output = params.uninitialized_single_output(0, m_attribute_name);
+
+ if (context_data.has_value()) {
+ AttributesRef attributes = context_data.value().data->attributes;
+ Optional<GenericMutableArrayRef> opt_array = attributes.try_get(m_attribute_name,
+ m_attribute_type);
+ if (opt_array.has_value()) {
+ GenericMutableArrayRef array = opt_array.value();
+ for (uint i : mask.indices()) {
+ m_attribute_type.copy_to_uninitialized(array[i], r_output[i]);
+ }
+ return;
+ }
+ }
+
+ /* Fallback */
+ for (uint i : mask.indices()) {
+ m_attribute_type.construct_default(r_output[i]);
+ }
+}
+
} // namespace FN
diff --git a/source/blender/functions/intern/multi_functions/mixed.h b/source/blender/functions/intern/multi_functions/mixed.h
index 37c110e8c4d..48ac412edbd 100644
--- a/source/blender/functions/intern/multi_functions/mixed.h
+++ b/source/blender/functions/intern/multi_functions/mixed.h
@@ -177,6 +177,16 @@ class MF_PerlinNoise_3D_to_3D final : public MultiFunction {
void call(MFMask mask, MFParams params, MFContext context) const override;
};
+class MF_ParticleAttribute final : public MultiFunction {
+ private:
+ std::string m_attribute_name;
+ const CPPType &m_attribute_type;
+
+ public:
+ MF_ParticleAttribute(StringRef attribute_name, const CPPType &attribute_type);
+ void call(MFMask mask, MFParams params, MFContext context) const override;
+};
+
template<typename FromT, typename ToT, ToT (*Compute)(const FromT &)>
class MF_Mappping final : public MultiFunction {
public:
diff --git a/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc b/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
index f70363f6b0e..69552967358 100644
--- a/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
+++ b/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
@@ -462,6 +462,33 @@ static void INSERT_perlin_noise(VTreeMFNetworkBuilder &builder, const VNode &vno
}
}
+static void INSERT_particle_info(VTreeMFNetworkBuilder &builder, const VNode &vnode)
+{
+ {
+ const MultiFunction &fn = builder.construct_fn<MF_ParticleAttribute>("ID", CPP_TYPE<int>());
+ MFBuilderFunctionNode &node = builder.add_function(fn, {}, {0});
+ builder.map_sockets(vnode.output(0), node.output(0));
+ }
+ {
+ const MultiFunction &fn = builder.construct_fn<MF_ParticleAttribute>("Position",
+ CPP_TYPE<float3>());
+ MFBuilderFunctionNode &node = builder.add_function(fn, {}, {0});
+ builder.map_sockets(vnode.output(1), node.output(0));
+ }
+ {
+ const MultiFunction &fn = builder.construct_fn<MF_ParticleAttribute>("Velocity",
+ CPP_TYPE<float3>());
+ MFBuilderFunctionNode &node = builder.add_function(fn, {}, {0});
+ builder.map_sockets(vnode.output(2), node.output(0));
+ }
+ {
+ const MultiFunction &fn = builder.construct_fn<MF_ParticleAttribute>("Birth Time",
+ CPP_TYPE<float>());
+ MFBuilderFunctionNode &node = builder.add_function(fn, {}, {0});
+ builder.map_sockets(vnode.output(3), node.output(0));
+ }
+}
+
void add_vtree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
{
mappings.vnode_inserters.add_new("fn_CombineColorNode", INSERT_combine_color);
@@ -480,6 +507,7 @@ void add_vtree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
mappings.vnode_inserters.add_new("fn_TimeInfoNode", INSERT_time_info);
m
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list