From 8369adabc0ec7a1fce248b688bf20860ae0434bb Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 21 Jul 2020 17:20:05 +0200 Subject: 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. --- .../intern/multi_function_network_evaluation.cc | 2 +- .../intern/multi_function_network_optimization.cc | 30 +++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'source/blender/functions/intern') diff --git a/source/blender/functions/intern/multi_function_network_evaluation.cc b/source/blender/functions/intern/multi_function_network_evaluation.cc index a7e1a2f42af..58577e31c42 100644 --- a/source/blender/functions/intern/multi_function_network_evaluation.cc +++ b/source/blender/functions/intern/multi_function_network_evaluation.cc @@ -230,7 +230,7 @@ BLI_NOINLINE void MFNetworkEvaluator::evaluate_network_to_compute_outputs( } BLI_assert(node.is_function()); - BLI_assert(node.all_inputs_have_origin()); + BLI_assert(!node.has_unlinked_inputs()); const MFFunctionNode &function_node = node.as_function(); bool all_origins_are_computed = true; diff --git a/source/blender/functions/intern/multi_function_network_optimization.cc b/source/blender/functions/intern/multi_function_network_optimization.cc index e76b2f51a15..f1e047f01a1 100644 --- a/source/blender/functions/intern/multi_function_network_optimization.cc +++ b/source/blender/functions/intern/multi_function_network_optimization.cc @@ -142,13 +142,24 @@ void dead_node_removal(MFNetwork &network) * * \{ */ +static bool function_node_can_be_constant(MFFunctionNode *node) +{ + if (node->has_unlinked_inputs()) { + return false; + } + if (node->function().depends_on_context()) { + return false; + } + return true; +} + static Vector find_non_constant_nodes(MFNetwork &network) { Vector non_constant_nodes; non_constant_nodes.extend(network.dummy_nodes()); for (MFFunctionNode *node : network.function_nodes()) { - if (!node->all_inputs_have_origin()) { + if (!function_node_can_be_constant(node)) { non_constant_nodes.append(node); } } @@ -319,17 +330,18 @@ void constant_folding(MFNetwork &network, ResourceCollector &resources) static uint64_t compute_node_hash(MFFunctionNode &node, RNG *rng, Span node_hashes) { + if (node.function().depends_on_context()) { + return BLI_rng_get_uint(rng); + } + if (node.has_unlinked_inputs()) { + return BLI_rng_get_uint(rng); + } + uint64_t combined_inputs_hash = 394659347u; for (MFInputSocket *input_socket : node.inputs()) { MFOutputSocket *origin_socket = input_socket->origin(); - uint64_t input_hash; - if (origin_socket == nullptr) { - input_hash = BLI_rng_get_uint(rng); - } - else { - input_hash = BLI_ghashutil_combine_hash(node_hashes[origin_socket->node().id()], - origin_socket->index()); - } + uint64_t input_hash = BLI_ghashutil_combine_hash(node_hashes[origin_socket->node().id()], + origin_socket->index()); combined_inputs_hash = BLI_ghashutil_combine_hash(combined_inputs_hash, input_hash); } -- cgit v1.2.3