Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-07-21 18:20:05 +0300
committerJacques Lucke <jacques@blender.org>2020-07-21 18:35:09 +0300
commit8369adabc0ec7a1fce248b688bf20860ae0434bb (patch)
treeaf767efe8c6765c5876391a5eb96923fc8d6ac68 /source/blender/nodes/intern/node_socket.cc
parent6c7e62ef9be564fbee279c7467c9b6adaf51b6c8 (diff)
Particles: initial object socket and emitter node support
Object sockets work now, but only the new Object Transforms and the Particle Mesh Emitter node use it. The emitter does not actually use the mesh surface yet. Instead, new particles are just emitted around the origin of the object. Internally, handles to object data blocks are passed around in the network, instead of raw object pointers. Using handles has a couple of benefits: * The caller of the function has control over which handles can be resolved and therefore limit access to specific data. The set of data blocks that is accessed by a node tree should be known statically. This is necessary for a proper integration with the dependency graph. * When the pointer to an object changes (e.g. after restarting Blender), all handles are still valid. * When an object is deleted, the handle is invalidated without causing crashes. * The handle is just an integer that can be stored per particle and can be cached easily. The mapping between handles and their corresponding data blocks is stored in the Simulation data block.
Diffstat (limited to 'source/blender/nodes/intern/node_socket.cc')
-rw-r--r--source/blender/nodes/intern/node_socket.cc56
1 files changed, 55 insertions, 1 deletions
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index 3a82438a211..49868505d68 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -34,6 +34,7 @@
#include "BKE_lib_id.h"
#include "BKE_node.h"
+#include "BKE_persistent_data_handle.hh"
#include "RNA_access.h"
#include "RNA_types.h"
@@ -583,6 +584,59 @@ static bNodeSocketType *make_socket_type_string()
return socktype;
}
+class ObjectSocketMultiFunction : public blender::fn::MultiFunction {
+ private:
+ const Object *object_;
+
+ public:
+ ObjectSocketMultiFunction(const Object *object) : object_(object)
+ {
+ blender::fn::MFSignatureBuilder signature = this->get_builder("Object Socket");
+ signature.depends_on_context();
+ signature.single_output<blender::bke::PersistentObjectHandle>("Object");
+ }
+
+ void call(blender::IndexMask mask,
+ blender::fn::MFParams params,
+ blender::fn::MFContext context) const override
+ {
+ blender::MutableSpan output =
+ params.uninitialized_single_output<blender::bke::PersistentObjectHandle>(0, "Object");
+
+ /* Try to get a handle map, so that the object can be converted to a handle. */
+ const blender::bke::PersistentDataHandleMap *handle_map =
+ context.get_global_context<blender::bke::PersistentDataHandleMap>(
+ "PersistentDataHandleMap");
+
+ if (handle_map == nullptr) {
+ /* Return empty handles when there is no handle map. */
+ output.fill_indices(mask, blender::bke::PersistentObjectHandle());
+ return;
+ }
+
+ blender::bke::PersistentObjectHandle handle = handle_map->lookup(object_);
+ for (int64_t i : mask) {
+ output[i] = handle;
+ }
+ }
+};
+
+MAKE_CPP_TYPE(PersistentObjectHandle, blender::bke::PersistentObjectHandle);
+
+static bNodeSocketType *make_socket_type_object()
+{
+ bNodeSocketType *socktype = make_standard_socket_type(SOCK_OBJECT, PROP_NONE);
+ socktype->get_mf_data_type = []() {
+ /* Objects are not passed along as raw pointers, but as handles. */
+ return blender::fn::MFDataType::ForSingle<blender::bke::PersistentObjectHandle>();
+ };
+ socktype->expand_in_mf_network = [](blender::nodes::SocketMFNetworkBuilder &builder) {
+ const Object *object = builder.socket_default_value<bNodeSocketValueObject>()->value;
+ builder.construct_generator_fn<ObjectSocketMultiFunction>(object);
+ };
+ return socktype;
+}
+
void register_standard_node_socket_types(void)
{
/* draw callbacks are set in drawnode.c to avoid bad-level calls */
@@ -615,7 +669,7 @@ void register_standard_node_socket_types(void)
nodeRegisterSocketType(make_standard_socket_type(SOCK_SHADER, PROP_NONE));
- nodeRegisterSocketType(make_standard_socket_type(SOCK_OBJECT, PROP_NONE));
+ nodeRegisterSocketType(make_socket_type_object());
nodeRegisterSocketType(make_standard_socket_type(SOCK_IMAGE, PROP_NONE));