[Bf-blender-cvs] [995a96e6301] tmp-overlay-engine: Overlay Engine: Motion Path

Clément Foucault noreply at git.blender.org
Sat Nov 16 00:29:58 CET 2019


Commit: 995a96e630129bb263d6f586cb97136014ad7f07
Author: Clément Foucault
Date:   Fri Nov 15 18:00:57 2019 +0100
Branches: tmp-overlay-engine
https://developer.blender.org/rB995a96e630129bb263d6f586cb97136014ad7f07

Overlay Engine: Motion Path

- Now working with Alt+B clipping
- Now scalling with DPI setting

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_engine.c
A	source/blender/draw/engines/overlay/overlay_motion_path.c
M	source/blender/draw/engines/overlay/overlay_private.h
M	source/blender/draw/engines/overlay/overlay_shader.c
A	source/blender/draw/engines/overlay/shaders/motion_path_line_geom.glsl
A	source/blender/draw/engines/overlay/shaders/motion_path_line_vert.glsl
A	source/blender/draw/engines/overlay/shaders/motion_path_point_vert.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 69261ac8369..2ebfc018b21 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -141,6 +141,7 @@ set(SRC
   engines/overlay/overlay_facing.c
   engines/overlay/overlay_grid.c
   engines/overlay/overlay_image.c
+  engines/overlay/overlay_motion_path.c
   engines/overlay/overlay_outline.c
   engines/overlay/overlay_shader.c
   engines/overlay/overlay_wireframe.c
@@ -409,6 +410,9 @@ data_to_c_simple(engines/overlay/shaders/grid_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/grid_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/image_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/image_frag.glsl SRC)
+data_to_c_simple(engines/overlay/shaders/motion_path_line_geom.glsl SRC)
+data_to_c_simple(engines/overlay/shaders/motion_path_line_vert.glsl SRC)
+data_to_c_simple(engines/overlay/shaders/motion_path_point_vert.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_detect_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_expand_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/outline_prepass_frag.glsl SRC)
diff --git a/source/blender/draw/engines/overlay/overlay_engine.c b/source/blender/draw/engines/overlay/overlay_engine.c
index eab0d0701db..12f2076813e 100644
--- a/source/blender/draw/engines/overlay/overlay_engine.c
+++ b/source/blender/draw/engines/overlay/overlay_engine.c
@@ -154,6 +154,7 @@ static void OVERLAY_cache_init(void *vedata)
   OVERLAY_facing_cache_init(vedata);
   OVERLAY_grid_cache_init(vedata);
   OVERLAY_image_cache_init(vedata);
+  OVERLAY_motion_path_cache_init(vedata);
   OVERLAY_outline_cache_init(vedata);
   OVERLAY_wireframe_cache_init(vedata);
 }
@@ -204,6 +205,8 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
       /* Show if this is the camera we're looking through since it's useful for selecting. */
       ((draw_ctx->rv3d->persp == RV3D_CAMOB) && ((ID *)draw_ctx->v3d->camera == ob->id.orig_id));
 
+  const bool draw_motion_paths = (pd->overlay.flag & V3D_OVERLAY_HIDE_MOTION_PATHS) == 0;
+
   bool init;
   OVERLAY_DupliData *dupli = OVERLAY_duplidata_get(ob, vedata, &init);
 
@@ -241,6 +244,10 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob)
     OVERLAY_pose_armature_cache_populate(vedata, ob);
   }
 
+  if (draw_motion_paths) {
+    OVERLAY_motion_path_cache_populate(vedata, ob);
+  }
+
   // if (is_geom) {
   //   if (paint_vertex_mode) {
   //     OVERLAY_paint_vertex_cache_populate();
@@ -314,6 +321,7 @@ static void OVERLAY_draw_scene(void *vedata)
   OVERLAY_extra_draw(vedata);
   OVERLAY_armature_draw(vedata);
   OVERLAY_grid_draw(vedata);
