Geometry Nodes: new Bake node #115466
|
@ -48,8 +48,11 @@ struct PrevCache {
|
|||
SubFrame frame;
|
||||
};
|
||||
|
||||
/**
|
||||
* Baked data that corresponds to either a Simulation Output or Bake node.
|
||||
*/
|
||||
struct NodeBakeCache {
|
||||
/** All cached frames. */
|
||||
/** All cached frames sorted by frame. */
|
||||
Vector<std::unique_ptr<FrameCache>> frames;
|
||||
|
||||
/** Where to load blobs from disk when loading the baked data lazily. */
|
||||
|
@ -59,15 +62,10 @@ struct NodeBakeCache {
|
|||
/** Used to avoid checking if a bake exists many times. */
|
||||
bool failed_finding_bake = false;
|
||||
|
||||
IndexRange frame_range() const
|
||||
{
|
||||
if (this->frames.is_empty()) {
|
||||
return {};
|
||||
}
|
||||
const int start_frame = this->frames.first()->frame.frame();
|
||||
const int end_frame = this->frames.last()->frame.frame();
|
||||
return {start_frame, end_frame - start_frame + 1};
|
||||
}
|
||||
/** Range spanning from the first to the last baked frame. */
|
||||
IndexRange frame_range() const;
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
struct SimulationNodeCache {
|
||||
|
@ -89,21 +87,16 @@ struct BakeNodeCache {
|
|||
|
||||
struct ModifierCache {
|
||||
mutable std::mutex mutex;
|
||||
/**
|
||||
* Set of nested node IDs (see #bNestedNodeRef) that is expected to be baked in the next
|
||||
* evaluation. This is filled and cleared by the bake operator.
|
||||
*/
|
||||
Set<int> requested_bakes;
|
||||
Map<int, std::unique_ptr<SimulationNodeCache>> simulation_cache_by_id;
|
||||
Map<int, std::unique_ptr<BakeNodeCache>> bake_cache_by_id;
|
||||
|
||||
SimulationNodeCache *get_simulation_node_cache(const int id)
|
||||
{
|
||||
std::unique_ptr<SimulationNodeCache> *ptr = this->simulation_cache_by_id.lookup_ptr(id);
|
||||
return ptr ? (*ptr).get() : nullptr;
|
||||
}
|
||||
|
||||
BakeNodeCache *get_bake_node_cache(const int id)
|
||||
{
|
||||
std::unique_ptr<BakeNodeCache> *ptr = this->bake_cache_by_id.lookup_ptr(id);
|
||||
return ptr ? (*ptr).get() : nullptr;
|
||||
}
|
||||
SimulationNodeCache *get_simulation_node_cache(const int id);
|
||||
BakeNodeCache *get_bake_node_cache(const int id);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,6 +36,34 @@ void BakeNodeCache::reset()
|
|||
new (this) BakeNodeCache();
|
||||
}
|
||||
|
||||
void NodeBakeCache::reset()
|
||||
{
|
||||
std::destroy_at(this);
|
||||
new (this) NodeBakeCache();
|
||||
}
|
||||
|
||||
IndexRange NodeBakeCache::frame_range() const
|
||||
{
|
||||
if (this->frames.is_empty()) {
|
||||
return {};
|
||||
}
|
||||
const int start_frame = this->frames.first()->frame.frame();
|
||||
const int end_frame = this->frames.last()->frame.frame();
|
||||
return {start_frame, end_frame - start_frame + 1};
|
||||
}
|
||||
|
||||
SimulationNodeCache *ModifierCache::get_simulation_node_cache(const int id)
|
||||
{
|
||||
std::unique_ptr<SimulationNodeCache> *ptr = this->simulation_cache_by_id.lookup_ptr(id);
|
||||
return ptr ? (*ptr).get() : nullptr;
|
||||
}
|
||||
|
||||
BakeNodeCache *ModifierCache::get_bake_node_cache(const int id)
|
||||
{
|
||||
std::unique_ptr<BakeNodeCache> *ptr = this->bake_cache_by_id.lookup_ptr(id);
|
||||
return ptr ? (*ptr).get() : nullptr;
|
||||
}
|
||||
|
||||
void scene_simulation_states_reset(Scene &scene)
|
||||
{
|
||||
FOREACH_SCENE_OBJECT_BEGIN (&scene, ob) {
|
||||
|
|
|
@ -880,6 +880,7 @@ void timeline_draw_cache(const SpaceAction *saction, const Object *ob, const Sce
|
|||
continue;
|
||||
}
|
||||
if (nmd->node_group->nested_node_refs_num == 0) {
|
||||
/* Skip when there are no bake nodes or simulations. */
|
||||
continue;
|
||||
}
|
||||
const blender::bke::bake::ModifierCache &modifier_cache = *nmd->runtime->cache;
|
||||
|
|
|
@ -875,10 +875,7 @@ static bool try_find_baked_data(bake::NodeBakeCache &bake,
|
|||
if (meta_files.is_empty()) {
|
||||
return false;
|
||||
}
|
||||
/* Reset bake. */
|
||||
std::destroy_at(&bake);
|
||||
new (&bake) bake::NodeBakeCache();
|
||||
|
||||
bake.reset();
|
||||
for (const bake::MetaFile &meta_file : meta_files) {
|
||||
auto frame_cache = std::make_unique<bake::FrameCache>();
|
||||
frame_cache->frame = meta_file.frame;
|
||||
|
@ -1253,6 +1250,7 @@ class NodesModifierBakeParams : public nodes::GeoNodesBakeParams {
|
|||
|
||||
if (depsgraph_is_active_) {
|
||||
if (modifier_cache_->requested_bakes.contains(id)) {
|
||||
/* This node is baked during the current evaluation. */
|
||||
auto &store_info = behavior.emplace<sim_output::StoreNewState>();
|
||||
store_info.store_fn = [modifier_cache = modifier_cache_,
|
||||
node_cache = &node_cache,
|
||||
|
|
Loading…
Reference in New Issue