Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2021-07-21 18:30:00 +0300
committerAntonio Vazquez <blendergit@gmail.com>2021-07-21 18:30:00 +0300
commit02c13cad057c6c96a5a8331051c84df070db8c6f (patch)
tree13f8618effac63298db0b4a136c8531558ab4b73 /source/blender
parentcdd7a00a50aca7a2aefa3c833bbd37df2ec36bf0 (diff)
GPencil: Use current frame to insert asset instead of absolute values
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/gpencil/gpencil_asset.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/source/blender/editors/gpencil/gpencil_asset.c b/source/blender/editors/gpencil/gpencil_asset.c
index 0b353e8ac23..76e37c67467 100644
--- a/source/blender/editors/gpencil/gpencil_asset.c
+++ b/source/blender/editors/gpencil/gpencil_asset.c
@@ -743,6 +743,20 @@ static void gpencil_asset_transform_strokes(tGPDasset *tgpa,
}
/* Helper: Get a material from the datablock */
+static int gpencil_asset_get_first_franum(bGPdata *gpd)
+{
+ int first_fra = INT_MAX;
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ if (gpf->framenum < first_fra) {
+ first_fra = gpf->framenum;
+ }
+ }
+ }
+ return first_fra;
+}
+
+/* Helper: Get a material from the datablock */
static Material *gpencil_asset_material_get_from_id(ID *id, const int slot_index)
{
const short *tot_slots_data_ptr = BKE_id_material_len_p(id);
@@ -772,6 +786,8 @@ static void gpencil_asset_add_strokes(tGPDasset *tgpa)
float vec[3];
sub_v3_v3v3(vec, dest_pt, tgpa->ob->loc);
+ /* Get the first frame in the asset. */
+ int const first_fra = gpencil_asset_get_first_franum(gpd_asset);
/* Layers must be added inverse to keep strokes order. */
LISTBASE_FOREACH_BACKWARD (bGPDlayer *, gpl_asset, &gpd_asset->layers) {
@@ -790,11 +806,11 @@ static void gpencil_asset_add_strokes(tGPDasset *tgpa)
LISTBASE_FOREACH (bGPDframe *, gpf_asset, &gpl_asset->frames) {
/* Check if frame is in target layer. */
- bGPDframe *gpf_target = BKE_gpencil_layer_frame_get(
- gpl_target, gpf_asset->framenum, GP_GETFRAME_USE_PREV);
- if (gpf_target == NULL) {
- gpf_target = BKE_gpencil_layer_frame_get(
- gpl_target, gpf_asset->framenum, GP_GETFRAME_ADD_NEW);
+ int fra = tgpa->cframe + (gpf_asset->framenum - first_fra);
+ bGPDframe *gpf_target = BKE_gpencil_layer_frame_get(gpl_target, fra, GP_GETFRAME_USE_PREV);
+
+ if ((gpf_target == NULL) || (gpf_target->framenum != fra)) {
+ gpf_target = BKE_gpencil_layer_frame_get(gpl_target, fra, GP_GETFRAME_ADD_NEW);
BLI_assert(gpf_target != NULL);
if (tgpa->asset_frames == NULL) {