[Bf-blender-cvs] [badad91ac31] functions-experimental-refactor: make Object socket work again
Jacques Lucke
noreply at git.blender.org
Thu Oct 31 15:02:00 CET 2019
Commit: badad91ac310e120d0c31557de5fb1474882c626
Author: Jacques Lucke
Date: Thu Oct 31 14:39:16 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rBbadad91ac310e120d0c31557de5fb1474882c626
make Object socket work again
===================================================================
M source/blender/blenkernel/BKE_multi_functions.h
M source/blender/blenkernel/intern/multi_functions.cc
M source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_multi_functions.h b/source/blender/blenkernel/BKE_multi_functions.h
index 9776dc56768..4178e833f68 100644
--- a/source/blender/blenkernel/BKE_multi_functions.h
+++ b/source/blender/blenkernel/BKE_multi_functions.h
@@ -47,6 +47,12 @@ class MultiFunction_FloatRange final : public MultiFunction {
void call(ArrayRef<uint> mask_indices, MFParams ¶ms, MFContext &context) const override;
};
+class MultiFunction_ObjectWorldLocation final : public MultiFunction {
+ public:
+ MultiFunction_ObjectWorldLocation();
+ void call(ArrayRef<uint> mask_indices, MFParams ¶ms, MFContext &context) const override;
+};
+
class MultiFunction_GetListElement final : public MultiFunction {
private:
const CPPType &m_base_type;
diff --git a/source/blender/blenkernel/intern/multi_functions.cc b/source/blender/blenkernel/intern/multi_functions.cc
index 76dc6371057..498696dcae3 100644
--- a/source/blender/blenkernel/intern/multi_functions.cc
+++ b/source/blender/blenkernel/intern/multi_functions.cc
@@ -6,6 +6,8 @@
#include "BLI_lazy_init_cxx.h"
#include "BLI_string_map.h"
+#include "DNA_object_types.h"
+
namespace BKE {
using BLI::float3;
@@ -179,6 +181,31 @@ void MultiFunction_FloatRange::call(ArrayRef<uint> mask_indices,
}
}
+MultiFunction_ObjectWorldLocation::MultiFunction_ObjectWorldLocation()
+{
+ MFSignatureBuilder signature("Object Location");
+ signature.readonly_single_input<Object *>("Object");
+ signature.single_output<float3>("Location");
+ this->set_signature(signature);
+}
+
+void MultiFunction_ObjectWorldLocation::call(ArrayRef<uint> mask_indices,
+ MFParams ¶ms,
+ MFContext &UNUSED(context)) const
+{
+ auto objects = params.readonly_single_input<Object *>(0, "Object");
+ auto locations = params.single_output<float3>(1, "Location");
+
+ for (uint i : mask_indices) {
+ if (objects[i] != nullptr) {
+ locations[i] = objects[i]->obmat[3];
+ }
+ else {
+ locations[i] = float3(0, 0, 0);
+ }
+ }
+}
+
MultiFunction_PackList::MultiFunction_PackList(const CPPType &base_type,
ArrayRef<bool> input_list_status)
: m_base_type(base_type), m_input_list_status(input_list_status)
diff --git a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
index 427ca00880d..1c0ea3983b5 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
+++ b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
@@ -77,6 +77,9 @@ static MFDataType get_type_by_socket(const VirtualSocket &vsocket)
else if (idname == "fn_BooleanSocket") {
return MFDataType::ForSingle<bool>();
}
+ else if (idname == "fn_ObjectSocket") {
+ return MFDataType::ForSingle<Object *>();
+ }
else if (idname == "fn_FloatListSocket") {
return MFDataType::ForVector<float>();
}
@@ -89,6 +92,10 @@ static MFDataType get_type_by_socket(const VirtualSocket &vsocket)
else if (idname == "fn_BooleanListSocket") {
return MFDataType::ForVector<bool>();
}
+ else if (idname == "fn_ObjectListSocket") {
+ return MFDataType::ForVector<Object *>();
+ }
+
return MFDataType();
}
@@ -106,6 +113,9 @@ static const CPPType &get_cpp_type_by_name(StringRef name)
else if (name == "Boolean") {
return BKE::GET_TYPE<bool>();
}
+ else if (name == "Object") {
+ return BKE::GET_TYPE<Object *>();
+ }
BLI_assert(false);
return BKE::GET_TYPE<float>();
@@ -531,6 +541,15 @@ static void INSERT_pack_list(VTreeMFNetworkBuilder &builder,
builder.map_sockets(vnode.output(0), packed_list_socket);
}
+static void INSERT_object_location(VTreeMFNetworkBuilder &builder,
+ OwnedResources &resources,
+ const VirtualNode &vnode)
+{
+ const MultiFunction &fn = allocate_resource<BKE::MultiFunction_ObjectWorldLocation>(
+ "object location function", resources);
+ builder.add_function(fn, {0}, {1}, vnode);
+}
+
static StringMap<InsertVNodeFunction> get_node_inserters()
{
StringMap<InsertVNodeFunction> inserters;
@@ -541,6 +560,7 @@ static StringMap<InsertVNodeFunction> get_node_inserters()
inserters.add_new("fn_ListLengthNode", INSERT_list_length);
inserters.add_new("fn_PackListNode", INSERT_pack_list);
inserters.add_new("fn_GetListElementNode", INSERT_get_list_element);
+ inserters.add_new("fn_ObjectTransformsNode", INSERT_object_location);
return inserters;
}
@@ -584,6 +604,19 @@ static MFBuilderOutputSocket &INSERT_int_socket(VTreeMFNetworkBuilder &builder,
return *node.outputs()[0];
}
+static MFBuilderOutputSocket &INSERT_object_socket(VTreeMFNetworkBuilder &builder,
+ OwnedResources &resources,
+ const VirtualSocket &vsocket)
+{
+ PointerRNA rna = vsocket.rna();
+ Object *value = (Object *)RNA_pointer_get(&rna, "value").data;
+
+ const MultiFunction &fn = allocate_resource<BKE::MultiFunction_ConstantValue<Object *>>(
+ "object socket", resources, value);
+ MFBuilderFunctionNode &node = builder.add_function(fn, {}, {0});
+ return *node.outputs()[0];
+}
+
template<typename T>
static MFBuilderOutputSocket &INSERT_empty_list_socket(VTreeMFNetworkBuilder &builder,
OwnedResources &resources,
@@ -601,9 +634,11 @@ static StringMap<InsertUnlinkedInputFunction> get_unlinked_input_inserter()
inserters.add_new("fn_VectorSocket", INSERT_vector_socket);
inserters.add_new("fn_FloatSocket", INSERT_float_socket);
inserters.add_new("fn_IntegerSocket", INSERT_int_socket);
+ inserters.add_new("fn_ObjectSocket", INSERT_object_socket);
inserters.add_new("fn_VectorListSocket", INSERT_empty_list_socket<float3>);
inserters.add_new("fn_FloatListSocket", INSERT_empty_list_socket<float>);
inserters.add_new("fn_IntegerListSocket", INSERT_empty_list_socket<int32_t>);
+ inserters.add_new("fn_ObjectListSocket", INSERT_empty_list_socket<Object *>);
return inserters;
}
More information about the Bf-blender-cvs
mailing list