move modifier callback wrappers into modifier.c

This commit is contained in:
Campbell Barton 2013-06-19 08:00:20 +00:00
parent b375706935
commit d9ec2efe8f
3 changed files with 89 additions and 64 deletions

View File

@ -391,5 +391,30 @@ void modifier_mdef_compact_influences(struct ModifierData *md);
void modifier_path_init(char *path, int path_maxlen, const char *name);
const char *modifier_path_relbase(struct Object *ob);
/* wrappers for modifier callbacks */
struct DerivedMesh *modwrap_applyModifier(
ModifierData *md, struct Object *ob,
struct DerivedMesh *dm,
ModifierApplyFlag flag);
struct DerivedMesh *modwrap_applyModifierEM(
ModifierData *md, struct Object *ob,
struct BMEditMesh *em,
struct DerivedMesh *dm,
ModifierApplyFlag flag);
void modwrap_deformVerts(
ModifierData *md, struct Object *ob,
struct DerivedMesh *dm,
float (*vertexCos)[3], int numVerts,
ModifierApplyFlag flag);
void modwrap_deformVertsEM(
ModifierData *md, struct Object *ob,
struct BMEditMesh *em, struct DerivedMesh *dm,
float (*vertexCos)[3], int numVerts);
#endif

View File

@ -845,69 +845,6 @@ DerivedMesh *mesh_create_derived(Mesh *me, Object *ob, float (*vertCos)[3])
return dm;
}
/***/
/* wrapper around ModifierTypeInfo.applyModifier that ensures valid normals */
static DerivedMesh *modwrap_applyModifier(
ModifierData *md, Object *ob,
DerivedMesh *dm,
ModifierApplyFlag flag)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
return mti->applyModifier(md, ob, dm, flag);
}
static DerivedMesh *modwrap_applyModifierEM(
ModifierData *md, Object *ob,
BMEditMesh *em,
DerivedMesh *dm,
ModifierApplyFlag flag)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
return mti->applyModifierEM(md, ob, em, dm, flag);
}
static void modwrap_deformVerts(
ModifierData *md, Object *ob,
DerivedMesh *dm,
float (*vertexCos)[3], int numVerts,
ModifierApplyFlag flag)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(!dm || CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
mti->deformVerts(md, ob, dm, vertexCos, numVerts, flag);
}
static void modwrap_deformVertsEM(
ModifierData *md, Object *ob,
BMEditMesh *em, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(!dm || CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
mti->deformVertsEM(md, ob, em, dm, vertexCos, numVerts);
}
/* end modifier callback wrappers */
DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob,
ModifierData *md, int build_shapekey_layers)
{

View File

@ -36,7 +36,7 @@
* \ingroup bke
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
@ -60,6 +60,7 @@
#include "BKE_cloth.h"
#include "BKE_key.h"
#include "BKE_multires.h"
#include "BKE_DerivedMesh.h"
/* may move these, only for modifier_path_relbase */
#include "BKE_global.h" /* ugh, G.main->name only */
@ -693,3 +694,65 @@ void modifier_path_init(char *path, int path_maxlen, const char *name)
G.relbase_valid ? "//" : BLI_temporary_dir(),
name);
}
/* wrapper around ModifierTypeInfo.applyModifier that ensures valid normals */
struct DerivedMesh *modwrap_applyModifier(
ModifierData *md, Object *ob,
struct DerivedMesh *dm,
ModifierApplyFlag flag)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
return mti->applyModifier(md, ob, dm, flag);
}
struct DerivedMesh *modwrap_applyModifierEM(
ModifierData *md, Object *ob,
struct BMEditMesh *em,
DerivedMesh *dm,
ModifierApplyFlag flag)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
return mti->applyModifierEM(md, ob, em, dm, flag);
}
void modwrap_deformVerts(
ModifierData *md, Object *ob,
DerivedMesh *dm,
float (*vertexCos)[3], int numVerts,
ModifierApplyFlag flag)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(!dm || CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
mti->deformVerts(md, ob, dm, vertexCos, numVerts, flag);
}
void modwrap_deformVertsEM(
ModifierData *md, Object *ob,
struct BMEditMesh *em, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(!dm || CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
mti->deformVertsEM(md, ob, em, dm, vertexCos, numVerts);
}
/* end modifier callback wrappers */