[Bf-blender-cvs] [0e94d910489] blender2.8: Draw Manager: pose-mode custom bone display

Campbell Barton noreply at git.blender.org
Fri Apr 28 14:27:34 CEST 2017


Commit: 0e94d910489e2bd4a23573c315fee26b740af3a4
Author: Campbell Barton
Date:   Fri Apr 28 22:30:21 2017 +1000
Branches: blender2.8
https://developer.blender.org/rB0e94d910489e2bd4a23573c315fee26b740af3a4

Draw Manager: pose-mode custom bone display

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

M	source/blender/draw/intern/draw_armature.c
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h

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

diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c
index 64568d92efc..9a4c996837f 100644
--- a/source/blender/draw/intern/draw_armature.c
+++ b/source/blender/draw/intern/draw_armature.c
@@ -107,6 +107,28 @@ static void DRW_shgroup_bone_octahedral_wire(const float (*bone_mat)[4], const f
 	DRW_shgroup_call_dynamic_add(g_data.bone_octahedral_wire, bone_mat, color);
 }
 
+/* Custom (geometry) */
+
+static void DRW_shgroup_bone_custom_solid(const float (*bone_mat)[4], const float color[4], Object *custom)
+{
+	/* grr, not re-using instances! */
+	struct Batch *geom = DRW_cache_object_surface_get(custom);
+	if (geom) {
+		DRWShadingGroup *shgrp_geom_solid = shgroup_instance_objspace_solid(g_data.bone_solid, geom, g_data.ob->obmat);
+		DRW_shgroup_call_dynamic_add(shgrp_geom_solid, bone_mat, color);
+	}
+}
+
+static void DRW_shgroup_bone_custom_wire(const float (*bone_mat)[4], const float color[4], Object *custom)
+{
+	/* grr, not re-using instances! */
+	struct Batch *geom = DRW_cache_object_wire_get(custom);
+	if (geom) {
+		DRWShadingGroup *shgrp_geom_wire = shgroup_instance_objspace_wire(g_data.bone_wire, geom, g_data.ob->obmat);
+		DRW_shgroup_call_dynamic_add(shgrp_geom_wire, bone_mat, color);
+	}
+}
+
 /* Head and tail sphere */
 static void DRW_shgroup_bone_point_solid(const float (*bone_mat)[4], const float color[4])
 {
@@ -289,7 +311,7 @@ static const float *get_bone_wire_color(const EditBone *eBone, const bPoseChanne
 /** \name Helper Utils
  * \{ */
 
-static void draw_bone_update_disp_matrix(EditBone *eBone, bPoseChannel *pchan, int drawtype)
+static void draw_bone_update_disp_matrix_default(EditBone *eBone, bPoseChannel *pchan)
 {
 	float s[4][4], ebmat[4][4];
 	float length;
@@ -316,27 +338,30 @@ static void draw_bone_update_disp_matrix(EditBone *eBone, bPoseChannel *pchan, i
 		disp_tail_mat = eBone->disp_tail_mat;
 	}
 
-	if (pchan && pchan->custom) {
-		/* TODO */
-	}
-	else if (drawtype == ARM_ENVELOPE) {
-		/* TODO */
-	}
-	else if (drawtype == ARM_LINE) {
-		/* TODO */
-	}
-	else if (drawtype == ARM_WIRE) {
-		/* TODO */
-	}
-	else if (drawtype == ARM_B_BONE) {
-		/* TODO */
-	}
-	else {
-		scale_m4_fl(s, length);
-		mul_m4_m4m4(disp_mat, bone_mat, s);
-		copy_m4_m4(disp_tail_mat, disp_mat);
-		translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f);
-	}
+	scale_m4_fl(s, length);
+	mul_m4_m4m4(disp_mat, bone_mat, s);
+	copy_m4_m4(disp_tail_mat, disp_mat);
+	translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f);
+}
+
+static void draw_bone_update_disp_matrix_custom(bPoseChannel *pchan)
+{
+	float s[4][4];
+	float length;
+	float (*bone_mat)[4];
+	float (*disp_mat)[4];
+	float (*disp_tail_mat)[4];
+
+	/* See TODO above */
+	length = PCHAN_CUSTOM_DRAW_SIZE(pchan);
+	bone_mat = pchan->pose_mat;
+	disp_mat = pchan->disp_mat;
+	disp_tail_mat = pchan->disp_tail_mat;
+
+	scale_m4_fl(s, length);
+	mul_m4_m4m4(disp_mat, bone_mat, s);
+	copy_m4_m4(disp_tail_mat, disp_mat);
+	translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f);
 }
 
 static void draw_axes(EditBone *eBone, bPoseChannel *pchan)
