Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/intern/node_geometry_exec.cc
| /* | /* | ||||
| * This program is free software; you can redistribute it and/or | * This program is free software; you can redistribute it and/or | ||||
| * modify it under the terms of the GNU General Public License | * modify it under the terms of the GNU General Public License | ||||
| * as published by the Free Software Foundation; either version 2 | * as published by the Free Software Foundation; either version 2 | ||||
| * of the License, or (at your option) any later version. | * of the License, or (at your option) any later version. | ||||
| * | * | ||||
| * This program is distributed in the hope that it will be useful, | * This program is distributed in the hope that it will be useful, | ||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| * GNU General Public License for more details. | * GNU General Public License for more details. | ||||
| * | * | ||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include "DNA_modifier_types.h" | |||||
| #include "BKE_node_ui_storage.hh" | |||||
| #include "DEG_depsgraph_query.h" | |||||
| #include "NOD_geometry_exec.hh" | #include "NOD_geometry_exec.hh" | ||||
| #include "NOD_type_callbacks.hh" | #include "NOD_type_callbacks.hh" | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| namespace blender::nodes { | namespace blender::nodes { | ||||
| void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::string message) const | |||||
| { | |||||
| bNodeTree *original_ntree = (bNodeTree *)DEG_get_original_id(&(ID &)ntree_); | |||||
| if (original_ntree != nullptr) { | |||||
| const NodeUIStorageContextModifier context = NodeUIStorageContextModifier(*self_object_, | |||||
| *modifier_); | |||||
| BKE_nodetree_error_message_add(*original_ntree, context, node_, type, std::move(message)); | |||||
| } | |||||
| } | |||||
| const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const | const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const | ||||
| { | { | ||||
| LISTBASE_FOREACH (const bNodeSocket *, socket, &node_.inputs) { | LISTBASE_FOREACH (const bNodeSocket *, socket, &node_.inputs) { | ||||
| if ((socket->flag & SOCK_UNAVAIL) != 0) { | if ((socket->flag & SOCK_UNAVAIL) != 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (name == socket->name) { | if (name == socket->name) { | ||||
| return socket; | return socket; | ||||
| Show All 12 Lines | ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name, | ||||
| const bNodeSocket *found_socket = this->find_available_socket(name); | const bNodeSocket *found_socket = this->find_available_socket(name); | ||||
| BLI_assert(found_socket != nullptr); /* There should always be available socket for the name. */ | BLI_assert(found_socket != nullptr); /* There should always be available socket for the name. */ | ||||
| if (found_socket == nullptr) { | if (found_socket == nullptr) { | ||||
| return component.attribute_get_constant_for_read(domain, type, default_value); | return component.attribute_get_constant_for_read(domain, type, default_value); | ||||
| } | } | ||||
| if (found_socket->type == SOCK_STRING) { | if (found_socket->type == SOCK_STRING) { | ||||
| const std::string name = this->get_input<std::string>(found_socket->identifier); | const std::string name = this->get_input<std::string>(found_socket->identifier); | ||||
| return component.attribute_get_for_read(name, domain, type, default_value); | /* Try getting the attribute without the default value, if that doesn't work, use the default | ||||
| * value and output an error message. */ | |||||
| ReadAttributePtr attribute = component.attribute_try_get_for_read(name, domain, type); | |||||
| if (attribute) { | |||||
| return attribute; | |||||
| } | |||||
| if (default_value == nullptr) { | |||||
JacquesLucke: I think the check should be `!name.is_empty()` instead. | |||||
| this->error_message_add(NodeWarningType::Error, | |||||
| std::string("No attribute with name '") + name + "'."); | |||||
| } | |||||
| return component.attribute_get_constant_for_read(domain, type, default_value); | |||||
| } | } | ||||
| if (found_socket->type == SOCK_FLOAT) { | if (found_socket->type == SOCK_FLOAT) { | ||||
| const float value = this->get_input<float>(found_socket->identifier); | const float value = this->get_input<float>(found_socket->identifier); | ||||
| return component.attribute_get_constant_for_read_converted( | return component.attribute_get_constant_for_read_converted( | ||||
| domain, CD_PROP_FLOAT, type, &value); | domain, CD_PROP_FLOAT, type, &value); | ||||
| } | } | ||||
| if (found_socket->type == SOCK_VECTOR) { | if (found_socket->type == SOCK_VECTOR) { | ||||
| const float3 value = this->get_input<float3>(found_socket->identifier); | const float3 value = this->get_input<float3>(found_socket->identifier); | ||||
| ▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines | |||||
I think the check should be !name.is_empty() instead.