83 G.is_rendering =
true;
100 for (
auto item : nmd->
runtime->
cache->simulation_cache_by_id.items()) {
101 if (item.value->cache_status != bake::CacheStatus::Baked) {
106 objects_to_calc.
append(
object);
112 const float frame_step_size = 1.0f;
113 const float progress_per_frame = 1.0f /
120 if (
G.is_break || worker_status->
stop) {
129 worker_status->
progress += progress_per_frame;
144 G.is_rendering =
false;
180 "Calculating simulation...",
214 if (!use_frame_cache) {
228 std::optional<bake::BakePath>
path;
269 G.is_rendering =
true;
276 global_bake_start_frame = std::min(global_bake_start_frame, request.
frame_start);
277 global_bake_end_frame = std::max(global_bake_end_frame, request.
frame_end);
283 const int frames_to_bake = global_bake_end_frame - global_bake_start_frame + 1;
285 const float frame_step_size = 1.0f;
286 const float progress_per_frame = frame_step_size / frames_to_bake;
289 struct MemoryBakeFile {
302 for (
float frame_f = global_bake_start_frame; frame_f <= global_bake_end_frame;
303 frame_f += frame_step_size)
307 if (
G.is_break || worker_status->
stop) {
326 if (bake_cache ==
nullptr) {
329 if (bake_cache->
frames.is_empty()) {
333 if (frame_cache.
frame != frame) {
339 if (request.
path.has_value()) {
343 request.
path->meta_dir.c_str(),
344 (frame_file_name +
".json").c_str());
347 fstream meta_file{meta_path, std::ios::out};
350 written_size += meta_file.tellp();
356 std::ostringstream meta_file{std::ios::binary};
359 packed_data.meta_files.append({frame_file_name +
".json", meta_file.str()});
362 for (
auto &&item : blob_stream_by_name.
items()) {
363 std::string
data = item.value.stream->str();
371 packed_data.blob_files.append({item.key, std::move(
data)});
374 written_size += meta_file.tellp();
378 worker_status->
progress += progress_per_frame;
392 PackedBake *packed_data = packed_data_by_bake.
lookup_ptr(&request);
408 MemoryBakeFile *memory_bake_files,
412 MemoryBakeFile &memory = memory_bake_files[i];
414 const int64_t data_size = memory.data.size();
415 if (data_size == 0) {
419 const void *
data = sharing_info->data.data();
431 bake->packed = packed_bake;
443 if (!node_cache->bake.frames.is_empty()) {
445 node_cache->cache_status = bake::CacheStatus::Baked;
462 G.is_rendering =
false;
479 &
bake.data_blocks_num,
480 &
bake.active_data_block,
482 nodes_modifier_data_block_destruct(data_block, true);
515 std::lock_guard
lock{modifier_cache.
mutex};
517 (*node_cache)->reset();
519 else if (
auto *node_cache = modifier_cache.
bake_cache_by_id.lookup_ptr(bake_id)) {
520 (*node_cache)->reset();
530 bake->packed =
nullptr;
534 *bmain,
object, nmd, bake_id);
538 const char *meta_dir = bake_path->meta_dir.c_str();
544 const char *blobs_dir = bake_path->blobs_dir.c_str();
550 if (bake_path->bake_dir.has_value()) {
551 const char *zone_bake_dir = bake_path->bake_dir->c_str();
556 *bmain,
object, nmd))
559 BLI_delete(modifier_bake_dir->c_str(),
true,
false);
628 for (
Object *
object : objects) {
647 const int id = nested_node_ref.id;
657 request.
blob_sharing = std::make_unique<bake::BlobWriteSharing>();
662 scene, *
object, *nmd,
id);
669 requests.
append(std::move(request));
709 char *
norm =
static_cast<char *
>(norm_buf.
buffer());
761 if (bake_directory_set) {
772 "Bake directory of object %s, modifier %s is empty, setting default path",
787 for (
Object *
object : objects) {
815 for (
const Object *
object : objects) {
823 bool all_bakes_have_custom_dir =
true;
826 if (!bake_path || !bake_path.value().bake_dir ||
827 bake_path.value().bake_dir.value().empty())
829 all_bakes_have_custom_dir =
false;
833 bake_path.value().bake_dir.value(),
834 [](
int *value) { *value = 1; },
835 [](
int *value) { ++(*value); });
839 if (all_bakes_have_custom_dir) {
844 *bmain, *
object, *nmd);
845 if (!modifier_bake_dir) {
850 *modifier_bake_dir, [](
int *value) { *value = 1; }, [](
int *value) { ++(*value); });
878 bool has_path_conflict =
false;
879 bool has_existing_bake_data =
false;
880 for (
const auto &item : path_users.
items()) {
882 if (item.value > 1) {
885 "Path conflict: %d caches set to path %s",
888 has_path_conflict =
true;
893 has_existing_bake_data =
true;
897 if (has_path_conflict) {
901 if (has_existing_bake_data) {
904 IFACE_(
"Overwrite existing bake data?"),
946 for (
Object *
object : objects) {
970 if (
object ==
nullptr) {
991 if (
node ==
nullptr) {
1003 request.
blob_sharing = std::make_unique<bake::BlobWriteSharing>();
1011 if (!request.
path) {
1014 "Cannot determine bake location on disk. Falling back to packed bake.");
1019 const int current_frame = scene->
r.
cfra;
1028 *scene, *
object, nmd, bake_id);
1029 if (!frame_range.has_value()) {
1032 if (frame_range->is_empty()) {
1036 request.
frame_end = frame_range->last();
1040 requests.
append(std::move(request));
1080 if (
object ==
nullptr) {
1085 if (md ==
nullptr) {
1104 if (
object ==
nullptr) {
1109 if (md ==
nullptr) {
1116 *bmain, *
object, nmd, bake_id);
1137 ui::Layout &layout = *popup_menu_layout(pup);
1146 popup_menu_end(
C, pup);
1156 if (
object ==
nullptr) {
1161 if (md ==
nullptr) {
1174 *bmain, op->
reports, *
object, nmd, *
bake, method);
1175 if (
result != bake::UnpackGeometryNodesBakeResult::Success) {
1186 ot->
name =
"Calculate Simulation to Frame";
1188 "Calculate simulations in geometry nodes modifiers from the start to current frame";
1199 "Calculate all selected objects instead of just the active object");
1204 ot->
name =
"Bake Simulation";
1205 ot->
description =
"Bake simulations in geometry nodes modifiers";
1213 RNA_def_boolean(ot->
srna,
"selected",
false,
"Selected",
"Bake cache on all selected objects");
1218 ot->
name =
"Delete Cached Simulation";
1219 ot->
description =
"Delete cached/baked simulations in geometry nodes modifiers";
1225 RNA_def_boolean(ot->
srna,
"selected",
false,
"Selected",
"Delete cache on all selected objects");
1237 "Name of the modifier that contains the node");
1244 ot->
name =
"Bake Geometry Node";
1245 ot->
description =
"Bake a single bake node or simulation";
1246 ot->
idname =
"OBJECT_OT_geometry_node_bake_single";
1258 ot->
name =
"Delete Geometry Node Bake";
1259 ot->
description =
"Delete baked data of a single bake node or simulation";
1260 ot->
idname =
"OBJECT_OT_geometry_node_bake_delete_single";
1270 ot->
name =
"Pack Geometry Node Bake";
1271 ot->
description =
"Pack baked data from disk into the .blend file";
1272 ot->
idname =
"OBJECT_OT_geometry_node_bake_pack_single";
1282 ot->
name =
"Unpack Geometry Node Bake";
1283 ot->
description =
"Unpack baked data from the .blend file to disk";
1284 ot->
idname =
"OBJECT_OT_geometry_node_bake_unpack_single";
1296 "Use bake from current directory (create when necessary)",
1301 "Write bake to current directory (overwrite existing bake)",
1306 "Use bake in original location (create when necessary)",
1311 "Write bake to original location (overwrite existing file)",
1313 {0,
nullptr, 0,
nullptr,
nullptr},
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define GEO_NODE_SIMULATION_OUTPUT
Functions and classes for evaluating template expressions in filepaths.
File and directory operations.
#define BLI_path_join(...)
#define NS_VIEW3D_SHADING
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
constexpr IndexRange()=default
const Value * lookup_ptr(const Key &key) const
Value & lookup_or_add_default(const Key &key)
Value lookup_default(const Key &key, const Value &default_value) const
auto add_or_modify(const Key &key, const CreateValueF &create_value, const ModifyValueF &modify_value) -> decltype(create_value(nullptr))
ItemIterator items() const &
Value & lookup_or_add(const Key &key, const Value &value)
constexpr const char * c_str() const
void append(const T &value)
int64_t written_size() const
const Map< std::string, OutputStream > & get_stream_by_name() const
constexpr int64_t size() const
constexpr const char * data() const
std::optional< NodesModifierBakeTarget > get_node_bake_target(const Object &object, const NodesModifierData &nmd, int node_id)
std::string get_default_modifier_bake_directory(const Main &bmain, const Object &object, const NodesModifierData &nmd)
std::optional< BakePath > get_node_bake_path(const Main &bmain, const Object &object, const NodesModifierData &nmd, int node_id)
std::optional< IndexRange > get_node_bake_frame_range(const Scene &scene, const Object &object, const NodesModifierData &nmd, int node_id)
UnpackGeometryNodesBakeResult unpack_geometry_nodes_bake(Main &bmain, ReportList *reports, Object &object, NodesModifierData &nmd, NodesModifierBake &bake, ePF_FileStatus how)
void serialize_bake(const BakeValues &bake_values, BlobWriter &blob_writer, BlobWriteSharing &blob_sharing, std::ostream &r_stream)
PackGeometryNodesBakeResult pack_geometry_nodes_bake(Main &bmain, ReportList *reports, Object &object, NodesModifierData &nmd, NodesModifierBake &bake)
UnpackGeometryNodesBakeResult
std::string frame_to_file_name(const SubFrame &frame)
std::optional< std::string > get_modifier_bake_path(const Main &bmain, const Object &object, const NodesModifierData &nmd)
void clear(T **items, int *items_num, int *active_index, void(*destruct_item)(T *))
void OBJECT_OT_simulation_nodes_cache_bake(wmOperatorType *ot)
static wmOperatorStatus bake_single_node_exec(bContext *C, wmOperator *op)
static void bake_geometry_nodes_startjob(void *customdata, wmJobWorkerStatus *worker_status)
static void clear_requested_bakes_in_modifier_cache(BakeGeometryNodesJob &job)
static void bake_geometry_nodes_endjob(void *customdata)
static void simulate_to_frame_endjob(void *customdata)
static void bake_simulation_validate_paths(bContext *C, wmOperator *op, const Span< Object * > objects)
static wmOperatorStatus unpack_single_bake_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus unpack_single_bake_exec(bContext *C, wmOperator *op)
static wmOperatorStatus bake_simulation_modal(bContext *C, wmOperator *, const wmEvent *)
static void simulate_to_frame_startjob(void *customdata, wmJobWorkerStatus *worker_status)
void OBJECT_OT_geometry_node_bake_delete_single(wmOperatorType *ot)
static wmOperatorStatus simulate_to_frame_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus bake_simulation_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus simulate_to_frame_modal(bContext *C, wmOperator *, const wmEvent *)
void OBJECT_OT_geometry_node_bake_unpack_single(wmOperatorType *ot)
static void single_bake_operator_props(wmOperatorType *ot)
void OBJECT_OT_geometry_node_bake_pack_single(wmOperatorType *ot)
static void initialize_modifier_bake_directory_if_necessary(bContext *C, Object &object, NodesModifierData &nmd, wmOperator *op)
static wmOperatorStatus delete_baked_simulation_exec(bContext *C, wmOperator *op)
static Vector< NodeBakeRequest > bake_simulation_gather_requests(bContext *C, wmOperator *op)
static wmOperatorStatus bake_single_node_modal(bContext *C, wmOperator *, const wmEvent *)
static PathUsersMap bake_simulation_get_path_users(bContext *C, const Span< Object * > objects)
static wmOperatorStatus bake_simulation_exec(bContext *C, wmOperator *op)
static bool may_have_disk_bake(const NodesModifierData &nmd)
void OBJECT_OT_geometry_node_bake_single(wmOperatorType *ot)
static wmOperatorStatus pack_single_bake_exec(bContext *C, wmOperator *op)
static bool bake_simulation_poll(bContext *C)
static bool simulate_to_frame_poll(bContext *C)
static wmOperatorStatus delete_single_bake_exec(bContext *C, wmOperator *op)
static Vector< NodeBakeRequest > collect_simulations_to_bake(Main &bmain, Scene &scene, const Span< Object * > objects)
static wmOperatorStatus bake_single_node_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void request_bakes_in_modifier_cache(BakeGeometryNodesJob &job)
void OBJECT_OT_simulation_nodes_cache_calculate_to_frame(wmOperatorType *ot)
static void reset_old_bake_cache(NodeBakeRequest &request)
static bool bake_directory_has_data(const StringRefNull absolute_bake_dir)
Map< std::string, int, default_inline_buffer_capacity(sizeof(std::string)), DefaultProbingStrategy, PathStringHash, PathStringEquality > PathUsersMap
static Vector< NodeBakeRequest > bake_single_node_gather_bake_request(bContext *C, wmOperator *op)
static wmOperatorStatus start_bake_job(bContext *C, Vector< NodeBakeRequest > requests, wmOperator *op, const BakeRequestsMode mode)
static void try_delete_bake(Main *bmain, Object &object, NodesModifierData &nmd, const int bake_id, ReportList *reports)
void OBJECT_OT_simulation_nodes_cache_delete(wmOperatorType *ot)
static void clear_data_block_references(NodesModifierBake &bake)
Object * context_active_object(const bContext *C)
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void popup_menu_reports(bContext *C, ReportList *reports) ATTR_NONNULL()
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void DEG_time_tag_update(Main *bmain)
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
unsigned __int64 uint64_t
ModifierData * BKE_modifiers_findby_name(const Object *ob, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void WM_jobs_callbacks(wmJob *wm_job, wm_jobs_start_callback startjob, void(*initjob)(void *), void(*update)(void *), void(*endjob)(void *))
void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop)
ID * WM_operator_properties_id_lookup_from_name_or_session_uid(Main *bmain, PointerRNA *ptr, const ID_Type type)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
@ OB_FLAG_USE_SIMULATION_CACHE
@ WM_JOB_TYPE_BAKE_GEOMETRY_NODES
@ WM_JOB_TYPE_CALCULATE_SIMULATION_NODES
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
wmWindow * CTX_wm_window(const bContext *C)
void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void(*free)(void *customdata))
void BLI_path_slash_native(char *path) ATTR_NONNULL(1)
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
void WM_locked_interface_set(wmWindowManager *wm, bool lock)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1)
std::string BKE_path_template_escape(StringRef text)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
BMesh const char void * data
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
@ NODES_MODIFIER_BAKE_MODE_STILL
wmWindowManager * CTX_wm_manager(const bContext *C)
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT const size_t num
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
bool ED_operator_object_active_editable(bContext *C)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void DEG_id_tag_update_for_side_effect_request(Depsgraph *depsgraph, ID *id, unsigned int flags)
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
@ NODES_MODIFIER_BAKE_TARGET_DISK
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
constexpr int64_t default_inline_buffer_capacity(size_t element_size)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
wmJob * WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, const eWM_JobFlag flag, const eWM_JobType job_type)
PythonProbingStrategy<> DefaultProbingStrategy
constexpr int64_t PACKED_FILE_MAX_SIZE
Scene * CTX_data_scene(const bContext *C)
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
void nodes_modifier_packed_bake_free(NodesModifierPackedBake *packed_bake)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
PackedFile * BKE_packedfile_new_from_memory(const void *mem, int memlen, const ImplicitSharingInfo *sharing_info=nullptr)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
Object * CTX_data_active_object(const bContext *C)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
void WM_jobs_timer(wmJob *wm_job, double time_step, uint note, uint endnote, void(*timer_step)(void *))
bool BLI_file_ensure_parent_dir_exists(const char *filepath) ATTR_NONNULL(1)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
NodesModifierBake * bakes
struct bNodeTree * node_group
NodesModifierBakeTarget bake_target
NodesModifierRuntime * runtime
NodesModifierBakeFile * blob_files
NodesModifierBakeFile * meta_files
std::shared_ptr< bke::bake::ModifierCache > cache
Map< int, std::unique_ptr< SimulationNodeCache > > simulation_cache_by_id
Map< int, std::unique_ptr< BakeNodeCache > > bake_cache_by_id
NodeBakeCache * get_node_bake_cache(const int id)
Vector< std::unique_ptr< FrameCache > > frames
std::string error_message
Vector< NodeBakeRequest > bake_requests
std::optional< bake::BakePath > path
std::unique_ptr< bake::BlobWriteSharing > blob_sharing
bool operator()(const StringRef a, const StringRef b) const
uint64_t operator()(const StringRef s) const
Vector< Object * > objects
void operator_context_set(wm::OpCallContext opcontext)
void op_enum(StringRefNull opname, StringRefNull propname, IDProperty *properties, wm::OpCallContext context, eUI_Item_Flag flag, const int active=-1)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
struct wmOperatorType * type