Simulation Nodes: bake simulation states to disk #106937

Merged
Jacques Lucke merged 116 commits from JacquesLucke/blender:sim-bake into geometry-nodes-simulation 2023-04-22 14:48:56 +02:00
1 changed files with 33 additions and 9 deletions
Showing only changes of commit 97c38b45a3 - Show all commits

View File

@ -308,19 +308,43 @@ static void load_attributes(const io::serialize::ArrayValue &io_attributes,
const eAttrDomain domain = get_domain_from_io_name(*domain_str);
const eCustomDataType data_type = get_data_type_from_io_name(*type_str);
bke::GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_only_span(
*name, domain, data_type);
if (!attribute) {
const CPPType *cpp_type = custom_data_type_to_cpp_type(data_type);
if (!cpp_type) {
continue;
}
const CPPType &cpp_type = attribute.span.type();
if (attributes.contains(*name)) {
bke::GSpanAttributeWriter attribute = attributes.lookup_or_add_for_write_only_span(
*name, domain, data_type);
if (!attribute) {
continue;
}
if (!read_bdata_simple_gspan(bdata_reader, *io_data, attribute.span)) {
cpp_type.value_initialize_n(attribute.span.data(), attribute.span.size());
if (!read_bdata_simple_gspan(bdata_reader, *io_data, attribute.span)) {
cpp_type->value_initialize_n(attribute.span.data(), attribute.span.size());
}
attribute.finish();
}
else {
const int domain_size = attributes.domain_size(domain);
const std::optional<BDataSharing::SharingInfoWithData> data = bdata_sharing.read_shared(
*io_data, [&]() {
void *data_mem = MEM_mallocN_aligned(
domain_size * cpp_type->size(), cpp_type->alignment(), __func__);
if (!read_bdata_simple_gspan(
bdata_reader, *io_data, {*cpp_type, data_mem, domain_size})) {
cpp_type->value_initialize_n(data_mem, domain_size);
}
return BDataSharing::SharingInfoWithData{implicit_sharing::info_for_mem_free(data_mem),
data_mem};
});
if (!data) {
continue;
}
attributes.add(
*name, domain, data_type, AttributeInitShared(data->data, *data->sharing_info));
data->sharing_info->remove_user_and_delete_if_last();
}
attribute.finish();
}
}