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>2021-10-26 21:00:03 +0300
committerJacques Lucke <jacques@blender.org>2021-10-26 21:00:10 +0300
commit0bfae1b12078ef278a56c6e932c13be5bc9781aa (patch)
tree38122afad7575db55b0aafa3958af8022fe3cdde /source/blender/nodes/intern
parentbe3e09ecec5372f87b3e9779adb821867b062be1 (diff)
Geometry Nodes: geometry component type warning system
Previously, every node had to create warnings for unsupported input geometry manually. Now this is automated. Nodes just have to specify the geometry types they support in the node declaration. Differential Revision: https://developer.blender.org/D12899
Diffstat (limited to 'source/blender/nodes/intern')
-rw-r--r--source/blender/nodes/intern/extern_implementations.cc1
-rw-r--r--source/blender/nodes/intern/node_geometry_exec.cc65
-rw-r--r--source/blender/nodes/intern/node_socket_declarations.cc41
3 files changed, 107 insertions, 0 deletions
diff --git a/source/blender/nodes/intern/extern_implementations.cc b/source/blender/nodes/intern/extern_implementations.cc
index 42d4b2878bc..35de319f20b 100644
--- a/source/blender/nodes/intern/extern_implementations.cc
+++ b/source/blender/nodes/intern/extern_implementations.cc
@@ -15,6 +15,7 @@
*/
#include "NOD_socket_declarations.hh"
+#include "NOD_socket_declarations_geometry.hh"
namespace blender::nodes {
#define MAKE_EXTERN_SOCKET_IMPLEMENTATION(TYPE) \
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index 8ea085d42f9..bcf6ff2fcf6 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -36,6 +36,71 @@ void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::strin
local_logger.log_node_warning(provider_->dnode, type, std::move(message));
}
+void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
+ const GeometrySet &geometry_set) const
+{
+ const int input_index = provider_->dnode->input_by_identifier(identifier).index();
+ const SocketDeclaration &decl = *provider_->dnode->declaration()->inputs()[input_index];
+ const decl::Geometry *geo_decl = dynamic_cast<const decl::Geometry *>(&decl);
+ if (geo_decl == nullptr) {
+ return;
+ }
+
+ const bool only_realized_data = geo_decl->only_realized_data();
+ const bool only_instances = geo_decl->only_instances();
+ const Span<GeometryComponentType> supported_types = geo_decl->supported_types();
+
+ if (only_realized_data) {
+ if (geometry_set.has_instances()) {
+ this->error_message_add(NodeWarningType::Info, "Instances in input geometry are ignored");
+ }
+ }
+ if (only_instances) {
+ if (geometry_set.has_realized_data()) {
+ this->error_message_add(NodeWarningType::Info,
+ "Realized data in input geometry are ignored");
+ }
+ }
+ if (supported_types.is_empty()) {
+ /* Assume all types are supported. */
+ return;
+ }
+ const Vector<GeometryComponentType> types_in_geometry = geometry_set.gather_component_types(
+ true, true);
+ for (const GeometryComponentType type : types_in_geometry) {
+ if (type == GEO_COMPONENT_TYPE_INSTANCES) {
+ continue;
+ }
+ if (supported_types.contains(type)) {
+ continue;
+ }
+ std::string message = TIP_("Input geometry has unsupported type: ");
+ switch (type) {
+ case GEO_COMPONENT_TYPE_MESH: {
+ message += TIP_("Mesh");
+ break;
+ }
+ case GEO_COMPONENT_TYPE_POINT_CLOUD: {
+ message += TIP_("Point Cloud");
+ break;
+ }
+ case GEO_COMPONENT_TYPE_INSTANCES: {
+ BLI_assert_unreachable();
+ break;
+ }
+ case GEO_COMPONENT_TYPE_VOLUME: {
+ message += TIP_("Volume");
+ break;
+ }
+ case GEO_COMPONENT_TYPE_CURVE: {
+ message += TIP_("Curve");
+ break;
+ }
+ }
+ this->error_message_add(NodeWarningType::Info, std::move(message));
+ }
+}
+
const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const
{
for (const InputSocketRef *socket : provider_->dnode->inputs()) {
diff --git a/source/blender/nodes/intern/node_socket_declarations.cc b/source/blender/nodes/intern/node_socket_declarations.cc
index e823476f9e4..ed5691ebf7f 100644
--- a/source/blender/nodes/intern/node_socket_declarations.cc
+++ b/source/blender/nodes/intern/node_socket_declarations.cc
@@ -15,6 +15,7 @@
*/
#include "NOD_socket_declarations.hh"
+#include "NOD_socket_declarations_geometry.hh"
#include "BKE_node.h"
@@ -333,6 +334,46 @@ bool Geometry::matches(const bNodeSocket &socket) const
return true;
}
+Span<GeometryComponentType> Geometry::supported_types() const
+{
+ return supported_types_;
+}
+
+bool Geometry::only_realized_data() const
+{
+ return only_realized_data_;
+}
+
+bool Geometry::only_instances() const
+{
+ return only_instances_;
+}
+
+GeometryBuilder &GeometryBuilder::supported_type(GeometryComponentType supported_type)
+{
+ decl_->supported_types_ = {supported_type};
+ return *this;
+}
+
+GeometryBuilder &GeometryBuilder::supported_type(
+ blender::Vector<GeometryComponentType> supported_types)
+{
+ decl_->supported_types_ = std::move(supported_types);
+ return *this;
+}
+
+GeometryBuilder &GeometryBuilder::only_realized_data(bool value)
+{
+ decl_->only_realized_data_ = value;
+ return *this;
+}
+
+GeometryBuilder &GeometryBuilder::only_instances(bool value)
+{
+ decl_->only_instances_ = value;
+ return *this;
+}
+
/** \} */
} // namespace blender::nodes::decl