1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/blenkernel/intern/editmesh_cache.c
* \ingroup bke
*
* Manage edit mesh cache: #EditMeshData
*/
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "BLI_math.h"
#include "BKE_editmesh.h"
#include "BKE_editmesh_cache.h" /* own include */
void BKE_editmesh_cache_ensure_poly_normals(BMEditMesh *em, EditMeshData *emd)
{
if (!(emd->vertexCos && (emd->polyNos == NULL))) {
return;
}
BMesh *bm = em->bm;
const float (*vertexCos)[3];
float (*polyNos)[3];
BMFace *efa;
BMIter fiter;
int i;
BM_mesh_elem_index_ensure(bm, BM_VERT);
polyNos = MEM_mallocN(sizeof(*polyNos) * bm->totface, __func__);
vertexCos = emd->vertexCos;
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
BM_elem_index_set(efa, i); /* set_inline */
BM_face_calc_normal_vcos(bm, efa, polyNos[i], vertexCos);
}
bm->elem_index_dirty &= ~BM_FACE;
emd->polyNos = (const float (*)[3])polyNos;
}
void BKE_editmesh_cache_ensure_vert_normals(BMEditMesh *em, EditMeshData *emd)
{
if (!(emd->vertexCos && (emd->vertexNos == NULL))) {
return;
}
BMesh *bm = em->bm;
const float (*vertexCos)[3], (*polyNos)[3];
float (*vertexNos)[3];
/* calculate vertex normals from poly normals */
BKE_editmesh_cache_ensure_poly_normals(em, emd);
BM_mesh_elem_index_ensure(bm, BM_FACE);
polyNos = emd->polyNos;
vertexCos = emd->vertexCos;
vertexNos = MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__);
BM_verts_calc_normal_vcos(bm, polyNos, vertexCos, vertexNos);
emd->vertexNos = (const float (*)[3])vertexNos;
}
void BKE_editmesh_cache_ensure_poly_centers(BMEditMesh *em, EditMeshData *emd)
{
if (emd->polyCos != NULL) {
return;
}
BMesh *bm = em->bm;
float (*polyCos)[3];
BMFace *efa;
BMIter fiter;
int i;
polyCos = MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__);
if (emd->vertexCos) {
const float (*vertexCos)[3];
vertexCos = emd->vertexCos;
BM_mesh_elem_index_ensure(bm, BM_VERT);
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
BM_face_calc_center_mean_vcos(bm, efa, polyCos[i], vertexCos);
}
}
else {
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
BM_face_calc_center_mean(efa, polyCos[i]);
}
}
emd->polyCos = (const float (*)[3])polyCos;
}
|