quiet some warnings from recent merge
[blender.git] / source / blender / modifiers / intern / MOD_dynamicpaint.c
1 /*
2 * ***** BEGIN GPL LICENSE BLOCK *****
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * Contributor(s): Miika Hämäläinen
10 *
11 * ***** END GPL LICENSE BLOCK *****
12 *
13 */
14
15 #include <stddef.h>
16
17 #include "DNA_dynamicpaint_types.h"
18 #include "DNA_meshdata_types.h"
19 #include "DNA_object_types.h"
20 #include "DNA_scene_types.h"
21
22 #include "MEM_guardedalloc.h"
23
24 #include "BLI_utildefines.h"
25
26 #include "BKE_cdderivedmesh.h"
27 #include "BKE_dynamicpaint.h"
28 #include "BKE_modifier.h"
29
30 #include "depsgraph_private.h"
31
32 #include "MOD_util.h"
33
34
35 static void initData(ModifierData *md) 
36 {
37         DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
38         
39         pmd->canvas = NULL;
40         pmd->brush = NULL;
41         pmd->type = MOD_DYNAMICPAINT_TYPE_CANVAS;
42 }
43
44 static void copyData(ModifierData *md, ModifierData *target)
45 {
46         DynamicPaintModifierData *pmd  = (DynamicPaintModifierData*)md;
47         DynamicPaintModifierData *tpmd = (DynamicPaintModifierData*)target;
48         
49         dynamicPaint_Modifier_copy(pmd, tpmd);
50 }
51
52 static void freeData(ModifierData *md)
53 {
54         DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
55         dynamicPaint_Modifier_free(pmd);
56 }
57
58 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
59 {
60         DynamicPaintModifierData *pmd = (DynamicPaintModifierData*)md;
61         CustomDataMask dataMask = 0;
62
63         if (pmd->canvas) {
64                 DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
65                 for(; surface; surface=surface->next) {
66                         /* tface */
67                         if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ || 
68                                 surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) {
69                                 dataMask |= (1 << CD_MTFACE);
70                         }
71                         /* mcol */
72                         if (surface->type == MOD_DPAINT_SURFACE_T_PAINT ||
73                                 surface->init_color_type == MOD_DPAINT_INITIAL_VERTEXCOLOR) {
74                                 dataMask |= (1 << CD_MCOL);
75                         }
76                         /* CD_MDEFORMVERT */
77                         if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
78                                 dataMask |= (1 << CD_MDEFORMVERT);
79                         }
80                 }
81         }
82
83         if (pmd->brush) {
84                 if (pmd->brush->flags & MOD_DPAINT_USE_MATERIAL) {
85                         dataMask |= (1 << CD_MTFACE);
86                 }
87         }
88         return dataMask;
89 }
90
91 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, 
92                                                 DerivedMesh *dm,
93                                                 int UNUSED(useRenderParams),
94                                                 int UNUSED(isFinalCalc))
95 {
96         DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
97
98         return dynamicPaint_Modifier_do(pmd, md->scene, ob, dm);
99 }
100
101 static void updateDepgraph(ModifierData *md, DagForest *forest,
102                                                 struct Scene *scene,
103                                                 Object *ob,
104                                                 DagNode *obNode)
105 {
106         DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
107
108         /* add relation from canvases to all brush objects */
109         if(pmd && pmd->canvas)
110         {
111                 Base *base = scene->base.first;
112
113                 for(; base; base = base->next) {
114                         DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint);
115
116                         if(pmd2 && pmd2->brush && ob!=base->object)
117                         {
118                                 DagNode *brushNode = dag_get_node(forest, base->object);
119                                 dag_add_relation(forest, brushNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Dynamic Paint Brush");
120                         }
121                 }
122         }
123 }
124
125 static int dependsOnTime(ModifierData *UNUSED(md))
126 {
127         return 1;
128 }
129
130 static void foreachIDLink(ModifierData *md, Object *ob,
131                                            IDWalkFunc walk, void *userData)
132 {
133         DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
134
135         if(pmd->canvas) {
136                 DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
137
138                 for(; surface; surface=surface->next) {
139                         walk(userData, ob, (ID **)&surface->brush_group);
140                         walk(userData, ob, (ID **)&surface->init_texture);
141                 }
142         }
143         if (pmd->brush) {
144                 walk(userData, ob, (ID **)&pmd->brush->mat);
145         }
146 }
147
148 static void foreachTexLink(ModifierData *UNUSED(md), Object *UNUSED(ob),
149                                            TexWalkFunc UNUSED(walk), void *UNUSED(userData))
150 {
151         //walk(userData, ob, md, ""); /* re-enable when possible */
152 }
153
154 ModifierTypeInfo modifierType_DynamicPaint = {
155         /* name */              "Dynamic Paint",
156         /* structName */        "DynamicPaintModifierData",
157         /* structSize */        sizeof(DynamicPaintModifierData),
158         /* type */              eModifierTypeType_Constructive,
159         /* flags */             eModifierTypeFlag_AcceptsMesh
160                                                         | eModifierTypeFlag_UsesPointCache
161                                                         | eModifierTypeFlag_Single,
162
163         /* copyData */          copyData,
164         /* deformVerts */       0,
165         /* deformMatrices */    0,
166         /* deformVertsEM */     0,
167         /* deformMatricesEM */  0,
168         /* applyModifier */     applyModifier,
169         /* applyModifierEM */   0,
170         /* initData */          initData,
171         /* requiredDataMask */  requiredDataMask,
172         /* freeData */          freeData,
173         /* isDisabled */        0,
174         /* updateDepgraph */    updateDepgraph,
175         /* dependsOnTime */     dependsOnTime,
176         /* dependsOnNormals */  0,
177         /* foreachObjectLink */ 0,
178         /* foreachIDLink */     foreachIDLink,
179         /* foreachTexLink */    foreachTexLink,
180 };