diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_editmesh_cache.h | 36 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 74 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editmesh_cache.c | 120 |
4 files changed, 162 insertions, 70 deletions
diff --git a/source/blender/blenkernel/BKE_editmesh_cache.h b/source/blender/blenkernel/BKE_editmesh_cache.h new file mode 100644 index 00000000000..aaaa79a0857 --- /dev/null +++ b/source/blender/blenkernel/BKE_editmesh_cache.h @@ -0,0 +1,36 @@ +/* + * ***** 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 ***** + */ + +#ifndef __BKE_EDITMESH_CACHE_H__ +#define __BKE_EDITMESH_CACHE_H__ + +/** \file BKE_editmesh_cache.h + * \ingroup bke + */ + +struct BMEditMesh; +struct EditMeshData; + +void BKE_editmesh_cache_ensure_poly_normals(struct BMEditMesh *em, struct EditMeshData *emd); +void BKE_editmesh_cache_ensure_vert_normals(struct BMEditMesh *em, struct EditMeshData *emd); + +void BKE_editmesh_cache_ensure_poly_centers(struct BMEditMesh *em, struct EditMeshData *emd); + +#endif /* __BKE_EDITMESH_CACHE_H__ */ diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 452ca90ecf1..7b1af2cb283 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -110,6 +110,7 @@ set(SRC intern/editlattice.c intern/editmesh.c intern/editmesh_bvh.c + intern/editmesh_cache.c intern/editmesh_tangent.c intern/effect.c intern/fcurve.c @@ -264,6 +265,7 @@ set(SRC BKE_editlattice.h BKE_editmesh.h BKE_editmesh_bvh.h + BKE_editmesh_cache.h BKE_editmesh_tangent.h BKE_effect.h BKE_fcurve.h diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 27d1ad01f2d..38a6556dc21 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -53,6 +53,7 @@ #include "BKE_mesh.h" #include "BKE_editmesh.h" #include "BKE_editmesh_bvh.h" +#include "BKE_editmesh_cache.h" #include "BKE_editmesh_tangent.h" #include "DNA_scene_types.h" @@ -76,84 +77,17 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm); static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm) { - if (bmdm->emd.vertexCos && (bmdm->emd.vertexNos == NULL)) { - - BMesh *bm = bmdm->em->bm; - const float (*vertexCos)[3], (*polyNos)[3]; - float (*vertexNos)[3]; - - /* calculate vertex normals from poly normals */ - emDM_ensurePolyNormals(bmdm); - - BM_mesh_elem_index_ensure(bm, BM_FACE); - - polyNos = bmdm->emd.polyNos; - vertexCos = bmdm->emd.vertexCos; - vertexNos = MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__); - - BM_verts_calc_normal_vcos(bm, polyNos, vertexCos, vertexNos); - - bmdm->emd.vertexNos = (const float (*)[3])vertexNos; - } + BKE_editmesh_cache_ensure_vert_normals(bmdm->em, &bmdm->emd); } static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm) { - if (bmdm->emd.vertexCos && (bmdm->emd.polyNos == NULL)) { - BMesh *bm = bmdm->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 = bmdm->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; - - bmdm->emd.polyNos = (const float (*)[3])polyNos; - } + BKE_editmesh_cache_ensure_poly_normals(bmdm->em, &bmdm->emd); } static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm) { - if (bmdm->emd.polyCos == NULL) { - BMesh *bm = bmdm->em->bm; - float (*polyCos)[3]; - - BMFace *efa; - BMIter fiter; - int i; - - polyCos = MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__); - - if (bmdm->emd.vertexCos) { - const float (*vertexCos)[3]; - vertexCos = bmdm->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]); - } - } - - bmdm->emd.polyCos = (const float (*)[3])polyCos; - } + BKE_editmesh_cache_ensure_poly_centers(bmdm->em, &bmdm->emd); } static void emDM_calcNormals(DerivedMesh *dm) diff --git a/source/blender/blenkernel/intern/editmesh_cache.c b/source/blender/blenkernel/intern/editmesh_cache.c new file mode 100644 index 00000000000..f0af0ede9b1 --- /dev/null +++ b/source/blender/blenkernel/intern/editmesh_cache.c @@ -0,0 +1,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; +} |