@@ -414,10 +439,23 @@ static void draw_points(
  * \{ */
 
 static void draw_bone_custom_shape(
-        EditBone *UNUSED(eBone), bPoseChannel *UNUSED(pchan), bArmature *UNUSED(arm),
-        const int UNUSED(select_id))
+        EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
+        const int select_id)
 {
-	/* work in progress  -- fclem */
+	const float *col_solid = get_bone_solid_color(eBone, pchan, arm);
+	const float *col_wire = get_bone_wire_color(eBone, pchan, arm);
+	const float (*disp_mat)[4] = pchan->custom_tx ? pchan->custom_tx->disp_mat : pchan->disp_mat;
+
+	if (select_id != -1) {
+		DRW_select_load_id(select_id | BONESEL_BONE);
+	}
+
+	DRW_shgroup_bone_custom_solid(disp_mat, col_solid, pchan->custom);
+	DRW_shgroup_bone_custom_wire(disp_mat, col_wire, pchan->custom);
+
+	if (select_id != -1) {
+		DRW_select_load_id(-1);
+	}
 }
 
 static void draw_bone_envelope(
@@ -493,21 +531,24 @@ static void draw_armature_edit(Object *ob)
 			if ((eBone->flag & BONE_HIDDEN_A) == 0) {
 				const int select_id = is_select ? index : (unsigned int)-1;
 
-				draw_bone_update_disp_matrix(eBone, NULL, arm->drawtype);
-
 				if (arm->drawtype == ARM_ENVELOPE) {
+					draw_bone_update_disp_matrix_default(eBone, NULL);
 					draw_bone_envelope(eBone, NULL, arm, select_id);
 				}
 				else if (arm->drawtype == ARM_LINE) {
+					draw_bone_update_disp_matrix_default(eBone, NULL);
 					draw_bone_line(eBone, NULL, arm, select_id);
 				}
 				else if (arm->drawtype == ARM_WIRE) {
+					draw_bone_update_disp_matrix_default(eBone, NULL);
 					draw_bone_wire(eBone, NULL, arm, select_id);
 				}
 				else if (arm->drawtype == ARM_B_BONE) {
+					draw_bone_update_disp_matrix_default(eBone, NULL);
 					draw_bone_box(eBone, NULL, arm, select_id);
 				}
 				else {
+					draw_bone_update_disp_matrix_default(eBone, NULL);
 					draw_bone_octahedral(eBone, NULL, arm, select_id);
 				}
 
@@ -576,24 +617,29 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
 			if (bone->layer & arm->layer) {
 				const int select_id = is_pose_select ? index : (unsigned int)-1;
 
-				draw_bone_update_disp_matrix(NULL, pchan, arm->drawtype);
 
 				if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
+					draw_bone_update_disp_matrix_custom(pchan);
 					draw_bone_custom_shape(NULL, pchan, arm, select_id);
 				}
 				else if (arm->drawtype == ARM_ENVELOPE) {
+					draw_bone_update_disp_matrix_default(NULL, pchan);
 					draw_bone_envelope(NULL, pchan, arm, select_id);
 				}
 				else if (arm->drawtype == ARM_LINE) {
+					draw_bone_update_disp_matrix_default(NULL, pchan);
 					draw_bone_line(NULL, pchan, arm, select_id);
 				}
 				else if (arm->drawtype == ARM_WIRE) {
+					draw_bone_update_disp_matrix_default(NULL, pchan);
 					draw_bone_wire(NULL, pchan, arm, select_id);
 				}
 				else if (arm->drawtype == ARM_B_BONE) {
+					draw_bone_update_disp_matrix_default(NULL, pchan);
 					draw_bone_box(NULL, pchan, arm, select_id);
 				}
 				else {
+					draw_bone_update_disp_matrix_default(NULL, pchan);
 					draw_bone_octahedral(NULL, pchan, arm, select_id);
 				}
 
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index f28e7ac3d6f..0b859e18d29 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -453,6 +453,19 @@ Batch *DRW_cache_screenspace_circle_get(void)
 /** \name Common Object API
  * \{ */
 
+Batch *DRW_cache_object_wire_get(Object *ob)
+{
+	switch (ob->type) {
+		case OB_MESH:
+			/* TODO, return regular edges (fails with pose-mode custom drawing. needs investigation) */
+			return DRW_cache_mesh_wire_outline_get(ob);
+
+		/* TODO, should match 'DRW_cache_object_surface_get' */
+		default:
+			return NULL;
+	}
+}
+
 Batch *DRW_cache_object_surface_get(Object *ob)
 {
 	switch (ob->type) {
@@ -1613,6 +1626,14 @@ Batch *DRW_cache_mesh_surface_verts_get(Object *ob)
 	return DRW_mesh_batch_cache_get_points_with_normals(me);
 }
 
+Batch *DRW_cache_mesh_edges_get(Object *ob)
+{
+	BLI_assert(ob->type == OB_MESH);
+
+	Mesh *me = ob->data;
+	return DRW_mesh_batch_cache_get_all_edges(me);
+}
+
 Batch *DRW_cache_mesh_verts_get(Object *ob)
 {
 	BLI_assert(ob->type == OB_MESH);
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index ad122ac5222..22ac997458c 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -39,6 +39,7 @@ struct Batch *DRW_cache_single_line_endpoints_get(void);
 struct Batch *DRW_cache_screenspace_circle_get(void);
 
 /* Common Object */
+struct Batch *DRW_cache_object_wire_get(struct Object *ob);
 struct Batch *DRW_cache_object_surface_get(struct Object *ob);
 struct Batch **DRW_cache_object_surface_material_get(struct Object *ob);
 
@@ -91,6 +92,7 @@ struct Batch *DRW_cache_face_centers_get(struct Object *ob);
 struct Batch *DRW_cache_mesh_wire_outline_get(struct Object *ob);
 struct Batch *DRW_cache_mesh_surface_get(struct Object *ob);
 struct Batch *DRW_cache_mesh_surface_verts_get(struct Object *ob);
+struct Batch *DRW_cache_mesh_edges_get(struct Object *ob);
 struct Batch *DRW_cache_mesh_verts_get(struct Object *ob);
 struct Batch **DRW_cache_mesh_surface_shaded_get(struct Object *ob);




More information about the Bf-blender-cvs mailing list