diff options
author | Rohan Rathi <rohanrathi08@gmail.com> | 2018-07-21 16:59:15 +0300 |
---|---|---|
committer | Rohan Rathi <rohanrathi08@gmail.com> | 2018-07-21 16:59:15 +0300 |
commit | 4e6bcd10e559ab541df53a3d7b645faac1a7fe27 (patch) | |
tree | ba214c23868fe76ec5d2199b83846814bf79be25 /source/blender/modifiers/intern | |
parent | b6b185691f018f6b175ffb58c65418991cda75f2 (diff) | |
parent | e361e9e99c5b6140b6284e81fa315bdcc48cee58 (diff) |
Merge branch 'blender2.8' into soc-2018-bevel
Diffstat (limited to 'source/blender/modifiers/intern')
34 files changed, 279 insertions, 232 deletions
diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index 09ba865cce3..c44b65dffec 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -64,14 +64,14 @@ static void initData(ModifierData *md) amd->deformflag = ARM_DEF_VGROUP; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const ArmatureModifierData *amd = (const ArmatureModifierData *) md; #endif ArmatureModifierData *tamd = (ArmatureModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tamd->prevCos = NULL; } @@ -85,7 +85,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED( return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { ArmatureModifierData *amd = (ArmatureModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index 6cea7b8fece..db1078fa677 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -76,7 +76,7 @@ static void initData(ModifierData *md) bmd->double_threshold = 1e-6f; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { BooleanModifierData *bmd = (BooleanModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c index cd6cd709b1d..a0901b6d838 100644 --- a/source/blender/modifiers/intern/MOD_cast.c +++ b/source/blender/modifiers/intern/MOD_cast.c @@ -63,7 +63,7 @@ static void initData(ModifierData *md) cmd->object = NULL; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { CastModifierData *cmd = (CastModifierData *) md; short flag; diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 58979fa201b..53e71bfc1a4 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -42,6 +42,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "BKE_cloth.h" @@ -155,7 +156,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const ClothModifierData *clmd = (const ClothModifierData *) md; ClothModifierData *tclmd = (ClothModifierData *) target; @@ -170,14 +171,21 @@ static void copyData(const ModifierData *md, ModifierData *target) MEM_freeN(tclmd->coll_parms); BKE_ptcache_free_list(&tclmd->ptcaches); - tclmd->point_cache = NULL; + if (flag & LIB_ID_CREATE_NO_MAIN) { + /* Share the cache with the original object's modifier. */ + tclmd->modifier.flag |= eModifierFlag_SharedCaches; + tclmd->ptcaches = clmd->ptcaches; + tclmd->point_cache = clmd->point_cache; + } + else { + tclmd->point_cache = BKE_ptcache_add(&tclmd->ptcaches); + tclmd->point_cache->step = 1; + } tclmd->sim_parms = MEM_dupallocN(clmd->sim_parms); if (clmd->sim_parms->effector_weights) tclmd->sim_parms->effector_weights = MEM_dupallocN(clmd->sim_parms->effector_weights); tclmd->coll_parms = MEM_dupallocN(clmd->coll_parms); - tclmd->point_cache = BKE_ptcache_add(&tclmd->ptcaches); - tclmd->point_cache->step = 1; tclmd->clothObject = NULL; tclmd->hairdata = NULL; tclmd->solver_result = NULL; @@ -206,7 +214,12 @@ static void freeData(ModifierData *md) if (clmd->coll_parms) MEM_freeN(clmd->coll_parms); - BKE_ptcache_free_list(&clmd->ptcaches); + if (md->flag & eModifierFlag_SharedCaches) { + BLI_listbase_clear(&clmd->ptcaches); + } + else { + BKE_ptcache_free_list(&clmd->ptcaches); + } clmd->point_cache = NULL; if (clmd->hairdata) diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index 879b07de6d9..d59360896e8 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -80,12 +80,12 @@ static void initData(ModifierData *md) } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const CorrectiveSmoothModifierData *csmd = (const CorrectiveSmoothModifierData *)md; CorrectiveSmoothModifierData *tcsmd = (CorrectiveSmoothModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); if (csmd->bind_coords) { tcsmd->bind_coords = MEM_dupallocN(csmd->bind_coords); diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index e90ff939b68..b74b63e2478 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -71,7 +71,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, int UNUSED(userRenderParams)) +static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, bool UNUSED(userRenderParams)) { CurveModifierData *cmd = (CurveModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c index 8e025059d6c..ac45ce8732d 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.c +++ b/source/blender/modifiers/intern/MOD_datatransfer.c @@ -133,7 +133,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { DataTransferModifierData *dtmd = (DataTransferModifierData *) md; /* If no source object, bypass. */ diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index ac8fb91bc8d..1b8b7120058 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -138,7 +138,7 @@ static void foreachTexLink( walk(userData, ob, md, "texture"); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { DisplaceModifierData *dmd = (DisplaceModifierData *) md; return ((!dmd->texture && dmd->direction == MOD_DISP_DIR_RGB_XYZ) || dmd->strength == 0.0f); diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c index 9131bc0659f..61219096b43 100644 --- a/source/blender/modifiers/intern/MOD_dynamicpaint.c +++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c @@ -57,7 +57,7 @@ static void initData(ModifierData *md) pmd->type = MOD_DYNAMICPAINT_TYPE_CANVAS; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { const DynamicPaintModifierData *pmd = (const DynamicPaintModifierData *)md; DynamicPaintModifierData *tpmd = (DynamicPaintModifierData *)target; diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index 948aaf0751e..04bfe96bc59 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -70,14 +70,14 @@ static void freeData(ModifierData *md) MEM_SAFE_FREE(emd->facepa); } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const ExplodeModifierData *emd = (const ExplodeModifierData *) md; #endif ExplodeModifierData *temd = (ExplodeModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); temd->facepa = NULL; } diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c index ffa74be0b33..ebea7250d18 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim.c +++ b/source/blender/modifiers/intern/MOD_fluidsim.c @@ -33,14 +33,13 @@ */ +#include "DNA_mesh_types.h" #include "DNA_scene_types.h" #include "DNA_object_fluidsim_types.h" #include "DNA_object_types.h" #include "BLI_utildefines.h" - -#include "BKE_cdderivedmesh.h" #include "BKE_layer.h" #include "BKE_modifier.h" @@ -65,45 +64,49 @@ static void freeData(ModifierData *md) fluidsim_free(fluidmd); } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { const FluidsimModifierData *fluidmd = (const FluidsimModifierData *) md; FluidsimModifierData *tfluidmd = (FluidsimModifierData *) target; - if (fluidmd->fss) { - tfluidmd->fss = MEM_dupallocN(fluidmd->fss); - if (tfluidmd->fss && (tfluidmd->fss->meshVelocities != NULL)) { - tfluidmd->fss->meshVelocities = MEM_dupallocN(tfluidmd->fss->meshVelocities); - } + /* Free any FSS that was allocated in initData() */ + if (tfluidmd->fss) { + MEM_SAFE_FREE(tfluidmd->fss->meshVelocities); + MEM_freeN(tfluidmd->fss); } - /* Seems to never be used, but for sqke of consistency... */ - BLI_assert(fluidmd->point_cache == NULL); - BLI_assert(tfluidmd->point_cache == NULL); - tfluidmd->point_cache = NULL; + if (fluidmd->fss == NULL) { + tfluidmd->fss = NULL; + return; + } + + tfluidmd->fss = MEM_dupallocN(fluidmd->fss); + if (tfluidmd->fss->meshVelocities != NULL) { + tfluidmd->fss->meshVelocities = MEM_dupallocN(tfluidmd->fss->meshVelocities); + } } -static DerivedMesh *applyModifier( +static Mesh *applyModifier( ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *dm) + Mesh *mesh) { FluidsimModifierData *fluidmd = (FluidsimModifierData *) md; - DerivedMesh *result = NULL; + Mesh *result = NULL; /* check for alloc failing */ if (!fluidmd->fss) { initData(md); if (!fluidmd->fss) { - return dm; + return mesh; } } - result = fluidsimModifier_do(fluidmd, ctx, dm); + result = fluidsimModifier_do(fluidmd, ctx, mesh); - return result ? result : dm; + return result ? result : mesh; } static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) @@ -150,14 +153,14 @@ ModifierTypeInfo modifierType_Fluidsim = { /* 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, diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index cea9e69526c..44079163de5 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -47,8 +47,8 @@ #include "BLI_utildefines.h" #include "BKE_fluidsim.h" /* ensure definitions here match */ -#include "BKE_cdderivedmesh.h" #include "BKE_main.h" +#include "BKE_mesh.h" #ifdef WITH_MOD_FLUID # include "BKE_global.h" #endif @@ -160,22 +160,18 @@ void fluidsim_free(FluidsimModifierData *fluidmd) MEM_SAFE_FREE(fluidmd->fss); } - /* Seems to never be used, but for sqke of consistency... */ - BLI_assert(fluidmd->point_cache == NULL); - fluidmd->point_cache = NULL; - return; } #ifdef WITH_MOD_FLUID /* read .bobj.gz file into a fluidsimDerivedMesh struct */ -static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_example) +static Mesh *fluidsim_read_obj(const char *filename, const MPoly *mp_example) { int wri = 0, i; int gotBytes; gzFile gzf; int numverts = 0, numfaces = 0; - DerivedMesh *dm = NULL; + Mesh *mesh = NULL; MPoly *mp; MLoop *ml; MVert *mv; @@ -224,9 +220,9 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam return NULL; } - dm = CDDM_new(numverts, 0, 0, numfaces * 3, numfaces); + mesh = BKE_mesh_new_nomain(numverts, 0, 0, numfaces * 3, numfaces); - if (!dm) { + if (!mesh) { gzclose(gzf); return NULL; } @@ -235,7 +231,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam gotBytes = gzread(gzf, &wri, sizeof(wri)); /* read vertex position from file */ - mv = CDDM_get_verts(dm); + mv = mesh->mvert; for (i = 0; i < numverts; i++, mv++) gotBytes = gzread(gzf, mv->co, sizeof(float) * 3); @@ -243,16 +239,16 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam /* should be the same as numverts */ gotBytes = gzread(gzf, &wri, sizeof(wri)); if (wri != numverts) { - if (dm) - dm->release(dm); + if (mesh) + BKE_id_free(NULL, mesh); gzclose(gzf); return NULL; } normals = MEM_calloc_arrayN(numverts, 3 * sizeof(short), "fluid_tmp_normals"); if (!normals) { - if (dm) - dm->release(dm); + if (mesh) + BKE_id_free(NULL, mesh); gzclose(gzf); return NULL; } @@ -268,16 +264,16 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam if (wri != numfaces) { printf("Fluidsim: error in reading data from file.\n"); - if (dm) - dm->release(dm); + if (mesh) + BKE_id_free(NULL, mesh); gzclose(gzf); MEM_freeN(normals); return NULL; } /* read triangles from file */ - mp = CDDM_get_polys(dm); - ml = CDDM_get_loops(dm); + mp = mesh->mpoly; + ml = mesh->mloop; for (i = 0; i < numfaces; i++, mp++, ml += 3) { int face[3]; @@ -298,13 +294,12 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam gzclose(gzf); - CDDM_calc_edges(dm); - - CDDM_apply_vert_normals(dm, (short (*)[3])normals); + BKE_mesh_calc_edges(mesh, false, false); + BKE_mesh_apply_vert_normals(mesh, (short (*)[3])normals); MEM_freeN(normals); // CDDM_calc_normals(result); - return dm; + return mesh; } @@ -374,14 +369,14 @@ void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value) /* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */ -static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename) +static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, Mesh *mesh, char *filename) { int wri, i, j; float wrf; gzFile gzf; FluidsimSettings *fss = fluidmd->fss; int len = strlen(filename); - int totvert = dm->getNumVerts(dm); + int totvert = mesh->totvert; FluidVertexVelocity *velarray = NULL; /* mesh and vverts have to be valid from loading... */ @@ -395,7 +390,7 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * if (fss->domainNovecgen > 0) return; - fss->meshVelocities = MEM_calloc_arrayN(dm->getNumVerts(dm), sizeof(FluidVertexVelocity), "Fluidsim_velocities"); + fss->meshVelocities = MEM_calloc_arrayN(mesh->totvert, sizeof(FluidVertexVelocity), "Fluidsim_velocities"); fss->totvert = totvert; velarray = fss->meshVelocities; @@ -430,8 +425,8 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh * gzclose(gzf); } -static DerivedMesh *fluidsim_read_cache( - Object *ob, DerivedMesh *orgdm, +static Mesh *fluidsim_read_cache( + Object *ob, Mesh *orgmesh, FluidsimModifierData *fluidmd, int framenr, int useRenderParams) { int curFrame = framenr /* - 1 */ /*scene->r.sfra*/; /* start with 0 at start frame */ @@ -440,7 +435,7 @@ static DerivedMesh *fluidsim_read_cache( char targetFile[FILE_MAX]; FluidsimSettings *fss = fluidmd->fss; - DerivedMesh *dm = NULL; + Mesh *newmesh = NULL; MPoly *mpoly; MPoly mp_example = {0}; @@ -469,17 +464,17 @@ static DerivedMesh *fluidsim_read_cache( BLI_path_abs(targetFile, modifier_path_relbase_from_global(ob)); BLI_path_frame(targetFile, curFrame, 0); // fixed #frame-no - /* assign material + flags to new dm - * if there's no faces in original dm, keep materials and flags unchanged */ - mpoly = orgdm->getPolyArray(orgdm); + /* assign material + flags to new mesh. + * if there's no faces in original mesh, keep materials and flags unchanged */ + mpoly = orgmesh->mpoly; if (mpoly) { mp_example = *mpoly; } /* else leave NULL'd */ - dm = fluidsim_read_obj(targetFile, &mp_example); + newmesh = fluidsim_read_obj(targetFile, &mp_example); - if (!dm) { + if (!newmesh) { /* switch, abort background rendering when fluidsim mesh is missing */ const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp @@ -494,7 +489,7 @@ static DerivedMesh *fluidsim_read_cache( } } - /* display org. object upon failure which is in dm */ + /* display org. object upon failure which is in new mesh */ return NULL; } @@ -502,7 +497,7 @@ static DerivedMesh *fluidsim_read_cache( * TODO? use generate flag as loading flag as well? * warning, needs original .bobj.gz mesh loading filename */ if (displaymode == OB_FSDOM_FINAL) { - fluidsim_read_vel_cache(fluidmd, dm, targetFile); + fluidsim_read_vel_cache(fluidmd, newmesh, targetFile); } else { if (fss->meshVelocities) @@ -511,21 +506,21 @@ static DerivedMesh *fluidsim_read_cache( fss->meshVelocities = NULL; } - return dm; + return newmesh; } #endif // WITH_MOD_FLUID -DerivedMesh *fluidsimModifier_do( +Mesh *fluidsimModifier_do( FluidsimModifierData *fluidmd, const ModifierEvalContext *ctx, - DerivedMesh *dm) + Mesh *mesh) { #ifdef WITH_MOD_FLUID Object *ob = ctx->object; Depsgraph *depsgraph = ctx->depsgraph; const bool useRenderParams = (ctx->flag & MOD_APPLY_RENDER) != 0; // const bool isFinalCalc = (ctx->flag & MOD_APPLY_USECACHE) != 0; - DerivedMesh *result = NULL; + Mesh *result = NULL; int framenr; FluidsimSettings *fss = NULL; @@ -533,11 +528,11 @@ DerivedMesh *fluidsimModifier_do( /* only handle fluidsim domains */ if (fluidmd && fluidmd->fss && (fluidmd->fss->type != OB_FLUIDSIM_DOMAIN)) - return dm; + return mesh; /* sanity check */ if (!fluidmd || !fluidmd->fss) - return dm; + return mesh; fss = fluidmd->fss; @@ -552,15 +547,13 @@ DerivedMesh *fluidsimModifier_do( /* try to read from cache */ /* if the frame is there, fine, otherwise don't do anything */ - if ((result = fluidsim_read_cache(ob, dm, fluidmd, framenr, useRenderParams))) + if ((result = fluidsim_read_cache(ob, mesh, fluidmd, framenr, useRenderParams))) return result; - return dm; + return mesh; #else /* unused */ - (void)fluidmd; - (void)ctx; - (void)dm; + UNUSED_VARS(fluidmd, ctx, mesh); return NULL; #endif } diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.h b/source/blender/modifiers/intern/MOD_fluidsim_util.h index 0a0c8419a99..041a67eddbd 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.h +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.h @@ -36,16 +36,16 @@ struct Object; struct Scene; struct FluidsimModifierData; -struct DerivedMesh; +struct Mesh; struct ModifierEvalContext; /* new fluid-modifier interface */ void fluidsim_init(struct FluidsimModifierData *fluidmd); void fluidsim_free(struct FluidsimModifierData *fluidmd); -struct DerivedMesh *fluidsimModifier_do( +struct Mesh *fluidsimModifier_do( struct FluidsimModifierData *fluidmd, const struct ModifierEvalContext *ctx, - struct DerivedMesh *dm); + struct Mesh *dm); #endif diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index a5013bb38c6..a1629d8c1f2 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -63,12 +63,12 @@ static void initData(ModifierData *md) hmd->flag = 0; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const HookModifierData *hmd = (const HookModifierData *) md; HookModifierData *thmd = (HookModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); thmd->curfalloff = curvemapping_copy(hmd->curfalloff); @@ -96,7 +96,7 @@ static void freeData(ModifierData *md) MEM_SAFE_FREE(hmd->indexar); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { HookModifierData *hmd = (HookModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index e5b96c633f7..2406739e6df 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -704,18 +704,18 @@ static void initData(ModifierData *md) lmd->flag = 0; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const LaplacianDeformModifierData *lmd = (const LaplacianDeformModifierData *)md; LaplacianDeformModifierData *tlmd = (LaplacianDeformModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tlmd->vertexco = MEM_dupallocN(lmd->vertexco); tlmd->cache_system = NULL; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; if (lmd->anchor_grp_name[0]) return 0; diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c index 580de4b1572..19838a2b637 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c @@ -81,7 +81,7 @@ struct BLaplacianSystem { typedef struct BLaplacianSystem LaplacianSystem; static CustomDataMask required_data_mask(Object *ob, ModifierData *md); -static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, int useRenderParams); +static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, bool useRenderParams); static float compute_volume(const float center[3], float (*vertexCos)[3], const MPoly *mpoly, int numPolys, const MLoop *mloop); static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numPolys, int a_numLoops, int a_numVerts); static void delete_laplacian_system(LaplacianSystem *sys); @@ -474,7 +474,7 @@ static void init_data(ModifierData *md) smd->defgrp_name[0] = '\0'; } -static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool is_disabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { LaplacianSmoothModifierData *smd = (LaplacianSmoothModifierData *) md; short flag; diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c index 540876ac339..3acd39bf19d 100644 --- a/source/blender/modifiers/intern/MOD_lattice.c +++ b/source/blender/modifiers/intern/MOD_lattice.c @@ -67,7 +67,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(userRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(userRenderParams)) { LatticeModifierData *lmd = (LatticeModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c index 9d6dfc0e1eb..8d2ac001e2d 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.c +++ b/source/blender/modifiers/intern/MOD_meshcache.c @@ -72,7 +72,7 @@ static bool dependsOnTime(ModifierData *md) return (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { MeshCacheModifierData *mcmd = (MeshCacheModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index af37b30b7aa..9bfbbc4e44e 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -81,12 +81,12 @@ static void freeData(ModifierData *md) if (mmd->bindcos) MEM_freeN(mmd->bindcos); /* deprecated */ } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const MeshDeformModifierData *mmd = (const MeshDeformModifierData *) md; MeshDeformModifierData *tmmd = (MeshDeformModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); if (mmd->bindinfluences) tmmd->bindinfluences = MEM_dupallocN(mmd->bindinfluences); if (mmd->bindoffsets) tmmd->bindoffsets = MEM_dupallocN(mmd->bindoffsets); @@ -109,7 +109,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c index a6c9f865e4c..cef55bf467b 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.c +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c @@ -55,14 +55,14 @@ static void initData(ModifierData *md) mcmd->read_flag = MOD_MESHSEQ_READ_ALL; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const MeshSeqCacheModifierData *mcmd = (const MeshSeqCacheModifierData *)md; #endif MeshSeqCacheModifierData *tmcmd = (MeshSeqCacheModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tmcmd->reader = NULL; } @@ -79,7 +79,7 @@ static void freeData(ModifierData *md) } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_none.c b/source/blender/modifiers/intern/MOD_none.c index c973bd18830..7a6a5b94b8e 100644 --- a/source/blender/modifiers/intern/MOD_none.c +++ b/source/blender/modifiers/intern/MOD_none.c @@ -43,7 +43,7 @@ * no other functions will be called */ -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *UNUSED(md), int UNUSED(userRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *UNUSED(md), bool UNUSED(userRenderParams)) { return true; } diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c index ae67296dda7..14af389668c 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.c +++ b/source/blender/modifiers/intern/MOD_normal_edit.c @@ -524,7 +524,7 @@ static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, walk(userData, ob, &enmd->target, IDWALK_CB_NOP); } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { NormalEditModifierData *enmd = (NormalEditModifierData *)md; diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 702e557ccb1..12845b27166 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -31,6 +31,7 @@ #include "DNA_customdata_types.h" #include "DNA_object_types.h" +#include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "DNA_scene_types.h" @@ -40,9 +41,9 @@ #include "BLI_task.h" #include "BLI_utildefines.h" -#include "BKE_cdderivedmesh.h" #include "BKE_global.h" #include "BKE_main.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_ocean.h" @@ -60,38 +61,8 @@ static void init_cache_data(Object *ob, struct OceanModifierData *omd) omd->chop_amount, omd->foam_coverage, omd->foam_fade, omd->resolution); } -static void clear_cache_data(struct OceanModifierData *omd) -{ - BKE_ocean_free_cache(omd->oceancache); - omd->oceancache = NULL; - omd->cached = false; -} - -/* keep in sync with init_ocean_modifier_bake(), object_modifier.c */ -static void init_ocean_modifier(struct OceanModifierData *omd) -{ - int do_heightfield, do_chop, do_normals, do_jacobian; - - if (!omd || !omd->ocean) return; - - do_heightfield = true; - do_chop = (omd->chop_amount > 0); - do_normals = (omd->flag & MOD_OCEAN_GENERATE_NORMALS); - do_jacobian = (omd->flag & MOD_OCEAN_GENERATE_FOAM); - - BKE_ocean_free_data(omd->ocean); - BKE_ocean_init(omd->ocean, omd->resolution * omd->resolution, omd->resolution * omd->resolution, - omd->spatial_size, omd->spatial_size, - omd->wind_velocity, omd->smallest_wave, 1.0, omd->wave_direction, omd->damp, omd->wave_alignment, - omd->depth, omd->time, - do_heightfield, do_chop, do_normals, do_jacobian, - omd->seed); -} - static void simulate_ocean_modifier(struct OceanModifierData *omd) { - if (!omd || !omd->ocean) return; - BKE_ocean_simulate(omd->ocean, omd->time, omd->wave_scale, omd->chop_amount); } #endif /* WITH_OCEANSIM */ @@ -125,8 +96,6 @@ static void initData(ModifierData *md) omd->seed = 0; omd->time = 1.0; - omd->refresh = 0; - omd->size = 1.0; omd->repeat_x = 1; omd->repeat_y = 1; @@ -141,7 +110,7 @@ static void initData(ModifierData *md) omd->foamlayername[0] = '\0'; /* layer name empty by default */ omd->ocean = BKE_ocean_add(); - init_ocean_modifier(omd); + BKE_ocean_init_from_modifier(omd->ocean, omd); simulate_ocean_modifier(omd); #else /* WITH_OCEANSIM */ /* unused */ @@ -163,7 +132,7 @@ static void freeData(ModifierData *md) #endif /* WITH_OCEANSIM */ } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #ifdef WITH_OCEANSIM #if 0 @@ -171,21 +140,20 @@ static void copyData(const ModifierData *md, ModifierData *target) #endif OceanModifierData *tomd = (OceanModifierData *) target; - modifier_copyData_generic(md, target); - - tomd->refresh = 0; + modifier_copyData_generic(md, target, flag); - /* XXX todo: copy cache runtime too */ - tomd->cached = 0; + /* The oceancache object will be recreated for this copy + * automatically when cached=true */ tomd->oceancache = NULL; tomd->ocean = BKE_ocean_add(); - init_ocean_modifier(tomd); + BKE_ocean_init_from_modifier(tomd->ocean, tomd); simulate_ocean_modifier(tomd); #else /* WITH_OCEANSIM */ /* unused */ (void)md; (void)target; + (void)flag; #endif /* WITH_OCEANSIM */ } @@ -343,9 +311,9 @@ static void generate_ocean_geometry_uvs( } } -static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) +static Mesh *generate_ocean_geometry(OceanModifierData *omd) { - DerivedMesh *result; + Mesh *result; GenerateOceanGeometryData gogd; @@ -370,13 +338,13 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) gogd.sx /= gogd.rx; gogd.sy /= gogd.ry; - result = CDDM_new(num_verts, 0, 0, num_polys * 4, num_polys); + result = BKE_mesh_new_nomain(num_verts, 0, 0, num_polys * 4, num_polys); - gogd.mverts = CDDM_get_verts(result); - gogd.mpolys = CDDM_get_polys(result); - gogd.mloops = CDDM_get_loops(result); + gogd.mverts = result->mvert; + gogd.mpolys = result->mpoly; + gogd.mloops = result->mloop; - gogd.origindex = CustomData_get_layer(&result->polyData, CD_ORIGINDEX); + gogd.origindex = CustomData_get_layer(&result->pdata, CD_ORIGINDEX); ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -388,11 +356,11 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) /* create faces */ BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_polygons, &settings); - CDDM_calc_edges(result); + BKE_mesh_calc_edges(result, false, false); /* add uvs */ - if (CustomData_number_of_layers(&result->loopData, CD_MLOOPUV) < MAX_MTFACE) { - gogd.mloopuvs = CustomData_add_layer(&result->loopData, CD_MLOOPUV, CD_CALLOC, NULL, num_polys * 4); + if (CustomData_number_of_layers(&result->ldata, CD_MLOOPUV) < MAX_MTFACE) { + gogd.mloopuvs = CustomData_add_layer(&result->ldata, CD_MLOOPUV, CD_CALLOC, NULL, num_polys * 4); if (gogd.mloopuvs) { /* unlikely to fail */ gogd.ix = 1.0 / gogd.rx; @@ -402,24 +370,24 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd) } } - result->dirty |= DM_DIRTY_NORMALS; + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; return result; } -static DerivedMesh *doOcean( - ModifierData *md, Scene *scene, Object *ob, - DerivedMesh *derivedData, - int UNUSED(useRenderParams)) +static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) { OceanModifierData *omd = (OceanModifierData *) md; + int cfra_scene = (int)DEG_get_ctime(ctx->depsgraph); + Object *ob = ctx->object; + bool allocated_ocean = false; - DerivedMesh *dm = NULL; + Mesh *result = NULL; OceanResult ocr; MVert *mverts; - int cfra; + int cfra_for_cache; int i, j; /* use cached & inverted value for speed @@ -432,58 +400,57 @@ static DerivedMesh *doOcean( /* can happen in when size is small, avoid bad array lookups later and quit now */ if (!isfinite(size_co_inv)) { - return derivedData; + return mesh; } - /* update modifier */ - if (omd->refresh & MOD_OCEAN_REFRESH_ADD) { - omd->ocean = BKE_ocean_add(); - } - if (omd->refresh & MOD_OCEAN_REFRESH_RESET) { - init_ocean_modifier(omd); - } - if (omd->refresh & MOD_OCEAN_REFRESH_CLEAR_CACHE) { - clear_cache_data(omd); - } - omd->refresh = 0; - /* do ocean simulation */ if (omd->cached == true) { if (!omd->oceancache) { init_cache_data(ob, omd); } - BKE_ocean_simulate_cache(omd->oceancache, scene->r.cfra); + BKE_ocean_simulate_cache(omd->oceancache, cfra_scene); } else { + /* omd->ocean is NULL on an original object (in contrast to an evaluated one). + * We can create a new one, but we have to free it as well once we're done. + * This function is only called on an original object when applying the modifier + * using the 'Apply Modifier' button, and thus it is not called frequently for + * simulation. */ + allocated_ocean |= BKE_ocean_ensure(omd); simulate_ocean_modifier(omd); } if (omd->geometry_mode == MOD_OCEAN_GEOM_GENERATE) { - dm = generate_ocean_geometry(omd); - DM_ensure_normals(dm); + result = generate_ocean_geometry(omd); + BKE_mesh_ensure_normals(result); } else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) { - dm = CDDM_copy(derivedData); + BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, + LIB_ID_CREATE_NO_MAIN | + LIB_ID_CREATE_NO_USER_REFCOUNT | + LIB_ID_CREATE_NO_DEG_TAG | + LIB_ID_COPY_NO_PREVIEW, + false); } - cfra = scene->r.cfra; - CLAMP(cfra, omd->bakestart, omd->bakeend); - cfra -= omd->bakestart; /* shift to 0 based */ + cfra_for_cache = cfra_scene; + CLAMP(cfra_for_cache, omd->bakestart, omd->bakeend); + cfra_for_cache -= omd->bakestart; /* shift to 0 based */ - mverts = dm->getVertArray(dm); + mverts = result->mvert; /* add vcols before displacement - allows lookup based on position */ if (omd->flag & MOD_OCEAN_GENERATE_FOAM) { - if (CustomData_number_of_layers(&dm->loopData, CD_MLOOPCOL) < MAX_MCOL) { - const int num_polys = dm->getNumPolys(dm); - const int num_loops = dm->getNumLoops(dm); - MLoop *mloops = dm->getLoopArray(dm); + if (CustomData_number_of_layers(&result->ldata, CD_MLOOPCOL) < MAX_MCOL) { + const int num_polys = result->totpoly; + const int num_loops = result->totloop; + MLoop *mloops = result->mloop; MLoopCol *mloopcols = CustomData_add_layer_named( - &dm->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, num_loops, omd->foamlayername); + &result->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, num_loops, omd->foamlayername); if (mloopcols) { /* unlikely to fail */ - MPoly *mpolys = dm->getPolyArray(dm); + MPoly *mpolys = result->mpoly; MPoly *mp; for (i = 0, mp = mpolys; i < num_polys; i++, mp++) { @@ -497,7 +464,7 @@ static DerivedMesh *doOcean( float foam; if (omd->oceancache && omd->cached == true) { - BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v); + BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v); foam = ocr.foam; CLAMP(foam, 0.0f, 1.0f); } @@ -520,7 +487,7 @@ static DerivedMesh *doOcean( /* Note: tried to parallelized that one and previous foam loop, but gives 20% slower results... odd. */ { - const int num_verts = dm->getNumVerts(dm); + const int num_verts = result->totvert; for (i = 0; i < num_verts; i++) { float *vco = mverts[i].co; @@ -528,7 +495,7 @@ static DerivedMesh *doOcean( const float v = OCEAN_CO(size_co_inv, vco[1]); if (omd->oceancache && omd->cached == true) { - BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v); + BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v); } else { BKE_ocean_eval_uv(omd->ocean, &ocr, u, v); @@ -543,33 +510,32 @@ static DerivedMesh *doOcean( } } + if (allocated_ocean) { + BKE_ocean_free(omd->ocean); + omd->ocean = NULL; + } + #undef OCEAN_CO - return dm; + return result; } #else /* WITH_OCEANSIM */ -static DerivedMesh *doOcean( - ModifierData *UNUSED(md), Scene *UNUSED(scene), Object *UNUSED(ob), - DerivedMesh *derivedData, - int UNUSED(useRenderParams)) +static Mesh *doOcean(ModifierData *UNUSED(md), const ModifierEvalContext *UNUSED(ctx), Mesh *mesh) { - /* unused */ - return derivedData; + return mesh; } #endif /* WITH_OCEANSIM */ -static DerivedMesh *applyModifier( +static Mesh *applyModifier( ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *derivedData) + Mesh *mesh) { - DerivedMesh *result; - Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); - + Mesh *result; - result = doOcean(md, scene, ctx->object, derivedData, 0); + result = doOcean(md, ctx, mesh); - if (result != derivedData) - result->dirty |= DM_DIRTY_NORMALS; + if (result != mesh) + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; return result; } @@ -590,14 +556,14 @@ ModifierTypeInfo modifierType_Ocean = { /* deformVerts_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, diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index bb6ed8e8344..edafcd6fcb9 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -88,7 +88,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) } -static bool isDisabled(const struct Scene *scene, ModifierData *md, int useRenderParams) +static bool isDisabled(const struct Scene *scene, ModifierData *md, bool useRenderParams) { ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md; ParticleSystem *psys; diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c index 1821a0fced0..6f9a44cd9e6 100644 --- a/source/blender/modifiers/intern/MOD_particlesystem.c +++ b/source/blender/modifiers/intern/MOD_particlesystem.c @@ -79,14 +79,14 @@ static void freeData(ModifierData *md) psmd->psys->flag |= PSYS_DELETE; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const ParticleSystemModifierData *psmd = (const ParticleSystemModifierData *) md; #endif ParticleSystemModifierData *tpsmd = (ParticleSystemModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tpsmd->mesh_final = NULL; tpsmd->mesh_original = NULL; diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index 72c1c1552c7..5497673a52d 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -84,7 +84,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *) md; return !smd->target; diff --git a/source/blender/modifiers/intern/MOD_smoke.c b/source/blender/modifiers/intern/MOD_smoke.c index e81c760ed67..9a27f31adaa 100644 --- a/source/blender/modifiers/intern/MOD_smoke.c +++ b/source/blender/modifiers/intern/MOD_smoke.c @@ -71,7 +71,7 @@ static void initData(ModifierData *md) smd->time = -1; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag)) { const SmokeModifierData *smd = (const SmokeModifierData *)md; SmokeModifierData *tsmd = (SmokeModifierData *)target; diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 280a795fae8..29508524f9c 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -61,7 +61,7 @@ static void initData(ModifierData *md) smd->defgrp_name[0] = '\0'; } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { SmoothModifierData *smd = (SmoothModifierData *) md; short flag; diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index 3de04e878ac..08dc7c92693 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -35,8 +35,9 @@ #include <stddef.h> -#include "DNA_scene_types.h" #include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_mesh_types.h" #ifdef WITH_OPENSUBDIV # include "DNA_userdef_types.h" @@ -44,9 +45,9 @@ #include "BLI_utildefines.h" - #include "BKE_cdderivedmesh.h" #include "BKE_scene.h" +#include "BKE_subdiv.h" #include "BKE_subsurf.h" #include "DEG_depsgraph.h" @@ -56,6 +57,8 @@ #include "intern/CCGSubSurf.h" +// #define USE_OPENSUBDIV + static void initData(ModifierData *md) { SubsurfModifierData *smd = (SubsurfModifierData *) md; @@ -65,14 +68,14 @@ static void initData(ModifierData *md) smd->flags |= eSubsurfModifierFlag_SubsurfUv; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 const SubsurfModifierData *smd = (const SubsurfModifierData *) md; #endif SubsurfModifierData *tsmd = (SubsurfModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); tsmd->emCache = tsmd->mCache = NULL; } @@ -91,7 +94,7 @@ static void freeData(ModifierData *md) } } -static bool isDisabled(const Scene *scene, ModifierData *md, int useRenderParams) +static bool isDisabled(const Scene *scene, ModifierData *md, bool useRenderParams) { SubsurfModifierData *smd = (SubsurfModifierData *) md; int levels = (useRenderParams) ? smd->renderLevels : smd->levels; @@ -181,9 +184,74 @@ static DerivedMesh *applyModifierEM( #endif result = subsurf_make_derived_from_derived(derivedData, smd, scene, NULL, ss_flags); + return result; +} + +#ifdef USE_OPENSUBDIV +static int subdiv_levels_for_modifier_get(const SubsurfModifierData *smd, + const ModifierEvalContext *ctx) +{ + Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); + const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER); + const int requested_levels = (use_render_params) ? smd->renderLevels + : smd->levels; + return get_render_subsurf_level(&scene->r, + requested_levels, + use_render_params); +} + +static void subdiv_settings_init(SubdivSettings *settings, + const SubsurfModifierData *smd, + const ModifierEvalContext *ctx) +{ + settings->is_simple = (smd->subdivType == SUBSURF_TYPE_SIMPLE); + settings->is_adaptive = !settings->is_simple; + settings->level = subdiv_levels_for_modifier_get(smd, ctx); + settings->fvar_linear_interpolation = + (smd->flags & eSubsurfModifierFlag_SubsurfUv) + ? SUBDIV_FVAR_LINEAR_INTERPOLATION_CORNERS_ONLY + : SUBDIV_FVAR_LINEAR_INTERPOLATION_ALL; +} + +static void subdiv_mesh_settings_init(SubdivToMeshSettings *settings, + const SubdivSettings *subdiv_settings) +{ + settings->resolution = (1 << subdiv_settings->level) + 1; +} +static Mesh *applyModifier_subdiv(ModifierData *md, + const ModifierEvalContext *ctx, + Mesh *mesh) +{ + Mesh *result = mesh; + SubsurfModifierData *smd = (SubsurfModifierData *) md; + SubdivSettings subdiv_settings; + subdiv_settings_init(&subdiv_settings, smd, ctx); + if (subdiv_settings.level == 0) { + /* NOTE: Shouldn't really happen, is supposed to be catched by + * isDisabled() callback. + */ + return result; + } + /* TODO(sergey): Try to re-use subdiv when possible. */ + Subdiv *subdiv = BKE_subdiv_new_from_mesh(&subdiv_settings, mesh); + if (subdiv == NULL) { + /* Happens on bad topology. */ + /* TODO(sergey): This also happens on meshes without faces, so probably + * need to handle those differently (i.e. set modifier error when + * topology itself is bad, and not do anything when there are no faces). + */ + return result; + } + SubdivToMeshSettings mesh_settings; + subdiv_mesh_settings_init(&mesh_settings, &subdiv_settings); + result = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh); + /* TODO(sergey): Cache subdiv somehow. */ + // BKE_subdiv_stats_print(&subdiv->stats); + BKE_subdiv_free(subdiv); return result; } +#endif static bool dependsOnNormals(ModifierData *md) { @@ -222,7 +290,11 @@ ModifierTypeInfo modifierType_Subsurf = { /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, +#ifdef USE_OPENSUBDIV + /* applyModifier */ applyModifier_subdiv, +#else /* applyModifier */ NULL, +#endif /* applyModifierEM */ NULL, /* initData */ initData, diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index a3ab2d74602..6dbeed9b4c8 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -136,12 +136,12 @@ static void freeData(ModifierData *md) } } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const SurfaceDeformModifierData *smd = (const SurfaceDeformModifierData *)md; SurfaceDeformModifierData *tsmd = (SurfaceDeformModifierData *)target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); if (smd->verts) { tsmd->verts = MEM_dupallocN(smd->verts); @@ -1195,7 +1195,7 @@ static void deformVertsEM( surfacedeformModifier_do(md, ctx, vertexCos, numVerts, ctx->object); } -static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md; diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 54f8ce8c515..a8f305bcc13 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -65,12 +65,12 @@ static void initData(ModifierData *md) wmd->flag = 0; } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const WarpModifierData *wmd = (const WarpModifierData *) md; WarpModifierData *twmd = (WarpModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); twmd->curfalloff = curvemapping_copy(wmd->curfalloff); } @@ -109,7 +109,7 @@ static void freeData(ModifierData *md) } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(userRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(userRenderParams)) { WarpModifierData *wmd = (WarpModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index a26cb73d823..a34ed1baaff 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -81,12 +81,12 @@ static void freeData(ModifierData *md) curvemapping_free(wmd->cmap_curve); } -static void copyData(const ModifierData *md, ModifierData *target) +static void copyData(const ModifierData *md, ModifierData *target, const int flag) { const WeightVGEditModifierData *wmd = (const WeightVGEditModifierData *) md; WeightVGEditModifierData *twmd = (WeightVGEditModifierData *) target; - modifier_copyData_generic(md, target); + modifier_copyData_generic(md, target, flag); twmd->cmap_curve = curvemapping_copy(wmd->cmap_curve); } @@ -148,7 +148,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md; /* If no vertex group, bypass. */ diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 90bd5acff62..b6a7228b171 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -185,7 +185,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { WeightVGMixModifierData *wmd = (WeightVGMixModifierData *) md; /* If no vertex group, bypass. */ diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 88e33f28eaf..05b1ec19253 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -358,7 +358,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams)) +static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams)) { WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md; /* If no vertex group, bypass. */ |