[Bf-blender-cvs] [c69f623] viewport_bvh_select: Support selecting lamps using new BVH selection

Julian Eisel noreply at git.blender.org
Sat Aug 27 23:38:33 CEST 2016


Commit: c69f6236993790e6dbe6121bd78c3d1be3f52876
Author: Julian Eisel
Date:   Sat Aug 27 23:34:36 2016 +0200
Branches: viewport_bvh_select
https://developer.blender.org/rBc69f6236993790e6dbe6121bd78c3d1be3f52876

Support selecting lamps using new BVH selection

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

M	source/blender/blenkernel/BKE_lamp.h
M	source/blender/blenkernel/intern/lamp.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/view3d_bvh.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_intern.h

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

diff --git a/source/blender/blenkernel/BKE_lamp.h b/source/blender/blenkernel/BKE_lamp.h
index 4d53850..58be8f4 100644
--- a/source/blender/blenkernel/BKE_lamp.h
+++ b/source/blender/blenkernel/BKE_lamp.h
@@ -49,6 +49,8 @@ struct Lamp *localize_lamp(struct Lamp *la) ATTR_WARN_UNUSED_RESULT;
 void BKE_lamp_make_local(struct Main *bmain, struct Lamp *la, const bool lib_local);
 void BKE_lamp_free(struct Lamp *la);
 
+struct BoundBox *BKE_lamp_drawboundbox_get(const struct Lamp *la);
+
 void lamp_drivers_update(struct Scene *scene, struct Lamp *la, float ctime);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index e9d039a..33cd38b 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -54,6 +54,7 @@
 #include "BKE_library_remap.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
+#include "BKE_object.h"
 
 void BKE_lamp_init(Lamp *la)
 {
@@ -239,3 +240,22 @@ void lamp_drivers_update(Scene *scene, Lamp *la, float ctime)
 	la->id.tag &= ~LIB_TAG_DOIT;
 }
 
+/**
+ * Get the visual bounding box of lamps, without things like direction indicator etc (we don't
+ * want this for selecting). Should match what #drawlamp draws (keep in sync!).
+ */
+BoundBox *BKE_lamp_drawboundbox_get(const Lamp *la)
+{
+	BoundBox *bb = MEM_callocN(sizeof(*bb), "Lamp boundbox");
+
+	const bool draw_outer = la->type != LA_HEMI &&
+	                        ((la->mode & LA_SHAD_RAY) || ((la->mode & LA_SHAD_BUF) && (la->type == LA_SPOT)));
+	const float lamprad = (float)U.obcenter_dia * 1.5f + (draw_outer ? 3.0f : 0.0f);
+	const float min[3] = {-lamprad, -lamprad, -lamprad};
+	const float max[3] = {lamprad, lamprad, lamprad};
+
+	BKE_boundbox_init_from_minmax(bb, min, max);
+
+	return bb;
+}
+
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index e582284..0dd74f6 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2330,8 +2330,11 @@ BoundBox *BKE_object_drawboundbox_get(
 				bb = BKE_camera_drawboundbox_get(scene, ob);
 				*r_needs_freeing = true;
 				break;
-			case OB_EMPTY:
 			case OB_LAMP:
+				bb = BKE_lamp_drawboundbox_get(ob->data);
+				*r_needs_freeing = true;
+				break;
+			case OB_EMPTY:
 			case OB_SPEAKER:
 				/* TODO */
 			default:
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 4739057..87d3533 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -1170,6 +1170,10 @@ static void draw_transp_sun_volume(Lamp *la)
 }
 #endif
 
