Blender V4.3
editlattice.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "MEM_guardedalloc.h"
10
11#include "DNA_curve_types.h"
12#include "DNA_key_types.h"
13#include "DNA_lattice_types.h"
14#include "DNA_listBase.h"
15#include "DNA_meshdata_types.h"
16#include "DNA_object_types.h"
17
18#include "BLI_listbase.h"
19#include "BLI_math_vector.h"
20
21#include "BKE_deform.hh"
22#include "BKE_key.hh"
23
24#include "BKE_editlattice.h" /* own include */
25
27{
28 Lattice *lt = static_cast<Lattice *>(ob->data);
29
30 if (lt->editlatt) {
31 Lattice *editlt = lt->editlatt->latt;
32
33 if (editlt->def) {
34 MEM_freeN(editlt->def);
35 }
36 if (editlt->dvert) {
37 BKE_defvert_array_free(editlt->dvert, editlt->pntsu * editlt->pntsv * editlt->pntsw);
38 }
39 MEM_freeN(editlt);
41
42 lt->editlatt = nullptr;
43 }
44}
45
47{
48 Lattice *lt = static_cast<Lattice *>(obedit->data);
49 KeyBlock *actkey;
50
52
53 actkey = BKE_keyblock_from_object(obedit);
54 if (actkey) {
56 }
57 lt->editlatt = static_cast<EditLatt *>(MEM_callocN(sizeof(EditLatt), "editlatt"));
58 lt->editlatt->latt = static_cast<Lattice *>(MEM_dupallocN(lt));
59 lt->editlatt->latt->def = static_cast<BPoint *>(MEM_dupallocN(lt->def));
60
61 if (lt->dvert) {
62 int tot = lt->pntsu * lt->pntsv * lt->pntsw;
63 lt->editlatt->latt->dvert = static_cast<MDeformVert *>(
64 MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert"));
66 }
67
68 if (lt->key) {
69 lt->editlatt->shapenr = obedit->shapenr;
70 }
71}
72
74{
75 Lattice *lt, *editlt;
76 KeyBlock *actkey;
77 BPoint *bp;
78 float *fp;
79 int tot;
80
81 lt = static_cast<Lattice *>(obedit->data);
82 editlt = lt->editlatt->latt;
83
84 MEM_freeN(lt->def);
85
86 lt->def = static_cast<BPoint *>(MEM_dupallocN(editlt->def));
87
88 lt->flag = editlt->flag;
89
90 lt->pntsu = editlt->pntsu;
91 lt->pntsv = editlt->pntsv;
92 lt->pntsw = editlt->pntsw;
93
94 lt->typeu = editlt->typeu;
95 lt->typev = editlt->typev;
96 lt->typew = editlt->typew;
97 lt->actbp = editlt->actbp;
98
99 lt->fu = editlt->fu;
100 lt->fv = editlt->fv;
101 lt->fw = editlt->fw;
102 lt->du = editlt->du;
103 lt->dv = editlt->dv;
104 lt->dw = editlt->dw;
105
106 if (lt->editlatt->shapenr) {
107 actkey = static_cast<KeyBlock *>(BLI_findlink(&lt->key->block, lt->editlatt->shapenr - 1));
108
109 /* active key: vertices */
110 tot = editlt->pntsu * editlt->pntsv * editlt->pntsw;
111
112 if (actkey->data) {
113 MEM_freeN(actkey->data);
114 }
115
116 fp = static_cast<float *>(actkey->data = MEM_callocN(lt->key->elemsize * tot, "actkey->data"));
117 actkey->totelem = tot;
118
119 bp = editlt->def;
120 while (tot--) {
121 copy_v3_v3(fp, bp->vec);
122 fp += 3;
123 bp++;
124 }
125 }
126
127 if (lt->dvert) {
128 BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
129 lt->dvert = nullptr;
130 }
131
132 if (editlt->dvert) {
133 tot = lt->pntsu * lt->pntsv * lt->pntsw;
134
135 lt->dvert = static_cast<MDeformVert *>(
136 MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert"));
137 BKE_defvert_array_copy(lt->dvert, editlt->dvert, tot);
138 }
139}
support for deformation groups and hooks.
void BKE_defvert_array_free(MDeformVert *dvert, int totvert)
Definition deform.cc:1066
void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert)
Definition deform.cc:1029
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1905
void BKE_keyblock_convert_to_lattice(const KeyBlock *kb, Lattice *lt)
Definition key.cc:2018
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE void copy_v3_v3(float r[3], const float a[3])
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
void BKE_editlattice_make(Object *obedit)
void BKE_editlattice_free(Object *ob)
void BKE_editlattice_load(Object *obedit)
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void *(* MEM_dupallocN)(const void *vmemh)
Definition mallocn.cc:39
float vec[4]
struct Lattice * latt
void * data
int elemsize
ListBase block
struct Key * key
struct MDeformVert * dvert
struct EditLatt * editlatt
struct BPoint * def