From 846056de6b272d1da087c5ad133f612eecc722af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 30 May 2019 19:34:54 +0200 Subject: Fix T64510 Armature: Empty Not Visible as Bone custom shape --- source/blender/draw/intern/draw_armature.c | 52 ++++++++++++++ source/blender/draw/intern/draw_common.c | 43 ++++++++++++ source/blender/draw/intern/draw_common.h | 19 +++++ source/blender/draw/modes/object_mode.c | 108 +++++++++-------------------- 4 files changed, 146 insertions(+), 76 deletions(-) (limited to 'source/blender/draw') diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c index 3f651b27dd0..4f387de16a8 100644 --- a/source/blender/draw/intern/draw_armature.c +++ b/source/blender/draw/intern/draw_armature.c @@ -80,6 +80,8 @@ static struct { DRWCallBuffer *lines_ik_no_target; DRWCallBuffer *lines_ik_spline; + DRWEmptiesBufferList empties; + DRWArmaturePasses passes; bool transparent; @@ -435,6 +437,50 @@ static void drw_shgroup_bone_custom_wire(const float (*bone_mat)[4], } } +static void drw_shgroup_bone_custom_empty(const float (*bone_mat)[4], + const float color[4], + const eGPUShaderConfig sh_cfg, + Object *custom) +{ + DRWEmptiesBufferList *buffers = &g_data.empties; + const float *draw_size = &custom->empty_drawsize; + + if (g_data.empties.plain_axes == NULL) { + empties_callbuffers_create(g_data.passes.bone_wire, buffers, sh_cfg); + } + + float final_color[4] = {color[0], color[1], color[2], 1.0f}; + float final_bonemat[4][4]; + mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat); + + switch (custom->empty_drawtype) { + case OB_PLAINAXES: + DRW_buffer_add_entry(buffers->plain_axes, final_color, draw_size, final_bonemat); + break; + case OB_SINGLE_ARROW: + DRW_buffer_add_entry(buffers->single_arrow, final_color, draw_size, final_bonemat); + DRW_buffer_add_entry(buffers->single_arrow_line, final_color, draw_size, final_bonemat); + break; + case OB_CUBE: + DRW_buffer_add_entry(buffers->cube, final_color, draw_size, final_bonemat); + break; + case OB_CIRCLE: + DRW_buffer_add_entry(buffers->circle, final_color, draw_size, final_bonemat); + break; + case OB_EMPTY_SPHERE: + DRW_buffer_add_entry(buffers->sphere, final_color, draw_size, final_bonemat); + break; + case OB_EMPTY_CONE: + DRW_buffer_add_entry(buffers->cone, final_color, draw_size, final_bonemat); + break; + case OB_ARROWS: + DRW_buffer_add_entry(buffers->empty_axes, final_color, draw_size, final_bonemat); + break; + case OB_EMPTY_IMAGE: + break; + } +} + /* Head and tail sphere */ static void drw_shgroup_bone_point(const float (*bone_mat)[4], const float bone_color[4], @@ -1394,6 +1440,12 @@ static void draw_bone_custom_shape(EditBone *eBone, DRW_select_load_id(select_id | BONESEL_BONE); } + if (pchan->custom->type == OB_EMPTY) { + Object *ob = pchan->custom; + if (ob->empty_drawtype != OB_EMPTY_IMAGE) { + drw_shgroup_bone_custom_empty(disp_mat, col_wire, sh_cfg, pchan->custom); + } + } if ((boneflag & BONE_DRAWWIRE) == 0) { drw_shgroup_bone_custom_solid(disp_mat, col_solid, col_hint, col_wire, sh_cfg, pchan->custom); } diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index e9c3607f4c5..866fd57b9a8 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -981,6 +981,49 @@ struct DRWCallBuffer *buffer_instance_bone_dof(struct DRWPass *pass, return DRW_shgroup_call_buffer_instance(grp, g_formats.instance_bone_dof, geom); } +void empties_callbuffers_create(struct DRWPass *pass, + DRWEmptiesBufferList *buffers, + eGPUShaderConfig sh_cfg) +{ + struct GPUBatch *geom; + + geom = DRW_cache_plain_axes_get(); + buffers->plain_axes = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_empty_cube_get(); + buffers->cube = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_circle_get(); + buffers->circle = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_empty_sphere_get(); + buffers->sphere = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_sphere_get(); + buffers->sphere_solid = buffer_instance_solid(pass, geom); + + geom = DRW_cache_empty_cylinder_get(); + buffers->cylinder = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_empty_capsule_cap_get(); + buffers->capsule_cap = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_empty_capsule_body_get(); + buffers->capsule_body = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_empty_cone_get(); + buffers->cone = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_single_arrow_get(); + buffers->single_arrow = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_single_line_get(); + buffers->single_arrow_line = buffer_instance(pass, geom, sh_cfg); + + geom = DRW_cache_bone_arrows_get(); + buffers->empty_axes = buffer_instance_empty_axes(pass, geom, sh_cfg); +} + struct GPUShader *mpath_line_shader_get(void) { COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT]; diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index 9c9e3a9b93e..05d7bafa00d 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -123,6 +123,21 @@ BLI_STATIC_ASSERT_ALIGN(GlobalsUboStorage, 16) void DRW_globals_update(void); void DRW_globals_free(void); +typedef struct DRWEmptiesBufferList { + struct DRWCallBuffer *plain_axes; + struct DRWCallBuffer *cube; + struct DRWCallBuffer *circle; + struct DRWCallBuffer *sphere; + struct DRWCallBuffer *sphere_solid; + struct DRWCallBuffer *cylinder; + struct DRWCallBuffer *capsule_cap; + struct DRWCallBuffer *capsule_body; + struct DRWCallBuffer *cone; + struct DRWCallBuffer *single_arrow; + struct DRWCallBuffer *single_arrow_line; + struct DRWCallBuffer *empty_axes; +} DRWEmptiesBufferList; + /* TODO(fclem) ideally, most of the DRWCallBuffer functions shouldn't create a shgroup. */ struct DRWCallBuffer *buffer_dynlines_flat_color(struct DRWPass *pass, eGPUShaderConfig sh_cfg); struct DRWCallBuffer *buffer_dynlines_dashed_uniform_color(struct DRWPass *pass, @@ -193,6 +208,10 @@ struct DRWCallBuffer *buffer_instance_bone_dof(struct DRWPass *pass, struct GPUBatch *geom, bool blend); +void empties_callbuffers_create(struct DRWPass *pass, + struct DRWEmptiesBufferList *buffers, + eGPUShaderConfig sh_cfg); + struct GPUShader *mpath_line_shader_get(void); struct GPUShader *mpath_points_shader_get(void); diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 9f5268500e8..8dae160682a 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -172,18 +172,7 @@ typedef struct OBJECT_ShadingGroupList { struct DRWPass *bone_axes; /* Empties */ - DRWCallBuffer *plain_axes; - DRWCallBuffer *cube; - DRWCallBuffer *circle; - DRWCallBuffer *sphere; - DRWCallBuffer *sphere_solid; - DRWCallBuffer *cylinder; - DRWCallBuffer *capsule_cap; - DRWCallBuffer *capsule_body; - DRWCallBuffer *cone; - DRWCallBuffer *single_arrow; - DRWCallBuffer *single_arrow_line; - DRWCallBuffer *empty_axes; + DRWEmptiesBufferList empties; /* Force Field */ DRWCallBuffer *field_wind; @@ -1252,41 +1241,7 @@ static void OBJECT_cache_init(void *vedata) sgl->image_empties = psl->image_empties[i] = DRW_pass_create("Image Empties", state); /* Empties */ - geom = DRW_cache_plain_axes_get(); - sgl->plain_axes = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_empty_cube_get(); - sgl->cube = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_circle_get(); - sgl->circle = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_empty_sphere_get(); - sgl->sphere = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_sphere_get(); - sgl->sphere_solid = buffer_instance_solid(sgl->non_meshes, geom); - - geom = DRW_cache_empty_cylinder_get(); - sgl->cylinder = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_empty_capsule_cap_get(); - sgl->capsule_cap = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_empty_capsule_body_get(); - sgl->capsule_body = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_empty_cone_get(); - sgl->cone = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_single_arrow_get(); - sgl->single_arrow = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_single_line_get(); - sgl->single_arrow_line = buffer_instance(sgl->non_meshes, geom, draw_ctx->sh_cfg); - - geom = DRW_cache_bone_arrows_get(); - sgl->empty_axes = buffer_instance_empty_axes(sgl->non_meshes, geom, draw_ctx->sh_cfg); + empties_callbuffers_create(sgl->non_meshes, &sgl->empties, draw_ctx->sh_cfg); /* Force Field */ geom = DRW_cache_field_wind_get(); @@ -2035,7 +1990,7 @@ static void camera_view3d_reconstruction(OBJECT_ShadingGroupList *sgl, }; mul_m4_m4m4(bundle_mat, bundle_mat, bundle_scale_mat); - DRW_buffer_add_entry(sgl->sphere_solid, bundle_mat, bundle_color_v4); + DRW_buffer_add_entry(sgl->empties.sphere_solid, bundle_mat, bundle_color_v4); } else { DRW_shgroup_empty_ex( @@ -2237,28 +2192,29 @@ static void DRW_shgroup_empty_ex(OBJECT_ShadingGroupList *sgl, char draw_type, const float color[4]) { + DRWEmptiesBufferList *buffers = &sgl->empties; switch (draw_type) { case OB_PLAINAXES: - DRW_buffer_add_entry(sgl->plain_axes, color, draw_size, mat); + DRW_buffer_add_entry(buffers->plain_axes, color, draw_size, mat); break; case OB_SINGLE_ARROW: - DRW_buffer_add_entry(sgl->single_arrow, color, draw_size, mat); - DRW_buffer_add_entry(sgl->single_arrow_line, color, draw_size, mat); + DRW_buffer_add_entry(buffers->single_arrow, color, draw_size, mat); + DRW_buffer_add_entry(buffers->single_arrow_line, color, draw_size, mat); break; case OB_CUBE: - DRW_buffer_add_entry(sgl->cube, color, draw_size, mat); + DRW_buffer_add_entry(buffers->cube, color, draw_size, mat); break; case OB_CIRCLE: - DRW_buffer_add_entry(sgl->circle, color, draw_size, mat); + DRW_buffer_add_entry(buffers->circle, color, draw_size, mat); break; case OB_EMPTY_SPHERE: - DRW_buffer_add_entry(sgl->sphere, color, draw_size, mat); + DRW_buffer_add_entry(buffers->sphere, color, draw_size, mat); break; case OB_EMPTY_CONE: - DRW_buffer_add_entry(sgl->cone, color, draw_size, mat); + DRW_buffer_add_entry(buffers->cone, color, draw_size, mat); break; case OB_ARROWS: - DRW_buffer_add_entry(sgl->empty_axes, color, draw_size, mat); + DRW_buffer_add_entry(buffers->empty_axes, color, draw_size, mat); break; case OB_EMPTY_IMAGE: BLI_assert(!"Should never happen, use DRW_shgroup_empty instead."); @@ -2424,7 +2380,7 @@ static void DRW_shgroup_volume_extra(OBJECT_ShadingGroupList *sgl, translate_m4(voxel_cubemat, 1.0f, 1.0f, 1.0f); mul_m4_m4m4(voxel_cubemat, ob->obmat, voxel_cubemat); - DRW_buffer_add_entry(sgl->cube, color, &one, voxel_cubemat); + DRW_buffer_add_entry(sgl->empties.cube, color, &one, voxel_cubemat); /* Don't show smoke before simulation starts, this could be made an option in the future. */ if (!sds->draw_velocity || !sds->fluid || CFRA < sds->point_cache[0]->startframe) { @@ -2605,13 +2561,13 @@ static void DRW_shgroup_lightprobe(OBJECT_Shaders *sh_data, copy_m4_m4(mat, ob->obmat); normalize_m4(mat); - DRW_buffer_add_entry(sgl->single_arrow, color, &ob->empty_drawsize, mat); - DRW_buffer_add_entry(sgl->single_arrow_line, color, &ob->empty_drawsize, mat); + DRW_buffer_add_entry(sgl->empties.single_arrow, color, &ob->empty_drawsize, mat); + DRW_buffer_add_entry(sgl->empties.single_arrow_line, color, &ob->empty_drawsize, mat); copy_m4_m4(mat, ob->obmat); zero_v3(mat[2]); - DRW_buffer_add_entry(sgl->cube, color, &one, mat); + DRW_buffer_add_entry(sgl->empties.cube, color, &one, mat); } if ((prb->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0) { @@ -2625,8 +2581,8 @@ static void DRW_shgroup_lightprobe(OBJECT_Shaders *sh_data, } if (prb->type == LIGHTPROBE_TYPE_GRID || prb->attenuation_type == LIGHTPROBE_SHAPE_BOX) { - DRW_buffer_add_entry(sgl->cube, color, &prb->distgridinf, ob->obmat); - DRW_buffer_add_entry(sgl->cube, color, &prb->distfalloff, ob->obmat); + DRW_buffer_add_entry(sgl->empties.cube, color, &prb->distgridinf, ob->obmat); + DRW_buffer_add_entry(sgl->empties.cube, color, &prb->distfalloff, ob->obmat); } else if (prb->type == LIGHTPROBE_TYPE_PLANAR) { float rangemat[4][4]; @@ -2634,17 +2590,17 @@ static void DRW_shgroup_lightprobe(OBJECT_Shaders *sh_data, normalize_v3(rangemat[2]); mul_v3_fl(rangemat[2], prb->distinf); - DRW_buffer_add_entry(sgl->cube, color, &one, rangemat); + DRW_buffer_add_entry(sgl->empties.cube, color, &one, rangemat); copy_m4_m4(rangemat, ob->obmat); normalize_v3(rangemat[2]); mul_v3_fl(rangemat[2], prb->distfalloff); - DRW_buffer_add_entry(sgl->cube, color, &one, rangemat); + DRW_buffer_add_entry(sgl->empties.cube, color, &one, rangemat); } else { - DRW_buffer_add_entry(sgl->sphere, color, &prb->distgridinf, ob->obmat); - DRW_buffer_add_entry(sgl->sphere, color, &prb->distfalloff, ob->obmat); + DRW_buffer_add_entry(sgl->empties.sphere, color, &prb->distgridinf, ob->obmat); + DRW_buffer_add_entry(sgl->empties.sphere, color, &prb->distfalloff, ob->obmat); } } @@ -2663,10 +2619,10 @@ static void DRW_shgroup_lightprobe(OBJECT_Shaders *sh_data, } if (prb->parallax_type == LIGHTPROBE_SHAPE_BOX) { - DRW_buffer_add_entry(sgl->cube, color, dist, obmat); + DRW_buffer_add_entry(sgl->empties.cube, color, dist, obmat); } else { - DRW_buffer_add_entry(sgl->sphere, color, dist, obmat); + DRW_buffer_add_entry(sgl->empties.sphere, color, dist, obmat); } } } @@ -2928,7 +2884,7 @@ static void DRW_shgroup_bounds(OBJECT_ShadingGroupList *sgl, Object *ob, int the size_to_mat4(tmp, size); copy_v3_v3(tmp[3], center); mul_m4_m4m4(tmp, ob->obmat, tmp); - DRW_buffer_add_entry(sgl->cube, color, &one, tmp); + DRW_buffer_add_entry(sgl->empties.cube, color, &one, tmp); break; case OB_BOUND_SPHERE: size[0] = max_fff(size[0], size[1], size[2]); @@ -2936,7 +2892,7 @@ static void DRW_shgroup_bounds(OBJECT_ShadingGroupList *sgl, Object *ob, int the size_to_mat4(tmp, size); copy_v3_v3(tmp[3], center); mul_m4_m4m4(tmp, ob->obmat, tmp); - DRW_buffer_add_entry(sgl->sphere, color, &one, tmp); + DRW_buffer_add_entry(sgl->empties.sphere, color, &one, tmp); break; case OB_BOUND_CYLINDER: size[0] = max_ff(size[0], size[1]); @@ -2944,7 +2900,7 @@ static void DRW_shgroup_bounds(OBJECT_ShadingGroupList *sgl, Object *ob, int the size_to_mat4(tmp, size); copy_v3_v3(tmp[3], center); mul_m4_m4m4(tmp, ob->obmat, tmp); - DRW_buffer_add_entry(sgl->cylinder, color, &one, tmp); + DRW_buffer_add_entry(sgl->empties.cylinder, color, &one, tmp); break; case OB_BOUND_CONE: size[0] = max_ff(size[0], size[1]); @@ -2955,7 +2911,7 @@ static void DRW_shgroup_bounds(OBJECT_ShadingGroupList *sgl, Object *ob, int the swap_v3_v3(tmp[1], tmp[2]); tmp[3][2] -= size[2]; mul_m4_m4m4(tmp, ob->obmat, tmp); - DRW_buffer_add_entry(sgl->cone, color, &one, tmp); + DRW_buffer_add_entry(sgl->empties.cone, color, &one, tmp); break; case OB_BOUND_CAPSULE: size[0] = max_ff(size[0], size[1]); @@ -2964,14 +2920,14 @@ static void DRW_shgroup_bounds(OBJECT_ShadingGroupList *sgl, Object *ob, int the copy_v2_v2(tmp[3], center); tmp[3][2] = center[2] + max_ff(0.0f, size[2] - size[0]); mul_m4_m4m4(final_mat, ob->obmat, tmp); - DRW_buffer_add_entry(sgl->capsule_cap, color, &one, final_mat); + DRW_buffer_add_entry(sgl->empties.capsule_cap, color, &one, final_mat); negate_v3(tmp[2]); tmp[3][2] = center[2] - max_ff(0.0f, size[2] - size[0]); mul_m4_m4m4(final_mat, ob->obmat, tmp); - DRW_buffer_add_entry(sgl->capsule_cap, color, &one, final_mat); + DRW_buffer_add_entry(sgl->empties.capsule_cap, color, &one, final_mat); tmp[2][2] = max_ff(0.0f, size[2] * 2.0f - size[0] * 2.0f); mul_m4_m4m4(final_mat, ob->obmat, tmp); - DRW_buffer_add_entry(sgl->capsule_body, color, &one, final_mat); + DRW_buffer_add_entry(sgl->empties.capsule_body, color, &one, final_mat); break; } } @@ -3436,7 +3392,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob) float *color, axes_size = 1.0f; DRW_object_wire_theme_get(ob, view_layer, &color); - DRW_buffer_add_entry(sgl->empty_axes, color, &axes_size, ob->obmat); + DRW_buffer_add_entry(sgl->empties.empty_axes, color, &axes_size, ob->obmat); } if ((md = modifiers_findByType(ob, eModifierType_Smoke)) && -- cgit v1.2.3