diff options
Diffstat (limited to 'source/blender/blenkernel/intern/lattice.c')
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 161 |
1 files changed, 88 insertions, 73 deletions
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 1e99712f47a..0fa675639ea 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -53,7 +53,6 @@ #include "BKE_anim.h" #include "BKE_cdderivedmesh.h" #include "BKE_curve.h" -#include "BKE_depsgraph.h" #include "BKE_displist.h" #include "BKE_key.h" #include "BKE_lattice.h" @@ -66,10 +65,7 @@ #include "BKE_deform.h" -/* Workaround for cyclic dependency with curves. - * In such case curve_cache might not be ready yet, - */ -#define CYCLIC_DEPENDENCY_WORKAROUND +#include "DEG_depsgraph_query.h" int BKE_lattice_index_from_uvw(Lattice *lt, const int u, const int v, const int w) @@ -215,9 +211,9 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) /* works best if we force to linear type (endpoints match) */ lt->typeu = lt->typev = lt->typew = KEY_LINEAR; - /* prevent using deformed locations */ - if (ltOb->curve_cache != NULL) { - BKE_displist_free(<Ob->curve_cache->disp); + if (ltOb->runtime.curve_cache) { + /* prevent using deformed locations */ + BKE_displist_free(<Ob->runtime.curve_cache->disp); } copy_m4_m4(mat, ltOb->obmat); @@ -290,7 +286,7 @@ void BKE_lattice_copy_data(Main *bmain, Lattice *lt_dst, const Lattice *lt_src, { lt_dst->def = MEM_dupallocN(lt_src->def); - if (lt_src->key) { + if (lt_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) { BKE_id_copy_ex(bmain, <_src->key->id, (ID **)<_dst->key, flag, false); } @@ -306,7 +302,7 @@ void BKE_lattice_copy_data(Main *bmain, Lattice *lt_dst, const Lattice *lt_src, Lattice *BKE_lattice_copy(Main *bmain, const Lattice *lt) { Lattice *lt_copy; - BKE_id_copy_ex(bmain, <->id, (ID **)<_copy, 0, false); + BKE_id_copy_ex(bmain, <->id, (ID **)<_copy, LIB_ID_COPY_SHAPEKEY, false); return lt_copy; } @@ -315,6 +311,8 @@ void BKE_lattice_free(Lattice *lt) { BKE_animdata_free(<->id, false); + BKE_lattice_batch_cache_free(lt); + MEM_SAFE_FREE(lt->def); if (lt->dvert) { BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw); @@ -351,7 +349,7 @@ LatticeDeformData *init_latt_deform(Object *oblatt, Object *ob) /* we make an array with all differences */ Lattice *lt = oblatt->data; BPoint *bp; - DispList *dl = oblatt->curve_cache ? BKE_displist_find(&oblatt->curve_cache->disp, DL_VERTS) : NULL; + DispList *dl = oblatt->runtime.curve_cache ? BKE_displist_find(&oblatt->runtime.curve_cache->disp, DL_VERTS) : NULL; const float *co = dl ? dl->verts : NULL; float *fp, imat[4][4]; float fu, fv, fw; @@ -422,10 +420,11 @@ void calc_latt_deform(LatticeDeformData *lattice_deform_data, float co[3], float int defgrp_index = -1; float co_prev[3], weight_blend = 0.0f; MDeformVert *dvert = BKE_lattice_deform_verts_get(ob); + float *__restrict latticedata = lattice_deform_data->latticedata; if (lt->editlatt) lt = lt->editlatt->latt; - if (lattice_deform_data->latticedata == NULL) return; + if (latticedata == NULL) return; if (lt->vgroup[0] && dvert) { defgrp_index = defgroup_name_index(ob, lt->vgroup); @@ -506,7 +505,7 @@ void calc_latt_deform(LatticeDeformData *lattice_deform_data, float co[3], float idx_u = idx_v; } - madd_v3_v3fl(co, &lattice_deform_data->latticedata[idx_u * 3], u); + madd_v3_v3fl(co, &latticedata[idx_u * 3], u); if (defgrp_index != -1) weight_blend += (u * defvert_find_weight(dvert + idx_u, defgrp_index)); @@ -559,7 +558,7 @@ static bool where_on_path_deform(Object *ob, float ctime, float vec[4], float di int cycl = 0; /* test for cyclic */ - bl = ob->curve_cache->bev.first; + bl = ob->runtime.curve_cache->bev.first; if (!bl->nr) return false; if (bl->poly > -1) cycl = 1; @@ -574,7 +573,7 @@ static bool where_on_path_deform(Object *ob, float ctime, float vec[4], float di if (where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) { if (cycl == 0) { - Path *path = ob->curve_cache->path; + Path *path = ob->runtime.curve_cache->path; float dvec[3]; if (ctime < 0.0f) { @@ -603,7 +602,7 @@ static bool where_on_path_deform(Object *ob, float ctime, float vec[4], float di /* co: local coord, result local too */ /* returns quaternion for rotation, using cd->no_rot_axis */ /* axis is using another define!!! */ -static bool calc_curve_deform(Scene *scene, Object *par, float co[3], +static bool calc_curve_deform(Object *par, float co[3], const short axis, CurveDeform *cd, float r_quat[4]) { Curve *cu = par->data; @@ -611,14 +610,12 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3], short index; const bool is_neg_axis = (axis > 2); - /* to be sure, mostly after file load, also cyclic dependencies */ -#ifdef CYCLIC_DEPENDENCY_WORKAROUND - if (par->curve_cache == NULL) { - BKE_displist_make_curveTypes(scene, par, false); + if (par->runtime.curve_cache == NULL) { + /* Happens with a cyclic dependencies. */ + return false; } -#endif - if (par->curve_cache->path == NULL) { + if (par->runtime.curve_cache->path == NULL) { return false; /* happens on append, cyclic dependencies and empty curves */ } @@ -628,7 +625,7 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3], if (cu->flag & CU_STRETCH) fac = -(co[index] - cd->dmax[index]) / (cd->dmax[index] - cd->dmin[index]); else - fac = -(co[index] - cd->dmax[index]) / (par->curve_cache->path->totdist); + fac = -(co[index] - cd->dmax[index]) / (par->runtime.curve_cache->path->totdist); } else { index = axis; @@ -636,8 +633,8 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3], fac = (co[index] - cd->dmin[index]) / (cd->dmax[index] - cd->dmin[index]); } else { - if (LIKELY(par->curve_cache->path->totdist > FLT_EPSILON)) { - fac = +(co[index] - cd->dmin[index]) / (par->curve_cache->path->totdist); + if (LIKELY(par->runtime.curve_cache->path->totdist > FLT_EPSILON)) { + fac = +(co[index] - cd->dmin[index]) / (par->runtime.curve_cache->path->totdist); } else { fac = 0.0f; @@ -707,14 +704,12 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3], } void curve_deform_verts( - Scene *scene, Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3], - int numVerts, const char *vgroup, short defaxis) + Object *cuOb, Object *target, float (*vertexCos)[3], + int numVerts, MDeformVert *dvert, const int defgrp_index, short defaxis) { Curve *cu; int a; CurveDeform cd; - MDeformVert *dvert = NULL; - int defgrp_index = -1; const bool is_neg_axis = (defaxis > 2); if (cuOb->type != OB_CURVE) @@ -735,26 +730,6 @@ void curve_deform_verts( cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f; } - /* Check whether to use vertex groups (only possible if target is a Mesh or Lattice). - * We want either a Mesh/Lattice with no derived data, or derived data with deformverts. - */ - if (vgroup && vgroup[0] && ELEM(target->type, OB_MESH, OB_LATTICE)) { - defgrp_index = defgroup_name_index(target, vgroup); - - if (defgrp_index != -1) { - /* if there's derived data without deformverts, don't use vgroups */ - if (dm) { - dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); - } - else if (target->type == OB_LATTICE) { - dvert = ((Lattice *)target->data)->dvert; - } - else { - dvert = ((Mesh *)target->data)->dvert; - } - } - } - if (dvert) { MDeformVert *dvert_iter; float vec[3]; @@ -766,7 +741,7 @@ void curve_deform_verts( if (weight > 0.0f) { mul_m4_v3(cd.curvespace, vertexCos[a]); copy_v3_v3(vec, vertexCos[a]); - calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL); + calc_curve_deform(cuOb, vec, defaxis, &cd, NULL); interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight); mul_m4_v3(cd.objectspace, vertexCos[a]); } @@ -789,7 +764,7 @@ void curve_deform_verts( if (weight > 0.0f) { /* already in 'cd.curvespace', prev for loop */ copy_v3_v3(vec, vertexCos[a]); - calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL); + calc_curve_deform(cuOb, vec, defaxis, &cd, NULL); interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight); mul_m4_v3(cd.objectspace, vertexCos[a]); } @@ -800,7 +775,7 @@ void curve_deform_verts( if (cu->flag & CU_DEFORM_BOUNDS_OFF) { for (a = 0; a < numVerts; a++) { mul_m4_v3(cd.curvespace, vertexCos[a]); - calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL); + calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL); mul_m4_v3(cd.objectspace, vertexCos[a]); } } @@ -815,7 +790,7 @@ void curve_deform_verts( for (a = 0; a < numVerts; a++) { /* already in 'cd.curvespace', prev for loop */ - calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL); + calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL); mul_m4_v3(cd.objectspace, vertexCos[a]); } } @@ -825,7 +800,7 @@ void curve_deform_verts( /* input vec and orco = local coord in armature space */ /* orco is original not-animated or deformed reference point */ /* result written in vec and mat */ -void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, +void curve_deform_vector(Object *cuOb, Object *target, float orco[3], float vec[3], float mat[3][3], int no_rot_axis) { CurveDeform cd; @@ -844,7 +819,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, mul_m4_v3(cd.curvespace, vec); - if (calc_curve_deform(scene, cuOb, vec, target->trackflag, &cd, quat)) { + if (calc_curve_deform(cuOb, vec, target->trackflag, &cd, quat)) { float qmat[3][3]; quat_to_mat3(qmat, quat); @@ -857,7 +832,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, } -void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, +void lattice_deform_verts(Object *laOb, Object *target, Mesh *mesh, float (*vertexCos)[3], int numVerts, const char *vgroup, float fac) { LatticeDeformData *lattice_deform_data; @@ -878,8 +853,8 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, if (defgrp_index != -1) { /* if there's derived data without deformverts, don't use vgroups */ - if (dm) { - dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); + if (mesh) { + dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT); } else if (target->type == OB_LATTICE) { dvert = ((Lattice *)target->data)->dvert; @@ -1027,47 +1002,54 @@ void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]) } } -void BKE_lattice_modifiers_calc(Scene *scene, Object *ob) +void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob) { Lattice *lt = ob->data; + /* Get vertex coordinates from the original copy; otherwise we get already-modified coordinates. */ + Object *ob_orig = DEG_get_original_object(ob); VirtualModifierData virtualModifierData; ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData); float (*vertexCos)[3] = NULL; int numVerts, editmode = (lt->editlatt != NULL); + const ModifierEvalContext mectx = {depsgraph, ob, 0}; - if (ob->curve_cache) { - BKE_displist_free(&ob->curve_cache->disp); + if (ob->runtime.curve_cache) { + BKE_displist_free(&ob->runtime.curve_cache->disp); } else { - ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice"); + ob->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice"); } for (; md; md = md->next) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - md->scene = scene; - if (!(mti->flags & eModifierTypeFlag_AcceptsLattice)) continue; if (!(md->mode & eModifierMode_Realtime)) continue; if (editmode && !(md->mode & eModifierMode_Editmode)) continue; - if (mti->isDisabled && mti->isDisabled(md, 0)) continue; + if (mti->isDisabled && mti->isDisabled(scene, md, 0)) continue; if (mti->type != eModifierTypeType_OnlyDeform) continue; - if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts); - mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0); + if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob_orig, &numVerts); + mti->deformVerts(md, &mectx, NULL, vertexCos, numVerts); } - /* always displist to make this work like derivedmesh */ - if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts); + if (ob->id.tag & LIB_TAG_COPIED_ON_WRITE) { + if (vertexCos) { + BKE_lattice_vertexcos_apply(ob, vertexCos); + MEM_freeN(vertexCos); + } + } + else { + /* Displist won't do anything; this is just for posterity's sake until we remove it. */ + if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob_orig, &numVerts); - { DispList *dl = MEM_callocN(sizeof(*dl), "lt_dl"); dl->type = DL_VERTS; dl->parts = 1; dl->nr = numVerts; dl->verts = (float *) vertexCos; - BLI_addtail(&ob->curve_cache->disp, dl); + BLI_addtail(&ob->runtime.curve_cache->disp, dl); } } @@ -1141,7 +1123,7 @@ BoundBox *BKE_lattice_boundbox_get(Object *ob) void BKE_lattice_minmax_dl(Object *ob, Lattice *lt, float min[3], float max[3]) { - DispList *dl = ob->curve_cache ? BKE_displist_find(&ob->curve_cache->disp, DL_VERTS) : NULL; + DispList *dl = ob->runtime.curve_cache ? BKE_displist_find(&ob->runtime.curve_cache->disp, DL_VERTS) : NULL; if (!dl) { BKE_lattice_minmax(lt, min, max); @@ -1226,9 +1208,42 @@ void BKE_lattice_translate(Lattice *lt, float offset[3], bool do_keys) } } +bool BKE_lattice_is_any_selected(const Lattice *lt) +{ + /* Intentionally don't handle 'lt->editlatt' (caller must do this). */ + const BPoint *bp = lt->def; + int a = lt->pntsu * lt->pntsv * lt->pntsw; + while (a--) { + if (bp->hide == 0) { + if (bp->f1 & SELECT) { + return true; + } + } + bp++; + } + return false; +} + /* **** Depsgraph evaluation **** */ -void BKE_lattice_eval_geometry(EvaluationContext *UNUSED(eval_ctx), +void BKE_lattice_eval_geometry(struct Depsgraph *UNUSED(depsgraph), Lattice *UNUSED(latt)) { } + +/* Draw Engine */ +void (*BKE_lattice_batch_cache_dirty_tag_cb)(Lattice *lt, int mode) = NULL; +void (*BKE_lattice_batch_cache_free_cb)(Lattice *lt) = NULL; + +void BKE_lattice_batch_cache_dirty_tag(Lattice *lt, int mode) +{ + if (lt->batch_cache) { + BKE_lattice_batch_cache_dirty_tag_cb(lt, mode); + } +} +void BKE_lattice_batch_cache_free(Lattice *lt) +{ + if (lt->batch_cache) { + BKE_lattice_batch_cache_free_cb(lt); + } +} |