move editmesh_bvh.c into blenkernel.

This commit is contained in:
Campbell Barton
2013-04-16 05:23:34 +00:00
parent d044fd3299
commit fa919d23bc
8 changed files with 114 additions and 117 deletions

View File

@@ -25,12 +25,12 @@
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/mesh/editmesh_bvh.h
* \ingroup edmesh
/** \file BKE_editmesh_bvh.h
* \ingroup bke
*/
#ifndef __EDITBMESH_BVH_H__
#define __EDITBMESH_BVH_H__
#ifndef __BKE_EDITMESH_BVH_H__
#define __BKE_EDITMESH_BVH_H__
struct BMEditMesh;
struct BMFace;
@@ -42,22 +42,17 @@ struct BVHTree;
struct Scene;
struct Object;
#ifndef IN_EDITMESHBVH
typedef struct BMBVHTree BMBVHTree;
#endif
struct BMBVHTree *BMBVH_NewBVH(struct BMEditMesh *em, int flag, struct Scene *scene, struct Object *obedit);
void BMBVH_FreeBVH(struct BMBVHTree *tree);
struct BVHTree *BMBVH_BVHTree(struct BMBVHTree *tree);
BMBVHTree *BMBVH_NewBVH(struct BMEditMesh *em, int flag, struct Scene *scene);
void BMBVH_FreeBVH(BMBVHTree *tree);
struct BVHTree *BMBVH_BVHTree(BMBVHTree *tree);
struct BMFace *BMBVH_RayCast(struct BMBVHTree *tree, const float co[3], const float dir[3],
struct BMFace *BMBVH_RayCast(BMBVHTree *tree, const float co[3], const float dir[3],
float r_hitout[3], float r_cagehit[3]);
int BMBVH_EdgeVisible(struct BMBVHTree *tree, struct BMEdge *e,
struct ARegion *ar, struct View3D *v3d, struct Object *obedit);
/*find a vert closest to co in a sphere of radius maxdist*/
struct BMVert *BMBVH_FindClosestVert(struct BMBVHTree *tree, const float co[3], const float maxdist);
struct BMVert *BMBVH_FindClosestVert(BMBVHTree *tree, const float co[3], const float maxdist);
/* BMBVH_NewBVH flag parameter */
enum {
@@ -67,4 +62,4 @@ enum {
BMBVH_RESPECT_HIDDEN = 8 /* omit hidden geometry */
};
#endif /* __EDITBMESH_BVH_H__ */
#endif /* __BKE_EDITMESH_BVH_H__ */

View File

@@ -84,6 +84,7 @@ set(SRC
intern/displist.c
intern/dynamicpaint.c
intern/editderivedmesh.c
intern/editmesh_bvh.c
intern/effect.c
intern/fcurve.c
intern/fluidsim.c
@@ -237,6 +238,7 @@ set(SRC
BKE_subsurf.h
BKE_suggestions.h
BKE_editmesh.h
BKE_editmesh_bvh.h
BKE_text.h
BKE_texture.h
BKE_tracking.h

View File

@@ -25,16 +25,14 @@
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/mesh/editmesh_bvh.c
* \ingroup edmesh
/** \file blender/blenkernel/intern/editmesh_bvh.c
* \ingroup bke
*/
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_view3d_types.h"
#include "BLI_math.h"
#include "BLI_smallhash.h"
@@ -42,10 +40,7 @@
#include "BKE_DerivedMesh.h"
#include "BKE_editmesh.h"
#include "ED_view3d.h"
#define IN_EDITMESHBVH /* needed for typedef workaround */
#include "editmesh_bvh.h" /* own include */
#include "BKE_editmesh_bvh.h" /* own include */
typedef struct BMBVHTree {
@@ -81,7 +76,7 @@ static void cage_mapped_verts_callback(void *userData, int index, const float co
}
}
BMBVHTree *BMBVH_NewBVH(BMEditMesh *em, int flag, Scene *scene, Object *obedit)
BMBVHTree *BMBVH_NewBVH(BMEditMesh *em, int flag, Scene *scene)
{
BMBVHTree *tree = MEM_callocN(sizeof(*tree), "BMBVHTree");
DerivedMesh *cage, *final;
@@ -96,7 +91,7 @@ BMBVHTree *BMBVH_NewBVH(BMEditMesh *em, int flag, Scene *scene, Object *obedit)
BMEdit_RecalcTessellation(em);
tree->ob = obedit;
tree->ob = em->ob;
tree->scene = scene;
tree->em = em;
tree->bm = em->bm;
@@ -138,7 +133,7 @@ BMBVHTree *BMBVH_NewBVH(BMEditMesh *em, int flag, Scene *scene, Object *obedit)
em->bm->elem_index_dirty &= ~BM_VERT;
cage = editbmesh_get_derived_cage_and_final(scene, obedit, em, &final, CD_MASK_DERIVEDMESH);
cage = editbmesh_get_derived_cage_and_final(scene, em->ob, em, &final, CD_MASK_DERIVEDMESH);
cagecos = MEM_callocN(sizeof(float) * 3 * em->bm->totvert, "bmbvh cagecos");
data[0] = em;
@@ -360,86 +355,3 @@ static short winding(const float v1[3], const float v2[3], const float v3[3])
return 1;
}
#endif
#if 0 //BMESH_TODO: not implemented yet
int BMBVH_VertVisible(BMBVHTree *tree, BMEdge *e, RegionView3D *r3d)
{
}
#endif
static BMFace *edge_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3], float *r_hitout, BMEdge *e)
{
BMFace *f = BMBVH_RayCast(tree, co, dir, r_hitout, NULL);
if (f && BM_edge_in_face(f, e))
return NULL;
return f;
}
static void scale_point(float c1[3], const float p[3], const float s)
{
sub_v3_v3(c1, p);
mul_v3_fl(c1, s);
add_v3_v3(c1, p);
}
int BMBVH_EdgeVisible(BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v3d, Object *obedit)
{
BMFace *f;
float co1[3], co2[3], co3[3], dir1[3], dir2[3], dir3[3];
float origin[3], invmat[4][4];
float epsilon = 0.01f;
float end[3];
const float mval_f[2] = {ar->winx / 2.0f,
ar->winy / 2.0f};
ED_view3d_win_to_segment(ar, v3d, mval_f, origin, end);
invert_m4_m4(invmat, obedit->obmat);
mul_m4_v3(invmat, origin);
copy_v3_v3(co1, e->v1->co);
mid_v3_v3v3(co2, e->v1->co, e->v2->co);
copy_v3_v3(co3, e->v2->co);
scale_point(co1, co2, 0.99);
scale_point(co3, co2, 0.99);
/* ok, idea is to generate rays going from the camera origin to the
* three points on the edge (v1, mid, v2)*/
sub_v3_v3v3(dir1, origin, co1);
sub_v3_v3v3(dir2, origin, co2);
sub_v3_v3v3(dir3, origin, co3);
normalize_v3(dir1);
normalize_v3(dir2);
normalize_v3(dir3);
mul_v3_fl(dir1, epsilon);
mul_v3_fl(dir2, epsilon);
mul_v3_fl(dir3, epsilon);
/* offset coordinates slightly along view vectors, to avoid
* hitting the faces that own the edge.*/
add_v3_v3v3(co1, co1, dir1);
add_v3_v3v3(co2, co2, dir2);
add_v3_v3v3(co3, co3, dir3);
normalize_v3(dir1);
normalize_v3(dir2);
normalize_v3(dir3);
/* do three samplings: left, middle, right */
f = edge_ray_cast(tree, co1, dir1, NULL, e);
if (f && !edge_ray_cast(tree, co2, dir2, NULL, e))
return 1;
else if (f && !edge_ray_cast(tree, co3, dir3, NULL, e))
return 1;
else if (!f)
return 1;
return 0;
}

View File

@@ -62,6 +62,7 @@ struct BMEditSelection;
struct BMesh;
struct BMVert;
struct BMLoop;
struct BMBVHTree;
struct MLoopCol;
struct BMEdge;
struct BMFace;
@@ -135,6 +136,8 @@ struct UvVertMap *EDBM_uv_vert_map_create(struct BMEditMesh *em, bool use_select
void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag);
void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag);
bool BMBVH_EdgeVisible(struct BMBVHTree *tree, struct BMEdge *e,
struct ARegion *ar, struct View3D *v3d, struct Object *obedit);
/* editmesh_select.c */
void EDBM_select_mirrored(struct Object *obedit, struct BMEditMesh *em, bool extend);
@@ -299,8 +302,6 @@ bool ED_mesh_pick_face_vert(struct bContext *C, struct Object *ob, const int mva
#define ED_MESH_PICK_DEFAULT_VERT_SIZE 50
#define ED_MESH_PICK_DEFAULT_FACE_SIZE 3
#include "../mesh/editmesh_bvh.h"
#ifdef __cplusplus
}
#endif

View File

@@ -43,7 +43,6 @@ set(SRC
editface.c
editmesh_add.c
editmesh_bevel.c
editmesh_bvh.c
editmesh_extrude.c
editmesh_inset.c
editmesh_knife.c
@@ -57,7 +56,6 @@ set(SRC
mesh_ops.c
meshtools.c
editmesh_bvh.h
mesh_intern.h
)

View File

@@ -47,6 +47,8 @@
#include "BKE_DerivedMesh.h"
#include "BKE_context.h"
#include "BKE_editmesh.h"
#include "BKE_editmesh_bvh.h"
#include "BIF_gl.h"
#include "BIF_glutil.h" /* for paint cursor */
@@ -60,7 +62,6 @@
#include "WM_types.h"
#include "DNA_object_types.h"
#include "BKE_editmesh.h"
#include "UI_resources.h"
#include "RNA_access.h"
@@ -3016,7 +3017,7 @@ static void knifetool_init(bContext *C, KnifeTool_OpData *kcd,
kcd->bmbvh = BMBVH_NewBVH(kcd->em,
(BMBVH_USE_CAGE | BMBVH_RETURN_ORIG) |
(only_select ? BMBVH_RESPECT_SELECT : BMBVH_RESPECT_HIDDEN),
scene, obedit);
scene);
kcd->arena = BLI_memarena_new(1 << 15, "knife");
kcd->vthresh = KMAXDIST - 1;

View File

@@ -43,6 +43,7 @@
#include "BKE_mesh.h"
#include "BKE_report.h"
#include "BKE_editmesh.h"
#include "BKE_editmesh_bvh.h"
#include "BKE_object.h" /* XXX. only for EDBM_mesh_ensure_valid_dm_hack() which will be removed */
@@ -52,6 +53,7 @@
#include "ED_mesh.h"
#include "ED_screen.h"
#include "ED_util.h"
#include "ED_view3d.h"
#include "mesh_intern.h" /* own include */
@@ -1164,7 +1166,7 @@ void EDBM_verts_mirror_cache_begin(BMEditMesh *em, const bool use_select)
ED_mesh_mirrtopo_init(me, -1, &mesh_topo_store, true);
}
else {
tree = BMBVH_NewBVH(em, 0, NULL, NULL);
tree = BMBVH_NewBVH(em, 0, NULL);
}
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
@@ -1376,3 +1378,88 @@ int EDBM_view3d_poll(bContext *C)
return 0;
}
/* -------------------------------------------------------------------- */
/* BMBVH functions */
// XXX
#if 0 //BMESH_TODO: not implemented yet
int BMBVH_VertVisible(BMBVHTree *tree, BMEdge *e, RegionView3D *r3d)
{
}
#endif
static BMFace *edge_ray_cast(struct BMBVHTree *tree, const float co[3], const float dir[3], float *r_hitout, BMEdge *e)
{
BMFace *f = BMBVH_RayCast(tree, co, dir, r_hitout, NULL);
if (f && BM_edge_in_face(f, e))
return NULL;
return f;
}
static void scale_point(float c1[3], const float p[3], const float s)
{
sub_v3_v3(c1, p);
mul_v3_fl(c1, s);
add_v3_v3(c1, p);
}
bool BMBVH_EdgeVisible(struct BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v3d, Object *obedit)
{
BMFace *f;
float co1[3], co2[3], co3[3], dir1[3], dir2[3], dir3[3];
float origin[3], invmat[4][4];
float epsilon = 0.01f;
float end[3];
const float mval_f[2] = {ar->winx / 2.0f,
ar->winy / 2.0f};
ED_view3d_win_to_segment(ar, v3d, mval_f, origin, end);
invert_m4_m4(invmat, obedit->obmat);
mul_m4_v3(invmat, origin);
copy_v3_v3(co1, e->v1->co);
mid_v3_v3v3(co2, e->v1->co, e->v2->co);
copy_v3_v3(co3, e->v2->co);
scale_point(co1, co2, 0.99);
scale_point(co3, co2, 0.99);
/* ok, idea is to generate rays going from the camera origin to the
* three points on the edge (v1, mid, v2)*/
sub_v3_v3v3(dir1, origin, co1);
sub_v3_v3v3(dir2, origin, co2);
sub_v3_v3v3(dir3, origin, co3);
normalize_v3(dir1);
normalize_v3(dir2);
normalize_v3(dir3);
mul_v3_fl(dir1, epsilon);
mul_v3_fl(dir2, epsilon);
mul_v3_fl(dir3, epsilon);
/* offset coordinates slightly along view vectors, to avoid
* hitting the faces that own the edge.*/
add_v3_v3v3(co1, co1, dir1);
add_v3_v3v3(co2, co2, dir2);
add_v3_v3v3(co3, co3, dir3);
normalize_v3(dir1);
normalize_v3(dir2);
normalize_v3(dir3);
/* do three samplings: left, middle, right */
f = edge_ray_cast(tree, co1, dir1, NULL, e);
if (f && !edge_ray_cast(tree, co2, dir2, NULL, e))
return true;
else if (f && !edge_ray_cast(tree, co3, dir3, NULL, e))
return true;
else if (!f)
return true;
return false;
}

View File

@@ -63,6 +63,7 @@
#include "BKE_nla.h"
#include "BKE_bmesh.h"
#include "BKE_editmesh_bvh.h"
#include "BKE_context.h"
#include "BKE_constraint.h"
#include "BKE_global.h"
@@ -5175,7 +5176,7 @@ static int createEdgeSlideVerts(TransInfo *t)
use_btree_disp = (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE);
if (use_btree_disp) {
btree = BMBVH_NewBVH(em, BMBVH_RESPECT_HIDDEN, NULL, NULL);
btree = BMBVH_NewBVH(em, BMBVH_RESPECT_HIDDEN, NULL);
}
else {
btree = NULL;