Data Transfer Modifier: fix mesh_get_eval_final usage.
authorAlexander Gavrilov <angavrilov@gmail.com>
Mon, 3 Dec 2018 13:56:11 +0000 (16:56 +0300)
committerAlexander Gavrilov <angavrilov@gmail.com>
Mon, 3 Dec 2018 14:01:02 +0000 (17:01 +0300)
It can't be used during modifier evaluation, and rna
enum code should access the evaluated objects.

source/blender/blenkernel/intern/data_transfer.c
source/blender/makesrna/intern/rna_modifier.c
source/blender/modifiers/intern/MOD_datatransfer.c

index 73c5f6cecdf85ef2865b9ec9c82144fea79e0508..7ac9d2d985c9a05683df44d3cbedba0507967774 100644 (file)
@@ -1087,6 +1087,7 @@ bool BKE_object_data_transfer_ex(
        bool geom_map_init[DATAMAX] = {0};
        ListBase lay_map = {NULL};
        bool changed = false;
        bool geom_map_init[DATAMAX] = {0};
        ListBase lay_map = {NULL};
        bool changed = false;
+       bool is_modifier = false;
 
        const bool use_delete = false;  /* We never delete data layers from destination here. */
 
 
        const bool use_delete = false;  /* We never delete data layers from destination here. */
 
@@ -1099,6 +1100,7 @@ bool BKE_object_data_transfer_ex(
                /* Never create needed custom layers on passed destination mesh
                 * (assumed to *not* be ob_dst->data, aka modifier case). */
                use_create = false;
                /* Never create needed custom layers on passed destination mesh
                 * (assumed to *not* be ob_dst->data, aka modifier case). */
                use_create = false;
+               is_modifier = true;
        }
        else {
                me_dst = ob_dst->data;
        }
        else {
                me_dst = ob_dst->data;
@@ -1113,7 +1115,17 @@ bool BKE_object_data_transfer_ex(
 
        /* Get source evaluated mesh.*/
        me_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types);
 
        /* Get source evaluated mesh.*/
        me_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types);
-       me_src = mesh_get_eval_final(depsgraph, scene, ob_src, me_src_mask);
+       if (is_modifier) {
+               me_src = ob_src->runtime.mesh_eval;
+
+               if (me_src == NULL || (me_src_mask & ~ob_src->lastDataMask) != 0) {
+                       printf("Data Transfer: source mesh data is not ready - dependency cycle?\n");
+                       return changed;
+               }
+       }
+       else {
+               me_src = mesh_get_eval_final(depsgraph, scene, ob_src, me_src_mask);
+       }
        if (!me_src) {
                return changed;
        }
        if (!me_src) {
                return changed;
        }
index aa35f6e3278adff86cf3240d0761928e6845f40a..5e69f8a32f3bbbd517e895bfae49422558098b0f 100644 (file)
@@ -312,6 +312,7 @@ const EnumPropertyItem rna_enum_axis_flag_xyz_items[] = {
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
 
 #ifdef WITH_ALEMBIC
 #  include "ABC_alembic.h"
 
 #ifdef WITH_ALEMBIC
 #  include "ABC_alembic.h"
@@ -902,7 +903,6 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf(
        }
 
        Depsgraph *depsgraph = CTX_data_depsgraph(C);
        }
 
        Depsgraph *depsgraph = CTX_data_depsgraph(C);
-       Scene *scene = CTX_data_scene(C);
 
        /* No active here! */
        RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC);
 
        /* No active here! */
        RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC);
@@ -940,7 +940,10 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf(
                        Mesh *me_eval;
                        int num_data, i;
 
                        Mesh *me_eval;
                        int num_data, i;
 
-                       me_eval = mesh_get_eval_final(depsgraph, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPUV);
+                       Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
+                       Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src);
+
+                       me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, CD_MASK_BAREMESH | CD_MLOOPUV);
                        num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPUV);
 
                        RNA_enum_item_add_separator(&item, &totitem);
                        num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPUV);
 
                        RNA_enum_item_add_separator(&item, &totitem);
@@ -959,7 +962,10 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf(
                        Mesh *me_eval;
                        int num_data, i;
 
                        Mesh *me_eval;
                        int num_data, i;
 
-                       me_eval = mesh_get_eval_final(depsgraph, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPCOL);
+                       Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
+                       Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src);
+
+                       me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, CD_MASK_BAREMESH | CD_MLOOPCOL);
                        num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPCOL);
 
                        RNA_enum_item_add_separator(&item, &totitem);
                        num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPCOL);
 
                        RNA_enum_item_add_separator(&item, &totitem);
index d3c0dd783cccd928f4f0968cf5050883d14f5da0..b2cb82d6be3f17ccb2b8f976a5104b6643c28a19 100644 (file)
@@ -176,7 +176,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
                BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, dtmd->ob_source);
        }
 
                BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, dtmd->ob_source);
        }
 
-       if ((result == me_mod || (me->mvert == result->mvert) || (me->medge == result->medge)) &&
+       if (((result == me) || (me->mvert == result->mvert) || (me->medge == result->medge)) &&
            (dtmd->data_types & DT_TYPES_AFFECT_MESH))
        {
                /* We need to duplicate data here, otherwise setting custom normals, edges' shaprness, etc., could
            (dtmd->data_types & DT_TYPES_AFFECT_MESH))
        {
                /* We need to duplicate data here, otherwise setting custom normals, edges' shaprness, etc., could