[Bf-blender-cvs] [bc2230df715] geometry-nodes: Geometry Nodes: cleanup geometry node interface
Jacques Lucke
noreply at git.blender.org
Thu Nov 12 16:31:39 CET 2020
Commit: bc2230df715e222e344e7d0b07b9adcd41fc1d2c
Author: Jacques Lucke
Date: Thu Nov 12 16:31:32 2020 +0100
Branches: geometry-nodes
https://developer.blender.org/rBbc2230df715e222e344e7d0b07b9adcd41fc1d2c
Geometry Nodes: cleanup geometry node interface
Previously, the execution function of a geometry node has three parameters.
Now it has only one. This makes it easier to pass more information to the
execution function, that might only be used by a few nodes, because we
don't have to add more parameters that are unused in most cases.
===================================================================
M source/blender/blenkernel/BKE_node.h
M source/blender/modifiers/intern/MOD_nodes.cc
M source/blender/nodes/NOD_geometry_exec.hh
M source/blender/nodes/geometry/nodes/node_geo_boolean.cc
M source/blender/nodes/geometry/nodes/node_geo_edge_split.cc
M source/blender/nodes/geometry/nodes/node_geo_object_info.cc
M source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
M source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
M source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
M source/blender/nodes/geometry/nodes/node_geo_transform.cc
M source/blender/nodes/geometry/nodes/node_geo_triangulate.cc
M source/blender/nodes/intern/node_geometry_exec.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 07833b93f43..5c2346f2c94 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -112,8 +112,7 @@ namespace blender {
namespace nodes {
class SocketMFNetworkBuilder;
class NodeMFNetworkBuilder;
-class GeoNodeInputs;
-class GeoNodeOutputs;
+class GeoNodeExecParams;
} // namespace nodes
namespace fn {
class CPPType;
@@ -122,9 +121,7 @@ class MFDataType;
} // namespace blender
using NodeExpandInMFNetworkFunction = void (*)(blender::nodes::NodeMFNetworkBuilder &builder);
-using NodeGeometryExecFunction = void (*)(struct bNode *node,
- blender::nodes::GeoNodeInputs inputs,
- blender::nodes::GeoNodeOutputs outputs);
+using NodeGeometryExecFunction = void (*)(blender::nodes::GeoNodeExecParams params);
using SocketGetCPPTypeFunction = const blender::fn::CPPType *(*)();
using SocketGetCPPValueFunction = void (*)(const struct bNodeSocket &socket, void *r_value);
using SocketExpandInMFNetworkFunction = void (*)(blender::nodes::SocketMFNetworkBuilder &builder);
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 1791ab1fcc6..a2cfebddcc5 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -251,9 +251,8 @@ class GeometryNodesEvaluator {
/* Execute the node. */
GValueMap<StringRef> node_outputs_map{allocator_};
- GeoNodeInputs node_inputs{bnode, node_inputs_map, handle_map_};
- GeoNodeOutputs node_outputs{bnode, node_outputs_map};
- this->execute_node(node, node_inputs, node_outputs);
+ GeoNodeExecParams params{bnode, node_inputs_map, node_outputs_map, handle_map_};
+ this->execute_node(node, params);
/* Forward computed outputs to linked input sockets. */
for (const DOutputSocket *output_socket : node.outputs()) {
@@ -264,23 +263,23 @@ class GeometryNodesEvaluator {
}
}
- void execute_node(const DNode &node, GeoNodeInputs node_inputs, GeoNodeOutputs node_outputs)
+ void execute_node(const DNode &node, GeoNodeExecParams params)
{
- bNode *bnode = node.bnode();
- if (bnode->typeinfo->geometry_node_execute != nullptr) {
- bnode->typeinfo->geometry_node_execute(bnode, node_inputs, node_outputs);
+ const bNode &bnode = params.node();
+ if (bnode.typeinfo->geometry_node_execute != nullptr) {
+ bnode.typeinfo->geometry_node_execute(params);
return;
}
/* Use the multi-function implementation of the node. */
const MultiFunction &fn = *mf_by_node_.lookup(&node);
- MFContextBuilder context;
- MFParamsBuilder params{fn, 1};
+ MFContextBuilder fn_context;
+ MFParamsBuilder fn_params{fn, 1};
Vector<GMutablePointer> input_data;
for (const DInputSocket *dsocket : node.inputs()) {
if (dsocket->is_available()) {
- GMutablePointer data = node_inputs.extract(dsocket->identifier());
- params.add_readonly_single_input(GSpan(*data.type(), data.get(), 1));
+ GMutablePointer data = params.extract_input(dsocket->identifier());
+ fn_params.add_readonly_single_input(GSpan(*data.type(), data.get(), 1));
input_data.append(data);
}
}
@@ -289,18 +288,18 @@ class GeometryNodesEvaluator {
if (dsocket->is_available()) {
const CPPType &type = *socket_cpp_type_get(*dsocket->typeinfo());
void *buffer = allocator_.allocate(type.size(), type.alignment());
- params.add_uninitialized_single_output(GMutableSpan(type, buffer, 1));
+ fn_params.add_uninitialized_single_output(GMutableSpan(type, buffer, 1));
output_data.append(GMutablePointer(type, buffer));
}
}
- fn.call(IndexRange(1), params, context);
+ fn.call(IndexRange(1), fn_params, fn_context);
for (GMutablePointer value : input_data) {
value.destruct();
}
for (const int i : node.outputs().index_range()) {
if (node.output(i).is_available()) {
GMutablePointer value = output_data[i];
- node_outputs.set_by_move(node.output(i).identifier(), value);
+ params.set_output_by_move(node.output(i).identifier(), value);
value.destruct();
}
}
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index db28cdbd844..937a5a33ec8 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -38,37 +38,37 @@ using fn::CPPType;
using fn::GMutablePointer;
using fn::GValueMap;
-class GeoNodeInputs {
+class GeoNodeExecParams {
private:
- const bNode *node_;
- GValueMap<StringRef> &values_;
+ const bNode &node_;
+ GValueMap<StringRef> &input_values_;
+ GValueMap<StringRef> &output_values_;
const PersistentDataHandleMap &handle_map_;
public:
- GeoNodeInputs(const bNode &node,
- GValueMap<StringRef> &values,
- const PersistentDataHandleMap &handle_map)
- : node_(&node), values_(values), handle_map_(handle_map)
+ GeoNodeExecParams(const bNode &node,
+ GValueMap<StringRef> &input_values,
+ GValueMap<StringRef> &output_values,
+ const PersistentDataHandleMap &handle_map)
+ : node_(node),
+ input_values_(input_values),
+ output_values_(output_values),
+ handle_map_(handle_map)
{
}
- const PersistentDataHandleMap &handle_map() const
- {
- return handle_map_;
- }
-
/**
* Get the input value for the input socket with the given identifier.
*
* The node calling becomes responsible for destructing the value before it is done
* executing. This method can only be called once for each identifier.
*/
- GMutablePointer extract(StringRef identifier)
+ GMutablePointer extract_input(StringRef identifier)
{
#ifdef DEBUG
- this->check_extract(identifier);
+ this->check_extract_input(identifier);
#endif
- return values_.extract(identifier);
+ return input_values_.extract(identifier);
}
/**
@@ -76,55 +76,55 @@ class GeoNodeInputs {
*
* This method can only be called once for each identifier.
*/
- template<typename T> T extract(StringRef identifier)
+ template<typename T> T extract_input(StringRef identifier)
{
#ifdef DEBUG
- this->check_extract(identifier, &CPPType::get<T>());
+ this->check_extract_input(identifier, &CPPType::get<T>());
#endif
- return values_.extract<T>(identifier);
- }
-
- private:
- void check_extract(StringRef identifier, const CPPType *requested_type = nullptr);
-};
-
-class GeoNodeOutputs {
- private:
- const bNode *node_;
- GValueMap<StringRef> &values_;
-
- public:
- GeoNodeOutputs(const bNode &node, GValueMap<StringRef> &values) : node_(&node), values_(values)
- {
+ return input_values_.extract<T>(identifier);
}
/**
* Move-construct a new value based on the given value and store it for the given socket
* identifier.
*/
- void set_by_move(StringRef identifier, GMutablePointer value)
+ void set_output_by_move(StringRef identifier, GMutablePointer value)
{
#ifdef DEBUG
BLI_assert(value.type() != nullptr);
BLI_assert(value.get() != nullptr);
- this->check_set(identifier, *value.type());
+ this->check_set_output(identifier, *value.type());
#endif
- values_.add_new_by_move(identifier, value);
+ output_values_.add_new_by_move(identifier, value);
}
/**
* Store the output value for the given socket identifier.
*/
- template<typename T> void set(StringRef identifier, T &&value)
+ template<typename T> void set_output(StringRef identifier, T &&value)
{
#ifdef DEBUG
- this->check_set(identifier, CPPType::get<std::decay_t<T>>());
+ this->check_set_output(identifier, CPPType::get<std::decay_t<T>>());
#endif
- values_.add_new(identifier, std::forward<T>(value));
+ output_values_.add_new(identifier, std::forward<T>(value));
+ }
+
+ /**
+ * Get the node that is currently being executed.
+ */
+ const bNode &node() const
+ {
+ return node_;
+ }
+
+ const PersistentDataHandleMap &handle_map() const
+ {
+ return handle_map_;
}
private:
- void check_set(StringRef identifier, const CPPType &value_type);
+ void check_extract_input(StringRef identifier, const CPPType *requested_type = nullptr);
+ void check_set_output(StringRef identifier, const CPPType &value_type);
};
} // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
index f68c88b187d..136e70b3822 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
@@ -103,35 +103,35 @@ static Mesh *mesh_boolean_calc(const Mesh *mesh_a, const Mesh *mesh_b, int boole
}
namespace blender::nodes {
-static void geo_boolean_exec(bNode *node, GeoNodeInputs inputs, GeoNodeOutputs outputs)
+static void geo_boolean_exec(GeoNodeExecParams params)
{
- GeometrySetPtr geometry_set_in_a = inputs.extract<GeometrySetPtr>("Geometry A");
- GeometrySetPtr geometry_set_in_b = inputs.extract<GeometrySetPtr>("Geometry B");
+ GeometrySetPtr geometry_set_in_a = params.extract_input<GeometrySetPtr>("Geometry A");
+ GeometrySetPtr geometry_set_in_b = params.extract_input<GeometrySetPtr>("Geometry B");
GeometrySetPtr geometry_set_out;
if (!geometry_set_in_a.has_value() || !geometry_set_in_b.has_value()) {
- outputs.set("Geometry", std::move(geometry_set_out));
+ params.set_output("Geometry", std::move(geometry_set_out));
return;
}
const Mesh *mesh_in_a = geometry_set_in_a->get_mesh_for_read();
const Mesh *mesh_in_b = geometry_set_in_b->get_mesh_for_read();
if (mesh_in_a == nullptr || mesh_in_b == nullptr) {
- outputs.set("Geometry", std::move(geometry_set_out));
+ params.set_output("Geometry", std::move(geometry_set_out));
return;
}
- GeometryNodeBooleanOperation operation = (GeometryNodeBooleanOperation)node->custom1;
+ GeometryNodeBooleanOperation op
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list