[Bf-blender-cvs] [cbb91b06b13] temp-geometry-nodes-mix-attributes: move getting input attributes to GeoNodeExecParams
Jacques Lucke
noreply at git.blender.org
Wed Dec 9 15:03:31 CET 2020
Commit: cbb91b06b137ed2cd0eb9ab71c9362d564ce874d
Author: Jacques Lucke
Date: Wed Dec 9 15:02:24 2020 +0100
Branches: temp-geometry-nodes-mix-attributes
https://developer.blender.org/rBcbb91b06b137ed2cd0eb9ab71c9362d564ce874d
move getting input attributes to GeoNodeExecParams
===================================================================
M source/blender/nodes/NOD_geometry_exec.hh
M source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
M source/blender/nodes/intern/node_geometry_exec.cc
===================================================================
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index fde576d7429..40db2c391e7 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -148,6 +148,22 @@ class GeoNodeExecParams {
return self_object_;
}
+ ReadAttributePtr get_input_attribute(const StringRef name,
+ const GeometryComponent &component,
+ const AttributeDomain domain,
+ const CustomDataType type,
+ const void *default_value) const;
+
+ template<typename T>
+ bke::TypedReadAttribute<T> get_input_attribute(const StringRef name,
+ const GeometryComponent &component,
+ const AttributeDomain domain,
+ const T &default_value) const
+ {
+ const CustomDataType type = bke::cpp_type_to_custom_data_type(CPPType::get<T>());
+ return this->get_input_attribute(name, component, domain, type, &default_value);
+ }
+
private:
/* Utilities for detecting common errors at when using this class. */
void check_extract_input(StringRef identifier, const CPPType *requested_type = nullptr) const;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
index bc45b286ebb..1f1f3298e71 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
@@ -90,48 +90,6 @@ static void do_mix_operation_color4f(const int blend_mode,
}
}
-static ReadAttributePtr get_input_attribute(const GeometryComponent &component,
- const GeoNodeExecParams ¶ms,
- const AttributeDomain result_domain,
- const CustomDataType result_type,
- const StringRef name,
- const void *default_value)
-{
- const bNode &node = params.node();
- const bNodeSocket *found_socket = nullptr;
- LISTBASE_FOREACH (const bNodeSocket *, socket, &node.inputs) {
- if ((socket->flag & SOCK_UNAVAIL) != 0) {
- continue;
- }
- if (name == socket->name) {
- found_socket = socket;
- break;
- }
- }
-
- if (found_socket->type == SOCK_STRING) {
- const std::string name = params.get_input<std::string>(found_socket->identifier);
- return component.attribute_get_for_read(name, result_domain, result_type, default_value);
- }
- if (found_socket->type == SOCK_FLOAT) {
- const float value = params.get_input<float>(found_socket->identifier);
- return component.attribute_get_constant_for_read_converted(
- result_domain, CD_PROP_FLOAT, result_type, &value);
- }
- if (found_socket->type == SOCK_VECTOR) {
- const float3 value = params.get_input<float3>(found_socket->identifier);
- return component.attribute_get_constant_for_read_converted(
- result_domain, CD_PROP_FLOAT3, result_type, &value);
- }
- if (found_socket->type == SOCK_RGBA) {
- const Color4f value = params.get_input<Color4f>(found_socket->identifier);
- return component.attribute_get_constant_for_read_converted(
- result_domain, CD_PROP_COLOR, result_type, &value);
- }
- BLI_assert(false);
- return component.attribute_get_constant_for_read(result_domain, result_type, default_value);
-}
-
static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms)
{
const bNode &node = params.node();
@@ -154,13 +112,12 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
return;
}
- const float default_factor = 0.5f;
- FloatReadAttribute attribute_factor = get_input_attribute(
- component, params, result_domain, CD_PROP_FLOAT, "Factor", &default_factor);
- ReadAttributePtr attribute_a = get_input_attribute(
- component, params, result_domain, result_type, "A", nullptr);
- ReadAttributePtr attribute_b = get_input_attribute(
- component, params, result_domain, result_type, "B", nullptr);
+ FloatReadAttribute attribute_factor = params.get_input_attribute<float>(
+ "Factor", component, result_domain, 0.5f);
+ ReadAttributePtr attribute_a = params.get_input_attribute(
+ "A", component, result_domain, result_type, nullptr);
+ ReadAttributePtr attribute_b = params.get_input_attribute(
+ "B", component, result_domain, result_type, nullptr);
if (result_type == CD_PROP_FLOAT) {
FloatReadAttribute attribute_a_float = std::move(attribute_a);
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index 50292cb8cfb..b4077235e78 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -19,6 +19,46 @@
namespace blender::nodes {
+ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name,
+ const GeometryComponent &component,
+ const AttributeDomain domain,
+ const CustomDataType type,
+ const void *default_value) const
+{
+ const bNodeSocket *found_socket = nullptr;
+ LISTBASE_FOREACH (const bNodeSocket *, socket, &node_.inputs) {
+ if ((socket->flag & SOCK_UNAVAIL) != 0) {
+ continue;
+ }
+ if (name == socket->name) {
+ found_socket = socket;
+ break;
+ }
+ }
+
+ if (found_socket->type == SOCK_STRING) {
+ const std::string name = this->get_input<std::string>(found_socket->identifier);
+ return component.attribute_get_for_read(name, domain, type, default_value);
+ }
+ if (found_socket->type == SOCK_FLOAT) {
+ const float value = this->get_input<float>(found_socket->identifier);
+ return component.attribute_get_constant_for_read_converted(
+ domain, CD_PROP_FLOAT, type, &value);
+ }
+ if (found_socket->type == SOCK_VECTOR) {
+ const float3 value = this->get_input<float3>(found_socket->identifier);
+ return component.attribute_get_constant_for_read_converted(
+ domain, CD_PROP_FLOAT3, type, &value);
+ }
+ if (found_socket->type == SOCK_RGBA) {
+ const Color4f value = this->get_input<Color4f>(found_socket->identifier);
+ return component.attribute_get_constant_for_read_converted(
+ domain, CD_PROP_COLOR, type, &value);
+ }
+ BLI_assert(false);
+ return component.attribute_get_constant_for_read(domain, type, default_value);
+}
+
void GeoNodeExecParams::check_extract_input(StringRef identifier,
const CPPType *requested_type) const
{
More information about the Bf-blender-cvs
mailing list