Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/node_tree_update.cc
| Show First 20 Lines • Show All 979 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); | this->propagate_runtime_flags(*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) | void propagate_runtime_flags(const NodeTreeRef &tree_ref) | ||||
| { | { | ||||
| bNodeTree &ntree = *tree_ref.btree(); | bNodeTree &ntree = *tree_ref.btree(); | ||||
| ntree.runtime_flag &= ~NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | ntree.runtime_flag = 0; | ||||
| if (ntree.type != NTREE_SHADER) { | if (ntree.type != NTREE_SHADER) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Check if a used node group has an animated image. */ | /* Check if a used node group has an animated image. */ | ||||
| for (const NodeRef *group_node : tree_ref.nodes_by_type("NodeGroup")) { | for (const NodeRef *group_node : tree_ref.nodes_by_type("NodeGroup")) { | ||||
| const bNodeTree *group = reinterpret_cast<bNodeTree *>(group_node->bnode()->id); | const bNodeTree *group = reinterpret_cast<bNodeTree *>(group_node->bnode()->id); | ||||
| if (group != nullptr) { | if (group != nullptr) { | ||||
| if (group->runtime_flag & NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION) { | ntree.runtime_flag |= group->runtime_flag; | ||||
| ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | |||||
| return; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /* Check if the tree itself has an animated image. */ | /* Check if the tree itself has an animated image. */ | ||||
| for (const StringRefNull idname : {"ShaderNodeTexImage", "ShaderNodeTexEnvironment"}) | for (const StringRefNull idname : {"ShaderNodeTexImage", "ShaderNodeTexEnvironment"}) { | ||||
| for (const NodeRef *node : tree_ref.nodes_by_type(idname)) { | for (const NodeRef *node : tree_ref.nodes_by_type(idname)) { | ||||
| Image *image = reinterpret_cast<Image *>(node->bnode()->id); | Image *image = reinterpret_cast<Image *>(node->bnode()->id); | ||||
| if (image != nullptr && BKE_image_is_animated(image)) { | if (image != nullptr && BKE_image_is_animated(image)) { | ||||
| ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; | ||||
| return; | break; | ||||
| } | |||||
| } | |||||
| } | |||||
| /* Check if the tree has a material output. */ | |||||
| for (const StringRefNull idname : {"ShaderNodeOutputMaterial", | |||||
| "ShaderNodeOutputLight", | |||||
| "ShaderNodeOutputWorld", | |||||
| "ShaderNodeOutputAOV"}) { | |||||
| const Span<const NodeRef *> nodes = tree_ref.nodes_by_type(idname); | |||||
| if (!nodes.is_empty()) { | |||||
| ntree.runtime_flag |= NTREE_RUNTIME_FLAG_HAS_MATERIAL_OUTPUT; | |||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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) | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | bool is_output_node(const NodeRef &node) const | ||||
| const bNode &bnode = *node.bnode(); | const bNode &bnode = *node.bnode(); | ||||
| if (bnode.typeinfo->nclass == NODE_CLASS_OUTPUT) { | if (bnode.typeinfo->nclass == NODE_CLASS_OUTPUT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (bnode.type == NODE_GROUP_OUTPUT) { | if (bnode.type == NODE_GROUP_OUTPUT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* Assume node groups without output sockets are outputs. */ | /* Assume node groups without output sockets are outputs. */ | ||||
| /* TODO: Store whether a node group contains a top-level output node (e.g. Material Output) in | if (bnode.type == NODE_GROUP) { | ||||
| * run-time information on the node group itself. */ | const bNodeTree *node_group = reinterpret_cast<const bNodeTree *>(bnode.id); | ||||
| if (bnode.type == NODE_GROUP && node.outputs().is_empty()) { | if (node_group->runtime_flag & NTREE_RUNTIME_FLAG_HAS_MATERIAL_OUTPUT) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | |||||
| return false; | return false; | ||||
| } | } | ||||
| /** | /** | ||||
| * Computes a hash that changes when the node tree topology connected to an output node changes. | * Computes a hash that changes when the node tree topology connected to an output node changes. | ||||
| * Adding reroutes does not have an effect on the hash. | * Adding reroutes does not have an effect on the hash. | ||||
| */ | */ | ||||
| uint32_t get_combined_socket_topology_hash(const NodeTreeRef &tree, | uint32_t get_combined_socket_topology_hash(const NodeTreeRef &tree, | ||||
| ▲ Show 20 Lines • Show All 337 Lines • Show Last 20 Lines | |||||