WIP: Experiment: Geometry Nodes: support baking individual simulations #112179

Closed
Jacques Lucke wants to merge 51 commits from JacquesLucke/blender:simulation-bake-individual into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 38 additions and 8 deletions
Showing only changes of commit 259e635ced - Show all commits

View File

@ -370,11 +370,14 @@ static void bake_simulation_job_startjob(void *customdata,
for (ModifierBakeData &modifier_bake_data : object_bake_data.modifiers) {
NodesModifierData &nmd = *modifier_bake_data.nmd;
for (ZoneBakeData &zone_bake_data : modifier_bake_data.zones) {
if (std::unique_ptr<bake::NodeCache> &node_cache = nmd.runtime->cache->cache_by_id.lookup(
zone_bake_data.zone_id))
if (std::unique_ptr<bake::NodeCache> *node_cache_ptr =
nmd.runtime->cache->cache_by_id.lookup_ptr(zone_bake_data.zone_id))
{
/* Tag the caches as being baked so that they are not changed anymore. */
node_cache->cache_status = bake::CacheStatus::Baked;
bake::NodeCache &node_cache = **node_cache_ptr;
if (!node_cache.frame_caches.is_empty()) {
/* Tag the caches as being baked so that they are not changed anymore. */
node_cache.cache_status = bake::CacheStatus::Baked;
}
}
}
}

View File

@ -16,6 +16,7 @@ set(INC
../../gpu
../../imbuf
../../makesrna
../../modifiers
../../render
../../windowmanager
../../../../extern/fmtlib/include

View File

@ -8,6 +8,7 @@
#include "BLI_task.hh"
#include "BKE_attribute_math.hh"
#include "BKE_bake_geometry_nodes_modifier.hh"
#include "BKE_bake_items_socket.hh"
#include "BKE_compute_contexts.hh"
#include "BKE_context.h"
@ -40,6 +41,8 @@
#include "RNA_access.hh"
#include "RNA_prototypes.h"
#include "MOD_nodes.hh"
#include "node_geometry_util.hh"
namespace blender::nodes {
@ -816,7 +819,7 @@ static void node_copy_storage(bNodeTree * /*dst_tree*/, bNode *dst_node, const b
dst_node->storage = dst_storage;
}
static void node_layout(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
const bNode *node = static_cast<bNode *>(ptr->data);
SpaceNode *snode = CTX_wm_space_node(C);
@ -858,9 +861,32 @@ static void node_layout(uiLayout *layout, bContext *C, PointerRNA *ptr)
PointerRNA bake_rna;
RNA_pointer_create(&object->id, &RNA_NodesModifierBake, (void *)bake, &bake_rna);
uiItemR(layout, &bake_rna, "directory", UI_ITEM_NONE, "Path", ICON_NONE);
bool is_baked = false;
if (nmd.runtime->cache) {
const bke::bake::ModifierCache &cache = *nmd.runtime->cache;
std::lock_guard lock{cache.mutex};
if (const std::unique_ptr<bke::bake::NodeCache> *node_cache_ptr = cache.cache_by_id.lookup_ptr(
*bake_id))
{
const bke::bake::NodeCache &node_cache = **node_cache_ptr;
if (node_cache.cache_status == bke::bake::CacheStatus::Baked &&
!node_cache.frame_caches.is_empty())
{
is_baked = true;
const int first_frame = node_cache.frame_caches.first()->frame.frame();
const int last_frame = node_cache.frame_caches.last()->frame.frame();
char baked_label[1024];
SNPRINTF(baked_label, "Baked %d - %d", first_frame, last_frame);
uiItemL(layout, baked_label, ICON_NONE);
}
}
}
uiLayout *col = uiLayoutColumn(layout, true);
uiLayoutSetActive(col, !is_baked);
uiItemR(col, &bake_rna, "directory", UI_ITEM_NONE, "Path", ICON_NONE);
if (StringRef(bake->directory).is_empty()) {
uiItemL(layout, "Uses modifier bake path", ICON_INFO);
uiItemL(col, "Uses modifier bake path", ICON_INFO);
}
}
@ -910,7 +936,7 @@ static void node_register()
ntype.gather_add_node_search_ops = search_node_add_ops;
ntype.gather_link_search_ops = nullptr;
ntype.insert_link = node_insert_link;
ntype.draw_buttons_ex = node_layout;
ntype.draw_buttons_ex = node_layout_ex;
node_type_storage(&ntype, "NodeGeometrySimulationOutput", node_free_storage, node_copy_storage);
nodeRegisterType(&ntype);
}