diff options
Diffstat (limited to 'source/blender/blenkernel/BKE_modifier.h')
-rw-r--r-- | source/blender/blenkernel/BKE_modifier.h | 205 |
1 files changed, 124 insertions, 81 deletions
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 2d39ac4d102..581b69619f2 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -33,11 +33,12 @@ #include "BKE_customdata.h" struct ID; +struct Depsgraph; struct DerivedMesh; -struct DagForest; -struct DagNode; +struct Mesh; struct Object; struct Scene; +struct ViewLayer; struct ListBase; struct bArmature; struct Main; @@ -118,27 +119,23 @@ typedef enum ModifierApplyFlag { MOD_APPLY_IGNORE_SIMPLIFY = 1 << 3, /* Ignore scene simplification flag and use subdivisions * level set in multires modifier. */ - MOD_APPLY_ALLOW_GPU = 1 << 4, /* Allow modifier to be applied and stored in the GPU. - * Used by the viewport in order to be able to have SS - * happening on GPU. - * Render pipeline (including viewport render) should - * have DM on the CPU. - */ } ModifierApplyFlag; - typedef struct ModifierUpdateDepsgraphContext { struct Scene *scene; struct Object *object; - - /* Old depsgraph node handle. */ - struct DagForest *forest; - struct DagNode *obNode; - - /* new depsgraph node handle. */ struct DepsNodeHandle *node; } ModifierUpdateDepsgraphContext; +/* Contains the information for deformXXX and applyXXX functions below that + * doesn't change between consecutive modifiers. */ +typedef struct ModifierEvalContext { + struct Depsgraph *depsgraph; + struct Object *object; + ModifierApplyFlag flag; +} ModifierEvalContext; + + typedef struct ModifierTypeInfo { /* The user visible name for this modifier */ char name[32]; @@ -159,73 +156,73 @@ typedef struct ModifierTypeInfo { /* Copy instance data for this modifier type. Should copy all user * level settings to the target modifier. + * + * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). */ - void (*copyData)(const struct ModifierData *md, struct ModifierData *target); + void (*copyData)(const struct ModifierData *md, struct ModifierData *target, const int flag); + + + /********************* Deform modifier functions *********************/ /* DEPRECATED */ + + void (*deformVerts_DM_removed)(void); + void (*deformMatrices_DM_removed)(void); + void (*deformVertsEM_DM_removed)(void); + void (*deformMatricesEM_DM_removed)(void); + + /********************* Non-deform modifier functions *********************/ /* DEPRECATED */ + + void (*applyModifier_DM_removed)(void); + void (*applyModifierEM_DM_removed)(void); /********************* Deform modifier functions *********************/ /* Only for deform types, should apply the deformation * to the given vertex array. If the deformer requires information from - * the object it can obtain it from the derivedData argument if non-NULL, + * the object it can obtain it from the mesh argument if non-NULL, * and otherwise the ob argument. */ - void (*deformVerts)(struct ModifierData *md, struct Object *ob, - struct DerivedMesh *derivedData, - float (*vertexCos)[3], int numVerts, - ModifierApplyFlag flag); + void (*deformVerts)(struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct Mesh *mesh, float (*vertexCos)[3], int numVerts); /* Like deformMatricesEM but called from object mode (for supporting modifiers in sculpt mode) */ - void (*deformMatrices)(struct ModifierData *md, struct Object *ob, - struct DerivedMesh *derivedData, - float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); + void (*deformMatrices)(struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct Mesh *mesh, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); /* Like deformVerts but called during editmode (for supporting modifiers) */ - void (*deformVertsEM)(struct ModifierData *md, struct Object *ob, - struct BMEditMesh *editData, struct DerivedMesh *derivedData, - float (*vertexCos)[3], int numVerts); + void (*deformVertsEM)(struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *editData, + struct Mesh *mesh, float (*vertexCos)[3], int numVerts); /* Set deform matrix per vertex for crazyspace correction */ - void (*deformMatricesEM)(struct ModifierData *md, struct Object *ob, - struct BMEditMesh *editData, struct DerivedMesh *derivedData, - float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); + void (*deformMatricesEM)(struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *editData, + struct Mesh *mesh, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); /********************* Non-deform modifier functions *********************/ - /* For non-deform types: apply the modifier and return a derived - * data object (type is dependent on object type). + /* For non-deform types: apply the modifier and return a mesh object. * - * The derivedData argument should always be non-NULL; the modifier - * should read the object data from the derived object instead of the + * The mesh argument should always be non-NULL; the modifier + * should read the object data from the mesh object instead of the * actual object data. * - * The useRenderParams argument indicates if the modifier is being - * applied in the service of the renderer which may alter quality - * settings. - * - * The isFinalCalc parameter indicates if the modifier is being - * calculated for a final result or for something temporary - * (like orcos). This is a hack at the moment, it is meant so subsurf - * can know if it is safe to reuse its internal cache. - * - * The modifier may reuse the derivedData argument (i.e. return it in + * The modifier may reuse the mesh argument (i.e. return it in * modified form), but must not release it. */ - struct DerivedMesh *(*applyModifier)(struct ModifierData *md, struct Object *ob, - struct DerivedMesh *derivedData, - ModifierApplyFlag flag); + struct Mesh *(*applyModifier)(struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct Mesh *mesh); /* Like applyModifier but called during editmode (for supporting * modifiers). * - * The derived object that is returned must support the operations that + * The mesh object that is returned must support the operations that * are expected from editmode objects. The same qualifications regarding - * derivedData apply as for applyModifier. + * mesh apply as for applyModifier. */ - struct DerivedMesh *(*applyModifierEM)(struct ModifierData *md, struct Object *ob, - struct BMEditMesh *editData, - struct DerivedMesh *derivedData, - ModifierApplyFlag flag); + struct Mesh *(*applyModifierEM)(struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *editData, + struct Mesh *mesh); /********************* Optional functions *********************/ @@ -270,21 +267,12 @@ typedef struct ModifierTypeInfo { * * This function is optional (assumes never disabled if not present). */ - bool (*isDisabled)(struct ModifierData *md, int userRenderParams); - - /* Add the appropriate relations to the DEP graph depending on the - * modifier data. - * - * This function is optional. - */ - void (*updateDepgraph)(struct ModifierData *md, - const ModifierUpdateDepsgraphContext *ctx); + bool (*isDisabled)(const struct Scene *scene, struct ModifierData *md, bool userRenderParams); /* Add the appropriate relations to the dependency graph. * * This function is optional. */ - /* TODO(sergey): Remove once we finally switched to the new depsgraph. */ void (*updateDepsgraph)(struct ModifierData *md, const ModifierUpdateDepsgraphContext *ctx); @@ -351,7 +339,7 @@ void modifier_free(struct ModifierData *md); bool modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md); -void modifier_copyData_generic(const struct ModifierData *md, struct ModifierData *target); +void modifier_copyData_generic(const struct ModifierData *md, struct ModifierData *target, const int flag); void modifier_copyData(struct ModifierData *md, struct ModifierData *target); void modifier_copyData_ex(struct ModifierData *md, struct ModifierData *target, const int flag); bool modifier_dependsOnTime(struct ModifierData *md); @@ -361,7 +349,7 @@ bool modifier_couldBeCage(struct Scene *scene, struct ModifierData *md) bool modifier_isCorrectableDeformed(struct ModifierData *md); bool modifier_isSameTopology(ModifierData *md); bool modifier_isNonGeometrical(ModifierData *md); -bool modifier_isEnabled(struct Scene *scene, struct ModifierData *md, int required_mode); +bool modifier_isEnabled(const struct Scene *scene, struct ModifierData *md, int required_mode); void modifier_setError(struct ModifierData *md, const char *format, ...) ATTR_PRINTF_FORMAT(2, 3); bool modifier_isPreview(struct ModifierData *md); @@ -387,6 +375,7 @@ bool modifiers_isClothEnabled(struct Object *ob); bool modifiers_isParticleEnabled(struct Object *ob); struct Object *modifiers_isDeformedByArmature(struct Object *ob); +struct Object *modifiers_isDeformedByMeshDeform(struct Object *ob); struct Object *modifiers_isDeformedByLattice(struct Object *ob); struct Object *modifiers_isDeformedByCurve(struct Object *ob); bool modifiers_usesArmature(struct Object *ob, struct bArmature *arm); @@ -433,28 +422,82 @@ void modifier_path_init(char *path, int path_maxlen, const char *name); const char *modifier_path_relbase(struct Main *bmain, struct Object *ob); const char *modifier_path_relbase_from_global(struct Object *ob); -/* wrappers for modifier callbacks */ +/* wrappers for modifier callbacks that ensure valid normals */ -struct DerivedMesh *modwrap_applyModifier( - ModifierData *md, struct Object *ob, - struct DerivedMesh *dm, - ModifierApplyFlag flag); +struct DerivedMesh *modwrap_applyModifier_DM_deprecated( + ModifierData *md, const struct ModifierEvalContext *ctx, + struct DerivedMesh *dm); +struct Mesh *modwrap_applyModifier( + ModifierData *md, const struct ModifierEvalContext *ctx, + struct Mesh *me); -struct DerivedMesh *modwrap_applyModifierEM( - ModifierData *md, struct Object *ob, - struct BMEditMesh *em, - struct DerivedMesh *dm, - ModifierApplyFlag flag); +struct DerivedMesh *modwrap_applyModifierEM_DM_deprecated( + ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *em, struct DerivedMesh *dm); +struct Mesh *modwrap_applyModifierEM( + ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *em, struct Mesh *me); -void modwrap_deformVerts( - ModifierData *md, struct Object *ob, +void modwrap_deformVerts_DM_deprecated( + ModifierData *md, const struct ModifierEvalContext *ctx, struct DerivedMesh *dm, - float (*vertexCos)[3], int numVerts, - ModifierApplyFlag flag); + float (*vertexCos)[3], int numVerts); +void modwrap_deformVerts( + ModifierData *md, const struct ModifierEvalContext *ctx, + struct Mesh *me, + float (*vertexCos)[3], int numVerts); -void modwrap_deformVertsEM( - ModifierData *md, struct Object *ob, +void modwrap_deformVertsEM_DM_deprecated( + ModifierData *md, const struct ModifierEvalContext *ctx, struct BMEditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts); +void modwrap_deformVertsEM( + ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *em, struct Mesh *me, + 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 + */ + +void modifier_deformVerts_DM_deprecated( + struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts); + +void modifier_deformMatrices_DM_deprecated( + struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct DerivedMesh *dm, + float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); + +void modifier_deformVertsEM_DM_deprecated( + struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *editData, struct DerivedMesh *dm, + float (*vertexCos)[3], int numVerts); + +void modifier_deformMatricesEM_DM_deprecated( + struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *editData, struct DerivedMesh *dm, + float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); + +struct DerivedMesh *modifier_applyModifier_DM_deprecated( + struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct DerivedMesh *dm); + +struct DerivedMesh *modifier_applyModifierEM_DM_deprecated( + struct ModifierData *md, const struct ModifierEvalContext *ctx, + struct BMEditMesh *editData, struct DerivedMesh *dm); + +struct Mesh *BKE_modifier_get_evaluated_mesh_from_evaluated_object( + struct Object *ob_eval, bool *r_free_mesh); #endif |