ensure pasted graph keys are always selected.
[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 #include "stddef.h"
34
35 #include "MEM_guardedalloc.h"
36
37 #include "DNA_group_types.h"
38 #include "DNA_object_types.h"
39 #include "DNA_scene_types.h"
40 #include "DNA_smoke_types.h"
41
42 #include "BKE_utildefines.h"
43 #include "BKE_cdderivedmesh.h"
44 #include "BKE_modifier.h"
45 #include "BKE_smoke.h"
46
47 #include "depsgraph_private.h"
48
49 #include "MOD_util.h"
50
51
52 static void initData(ModifierData *md) 
53 {
54         SmokeModifierData *smd = (SmokeModifierData*) md;
55         
56         smd->domain = NULL;
57         smd->flow = NULL;
58         smd->coll = NULL;
59         smd->type = 0;
60         smd->time = -1;
61 }
62
63 static void copyData(ModifierData *md, ModifierData *target)
64 {
65         SmokeModifierData *smd  = (SmokeModifierData*)md;
66         SmokeModifierData *tsmd = (SmokeModifierData*)target;
67         
68         smokeModifier_copy(smd, tsmd);
69 }
70
71 static void freeData(ModifierData *md)
72 {
73         SmokeModifierData *smd = (SmokeModifierData*) md;
74         
75         smokeModifier_free (smd);
76 }
77
78 static void deformVerts(ModifierData *md, Object *ob,
79                                                 DerivedMesh *derivedData,
80                                                 float (*vertexCos)[3],
81                                                 int UNUSED(numVerts),
82                                                 int UNUSED(useRenderParams),
83                                                 int UNUSED(isFinalCalc))
84 {
85         SmokeModifierData *smd = (SmokeModifierData*) md;
86         DerivedMesh *dm = dm= get_cddm(ob, NULL, derivedData, vertexCos);
87
88         smokeModifier_do(smd, md->scene, ob, dm);
89
90         if(dm != derivedData)
91                 dm->release(dm);
92 }
93
94 static int dependsOnTime(ModifierData *UNUSED(md))
95 {
96         return 1;
97 }
98
99 static void updateDepgraph(ModifierData *md, DagForest *forest,
100                                                 struct Scene *scene,
101                                                 Object *UNUSED(ob),
102                                                 DagNode *obNode)
103 {
104         SmokeModifierData *smd = (SmokeModifierData *) md;
105
106         if(smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
107         {
108                 if(smd->domain->fluid_group)
109                 {
110                         GroupObject *go = NULL;
111                         
112                         for(go = smd->domain->fluid_group->gobject.first; go; go = go->next) 
113                         {
114                                 if(go->ob)
115                                 {
116                                         SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(go->ob, eModifierType_Smoke);
117                                         
118                                         // check for initialized smoke object
119                                         if(smd2 && (((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) || ((smd->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)))
120                                         {
121                                                 DagNode *curNode = dag_get_node(forest, go->ob);
122                                                 dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Smoke Flow");
123                                         }
124                                 }
125                         }
126                 }
127                 else {
128                         Base *base = scene->base.first;
129
130                         for(; base; base = base->next) {
131                                 SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(base->object, eModifierType_Smoke);
132
133                                 if(smd2 && (((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) || ((smd->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)))
134                                 {
135                                         DagNode *curNode = dag_get_node(forest, base->object);
136                                         dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Smoke Flow");
137                                 }
138                         }
139                 }
140         }
141 }
142
143
144 ModifierTypeInfo modifierType_Smoke = {
145         /* name */              "Smoke",
146         /* structName */        "SmokeModifierData",
147         /* structSize */        sizeof(SmokeModifierData),
148         /* type */              eModifierTypeType_OnlyDeform,
149         /* flags */             eModifierTypeFlag_AcceptsMesh
150                                                         | eModifierTypeFlag_UsesPointCache
151                                                         | eModifierTypeFlag_Single,
152
153         /* copyData */          copyData,
154         /* deformVerts */       deformVerts,
155         /* deformVertsEM */     0,
156         /* deformMatricesEM */  0,
157         /* applyModifier */     0,
158         /* applyModifierEM */   0,
159         /* initData */          initData,
160         /* requiredDataMask */  0,
161         /* freeData */          freeData,
162         /* isDisabled */        0,
163         /* updateDepgraph */    updateDepgraph,
164         /* dependsOnTime */     dependsOnTime,
165         /* dependsOnNormals */  0,
166         /* foreachObjectLink */ 0,
167         /* foreachIDLink */     0,
168 };