+  OVERLAY_motion_path_draw(vedata);
   OVERLAY_outline_draw(vedata);
 
   switch (pd->ctx_mode) {
diff --git a/source/blender/draw/engines/overlay/overlay_motion_path.c b/source/blender/draw/engines/overlay/overlay_motion_path.c
new file mode 100644
index 00000000000..c81887b9d89
--- /dev/null
+++ b/source/blender/draw/engines/overlay/overlay_motion_path.c
@@ -0,0 +1,230 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2019, Blender Foundation.
+ */
+
+/** \file
+ * \ingroup draw_engine
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_string.h"
+
+#include "DNA_armature_types.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "GPU_batch.h"
+
+#include "UI_resources.h"
+
+#include "draw_manager_text.h"
+
+#include "overlay_private.h"
+
+void OVERLAY_motion_path_cache_init(OVERLAY_Data *vedata)
+{
+  OVERLAY_PassList *psl = vedata->psl;
+  OVERLAY_PrivateData *pd = vedata->stl->pd;
+  DRWShadingGroup *grp;
+  GPUShader *sh;
+
+  DRWState state = DRW_STATE_WRITE_COLOR;
+  DRW_PASS_CREATE(psl->motion_paths_ps, state | pd->clipping_state);
+
+  sh = OVERLAY_shader_motion_path_line();
+  pd->motion_path_lines_grp = grp = DRW_shgroup_create(sh, psl->motion_paths_ps);
+  DRW_shgroup_uniform_block_persistent(grp, "globalsBlock", G_draw.block_ubo);
+
+  sh = OVERLAY_shader_motion_path_vert();
+  pd->motion_path_points_grp = grp = DRW_shgroup_create(sh, psl->motion_paths_ps);
+  DRW_shgroup_uniform_block_persistent(grp, "globalsBlock", G_draw.block_ubo);
+}
+
+/* Just convert the CPU cache to GPU cache. */
+static GPUVertBuf *mpath_vbo_get(bMotionPath *mpath)
+{
+  if (!mpath->points_vbo) {
+    GPUVertFormat format = {0};
+    /* Match structure of bMotionPathVert. */
+    GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+    GPU_vertformat_attr_add(&format, "flag", GPU_COMP_I32, 1, GPU_FETCH_INT);
+    mpath->points_vbo = GPU_vertbuf_create_with_format(&format);
+    GPU_vertbuf_data_alloc(mpath->points_vbo, mpath->length);
+    /* meh... a useless memcpy. */
+    memcpy(mpath->points_vbo->data, mpath->points, sizeof(bMotionPathVert) * mpath->length);
+  }
+  return mpath->points_vbo;
+}
+
+static GPUBatch *mpath_batch_line_get(bMotionPath *mpath)
+{
+  if (!mpath->batch_line) {
+    mpath->batch_line = GPU_batch_create(GPU_PRIM_LINE_STRIP, mpath_vbo_get(mpath), NULL);
+  }
+  return mpath->batch_line;
+}
+
+static GPUBatch *mpath_batch_points_get(bMotionPath *mpath)
+{
+  if (!mpath->batch_points) {
+    mpath->batch_points = GPU_batch_create(GPU_PRIM_POINTS, mpath_vbo_get(mpath), NULL);
+  }
+  return mpath->batch_points;
+}
+
+static void motion_path_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 motion_path_cache(OVERLAY_Data *vedata,
+                              Object *ob,
+                              bPoseChannel *pchan,
+                              bAnimVizSettings *avs,
+                              bMotionPath *mpath)
+{
+  OVERLAY_PrivateData *pd = vedata->stl->pd;
+  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 cfra = (int)DEG_get_ctime(draw_ctx->depsgraph);
+  bool selected = (pchan) ? (pchan->bone->flag & BONE_SELECTED) : (ob->base_flag & BASE_SELECTED);
+  bool show_keyframes = (avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) != 0;
+  bool show_keyframes_no = (avs->path_viewflag & MOTIONPATH_VIEW_KFNOS) != 0;
+  bool show_frame_no = (avs->path_viewflag & MOTIONPATH_VIEW_FNUMS) != 0;
+  bool show_lines = (mpath->flag & MOTIONPATH_FLAG_LINES) != 0;
+  float no_custom_col[3] = {-1.0f, -1.0f, -1.0f};
+  float *color = (mpath->flag & MOTIONPATH_FLAG_CUSTOM) ? mpath->color : no_custom_col;
+
+  int sfra, efra, stepsize;
+  motion_path_get_frame_range_to_draw(avs, mpath, cfra, &sfra, &efra, &stepsize);
+
+  int len = efra - sfra;
+  if (len == 0) {
+    return;
+  }
+  int start_index = sfra - mpath->start_frame;
+
+  /* Draw curve-line of path. */
+  if (show_lines) {
+    int motion_path_settings[4] = {cfra, sfra, efra, mpath->start_frame};
+    DRWShadingGroup *grp = DRW_shgroup_create_sub(pd->motion_path_lines_grp);
+    DRW_shgroup_uniform_ivec4_copy(grp, "mpathLineSettings", motion_path_settings);
+    DRW_shgroup_uniform_int_copy(grp, "lineThickness", mpath->line_thickness);
+    DRW_shgroup_uniform_bool_copy(grp, "selected", selected);
+    DRW_shgroup_uniform_vec3_copy(grp, "customColor", color);
+    /* Only draw the required range. */
+    DRW_shgroup_call_range(grp, mpath_batch_line_get(mpath), start_index, len);
+  }
+
+  /* Draw points. */
+  {
+    int pt_size = max_ii(mpath->line_thickness - 1, 1);
+    int motion_path_settings[4] = {pt_size, cfra, mpath->start_frame, stepsize};
+    DRWShadingGroup *grp = DRW_shgroup_create_sub(pd->motion_path_points_grp);
+    DRW_shgroup_uniform_ivec4_copy(grp, "mpathPointSettings", motion_path_settings);
+    DRW_shgroup_uniform_bool_copy(grp, "showKeyFrames", show_keyframes);
+    DRW_shgroup_uniform_vec3_copy(grp, "customColor", color);
+    /* Only draw the required range. */
+    DRW_shgroup_call_range(grp, mpath_batch_points_get(mpath), start_index, len);
+  }
+
+  /* Draw frame numbers at each framestep value */
+  if (show_frame_no || (show_keyframes_no && show_keyframes)) {
+    int i;
+    uchar col[4], col_kf[4];
+    UI_GetThemeColor3ubv(TH_TEXT_HI, col);
+    UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col_kf);
+    col[3] = col_kf[3] = 255;
+
+    bMotionPathVert *mpv = mpath->points + start_index;
+    for (i = 0; i < len; i += stepsize, mpv += stepsize) {
+      int frame = sfra + i;
+      char numstr[32];
+      size_t numstr_len;
+      bool is_keyframe = (mpv->flag & MOTIONPATH_VERT_KEY) != 0;
+
+      if ((show_keyframes && show_keyframes_no && is_keyframe) || (show_frame_no && (i == 0))) {
+        numstr_len = BLI_snprintf(numstr, sizeof(numstr), " %d", frame);
+        DRW_text_cache_add(
+            dt, mpv->co, numstr, nums

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list