+/**
+ * Note: BKE_lamp_drawboundbox_get tries to give the visual boundbox of what's drawn here (without things like
+ * sun direction indicator etc). If something is changed here that might influence the boundbox, keep it in sync!
+ */
 static void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
                      const char dt, const short dflag, const unsigned char ob_wire_col[4], const bool is_obact)
 {
diff --git a/source/blender/editors/space_view3d/view3d_bvh.c b/source/blender/editors/space_view3d/view3d_bvh.c
index 29ea22f..813c083 100644
--- a/source/blender/editors/space_view3d/view3d_bvh.c
+++ b/source/blender/editors/space_view3d/view3d_bvh.c
@@ -41,13 +41,15 @@
 #include "view3d_intern.h" /* own include */
 
 
-static void bvh_objects_insert(View3D *v3d, const Scene *scene)
+static void bvh_objects_insert(View3D *v3d, const RegionView3D *rv3d, const Scene *scene)
 {
+	Object *ob;
 	int i = 0;
 	for (Base *base = scene->base.first; base; base = base->next) {
+		ob = base->object;
 		if (BASE_SELECTABLE(v3d, base)) {
 			bool needs_freeing;
-			BoundBox *bb = BKE_object_drawboundbox_get(scene, base->object, &needs_freeing);
+			BoundBox *bb = BKE_object_drawboundbox_get(scene, ob, &needs_freeing);
 			if (bb) {
 				BoundBox bb_local = *bb;
 				if (needs_freeing) {
@@ -55,7 +57,15 @@ static void bvh_objects_insert(View3D *v3d, const Scene *scene)
 				}
 
 				for (int j = 0; j < 8; j++) {
-					mul_v3_m4v3(bb_local.vec[j], base->object->obmat, bb_local.vec[j]);
+					if (ob->type == OB_LAMP) {
+						/* for lamps, only use location and zoom independent size */
+						const float pixelsize = ED_view3d_pixel_size(rv3d, ob->obmat[3]);
+						mul_v3_fl(bb_local.vec[j], pixelsize);
+						add_v3_v3(bb_local.vec[j], ob->obmat[3]);
+					}
+					else {
+						mul_m4_v3(ob->obmat, bb_local.vec[j]);
+					}
 				}
 
 				BLI_bvhtree_insert(v3d->bvhtree, i++, &bb_local.vec[0][0], 8);
@@ -70,14 +80,14 @@ static void bvh_objects_insert(View3D *v3d, const Scene *scene)
 	}
 }
 
-void view3d_objectbvh_rebuild(View3D *v3d, const Scene *scene)
+void view3d_objectbvh_rebuild(View3D *v3d, const RegionView3D *rv3d, const Scene *scene)
 {
 	BVHTree *bvhtree = v3d->bvhtree;
 	if (bvhtree) {
 		view3d_objectbvh_free(v3d);
 	}
 	v3d->bvhtree = bvhtree = BLI_bvhtree_new(BLI_listbase_count(&scene->base), FLT_EPSILON, 2, 8);
-	bvh_objects_insert(v3d, scene);
+	bvh_objects_insert(v3d, rv3d, scene);
 	BLI_bvhtree_balance(bvhtree);
 }
 
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 4627b72..11903db 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -4050,7 +4050,8 @@ void view3d_main_region_draw(const bContext *C, ARegion *ar)
 	clip_border = (render_border && !BLI_rcti_compare(&ar->drawrct, &border_rect));
 
 	if (!scene->obedit) {
-		view3d_objectbvh_rebuild(v3d, scene);
+		ED_view3d_update_viewmat(scene, v3d, ar, NULL, NULL); /* XXX */
+		view3d_objectbvh_rebuild(v3d, ar->regiondata, scene);
 	}
 
 	/* draw viewport using opengl */
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index f936f6e..c1cb4e6 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -288,7 +288,7 @@ void VIEW3D_OT_snap_cursor_to_center(struct wmOperatorType *ot);
 void VIEW3D_OT_snap_cursor_to_selected(struct wmOperatorType *ot);
 void VIEW3D_OT_snap_cursor_to_active(struct wmOperatorType *ot);
 
-void view3d_objectbvh_rebuild(View3D *v3d, const Scene *scene);
+void view3d_objectbvh_rebuild(View3D *v3d, const RegionView3D *rv3d, const Scene *scene);
 void view3d_bvh_update(View3D *v3d, const Scene *scene);
 void view3d_objectbvh_free(View3D *v3d);




More information about the Bf-blender-cvs mailing list