Cleanup: Rename callback flags from library_query to `IDWALK_CB_...`
[blender-staging.git] / source / blender / modifiers / intern / MOD_uvproject.c
index b6539f4b028fcffd6151c3f2d5da31df89b52ee8..78dc1ea8bcb2968b821c2ceee96ade28f7f62cb5 100644 (file)
 #include "DNA_meshdata_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_object_types.h"
-#include "DNA_scene_types.h"
 
 #include "BLI_math.h"
-#include "BLI_string.h"
 #include "BLI_uvproject.h"
 #include "BLI_utildefines.h"
 
 
 #include "BKE_camera.h"
+#include "BKE_library_query.h"
 #include "BKE_mesh.h"
 #include "BKE_DerivedMesh.h"
 
 #include "MOD_modifiertypes.h"
-#include "MOD_util.h"
 
 #include "MEM_guardedalloc.h"
+
 #include "depsgraph_private.h"
+#include "DEG_depsgraph_build.h"
 
 static void initData(ModifierData *md)
 {
        UVProjectModifierData *umd = (UVProjectModifierData *) md;
-       int i;
 
-       for (i = 0; i < MOD_UVPROJECT_MAXPROJECTORS; ++i)
-               umd->projectors[i] = NULL;
-       umd->image = NULL;
        umd->flags = 0;
        umd->num_projectors = 1;
        umd->aspectx = umd->aspecty = 1.0f;
@@ -72,20 +68,11 @@ static void initData(ModifierData *md)
 
 static void copyData(ModifierData *md, ModifierData *target)
 {
+#if 0
        UVProjectModifierData *umd = (UVProjectModifierData *) md;
        UVProjectModifierData *tumd = (UVProjectModifierData *) target;
-       int i;
-
-       for (i = 0; i < MOD_UVPROJECT_MAXPROJECTORS; ++i)
-               tumd->projectors[i] = umd->projectors[i];
-       tumd->image = umd->image;
-       tumd->flags = umd->flags;
-       tumd->num_projectors = umd->num_projectors;
-       tumd->aspectx = umd->aspectx;
-       tumd->aspecty = umd->aspecty;
-       tumd->scalex = umd->scalex;
-       tumd->scaley = umd->scaley;
-       BLI_strncpy(tumd->uvlayer_name, umd->uvlayer_name, sizeof(umd->uvlayer_name));
+#endif
+       modifier_copyData_generic(md, target);
 }
 
 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md))
@@ -93,7 +80,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(
        CustomDataMask dataMask = 0;
 
        /* ask for UV coordinates */
-       dataMask |= CD_MASK_MTFACE;
+       dataMask |= CD_MLOOPUV | CD_MTEXPOLY;
 
        return dataMask;
 }
@@ -105,7 +92,7 @@ static void foreachObjectLink(ModifierData *md, Object *ob,
        int i;
 
        for (i = 0; i < MOD_UVPROJECT_MAXPROJECTORS; ++i)
-               walk(userData, ob, &umd->projectors[i]);
+               walk(userData, ob, &umd->projectors[i], IDWALK_CB_NOP);
 }
 
 static void foreachIDLink(ModifierData *md, Object *ob,
@@ -113,13 +100,13 @@ static void foreachIDLink(ModifierData *md, Object *ob,
 {
        UVProjectModifierData *umd = (UVProjectModifierData *) md;
 
-       walk(userData, ob, (ID **)&umd->image);
+       walk(userData, ob, (ID **)&umd->image, IDWALK_CB_USER);
 
-       foreachObjectLink(md, ob, (ObjectWalkFunc)walk,
-                         userData);
+       foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
 }
 
 static void updateDepgraph(ModifierData *md, DagForest *forest,
+                           struct Main *UNUSED(bmain),
                            struct Scene *UNUSED(scene),
                            Object *UNUSED(ob),
                            DagNode *obNode)
@@ -137,6 +124,21 @@ static void updateDepgraph(ModifierData *md, DagForest *forest,
        }
 }
 
+static void updateDepsgraph(ModifierData *md,
+                            struct Main *UNUSED(bmain),
+                            struct Scene *UNUSED(scene),
+                            Object *UNUSED(ob),
+                            struct DepsNodeHandle *node)
+{
+       UVProjectModifierData *umd = (UVProjectModifierData *)md;
+       int i;
+       for (i = 0; i < umd->num_projectors; ++i) {
+               if (umd->projectors[i] != NULL) {
+                       DEG_add_object_relation(node, umd->projectors[i], DEG_OB_COMP_TRANSFORM, "UV Project Modifier");
+               }
+       }
+}
+
 typedef struct Projector {
        Object *ob;             /* object this projector is derived from */
        float projmat[4][4];    /* projection matrix */
@@ -154,7 +156,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
        Image *image = umd->image;
        MPoly *mpoly, *mp;
        MLoop *mloop;
-       int override_image = ((umd->flags & MOD_UVPROJECT_OVERRIDEIMAGE) != 0);
+       const bool override_image = (umd->flags & MOD_UVPROJECT_OVERRIDEIMAGE) != 0;
        Projector projectors[MOD_UVPROJECT_MAXPROJECTORS];
        int num_projectors = 0;
        char uvname[MAX_CUSTOMDATA_LAYER_NAME];
@@ -245,7 +247,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
 
        numVerts = dm->getNumVerts(dm);
 
-       coords = MEM_callocN(sizeof(*coords) * numVerts,
+       coords = MEM_mallocN(sizeof(*coords) * numVerts,
                             "uvprojectModifier_do coords");
        dm->getVertCos(dm, coords);
 
@@ -384,6 +386,7 @@ ModifierTypeInfo modifierType_UVProject = {
        /* freeData */          NULL,
        /* isDisabled */        NULL,
        /* updateDepgraph */    updateDepgraph,
+       /* updateDepsgraph */   updateDepsgraph,
        /* dependsOnTime */     NULL,
        /* dependsOnNormals */  NULL,
        /* foreachObjectLink */ foreachObjectLink,