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.
This commit is contained in:
Jacques Lucke
2023-05-10 14:39:23 +02:00
parent 17d161f565
commit db6eda6c60
3 changed files with 45 additions and 28 deletions

View File

@@ -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<bNodeTree *>(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<Image *>(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<Image *>(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<const bNode *> 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<const bNode *> 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;
}
}
}

View File

@@ -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<NodesModifierData *>(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<NodesModifierData *>(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);

View File

@@ -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