[Bf-blender-cvs] [68a891f] viewport_bvh_select: Support selecting empties using new BVH selection

Julian Eisel noreply at git.blender.org
Sun Aug 28 03:43:42 CEST 2016


Commit: 68a891f2e5ebc2b6ea6c4a7c0ef991f789915585
Author: Julian Eisel
Date:   Sun Aug 28 03:38:51 2016 +0200
Branches: viewport_bvh_select
https://developer.blender.org/rB68a891f2e5ebc2b6ea6c4a7c0ef991f789915585

Support selecting empties using new BVH selection

Adding support for all empty draw types was a bit more involved, but things work now ;)

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

A	source/blender/blenkernel/BKE_empty.h
M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/empty.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_vector_inline.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/source/blender/blenkernel/BKE_empty.h b/source/blender/blenkernel/BKE_empty.h
new file mode 100644
index 0000000..cc814d0
--- /dev/null
+++ b/source/blender/blenkernel/BKE_empty.h
@@ -0,0 +1,48 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_EMPTY_H__
+#define __BKE_EMPTY_H__
+
+/** \file BKE_empty.h
+ *  \ingroup bke
+ *  \brief General operations for empties (object type).
+ */
+
+struct Image;
+struct ImBuf;
+struct Object;
+
+void BKE_empty_draw_type_set(struct Object *ob, const int value);
+
+struct BoundBox *BKE_empty_drawboundbox_get(const struct Object *ob);
+
+void BKE_empty_imbuf_get(
+        const struct Object *ob,
+        struct Image **r_ima, struct ImBuf **r_ibuf);
+
+void BKE_empty_image_size_get_ex(
+        const struct Object *ob, struct Image *ima, struct ImBuf *ibuf,
+        float r_size_xy[2], float r_scale_xy[2]);
+void BKE_empty_image_size_get(
+        const struct Object *ob,
+        float r_size_xy[2], float r_scale_xy[2]);
+
+#endif /* __BKE_EMPTY_H__ */
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 3da0560..fc4dfdb 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -152,7 +152,6 @@ struct BoundBox *BKE_object_drawboundbox_get(
         bool *r_needs_freeing);
 void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
 void BKE_object_dimensions_set(struct Object *ob, const float value[3]);
