Goals of the refactor: * Internal support for baking individual simulation zones (not exposed in the UI yet). * More well-defined access to simulation data in geometry nodes. Especially, it should be more obvious where data is modified. A similar approach should also work for the Bake node. Previously, there were a bunch of simulation specific properties in `GeoNodesModifierData` and then the simulation input and output nodes would have to figure out what to do with that data. Now, there is a new `GeoNodesSimulationParams` which controls the behavior of simulation zones. Contrary to before, different simulation zones can now be handled independently, even if that is not really used yet. `GeoNodesSimulationParams` has to be subclassed by a user of the geometry nodes API. The subclass controls what each simulation input and output node does. This some of the logic that was part of the node before, into the modifier. The way we store simulation data is "transposed". Previously, we stored zone data per frame, but now we store frame data per zone. This allows different zones to be more independent. Consequently, the way the simulation cache is accessed changed. I kept things simpler for now, avoiding many of the methods we had before, and directly accessing the data more often which is often simple enough. This change also makes it theoretically possible to store baked data for separate zones independently. A downside of this is, that existing baked data can't be read anymore. We don't really have compatibility guarantees for this format yet, so it's ok. Users will have to bake again. The bake folder for the modifier now contains an extra subfolder for every zone. Drawing the cached/baked frames in the timeline is less straight forward now. Currently, it just draws the state of one of the zones, which usually is identical to that of all other zones. This will change in the future though, and then the timeline drawing also needs some new UI work. Pull Request: https://projects.blender.org/blender/blender/pulls/111623
77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "BKE_bake_items_paths.hh"
|
|
|
|
#include "BLI_fileops.hh"
|
|
#include "BLI_path_util.h"
|
|
#include "BLI_string.h"
|
|
#include "BLI_string_utils.h"
|
|
|
|
namespace blender::bke::bake_paths {
|
|
|
|
std::string frame_to_file_name(const SubFrame &frame)
|
|
{
|
|
char file_name_c[FILE_MAX];
|
|
SNPRINTF(file_name_c, "%011.5f", double(frame));
|
|
BLI_string_replace_char(file_name_c, '.', '_');
|
|
return file_name_c;
|
|
}
|
|
|
|
std::optional<SubFrame> file_name_to_frame(const StringRefNull file_name)
|
|
{
|
|
char modified_file_name[FILE_MAX];
|
|
STRNCPY(modified_file_name, file_name.c_str());
|
|
BLI_string_replace_char(modified_file_name, '_', '.');
|
|
const SubFrame frame = std::stof(modified_file_name);
|
|
return frame;
|
|
}
|
|
|
|
Vector<MetaFile> find_sorted_meta_files(const StringRefNull meta_dir)
|
|
{
|
|
if (!BLI_is_dir(meta_dir.c_str())) {
|
|
return {};
|
|
}
|
|
|
|
direntry *dir_entries = nullptr;
|
|
const int dir_entries_num = BLI_filelist_dir_contents(meta_dir.c_str(), &dir_entries);
|
|
BLI_SCOPED_DEFER([&]() { BLI_filelist_free(dir_entries, dir_entries_num); });
|
|
|
|
Vector<MetaFile> meta_files;
|
|
for (const int i : IndexRange(dir_entries_num)) {
|
|
const direntry &dir_entry = dir_entries[i];
|
|
const StringRefNull dir_entry_path = dir_entry.path;
|
|
if (!dir_entry_path.endswith(".json")) {
|
|
continue;
|
|
}
|
|
const std::optional<SubFrame> frame = file_name_to_frame(dir_entry.relname);
|
|
if (!frame) {
|
|
continue;
|
|
}
|
|
meta_files.append({*frame, dir_entry_path});
|
|
}
|
|
|
|
std::sort(meta_files.begin(), meta_files.end(), [](const MetaFile &a, const MetaFile &b) {
|
|
return a.frame < b.frame;
|
|
});
|
|
|
|
return meta_files;
|
|
}
|
|
|
|
BakePath BakePath::from_single_root(StringRefNull root_dir)
|
|
{
|
|
char meta_dir[FILE_MAX];
|
|
BLI_path_join(meta_dir, sizeof(meta_dir), root_dir.c_str(), "meta");
|
|
char bdata_dir[FILE_MAX];
|
|
BLI_path_join(bdata_dir, sizeof(bdata_dir), root_dir.c_str(), "bdata");
|
|
|
|
BakePath bake_path;
|
|
bake_path.meta_dir = meta_dir;
|
|
bake_path.bdata_dir = bdata_dir;
|
|
bake_path.bake_dir = root_dir;
|
|
return bake_path;
|
|
}
|
|
|
|
} // namespace blender::bke::bake_paths
|