[Bf-blender-cvs] [9a02909bacd] temp-transform-conversions-split: Transform: Move graph editor conversion to its own file

mano-wii noreply at git.blender.org
Wed Sep 4 23:52:53 CEST 2019


Commit: 9a02909bacd3cb4b037f25113358c707b28150f5
Author: mano-wii
Date:   Wed Sep 4 17:27:39 2019 -0300
Branches: temp-transform-conversions-split
https://developer.blender.org/rB9a02909bacd3cb4b037f25113358c707b28150f5

Transform: Move graph editor conversion to its own file

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

M	source/blender/editors/transform/CMakeLists.txt
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/transform/transform_conversions.h
A	source/blender/editors/transform/transform_conversions_graph.c

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

diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt
index e9af71288ee..c379384c570 100644
--- a/source/blender/editors/transform/CMakeLists.txt
+++ b/source/blender/editors/transform/CMakeLists.txt
@@ -45,6 +45,7 @@ set(SRC
   transform_conversions_armature.c
   transform_conversions_cursor.c
   transform_conversions_curve.c
+  transform_conversions_graph.c
   transform_conversions_lattice.c
   transform_conversions_mball.c
   transform_conversions_mesh.c
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 698b7d45cf9..0b9e9eb972b 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -1477,553 +1477,6 @@ void flushTransIntFrameActionData(TransInfo *t)
 
 /* ********************* GRAPH EDITOR ************************* */
 
-typedef struct TransDataGraph {
-  float unit_scale;
-  float offset;
-} TransDataGraph;
-
-/* Helper function for createTransGraphEditData, which is responsible for associating
- * source data with transform data
- */
-static void bezt_to_transdata(TransData *td,
-                              TransData2D *td2d,
-                              TransDataGraph *tdg,
-                              AnimData *adt,
-                              BezTriple *bezt,
-                              int bi,
-                              bool selected,
-                              bool ishandle,
-                              bool intvals,
-                              float mtx[3][3],
-                              float smtx[3][3],
-                              float unit_scale,
-                              float offset)
-{
-  float *loc = bezt->vec[bi];
-  const float *cent = bezt->vec[1];
-
-  /* New location from td gets dumped onto the old-location of td2d, which then
-   * gets copied to the actual data at td2d->loc2d (bezt->vec[n])
-   *
-   * Due to NLA mapping, we apply NLA mapping to some of the verts here,
-   * and then that mapping will be undone after transform is done.
-   */
-
-  if (adt) {
-    td2d->loc[0] = BKE_nla_tweakedit_remap(adt, loc[0], NLATIME_CONVERT_MAP);
-    td2d->loc[1] = (loc[1] + offset) * unit_scale;
-    td2d->loc[2] = 0.0f;
-    td2d->loc2d = loc;
-
-    td->loc = td2d->loc;
-    td->center[0] = BKE_nla_tweakedit_remap(adt, cent[0], NLATIME_CONVERT_MAP);
-    td->center[1] = (cent[1] + offset) * unit_scale;
-    td->center[2] = 0.0f;
-
-    copy_v3_v3(td->iloc, td->loc);
-  }
-  else {
-    td2d->loc[0] = loc[0];
-    td2d->loc[1] = (loc[1] + offset) * unit_scale;
-    td2d->loc[2] = 0.0f;
-    td2d->loc2d = loc;
-
-    td->loc = td2d->loc;
-    copy_v3_v3(td->center, cent);
-    td->center[1] = (td->center[1] + offset) * unit_scale;
-    copy_v3_v3(td->iloc, td->loc);
-  }
-
-  if (!ishandle) {
-    td2d->h1 = bezt->vec[0];
-    td2d->h2 = bezt->vec[2];
-    copy_v2_v2(td2d->ih1, td2d->h1);
-    copy_v2_v2(td2d->ih2, td2d->h2);
-  }
-  else {
-    td2d->h1 = NULL;
-    td2d->h2 = NULL;
-  }
-
-  memset(td->axismtx, 0, sizeof(td->axismtx));
-  td->axismtx[2][2] = 1.0f;
-
-  td->ext = NULL;
-  td->val = NULL;
-
-  /* store AnimData info in td->extra, for applying mapping when flushing */
-  td->extra = adt;
-
-  if (selected) {
-    td->flag |= TD_SELECTED;
-    td->dist = 0.0f;
-  }
-  else {
-    td->dist = FLT_MAX;
-  }
-
-  if (ishandle) {
-    td->flag |= TD_NOTIMESNAP;
-  }
-  if (intvals) {
-    td->flag |= TD_INTVALUES;
-  }
-
-  /* copy space-conversion matrices for dealing with non-uniform scales */
-  copy_m3_m3(td->mtx, mtx);
-  copy_m3_m3(td->smtx, smtx);
-
-  tdg->unit_scale = unit_scale;
-  tdg->offset = offset;
-}
-
-static bool graph_edit_is_translation_mode(TransInfo *t)
-{
-  return ELEM(t->mode, TFM_TRANSLATION, TFM_TIME_TRANSLATE, TFM_TIME_SLIDE, TFM_TIME_DUPLICATE);
-}
-
-static bool graph_edit_use_local_center(TransInfo *t)
-{
-  return ((t->around == V3D_AROUND_LOCAL_ORIGINS) && (graph_edit_is_translation_mode(t) == false));
-}
-
-static void graph_key_shortest_dist(
-    TransInfo *t, FCurve *fcu, TransData *td_start, TransData *td, int cfra, bool use_handle)
-{
-  int j = 0;
-  TransData *td_iter = td_start;
-
-  td->dist = FLT_MAX;
-  for (; j < fcu->totvert; j++) {
-    BezTriple *bezt = fcu->bezt + j;
-    if (FrameOnMouseSide(t->frame_side, bezt->vec[1][0], cfra)) {
-      const bool sel2 = (bezt->f2 & SELECT) != 0;
-      const bool sel1 = use_handle ? (bezt->f1 & SELECT) != 0 : sel2;
-      const bool sel3 = use_handle ? (bezt->f3 & SELECT) != 0 : sel2;
-
-      if (sel1 || sel2 || sel3) {
-        td->dist = td->rdist = min_ff(td->dist, fabs(td_iter->center[0] - td->center[0]));
-      }
-
-      td_iter += 3;
-    }
-  }
-}
-
-static void createTransGraphEditData(bContext *C, TransInfo *t)
-{
-  SpaceGraph *sipo = (SpaceGraph *)t->sa->spacedata.first;
-  Scene *scene = t->scene;
-  ARegion *ar = t->ar;
-  View2D *v2d = &ar->v2d;
-
-  TransData *td = NULL;
-  TransData2D *td2d = NULL;
-  TransDataGraph *tdg = NULL;
-
-  bAnimContext ac;
-  ListBase anim_data = {NULL, NULL};
-  bAnimListElem *ale;
-  int filter;
-
-  BezTriple *bezt;
-  int count = 0, i;
-  float mtx[3][3], smtx[3][3];
-  const bool is_translation_mode = graph_edit_is_translation_mode(t);
-  const bool use_handle = !(sipo->flag & SIPO_NOHANDLES);
-  const bool use_local_center = graph_edit_use_local_center(t);
-  const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
-  short anim_map_flag = ANIM_UNITCONV_ONLYSEL | ANIM_UNITCONV_SELVERTS;
-
-  /* determine what type of data we are operating on */
-  if (ANIM_animdata_get_context(C, &ac) == 0) {
-    return;
-  }
-
-  anim_map_flag |= ANIM_get_normalization_flags(&ac);
-
-  /* filter data */
-  filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE);
-  ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
-  /* which side of the current frame should be allowed */
-  // XXX we still want this mode, but how to get this using standard transform too?
-  if (t->mode == TFM_TIME_EXTEND) {
-    /* only side on which mouse is gets transformed */
-    float xmouse, ymouse;
-
-    UI_view2d_region_to_view(v2d, t->mouse.imval[0], t->mouse.imval[1], &xmouse, &ymouse);
-    t->frame_side = (xmouse > CFRA) ? 'R' : 'L';  // XXX use t->frame_side
-  }
-  else {
-    /* normal transform - both sides of current frame are considered */
-    t->frame_side = 'B';
-  }
-
-  /* Loop 1: count how many BezTriples (specifically their verts)
-   * are selected (or should be edited). */
-  for (ale = anim_data.first; ale; ale = ale->next) {
-    AnimData *adt = ANIM_nla_mapping_get(&ac, ale);
-    FCurve *fcu = (FCurve *)ale->key_data;
-    float cfra;
-    int curvecount = 0;
-    bool selected = false;
-
-    /* F-Curve may not have any keyframes */
-    if (fcu->bezt == NULL) {
-      continue;
-    }
-
-    /* convert current-frame to action-time (slightly less accurate, especially under
-     * higher scaling ratios, but is faster than converting all points)
-     */
-    if (adt) {
-      cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
-    }
-    else {
-      cfra = (float)CFRA;
-    }
-
-    /* Only include BezTriples whose 'keyframe'
-     * occurs on the same side of the current frame as mouse. */
-    for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
-      if (FrameOnMouseSide(t->frame_side, bezt->vec[1][0], cfra)) {
-        const bool sel2 = (bezt->f2 & SELECT) != 0;
-        const bool sel1 = use_handle ? (bezt->f1 & SELECT) != 0 : sel2;
-        const bool sel3 = use_handle ? (bezt->f3 & SELECT) != 0 : sel2;
-
-        if (is_prop_edit) {
-          curvecount += 3;
-          if (sel2 || sel1 || sel3) {
-            selected = true;
-          }
-        }
-        else {
-          if (!is_translation_mode || !(sel2)) {
-            if (sel1) {
-              count++;
-            }
-
-            if (sel3) {
-              count++;
-            }
-          }
-
-          /* only include main vert if selected */
-          if (sel2 && !use_local_center) {
-            count++;
-          }
-        }
-      }
-    }
-
-    if (is_prop_edit) {
-      if (selected) {
-        count += curvecount;
-        ale->tag = true;
-      }
-    }
-  }
-
-  /* stop if trying to build list if nothing selected */
-  if (count == 0) {
-    /* cleanup temp list */
-    ANIM_animdata_freelist(&anim_data);
-    return;
-  }
-
-  TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
-
-  /* allocate memory for data */
-  tc->data_len = count;
-
-  tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData (Graph Editor)");
-  /* For each 2d vert a 3d vector is allocated,
-   * so that they can be treated just as if they were 3d verts. */
-  tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D (Graph Editor)");
-  tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataGraph), "TransDataGraph");
-  tc->custom.type.use_free = true;
-
-  td = tc->data;
-  td2d = tc->data_2d;
-  tdg = tc->custom.type.data;
-
-  /* precompute space-conversion matrices for dealing with non-uniform scaling of Graph Editor */
-  unit_m3(mtx);
-  unit_m3(smtx);
-
-  if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE)) {
-    float xscale, yscale;
-
-    /* apply scale factors to x and y axes of space-conversion matrices */
-    UI_view2d_scale_get(v2d, &xscale, &yscale);
-
-    /* mtx is data to global (i.e. view) conversion */
-    mul_v3_fl(mtx[0], xscale);
-    mul_v3_fl(mtx[1], yscale);
-
-    /* smtx is global (i.e. view) to data conversion */
-    if (IS_EQF(xscale, 0.0f) == 0) {
-      mul_v3_fl(smtx[0], 1.0f / xscale);
-    }
-    if (IS_EQF(yscale, 0.0f) == 0) {
-      mul_v3_fl(smtx[1], 1.0f / yscale);
-    }
-  }
-
-  /* loop 2: build transdata arrays */
-  for (ale = anim_data.first; ale; ale = ale->next) {
-    AnimData *adt = ANIM_nla_mapping_get(&ac, ale);
-    FCurve *fcu = (FCurve *)ale->key_data;
-    bool intvals = (fcu->flag & FCURVE_INT_VALUES) != 0;
-    float unit_scale, offset;
-    float cfra;
-
-    /* F-Curve may not have any keyfr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list