Files
test/source/blender/blenkernel/BKE_bake_items.hh
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

91 lines
2.0 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BKE_geometry_set.hh"
namespace blender::bke {
/**
* A "bake item" contains the baked data of e.g. one node socket at one frame. Typically, multiple
* bake items form the entire baked state for one frame.
*
* Bake items can be serialized. Also see `BKE_bake_items_serialize.hh`.
*/
class BakeItem {
public:
virtual ~BakeItem() = default;
};
class GeometryBakeItem : public BakeItem {
public:
GeometrySet geometry;
GeometryBakeItem(GeometrySet geometry);
/**
* Removes parts of the geometry that can't be stored in the simulation state:
* - Anonymous attributes can't be stored because it is not known which of them will or will not
* be used in the future.
* - Materials can't be stored directly, because they are linked ID data blocks that can't be
* restored from baked data currently.
*/
static void cleanup_geometry(GeometrySet &geometry);
};
/**
* References a field input/output that becomes an attribute as part of the simulation state.
* The attribute is actually stored in a #GeometryBakeItem, so this just references
* the attribute's name.
*/
class AttributeBakeItem : public BakeItem {
private:
std::string name_;
public:
AttributeBakeItem(std::string name) : name_(std::move(name)) {}
StringRefNull name() const
{
return name_;
}
};
/** Storage for a single value of a trivial type like `float`, `int`, etc. */
class PrimitiveBakeItem : public BakeItem {
private:
const CPPType &type_;
void *value_;
public:
PrimitiveBakeItem(const CPPType &type, const void *value);
~PrimitiveBakeItem();
const void *value() const
{
return value_;
}
const CPPType &type() const
{
return type_;
}
};
class StringBakeItem : public BakeItem {
private:
std::string value_;
public:
StringBakeItem(std::string value);
StringRefNull value() const
{
return value_;
}
};
} // namespace blender::bke