[Bf-blender-cvs] [24ea750659c] greasepencil-object: WIP: Boundbox for GP object
Antonio Vazquez
noreply at git.blender.org
Sat Jul 8 21:22:24 CEST 2017
Commit: 24ea750659ce6823756c0c9151c0c841c641356c
Author: Antonio Vazquez
Date: Sat Jul 8 21:22:12 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB24ea750659ce6823756c0c9151c0c841c641356c
WIP: Boundbox for GP object
This is the first implementation but cannot test because Eevee not support bounding box yet.
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/editors/space_view3d/drawobject.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index dfd126d50ed..b43c91a09a5 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -41,6 +41,8 @@ struct bGPDpalette;
struct bGPDpalettecolor;
struct Main;
struct PaletteColor;
+struct BoundBox;
+struct Object;
/* ------------ Grease-Pencil API ------------------ */
@@ -126,4 +128,7 @@ void BKE_gpencil_palettecolor_allnames(struct PaletteColor *palcolor, const char
void BKE_gpencil_palettecolor_changename(struct PaletteColor *palcolor, struct bGPdata *gpd, const char *newname);
void BKE_gpencil_palettecolor_delete_allstrokes(struct PaletteColor *palcolor);
+/* object boundbox */
+struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
+
#endif /* __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 18abedd7b3e..85c587d1cf8 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -47,6 +47,7 @@
#include "DNA_gpencil_types.h"
#include "DNA_userdef_types.h"
#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
#include "BKE_action.h"
#include "BKE_animsys.h"
@@ -55,6 +56,7 @@
#include "BKE_colortools.h"
#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_object.h"
/* Draw Engine */
void(*BKE_gpencil_batch_cache_dirty_cb)(bGPdata *gpd) = NULL;
@@ -1452,3 +1454,76 @@ void BKE_gpencil_batch_cache_alldirty()
}
}
+/* get stroke min max values */
+void static gpencil_minmax(bGPdata *gpd, float min[3], float max[3])
+{
+ int i;
+ bGPDspoint *pt;
+ bGPDframe *gpf;
+
+ for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+ gpf= gpl->actframe;
+ if (!gpf) {
+ continue;
+ }
+ for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ /* min */
+ if (pt->x < min[0]) {
+ min[0] = pt->x;
+ }
+ if (pt->y < min[1]) {
+ min[1] = pt->y;
+ }
+ if (pt->z < min[2]) {
+ min[2] = pt->z;
+ }
+ /* max */
+ if (pt->x > max[0]) {
+ max[0] = pt->x;
+ }
+ if (pt->y > max[1]) {
+ max[1] = pt->y;
+ }
+ if (pt->z > max[2]) {
+ max[2] = pt->z;
+ }
+ }
+ }
+ }
+}
+
+/* create bounding box values */
+static void boundbox_gpencil(Object *ob)
+{
+ BoundBox *bb;
+ bGPdata *gpd;
+ float min[3], max[3];
+
+ if (ob->bb == NULL) {
+ ob->bb = MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
+ }
+
+ bb = ob->bb;
+ gpd= ob->gpd;
+
+ INIT_MINMAX(min, max);
+ gpencil_minmax(gpd, min, max);
+ BKE_boundbox_init_from_minmax(bb, min, max);
+
+ bb->flag &= ~BOUNDBOX_DIRTY;
+}
+
+/* get bounding box */
+BoundBox *BKE_gpencil_boundbox_get(Object *ob)
+{
+ if ((!ob) || (ob->gpd == NULL))
+ return NULL;
+
+ if ((ob->bb) && ((ob->bb->flag & BOUNDBOX_DIRTY) == 0) && ((ob->gpd->flag & GP_DATA_CACHE_IS_DIRTY) == 0))
+ return ob->bb;
+
+ boundbox_gpencil(ob);
+
+ return ob->bb;
+}
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 1c47d9c64c8..6d7ec051cb9 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -78,6 +78,7 @@
#include "BKE_subsurf.h"
#include "BKE_unit.h"
#include "BKE_tracking.h"
+#include "BKE_gpencil.h"
#include "BKE_editmesh.h"
@@ -8146,6 +8147,9 @@ void draw_bounding_volume(Object *ob, char type, const unsigned char ob_wire_col
else if (ob->type == OB_LATTICE) {
bb = BKE_lattice_boundbox_get(ob);
}
+ else if (ob->type == OB_GPENCIL) {
+ bb = BKE_gpencil_boundbox_get(ob);
+ }
else {
const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {1.0f, 1.0f, 1.0f};
bb = &bb_local;
More information about the Bf-blender-cvs
mailing list