Blender V2.61 - r43446

MOD_smoke.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software  Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * Contributor(s): Daniel Dunbar
00022  *                 Ton Roosendaal,
00023  *                 Ben Batt,
00024  *                 Brecht Van Lommel,
00025  *                 Campbell Barton
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  *
00029  */
00030 
00036 #include <stddef.h>
00037 
00038 #include "MEM_guardedalloc.h"
00039 
00040 #include "DNA_group_types.h"
00041 #include "DNA_object_types.h"
00042 #include "DNA_scene_types.h"
00043 #include "DNA_smoke_types.h"
00044 #include "DNA_object_force.h"
00045 
00046 #include "BLI_utildefines.h"
00047 
00048 
00049 #include "BKE_cdderivedmesh.h"
00050 #include "BKE_modifier.h"
00051 #include "BKE_smoke.h"
00052 
00053 #include "depsgraph_private.h"
00054 
00055 #include "MOD_util.h"
00056 
00057 
00058 static void initData(ModifierData *md) 
00059 {
00060     SmokeModifierData *smd = (SmokeModifierData*) md;
00061     
00062     smd->domain = NULL;
00063     smd->flow = NULL;
00064     smd->coll = NULL;
00065     smd->type = 0;
00066     smd->time = -1;
00067 }
00068 
00069 static void copyData(ModifierData *md, ModifierData *target)
00070 {
00071     SmokeModifierData *smd  = (SmokeModifierData*)md;
00072     SmokeModifierData *tsmd = (SmokeModifierData*)target;
00073     
00074     smokeModifier_copy(smd, tsmd);
00075 }
00076 
00077 static void freeData(ModifierData *md)
00078 {
00079     SmokeModifierData *smd = (SmokeModifierData*) md;
00080     
00081     smokeModifier_free (smd);
00082 }
00083 
00084 static void deformVerts(ModifierData *md, Object *ob,
00085                         DerivedMesh *derivedData,
00086                         float (*vertexCos)[3],
00087                         int UNUSED(numVerts),
00088                         int UNUSED(useRenderParams),
00089                         int UNUSED(isFinalCalc))
00090 {
00091     SmokeModifierData *smd = (SmokeModifierData*) md;
00092     DerivedMesh *dm = get_cddm(ob, NULL, derivedData, vertexCos);
00093 
00094     smokeModifier_do(smd, md->scene, ob, dm);
00095 
00096     if(dm != derivedData)
00097         dm->release(dm);
00098 }
00099 
00100 static int dependsOnTime(ModifierData *UNUSED(md))
00101 {
00102     return 1;
00103 }
00104 
00105 static void updateDepgraph(ModifierData *md, DagForest *forest,
00106                         struct Scene *scene,
00107                         Object *UNUSED(ob),
00108                         DagNode *obNode)
00109 {
00110     SmokeModifierData *smd = (SmokeModifierData *) md;
00111 
00112     if(smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
00113     {
00114         if(smd->domain->fluid_group)
00115         {
00116             GroupObject *go = NULL;
00117             
00118             for(go = smd->domain->fluid_group->gobject.first; go; go = go->next) 
00119             {
00120                 if(go->ob)
00121                 {
00122                     SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(go->ob, eModifierType_Smoke);
00123                     
00124                     // check for initialized smoke object
00125                     if(smd2 && (((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) || ((smd->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)))
00126                     {
00127                         DagNode *curNode = dag_get_node(forest, go->ob);
00128                         dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Smoke Flow");
00129                     }
00130                 }
00131             }
00132         }
00133         else {
00134             Base *base = scene->base.first;
00135 
00136             for(; base; base = base->next) {
00137                 SmokeModifierData *smd2 = (SmokeModifierData *)modifiers_findByType(base->object, eModifierType_Smoke);
00138 
00139                 if(smd2 && (((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) || ((smd->type & MOD_SMOKE_TYPE_COLL) && smd2->coll)))
00140                 {
00141                     DagNode *curNode = dag_get_node(forest, base->object);
00142                     dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Smoke Flow");
00143                 }
00144             }
00145         }
00146     }
00147 }
00148 
00149 static void foreachIDLink(ModifierData *md, Object *ob,
00150                        IDWalkFunc walk, void *userData)
00151 {
00152     SmokeModifierData *smd = (SmokeModifierData*) md;
00153 
00154     if(smd->type==MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
00155         walk(userData, ob, (ID **)&smd->domain->coll_group);
00156         walk(userData, ob, (ID **)&smd->domain->fluid_group);
00157         walk(userData, ob, (ID **)&smd->domain->eff_group);
00158 
00159         if(smd->domain->effector_weights) {
00160             walk(userData, ob, (ID **)&smd->domain->effector_weights->group);
00161         }
00162     }
00163 }
00164 
00165 ModifierTypeInfo modifierType_Smoke = {
00166     /* name */              "Smoke",
00167     /* structName */        "SmokeModifierData",
00168     /* structSize */        sizeof(SmokeModifierData),
00169     /* type */              eModifierTypeType_OnlyDeform,
00170     /* flags */             eModifierTypeFlag_AcceptsMesh
00171                             | eModifierTypeFlag_UsesPointCache
00172                             | eModifierTypeFlag_Single,
00173 
00174     /* copyData */          copyData,
00175     /* deformVerts */       deformVerts,
00176     /* deformMatrices */    NULL,
00177     /* deformVertsEM */     NULL,
00178     /* deformMatricesEM */  NULL,
00179     /* applyModifier */     NULL,
00180     /* applyModifierEM */   NULL,
00181     /* initData */          initData,
00182     /* requiredDataMask */  NULL,
00183     /* freeData */          freeData,
00184     /* isDisabled */        NULL,
00185     /* updateDepgraph */    updateDepgraph,
00186     /* dependsOnTime */     dependsOnTime,
00187     /* dependsOnNormals */  NULL,
00188     /* foreachObjectLink */ NULL,
00189     /* foreachIDLink */     foreachIDLink,
00190     /* foreachTexLink */    NULL
00191 };