-void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
 void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set);
 void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
 bool BKE_object_minmax_dupli(struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 157c440..45fb8d1 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -102,6 +102,7 @@ set(SRC
 	intern/editmesh.c
 	intern/editmesh_bvh.c
 	intern/effect.c
+	intern/empty.c
 	intern/fcurve.c
 	intern/fluidsim.c
 	intern/fmodifier.c
@@ -229,6 +230,7 @@ set(SRC
 	BKE_editmesh.h
 	BKE_editmesh_bvh.h
 	BKE_effect.h
+	BKE_empty.h
 	BKE_fcurve.h
 	BKE_fluidsim.h
 	BKE_font.h
diff --git a/source/blender/blenkernel/intern/empty.c b/source/blender/blenkernel/intern/empty.c
new file mode 100644
index 0000000..daaf808
--- /dev/null
+++ b/source/blender/blenkernel/intern/empty.c
@@ -0,0 +1,185 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/empty.c
+ *  \ingroup bke
+ */
+
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_empty.h"
+#include "BKE_image.h"
+#include "BKE_object.h"
+
+#include "DNA_object_types.h"
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
+#include "MEM_guardedalloc.h"
+
+
+void BKE_empty_draw_type_set(Object *ob, const int value)
+{
+	ob->empty_drawtype = value;
+
+	if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
+		if (!ob->iuser) {
+			ob->iuser = MEM_callocN(sizeof(ImageUser), "image user");
+			ob->iuser->ok = 1;
+			ob->iuser->frames = 100;
+			ob->iuser->sfra = 1;
+			ob->iuser->fie_ima = 2;
+		}
+	}
+	else {
+		if (ob->iuser) {
+			MEM_freeN(ob->iuser);
+			ob->iuser = NULL;
+		}
+	}
+}
+
+BoundBox *BKE_empty_drawboundbox_get(const Object *ob)
+{
+	const float size = ob->empty_drawsize;
+	float min[3] = {0.0f};
+	float max[3] = {0.0f};
+
+	BLI_assert(ob->type == OB_EMPTY);
+
+	switch (ob->empty_drawtype) {
+		case OB_ARROWS:
+			min[0] = min[1] = -size * 0.08f;
+			copy_v3_fl(max, size);
+			break;
+		case OB_CIRCLE:
+			min[0] = min[2] = -size;
+			max[0] = max[2] = size;
+			break;
+		case OB_SINGLE_ARROW:
+			min[0] = min[1] = -size * 0.035f;
+			max[0] = max[1] = size * 0.035f;
+			max[2] = size;
+			break;
+		case OB_EMPTY_CONE:
+			min[0] = min[2] = -size;
+			max[0] = max[2] = size;
+			max[1] = size * 2.0f;
+			break;
+		case OB_EMPTY_IMAGE:
+		{
+			/* get correct image size */
+			float img_size[2], img_scale[2];
+			BKE_empty_image_size_get(ob, img_size, img_scale);
+			mul_v2_v2v2(max, img_size, img_scale);
+
+			/* apply offset */
+			float ofs[2];
+			mul_v2_v2v2(ofs, ob->ima_ofs, img_size);
+			mul_v2_v2(ofs, img_scale);
+			add_v2_v2(min, ofs);
+			add_v2_v2(max, ofs);
+			break;
+		}
+		default:
+			copy_v3_fl(min, -size);
+			copy_v3_fl(max, size);
+			break;
+	}
+
+	BoundBox *bb = MEM_callocN(sizeof(*bb), "Empty Boundbox");
+	BKE_boundbox_init_from_minmax(bb, min, max);
+
+	return bb;
+}
+
+/**
+ * \note Need to free \a r_ibuf using #BKE_image_release_ibuf.
+ */
+void BKE_empty_imbuf_get(const Object *ob, Image **r_ima, ImBuf **r_ibuf)
+{
+	BLI_assert(ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE);
+
+	*r_ima = ob->data;
+	*r_ibuf = BKE_image_acquire_ibuf(*r_ima, ob->iuser, NULL);
+
+	if (*r_ibuf && ((*r_ibuf)->rect == NULL) && ((*r_ibuf)->rect_float != NULL)) {
+		IMB_rect_from_float(* r_ibuf);
+	}
+}
+
+void BKE_empty_image_size_get_ex(
+        const Object *ob, Image *ima, ImBuf *ibuf,
+        float r_size_xy[2], float r_scale_xy[2])
+{
+	float sca_x = 1.0f;
+	float sca_y = 1.0f;
+	int ima_x, ima_y;
+
+	BLI_assert(ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE);
+	BLI_assert(r_size_xy || r_scale_xy);
+
+	/* Get the buffer dimensions so we can fallback to fake ones */
+	if (ibuf && ibuf->rect) {
+		ima_x = ibuf->x;
+		ima_y = ibuf->y;
+	}
+	else {
+		ima_x = 1;
+		ima_y = 1;
+	}
+
+	/* Get the image aspect even if the buffer is invalid */
+	if (ima) {
+		if (ima->aspx > ima->aspy) {
+			sca_y = ima->aspy / ima->aspx;
+		}
+		else if (ima->aspx < ima->aspy) {
+			sca_x = ima->aspx / ima->aspy;
+		}
+	}
+
+	/* Calculate Image scale */
+	const float scale = ob->empty_drawsize / max_ff((float)ima_x * sca_x, (float)ima_y * sca_y);
+
+	if (r_size_xy) {
+		r_size_xy[0] = ima_x;
+		r_size_xy[1] = ima_y;
+	}
+	if (r_scale_xy) {
+		r_scale_xy[0] = scale * sca_x;
+		r_scale_xy[1] = scale * sca_y;
+	}
+}
+
+void BKE_empty_image_size_get(const Object *ob, float r_size_xy[2], float r_scale_xy[2])
+{
+	Image *ima = NULL;
+	ImBuf *ibuf = NULL;
+
+	BKE_empty_imbuf_get(ob, &ima, &ibuf);
+	BKE_empty_image_size_get_ex(ob, ima, ibuf, r_size_xy, r_scale_xy);
+
+	if (ibuf) {
+		BKE_image_release_ibuf(ima, ibuf, NULL);
+	}
+}
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 546090b..70db0b6 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -86,6 +86,7 @@
 #include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_effect.h"
+#include "BKE_empty.h"
 #include "BKE_fcurve.h"
 #include "BKE_group.h"
 #include "BKE_icons.h"
@@ -2323,23 +2324,21 @@ BoundBox *BKE_object_drawboundbox_get(
 {
 	BoundBox *bb = BKE_object_boundbox_get((Object *)ob);
 
-	*r_needs_freeing = false;
+	*r_needs_freeing = (bb == NULL);
 	if (!bb) {
 		switch (ob->type) {
 			case OB_CAMERA:
 				bb = BKE_camera_drawboundbox_get(scene, ob);
-				*r_needs_freeing = true;
+				break;
+			case OB_EMPTY:
+				bb = BKE_empty_drawboundbox_get(ob);
 				break;
 			case OB_LAMP:
 				bb = BKE_lamp_drawboundbox_get(ob->data);
-				*r_needs_freeing = true;
 				break;
 			case OB_SPEAKER:
 				bb = BKE_speaker_drawboundbox_get();
-				*r_needs_freeing = true;
 				break;
-			case OB_EMPTY:
-				/* TODO */
 			default:
 				break;
 		}
@@ -2479,27 +2478,6 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool us
 	}
 }
 
-void BKE_object_empty_draw_type_set(Object *ob, const int value)
-{
-	ob->empty_drawtype = value;
-
-	if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
-		if (!ob->iuser) {
-			ob->iuser = MEM_callocN(sizeof(ImageUser), "image user");
-			ob->iuser->ok = 1;
-			ob->iuser->frames = 100;
-			ob->iuser->sfra = 1;
-			ob->iuser->fie_ima = 2;
-		}
-	}
-	else {
-		if (ob->iuser) {
-			MEM_freeN(ob->iuser);
-			ob->iuser = NULL;
-		}
-	}
-}
-
 bool BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
 {
 	bool ok = false;
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index d15fe1a..7fae8dd 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -117,6 +117,7 @@ MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f);
 MINLINE void mul_v3_fl(float r[3], float f);
 MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f);
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list