[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60936] branches/ soc-2013-meshdata_transfer/source/blender: -renaming BKE_bmbvh_new to BKE_bmbvh_new_from_editmesh
Walid Shouman
eng.walidshouman at gmail.com
Sat Oct 26 01:40:04 CEST 2013
Revision: 60936
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60936
Author: walid
Date: 2013-10-25 23:40:04 +0000 (Fri, 25 Oct 2013)
Log Message:
-----------
-renaming BKE_bmbvh_new to BKE_bmbvh_new_from_editmesh
-adding a new BKE_bmbvh_new that takes the looptris, looptris_num and
BMesh
-adding a bmesh tesselating function BM_tessellate_bmesh that should be
synced with edithmesh_tessface_calc_intern found in editmesh.c
-using the BKE_bmbvh_new instead of BKE_bmbvh_new_from_editmesh in the
bmesh_data_transfer.c
Modified Paths:
--------------
branches/soc-2013-meshdata_transfer/source/blender/blenkernel/BKE_editmesh_bvh.h
branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editderivedmesh.c
branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c
branches/soc-2013-meshdata_transfer/source/blender/bmesh/intern/bmesh_polygon.c
branches/soc-2013-meshdata_transfer/source/blender/bmesh/intern/bmesh_polygon.h
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/editmesh_knife.c
branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/editmesh_utils.c
branches/soc-2013-meshdata_transfer/source/blender/editors/transform/transform.c
Modified: branches/soc-2013-meshdata_transfer/source/blender/blenkernel/BKE_editmesh_bvh.h
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/blenkernel/BKE_editmesh_bvh.h 2013-10-25 23:05:34 UTC (rev 60935)
+++ branches/soc-2013-meshdata_transfer/source/blender/blenkernel/BKE_editmesh_bvh.h 2013-10-25 23:40:04 UTC (rev 60936)
@@ -33,15 +33,19 @@
#define __BKE_EDITMESH_BVH_H__
struct BMEditMesh;
+struct BMesh;
struct BMFace;
struct BMVert;
+struct BMLoop;
struct BMBVHTree;
struct BVHTree;
struct Scene;
typedef struct BMBVHTree BMBVHTree;
-BMBVHTree *BKE_bmbvh_new(struct BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free);
+BMBVHTree *BKE_bmbvh_new_from_editmesh(struct BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free);
+BMBVHTree *BKE_bmbvh_new(struct BMesh *bm, struct BMLoop *(*looptris)[3], int looptris_num, int flag,
+ const float (*cos_cage)[3], const bool cos_cage_free);
void BKE_bmbvh_free(BMBVHTree *tree);
struct BVHTree *BKE_bmbvh_tree_get(BMBVHTree *tree);
struct BMFace *BKE_bmbvh_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3], const float radius,
Modified: branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editderivedmesh.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editderivedmesh.c 2013-10-25 23:05:34 UTC (rev 60935)
+++ branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editderivedmesh.c 2013-10-25 23:40:04 UTC (rev 60936)
@@ -1848,7 +1848,7 @@
BM_mesh_elem_index_ensure(bm, BM_VERT);
}
- bmtree = BKE_bmbvh_new(em, 0, vertexCos, false);
+ bmtree = BKE_bmbvh_new_from_editmesh(em, 0, vertexCos, false);
for (i = 0; i < tottri; i++) {
BMFace *f_hit;
@@ -1948,7 +1948,7 @@
BM_mesh_elem_index_ensure(bm, BM_VERT);
}
- bmtree = BKE_bmbvh_new(em, 0, vertexCos, false);
+ bmtree = BKE_bmbvh_new_from_editmesh(em, 0, vertexCos, false);
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
BMFace *f_hit;
Modified: branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c 2013-10-25 23:05:34 UTC (rev 60935)
+++ branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c 2013-10-25 23:40:04 UTC (rev 60936)
@@ -44,7 +44,10 @@
struct BMBVHTree {
BVHTree *tree;
- BMEditMesh *em;
+ BMLoop *(*looptris)[3];
+ int looptris_num;
+
+ BMEditMesh *em; ///should be removed if its not being used anywhere else!
BMesh *bm;
const float (*cos_cage)[3];
@@ -53,7 +56,7 @@
int flag;
};
-BMBVHTree *BKE_bmbvh_new(BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free)
+BMBVHTree *BKE_bmbvh_new_from_editmesh(BMEditMesh *em, int flag, const float (*cos_cage)[3], const bool cos_cage_free)
{
/* could become argument */
const float epsilon = FLT_EPSILON * 2.0f;
@@ -71,7 +74,9 @@
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
}
- bmtree->em = em;
+ bmtree->em = em; ///should be removed ... left till we ensure its not being used at all
+ bmtree->looptris = em->looptris;
+ bmtree->looptris_num = em->tottri;
bmtree->bm = em->bm;
bmtree->cos_cage = cos_cage;
bmtree->cos_cage_free = cos_cage_free;
@@ -133,6 +138,88 @@
return bmtree;
}
+BMBVHTree *BKE_bmbvh_new(BMesh *bm, BMLoop *(*looptris)[3], int looptris_num, int flag, const float (*cos_cage)[3],
+const bool cos_cage_free)
+{
+ /* could become argument */
+ const float epsilon = FLT_EPSILON * 2.0f;
+
+ BMBVHTree *bmtree = MEM_callocN(sizeof(*bmtree), "BMBVHTree");
+ float cos[3][3];
+ int i;
+ int tottri;
+
+ /* BKE_editmesh_tessface_calc() must be called already */
+ BLI_assert(looptris_num != 0 || bm->totface == 0);
+
+ if (cos_cage) {
+ BM_mesh_elem_index_ensure(bm, BM_VERT);
+ }
+
+ bmtree->looptris = looptris;
+ bmtree->looptris_num = looptris_num;
+ bmtree->bm = bm;
+ bmtree->cos_cage = cos_cage;
+ bmtree->cos_cage_free = cos_cage_free;
+ bmtree->flag = flag;
+
+ if (flag & (BMBVH_RESPECT_SELECT)) {
+ tottri = 0;
+ for (i = 0; i < looptris_num; i++) {
+ if (BM_elem_flag_test(looptris[i][0]->f, BM_ELEM_SELECT)) {
+ tottri++;
+ }
+ }
+ }
+ else if (flag & (BMBVH_RESPECT_HIDDEN)) {
+ tottri = 0;
+ for (i = 0; i < looptris_num; i++) {
+ if (!BM_elem_flag_test(looptris[i][0]->f, BM_ELEM_HIDDEN)) {
+ tottri++;
+ }
+ }
+ }
+ else {
+ tottri = looptris_num;
+ }
+
+ bmtree->tree = BLI_bvhtree_new(tottri, epsilon, 8, 8);
+
+ for (i = 0; i < looptris_num; i++) {
+
+ if (flag & BMBVH_RESPECT_SELECT) {
+ /* note, the arrays wont align now! take care */
+ if (!BM_elem_flag_test(looptris[i][0]->f, BM_ELEM_SELECT)) {
+ continue;
+ }
+ }
+ else if (flag & BMBVH_RESPECT_HIDDEN) {
+ /* note, the arrays wont align now! take care */
+ if (BM_elem_flag_test(looptris[i][0]->f, BM_ELEM_HIDDEN)) {
+ continue;
+ }
+ }
+
+ if (cos_cage) {
+ copy_v3_v3(cos[0], cos_cage[BM_elem_index_get(looptris[i][0]->v)]);
+ copy_v3_v3(cos[1], cos_cage[BM_elem_index_get(looptris[i][1]->v)]);
+ copy_v3_v3(cos[2], cos_cage[BM_elem_index_get(looptris[i][2]->v)]);
+ }
+ else {
+ copy_v3_v3(cos[0], looptris[i][0]->v->co);
+ copy_v3_v3(cos[1], looptris[i][1]->v->co);
+ copy_v3_v3(cos[2], looptris[i][2]->v->co);
+ }
+
+ BLI_bvhtree_insert(bmtree->tree, i, (float *)cos, 3);
+ }
+
+ BLI_bvhtree_balance(bmtree->tree);
+
+ return bmtree;
+}
+
+
void BKE_bmbvh_free(BMBVHTree *bmtree)
{
BLI_bvhtree_free(bmtree->tree);
@@ -231,14 +318,14 @@
hit.index = -1;
/* ok to leave 'uv' uninitialized */
- bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
+ bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris;
bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
BLI_bvhtree_ray_cast(bmtree->tree, co, dir, radius, &hit, bmbvh_ray_cast_cb, &bmcb_data);
if (hit.index != -1 && hit.dist != dist) {
if (r_hitout) {
if (bmtree->flag & BMBVH_RETURN_ORIG) {
- BMLoop **ltri = bmtree->em->looptris[hit.index];
+ BMLoop **ltri = bmtree->looptris[hit.index];
interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcb_data.uv);
}
else {
@@ -254,7 +341,7 @@
*r_dist = hit.dist;
}
- return bmtree->em->looptris[hit.index][0]->f;
+ return bmtree->looptris[hit.index][0]->f;
}
return NULL;
@@ -327,7 +414,7 @@
hit.index = -1;
/* ok to leave 'uv' uninitialized */
- bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
+ bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris;
bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
bmcb_data.co_a = co_a;
bmcb_data.co_b = co_b;
@@ -337,7 +424,7 @@
/* duplicate of BKE_bmbvh_ray_cast() */
if (r_hitout) {
if (bmtree->flag & BMBVH_RETURN_ORIG) {
- BMLoop **ltri = bmtree->em->looptris[hit.index];
+ BMLoop **ltri = bmtree->looptris[hit.index];
interp_v3_v3v3v3_uv(r_hitout, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, bmcb_data.uv);
}
else {
@@ -354,7 +441,7 @@
*r_fac = hit.dist / dist;
}
- return bmtree->em->looptris[hit.index][0]->f;
+ return bmtree->looptris[hit.index][0]->f;
}
return NULL;
@@ -410,13 +497,13 @@
hit.dist = maxdist_sq;
hit.index = -1;
- bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
+ bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris;
bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
bmcb_data.maxdist = maxdist_sq;
BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_vert_closest_cb, &bmcb_data);
if (hit.index != -1) {
- BMLoop **ltri = bmtree->em->looptris[hit.index];
+ BMLoop **ltri = bmtree->looptris[hit.index];
return ltri[bmcb_data.index_tri]->v;
}
@@ -473,18 +560,18 @@
maxdist_sq = FLT_MAX;
//is that ok?
- if (bmtree->cos_cage) BLI_assert(!(bmtree->em->bm->elem_index_dirty & BM_FACE));
+ if (bmtree->cos_cage) BLI_assert(!(bmtree->bm->elem_index_dirty & BM_FACE));
hit.dist = maxdist_sq;
hit.index = -1;
- bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris;
+ bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris;
bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage;
bmcb_data.maxdist = maxdist_sq;
BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_face_closest_cb, &bmcb_data);
if (hit.index != -1) {
- BMLoop **ltri = bmtree->em->looptris[hit.index];
+ BMLoop **ltri = bmtree->looptris[hit.index];
return ltri[0]->f; //any loop would be ok
}
Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/intern/bmesh_polygon.c 2013-10-25 23:05:34 UTC (rev 60935)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/intern/bmesh_polygon.c 2013-10-25 23:40:04 UTC (rev 60936)
@@ -40,6 +40,8 @@
#include "intern/bmesh_private.h"
+#include "MEM_guardedalloc.h"
+
/**
* \brief TEST EDGE SIDE and POINT IN TRIANGLE
*
@@ -1107,3 +1109,182 @@
r_loops[2] = l; l = l->next;
r_loops[3] = l;
}
+
+
+///
+/// \brief BM_tessellate_bmesh get the looptris and its number from a certain bmesh
+/// keep in sync with editmesh_tessface_calc_intern found in editmesh.c
+/// \param looptris_num
+/// \param bm_src
+/// \return
+///
+
+void BM_tessellate_bmesh(BMLoop *(**looptris_r)[3], int *tottri_r, BMesh *bm)
+{
+ /* use this to avoid locking pthread for _every_ polygon
+ * and calling the fill function */
+#define USE_TESSFACE_SPEEDUP
+
+ /* this assumes all faces can be scan-filled, which isn't always true,
+ * worst case we over alloc a little which is acceptable */
+ const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
+ const int looptris_tot_prev_alloc = *looptris_r ? (MEM_allocN_len(*looptris_r) / sizeof(**looptris_r)) : 0;
+
+ BMLoop *(*looptris)[3];
+ BMIter iter;
+ BMFace *efa;
+ BMLoop *l;
+ int i = 0;
+
+ ScanFillContext sf_ctx;
+
+#if 0
+ /* note, we could be clever and re-use this array but would need to ensure
+ * its realloced at some point, for now just free it */
+ if (*looptris_r) MEM_freeN(*looptris_r);
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list