[Bf-blender-cvs] [abe0527e0fa] blender2.8: Manipulators: use nearest manipulator

Campbell Barton noreply at git.blender.org
Wed Jul 19 12:14:04 CEST 2017


Commit: abe0527e0fa77f15de4ebc7a7752a4c1375de1f1
Author: Campbell Barton
Date:   Wed Jul 19 20:12:24 2017 +1000
Branches: blender2.8
https://developer.blender.org/rBabe0527e0fa77f15de4ebc7a7752a4c1375de1f1

Manipulators: use nearest manipulator

Add utility function to get the nearest hit

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

M	source/blender/gpu/GPU_select.h
M	source/blender/gpu/intern/gpu_select.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c

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

diff --git a/source/blender/gpu/GPU_select.h b/source/blender/gpu/GPU_select.h
index cf5b8bf7d8f..0617d58f3b6 100644
--- a/source/blender/gpu/GPU_select.h
+++ b/source/blender/gpu/GPU_select.h
@@ -56,4 +56,7 @@ void GPU_select_cache_begin(void);
 void GPU_select_cache_load_id(void);
 void GPU_select_cache_end(void);
 
+/* utilities */
+const uint *GPU_select_buffer_near(const uint *buffer, int hits);
+
 #endif
diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c
index 162a605ef3d..affc96b2843 100644
--- a/source/blender/gpu/intern/gpu_select.c
+++ b/source/blender/gpu/intern/gpu_select.c
@@ -227,3 +227,29 @@ bool GPU_select_is_cached(void)
 {
 	return g_select_state.use_cache && gpu_select_pick_is_cached();
 }
+
+
+/* ----------------------------------------------------------------------------
+ * Utilities
+ */
+
+/**
+ * Helper function, nothing special but avoids doing inline since hit's aren't sorted by depth
+ * and purpose of 4x buffer indices isn't so clear.
+ *
+ * Note that comparing depth as uint is fine.
+ */
+const uint *GPU_select_buffer_near(const uint *buffer, int hits)
+{
+	const uint *buffer_near = NULL;
+	uint depth_min = (uint)-1;
+	for (int i = 0; i < hits; i++) {
+		if (buffer[1] < depth_min) {
+			BLI_assert(buffer[3] != -1);
+			depth_min = buffer[1];
+			buffer_near = buffer;
+		}
+		buffer += 4;
+	}
+	return buffer_near;
+}
\ No newline at end of file
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
index f5ef5572fd4..9507282192f 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
@@ -367,7 +367,6 @@ static int manipulator_find_intersected_3d_intern(
 	GLuint buffer[MAXPICKBUF];
 	short hits;
 	const bool do_passes = GPU_select_query_check_active();
-
 	rect.xmin = co[0] - hotspot;
 	rect.xmax = co[0] + hotspot;
 	rect.ymin = co[1] - hotspot;
@@ -392,7 +391,9 @@ static int manipulator_find_intersected_3d_intern(
 
 	ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_scene(C), ar, v3d, NULL, NULL, NULL);
 
-	return hits > 0 ? buffer[3] : -1;
+	const GLuint *hit_near = GPU_select_buffer_near(buffer, hits);
+
+	return hit_near ? hit_near[3] : -1;
 }
 
 /**




More information about the Bf-blender-cvs mailing list