Cleanup: move DerivedMesh wrappers for modifiers further down the hierarchy

The main goal of this patch is to cleanup the interface of every modifier. More specifically the interface of modifiers should be DerivedMesh-free.
Internally some modifiers still use DerivedMesh. However I think it is better when the wrappers are in the modifiers so that higher level functions can use the simplified interface.

This patch removes the applyModifier_DM and applyModifierEM_DM functions. In a previous patch (rB3614d9d) the other functions that used DerivedMesh have been removed.

Reviewers: brecht
This commit is contained in:
Jacques Lucke 2018-09-20 12:04:17 +02:00
parent add8e1c018
commit b5dbe43d3e
11 changed files with 98 additions and 143 deletions

View File

@ -171,30 +171,8 @@ typedef struct ModifierTypeInfo {
/********************* Non-deform modifier functions *********************/ /* DEPRECATED */
/* For non-deform types: apply the modifier and return a derived
* data object (type is dependent on object type).
*
* The derivedData argument should always be non-NULL; the modifier
* should read the object data from the derived object instead of the
* actual object data.
*
* The modifier may reuse the derivedData argument (i.e. return it in
* modified form), but must not release it.
*/
struct DerivedMesh *(*applyModifier_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
struct DerivedMesh *derivedData);
/* Like applyModifier but called during editmode (for supporting
* modifiers).
*
* The derived object that is returned must support the operations that
* are expected from editmode objects. The same qualifications regarding
* derivedData apply as for applyModifier.
*/
struct DerivedMesh *(*applyModifierEM_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
struct BMEditMesh *editData,
struct DerivedMesh *derivedData);
void (*applyModifier_DM_removed)(void);
void (*applyModifierEM_DM_removed)(void);
/********************* Deform modifier functions *********************/
@ -464,6 +442,16 @@ void modwrap_deformVertsEM(
struct BMEditMesh *em, struct DerivedMesh *dm,
float (*vertexCos)[3], int numVerts);
#define applyModifier_DM_wrapper(NEW_FUNC_NAME, OLD_FUNC_NAME) \
static Mesh *NEW_FUNC_NAME(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) \
{ \
DerivedMesh *dm = CDDM_from_mesh_ex(mesh, CD_REFERENCE, CD_MASK_EVERYTHING); \
DerivedMesh *ndm = OLD_FUNC_NAME(md, ctx, dm); \
if (ndm != dm) dm->release(dm); \
DM_to_mesh(ndm, mesh, ctx->object, CD_MASK_EVERYTHING, true); \
return mesh; \
}
/* wrappers for modifier callbacks that accept Mesh and select the proper implementation
* depending on if the modifier has been ported to Mesh or is still using DerivedMesh
*/
@ -472,18 +460,10 @@ void modifier_deformVerts_ensure_normals(
struct ModifierData *md, const struct ModifierEvalContext *ctx,
struct Mesh *mesh, float (*vertexCos)[3], int numVerts);
struct Mesh *modifier_applyModifier(
struct ModifierData *md, const struct ModifierEvalContext *ctx,
struct Mesh *mesh);
struct Mesh *modifier_applyModifier_ensure_normals(
struct ModifierData *md, const struct ModifierEvalContext *ctx,
struct Mesh *mesh);
struct Mesh *modifier_applyModifierEM(
struct ModifierData *md, const struct ModifierEvalContext *ctx,
struct BMEditMesh *editData, struct Mesh *mesh);
/* depricated variants of above that accept DerivedMesh */
void modifier_deformVerts_DM_deprecated(

View File

@ -2655,7 +2655,7 @@ static void editbmesh_calc_modifiers(
mask &= ~CD_MASK_ORCO;
DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX);
if (mti->applyModifierEM || mti->applyModifierEM_DM) {
if (mti->applyModifierEM) {
ndm = modwrap_applyModifierEM(md, &mectx_orco, em, orcodm);
}
else {
@ -2683,7 +2683,7 @@ static void editbmesh_calc_modifiers(
}
}
if (mti->applyModifierEM || mti->applyModifierEM_DM)
if (mti->applyModifierEM)
ndm = modwrap_applyModifierEM(md, &mectx_cache, em, dm);
else
ndm = modwrap_applyModifier(md, &mectx_cache, dm);

View File

@ -1021,7 +1021,7 @@ static void curve_calc_modifiers_post(
vertCos = NULL;
}
mesh_applied = modifier_applyModifier(md, &mectx_apply, modified);
mesh_applied = mti->applyModifier(md, &mectx_apply, modified);
if (mesh_applied) {
/* Modifier returned a new derived mesh */

View File

@ -1172,7 +1172,7 @@ Mesh *BKE_mesh_create_derived_for_modifier(
if (build_shapekey_layers)
add_shapekey_layers(mesh_temp, me);
result = modifier_applyModifier(md, &mectx, mesh_temp);
result = mti->applyModifier(md, &mectx, mesh_temp);
ASSERT_IS_VALID_MESH(result);
if (mesh_temp != result) {

View File

@ -898,29 +898,6 @@ void modifier_deformVerts_ensure_normals(struct ModifierData *md, const Modifier
mti->deformVerts(md, ctx, mesh, vertexCos, numVerts);
}
struct Mesh *modifier_applyModifier(struct ModifierData *md, const ModifierEvalContext *ctx,
struct Mesh *mesh)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
if (mti->applyModifier) {
return mti->applyModifier(md, ctx, mesh);
}
else {
DerivedMesh *dm = CDDM_from_mesh_ex(mesh, CD_REFERENCE, CD_MASK_EVERYTHING);
DerivedMesh *ndm = mti->applyModifier_DM(md, ctx, dm);
if (ndm != dm) {
dm->release(dm);
}
DM_to_mesh(ndm, mesh, ctx->object, CD_MASK_EVERYTHING, true);
return mesh;
}
}
struct Mesh *modifier_applyModifier_ensure_normals(struct ModifierData *md, const ModifierEvalContext *ctx,
struct Mesh *mesh)
{
@ -930,31 +907,7 @@ struct Mesh *modifier_applyModifier_ensure_normals(struct ModifierData *md, cons
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
BKE_mesh_calc_normals(mesh);
}
return modifier_applyModifier(md, ctx, mesh);
}
struct Mesh *modifier_applyModifierEM(struct ModifierData *md, const ModifierEvalContext *ctx,
struct BMEditMesh *editData,
struct Mesh *mesh)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
if (mti->applyModifierEM) {
return mti->applyModifierEM(md, ctx, editData, mesh);
}
else {
DerivedMesh *dm = CDDM_from_mesh_ex(mesh, CD_REFERENCE, CD_MASK_EVERYTHING);
DerivedMesh *ndm = mti->applyModifierEM_DM(md, ctx, editData, dm);
if (ndm != dm) {
dm->release(dm);
}
DM_to_mesh(ndm, mesh, ctx->object, CD_MASK_EVERYTHING, true);
return mesh;
}
return mti->applyModifier(md, ctx, mesh);
}
/* depricated variants of above that accept DerivedMesh */
@ -1045,31 +998,27 @@ struct DerivedMesh *modifier_applyModifier_DM_deprecated(struct ModifierData *md
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
if (mti->applyModifier_DM) {
return mti->applyModifier_DM(md, ctx, dm);
/* TODO(sybren): deduplicate all the copies of this code in this file. */
Mesh *mesh = NULL;
if (dm != NULL) {
mesh = BKE_id_new_nomain(ID_ME, NULL);
DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
}
else {
/* TODO(sybren): deduplicate all the copies of this code in this file. */
Mesh *mesh = NULL;
if (dm != NULL) {
mesh = BKE_id_new_nomain(ID_ME, NULL);
DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
}
struct Mesh *new_mesh = mti->applyModifier(md, ctx, mesh);
struct Mesh *new_mesh = mti->applyModifier(md, ctx, mesh);
/* Make a DM that doesn't reference new_mesh so we can free the latter. */
DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE, CD_MASK_EVERYTHING);
/* Make a DM that doesn't reference new_mesh so we can free the latter. */
DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE, CD_MASK_EVERYTHING);
if (new_mesh != mesh) {
BKE_id_free(NULL, new_mesh);
}
if (mesh != NULL) {
BKE_id_free(NULL, mesh);
}
return ndm;
if (new_mesh != mesh) {
BKE_id_free(NULL, new_mesh);
}
if (mesh != NULL) {
BKE_id_free(NULL, mesh);
}
return ndm;
}
struct DerivedMesh *modifier_applyModifierEM_DM_deprecated(struct ModifierData *md, const ModifierEvalContext *ctx,
@ -1078,31 +1027,27 @@ struct DerivedMesh *modifier_applyModifierEM_DM_deprecated(struct ModifierData *
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
if (mti->applyModifierEM_DM) {
return mti->applyModifierEM_DM(md, ctx, editData, dm);
/* TODO(sybren): deduplicate all the copies of this code in this file. */
Mesh *mesh = NULL;
if (dm != NULL) {
mesh = BKE_id_new_nomain(ID_ME, NULL);
DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
}
else {
/* TODO(sybren): deduplicate all the copies of this code in this file. */
Mesh *mesh = NULL;
if (dm != NULL) {
mesh = BKE_id_new_nomain(ID_ME, NULL);
DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
}
struct Mesh *new_mesh = mti->applyModifierEM(md, ctx, editData, mesh);
struct Mesh *new_mesh = mti->applyModifierEM(md, ctx, editData, mesh);
/* Make a DM that doesn't reference new_mesh so we can free the latter. */
DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE, CD_MASK_EVERYTHING);
/* Make a DM that doesn't reference new_mesh so we can free the latter. */
DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE, CD_MASK_EVERYTHING);
if (new_mesh != mesh) {
BKE_id_free(NULL, new_mesh);
}
if (mesh != NULL) {
BKE_id_free(NULL, mesh);
}
return ndm;
if (new_mesh != mesh) {
BKE_id_free(NULL, new_mesh);
}
if (mesh != NULL) {
BKE_id_free(NULL, mesh);
}
return ndm;
}
/**

View File

@ -309,7 +309,10 @@ Mesh *get_multires_mesh(
.depsgraph = depsgraph,
.object = ob_eval,
.flag = MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY};
Mesh *result = modifier_applyModifier(&mmd->modifier, &modifier_ctx, deformed_mesh);
const ModifierTypeInfo *mti = modifierType_getInfo(mmd->modifier.type);
Mesh *result = mti->applyModifier(&mmd->modifier, &modifier_ctx, deformed_mesh);
if (result == deformed_mesh) {
result = BKE_mesh_copy_for_eval(deformed_mesh);
}

View File

@ -31,6 +31,7 @@
#include "DNA_object_types.h"
#include "DNA_object_force_types.h"
#include "DNA_scene_types.h"
#include "DNA_mesh_types.h"
#include "BLI_utildefines.h"
@ -100,7 +101,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
static DerivedMesh *applyModifier(
static DerivedMesh *applyModifier_DM(
ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *dm)
{
@ -114,6 +115,8 @@ static DerivedMesh *applyModifier(
return dm;
}
applyModifier_DM_wrapper(applyModifier, applyModifier_DM)
static bool is_brush_cb(Object *UNUSED(ob), ModifierData *pmd)
{
return ((DynamicPaintModifierData *)pmd)->brush != NULL;
@ -183,14 +186,14 @@ ModifierTypeInfo modifierType_DynamicPaint = {
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ applyModifier,
/* applyModifier_DM */ NULL,
/* applyModifierEM_DM */NULL,
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
/* initData */ initData,

View File

@ -36,6 +36,7 @@
#include "DNA_meshdata_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "BLI_utildefines.h"
#include "BLI_kdtree.h"
@ -998,7 +999,7 @@ static ParticleSystemModifierData *findPrecedingParticlesystem(Object *ob, Modif
}
return psmd;
}
static DerivedMesh *applyModifier(
static DerivedMesh *applyModifier_DM(
ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData)
{
@ -1048,6 +1049,8 @@ static DerivedMesh *applyModifier(
return derivedData;
}
applyModifier_DM_wrapper(applyModifier, applyModifier_DM)
ModifierTypeInfo modifierType_Explode = {
/* name */ "Explode",
@ -1061,14 +1064,14 @@ ModifierTypeInfo modifierType_Explode = {
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ applyModifier,
/* applyModifier_DM */ NULL,
/* applyModifierEM_DM */NULL,
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
/* initData */ initData,

View File

@ -67,7 +67,7 @@ static void initData(ModifierData *md)
mmd->quality = 3;
}
static DerivedMesh *applyModifier(
static DerivedMesh *applyModifier_DM(
ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *dm)
{
@ -144,6 +144,8 @@ static DerivedMesh *applyModifier(
return result;
}
applyModifier_DM_wrapper(applyModifier, applyModifier_DM)
#ifdef WITH_OPENSUBDIV_MODIFIER
/* Subdivide into fully qualified mesh. */
@ -261,7 +263,7 @@ ModifierTypeInfo modifierType_Multires = {
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ applyModifier,
/* applyModifier_DM */ NULL,
/* applyModifierEM_DM */NULL,
/* deformVerts */ NULL,
@ -271,7 +273,7 @@ ModifierTypeInfo modifierType_Multires = {
#ifdef WITH_OPENSUBDIV_MODIFIER
/* applyModifier */ applyModifier_subdiv,
#else
/* applyModifier */ NULL,
/* applyModifier */ applyModifier,
#endif
/* applyModifierEM */ NULL,

View File

@ -42,6 +42,7 @@
#include "DNA_scene_types.h"
#include "DNA_smoke_types.h"
#include "DNA_object_force_types.h"
#include "DNA_mesh_types.h"
#include "BLI_utildefines.h"
@ -104,7 +105,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
static DerivedMesh *applyModifier(
static DerivedMesh *applyModifier_DM(
ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *dm)
{
@ -118,6 +119,8 @@ static DerivedMesh *applyModifier(
return smokeModifier_do(smd, ctx->depsgraph, scene, ctx->object, dm);
}
applyModifier_DM_wrapper(applyModifier, applyModifier_DM)
static bool dependsOnTime(ModifierData *UNUSED(md))
{
return true;
@ -182,14 +185,14 @@ ModifierTypeInfo modifierType_Smoke = {
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ applyModifier,
/* applyModifier_DM */ NULL,
/* applyModifierEM_DM */NULL,
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
/* initData */ initData,

View File

@ -99,7 +99,7 @@ static bool isDisabled(const Scene *scene, ModifierData *md, bool useRenderParam
return get_render_subsurf_level(&scene->r, levels, useRenderParams != 0) == 0;
}
static DerivedMesh *applyModifier(
static DerivedMesh *applyModifier_DM(
ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData)
{
@ -133,7 +133,9 @@ static DerivedMesh *applyModifier(
return result;
}
static DerivedMesh *applyModifierEM(
applyModifier_DM_wrapper(applyModifier, applyModifier_DM)
static DerivedMesh *applyModifierEM_DM(
ModifierData *md, const ModifierEvalContext *ctx,
struct BMEditMesh *UNUSED(editData),
DerivedMesh *derivedData)
@ -148,6 +150,20 @@ static DerivedMesh *applyModifierEM(
return result;
}
static Mesh *applyModifierEM(
struct ModifierData *md, const struct ModifierEvalContext *ctx,
struct BMEditMesh *editData,
struct Mesh *mesh)
{
DerivedMesh *dm = CDDM_from_mesh_ex(mesh, CD_REFERENCE, CD_MASK_EVERYTHING);
DerivedMesh *ndm = applyModifierEM_DM(md, ctx, editData, dm);
if (ndm != dm) {
dm->release(dm);
}
DM_to_mesh(ndm, mesh, ctx->object, CD_MASK_EVERYTHING, true);
return mesh;
}
#ifdef WITH_OPENSUBDIV_MODIFIER
static int subdiv_levels_for_modifier_get(const SubsurfModifierData *smd,
const ModifierEvalContext *ctx)
@ -275,8 +291,8 @@ ModifierTypeInfo modifierType_Subsurf = {
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ applyModifier,
/* applyModifierEM_DM */applyModifierEM,
/* applyModifier_DM */ NULL,
/* applyModifierEM_DM */NULL,
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
@ -285,9 +301,9 @@ ModifierTypeInfo modifierType_Subsurf = {
#ifdef WITH_OPENSUBDIV_MODIFIER
/* applyModifier */ applyModifier_subdiv,
#else
/* applyModifier */ NULL,
/* applyModifier */ applyModifier,
#endif
/* applyModifierEM */ NULL,
/* applyModifierEM */ applyModifierEM,
/* initData */ initData,
/* requiredDataMask */ NULL,