code cleanup: make bmesh operator names more consistant since python has access to...
[blender.git] / source / blender / modifiers / intern / MOD_smoke.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  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software  Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Daniel Dunbar
22  *                 Ton Roosendaal,
23  *                 Ben Batt,
24  *                 Brecht Van Lommel,
25  *                 Campbell Barton
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  *
29  */
30
31 /** \file blender/modifiers/intern/MOD_smoke.c
32  *  \ingroup modifiers
33  */
34
35
36 #include <stddef.h>
37
38 #include "MEM_guardedalloc.h"
39
40 #include "DNA_group_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_smoke_types.h"
44 #include "DNA_object_force.h"
45
46 #include "BLI_utildefines.h"
47
48
49 #include "BKE_cdderivedmesh.h"
50 #include "BKE_modifier.h"
51 #include "BKE_smoke.h"
52
53 #include "depsgraph_private.h"
54
55 #include "MOD_util.h"
56
57
58 static void initData(ModifierData *md) 
59 {
60         SmokeModifierData *smd = (SmokeModifierData *) md;
61         
62         smd->domain = NULL;
63         smd->flow = NULL;
64         smd->coll = NULL;
65         smd->type = 0;
66         smd->time = -1;
67 }
68
69 static void copyData(ModifierData *md, ModifierData *target)
70 {
71         SmokeModifierData *smd  = (SmokeModifierData *)md;
72         SmokeModifierData *tsmd = (SmokeModifierData *)target;
73         
74         smokeModifier_copy(smd, tsmd);
75 }
76
77 static void freeData(ModifierData *md)
78 {
79         SmokeModifierData *smd = (SmokeModifierData *) md;
80         
81         smokeModifier_free(smd);
82 }
83
84 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
85 {
86         SmokeModifierData *smd  = (SmokeModifierData *)md;
87         CustomDataMask dataMask = 0;
88
89         if (smd && (smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
90                 if (smd->flow->source == MOD_SMOKE_FLOW_SOURCE_MESH) {
91                         /* vertex groups */
92                         if (smd->flow->vgroup_density)
93                                 dataMask |= CD_MASK_MDEFORMVERT;
94                         /* uv layer */
95                         if (smd->flow->texture_type == MOD_SMOKE_FLOW_TEXTURE_MAP_UV)
96                                 dataMask |= CD_MASK_MTFACE;
97                 }
98         }
99         return dataMask;
100 }
101
102 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, 
103                                   DerivedMesh *dm,
104                                   ModifierApplyFlag UNUSED(flag))
105 {
106         SmokeModifierData *smd = (SmokeModifierData *) md;
107
108         return smokeModifier_do(smd, md->scene, ob, dm);
109 }
110
111 static int dependsOnTime(ModifierData *UNUSED(md))
112 {
113         return 1;
114 }
115
116 static void updateDepgraph(ModifierData *md, DagForest *forest,
117                            struct Scene *scene, struct Object *ob,
118                            DagNode *obNode)
119 {
120         SmokeModifierData *smd = (SmokeModifierData *) md;
121         Base *base;
122
123         if (smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
124                 if (smd->domain->fluid_group || smd->domain->coll_group) {
125                         GroupObject *go = NULL;
126                         
127                         if (smd->domain->fluid_group)
128                                 for (go = smd->domain->fluid_group->gobject.first; go; go = go->next) {
129                                         if (go->ob) {
130                                                 SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(go->ob, eModifierType_Smoke);
131                                                 
132                                                 /* check for initialized smoke object */
133                                                 if (smd2 && (smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) {
134                                                         DagNode *curNode = dag_get_node(forest, go->ob);
135                                                         dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Smoke Flow");
136                                                 }
137                                         }
138                                 }
139
140                         if (smd->domain->coll_group)
141                                 for (go = smd->domain->coll_group->gobject.first; go; go = go->next) {
142                                         if (go->ob) {
143                                                 SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(go->ob, eModifierType_Smoke);
144                                                 
145                                                 /* check for initialized smoke object */
146                                                 if (smd2 && (smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll) {
147                                                         DagNode *curNode = dag_get_node(forest, go->ob);
148                                                         dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Smoke Coll");
149                                                 }
150                                         }
151                                 }
152                 }
153                 else {
154                         base = scene->base.first;
155                         for (; base; base = base->next) {
156                                 SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(base->object, eModifierType_Smoke);
157
158                                 if (smd2 && (((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) || ((smd2->type & MOD_SMOKE_TYPE_COLL) && smd2->coll))) {
159                                         DagNode *curNode = dag_get_node(forest, base->object);
160                                         dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Smoke Flow/Coll");
161                                 }
162                         }
163                 }
164                 /* add relation to all "smoke flow" force fields */
165                 base = scene->base.first;
166                 for (; base; base = base->next) {
167                         if (base->object->pd && base->object->pd->forcefield == PFIELD_SMOKEFLOW && base->object->pd->f_source == ob) {
168                                 DagNode *node2 = dag_get_node(forest, base->object);
169                                 dag_add_relation(forest, obNode, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Field Source Object");
170                         }
171                 }
172         }
173 }
174
175 static void foreachIDLink(ModifierData *md, Object *ob,
176                           IDWalkFunc walk, void *userData)
177 {
178         SmokeModifierData *smd = (SmokeModifierData *) md;
179
180         if (smd->type == MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
181                 walk(userData, ob, (ID **)&smd->domain->coll_group);
182                 walk(userData, ob, (ID **)&smd->domain->fluid_group);
183                 walk(userData, ob, (ID **)&smd->domain->eff_group);
184
185                 if (smd->domain->effector_weights) {
186                         walk(userData, ob, (ID **)&smd->domain->effector_weights->group);
187                 }
188         }
189
190         if (smd->type == MOD_SMOKE_TYPE_FLOW && smd->flow) {
191                 walk(userData, ob, (ID **)&smd->flow->noise_texture);
192         }
193 }
194
195 ModifierTypeInfo modifierType_Smoke = {
196         /* name */              "Smoke",
197         /* structName */        "SmokeModifierData",
198         /* structSize */        sizeof(SmokeModifierData),
199         /* type */              eModifierTypeType_Constructive,
200         /* flags */             eModifierTypeFlag_AcceptsMesh |
201                                 eModifierTypeFlag_UsesPointCache |
202                                 eModifierTypeFlag_Single,
203
204         /* copyData */          copyData,
205         /* deformVerts */       NULL,
206         /* deformMatrices */    NULL,
207         /* deformVertsEM */     NULL,
208         /* deformMatricesEM */  NULL,
209         /* applyModifier */     applyModifier,
210         /* applyModifierEM */   NULL,
211         /* initData */          initData,
212         /* requiredDataMask */  requiredDataMask,
213         /* freeData */          freeData,
214         /* isDisabled */        NULL,
215         /* updateDepgraph */    updateDepgraph,
216         /* dependsOnTime */     dependsOnTime,
217         /* dependsOnNormals */  NULL,
218         /* foreachObjectLink */ NULL,
219         /* foreachIDLink */     foreachIDLink,
220         /* foreachTexLink */    NULL
221 };