style cleanup, brackets in else/if, some indentation.
[blender.git] / source / blender / modifiers / intern / MOD_dynamicpaint.c
index 1e01114..e567765 100644 (file)
@@ -1,28 +1,44 @@
 /*
-* ***** BEGIN GPL LICENSE BLOCK *****
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* Contributor(s): Miika Hämäläinen
-*
-* ***** END GPL LICENSE BLOCK *****
-*
-*/
-
-#include "stddef.h"
-
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software  Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Miika Hämäläinen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/modifiers/intern/MOD_dynamicpaint.c
+ *  \ingroup modifiers
+ */
+
+#include <stddef.h>
+
+#include "DNA_dynamicpaint_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
+
 #include "BKE_cdderivedmesh.h"
-#include "BKE_modifier.h"
 #include "BKE_dynamicpaint.h"
+#include "BKE_modifier.h"
 
 #include "depsgraph_private.h"
 
@@ -49,24 +65,46 @@ static void copyData(ModifierData *md, ModifierData *target)
 static void freeData(ModifierData *md)
 {
        DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
-       dynamicPaint_Modifier_free (pmd);
+       dynamicPaint_Modifier_free(pmd);
 }
 
-static CustomDataMask requiredDataMask(Object *ob, ModifierData *md)
+static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
 {
+       DynamicPaintModifierData *pmd = (DynamicPaintModifierData*)md;
        CustomDataMask dataMask = 0;
 
-       dataMask |= (1 << CD_MTFACE);
-       dataMask |= (1 << CD_MCOL);
-       dataMask |= (1 << CD_MDEFORMVERT);
+       if (pmd->canvas) {
+               DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
+               for(; surface; surface=surface->next) {
+                       /* tface */
+                       if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ || 
+                               surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) {
+                               dataMask |= (1 << CD_MTFACE);
+                       }
+                       /* mcol */
+                       if (surface->type == MOD_DPAINT_SURFACE_T_PAINT ||
+                               surface->init_color_type == MOD_DPAINT_INITIAL_VERTEXCOLOR) {
+                               dataMask |= (1 << CD_MCOL);
+                       }
+                       /* CD_MDEFORMVERT */
+                       if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
+                               dataMask |= (1 << CD_MDEFORMVERT);
+                       }
+               }
+       }
 
+       if (pmd->brush) {
+               if (pmd->brush->flags & MOD_DPAINT_USE_MATERIAL) {
+                       dataMask |= (1 << CD_MTFACE);
+               }
+       }
        return dataMask;
 }
 
 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, 
                                                DerivedMesh *dm,
-                                               int useRenderParams,
-                                               int isFinalCalc)
+                                               int UNUSED(useRenderParams),
+                                               int UNUSED(isFinalCalc))
 {
        DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
 
@@ -81,15 +119,13 @@ static void updateDepgraph(ModifierData *md, DagForest *forest,
        DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
 
        /* add relation from canvases to all brush objects */
-       if(pmd && pmd->canvas)
-       {
+       if (pmd && pmd->canvas) {
                Base *base = scene->base.first;
 
-               for(; base; base = base->next) {
+               for (; base; base = base->next) {
                        DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint);
 
-                       if(pmd2 && pmd2->brush && ob!=base->object)
-                       {
+                       if (pmd2 && pmd2->brush && ob!=base->object) {
                                DagNode *brushNode = dag_get_node(forest, base->object);
                                dag_add_relation(forest, brushNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Dynamic Paint Brush");
                        }
@@ -97,7 +133,7 @@ static void updateDepgraph(ModifierData *md, DagForest *forest,
        }
 }
 
-static int dependsOnTime(ModifierData *md)
+static int dependsOnTime(ModifierData *UNUSED(md))
 {
        return 1;
 }
@@ -120,10 +156,10 @@ static void foreachIDLink(ModifierData *md, Object *ob,
        }
 }
 
-static void foreachTexLink(ModifierData *md, Object *ob,
-                                          TexWalkFunc walk, void *userData)
+static void foreachTexLink(ModifierData *UNUSED(md), Object *UNUSED(ob),
+                                          TexWalkFunc UNUSED(walk), void *UNUSED(userData))
 {
-       walk(userData, ob, md, ""); /* property name isn't used */
+       //walk(userData, ob, md, ""); /* re-enable when possible */
 }
 
 ModifierTypeInfo modifierType_DynamicPaint = {
@@ -132,24 +168,26 @@ ModifierTypeInfo modifierType_DynamicPaint = {
        /* structSize */        sizeof(DynamicPaintModifierData),
        /* type */              eModifierTypeType_Constructive,
        /* flags */             eModifierTypeFlag_AcceptsMesh
-                                                       | eModifierTypeFlag_UsesPointCache
-                                                       | eModifierTypeFlag_Single,
+/*                            |eModifierTypeFlag_SupportsMapping*/
+                              |eModifierTypeFlag_UsesPointCache
+                              |eModifierTypeFlag_Single
+                              |eModifierTypeFlag_UsesPreview,
 
        /* copyData */          copyData,
-       /* deformVerts */       0,
-       /* deformMatrices */    0,
-       /* deformVertsEM */     0,
-       /* deformMatricesEM */  0,
+       /* deformVerts */       NULL,
+       /* deformMatrices */    NULL,
+       /* deformVertsEM */     NULL,
+       /* deformMatricesEM */  NULL,
        /* applyModifier */     applyModifier,
-       /* applyModifierEM */   0,
+       /* applyModifierEM */   NULL,
        /* initData */          initData,
        /* requiredDataMask */  requiredDataMask,
        /* freeData */          freeData,
-       /* isDisabled */        0,
+       /* isDisabled */        NULL,
        /* updateDepgraph */    updateDepgraph,
        /* dependsOnTime */     dependsOnTime,
-       /* dependsOnNormals */  0,
-       /* foreachObjectLink */ 0,
+       /* dependsOnNormals */  NULL,
+       /* foreachObjectLink */ NULL,
        /* foreachIDLink */     foreachIDLink,
        /* foreachTexLink */    foreachTexLink,
 };