[Bf-blender-cvs] [4df449edd51] blender2.8: Probe: Add initial visualisation

Clément Foucault noreply at git.blender.org
Fri Jun 9 01:27:17 CEST 2017


Commit: 4df449edd51bd5602c0c7763ac4984b6de81e285
Author: Clément Foucault
Date:   Wed Jun 7 16:00:10 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB4df449edd51bd5602c0c7763ac4984b6de81e285

Probe: Add initial visualisation

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

M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/modes/object_mode.c

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

diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 06ec0f746e0..b81f7bd2201 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -67,6 +67,7 @@ static struct DRWShapeCache {
 	Batch *drw_lamp_spot;
 	Batch *drw_lamp_spot_square;
 	Batch *drw_speaker;
+	Batch *drw_probe;
 	Batch *drw_bone_octahedral;
 	Batch *drw_bone_octahedral_wire;
 	Batch *drw_bone_box;
@@ -116,6 +117,7 @@ void DRW_shape_cache_free(void)
 	BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp_spot);
 	BATCH_DISCARD_ALL_SAFE(SHC.drw_lamp_spot_square);
 	BATCH_DISCARD_ALL_SAFE(SHC.drw_speaker);
+	BATCH_DISCARD_ALL_SAFE(SHC.drw_probe);
 	BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_octahedral);
 	BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_octahedral_wire);
 	BATCH_DISCARD_ALL_SAFE(SHC.drw_bone_box);
@@ -1317,6 +1319,60 @@ Batch *DRW_cache_speaker_get(void)
 
 /* -------------------------------------------------------------------- */
 
+/** \name Probe
+ * \{ */
+
+Batch *DRW_cache_probe_get(void)
+{
+#define CIRCLE_RESOL 16
+	if (!SHC.drw_probe) {
+		int v_idx = 0;
+		float v[3] = {0.0f, 1.0f, 0.0f};
+		/* TODO something nicer than just a circle */
+
+		/* Position Only 3D format */
+		static VertexFormat format = { 0 };
+		static struct { uint pos; } attr_id;
+		if (format.attrib_ct == 0) {
+			attr_id.pos = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT);
+		}
+
+		VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+		VertexBuffer_allocate_data(vbo, (CIRCLE_RESOL + 1) * 2 + 8);
+
+		VertexBuffer_set_attrib(vbo, attr_id.pos, v_idx++, v);
+		for (int a = 1; a < CIRCLE_RESOL; a++) {
+			v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+			v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+			VertexBuffer_set_attrib(vbo, attr_id.pos, v_idx++, v);
+
+			if ((a % 2 == 0) && (a % 4 != 0)) {
+				v[0] *= 0.5f;
+				v[1] *= 0.5f;
+				VertexBuffer_set_attrib(vbo, attr_id.pos, v_idx++, v);
+				v[0] *= 3.0f;
+				v[1] *= 3.0f;
+				VertexBuffer_set_attrib(vbo, attr_id.pos, v_idx++, v);
+				v[0] /= 1.5f;
+				v[1] /= 1.5f;
+			}
+
+			VertexBuffer_set_attrib(vbo, attr_id.pos, v_idx++, v);
+		}
+		v[0] = 0.0f;
+		v[1] = 1.0f;
+		VertexBuffer_set_attrib(vbo, attr_id.pos, v_idx++, v);
+
+		SHC.drw_probe = Batch_create(PRIM_LINES, vbo, NULL);
+	}
+	return SHC.drw_probe;
+#undef CIRCLE_RESOL
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
 /** \name Armature Bones
  * \{ */
 
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index f2c140923a8..82d6dd9fd32 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -78,6 +78,9 @@ struct Batch *DRW_cache_camera_tria_get(void);
 /* Speaker */
 struct Batch *DRW_cache_speaker_get(void);
 
+/* Probe */
+struct Batch *DRW_cache_probe_get(void);
+
 /* Bones */
 struct Batch *DRW_cache_bone_octahedral_get(void);
 struct Batch *DRW_cache_bone_octahedral_wire_outline_get(void);
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 4c2ef6ea29f..ec1f6da7ff2 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -142,6 +142,9 @@ typedef struct OBJECT_PrivateData{
 	/* Speaker */
 	DRWShadingGroup *speaker;
 
+	/* Speaker */
+	DRWShadingGroup *probe;
+
 	/* Lamps */
 	DRWShadingGroup *lamp_center;
 	DRWShadingGroup *lamp_center_group;
@@ -902,6 +905,11 @@ static void OBJECT_cache_init(void *vedata)
 		geom = DRW_cache_speaker_get();
 		stl->g_data->speaker = shgroup_instance(psl->non_meshes, geom);
 
+		/* Probe */
+		static float probeSize = 10.0f;
+		geom = DRW_cache_probe_get();
+		stl->g_data->probe = shgroup_instance_screenspace(psl->non_meshes, geom, &probeSize);
+
 		/* Camera */
 		geom = DRW_cache_camera_get();
 		stl->g_data->camera = shgroup_camera_instance(psl->non_meshes, geom);
@@ -1399,6 +1407,14 @@ static void DRW_shgroup_speaker(OBJECT_StorageList *stl, Object *ob, SceneLayer
 	DRW_shgroup_call_dynamic_add(stl->g_data->speaker, color, &one, ob->obmat);
 }
 
+static void DRW_shgroup_probe(OBJECT_StorageList *stl, Object *ob, SceneLayer *sl)
+{
+	float *color;
+	DRW_object_wire_theme_get(ob, sl, &color);
+
+	DRW_shgroup_call_dynamic_add(stl->g_data->probe, ob->obmat[3], color);
+}
+
 static void DRW_shgroup_relationship_lines(OBJECT_StorageList *stl, Object *ob)
 {
 	if (ob->parent && ((ob->parent->base_flag & BASE_VISIBLED) != 0)) {
@@ -1596,6 +1612,9 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
 		case OB_SPEAKER:
 			DRW_shgroup_speaker(stl, ob, sl);
 			break;
+		case OB_PROBE:
+			DRW_shgroup_probe(stl, ob, sl);
+			break;
 		case OB_ARMATURE:
 		{
 			bArmature *arm = ob->data;




More information about the Bf-blender-cvs mailing list