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