diff options
Diffstat (limited to 'source/blender/draw/engines/overlay/overlay_extra.c')
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_extra.c | 183 |
1 files changed, 63 insertions, 120 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c index fc52efb0174..af54e524445 100644 --- a/source/blender/draw/engines/overlay/overlay_extra.c +++ b/source/blender/draw/engines/overlay/overlay_extra.c @@ -24,28 +24,30 @@ #include "UI_resources.h" -#include "BKE_anim.h" +#include "BKE_anim_path.h" #include "BKE_camera.h" #include "BKE_constraint.h" #include "BKE_curve.h" #include "BKE_global.h" #include "BKE_mball.h" #include "BKE_mesh.h" -#include "BKE_movieclip.h" #include "BKE_modifier.h" +#include "BKE_movieclip.h" #include "BKE_object.h" #include "BKE_tracking.h" +#include "BLI_listbase.h" + #include "DNA_camera_types.h" #include "DNA_constraint_types.h" -#include "DNA_gpencil_types.h" +#include "DNA_curve_types.h" +#include "DNA_fluid_types.h" #include "DNA_lightprobe_types.h" #include "DNA_mesh_types.h" #include "DNA_meta_types.h" #include "DNA_modifier_types.h" #include "DNA_object_force_types.h" #include "DNA_rigidbody_types.h" -#include "DNA_fluid_types.h" #include "DEG_depsgraph_query.h" @@ -344,10 +346,13 @@ void OVERLAY_empty_cache_populate(OVERLAY_Data *vedata, Object *ob) } } -static void OVERLAY_bounds( - OVERLAY_ExtraCallBuffers *cb, Object *ob, int theme_id, char boundtype, bool around_origin) +static void OVERLAY_bounds(OVERLAY_ExtraCallBuffers *cb, + Object *ob, + const float *color, + char boundtype, + bool around_origin) { - float color[4], center[3], size[3], tmp[4][4], final_mat[4][4]; + float center[3], size[3], tmp[4][4], final_mat[4][4]; BoundBox bb_local; if (ob->type == OB_MBALL && !BKE_mball_is_basis(ob)) { @@ -362,7 +367,6 @@ static void OVERLAY_bounds( BKE_boundbox_init_from_minmax(bb, min, max); } - UI_GetThemeColor4fv(theme_id, color); BKE_boundbox_calc_size_aabb(bb, size); if (around_origin) { @@ -425,28 +429,28 @@ static void OVERLAY_bounds( } } -static void OVERLAY_collision(OVERLAY_ExtraCallBuffers *cb, Object *ob, int theme_id) +static void OVERLAY_collision(OVERLAY_ExtraCallBuffers *cb, Object *ob, const float *color) { switch (ob->rigidbody_object->shape) { case RB_SHAPE_BOX: - OVERLAY_bounds(cb, ob, theme_id, OB_BOUND_BOX, true); + OVERLAY_bounds(cb, ob, color, OB_BOUND_BOX, true); break; case RB_SHAPE_SPHERE: - OVERLAY_bounds(cb, ob, theme_id, OB_BOUND_SPHERE, true); + OVERLAY_bounds(cb, ob, color, OB_BOUND_SPHERE, true); break; case RB_SHAPE_CONE: - OVERLAY_bounds(cb, ob, theme_id, OB_BOUND_CONE, true); + OVERLAY_bounds(cb, ob, color, OB_BOUND_CONE, true); break; case RB_SHAPE_CYLINDER: - OVERLAY_bounds(cb, ob, theme_id, OB_BOUND_CYLINDER, true); + OVERLAY_bounds(cb, ob, color, OB_BOUND_CYLINDER, true); break; case RB_SHAPE_CAPSULE: - OVERLAY_bounds(cb, ob, theme_id, OB_BOUND_CAPSULE, true); + OVERLAY_bounds(cb, ob, color, OB_BOUND_CAPSULE, true); break; } } -static void OVERLAY_texture_space(OVERLAY_ExtraCallBuffers *cb, Object *ob, int theme_id) +static void OVERLAY_texture_space(OVERLAY_ExtraCallBuffers *cb, Object *ob, const float *color) { if (ob->data == NULL) { return; @@ -473,17 +477,27 @@ static void OVERLAY_texture_space(OVERLAY_ExtraCallBuffers *cb, Object *ob, int texcosize = mb->size; break; } + case ID_HA: + case ID_PT: + case ID_VO: { + /* No user defined texture space support. */ + break; + } default: BLI_assert(0); } - float mat[4][4], color[4]; - size_to_mat4(mat, texcosize); - copy_v3_v3(mat[3], texcoloc); + float mat[4][4]; - mul_m4_m4m4(mat, ob->obmat, mat); + if (texcoloc != NULL && texcosize != NULL) { + size_to_mat4(mat, texcosize); + copy_v3_v3(mat[3], texcoloc); + } + else { + unit_m4(mat); + } - UI_GetThemeColor4fv(theme_id, color); + mul_m4_m4m4(mat, ob->obmat, mat); DRW_buffer_add_entry(cb->empty_cube, color, mat); } @@ -600,7 +614,7 @@ void OVERLAY_light_cache_populate(OVERLAY_Data *vedata, Object *ob) float *color_p; DRW_object_wire_theme_get(ob, view_layer, &color_p); /* Remove the alpha. */ - float color[4] = {color_p[0], color_p[1], color_p[2], 1.0f}; + float color[4] = {UNPACK3(color_p), 1.0f}; /* Pack render data into object matrix. */ union { float mat[4][4]; @@ -867,18 +881,16 @@ static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb, /* Index must start in 1, to mimic BKE_tracking_track_get_indexed. */ int track_index = 1; + float bundle_color_custom[3]; + float *bundle_color_solid = G_draw.block.colorBundleSolid; + float *bundle_color_unselected = G_draw.block.colorWire; uchar text_color_selected[4], text_color_unselected[4]; - float bundle_color_unselected[4], bundle_color_solid[4]; - + /* Color Management: Exception here as texts are drawn in sRGB space directly. */ UI_GetThemeColor4ubv(TH_SELECT, text_color_selected); UI_GetThemeColor4ubv(TH_TEXT, text_color_unselected); - UI_GetThemeColor4fv(TH_WIRE, bundle_color_unselected); - UI_GetThemeColor4fv(TH_BUNDLE_SOLID, bundle_color_solid); - - float camera_mat[4][4], normal_mat[4][4]; - BKE_tracking_get_camera_object_matrix(scene, ob, camera_mat); - normalize_m4_m4(normal_mat, ob->obmat); + float camera_mat[4][4]; + BKE_tracking_get_camera_object_matrix(ob, camera_mat); LISTBASE_FOREACH (MovieTrackingObject *, tracking_object, &tracking->objects) { float tracking_object_mat[4][4]; @@ -889,16 +901,19 @@ static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb, else { const int framenr = BKE_movieclip_remap_scene_to_clip_frame( clip, DEG_get_ctime(draw_ctx->depsgraph)); + float object_mat[4][4]; BKE_tracking_camera_get_reconstructed_interpolate( tracking, tracking_object, framenr, object_mat); - invert_m4(object_mat); - mul_m4_m4m4(tracking_object_mat, normal_mat, object_mat); + float object_imat[4][4]; + invert_m4_m4(object_imat, object_mat); + + mul_m4_m4m4(tracking_object_mat, ob->obmat, object_imat); } ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object); - for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) { + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if ((track->flag & TRACK_HAS_BUNDLE) == 0) { continue; } @@ -910,7 +925,10 @@ static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb, const float *bundle_color; if (track->flag & TRACK_CUSTOMCOLOR) { - bundle_color = track->color; + /* Meh, hardcoded srgb transform here. */ + /* TODO change the actual DNA color to be linear. */ + srgb_to_linearrgb_v3_v3(bundle_color_custom, track->color); + bundle_color = bundle_color_custom; } else if (is_solid_bundle) { bundle_color = bundle_color_solid; @@ -1142,6 +1160,10 @@ void OVERLAY_camera_cache_populate(OVERLAY_Data *vedata, Object *ob) } else { copy_v3_fl3(scale, len_v3(ob->obmat[0]), len_v3(ob->obmat[1]), len_v3(ob->obmat[2])); + /* Avoid division by 0. */ + if (ELEM(0.0f, scale[0], scale[1], scale[2])) { + return; + } invert_v3(scale); } @@ -1328,87 +1350,6 @@ static void OVERLAY_relationship_lines(OVERLAY_ExtraCallBuffers *cb, /** \} */ /* -------------------------------------------------------------------- */ -/** \name GPencil. - * \{ */ - -static void OVERLAY_gpencil_color_names(Object *ob) -{ - if (ob->mode != OB_MODE_EDIT_GPENCIL) { - return; - } - - bGPdata *gpd = (bGPdata *)ob->data; - if (gpd == NULL) { - return; - } - - const DRWContextState *draw_ctx = DRW_context_state_get(); - ViewLayer *view_layer = draw_ctx->view_layer; - int theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL); - uchar color[4]; - UI_GetThemeColor4ubv(theme_id, color); - struct DRWTextStore *dt = DRW_text_cache_ensure(); - - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { - if (gpl->flag & GP_LAYER_HIDE) { - continue; - } - bGPDframe *gpf = gpl->actframe; - if (gpf == NULL) { - continue; - } - for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { - Material *ma = give_current_material(ob, gps->mat_nr + 1); - if (ma == NULL) { - continue; - } - - MaterialGPencilStyle *gp_style = ma->gp_style; - /* skip stroke if it doesn't have any valid data */ - if ((gps->points == NULL) || (gps->totpoints < 1) || (gp_style == NULL)) { - continue; - } - /* check if the color is visible */ - if (gp_style->flag & GP_STYLE_COLOR_HIDE) { - continue; - } - - /* only if selected */ - if (gps->flag & GP_STROKE_SELECT) { - float fpt[3]; - for (int i = 0; i < gps->totpoints; i++) { - bGPDspoint *pt = &gps->points[i]; - if (pt->flag & GP_SPOINT_SELECT) { - mul_v3_m4v3(fpt, ob->obmat, &pt->x); - DRW_text_cache_add(dt, - fpt, - ma->id.name + 2, - strlen(ma->id.name + 2), - 10, - 0, - DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, - color); - break; - } - } - } - } - } -} - -void OVERLAY_gpencil_cache_populate(OVERLAY_Data *UNUSED(vedata), Object *ob) -{ - /* don't show object extras in set's */ - if ((ob->base_flag & (BASE_FROM_SET | BASE_FROM_DUPLI)) == 0) { - if ((ob->dtx & OB_DRAWNAME) && DRW_state_show_text()) { - OVERLAY_gpencil_color_names(ob); - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Volumetric / Smoke sim * \{ */ @@ -1525,6 +1466,7 @@ static void OVERLAY_object_name(Object *ob, int theme_id) { struct DRWTextStore *dt = DRW_text_cache_ensure(); uchar color[4]; + /* Color Management: Exception here as texts are drawn in sRGB space directly. */ UI_GetThemeColor4ubv(theme_id, color); DRW_text_cache_add(dt, @@ -1564,8 +1506,9 @@ void OVERLAY_extra_cache_populate(OVERLAY_Data *vedata, Object *ob) const bool draw_xform = draw_ctx->object_mode == OB_MODE_OBJECT && (scene->toolsettings->transform_flag & SCE_XFORM_DATA_ORIGIN) && (ob->base_flag & BASE_SELECTED) && !is_select_mode; - const bool draw_volume = !from_dupli && (md = modifiers_findByType(ob, eModifierType_Fluid)) && - (modifier_isEnabled(scene, md, eModifierMode_Realtime)) && + const bool draw_volume = !from_dupli && + (md = BKE_modifiers_findby_type(ob, eModifierType_Fluid)) && + (BKE_modifier_is_enabled(scene, md, eModifierMode_Realtime)) && (((FluidModifierData *)md)->domain != NULL); float *color; @@ -1576,11 +1519,11 @@ void OVERLAY_extra_cache_populate(OVERLAY_Data *vedata, Object *ob) } if (draw_bounds) { - OVERLAY_bounds(cb, ob, theme_id, ob->boundtype, false); + OVERLAY_bounds(cb, ob, color, ob->boundtype, false); } /* Helpers for when we're transforming origins. */ if (draw_xform) { - float color_xform[4] = {0.75f, 0.75f, 0.75f, 0.5f}; + float color_xform[4] = {0.15f, 0.15f, 0.15f, 0.7f}; DRW_buffer_add_entry(cb->origin_xform, color_xform, ob->obmat); } /* don't show object extras in set's */ @@ -1595,10 +1538,10 @@ void OVERLAY_extra_cache_populate(OVERLAY_Data *vedata, Object *ob) OVERLAY_object_name(ob, theme_id); } if (draw_texspace) { - OVERLAY_texture_space(cb, ob, theme_id); + OVERLAY_texture_space(cb, ob, color); } if (ob->rigidbody_object != NULL) { - OVERLAY_collision(cb, ob, theme_id); + OVERLAY_collision(cb, ob, color); } if (ob->dtx & OB_AXIS) { DRW_buffer_add_entry(cb->empty_axes, color, ob->obmat); |