Cleanup: Rename callback flags from library_query to `IDWALK_CB_...`
[blender-staging.git] / source / blender / modifiers / intern / MOD_uvproject.c
index 88951919272bc9e4e7dea7edfd5f2ecb265f9d80..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];
@@ -212,7 +214,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
                                params.viewplane.ymax *= scay;
 
                                BKE_camera_params_compute_matrix(&params);
-                               mult_m4_m4m4(tmpmat, params.winmat, projectors[i].projmat);
+                               mul_m4_m4m4(tmpmat, params.winmat, projectors[i].projmat);
                        }
                }
                else {
@@ -223,7 +225,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
                mul_mat3_m4_fl(offsetmat, 0.5);
                offsetmat[3][0] = offsetmat[3][1] = offsetmat[3][2] = 0.5;
 
-               mult_m4_m4m4(projectors[i].projmat, offsetmat, tmpmat);
+               mul_m4_m4m4(projectors[i].projmat, offsetmat, tmpmat);
 
                /* calculate worldspace projector normal (for best projector test) */
                projectors[i].normal[0] = 0;
@@ -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);
 
@@ -321,12 +323,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
                                        do {
                                                unsigned int lidx = mp->loopstart + fidx;
                                                unsigned int vidx = mloop[lidx].v;
-                                               float tco[3];
-
-                                               copy_v3_v3(tco, coords[vidx]);
-                                               mul_project_m4_v3(best_projector->projmat, tco);
-                                               copy_v2_v2(mloop_uv[lidx].uv, tco);
-
+                                               mul_v2_project_m4_v3(mloop_uv[lidx].uv, best_projector->projmat, coords[vidx]);
                                        } while (fidx--);
                                }
                        }
@@ -366,13 +363,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        return result;
 }
 
-static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob,
-                                    struct BMEditMesh *UNUSED(editData),
-                                    DerivedMesh *derivedData)
-{
-       return applyModifier(md, ob, derivedData, MOD_APPLY_USECACHE);
-}
-
 
 ModifierTypeInfo modifierType_UVProject = {
        /* name */              "UVProject",
@@ -390,12 +380,13 @@ ModifierTypeInfo modifierType_UVProject = {
        /* deformVertsEM */     NULL,
        /* deformMatricesEM */  NULL,
        /* applyModifier */     applyModifier,
-       /* applyModifierEM */   applyModifierEM,
+       /* applyModifierEM */   NULL,
        /* initData */          initData,
        /* requiredDataMask */  requiredDataMask,
        /* freeData */          NULL,
        /* isDisabled */        NULL,
        /* updateDepgraph */    updateDepgraph,
+       /* updateDepsgraph */   updateDepsgraph,
        /* dependsOnTime */     NULL,
        /* dependsOnNormals */  NULL,
        /* foreachObjectLink */ foreachObjectLink,