Blender V5.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
8
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_meshdata_types.h"
15#include "DNA_object_types.h"
16
17#include "BLI_listbase.hh"
18#include "BLI_math_vector_c.hh"
19
20#include "BKE_deform.hh"
21#include "BKE_key.hh"
22
23#include "BKE_editlattice.h" /* own include */
24
25namespace blender {
26
28{
29 Lattice *lt = id_cast<Lattice *>(ob->data);
30
31 if (lt->editlatt) {
32 Lattice *editlt = lt->editlatt->latt;
33
34 if (editlt->def) {
35 MEM_delete(editlt->def);
36 }
37 if (editlt->dvert) {
38 BKE_defvert_array_free(editlt->dvert, editlt->pntsu * editlt->pntsv * editlt->pntsw);
39 }
40 MEM_delete(editlt);
41 MEM_delete(lt->editlatt);
42
43 lt->editlatt = nullptr;
44 }
45}
46
48{
49 Lattice *lt = id_cast<Lattice *>(obedit->data);
50 KeyBlock *actkey;
51
53
54 actkey = BKE_keyblock_from_object(obedit);
55 if (actkey) {
57 }
58 lt->editlatt = MEM_new<EditLatt>("editlatt");
59 lt->editlatt->latt = MEM_dupalloc(lt);
60 lt->editlatt->latt->def = MEM_dupalloc(lt->def);
61
62 if (lt->dvert) {
63 int tot = lt->pntsu * lt->pntsv * lt->pntsw;
65 "Lattice MDeformVert");
67 }
68
69 if (lt->key) {
70 lt->editlatt->shapenr = obedit->shapenr;
71 }
72}
73
75{
76 Lattice *lt, *editlt;
77 KeyBlock *actkey;
78 BPoint *bp;
79 float *fp;
80 int tot;
81
82 lt = id_cast<Lattice *>(obedit->data);
83 editlt = lt->editlatt->latt;
84
85 MEM_delete(lt->def);
86
87 lt->def = MEM_dupalloc(editlt->def);
88
89 lt->flag = editlt->flag;
90
91 lt->pntsu = editlt->pntsu;
92 lt->pntsv = editlt->pntsv;
93 lt->pntsw = editlt->pntsw;
94
95 lt->typeu = editlt->typeu;
96 lt->typev = editlt->typev;
97 lt->typew = editlt->typew;
98 lt->actbp = editlt->actbp;
99
100 lt->fu = editlt->fu;
101 lt->fv = editlt->fv;
102 lt->fw = editlt->fw;
103 lt->du = editlt->du;
104 lt->dv = editlt->dv;
105 lt->dw = editlt->dw;
106
107 if (lt->editlatt->shapenr) {
108 actkey = static_cast<KeyBlock *>(BLI_findlink(&lt->key->block, lt->editlatt->shapenr - 1));
109
110 /* active key: vertices */
111 tot = editlt->pntsu * editlt->pntsv * editlt->pntsw;
112
113 if (actkey->data) {
114 MEM_delete_void(actkey->data);
115 }
116
117 fp = static_cast<float *>(
118 actkey->data = MEM_new_array_zeroed(tot, size_t(lt->key->elemsize), "actkey->data"));
119 actkey->totelem = tot;
120
121 bp = editlt->def;
122 while (tot--) {
123 copy_v3_v3(fp, bp->vec);
124 fp += 3;
125 bp++;
126 }
127 }
128
129 if (lt->dvert) {
130 BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
131 lt->dvert = nullptr;
132 }
133
134 if (editlt->dvert) {
135 tot = lt->pntsu * lt->pntsv * lt->pntsw;
136
137 lt->dvert = MEM_new_array_uninitialized<MDeformVert>(size_t(tot), "Lattice MDeformVert");
138 BKE_defvert_array_copy(lt->dvert, editlt->dvert, tot);
139 }
140}
141
142} // namespace blender
support for deformation groups and hooks.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
BMesh Iterators.
void BKE_defvert_array_free(MDeformVert *dvert, int totvert)
Definition deform.cc:1079
void BKE_editlattice_load(struct Object *obedit)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert)
Definition deform.cc:1043
void BKE_editlattice_make(struct Object *obedit)
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1407
void BKE_editlattice_free(struct Object *ob)
void MEM_delete_void(void *vmemh)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void BKE_keyblock_convert_to_lattice(const KeyBlock *kb, Lattice *lt)
Definition key.cc:1517
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
struct Lattice * latt
ListBaseT< KeyBlock > block
struct EditLatt * editlatt
struct MDeformVert * dvert
struct BPoint * def