Files
test2/source/blender/blenkernel/intern/bake_items.cc
Jacques Lucke 860196d5a1 Geometry Nodes: extract bake items from simulation baking
The goal is to reuse the same bake items for simulation and normal baking (#110137).
Previously, the bake data was tied to a simulation state which made it harder to reuse.

Now the code for the following things can be reused easily:
- Convert geometry node socket values into bake items and back.
- Serialize and deserialize bake items.

Pull Request: https://projects.blender.org/blender/blender/pulls/110577
2023-07-28 18:30:32 +02:00

77 lines
2.4 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_bake_items.hh"
#include "BKE_bake_items_serialize.hh"
#include "BKE_curves.hh"
#include "BKE_instances.hh"
#include "BKE_lib_id.h"
#include "BKE_mesh.hh"
#include "BKE_pointcloud.h"
#include "BLI_endian_defines.h"
#include "BLI_endian_switch.h"
#include "BLI_math_matrix_types.hh"
#include "BLI_path_util.h"
#include "DNA_material_types.h"
#include "RNA_access.h"
#include "RNA_enum_types.h"
namespace blender::bke {
using namespace io::serialize;
using DictionaryValuePtr = std::shared_ptr<DictionaryValue>;
GeometryBakeItem::GeometryBakeItem(GeometrySet geometry) : geometry(std::move(geometry)) {}
static void remove_materials(Material ***materials, short *materials_num)
{
MEM_SAFE_FREE(*materials);
*materials_num = 0;
}
void GeometryBakeItem::cleanup_geometry(GeometrySet &main_geometry)
{
main_geometry.ensure_owns_all_data();
main_geometry.modify_geometry_sets([&](GeometrySet &geometry) {
if (Mesh *mesh = geometry.get_mesh_for_write()) {
mesh->attributes_for_write().remove_anonymous();
remove_materials(&mesh->mat, &mesh->totcol);
}
if (Curves *curves = geometry.get_curves_for_write()) {
curves->geometry.wrap().attributes_for_write().remove_anonymous();
remove_materials(&curves->mat, &curves->totcol);
}
if (PointCloud *pointcloud = geometry.get_pointcloud_for_write()) {
pointcloud->attributes_for_write().remove_anonymous();
remove_materials(&pointcloud->mat, &pointcloud->totcol);
}
if (bke::Instances *instances = geometry.get_instances_for_write()) {
instances->attributes_for_write().remove_anonymous();
}
geometry.keep_only_during_modify({GeometryComponent::Type::Mesh,
GeometryComponent::Type::Curve,
GeometryComponent::Type::PointCloud,
GeometryComponent::Type::Instance});
});
}
PrimitiveBakeItem::PrimitiveBakeItem(const CPPType &type, const void *value) : type_(type)
{
value_ = MEM_mallocN_aligned(type.size(), type.alignment(), __func__);
type.copy_construct(value, value_);
}
PrimitiveBakeItem::~PrimitiveBakeItem()
{
type_.destruct(value_);
MEM_freeN(value_);
}
StringBakeItem::StringBakeItem(std::string value) : value_(std::move(value)) {}
} // namespace blender::bke