Modifiers: add ModifierTypeInfo::foreach_cache callback
This allows modifiers to have cache pointers that are preserved over undo steps. I intend to use this for the baked data cache for the geometry nodes modifier. Pull Request: https://projects.blender.org/blender/blender/pulls/117307
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
* \ingroup bke
|
||||
*/
|
||||
#include "BLI_compiler_attrs.h"
|
||||
#include "BLI_function_ref.hh"
|
||||
#include "BLI_math_matrix_types.hh"
|
||||
#include "BLI_span.hh"
|
||||
|
||||
@@ -33,6 +34,7 @@ struct ModifierData;
|
||||
struct Object;
|
||||
struct Scene;
|
||||
struct StructRNA;
|
||||
struct IDCacheKey;
|
||||
|
||||
enum class ModifierTypeType {
|
||||
/* Should not be used, only for None modifier type */
|
||||
@@ -381,6 +383,14 @@ struct ModifierTypeInfo {
|
||||
* not been written (e.g. runtime data) can be reset.
|
||||
*/
|
||||
void (*blend_read)(BlendDataReader *reader, ModifierData *md);
|
||||
|
||||
/**
|
||||
* Iterate over all cache pointers of given modifier. Also see #IDTypeInfo::foreach_cache.
|
||||
*/
|
||||
void (*foreach_cache)(
|
||||
Object *object,
|
||||
ModifierData *md,
|
||||
blender::FunctionRef<void(const IDCacheKey &cache_key, void **cache_p, uint flags)> fn);
|
||||
};
|
||||
|
||||
/* Used to set a modifier's panel type. */
|
||||
|
||||
@@ -587,6 +587,22 @@ static void object_foreach_path(ID *id, BPathForeachPathData *bpath_data)
|
||||
}
|
||||
}
|
||||
|
||||
static void object_foreach_cache(ID *id,
|
||||
IDTypeForeachCacheFunctionCallback function_callback,
|
||||
void *user_data)
|
||||
{
|
||||
Object *ob = reinterpret_cast<Object *>(id);
|
||||
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
|
||||
if (const ModifierTypeInfo *info = BKE_modifier_get_info(ModifierType(md->type))) {
|
||||
if (info->foreach_cache) {
|
||||
info->foreach_cache(ob, md, [&](const IDCacheKey &cache_key, void **cache_p, uint flags) {
|
||||
function_callback(id, &cache_key, cache_p, flags, user_data);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void object_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
Object *ob = (Object *)id;
|
||||
@@ -1069,7 +1085,7 @@ IDTypeInfo IDType_ID_OB = {
|
||||
/*free_data*/ object_free_data,
|
||||
/*make_local*/ nullptr,
|
||||
/*foreach_id*/ object_foreach_id,
|
||||
/*foreach_cache*/ nullptr,
|
||||
/*foreach_cache*/ object_foreach_cache,
|
||||
/*foreach_path*/ object_foreach_path,
|
||||
/*owner_pointer_get*/ nullptr,
|
||||
|
||||
|
||||
@@ -284,4 +284,5 @@ ModifierTypeInfo modifierType_Armature = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -1104,4 +1104,5 @@ ModifierTypeInfo modifierType_Array = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -444,4 +444,5 @@ ModifierTypeInfo modifierType_Bevel = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -702,4 +702,5 @@ ModifierTypeInfo modifierType_Boolean = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -329,4 +329,5 @@ ModifierTypeInfo modifierType_Build = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -541,4 +541,5 @@ ModifierTypeInfo modifierType_Cast = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -304,4 +304,5 @@ ModifierTypeInfo modifierType_Cloth = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -316,4 +316,5 @@ ModifierTypeInfo modifierType_Collision = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -858,4 +858,5 @@ ModifierTypeInfo modifierType_CorrectiveSmooth = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -222,4 +222,5 @@ ModifierTypeInfo modifierType_Curve = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -531,4 +531,5 @@ ModifierTypeInfo modifierType_DataTransfer = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -305,4 +305,5 @@ ModifierTypeInfo modifierType_Decimate = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -474,4 +474,5 @@ ModifierTypeInfo modifierType_Displace = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -223,4 +223,5 @@ ModifierTypeInfo modifierType_DynamicPaint = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -192,4 +192,5 @@ ModifierTypeInfo modifierType_EdgeSplit = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -1247,4 +1247,5 @@ ModifierTypeInfo modifierType_Explode = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -263,4 +263,5 @@ ModifierTypeInfo modifierType_Fluid = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -330,4 +330,5 @@ ModifierTypeInfo modifierType_GreasePencilOpacity = {
|
||||
/*panel_register*/ blender::panel_register,
|
||||
/*blend_write*/ blender::blend_write,
|
||||
/*blend_read*/ blender::blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -185,4 +185,5 @@ ModifierTypeInfo modifierType_GreasePencilSubdiv = {
|
||||
/*panel_register*/ blender::panel_register,
|
||||
/*blend_write*/ blender::blend_write,
|
||||
/*blend_read*/ blender::blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -574,4 +574,5 @@ ModifierTypeInfo modifierType_Hook = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -884,4 +884,5 @@ ModifierTypeInfo modifierType_LaplacianDeform = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -584,4 +584,5 @@ ModifierTypeInfo modifierType_LaplacianSmooth = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -195,4 +195,5 @@ ModifierTypeInfo modifierType_Lattice = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -830,4 +830,5 @@ ModifierTypeInfo modifierType_Mask = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -226,4 +226,5 @@ ModifierTypeInfo modifierType_MeshToVolume = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -407,4 +407,5 @@ ModifierTypeInfo modifierType_MeshCache = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -648,4 +648,5 @@ ModifierTypeInfo modifierType_MeshDeform = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -462,4 +462,5 @@ ModifierTypeInfo modifierType_MeshSequenceCache = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -270,4 +270,5 @@ ModifierTypeInfo modifierType_Mirror = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -513,4 +513,5 @@ ModifierTypeInfo modifierType_Multires = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -2294,4 +2294,5 @@ ModifierTypeInfo modifierType_Nodes = {
|
||||
/*panel_register*/ blender::panel_register,
|
||||
/*blend_write*/ blender::blend_write,
|
||||
/*blend_read*/ blender::blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -55,4 +55,5 @@ ModifierTypeInfo modifierType_None = {
|
||||
/*panel_register*/ nullptr,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -749,4 +749,5 @@ ModifierTypeInfo modifierType_NormalEdit = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -723,4 +723,5 @@ ModifierTypeInfo modifierType_Ocean = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -670,4 +670,5 @@ ModifierTypeInfo modifierType_ParticleInstance = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -296,4 +296,5 @@ ModifierTypeInfo modifierType_ParticleSystem = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -294,4 +294,5 @@ ModifierTypeInfo modifierType_Remesh = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -1174,4 +1174,5 @@ ModifierTypeInfo modifierType_Screw = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -136,4 +136,5 @@ ModifierTypeInfo modifierType_ShapeKey = {
|
||||
/*panel_register*/ nullptr,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -243,4 +243,5 @@ ModifierTypeInfo modifierType_Shrinkwrap = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -564,4 +564,5 @@ ModifierTypeInfo modifierType_SimpleDeform = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -2101,4 +2101,5 @@ ModifierTypeInfo modifierType_Skin = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -248,4 +248,5 @@ ModifierTypeInfo modifierType_Smooth = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -123,4 +123,5 @@ ModifierTypeInfo modifierType_Softbody = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -296,4 +296,5 @@ ModifierTypeInfo modifierType_Solidify = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -517,4 +517,5 @@ ModifierTypeInfo modifierType_Subsurf = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -234,4 +234,5 @@ ModifierTypeInfo modifierType_Surface = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -1745,4 +1745,5 @@ ModifierTypeInfo modifierType_SurfaceDeform = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -162,4 +162,5 @@ ModifierTypeInfo modifierType_Triangulate = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -381,4 +381,5 @@ ModifierTypeInfo modifierType_UVProject = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -337,4 +337,5 @@ ModifierTypeInfo modifierType_UVWarp = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -345,4 +345,5 @@ ModifierTypeInfo modifierType_VolumeDisplace = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -229,4 +229,5 @@ ModifierTypeInfo modifierType_VolumeToMesh = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -503,4 +503,5 @@ ModifierTypeInfo modifierType_Warp = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -452,4 +452,5 @@ ModifierTypeInfo modifierType_Wave = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -664,4 +664,5 @@ ModifierTypeInfo modifierType_WeightedNormal = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -420,4 +420,5 @@ ModifierTypeInfo modifierType_WeightVGEdit = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -520,4 +520,5 @@ ModifierTypeInfo modifierType_WeightVGMix = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -765,4 +765,5 @@ ModifierTypeInfo modifierType_WeightVGProximity = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ blend_write,
|
||||
/*blend_read*/ blend_read,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -214,4 +214,5 @@ ModifierTypeInfo modifierType_Weld = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
@@ -196,4 +196,5 @@ ModifierTypeInfo modifierType_Wireframe = {
|
||||
/*panel_register*/ panel_register,
|
||||
/*blend_write*/ nullptr,
|
||||
/*blend_read*/ nullptr,
|
||||
/*foreach_cache*/ nullptr,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user