Refactor modifiers writing code.
This changes is needed to give more control to modifiers' writing callback when defined. It will allow to implement better culling of needless data when writing e.g. modifiers from library overrides. Ref. T97967. Reviewed By: brecht, JacquesLucke Differential Revision: https://developer.blender.org/D14939
This commit is contained in:
parent
f1beb3b3f6
commit
68d203af0b
Notes:
blender-bot
2023-02-13 15:30:03 +01:00
Referenced by issue #97967, LibOverride pulls heavy data modifier meshdeform
|
@ -364,7 +364,9 @@ typedef struct ModifierTypeInfo {
|
|||
* This method should write any additional arrays and referenced structs that should be
|
||||
* stored in the file.
|
||||
*/
|
||||
void (*blendWrite)(struct BlendWriter *writer, const struct ModifierData *md);
|
||||
void (*blendWrite)(struct BlendWriter *writer,
|
||||
const struct ID *id_owner,
|
||||
const struct ModifierData *md);
|
||||
|
||||
/**
|
||||
* Is called when the modifier is read from a file.
|
||||
|
@ -593,7 +595,9 @@ struct Mesh *BKE_modifier_get_evaluated_mesh_from_evaluated_object(struct Object
|
|||
|
||||
void BKE_modifier_check_uuids_unique_and_report(const struct Object *object);
|
||||
|
||||
void BKE_modifier_blend_write(struct BlendWriter *writer, struct ListBase *modbase);
|
||||
void BKE_modifier_blend_write(struct BlendWriter *writer,
|
||||
const struct ID *id_owner,
|
||||
struct ListBase *modbase);
|
||||
void BKE_modifier_blend_read_data(struct BlendDataReader *reader,
|
||||
struct ListBase *lb,
|
||||
struct Object *ob);
|
||||
|
|
|
@ -1067,7 +1067,7 @@ void BKE_modifier_check_uuids_unique_and_report(const Object *object)
|
|||
BLI_gset_free(used_uuids, NULL);
|
||||
}
|
||||
|
||||
void BKE_modifier_blend_write(BlendWriter *writer, ListBase *modbase)
|
||||
void BKE_modifier_blend_write(BlendWriter *writer, const ID *id_owner, ListBase *modbase)
|
||||
{
|
||||
if (modbase == NULL) {
|
||||
return;
|
||||
|
@ -1076,7 +1076,13 @@ void BKE_modifier_blend_write(BlendWriter *writer, ListBase *modbase)
|
|||
LISTBASE_FOREACH (ModifierData *, md, modbase) {
|
||||
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
||||
if (mti == NULL) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If the blendWrite callback is defined, it should handle the whole writing process. */
|
||||
if (mti->blendWrite != NULL) {
|
||||
mti->blendWrite(writer, id_owner, md);
|
||||
continue;
|
||||
}
|
||||
|
||||
BLO_write_struct_by_name(writer, mti->structName, md);
|
||||
|
@ -1162,10 +1168,6 @@ void BKE_modifier_blend_write(BlendWriter *writer, ListBase *modbase)
|
|||
writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (mti->blendWrite != NULL) {
|
||||
mti->blendWrite(writer, md);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -583,7 +583,7 @@ static void object_blend_write(BlendWriter *writer, ID *id, const void *id_addre
|
|||
}
|
||||
|
||||
BKE_particle_system_blend_write(writer, &ob->particlesystem);
|
||||
BKE_modifier_blend_write(writer, &ob->modifiers);
|
||||
BKE_modifier_blend_write(writer, &ob->id, &ob->modifiers);
|
||||
BKE_gpencil_modifier_blend_write(writer, &ob->greasepencil_modifiers);
|
||||
BKE_shaderfx_blend_write(writer, &ob->shader_fx);
|
||||
|
||||
|
|
|
@ -396,10 +396,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
region_type, "shading", "Shading", NULL, shading_panel_draw, panel_type);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const BevelModifierData *bmd = (const BevelModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, BevelModifierData, bmd);
|
||||
|
||||
if (bmd->custom_profile) {
|
||||
BKE_curveprofile_blend_write(writer, bmd->custom_profile);
|
||||
}
|
||||
|
|
|
@ -798,10 +798,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
modifier_panel_register(region_type, eModifierType_CorrectiveSmooth, panel_draw);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const CorrectiveSmoothModifierData *csmd = (const CorrectiveSmoothModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, CorrectiveSmoothModifierData, csmd);
|
||||
|
||||
if (csmd->bind_coords) {
|
||||
BLO_write_float3_array(writer, csmd->bind_coords_num, (float *)csmd->bind_coords);
|
||||
}
|
||||
|
|
|
@ -519,10 +519,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
region_type, "falloff", "Falloff", NULL, falloff_panel_draw, panel_type);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const HookModifierData *hmd = (const HookModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, HookModifierData, hmd);
|
||||
|
||||
if (hmd->curfalloff) {
|
||||
BKE_curvemapping_blend_write(writer, hmd->curfalloff);
|
||||
}
|
||||
|
|
|
@ -843,10 +843,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
modifier_panel_register(region_type, eModifierType_LaplacianDeform, panel_draw);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, LaplacianDeformModifierData, lmd);
|
||||
|
||||
BLO_write_float3_array(writer, lmd->verts_num, lmd->vertexco);
|
||||
}
|
||||
|
||||
|
|
|
@ -581,11 +581,13 @@ static void panelRegister(ARegionType *region_type)
|
|||
modifier_panel_register(region_type, eModifierType_MeshDeform, panel_draw);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
||||
int size = mmd->dyngridsize;
|
||||
|
||||
BLO_write_struct(writer, MeshDeformModifierData, mmd);
|
||||
|
||||
BLO_write_struct_array(writer, MDefInfluence, mmd->influences_num, mmd->bindinfluences);
|
||||
|
||||
/* NOTE: `bindoffset` is abusing `verts_num + 1` as its size, this becomes an incorrect value in
|
||||
|
|
|
@ -1729,9 +1729,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
panel_type);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
|
||||
|
||||
BLO_write_struct(writer, NodesModifierData, nmd);
|
||||
|
||||
if (nmd->settings.properties != nullptr) {
|
||||
/* Note that the property settings are based on the socket type info
|
||||
* and don't necessarily need to be written, but we can't just free them. */
|
||||
|
|
|
@ -1669,10 +1669,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
modifier_panel_register(region_type, eModifierType_SurfaceDeform, panel_draw);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const SurfaceDeformModifierData *smd = (const SurfaceDeformModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, SurfaceDeformModifierData, smd);
|
||||
|
||||
BLO_write_struct_array(writer, SDefVert, smd->bind_verts_num, smd->verts);
|
||||
|
||||
if (smd->verts) {
|
||||
|
|
|
@ -489,10 +489,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
region_type, "texture", "Texture", NULL, texture_panel_draw, panel_type);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const WarpModifierData *wmd = (const WarpModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, WarpModifierData, wmd);
|
||||
|
||||
if (wmd->curfalloff) {
|
||||
BKE_curvemapping_blend_write(writer, wmd->curfalloff);
|
||||
}
|
||||
|
|
|
@ -375,10 +375,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
region_type, "influence", "Influence", NULL, influence_panel_draw, panel_type);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const WeightVGEditModifierData *wmd = (const WeightVGEditModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, WeightVGEditModifierData, wmd);
|
||||
|
||||
if (wmd->cmap_curve) {
|
||||
BKE_curvemapping_blend_write(writer, wmd->cmap_curve);
|
||||
}
|
||||
|
|
|
@ -715,10 +715,12 @@ static void panelRegister(ARegionType *region_type)
|
|||
region_type, "influence", "Influence", NULL, influence_panel_draw, panel_type);
|
||||
}
|
||||
|
||||
static void blendWrite(BlendWriter *writer, const ModifierData *md)
|
||||
static void blendWrite(BlendWriter *writer, const ID *UNUSED(id_owner), const ModifierData *md)
|
||||
{
|
||||
const WeightVGProximityModifierData *wmd = (const WeightVGProximityModifierData *)md;
|
||||
|
||||
BLO_write_struct(writer, WeightVGProximityModifierData, wmd);
|
||||
|
||||
if (wmd->cmap_curve) {
|
||||
BKE_curvemapping_blend_write(writer, wmd->cmap_curve);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue