[Bf-blender-cvs] [2eb051e] mathutils_bvhtree: find_nearest implementation for bmesh BVHTree type.

Lukas Tönne noreply at git.blender.org
Thu Dec 18 16:35:54 CET 2014


Commit: 2eb051e37dea98652f429028fc3b32afa918ad85
Author: Lukas Tönne
Date:   Thu Dec 18 16:34:51 2014 +0100
Branches: mathutils_bvhtree
https://developer.blender.org/rB2eb051e37dea98652f429028fc3b32afa918ad85

find_nearest implementation for bmesh BVHTree type.

This uses only mesh vertices, since this function is supplied by the
bmesh bvhutils. Nearest face lookup could be added later.

===================================================================

M	source/blender/python/mathutils/mathutils_bvhtree.c

===================================================================

diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c
index 29c0407..3fbb220 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -439,6 +439,7 @@ static PyObject *py_BVHTree_find_nearest(PyBVHTree *self, PyObject *args, PyObje
 	static const float ZERO[3] = {0.0f, 0.0f, 0.0f};
 	
 	BVHTreeFromMesh *meshdata = &self->meshdata;
+	BMBVHTree *bmdata = self->bmdata;
 	Object *ob = self->ob;
 	const char *keywords[] = {"point", "max_dist", "use_poly_index", NULL};
 	
@@ -472,6 +473,14 @@ static PyObject *py_BVHTree_find_nearest(PyBVHTree *self, PyObject *args, PyObje
 			return bvhtree_nearest_to_py(nearest.co, nearest.no, ret_index, nearest.dist_sq);
 		}
 	}
+	else if (bmdata) {
+		BMVert *nearest_vert;
+		
+		nearest_vert = BKE_bmbvh_find_vert_closest(bmdata, point, max_dist);
+		if (nearest_vert) {
+			return bvhtree_ray_hit_to_py(nearest_vert->co, nearest_vert->no, BM_elem_index_get(nearest_vert), len_squared_v3v3(point, nearest_vert->co));
+		}
+	}
 	
 	return bvhtree_ray_hit_to_py(ZERO, ZERO, -1, 0.0f);
 }




More information about the Bf-blender-cvs mailing list