Blender  V3.3
editlattice.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "MEM_guardedalloc.h"
8 
9 #include "DNA_curve_types.h"
10 #include "DNA_key_types.h"
11 #include "DNA_lattice_types.h"
12 #include "DNA_listBase.h"
13 #include "DNA_meshdata_types.h"
14 #include "DNA_object_types.h"
15 
16 #include "BLI_listbase.h"
17 #include "BLI_math_vector.h"
18 
19 #include "BKE_deform.h"
20 #include "BKE_key.h"
21 
22 #include "BKE_editlattice.h" /* own include */
23 
25 {
26  Lattice *lt = ob->data;
27 
28  if (lt->editlatt) {
29  Lattice *editlt = lt->editlatt->latt;
30 
31  if (editlt->def) {
32  MEM_freeN(editlt->def);
33  }
34  if (editlt->dvert) {
35  BKE_defvert_array_free(editlt->dvert, editlt->pntsu * editlt->pntsv * editlt->pntsw);
36  }
37  MEM_freeN(editlt);
38  MEM_freeN(lt->editlatt);
39 
40  lt->editlatt = NULL;
41  }
42 }
43 
45 {
46  Lattice *lt = obedit->data;
47  KeyBlock *actkey;
48 
49  BKE_editlattice_free(obedit);
50 
51  actkey = BKE_keyblock_from_object(obedit);
52  if (actkey) {
54  }
55  lt->editlatt = MEM_callocN(sizeof(EditLatt), "editlatt");
56  lt->editlatt->latt = MEM_dupallocN(lt);
57  lt->editlatt->latt->def = MEM_dupallocN(lt->def);
58 
59  if (lt->dvert) {
60  int tot = lt->pntsu * lt->pntsv * lt->pntsw;
61  lt->editlatt->latt->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
63  }
64 
65  if (lt->key) {
66  lt->editlatt->shapenr = obedit->shapenr;
67  }
68 }
69 
71 {
72  Lattice *lt, *editlt;
73  KeyBlock *actkey;
74  BPoint *bp;
75  float *fp;
76  int tot;
77 
78  lt = obedit->data;
79  editlt = lt->editlatt->latt;
80 
81  MEM_freeN(lt->def);
82 
83  lt->def = MEM_dupallocN(editlt->def);
84 
85  lt->flag = editlt->flag;
86 
87  lt->pntsu = editlt->pntsu;
88  lt->pntsv = editlt->pntsv;
89  lt->pntsw = editlt->pntsw;
90 
91  lt->typeu = editlt->typeu;
92  lt->typev = editlt->typev;
93  lt->typew = editlt->typew;
94  lt->actbp = editlt->actbp;
95 
96  lt->fu = editlt->fu;
97  lt->fv = editlt->fv;
98  lt->fw = editlt->fw;
99  lt->du = editlt->du;
100  lt->dv = editlt->dv;
101  lt->dw = editlt->dw;
102 
103  if (lt->editlatt->shapenr) {
104  actkey = BLI_findlink(&lt->key->block, lt->editlatt->shapenr - 1);
105 
106  /* active key: vertices */
107  tot = editlt->pntsu * editlt->pntsv * editlt->pntsw;
108 
109  if (actkey->data) {
110  MEM_freeN(actkey->data);
111  }
112 
113  fp = actkey->data = MEM_callocN(lt->key->elemsize * tot, "actkey->data");
114  actkey->totelem = tot;
115 
116  bp = editlt->def;
117  while (tot--) {
118  copy_v3_v3(fp, bp->vec);
119  fp += 3;
120  bp++;
121  }
122  }
123 
124  if (lt->dvert) {
125  BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
126  lt->dvert = NULL;
127  }
128 
129  if (editlt->dvert) {
130  tot = lt->pntsu * lt->pntsv * lt->pntsw;
131 
132  lt->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
133  BKE_defvert_array_copy(lt->dvert, editlt->dvert, tot);
134  }
135 }
support for deformation groups and hooks.
void BKE_defvert_array_free(struct MDeformVert *dvert, int totvert)
Definition: deform.c:996
void BKE_defvert_array_copy(struct MDeformVert *dst, const struct MDeformVert *src, int totvert)
void BKE_keyblock_convert_to_lattice(const struct KeyBlock *kb, struct Lattice *lt)
struct KeyBlock * BKE_keyblock_from_object(struct Object *ob)
Definition: key.c:1890
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)
Definition: editlattice.c:44
void BKE_editlattice_free(Object *ob)
Definition: editlattice.c:24
void BKE_editlattice_load(Object *obedit)
Definition: editlattice.c:70
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
float vec[4]
struct Lattice * latt
void * data
Definition: DNA_key_types.h:50
int elemsize
Definition: DNA_key_types.h:80
ListBase block
Definition: DNA_key_types.h:84
struct Key * key
struct MDeformVert * dvert
struct EditLatt * editlatt
struct BPoint * def
short shapenr
void * data