[Bf-blender-cvs] [12c5ed6aca3] gpencil-new-data-proposal: new to old data structure : conversion of layers and frames, no strokes yet

Amelie Fondevilla noreply at git.blender.org
Mon Dec 5 15:01:22 CET 2022


Commit: 12c5ed6aca3af178403b508ebe88e655c1285528
Author: Amelie Fondevilla
Date:   Mon Dec 5 15:01:14 2022 +0100
Branches: gpencil-new-data-proposal
https://developer.blender.org/rB12c5ed6aca3af178403b508ebe88e655c1285528

new to old data structure : conversion of layers and frames, no strokes yet

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

M	source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc

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

diff --git a/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc b/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc
index 17295b3c469..02513b45171 100644
--- a/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc
+++ b/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc
@@ -38,6 +38,37 @@ bGPdata *convert_new_to_old_gpencil_data(const GPData &new_gpd)
 {
   bGPdata *gpd = reinterpret_cast<bGPdata *>(MEM_mallocN(sizeof(bGPdata), __func__));
 
+  BLI_listbase_clear(&gpd->layers);
+  gpd->totlayer = gpd->totframe = gpd->totstroke = 0;
+
+  int frm_offset{0};
+  gpd->totlayer = new_gpd.layers_size;
+  for (int lay_i = 0; lay_i < new_gpd.layers_size; lay_i++) {
+    bGPDlayer *gpl = reinterpret_cast<bGPDlayer *>(MEM_mallocN(sizeof(bGPDlayer), __func__));
+    const ::GPLayer *lay{new_gpd.layers_array + lay_i};
+    sprintf(gpl->info, "%s", lay->name);
+
+    BLI_listbase_clear(&gpl->mask_layers);
+    BLI_listbase_clear(&gpl->frames);
+    BLI_addtail(&gpd->layers, gpl);
+
+    /* Add frames of correct layer index.
+       Assumes that frames in new data structure are sorted by layer index.
+    */
+    while ((frm_offset < new_gpd.frames_size) &&
+           (new_gpd.frames_array[frm_offset].layer_index == lay_i)) {
+      bGPDframe *gpf = reinterpret_cast<bGPDframe *>(MEM_mallocN(sizeof(bGPDframe), __func__));
+      const ::GPFrame *frm{new_gpd.frames_array + frm_offset};
+      gpf->framenum = frm->start_time;
+
+      BLI_listbase_clear(&gpf->strokes);
+
+      BLI_addtail(&gpl->frames, gpf);
+      ++(gpd->totframe);
+      ++frm_offset;
+    }
+  }
+
   return gpd;
 }



More information about the Bf-blender-cvs mailing list