Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/node_tree_update.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||||||
| #include "BLI_map.hh" | #include "BLI_map.hh" | ||||||||
| #include "BLI_multi_value_map.hh" | #include "BLI_multi_value_map.hh" | ||||||||
| #include "BLI_noise.hh" | #include "BLI_noise.hh" | ||||||||
| #include "BLI_set.hh" | #include "BLI_set.hh" | ||||||||
| #include "BLI_stack.hh" | #include "BLI_stack.hh" | ||||||||
| #include "BLI_vector_set.hh" | #include "BLI_vector_set.hh" | ||||||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||||||
| #include "DNA_modifier_types.h" | #include "DNA_modifier_types.h" | ||||||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||||||
| #include "BKE_anim_data.h" | #include "BKE_anim_data.h" | ||||||||
| #include "BKE_image.h" | |||||||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||||||
| #include "BKE_node_tree_update.h" | #include "BKE_node_tree_update.h" | ||||||||
| #include "MOD_nodes.h" | #include "MOD_nodes.h" | ||||||||
| #include "NOD_node_declaration.hh" | #include "NOD_node_declaration.hh" | ||||||||
| #include "NOD_node_tree_ref.hh" | #include "NOD_node_tree_ref.hh" | ||||||||
| ▲ Show 20 Lines • Show All 961 Lines • ▼ Show 20 Lines | TreeUpdateResult update_tree(bNodeTree &ntree) | ||||||||
| this->remove_unused_previews_when_necessary(ntree); | this->remove_unused_previews_when_necessary(ntree); | ||||||||
| this->ensure_tree_ref(ntree, tree_ref); | this->ensure_tree_ref(ntree, tree_ref); | ||||||||
| if (ntree.type == NTREE_GEOMETRY) { | if (ntree.type == NTREE_GEOMETRY) { | ||||||||
| if (node_field_inferencing::update_field_inferencing(*tree_ref)) { | if (node_field_inferencing::update_field_inferencing(*tree_ref)) { | ||||||||
| result.interface_changed = true; | result.interface_changed = true; | ||||||||
| } | } | ||||||||
| } | } | ||||||||
| ntree.runtime_flag &= ~NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | |||||||||
| for (const NodeRef *group_node : tree_ref->nodes_by_type("NodeGroup")) { | |||||||||
| const bNodeTree *group = reinterpret_cast<bNodeTree *>(group_node->bnode()->id); | |||||||||
| if (group != nullptr) { | |||||||||
| if (group->runtime_flag & NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION) { | |||||||||
| ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | |||||||||
| break; | |||||||||
| } | |||||||||
| } | |||||||||
| } | |||||||||
| for (const NodeRef *image_node : tree_ref->nodes_by_type("ShaderNodeTexImage")) { | |||||||||
| Image *image = reinterpret_cast<Image *>(image_node->bnode()->id); | |||||||||
| if (BKE_image_is_animated(image)) { | |||||||||
| ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | |||||||||
| } | |||||||||
| } | |||||||||
| result.output_changed = this->check_if_output_changed(*tree_ref); | result.output_changed = this->check_if_output_changed(*tree_ref); | ||||||||
| this->update_socket_link_and_use(*tree_ref); | this->update_socket_link_and_use(*tree_ref); | ||||||||
| this->update_node_levels(ntree); | this->update_node_levels(ntree); | ||||||||
| this->update_link_validation(ntree); | this->update_link_validation(ntree); | ||||||||
| if (ntree.type == NTREE_TEXTURE) { | if (ntree.type == NTREE_TEXTURE) { | ||||||||
| ▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | void remove_unused_previews_when_necessary(bNodeTree &ntree) | ||||||||
| } | } | ||||||||
| BKE_node_preview_remove_unused(&ntree); | BKE_node_preview_remove_unused(&ntree); | ||||||||
| } | } | ||||||||
| void update_node_levels(bNodeTree &ntree) | void update_node_levels(bNodeTree &ntree) | ||||||||
| { | { | ||||||||
| ntreeUpdateNodeLevels(&ntree); | ntreeUpdateNodeLevels(&ntree); | ||||||||
| } | } | ||||||||
HooglyBoogly: Maybe it verges on negligible, but I think this could return early for non-shader node trees. | |||||||||
Done Inline ActionsReturning early should be fine, but yeah, that's mostly negilible. JacquesLucke: Returning early should be fine, but yeah, that's mostly negilible.
I think the `nodes_by_type`… | |||||||||
| void update_link_validation(bNodeTree &ntree) | void update_link_validation(bNodeTree &ntree) | ||||||||
Not Done Inline ActionsMaybe this comment could mention the requirement that the child node trees have been updated first? HooglyBoogly: Maybe this comment could mention the requirement that the child node trees have been updated… | |||||||||
Done Inline ActionsCould be added, but generally, the entire update mechanism assumes that child node trees are updated first. It's hardly a special case in this function. JacquesLucke: Could be added, but generally, the entire update mechanism assumes that child node trees are… | |||||||||
Not Done Inline ActionsAh, sure, fair enough. HooglyBoogly: Ah, sure, fair enough. | |||||||||
| { | { | ||||||||
| LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { | LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { | ||||||||
Not Done Inline Actions
HooglyBoogly: | |||||||||
| link->flag |= NODE_LINK_VALID; | link->flag |= NODE_LINK_VALID; | ||||||||
| if (link->fromnode && link->tonode && link->fromnode->level <= link->tonode->level) { | if (link->fromnode && link->tonode && link->fromnode->level <= link->tonode->level) { | ||||||||
| link->flag &= ~NODE_LINK_VALID; | link->flag &= ~NODE_LINK_VALID; | ||||||||
| } | } | ||||||||
| else if (ntree.typeinfo->validate_link) { | else if (ntree.typeinfo->validate_link) { | ||||||||
| const eNodeSocketDatatype from_type = static_cast<eNodeSocketDatatype>( | const eNodeSocketDatatype from_type = static_cast<eNodeSocketDatatype>( | ||||||||
| link->fromsock->type); | link->fromsock->type); | ||||||||
| const eNodeSocketDatatype to_type = static_cast<eNodeSocketDatatype>(link->tosock->type); | const eNodeSocketDatatype to_type = static_cast<eNodeSocketDatatype>(link->tosock->type); | ||||||||
| ▲ Show 20 Lines • Show All 441 Lines • Show Last 20 Lines | |||||||||
Maybe it verges on negligible, but I think this could return early for non-shader node trees. That would avoid two map lookups (nodeTypeFind does show up in profiles the last time I checked), and could potentially avoid the nodes_by_type map if that becomes lazy.