[Bf-blender-cvs] [a50b173952] master: Use the same solution to test the pixel distance to the AABB, with BoundBox

Germano Cavalcante noreply at git.blender.org
Tue Jan 31 02:28:16 CET 2017


Commit: a50b173952c85a51828f28569a9923bd29764292
Author: Germano Cavalcante
Date:   Mon Jan 30 22:27:38 2017 -0300
Branches: master
https://developer.blender.org/rBa50b173952c85a51828f28569a9923bd29764292

Use the same solution to test the pixel distance to the AABB, with BoundBox

The previous solution took arbitrary values to determine if the mouse was near or not to the Bound Box (it simply scaled the Bound Box).

Now the same function that detected the distance from the BVHTree nodes to the mouse is used in the Bound Box

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

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/transform/transform_snap_object.c

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

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 4349e68f7c..d812ab832a 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -139,7 +139,6 @@ void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], cons
 void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3]);
 void BKE_boundbox_calc_size_aabb(const struct BoundBox *bb, float r_size[3]);
 void BKE_boundbox_minmax(const struct BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3]);
-void BKE_boundbox_scale(struct BoundBox *bb_dst, const struct BoundBox *bb_src, float scale);
 struct BoundBox *BKE_boundbox_ensure_minimum_dimensions(
         struct BoundBox *bb, struct BoundBox *bb_temp, const float epsilon);
 
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 09b3a7312b..e5393666a7 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1204,7 +1204,7 @@ void BKE_object_make_local_ex(Main *bmain, Object *ob, const bool lib_local, con
 	if (lib_local || is_local) {
 		if (!is_lib) {
 			id_clear_lib_data(bmain, &ob->id);
-			BKE_id_expand_local(bmain, &ob->id);
+			BKE_id_expand_local(&ob->id);
 			if (clear_proxy) {
 				if (ob->proxy_from != NULL) {
 					ob->proxy_from->proxy = NULL;
@@ -2236,18 +2236,6 @@ void BKE_boundbox_minmax(const BoundBox *bb, float obmat[4][4], float r_min[3],
 	}
 }
 
-void BKE_boundbox_scale(struct BoundBox *bb_dst, const struct BoundBox *bb_src, float scale)
-{
-	float cent[3];
-	BKE_boundbox_calc_center_aabb(bb_src, cent);
-
-	for (int i = 0; i < ARRAY_SIZE(bb_dst->vec); i++) {
-		bb_dst->vec[i][0] = ((bb_src->vec[i][0] - cent[0]) * scale) + cent[0];
-		bb_dst->vec[i][1] = ((bb_src->vec[i][1] - cent[1]) * scale) + cent[1];
-		bb_dst->vec[i][2] = ((bb_src->vec[i][2] - cent[2]) * scale) + cent[2];
-	}
-}
-
 /**
  * Returns a BBox which each dimensions are at least epsilon.
  * \note In case a given dimension needs to be enlarged, its final value will be in [epsilon, 3 * epsilon] range.
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 3f8e1176f3..5d9892cd50 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -244,7 +244,7 @@ typedef struct BVHTreeFromMeshType {
 	char type;
 } BVHTreeFromMeshType;
 
-/*
+/**
  * Generates a struct with the immutable parameters that will be used on all objects.
  *
  * \param snap_to: Element to snap, Vertice, Edge or Face.
@@ -376,15 +376,7 @@ static bool test_projected_edge_dist(
 	dist_squared_ray_to_seg_v3(ray_start, ray_dir, va, vb, tmp_co, &depth);
 	return test_projected_vert_dist(depth_range, mval, tmp_co, pmat, win_half, is_persp, dist_px_sq, r_co);
 }
-
-/** \} */
-
-
-/* -------------------------------------------------------------------- */
-
-/** \Walk DFS
- * \{ */
-typedef struct Object_Nearest2dPrecalc {
+typedef struct Nearest2dPrecalc {
 	float ray_origin_local[3];
 	float ray_direction_local[3];
 	float ray_inv_dir[3];
@@ -392,76 +384,65 @@ typedef struct Object_Nearest2dPrecalc {
 	float depth_range[2];
 	float pmat[4][4]; /* perspective matrix multiplied by object matrix */
 	float win_half[2];
-	bool is_persp;
-	float dist_px_sq;
 
 	float mval[2];
 	bool sign[3];
-	bool r_axis_closest[3];
-
-	void *userdata;
-	int index;
-	float co[3];
-	float no[3];
-} Object_Nearest2dPrecalc;
-
+} Nearest2dPrecalc;
 
-static void nearest2d_precalc(
-        Object_Nearest2dPrecalc *neasrest_precalc, SnapData *snapdata,
-        const float dist_px, float obmat[4][4],
+/**
+ * \param lpmat: Perspective matrix multiplied by object matrix
+ */
+static void dist_squared_to_projected_aabb_precalc(
+        struct Nearest2dPrecalc *neasrest_precalc,
+        float lpmat[4][4], const float win_half[2],
+        const float depth_range[2], const float mval[2],
         const float ray_origin_local[3], const float ray_direction_local[3])
 {
-	if (obmat) {
-		mul_m4_m4m4(neasrest_precalc->pmat, snapdata->pmat, obmat);
-	}
-	else {
-		copy_m4_m4(neasrest_precalc->pmat, snapdata->pmat);
-	}
-	copy_v2_v2(neasrest_precalc->win_half, snapdata->win_half);
-	neasrest_precalc->dist_px_sq = SQUARE(dist_px);
-	neasrest_precalc->is_persp = snapdata->view_proj == VIEW_PROJ_PERSP;
-	copy_v2_v2(neasrest_precalc->depth_range, snapdata->depth_range);
+	copy_m4_m4(neasrest_precalc->pmat, lpmat);
+	copy_v2_v2(neasrest_precalc->win_half, win_half);
+	copy_v2_v2(neasrest_precalc->depth_range, depth_range);
 
 	copy_v3_v3(neasrest_precalc->ray_origin_local, ray_origin_local);
 	copy_v3_v3(neasrest_precalc->ray_direction_local, ray_direction_local);
-	copy_v2_v2(neasrest_precalc->mval, snapdata->mval);
+	copy_v2_v2(neasrest_precalc->mval, mval);
 
 	for (int i = 0; i < 3; i++) {
-		neasrest_precalc->ray_inv_dir[i] = 
+		neasrest_precalc->ray_inv_dir[i] =
 		        (neasrest_precalc->ray_direction_local[i] != 0.0f) ?
 		        (1.0f / neasrest_precalc->ray_direction_local[i]) : FLT_MAX;
 		neasrest_precalc->sign[i] = (neasrest_precalc->ray_inv_dir[i] < 0.0f);
-		neasrest_precalc->r_axis_closest[i] = true;
 	}
 }
 
-static bool cb_walk_parent_snap_project(const BVHTreeAxisRange *bounds, void *user_data)
+static float dist_squared_to_projected_aabb(
+        struct Nearest2dPrecalc *data,
+        const float bbmin[3], const float bbmax[3],
+        bool r_axis_closest[3])
 {
-	Object_Nearest2dPrecalc *data = user_data;
 	float local_bvmin[3], local_bvmax[3];
 	if (data->sign[0]) {
-		local_bvmin[0] = bounds[0].max;
-		local_bvmax[0] = bounds[0].min;
+		local_bvmin[0] = bbmax[0];
+		local_bvmax[0] = bbmin[0];
 	}
 	else {
-		local_bvmin[0] = bounds[0].min;
-		local_bvmax[0] = bounds[0].max;
+		local_bvmin[0] = bbmin[0];
+		local_bvmax[0] = bbmax[0];
 	}
 	if (data->sign[1]) {
-		local_bvmin[1] = bounds[1].max;
-		local_bvmax[1] = bounds[1].min;
+		local_bvmin[1] = bbmax[1];
+		local_bvmax[1] = bbmin[1];
 	}
 	else {
-		local_bvmin[1] = bounds[1].min;
-		local_bvmax[1] = bounds[1].max;
+		local_bvmin[1] = bbmin[1];
+		local_bvmax[1] = bbmax[1];
 	}
 	if (data->sign[2]) {
-		local_bvmin[2] = bounds[2].max;
-		local_bvmax[2] = bounds[2].min;
+		local_bvmin[2] = bbmax[2];
+		local_bvmax[2] = bbmin[2];
 	}
 	else {
-		local_bvmin[2] = bounds[2].min;
-		local_bvmax[2] = bounds[2].max;
+		local_bvmin[2] = bbmin[2];
+		local_bvmax[2] = bbmax[2];
 	}
 
 	const float tmin[3] = {
@@ -484,38 +465,38 @@ static bool cb_walk_parent_snap_project(const BVHTreeAxisRange *bounds, void *us
 		rtmax = tmax[0];
 		va[0] = vb[0] = local_bvmax[0];
 		main_axis = 3;
-		data->r_axis_closest[0] = data->sign[0];
+		r_axis_closest[0] = data->sign[0];
 	}
 	else if ((tmax[1] <= tmax[0]) && (tmax[1] <= tmax[2])) {
 		rtmax = tmax[1];
 		va[1] = vb[1] = local_bvmax[1];
 		main_axis = 2;
-		data->r_axis_closest[1] = data->sign[1];
+		r_axis_closest[1] = data->sign[1];
 	}
 	else {
 		rtmax = tmax[2];
 		va[2] = vb[2] = local_bvmax[2];
 		main_axis = 1;
-		data->r_axis_closest[2] = data->sign[2];
+		r_axis_closest[2] = data->sign[2];
 	}
 
 	if ((tmin[0] >= tmin[1]) && (tmin[0] >= tmin[2])) {
 		rtmin = tmin[0];
 		va[0] = vb[0] = local_bvmin[0];
 		main_axis -= 3;
-		data->r_axis_closest[0] = !data->sign[0];
+		r_axis_closest[0] = !data->sign[0];
 	}
 	else if ((tmin[1] >= tmin[0]) && (tmin[1] >= tmin[2])) {
 		rtmin = tmin[1];
 		va[1] = vb[1] = local_bvmin[1];
 		main_axis -= 1;
-		data->r_axis_closest[1] = !data->sign[1];
+		r_axis_closest[1] = !data->sign[1];
 	}
 	else {
 		rtmin = tmin[2];
 		va[2] = vb[2] = local_bvmin[2];
 		main_axis -= 2;
-		data->r_axis_closest[2] = !data->sign[2];
+		r_axis_closest[2] = !data->sign[2];
 	}
 	if (main_axis < 0) {
 		main_axis += 3;
@@ -531,13 +512,13 @@ static bool cb_walk_parent_snap_project(const BVHTreeAxisRange *bounds, void *us
 			float dvec[3];
 			sub_v3_v3v3(dvec, local_bvmax, data->ray_origin_local);
 			if (dot_v3v3(dvec, data->ray_direction_local) < (data->depth_range[0])) {
-				return false;
+				return FLT_MAX;
 			}
 		}
 #endif
 		const float proj = rtmin * data->ray_direction_local[main_axis];
-		data->r_axis_closest[main_axis] = (proj - va[main_axis]) < (vb[main_axis] - proj);
-		return true;
+		r_axis_closest[main_axis] = (proj - va[main_axis]) < (vb[main_axis] - proj);
+		return 0.0f;
 	}
 #ifdef IGNORE_BEHIND_RAY
 	/* `if rtmin < depth_min`, the hit is behing us */
@@ -546,7 +527,7 @@ static bool cb_walk_parent_snap_project(const BVHTreeAxisRange *bounds, void *us
 		float dvec[3];
 		sub_v3_v3v3(dvec, local_bvmax, data->ray_origin_local);
 		if (dot_v3v3(dvec, data->ray_direction_local) < (data->depth_range[0])) {
-			return false;
+			return FLT_MAX;
 		}
 	}
 #endif
@@ -598,28 +579,90 @@ static bool cb_walk_parent_snap_project(const BVHTreeAxisRange *bounds, void *us
 		lambda /= edge[0] * edge[0] + edge[1] * edge[1];
 		if (lambda <= 0.0f) {
 			rdist = len_squared_v2v2(data->mval, va2d);
-			data->r_axis_closest[main_axis] = true;
+			r_axis_closest[main_axis] = true;
 		}
 		else if (lambda >= 1.0f) {
 			rdist = len_squared_v2v2(data->mval, vb2d);
-			data->r_axis_closest[main_axis] = false;
+			r_axis_closest[main_axis] = false;
 		}
 		else {
 			va2d[0] += edge[0] * lambda;
 			va2d[1] += edge[1] * lambda;
 			rdist = len_squared_v2v2(data->mval, va2d);
-			data->r_axis_closest[main_axis] = lambda < 0.5f;
+			r_axis_closest[main_axis] = lambda < 0.5f;
 		}
 	}
 	else {
 		rdist = len_squared_v2v2(data->mval, va2d);
 	}
+	return rdist;
+}
+
+static float dist_squared_to_projected_aabb_simple(
+        float lpmat[4][4], const float win_half[2],
+        const float depth_range[2], const float mval[2],
+        const float ray_origin_local[3], const float ray_direction_local[3],
+        const float bbmin[3], const float bbmax[3])
+{
+	struct Nearest2dPrecalc data;
+	dist_squared_to_projected_aabb_precalc(
+	        &data, lpmat, win_half, depth_range,
+	        mval, ray_origin_local, ray_direction_local);
+
+	bool dummy[3] = {true, true, true};
+	return dist_squared_to_projected_aabb(&data, bbmin, b

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list