[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15688] branches/soc-2008-jaguarandi/ source/blender: *BVHTreeFromMesh api changed..
André Pinto
andresusanopinto at gmail.com
Tue Jul 22 13:50:50 CEST 2008
Revision: 15688
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15688
Author: jaguarandi
Date: 2008-07-22 13:50:50 +0200 (Tue, 22 Jul 2008)
Log Message:
-----------
*BVHTreeFromMesh api changed.. it now stores all information like defaults callbacks to raycast and nearest surface (just to make it easier to use)
*Fixed button size of "Above surface"
Modified Paths:
--------------
branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h
branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/shrinkwrap.c
branches/soc-2008-jaguarandi/source/blender/src/buttons_editing.c
Modified: branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h
===================================================================
--- branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h 2008-07-22 09:53:25 UTC (rev 15687)
+++ branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h 2008-07-22 11:50:50 UTC (rev 15688)
@@ -61,11 +61,46 @@
void space_transform_apply_normal (const SpaceTransform *data, float *co);
void space_transform_invert_normal(const SpaceTransform *data, float *co);
+/* BVH from mesh */
+#include "BLI_kdopbvh.h"
+struct DerivedMesh;
+struct MVert;
+struct MFace;
+
+//struct that kepts basic information about a BVHTree build from a mesh
+typedef struct BVHTreeFromMesh
+{
+ struct BVHTree *tree;
+
+ //Callbacks
+ BVHTree_NearestPointCallback nearest_callback;
+ BVHTree_RayCastCallback raycast_callback;
+
+ //Mesh represented on this BVH
+ struct DerivedMesh *mesh;
+ struct MVert *vert;
+ struct MFace *face;
+
+ //radius for sphere cast
+ float sphere_radius;
+
+} BVHTreeFromMesh;
+
+// Builds a bvh tree where nodes are the vertexs of the given mesh. And configures BVHMesh if one given.
+struct BVHTree* bvhtree_from_mesh_verts(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
+
+// Builds a bvh tree where nodes are the faces of the given mesh. And configures BVHMesh if one is given.
+struct BVHTree* bvhtree_from_mesh_faces(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
+
+
+
+
/* Shrinkwrap stuff */
struct Object;
struct DerivedMesh;
struct ShrinkwrapModifierData;
+struct BVHTree;
@@ -75,6 +110,9 @@
struct Object *ob; //object we are applying shrinkwrap to
struct DerivedMesh *original; //mesh before shrinkwrap (TODO clean this variable.. we don't really need it)
+ struct BVHTree *original_tree; //BVHTree build with the original mesh (to be used on kept volume)
+ struct BVHMeshCallbackUserdata *callback;
+
struct DerivedMesh *final; //initially a copy of original mesh.. mesh thats going to be shrinkwrapped
struct DerivedMesh *target; //mesh we are shrinking to
Modified: branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/shrinkwrap.c
===================================================================
--- branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/shrinkwrap.c 2008-07-22 09:53:25 UTC (rev 15687)
+++ branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/shrinkwrap.c 2008-07-22 11:50:50 UTC (rev 15688)
@@ -104,7 +104,7 @@
else
return mesh_get_derived_final(ob, dataMask);
}
-
+
/* ray - triangle */
#define ISECT_EPSILON 1e-6
static float ray_tri_intersection(const BVHTreeRay *ray, const float m_dist, const float *v0, const float *v1, const float *v2)
@@ -167,39 +167,25 @@
/*
- * BVH tree from mesh vertices
+ * BVH Tree from Mesh
*/
-typedef struct BVHMeshCallbackUserdata
-{
- //Mesh represented on this BVH
- DerivedMesh *mesh;
- MVert *vert;
- MFace *face;
+//callbacks
+static void mesh_faces_nearest_point(void *userdata, int index, const float *co, BVHTreeNearest *nearest);
+static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit);
- //radius for sphere cast
- float sphere_radius;
-
-} BVHMeshCallbackUserdata;
-
-
-static void bvhtree_meshcallbackdata_init(BVHMeshCallbackUserdata *data, DerivedMesh *mesh, float cast_radius)
-{
- data->mesh = mesh;
- data->vert = mesh->getVertDataArray(mesh, CD_MVERT);
- data->face = mesh->getFaceDataArray(mesh, CD_MFACE);
- data->sphere_radius = cast_radius;
-}
-
/*
* Builds a bvh tree.. where nodes are the vertexs of the given mesh
*/
-static BVHTree* bvhtree_from_mesh_verts(DerivedMesh *mesh, float epsilon, int tree_type, int axis)
+BVHTree* bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
{
int i;
int numVerts= mesh->getNumVerts(mesh);
MVert *vert = mesh->getVertDataArray(mesh, CD_MVERT);
BVHTree *tree = NULL;
+ if(data)
+ memset(data, 0, sizeof(*data));
+
if(vert == NULL)
{
printf("bvhtree cant be build: cant get a vertex array");
@@ -213,6 +199,19 @@
BLI_bvhtree_insert(tree, i, vert[i].co, 1);
BLI_bvhtree_balance(tree);
+
+ if(data)
+ {
+ data->tree = tree;
+ data->nearest_callback = NULL;
+ data->raycast_callback = NULL;
+
+ data->mesh = mesh;
+ data->vert = mesh->getVertDataArray(mesh, CD_MVERT);
+ data->face = mesh->getFaceDataArray(mesh, CD_MFACE);
+
+ data->sphere_radius = epsilon;
+ }
}
return tree;
@@ -221,7 +220,7 @@
/*
* Builds a bvh tree.. where nodes are the faces of the given mesh.
*/
-static BVHTree* bvhtree_from_mesh_faces(DerivedMesh *mesh, float epsilon, int tree_type, int axis)
+BVHTree* bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *mesh, float epsilon, int tree_type, int axis)
{
int i;
int numFaces= mesh->getNumFaces(mesh);
@@ -229,6 +228,9 @@
MFace *face = mesh->getFaceDataArray(mesh, CD_MFACE);
BVHTree *tree = NULL;
+ if(data)
+ memset(data, 0, sizeof(*data));
+
if(vert == NULL && face == NULL)
{
printf("bvhtree cant be build: cant get a vertex/face array");
@@ -251,6 +253,19 @@
BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3);
}
BLI_bvhtree_balance(tree);
+
+ if(data)
+ {
+ data->tree = tree;
+ data->nearest_callback = mesh_faces_nearest_point;
+ data->raycast_callback = mesh_faces_spherecast;
+
+ data->mesh = mesh;
+ data->vert = mesh->getVertDataArray(mesh, CD_MVERT);
+ data->face = mesh->getFaceDataArray(mesh, CD_MFACE);
+
+ data->sphere_radius = epsilon;
+ }
}
return tree;
@@ -262,7 +277,7 @@
*/
static void mesh_faces_nearest_point(void *userdata, int index, const float *co, BVHTreeNearest *nearest)
{
- const BVHMeshCallbackUserdata *data = (BVHMeshCallbackUserdata*) userdata;
+ const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata;
MVert *vert = data->vert;
MFace *face = data->face + index;
@@ -300,7 +315,7 @@
*/
static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
{
- const BVHMeshCallbackUserdata *data = (BVHMeshCallbackUserdata*) userdata;
+ const BVHTreeFromMesh *data = (BVHTreeFromMesh*) userdata;
MVert *vert = data->vert;
MFace *face = data->face + index;
@@ -1264,18 +1279,17 @@
int vgroup = get_named_vertexgroup_num(calc->ob, calc->smd->vgroup_name);
float tmp_co[3];
- BVHTree *tree = NULL;
+ BVHTreeFromMesh treeData;
BVHTreeNearest nearest;
int numVerts;
MVert *vert = NULL;
MDeformVert *dvert = NULL;
- BENCH_VAR(query);
- BENCH(tree = bvhtree_from_mesh_verts(calc->target, 0.0, 2, 6));
- if(tree == NULL) return OUT_OF_MEMORY();
+ bvhtree_from_mesh_verts(&treeData, calc->target, 0.0, 2, 6);
+ if(treeData.tree == NULL) return OUT_OF_MEMORY();
//Setup nearest
nearest.index = -1;
@@ -1287,7 +1301,6 @@
vert = calc->final->getVertDataArray(calc->final, CD_MVERT);
dvert = calc->final->getVertDataArray(calc->final, CD_MDEFORMVERT);
- BENCH_BEGIN(query);
for(i=0; i<numVerts; i++)
{
int index;
@@ -1303,7 +1316,7 @@
}
else nearest.dist = FLT_MAX;
- index = BLI_bvhtree_find_nearest(tree, tmp_co, &nearest, NULL, NULL);
+ index = BLI_bvhtree_find_nearest(treeData.tree, tmp_co, &nearest, treeData.nearest_callback, &treeData);
if(index != -1)
{
@@ -1315,10 +1328,8 @@
VecLerpf(vert[i].co, vert[i].co, tmp_co, weight); //linear interpolation
}
}
- BENCH_END(query);
- BENCH_REPORT(query);
- BLI_bvhtree_free(tree);
+ BLI_bvhtree_free(treeData.tree);
}
/*
@@ -1419,7 +1430,6 @@
}
*/
-
/*
* This function raycast a single vertex and updates the hit if the "hit" is considered valid.
* Returns TRUE if "hit" was updated.
@@ -1428,7 +1438,7 @@
* MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE (front faces hits are ignored)
* MOD_SHRINKWRAP_CULL_TARGET_BACKFACE (back faces hits are ignored)
*/
-static int normal_projection_project_vertex(char options, const float *vert, const float *dir, const SpaceTransform *transf, BVHTree *tree, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, BVHMeshCallbackUserdata *userdata)
+static int normal_projection_project_vertex(char options, const float *vert, const float *dir, const SpaceTransform *transf, BVHTree *tree, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
{
float tmp_co[3], tmp_no[3];
const float *co, *no;
@@ -1490,20 +1500,17 @@
char use_normal = calc->smd->shrinkOpts;
//setup raytracing
- BVHTree *tree = NULL;
+ BVHTreeFromMesh treeData;
BVHTreeRayHit hit;
- BVHMeshCallbackUserdata userdata;
- BVHTree_RayCastCallback callback = NULL;
+/*
//cutTree
DerivedMesh * limit_mesh = NULL;
- BVHTree *limit_tree = NULL;
- BVHMeshCallbackUserdata limit_userdata;
- BVHTree_RayCastCallback limit_callback = NULL;
+ BVHTreeFromMesh limitData;
SpaceTransform local2cut;
+*/
-
int numVerts;
MVert *vert = NULL;
MDeformVert *dvert = NULL;
@@ -1511,27 +1518,23 @@
if( (use_normal & (MOD_SHRINKWRAP_ALLOW_INVERTED_NORMAL | MOD_SHRINKWRAP_ALLOW_DEFAULT_NORMAL)) == 0)
return; //Nothing todo
- BENCH(tree = bvhtree_from_mesh_faces(calc->target, calc->keptDist, 4, 6));
- if(tree == NULL) return OUT_OF_MEMORY();
- bvhtree_meshcallbackdata_init(&userdata, calc->target, calc->keptDist);
- callback = mesh_faces_spherecast;
+ bvhtree_from_mesh_faces(&treeData, calc->target, calc->keptDist, 4, 6);
+ if(treeData.tree == NULL) return OUT_OF_MEMORY();
+/*
if(calc->smd->cutPlane)
{
+ space_transform_setup( &local2cut, calc->ob, calc->smd->cutPlane);
+
//TODO currently we need a copy in case object_get_derived_final returns an emDM that does not defines getVertArray or getFace array
limit_mesh = CDDM_copy( object_get_derived_final(calc->smd->cutPlane, CD_MASK_BAREMESH) );
if(limit_mesh)
- {
- BENCH(limit_tree = bvhtree_from_mesh_faces(limit_mesh, 0.0, 4, 6));
- bvhtree_meshcallbackdata_init(&limit_userdata, limit_mesh, 0.0);
- limit_callback = mesh_faces_spherecast;
-
- space_transform_setup( &local2cut, calc->ob, calc->smd->cutPlane);
- }
- else printf("CutPlane finalDerived mesh is null\n");
+ bvhtree_from_mesh_faces(&limitData, limit_mesh, 0.0, 4, 6);
+ else
+ printf("CutPlane finalDerived mesh is null\n");
}
+*/
-
//Project each vertex along normal
numVerts= calc->final->getNumVerts(calc->final);
vert = calc->final->getVertDataArray(calc->final, CD_MVERT);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list