[Bf-blender-cvs] [02c13cad057] asset-greasepencil: GPencil: Use current frame to insert asset instead of absolute values
Antonio Vazquez
noreply at git.blender.org
Wed Jul 21 17:30:08 CEST 2021
Commit: 02c13cad057c6c96a5a8331051c84df070db8c6f
Author: Antonio Vazquez
Date: Wed Jul 21 17:30:00 2021 +0200
Branches: asset-greasepencil
https://developer.blender.org/rB02c13cad057c6c96a5a8331051c84df070db8c6f
GPencil: Use current frame to insert asset instead of absolute values
===================================================================
M source/blender/editors/gpencil/gpencil_asset.c
===================================================================
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
@@ -742,6 +742,20 @@ static void gpencil_asset_transform_strokes(tGPDasset *tgpa,
copy_v2_v2(tgpa->vinit_rotation, vr);
}
+/* 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)
{
@@ -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) {
More information about the Bf-blender-cvs
mailing list