b13d86a609e1035d389c9409b5e7c6065451adb5
[blender.git] / source / blender / modifiers / intern / MOD_smoke.c
1 /*
2 * $Id$
3 *
4 * ***** BEGIN GPL LICENSE BLOCK *****
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software  Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * The Original Code is Copyright (C) 2005 by the Blender Foundation.
21 * All rights reserved.
22 *
23 * Contributor(s): Daniel Dunbar
24 *                 Ton Roosendaal,
25 *                 Ben Batt,
26 *                 Brecht Van Lommel,
27 *                 Campbell Barton
28 *
29 * ***** END GPL LICENSE BLOCK *****
30 *
31 */
32
33 /** \file blender/modifiers/intern/MOD_smoke.c
34  *  \ingroup modifiers
35  */
36
37
38 #include <stddef.h>
39
40 #include "MEM_guardedalloc.h"
41
42 #include "DNA_group_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_smoke_types.h"
46
47 #include "BLI_utildefines.h"
48
49
50 #include "BKE_cdderivedmesh.h"
51 #include "BKE_modifier.h"
52 #include "BKE_smoke.h"
53
54 #include "depsgraph_private.h"
55
56 #include "MOD_util.h"
57
58
59 static void initData(ModifierData *md) 
60 {
61         SmokeModifierData *smd = (SmokeModifierData*) md;
62         
63         smd->domain = NULL;
64         smd->flow = NULL;
65         smd->coll = NULL;
66         smd->type = 0;
67         smd->time = -1;
68 }
69
70 static void copyData(ModifierData *md, ModifierData *target)
71 {
72         SmokeModifierData *smd  = (SmokeModifierData*)md;
73         SmokeModifierData *tsmd = (SmokeModifierData*)target;
74         
75         smokeModifier_copy(smd, tsmd);
76 }
77
78 static void freeData(ModifierData *md)
79 {
80         SmokeModifierData *smd = (SmokeModifierData*) md;
81         
82         smokeModifier_free (smd);
83 }
84
85 static void deformVerts(ModifierData *md, Object *ob,
86                                                 DerivedMesh *derivedData,
87                                                 float (*vertexCos)[3],
88                                                 int UNUSED(numVerts),
89                                                 int UNUSED(useRenderParams),
90                                                 int UNUSED(isFinalCalc))
91 {
92         SmokeModifierData *smd = (SmokeModifierData*) md;
93         DerivedMesh *dm = get_cddm(ob, NULL, derivedData, vertexCos);
94
95         smokeModifier_do(smd, md->scene, ob, dm);
96
97         if(dm != derivedData)
98                 dm->release(dm);
99 }
100
101 static int dependsOnTime(ModifierData *UNUSED(md))
102 {
103         return 1;
104 }
105
106 static void updateDepgraph(ModifierData *md, DagForest *forest,
107                                                 struct Scene *scene,
108                                                 Object *UNUSED(ob),
109                                                 DagNode *obNode)
110 {
111         SmokeModifierData *smd = (SmokeModifierData *) md;
112
113         if(smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
114         {
115                 if(smd->domain->fluid_group)
116                 {
117                         GroupObject *go = NULL;
118                         
119                         for(go = smd->domain->fluid_group->gobject.first; go; go = go->next) 
120                         {
121                                 if(go->ob)
122                                 {
123                                         SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(go->ob, eModifierType_Smoke);
124                                         
125                                         // check for initialized smoke object
126                                         if(smd2 && (((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) || ((smd->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)))
127                                         {
128                                                 DagNode *curNode = dag_get_node(forest, go->ob);
129                                                 dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Smoke Flow");
130                                         }
131                                 }
132                         }
133                 }
134                 else {
135                         Base *base = scene->base.first;
136
137                         for(; base; base = base->next) {
138                                 SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(base->object, eModifierType_Smoke);
139
140                                 if(smd2 && (((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) || ((smd->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)))
141                                 {
142                                         DagNode *curNode = dag_get_node(forest, base->object);
143                                         dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Smoke Flow");
144                                 }
145                         }
146                 }
147         }
148 }
149
150
151 ModifierTypeInfo modifierType_Smoke = {
152         /* name */              "Smoke",
153         /* structName */        "SmokeModifierData",
154         /* structSize */        sizeof(SmokeModifierData),
155         /* type */              eModifierTypeType_OnlyDeform,
156         /* flags */             eModifierTypeFlag_AcceptsMesh
157                                                         | eModifierTypeFlag_UsesPointCache
158                                                         | eModifierTypeFlag_Single,
159
160         /* copyData */          copyData,
161         /* deformVerts */       deformVerts,
162         /* deformMatrices */    NULL,
163         /* deformVertsEM */     NULL,
164         /* deformMatricesEM */  NULL,
165         /* applyModifier */     NULL,
166         /* applyModifierEM */   NULL,
167         /* initData */          initData,
168         /* requiredDataMask */  NULL,
169         /* freeData */          freeData,
170         /* isDisabled */        NULL,
171         /* updateDepgraph */    updateDepgraph,
172         /* dependsOnTime */     dependsOnTime,
173         /* dependsOnNormals */  NULL,
174         /* foreachObjectLink */ NULL,
175         /* foreachIDLink */     NULL,
176 };