svn merge -r 16454:16593 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / blenkernel / intern / modifier.c
index f71ebc76e68ba8edd587e162f2d2d4a4e37d834b..56b4aa574c78fe103f3f02cf6422762f71a8065d 100644 (file)
@@ -55,7 +55,9 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_armature_types.h"
 #include "MEM_guardedalloc.h"
 
 #include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_cloth_types.h"
 #include "DNA_cloth_types.h"
+#include "DNA_curve_types.h"
 #include "DNA_effect_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_effect_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
@@ -66,8 +68,6 @@
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_texture_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_camera_types.h"
 
 #include "BLI_editVert.h"
 
 
 #include "BLI_editVert.h"
 
 #include "BKE_main.h"
 #include "BKE_anim.h"
 #include "BKE_bad_level_calls.h"
 #include "BKE_main.h"
 #include "BKE_anim.h"
 #include "BKE_bad_level_calls.h"
+#include "BKE_bmesh.h"
+#include "BKE_booleanops.h"
 #include "BKE_cloth.h"
 #include "BKE_collision.h"
 #include "BKE_cloth.h"
 #include "BKE_collision.h"
+#include "BKE_cdderivedmesh.h"
 #include "BKE_curve.h"
 #include "BKE_customdata.h"
 #include "BKE_curve.h"
 #include "BKE_customdata.h"
-#include "BKE_global.h"
-#include "BKE_cdderivedmesh.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_DerivedMesh.h"
-#include "BKE_booleanops.h"
 #include "BKE_displist.h"
 #include "BKE_displist.h"
-#include "BKE_modifier.h"
+#include "BKE_fluidsim.h"
+#include "BKE_global.h"
 #include "BKE_lattice.h"
 #include "BKE_library.h"
 #include "BKE_lattice.h"
 #include "BKE_library.h"
-#include "BKE_subsurf.h"
-#include "BKE_object.h"
-#include "BKE_mesh.h"
-#include "BKE_softbody.h"
-#include "BKE_cloth.h"
 #include "BKE_material.h"
 #include "BKE_material.h"
+#include "BKE_mesh.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
+#include "BKE_softbody.h"
+#include "BKE_subsurf.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
+
 #include "depsgraph_private.h"
 #include "depsgraph_private.h"
-#include "BKE_bmesh.h"
 #include "BKE_deform.h"
 #include "BKE_shrinkwrap.h"
 
 #include "BKE_deform.h"
 #include "BKE_shrinkwrap.h"
 
@@ -6921,6 +6922,93 @@ static DerivedMesh * explodeModifier_applyModifier(
        }
        return derivedData;
 }
        }
        return derivedData;
 }
+
+/* Fluidsim */
+static void fluidsimModifier_initData(ModifierData *md)
+{
+       FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
+       
+       fluidsim_init(fluidmd);
+}
+static void fluidsimModifier_freeData(ModifierData *md)
+{
+       FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
+       
+       fluidsim_free(fluidmd);
+}
+
+static void fluidsimModifier_copyData(ModifierData *md, ModifierData *target)
+{
+       FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
+       FluidsimModifierData *tfluidmd= (FluidsimModifierData*) target;
+       
+       if(tfluidmd->fss)
+               MEM_freeN(tfluidmd->fss);
+       
+       tfluidmd->fss = MEM_dupallocN(fluidmd->fss);
+}
+
+static DerivedMesh * fluidsimModifier_applyModifier(
+               ModifierData *md, Object *ob, DerivedMesh *derivedData,
+  int useRenderParams, int isFinalCalc)
+{
+       FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
+       DerivedMesh *result = NULL;
+       
+       /* check for alloc failing */
+       if(!fluidmd->fss)
+       {
+               fluidsimModifier_initData(md);
+               
+               if(!fluidmd->fss)
+                       return derivedData;
+       }
+
+       result = fluidsimModifier_do(fluidmd, ob, derivedData, useRenderParams, isFinalCalc);
+
+       if(result) 
+       { 
+               return result; 
+       }
+       
+       return derivedData;
+}
+
+static void fluidsimModifier_updateDepgraph(
+               ModifierData *md, DagForest *forest,
+      Object *ob, DagNode *obNode)
+{
+       FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
+       Base *base;
+
+       if(fluidmd && fluidmd->fss)
+       {
+               if(fluidmd->fss->type == OB_FLUIDSIM_DOMAIN)
+               {
+                       for(base = G.scene->base.first; base; base= base->next) 
+                       {
+                               Object *ob1= base->object;
+                               if(ob1 != ob)
+                               {
+                                       FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(ob1, eModifierType_Fluidsim);
+                                       
+                                       // only put dependancies from NON-DOMAIN fluids in here
+                                       if(fluidmdtmp && fluidmdtmp->fss && (fluidmdtmp->fss->type!=OB_FLUIDSIM_DOMAIN))
+                                       {
+                                               DagNode *curNode = dag_get_node(forest, ob1);
+                                               dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Fluidsim Object");
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+static int fluidsimModifier_dependsOnTime(ModifierData *md) 
+{
+       return 1;
+}
+
 /* MeshDeform */
 
 static void meshdeformModifier_initData(ModifierData *md)
 /* MeshDeform */
 
 static void meshdeformModifier_initData(ModifierData *md)
@@ -7674,6 +7762,17 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
                mti->dependsOnTime = explodeModifier_dependsOnTime;
                mti->requiredDataMask = explodeModifier_requiredDataMask;
                mti->applyModifier = explodeModifier_applyModifier;
                mti->dependsOnTime = explodeModifier_dependsOnTime;
                mti->requiredDataMask = explodeModifier_requiredDataMask;
                mti->applyModifier = explodeModifier_applyModifier;
+               
+               mti = INIT_TYPE(Fluidsim);
+               mti->type = eModifierTypeType_Nonconstructive
+                               | eModifierTypeFlag_RequiresOriginalData;
+               mti->flags = eModifierTypeFlag_AcceptsMesh;
+               mti->initData = fluidsimModifier_initData;
+               mti->freeData = fluidsimModifier_freeData;
+               mti->copyData = fluidsimModifier_copyData;
+               mti->dependsOnTime = fluidsimModifier_dependsOnTime;
+               mti->applyModifier = fluidsimModifier_applyModifier;
+               mti->updateDepgraph = fluidsimModifier_updateDepgraph;
 
                mti = INIT_TYPE(Shrinkwrap);
                mti->type = eModifierTypeType_OnlyDeform;
 
                mti = INIT_TYPE(Shrinkwrap);
                mti->type = eModifierTypeType_OnlyDeform;