From db6eda6c609fe3033fc2ecd6103da86d14547e95 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 10 May 2023 14:39:23 +0200 Subject: [PATCH] Geometry Nodes: show simulated frames only when there is a simulation Previously, the timeline would sometimes show cached frames even when there is no simulation zone in the node tree. --- .../blenkernel/intern/node_tree_update.cc | 47 ++++++++++--------- .../editors/space_action/action_draw.cc | 24 +++++++--- source/blender/makesdna/DNA_node_types.h | 2 + 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc index edc56c58486..1ab354f9771 100644 --- a/source/blender/blenkernel/intern/node_tree_update.cc +++ b/source/blender/blenkernel/intern/node_tree_update.cc @@ -709,37 +709,42 @@ class NodeTreeMainUpdater { ntree.ensure_topology_cache(); ntree.runtime->runtime_flag = 0; - if (ntree.type != NTREE_SHADER) { - return; - } - /* Check if a used node group has an animated image. */ - for (const bNode *group_node : ntree.nodes_by_type("ShaderNodeGroup")) { + for (const bNode *group_node : ntree.group_nodes()) { const bNodeTree *group = reinterpret_cast(group_node->id); if (group != nullptr) { ntree.runtime->runtime_flag |= group->runtime->runtime_flag; } } - /* Check if the tree itself has an animated image. */ - for (const StringRefNull idname : {"ShaderNodeTexImage", "ShaderNodeTexEnvironment"}) { - for (const bNode *node : ntree.nodes_by_type(idname)) { - Image *image = reinterpret_cast(node->id); - if (image != nullptr && BKE_image_is_animated(image)) { - ntree.runtime->runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; + + if (ntree.type == NTREE_SHADER) { + /* Check if the tree itself has an animated image. */ + for (const StringRefNull idname : {"ShaderNodeTexImage", "ShaderNodeTexEnvironment"}) { + for (const bNode *node : ntree.nodes_by_type(idname)) { + Image *image = reinterpret_cast(node->id); + if (image != nullptr && BKE_image_is_animated(image)) { + ntree.runtime->runtime_flag |= NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION; + break; + } + } + } + /* Check if the tree has a material output. */ + for (const StringRefNull idname : {"ShaderNodeOutputMaterial", + "ShaderNodeOutputLight", + "ShaderNodeOutputWorld", + "ShaderNodeOutputAOV"}) + { + const Span nodes = ntree.nodes_by_type(idname); + if (!nodes.is_empty()) { + ntree.runtime->runtime_flag |= NTREE_RUNTIME_FLAG_HAS_MATERIAL_OUTPUT; break; } } } - /* Check if the tree has a material output. */ - for (const StringRefNull idname : {"ShaderNodeOutputMaterial", - "ShaderNodeOutputLight", - "ShaderNodeOutputWorld", - "ShaderNodeOutputAOV"}) - { - const Span nodes = ntree.nodes_by_type(idname); - if (!nodes.is_empty()) { - ntree.runtime->runtime_flag |= NTREE_RUNTIME_FLAG_HAS_MATERIAL_OUTPUT; - break; + if (ntree.type == NTREE_GEOMETRY) { + /* Check if there is a simulation zone. */ + if (!ntree.nodes_by_type("GeometryNodeSimulationOutput").is_empty()) { + ntree.runtime->runtime_flag |= NTREE_RUNTIME_FLAG_HAS_SIMULATION_ZONE; } } } diff --git a/source/blender/editors/space_action/action_draw.cc b/source/blender/editors/space_action/action_draw.cc index a85e28b781f..60d0f0e2def 100644 --- a/source/blender/editors/space_action/action_draw.cc +++ b/source/blender/editors/space_action/action_draw.cc @@ -22,12 +22,14 @@ #include "DNA_cachefile_types.h" #include "DNA_gpencil_legacy_types.h" #include "DNA_modifier_types.h" +#include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "BKE_action.h" #include "BKE_context.h" +#include "BKE_node_runtime.hh" #include "BKE_pointcache.h" #include "BKE_simulation_state.hh" @@ -757,14 +759,22 @@ void timeline_draw_cache(const SpaceAction *saction, const Object *ob, const Sce y_offset += cache_draw_height; } LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { - if (md->type == eModifierType_Nodes) { - const NodesModifierData *nmd = reinterpret_cast(md); - if (nmd->simulation_cache != nullptr) { - timeline_cache_draw_simulation_nodes( - *scene, *nmd->simulation_cache, y_offset, cache_draw_height, pos_id); - y_offset += cache_draw_height; - } + if (md->type != eModifierType_Nodes) { + continue; } + const NodesModifierData *nmd = reinterpret_cast(md); + if (nmd->node_group == nullptr) { + continue; + } + if (nmd->simulation_cache == nullptr) { + continue; + } + if ((nmd->node_group->runtime->runtime_flag & NTREE_RUNTIME_FLAG_HAS_SIMULATION_ZONE) == 0) { + continue; + } + timeline_cache_draw_simulation_nodes( + *scene, *nmd->simulation_cache, y_offset, cache_draw_height, pos_id); + y_offset += cache_draw_height; } GPU_blend(GPU_BLEND_NONE); diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 58140e34130..8393d1307ce 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -690,6 +690,8 @@ typedef enum eNodeTreeRuntimeFlag { NTREE_RUNTIME_FLAG_HAS_IMAGE_ANIMATION = 1 << 0, /** There is a material output node in the group. */ NTREE_RUNTIME_FLAG_HAS_MATERIAL_OUTPUT = 1 << 1, + /** There is a simulation zone in the group. */ + NTREE_RUNTIME_FLAG_HAS_SIMULATION_ZONE = 1 << 2, } eNodeTreeRuntimeFlag; /* socket value structs for input buttons