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 956 Lines • ▼ Show 20 Lines | TreeUpdateResult update_tree(bNodeTree &ntree) | ||||||||
| this->update_socket_link_and_use(*tree_ref); | this->update_socket_link_and_use(*tree_ref); | ||||||||
| this->update_individual_nodes(ntree, tree_ref); | this->update_individual_nodes(ntree, tree_ref); | ||||||||
| this->update_internal_links(ntree, tree_ref); | this->update_internal_links(ntree, tree_ref); | ||||||||
| this->update_generic_callback(ntree, tree_ref); | this->update_generic_callback(ntree, tree_ref); | ||||||||
| 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); | ||||||||
| this->update_has_image_animation(*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; | ||||||||
| } | } | ||||||||
| } | } | ||||||||
| result.output_changed = this->check_if_output_changed(*tree_ref); | result.output_changed = this->check_if_output_changed(*tree_ref); | ||||||||
| ▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | const uint32_t allowed_flags = NTREE_CHANGED_LINK | NTREE_CHANGED_SOCKET_PROPERTY | | ||||||||
| NTREE_CHANGED_NODE_PROPERTY | NTREE_CHANGED_NODE_OUTPUT | | NTREE_CHANGED_NODE_PROPERTY | NTREE_CHANGED_NODE_OUTPUT | | ||||||||
| NTREE_CHANGED_INTERFACE; | NTREE_CHANGED_INTERFACE; | ||||||||
| if ((ntree.changed_flag & allowed_flags) == ntree.changed_flag) { | if ((ntree.changed_flag & allowed_flags) == ntree.changed_flag) { | ||||||||
| return; | return; | ||||||||
| } | } | ||||||||
| BKE_node_preview_remove_unused(&ntree); | BKE_node_preview_remove_unused(&ntree); | ||||||||
| } | } | ||||||||
| void update_has_image_animation(const NodeTreeRef &tree_ref) | |||||||||
| { | |||||||||
| bNodeTree &ntree = *tree_ref.btree(); | |||||||||
| ntree.runtime_flag &= ~NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | |||||||||
HooglyBoogly: Maybe it verges on negligible, but I think this could return early for non-shader node trees. | |||||||||
JacquesLuckeAuthorUnsubmitted 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`… | |||||||||
| /* Check if a used node group has an animated image. */ | |||||||||
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. | |||||||||
| for (const NodeRef *group_node : tree_ref.nodes_by_type("NodeGroup")) { | |||||||||
| const bNodeTree *group = reinterpret_cast<bNodeTree *>(group_node->bnode()->id); | |||||||||
Not Done Inline Actions
HooglyBoogly: | |||||||||
| if (group != nullptr) { | |||||||||
| if (group->runtime_flag & NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION) { | |||||||||
| ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | |||||||||
| return; | |||||||||
| } | |||||||||
| } | |||||||||
| } | |||||||||
| /* Check if the tree itself has an animated image. */ | |||||||||
| for (const StringRefNull idname : {"ShaderNodeTexImage", "ShaderNodeTexEnvironment"}) | |||||||||
| for (const NodeRef *node : tree_ref.nodes_by_type(idname)) { | |||||||||
| Image *image = reinterpret_cast<Image *>(node->bnode()->id); | |||||||||
| if (image != nullptr && BKE_image_is_animated(image)) { | |||||||||
| ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | |||||||||
| return; | |||||||||
| } | |||||||||
| } | |||||||||
| } | |||||||||
| void update_node_levels(bNodeTree &ntree) | void update_node_levels(bNodeTree &ntree) | ||||||||
| { | { | ||||||||
| ntreeUpdateNodeLevels(&ntree); | ntreeUpdateNodeLevels(&ntree); | ||||||||
| } | } | ||||||||
| void update_link_validation(bNodeTree &ntree) | void update_link_validation(bNodeTree &ntree) | ||||||||
| { | { | ||||||||
| LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { | LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { | ||||||||
| ▲ Show 20 Lines • Show All 449 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.