diff options
author | Jacques Lucke <jacques@blender.org> | 2021-10-26 21:00:03 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-10-26 21:00:10 +0300 |
commit | 0bfae1b12078ef278a56c6e932c13be5bc9781aa (patch) | |
tree | 38122afad7575db55b0aafa3958af8022fe3cdde /source/blender/nodes/intern/node_geometry_exec.cc | |
parent | be3e09ecec5372f87b3e9779adb821867b062be1 (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/node_geometry_exec.cc')
-rw-r--r-- | source/blender/nodes/intern/node_geometry_exec.cc | 65 |
1 files changed, 65 insertions, 0 deletions
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()) { |