Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/lattice.c
| Show First 20 Lines • Show All 534 Lines • ▼ Show 20 Lines | void BKE_lattice_vert_coords_apply(Lattice *lt, const float (*vert_coords)[3]) | ||||
| const int vert_len = lt->pntsu * lt->pntsv * lt->pntsw; | const int vert_len = lt->pntsu * lt->pntsv * lt->pntsw; | ||||
| for (int i = 0; i < vert_len; i++) { | for (int i = 0; i < vert_len; i++) { | ||||
| copy_v3_v3(lt->def[i].vec, vert_coords[i]); | copy_v3_v3(lt->def[i].vec, vert_coords[i]); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob) | void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob) | ||||
| { | { | ||||
| BKE_object_free_derived_caches(ob); | |||||
| if (ob->runtime.curve_cache == NULL) { | |||||
| ob->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice"); | |||||
| } | |||||
| Lattice *lt = ob->data; | 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; | VirtualModifierData virtualModifierData; | ||||
| ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData); | ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData); | ||||
| float(*vert_coords)[3] = NULL; | float(*vert_coords)[3] = NULL; | ||||
| int numVerts; | int numVerts; | ||||
| const bool is_editmode = (lt->editlatt != NULL); | const bool is_editmode = (lt->editlatt != NULL); | ||||
| const ModifierEvalContext mectx = {depsgraph, ob, 0}; | const ModifierEvalContext mectx = {depsgraph, ob, 0}; | ||||
| if (ob->runtime.curve_cache) { | |||||
| BKE_displist_free(&ob->runtime.curve_cache->disp); | |||||
| } | |||||
| else { | |||||
| ob->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice"); | |||||
| } | |||||
| for (; md; md = md->next) { | for (; md; md = md->next) { | ||||
| const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); | const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); | ||||
| if (!(mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) { | if (!(mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!(md->mode & eModifierMode_Realtime)) { | if (!(md->mode & eModifierMode_Realtime)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (is_editmode && !(md->mode & eModifierMode_Editmode)) { | if (is_editmode && !(md->mode & eModifierMode_Editmode)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { | if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (mti->type != eModifierTypeType_OnlyDeform) { | if (mti->type != eModifierTypeType_OnlyDeform) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!vert_coords) { | if (vert_coords == NULL) { | ||||
| Lattice *lt_orig = ob_orig->data; | /* Get either the edit-mode or regular lattice, whichever is in use now. */ | ||||
| if (lt_orig->editlatt) { | const Lattice *effective_lattice = BKE_object_get_lattice(ob); | ||||
| lt_orig = lt_orig->editlatt->latt; | vert_coords = BKE_lattice_vert_coords_alloc(effective_lattice, &numVerts); | ||||
| } | |||||
| vert_coords = BKE_lattice_vert_coords_alloc(lt_orig, &numVerts); | |||||
| } | } | ||||
| mti->deformVerts(md, &mectx, NULL, vert_coords, numVerts); | mti->deformVerts(md, &mectx, NULL, vert_coords, numVerts); | ||||
| } | } | ||||
| if (ob->id.tag & LIB_TAG_COPIED_ON_WRITE) { | if (vert_coords == NULL) { | ||||
| if (vert_coords) { | return; | ||||
| BKE_lattice_vert_coords_apply(ob->data, vert_coords); | |||||
| MEM_freeN(vert_coords); | |||||
| } | |||||
| } | } | ||||
| else { | |||||
| /* Displist won't do anything; this is just for posterity's sake until we remove it. */ | |||||
| if (!vert_coords) { | |||||
| Lattice *lt_orig = ob_orig->data; | |||||
| if (lt_orig->editlatt) { | |||||
| lt_orig = lt_orig->editlatt->latt; | |||||
| } | |||||
| vert_coords = BKE_lattice_vert_coords_alloc(lt_orig, &numVerts); | |||||
| } | |||||
| DispList *dl = MEM_callocN(sizeof(*dl), "lt_dl"); | |||||
| dl->type = DL_VERTS; | |||||
| dl->parts = 1; | |||||
| dl->nr = numVerts; | |||||
| dl->verts = (float *)vert_coords; | |||||
| BLI_addtail(&ob->runtime.curve_cache->disp, dl); | Lattice *lt_eval = BKE_object_get_evaluated_lattice(ob); | ||||
| if (lt_eval == NULL) { | |||||
| BKE_id_copy_ex(NULL, <->id, (ID **)<_eval, LIB_ID_COPY_LOCALIZE); | |||||
| BKE_object_eval_assign_data(ob, <_eval->id, true); | |||||
| } | } | ||||
| BKE_lattice_vert_coords_apply(lt_eval, vert_coords); | |||||
| MEM_freeN(vert_coords); | |||||
| } | } | ||||
| struct MDeformVert *BKE_lattice_deform_verts_get(const struct Object *oblatt) | struct MDeformVert *BKE_lattice_deform_verts_get(const struct Object *oblatt) | ||||
| { | { | ||||
| Lattice *lt = (Lattice *)oblatt->data; | |||||
| BLI_assert(oblatt->type == OB_LATTICE); | BLI_assert(oblatt->type == OB_LATTICE); | ||||
| if (lt->editlatt) { | Lattice *lt = BKE_object_get_lattice(oblatt); | ||||
| lt = lt->editlatt->latt; | |||||
| } | |||||
| return lt->dvert; | return lt->dvert; | ||||
| } | } | ||||
| struct BPoint *BKE_lattice_active_point_get(Lattice *lt) | struct BPoint *BKE_lattice_active_point_get(Lattice *lt) | ||||
| { | { | ||||
| BLI_assert(GS(lt->id.name) == ID_LT); | BLI_assert(GS(lt->id.name) == ID_LT); | ||||
| if (lt->editlatt) { | if (lt->editlatt) { | ||||
| ▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines | |||||