Fix T61791: Motion path step is not taken into account

This commit is contained in:
Jacques Lucke 2019-02-21 13:28:21 +01:00
parent d542c6a5f3
commit 4f0b61f15b
Notes: blender-bot 2023-02-14 05:25:44 +01:00
Referenced by issue #61791, Motion Path step is not taken into account
2 changed files with 42 additions and 44 deletions

View File

@ -142,6 +142,33 @@ static void MPATH_cache_init(void *vedata)
}
}
static void MPATH_get_frame_range_to_draw(
bAnimVizSettings *avs, bMotionPath *mpath, int current_frame,
int *r_start, int *r_end, int *r_step)
{
int start, end;
if (avs->path_type == MOTIONPATH_TYPE_ACFRA) {
start = current_frame - avs->path_bc;
end = current_frame + avs->path_ac + 1;
}
else {
start = avs->path_sf;
end = avs->path_ef;
}
if (start > end) {
SWAP(int, start, end);
}
CLAMP(start, mpath->start_frame, mpath->end_frame);
CLAMP(end, mpath->start_frame, mpath->end_frame);
*r_start = start;
*r_end = end;
*r_step = max_ii(avs->path_step, 1);
}
static void MPATH_cache_motion_path(MPATH_PassList *psl,
Object *ob, bPoseChannel *pchan,
bAnimVizSettings *avs, bMotionPath *mpath)
@ -149,53 +176,18 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl,
const DRWContextState *draw_ctx = DRW_context_state_get();
struct DRWTextStore *dt = DRW_text_cache_ensure();
int txt_flag = DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_ASCII;
int stepsize = avs->path_step;
int sfra, efra, sind, len;
int cfra = (int)DEG_get_ctime(draw_ctx->depsgraph);
bool sel = (pchan) ? (pchan->bone->flag & BONE_SELECTED) : (ob->flag & SELECT);
bool show_keyframes = (avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) != 0;
bMotionPathVert *mpv, *mpv_start;
/* get frame ranges */
if (avs->path_type == MOTIONPATH_TYPE_ACFRA) {
/* With "Around Current", we only choose frames from around
* the current frame to draw.
*/
sfra = cfra - avs->path_bc;
efra = cfra + avs->path_ac + 1;
}
else {
/* Use the current display range */
sfra = avs->path_sf;
efra = avs->path_ef;
}
int sfra, efra, stepsize;
MPATH_get_frame_range_to_draw(avs, mpath, cfra, &sfra, &efra, &stepsize);
/* no matter what, we can only show what is in the cache and no more
* - abort if whole range is past ends of path
* - otherwise clamp endpoints to extents of path
*/
if (sfra < mpath->start_frame) {
/* start clamp */
sfra = mpath->start_frame;
}
if (efra > mpath->end_frame) {
/* end clamp */
efra = mpath->end_frame;
}
if ((sfra > mpath->end_frame) || (efra < mpath->start_frame)) {
/* whole path is out of bounds */
int len = efra - sfra;
if (len == 0) {
return;
}
len = efra - sfra;
if ((len <= 0) || (mpath->points == NULL)) {
return;
}
sind = sfra - mpath->start_frame;
mpv_start = (mpath->points + sind);
int start_index = sfra - mpath->start_frame;
bool use_custom_col = (mpath->flag & MOTIONPATH_FLAG_CUSTOM) != 0;
@ -216,16 +208,15 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl,
DRW_shgroup_uniform_vec3(shgrp, "customColor", mpath->color, 1);
}
/* Only draw the required range. */
DRW_shgroup_call_range_add(shgrp, mpath_batch_line_get(mpath), NULL, sind, len);
DRW_shgroup_call_range_add(shgrp, mpath_batch_line_get(mpath), NULL, start_index, len);
}
/* Draw points. */
DRWShadingGroup *shgrp = DRW_shgroup_create(mpath_points_shader_get(), psl->points);
DRW_shgroup_uniform_int_copy(shgrp, "frameCurrent", cfra);
DRW_shgroup_uniform_int_copy(shgrp, "cacheStart", mpath->start_frame);
DRW_shgroup_uniform_int_copy(shgrp, "pointSize", mpath->line_thickness);
DRW_shgroup_uniform_int_copy(shgrp, "pointSize", max_ii(mpath->line_thickness - 1, 1));
DRW_shgroup_uniform_int_copy(shgrp, "stepSize", stepsize);
DRW_shgroup_uniform_bool_copy(shgrp, "selected", sel);
DRW_shgroup_uniform_bool_copy(shgrp, "showKeyFrames", show_keyframes);
DRW_shgroup_uniform_bool_copy(shgrp, "useCustomColor", use_custom_col);
DRW_shgroup_uniform_block(shgrp, "globalsBlock", G_draw.block_ubo);
@ -233,7 +224,7 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl,
DRW_shgroup_uniform_vec3(shgrp, "customColor", mpath->color, 1);
}
/* Only draw the required range. */
DRW_shgroup_call_range_add(shgrp, mpath_batch_points_get(mpath), NULL, sind, len);
DRW_shgroup_call_range_add(shgrp, mpath_batch_points_get(mpath), NULL, start_index, len);
/* Draw frame numbers at each framestep value */
bool show_kf_no = (avs->path_viewflag & MOTIONPATH_VIEW_KFNOS) != 0;
@ -244,6 +235,8 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl,
UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col_kf);
col[3] = col_kf[3] = 255;
bMotionPathVert *mpv;
bMotionPathVert *mpv_start = mpath->points + start_index;
for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize) {
int frame = sfra + i;
char numstr[32];

View File

@ -7,6 +7,7 @@ uniform int cacheStart;
uniform bool showKeyFrames = true;
uniform bool useCustomColor;
uniform vec3 customColor;
uniform int stepSize;
in vec3 pos;
in int flag;
@ -27,6 +28,10 @@ void main()
/* Bias to reduce z fighting with the path */
gl_Position.z -= 1e-4;
if (gl_VertexID % stepSize == 0) {
gl_PointSize = float(pointSize) + 4;
}
if (showKeyFrames) {
if ((flag & MOTIONPATH_VERT_KEY) != 0) {
gl_PointSize = float(pointSize + 5);