code cleanup: function naming, use BKE_*type* prefix.
[blender.git] / source / blender / editors / physics / physics_fluid.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) Blender Foundation
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/physics/physics_fluid.c
29  *  \ingroup edphys
30  */
31
32 #include <math.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <sys/stat.h>
36
37 #include "MEM_guardedalloc.h"
38
39 /* types */
40 #include "DNA_anim_types.h"
41 #include "DNA_action_types.h"
42 #include "DNA_object_types.h"
43 #include "DNA_object_fluidsim.h"        
44
45 #include "BLI_blenlib.h"
46 #include "BLI_threads.h"
47 #include "BLI_math.h"
48 #include "BLI_utildefines.h"
49
50 #include "BKE_animsys.h"
51 #include "BKE_armature.h"
52 #include "BKE_blender.h"
53 #include "BKE_context.h"
54 #include "BKE_customdata.h"
55 #include "BKE_DerivedMesh.h"
56 #include "BKE_displist.h"
57 #include "BKE_effect.h"
58 #include "BKE_fluidsim.h"
59 #include "BKE_global.h"
60 #include "BKE_ipo.h"
61 #include "BKE_key.h"
62 #include "BKE_main.h"
63 #include "BKE_modifier.h"
64 #include "BKE_object.h"
65 #include "BKE_report.h"
66 #include "BKE_scene.h"
67 #include "BKE_softbody.h"
68 #include "BKE_unit.h"
69
70
71 #include "LBM_fluidsim.h"
72
73 #include "ED_screen.h"
74 #include "ED_fluidsim.h"
75
76 #include "WM_types.h"
77 #include "WM_api.h"
78
79 #include "physics_intern.h" // own include
80
81 /* enable/disable overall compilation */
82 #ifdef WITH_MOD_FLUID
83
84 #include "WM_api.h"
85
86 #include "DNA_scene_types.h"
87 #include "DNA_ipo_types.h"
88 #include "DNA_mesh_types.h"
89
90 #include "PIL_time.h"
91
92
93 static float get_fluid_viscosity(FluidsimSettings *settings)
94 {
95         return (1.0f/powf(10.0f, settings->viscosityExponent)) * settings->viscosityValue;
96 }
97
98 static float get_fluid_rate(FluidsimSettings *settings)
99 {
100         float rate = 1.0f; /* default rate if not animated... */
101         
102         rate = settings->animRate;
103         
104         if (rate < 0.0f)
105                 rate = 0.0f;
106         
107         return rate;
108 }
109
110 static void get_fluid_gravity(float *gravity, Scene *scene, FluidsimSettings *fss)
111 {
112         if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
113                 copy_v3_v3(gravity, scene->physics_settings.gravity);
114         }
115         else {
116                 copy_v3_v3(gravity, fss->grav);
117         }
118 }
119
120 static float get_fluid_size_m(Scene *scene, Object *domainob, FluidsimSettings *fss)
121 {
122         if (!scene->unit.system) {
123                 return fss->realsize;
124         }
125         else {
126                 float dim[3];
127                 float longest_axis;
128                 
129                 BKE_object_dimensions_get(domainob, dim);
130                 longest_axis = MAX3(dim[0], dim[1], dim[2]);
131                 
132                 return longest_axis * scene->unit.scale_length;
133         }
134 }
135
136 static int fluid_is_animated_mesh(FluidsimSettings *fss)
137 {
138         return ((fss->type == OB_FLUIDSIM_CONTROL) || fss->domainNovecgen);
139 }
140
141 /* ********************** fluid sim settings struct functions ********************** */
142
143 #if 0
144 /* helper function */
145 void fluidsimGetGeometryObjFilename(Object *ob, char *dst) { //, char *srcname)
146 {
147         //BLI_snprintf(dst, FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name);
148         BLI_snprintf(dst, FILE_MAXFILE, "fluidcfgdata_%s.bobj.gz", ob->id.name);
149 }
150 #endif
151
152
153 /* ********************** fluid sim channel helper functions ********************** */
154
155 typedef struct FluidAnimChannels {
156         int length;
157         
158         double aniFrameTime;
159         
160         float *timeAtFrame;
161         float *DomainTime;
162         float *DomainGravity;
163         float *DomainViscosity;
164 } FluidAnimChannels;
165
166 typedef struct FluidObject {
167         struct FluidObject *next, *prev;
168         
169         struct Object *object;
170         
171         float *Translation;
172         float *Rotation;
173         float *Scale;
174         float *Active;
175         
176         float *InitialVelocity;
177         
178         float *AttractforceStrength;
179         float *AttractforceRadius;
180         float *VelocityforceStrength;
181         float *VelocityforceRadius;
182         
183         float *VertexCache;
184         int numVerts, numTris;
185 } FluidObject;
186
187 // no. of entries for the two channel sizes
188 #define CHANNEL_FLOAT 1
189 #define CHANNEL_VEC   3
190
191 // simplify channels before printing
192 // for API this is done anyway upon init
193 #if 0
194 static void fluidsimPrintChannel(FILE *file, float *channel, int paramsize, char *str, int entries) 
195
196         int i, j;
197         int channelSize = paramsize; 
198
199         if (entries==3) {
200                 elbeemSimplifyChannelVec3(channel, &channelSize);
201         }
202         else if (entries==1) {
203                 elbeemSimplifyChannelFloat(channel, &channelSize);
204         }
205         else {
206                 // invalid, cant happen?
207         }
208
209         fprintf(file, "      CHANNEL %s =\n", str);
210         for (i=0; i < channelSize; i++) {
211                 fprintf(file, "        ");
212                 for (j=0;j <= entries;j++) {  // also print time value
213                         fprintf(file, " %f ", channel[i*(entries + 1) + j]);
214                         if (j==entries-1) { fprintf(file, "  "); }
215                 } 
216                 fprintf(file, "\n");
217         } 
218
219         fprintf(file,  "      ;\n");
220 }
221 #endif
222
223
224 /* Note: fluid anim channel data layout
225  * ------------------------------------
226  * CHANNEL_FLOAT:
227  * frame 1     |frame 2
228  * [dataF][time][dataF][time]
229  *
230  * CHANNEL_VEC:
231  * frame 1                   |frame 2
232  * [dataX][dataY][dataZ][time][dataX][dataY][dataZ][time]
233  *
234  */
235
236 static void init_time(FluidsimSettings *domainSettings, FluidAnimChannels *channels)
237 {
238         int i;
239         
240         channels->timeAtFrame = MEM_callocN((channels->length+1)*sizeof(float), "timeAtFrame channel");
241         
242         channels->timeAtFrame[0] = channels->timeAtFrame[1] = domainSettings->animStart; // start at index 1
243         
244         for (i=2; i <= channels->length; i++) {
245                 channels->timeAtFrame[i] = channels->timeAtFrame[i-1] + channels->aniFrameTime;
246         }
247 }
248
249 /* if this is slow, can replace with faster, less readable code */
250 static void set_channel(float *channel, float time, float *value, int i, int size)
251 {
252         if (size == CHANNEL_FLOAT) {
253                 channel[(i * 2) + 0] = value[0];
254                 channel[(i * 2) + 1] = time;
255         }
256         else if (size == CHANNEL_VEC) {
257                 channel[(i * 4) + 0] = value[0];
258                 channel[(i * 4) + 1] = value[1];
259                 channel[(i * 4) + 2] = value[2];
260                 channel[(i * 4) + 3] = time;
261         }
262 }
263
264 static void set_vertex_channel(float *channel, float time, struct Scene *scene, struct FluidObject *fobj, int i)
265 {
266         Object *ob = fobj->object;
267         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
268         float *verts;
269         int *tris=NULL, numVerts=0, numTris=0;
270         int modifierIndex = modifiers_indexInObject(ob, (ModifierData *)fluidmd);
271         int framesize = (3*fobj->numVerts) + 1;
272         int j;
273         
274         if (channel == NULL)
275                 return;
276         
277         initElbeemMesh(scene, ob, &numVerts, &verts, &numTris, &tris, 1, modifierIndex);
278         
279         /* don't allow mesh to change number of verts in anim sequence */
280         if (numVerts != fobj->numVerts) {
281                 MEM_freeN(channel);
282                 channel = NULL;
283                 return;
284         }
285         
286         /* fill frame of channel with vertex locations */
287         for (j=0; j < (3*numVerts); j++) {
288                 channel[i*framesize + j] = verts[j];
289         }
290         channel[i*framesize + framesize-1] = time;
291         
292         MEM_freeN(verts);
293         MEM_freeN(tris);
294 }
295
296 static void free_domain_channels(FluidAnimChannels *channels)
297 {
298         if (!channels->timeAtFrame)
299                 return;
300         MEM_freeN(channels->timeAtFrame);
301         channels->timeAtFrame = NULL;
302         MEM_freeN(channels->DomainGravity);
303         channels->DomainGravity = NULL;
304         MEM_freeN(channels->DomainViscosity);
305         channels->DomainViscosity = NULL;
306         MEM_freeN(channels->DomainTime);
307         channels->DomainTime = NULL;
308 }
309
310 static void free_all_fluidobject_channels(ListBase *fobjects)
311 {
312         FluidObject *fobj;
313         
314         for (fobj=fobjects->first; fobj; fobj=fobj->next) {
315                 if (fobj->Translation) {
316                         MEM_freeN(fobj->Translation);
317                         fobj->Translation = NULL;
318                         MEM_freeN(fobj->Rotation);
319                         fobj->Rotation = NULL;
320                         MEM_freeN(fobj->Scale);
321                         fobj->Scale = NULL;
322                         MEM_freeN(fobj->Active);
323                         fobj->Active = NULL;
324                         MEM_freeN(fobj->InitialVelocity);
325                         fobj->InitialVelocity = NULL;
326                 }
327                 
328                 if (fobj->AttractforceStrength) {
329                         MEM_freeN(fobj->AttractforceStrength);
330                         fobj->AttractforceStrength = NULL;
331                         MEM_freeN(fobj->AttractforceRadius);
332                         fobj->AttractforceRadius = NULL;
333                         MEM_freeN(fobj->VelocityforceStrength);
334                         fobj->VelocityforceStrength = NULL;
335                         MEM_freeN(fobj->VelocityforceRadius);
336                         fobj->VelocityforceRadius = NULL;
337                 }
338                 
339                 if (fobj->VertexCache) {
340                         MEM_freeN(fobj->VertexCache);
341                         fobj->VertexCache = NULL;
342                 }
343         }
344 }
345
346 static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), FluidsimSettings *domainSettings, FluidAnimChannels *channels, ListBase *fobjects)
347 {
348         Scene *scene = CTX_data_scene(C);
349         Base *base;
350         int i;
351         int length = channels->length;
352         float eval_time;
353         
354         /* init time values (assuming that time moves at a constant speed; may be overridden later) */
355         init_time(domainSettings, channels);
356         
357         /* allocate domain animation channels */
358         channels->DomainGravity = MEM_callocN(length * (CHANNEL_VEC+1) * sizeof(float), "channel DomainGravity");
359         channels->DomainViscosity = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "channel DomainViscosity");
360         channels->DomainTime = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "channel DomainTime");
361         
362         /* allocate fluid objects */
363         for (base=scene->base.first; base; base= base->next) {
364                 Object *ob = base->object;
365                 FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
366                 
367                 if (fluidmd) {
368                         FluidObject *fobj = MEM_callocN(sizeof(FluidObject), "Fluid Object");
369                         fobj->object = ob;
370                         
371                         if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) {
372                                 BLI_addtail(fobjects, fobj);
373                                 continue;
374                         }
375                         
376                         fobj->Translation = MEM_callocN(length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject Translation");
377                         fobj->Rotation = MEM_callocN(length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject Rotation");
378                         fobj->Scale = MEM_callocN(length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject Scale");
379                         fobj->Active = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject Active");
380                         fobj->InitialVelocity = MEM_callocN(length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject InitialVelocity");
381                         
382                         if (fluidmd->fss->type == OB_FLUIDSIM_CONTROL) {
383                                 fobj->AttractforceStrength = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject AttractforceStrength");
384                                 fobj->AttractforceRadius = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject AttractforceRadius");
385                                 fobj->VelocityforceStrength = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject VelocityforceStrength");
386                                 fobj->VelocityforceRadius = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject VelocityforceRadius");
387                         }
388                         
389                         if (fluid_is_animated_mesh(fluidmd->fss)) {
390                                 float *verts=NULL;
391                                 int *tris=NULL, modifierIndex = modifiers_indexInObject(ob, (ModifierData *)fluidmd);
392
393                                 initElbeemMesh(scene, ob, &fobj->numVerts, &verts, &fobj->numTris, &tris, 0, modifierIndex);
394                                 fobj->VertexCache = MEM_callocN(length *((fobj->numVerts*CHANNEL_VEC)+1) * sizeof(float), "fluidobject VertexCache");
395                                 
396                                 MEM_freeN(verts);
397                                 MEM_freeN(tris);
398                         }
399                         
400                         BLI_addtail(fobjects, fobj);
401                 }
402         }
403         
404         /* now we loop over the frames and fill the allocated channels with data */
405         for (i=0; i<channels->length; i++) {
406                 FluidObject *fobj;
407                 float viscosity, gravity[3];
408                 float timeAtFrame, time;
409                 
410                 eval_time = domainSettings->bakeStart + i;
411                 
412                 /* XXX: This can't be used due to an anim sys optimization that ignores recalc object animation,
413                  * leaving it for the depgraph (this ignores object animation such as modifier properties though... :/ )
414                  * --> BKE_animsys_evaluate_all_animation(G.main, eval_time);
415                  * This doesn't work with drivers:
416                  * --> BKE_animsys_evaluate_animdata(&fsDomain->id, fsDomain->adt, eval_time, ADT_RECALC_ALL);
417                  */
418                 
419                 /* Modifying the global scene isn't nice, but we can do it in 
420                  * this part of the process before a threaded job is created */
421                 scene->r.cfra = (int)eval_time;
422                 ED_update_for_newframe(CTX_data_main(C), scene, CTX_wm_screen(C), 1);
423                 
424                 /* now scene data should be current according to animation system, so we fill the channels */
425                 
426                 /* Domain time */
427                 // TODO: have option for not running sim, time mangling, in which case second case comes in handy
428                 if (channels->DomainTime) {
429                         time = get_fluid_rate(domainSettings) * channels->aniFrameTime;
430                         timeAtFrame = channels->timeAtFrame[i] + time;
431                         
432                         channels->timeAtFrame[i+1] = timeAtFrame;
433                         set_channel(channels->DomainTime, i, &time, i, CHANNEL_FLOAT);
434                 }
435                 else {
436                         timeAtFrame = channels->timeAtFrame[i+1];
437                 }
438                 
439                 /* Domain properties - gravity/viscosity */
440                 get_fluid_gravity(gravity, scene, domainSettings);
441                 set_channel(channels->DomainGravity, timeAtFrame, gravity, i, CHANNEL_VEC);
442                 viscosity = get_fluid_viscosity(domainSettings);
443                 set_channel(channels->DomainViscosity, timeAtFrame, &viscosity, i, CHANNEL_FLOAT);
444                 
445                 /* object movement */
446                 for (fobj=fobjects->first; fobj; fobj=fobj->next) {
447                         Object *ob = fobj->object;
448                         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
449                         float active= (float)(fluidmd->fss->flag & OB_FLUIDSIM_ACTIVE);
450                         float rot_d[3] = {0.f, 0.f, 0.f}, old_rot[3] = {0.f, 0.f, 0.f};
451                         
452                         if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE))
453                                 continue;
454                         
455                         /* init euler rotation values and convert to elbeem format */
456                         /* get the rotation from ob->obmat rather than ob->rot to account for parent animations */
457                         if (i) {
458                                 copy_v3_v3(old_rot, fobj->Rotation + 4*(i-1));
459                                 mul_v3_fl(old_rot, -M_PI/180.f);
460                         }
461
462                         mat4_to_compatible_eulO(rot_d, old_rot, 0, ob->obmat);
463                         mul_v3_fl(rot_d, -180.f/M_PI);
464                         
465                         set_channel(fobj->Translation, timeAtFrame, ob->loc, i, CHANNEL_VEC);
466                         set_channel(fobj->Rotation, timeAtFrame, rot_d, i, CHANNEL_VEC);
467                         set_channel(fobj->Scale, timeAtFrame, ob->size, i, CHANNEL_VEC);
468                         set_channel(fobj->Active, timeAtFrame, &active, i, CHANNEL_FLOAT);
469                         set_channel(fobj->InitialVelocity, timeAtFrame, &fluidmd->fss->iniVelx, i, CHANNEL_VEC);
470                         
471                         if (fluidmd->fss->type == OB_FLUIDSIM_CONTROL) {
472                                 set_channel(fobj->AttractforceStrength, timeAtFrame, &fluidmd->fss->attractforceStrength, i, CHANNEL_FLOAT);
473                                 set_channel(fobj->AttractforceRadius, timeAtFrame, &fluidmd->fss->attractforceRadius, i, CHANNEL_FLOAT);
474                                 set_channel(fobj->VelocityforceStrength, timeAtFrame, &fluidmd->fss->velocityforceStrength, i, CHANNEL_FLOAT);
475                                 set_channel(fobj->VelocityforceRadius, timeAtFrame, &fluidmd->fss->velocityforceRadius, i, CHANNEL_FLOAT);
476                         }
477                         
478                         if (fluid_is_animated_mesh(fluidmd->fss)) {
479                                 set_vertex_channel(fobj->VertexCache, timeAtFrame, scene, fobj, i);
480                         }
481                 }
482         }
483 }
484
485 static void export_fluid_objects(ListBase *fobjects, Scene *scene, int length)
486 {
487         FluidObject *fobj;
488         
489         for (fobj=fobjects->first; fobj; fobj=fobj->next) {
490                 Object *ob = fobj->object;
491                 FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
492                 int modifierIndex = modifiers_indexInObject(ob, (ModifierData *)fluidmd);
493                 
494                 float *verts=NULL;
495                 int *tris=NULL;
496                 int numVerts=0, numTris=0;
497                 int deform = fluid_is_animated_mesh(fluidmd->fss);
498                 
499                 elbeemMesh fsmesh;
500                 
501                 if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE))
502                         continue;
503                 
504                 elbeemResetMesh(&fsmesh);
505                 
506                 fsmesh.type = fluidmd->fss->type;
507                 fsmesh.name = ob->id.name;
508                 
509                 initElbeemMesh(scene, ob, &numVerts, &verts, &numTris, &tris, 0, modifierIndex);
510                 
511                 fsmesh.numVertices   = numVerts;
512                 fsmesh.numTriangles  = numTris;
513                 fsmesh.vertices      = verts;
514                 fsmesh.triangles     = tris;
515                 
516                 fsmesh.channelSizeTranslation  = 
517                 fsmesh.channelSizeRotation     = 
518                 fsmesh.channelSizeScale        = 
519                 fsmesh.channelSizeInitialVel   = 
520                 fsmesh.channelSizeActive       = length;
521                 
522                 fsmesh.channelTranslation      = fobj->Translation;
523                 fsmesh.channelRotation         = fobj->Rotation;
524                 fsmesh.channelScale            = fobj->Scale;
525                 fsmesh.channelActive           = fobj->Active;
526                 
527                 if ( ELEM(fsmesh.type, OB_FLUIDSIM_FLUID, OB_FLUIDSIM_INFLOW)) {
528                         fsmesh.channelInitialVel = fobj->InitialVelocity;
529                         fsmesh.localInivelCoords = ((fluidmd->fss->typeFlags & OB_FSINFLOW_LOCALCOORD)?1:0);
530                 } 
531                 
532                 if (fluidmd->fss->typeFlags & OB_FSBND_NOSLIP)
533                         fsmesh.obstacleType = FLUIDSIM_OBSTACLE_NOSLIP;
534                 else if (fluidmd->fss->typeFlags & OB_FSBND_PARTSLIP)
535                         fsmesh.obstacleType = FLUIDSIM_OBSTACLE_PARTSLIP;
536                 else if (fluidmd->fss->typeFlags & OB_FSBND_FREESLIP)
537                         fsmesh.obstacleType = FLUIDSIM_OBSTACLE_FREESLIP;
538                 
539                 fsmesh.obstaclePartslip = fluidmd->fss->partSlipValue;
540                 fsmesh.volumeInitType = fluidmd->fss->volumeInitType;
541                 fsmesh.obstacleImpactFactor = fluidmd->fss->surfaceSmoothing; // misused value
542                 
543                 if (fsmesh.type == OB_FLUIDSIM_CONTROL) {
544                         fsmesh.cpsTimeStart = fluidmd->fss->cpsTimeStart;
545                         fsmesh.cpsTimeEnd = fluidmd->fss->cpsTimeEnd;
546                         fsmesh.cpsQuality = fluidmd->fss->cpsQuality;
547                         fsmesh.obstacleType = (fluidmd->fss->flag & OB_FLUIDSIM_REVERSE);
548                         
549                         fsmesh.channelSizeAttractforceRadius = 
550                         fsmesh.channelSizeVelocityforceStrength = 
551                         fsmesh.channelSizeVelocityforceRadius = 
552                         fsmesh.channelSizeAttractforceStrength = length;
553                         
554                         fsmesh.channelAttractforceStrength = fobj->AttractforceStrength;
555                         fsmesh.channelAttractforceRadius = fobj->AttractforceRadius;
556                         fsmesh.channelVelocityforceStrength = fobj->VelocityforceStrength;
557                         fsmesh.channelVelocityforceRadius = fobj->VelocityforceRadius;
558                 }
559                 else {
560                         fsmesh.channelAttractforceStrength =
561                         fsmesh.channelAttractforceRadius = 
562                         fsmesh.channelVelocityforceStrength = 
563                         fsmesh.channelVelocityforceRadius = NULL; 
564                 }
565                 
566                 /* animated meshes */
567                 if (deform) {
568                         fsmesh.channelSizeVertices = length;
569                         fsmesh.channelVertices = fobj->VertexCache;
570                                 
571                         // remove channels
572                         fsmesh.channelTranslation      = 
573                         fsmesh.channelRotation         = 
574                         fsmesh.channelScale            = NULL; 
575                 }
576                 
577                 elbeemAddMesh(&fsmesh);
578                 
579                 if (verts) MEM_freeN(verts);
580                 if (tris) MEM_freeN(tris);
581         }
582 }
583
584 static int fluid_validate_scene(ReportList *reports, Scene *scene, Object *fsDomain)
585 {
586         Base *base;
587         Object *newdomain = NULL;
588         int channelObjCount = 0;
589         int fluidInputCount = 0;
590
591         for (base=scene->base.first; base; base= base->next) {
592                 Object *ob = base->object;
593                 FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);                    
594
595                 /* only find objects with fluid modifiers */
596                 if (!fluidmdtmp || ob->type != OB_MESH) continue;
597                         
598                 if (fluidmdtmp->fss->type == OB_FLUIDSIM_DOMAIN) {
599                         /* if no initial domain object given, find another potential domain */
600                         if (!fsDomain) {
601                                 newdomain = ob;
602                         }
603                         /* if there's more than one domain, cancel */
604                         else if (fsDomain && ob != fsDomain) {
605                                 BKE_report(reports, RPT_ERROR, "There should be only one domain object");
606                                 return 0;
607                         }
608                 }
609                 
610                 /* count number of objects needed for animation channels */
611                 if ( !ELEM(fluidmdtmp->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE) )
612                         channelObjCount++;
613                 
614                 /* count number of fluid input objects */
615                 if (ELEM(fluidmdtmp->fss->type, OB_FLUIDSIM_FLUID, OB_FLUIDSIM_INFLOW))
616                         fluidInputCount++;
617         }
618
619         if (newdomain)
620                 fsDomain = newdomain;
621         
622         if (!fsDomain) {
623                 BKE_report(reports, RPT_ERROR, "No domain object found");
624                 return 0;
625         }
626         
627         if (channelObjCount>=255) {
628                 BKE_report(reports, RPT_ERROR, "Cannot bake with more then 256 objects");
629                 return 0;
630         }
631         
632         if (fluidInputCount == 0) {
633                 BKE_report(reports, RPT_ERROR, "No fluid input objects in the scene");
634                 return 0;
635         }
636         
637         return 1;
638 }
639
640
641 #define FLUID_SUFFIX_CONFIG             "fluidsim.cfg"
642 #define FLUID_SUFFIX_CONFIG_TMP (FLUID_SUFFIX_CONFIG ".tmp")
643 #define FLUID_SUFFIX_SURFACE    "fluidsurface"
644
645 static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetFile, char *debugStrBuffer)
646 {
647         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsDomain, eModifierType_Fluidsim);
648         FluidsimSettings *domainSettings= fluidmd->fss; 
649         FILE *fileCfg;
650         int dirExist = 0;
651         char newSurfdataPath[FILE_MAX]; // modified output settings
652         const char *suffixConfigTmp = FLUID_SUFFIX_CONFIG_TMP;
653         int outStringsChanged = 0;
654
655         // prepare names...
656         const char *relbase= modifier_path_relbase(fsDomain);
657
658         BLI_strncpy(targetDir, domainSettings->surfdataPath, FILE_MAXDIR);
659         BLI_strncpy(newSurfdataPath, domainSettings->surfdataPath, FILE_MAXDIR); /* if 0'd out below, this value is never used! */
660         BLI_path_abs(targetDir, relbase); // fixed #frame-no
661
662         /* .tmp: don't overwrite/delete original file */
663         BLI_join_dirfile(targetFile, FILE_MAX, targetDir, suffixConfigTmp);
664
665         // make sure all directories exist
666         // as the bobjs use the same dir, this only needs to be checked
667         // for the cfg output
668         BLI_make_existing_file(targetFile);
669         
670         // check selected directory
671         // simply try to open cfg file for writing to test validity of settings
672         fileCfg = BLI_fopen(targetFile, "w");
673         if (fileCfg) { 
674                 dirExist = 1; fclose(fileCfg); 
675                 // remove cfg dummy from  directory test
676                 BLI_delete(targetFile, 0, 0);
677         }
678         
679         if (targetDir[0] == '\0' || (!dirExist)) {
680                 char blendDir[FILE_MAX];
681                 char blendFile[FILE_MAX];
682                 
683                 // invalid dir, reset to current/previous
684                 BLI_strncpy(blendDir, G.main->name, FILE_MAX);
685                 BLI_splitdirstring(blendDir, blendFile);
686                 BLI_replace_extension(blendFile, FILE_MAX, ""); /* strip .blend */
687
688                 BLI_snprintf(newSurfdataPath, FILE_MAX, "//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name);
689                 
690                 BLI_snprintf(debugStrBuffer, 256, "fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath);
691                 elbeemDebugOut(debugStrBuffer);
692                 outStringsChanged=1;
693         }
694         
695         // check if modified output dir is ok
696 #if 0
697         if (outStringsChanged) {
698                 char dispmsg[FILE_MAX+256];
699                 int  selection=0;
700                 BLI_strncpy(dispmsg, "Output settings set to: '", sizeof(dispmsg));
701                 strcat(dispmsg, newSurfdataPath);
702                 strcat(dispmsg, "'%t|Continue with changed settings%x1|Discard and abort%x0");
703                 
704                 // ask user if thats what he/she wants...
705                 selection = pupmenu(dispmsg);
706                 if (selection<1) return 0; // 0 from menu, or -1 aborted
707                 BLI_strncpy(targetDir, newSurfdataPath, sizeof(targetDir));
708                 strncpy(domainSettings->surfdataPath, newSurfdataPath, FILE_MAXDIR);
709                 BLI_path_abs(targetDir, G.main->name); // fixed #frame-no 
710         }
711 #endif  
712         return outStringsChanged;
713 }
714
715 /* ******************************************************************************** */
716 /* ********************** write fluidsim config to file ************************* */
717 /* ******************************************************************************** */
718
719 typedef struct FluidBakeJob {
720         /* from wmJob */
721         void *owner;
722         short *stop, *do_update;
723         float *progress;
724         int current_frame;
725         elbeemSimulationSettings *settings;
726 } FluidBakeJob;
727
728 static void fluidbake_free(void *customdata)
729 {
730         FluidBakeJob *fb= (FluidBakeJob *)customdata;
731         MEM_freeN(fb);
732 }
733
734 /* called by fluidbake, only to check job 'stop' value */
735 static int fluidbake_breakjob(void *customdata)
736 {
737         FluidBakeJob *fb= (FluidBakeJob *)customdata;
738
739         if (fb->stop && *(fb->stop))
740                 return 1;
741         
742         /* this is not nice yet, need to make the jobs list template better 
743          * for identifying/acting upon various different jobs */
744         /* but for now we'll reuse the render break... */
745         return (G.afbreek);
746 }
747
748 /* called by fluidbake, wmJob sends notifier */
749 static void fluidbake_updatejob(void *customdata, float progress)
750 {
751         FluidBakeJob *fb= (FluidBakeJob *)customdata;
752         
753         *(fb->do_update)= 1;
754         *(fb->progress)= progress;
755 }
756
757 static void fluidbake_startjob(void *customdata, short *stop, short *do_update, float *progress)
758 {
759         FluidBakeJob *fb= (FluidBakeJob *)customdata;
760         
761         fb->stop= stop;
762         fb->do_update = do_update;
763         fb->progress = progress;
764         
765         G.afbreek= 0;   /* XXX shared with render - replace with job 'stop' switch */
766         
767         elbeemSimulate();
768         *do_update= 1;
769         *stop = 0;
770 }
771
772 static void fluidbake_endjob(void *customdata)
773 {
774         FluidBakeJob *fb= (FluidBakeJob *)customdata;
775         
776         if (fb->settings) {
777                 MEM_freeN(fb->settings);
778                 fb->settings = NULL;
779         }
780 }
781
782 int runSimulationCallback(void *data, int status, int frame)
783 {
784         FluidBakeJob *fb = (FluidBakeJob *)data;
785         elbeemSimulationSettings *settings = fb->settings;
786         
787         if (status == FLUIDSIM_CBSTATUS_NEWFRAME) {
788                 fluidbake_updatejob(fb, frame / (float)settings->noOfFrames);
789                 //printf("elbeem blender cb s%d, f%d, domainid:%d noOfFrames: %d\n", status, frame, settings->domainId, settings->noOfFrames ); // DEBUG
790         }
791         
792         if (fluidbake_breakjob(fb)) {
793                 return FLUIDSIM_CBRET_ABORT;
794         }
795         
796         return FLUIDSIM_CBRET_CONTINUE;
797 }
798
799 static void fluidbake_free_data(FluidAnimChannels *channels, ListBase *fobjects, elbeemSimulationSettings *fsset, FluidBakeJob *fb)
800 {
801         free_domain_channels(channels);
802         MEM_freeN(channels);
803         channels = NULL;
804
805         free_all_fluidobject_channels(fobjects);
806         BLI_freelistN(fobjects);
807         MEM_freeN(fobjects);
808         fobjects = NULL;
809         
810         if (fsset) {
811                 MEM_freeN(fsset);
812                 fsset = NULL;
813         }
814         
815         if (fb) {
816                 MEM_freeN(fb);
817                 fb = NULL;
818         }
819 }
820
821 /* copied from rna_fluidsim.c: fluidsim_find_lastframe() */
822 static void fluidsim_delete_until_lastframe(FluidsimSettings *fss, const char *relbase)
823 {
824         char targetDir[FILE_MAX], targetFile[FILE_MAX];
825         char targetDirVel[FILE_MAX], targetFileVel[FILE_MAX];
826         char previewDir[FILE_MAX], previewFile[FILE_MAX];
827         int curFrame = 1, exists = 0;
828
829         BLI_join_dirfile(targetDir,    sizeof(targetDir),    fss->surfdataPath, OB_FLUIDSIM_SURF_FINAL_OBJ_FNAME);
830         BLI_join_dirfile(targetDirVel, sizeof(targetDirVel), fss->surfdataPath, OB_FLUIDSIM_SURF_FINAL_VEL_FNAME);
831         BLI_join_dirfile(previewDir,   sizeof(previewDir),   fss->surfdataPath, OB_FLUIDSIM_SURF_PREVIEW_OBJ_FNAME);
832
833         BLI_path_abs(targetDir,    relbase);
834         BLI_path_abs(targetDirVel, relbase);
835         BLI_path_abs(previewDir,   relbase);
836
837         do {
838                 BLI_strncpy(targetFile, targetDir, sizeof(targetFile));
839                 BLI_strncpy(targetFileVel, targetDirVel, sizeof(targetFileVel));
840                 BLI_strncpy(previewFile, previewDir, sizeof(previewFile));
841
842                 BLI_path_frame(targetFile, curFrame, 0);
843                 BLI_path_frame(targetFileVel, curFrame, 0);
844                 BLI_path_frame(previewFile, curFrame, 0);
845
846                 curFrame++;
847
848                 if ((exists = BLI_exists(targetFile))) {
849                         BLI_delete(targetFile, 0, 0);
850                         BLI_delete(targetFileVel, 0, 0);
851                         BLI_delete(previewFile, 0, 0);
852                 }
853         } while (exists);
854
855         return;
856 }
857
858 static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, short do_job)
859 {
860         Scene *scene= CTX_data_scene(C);
861         int i;
862         FluidsimSettings *domainSettings;
863
864         char debugStrBuffer[256];
865         
866         int gridlevels = 0;
867         const char *relbase= modifier_path_relbase(fsDomain);
868         const char *strEnvName = "BLENDER_ELBEEMDEBUG"; // from blendercall.cpp
869         const char *suffixConfigTmp = FLUID_SUFFIX_CONFIG_TMP;
870         const char *suffixSurface = FLUID_SUFFIX_SURFACE;
871
872         char targetDir[FILE_MAX];  // store & modify output settings
873         char targetFile[FILE_MAX]; // temp. store filename from targetDir for access
874         int  outStringsChanged = 0;             // modified? copy back before baking
875
876         float domainMat[4][4];
877         float invDomMat[4][4];
878
879         int noFrames;
880         int origFrame = scene->r.cfra;
881         
882         FluidAnimChannels *channels = MEM_callocN(sizeof(FluidAnimChannels), "fluid domain animation channels");
883         ListBase *fobjects = MEM_callocN(sizeof(ListBase), "fluid objects");
884         FluidsimModifierData *fluidmd = NULL;
885         Mesh *mesh = NULL;
886
887         FluidBakeJob *fb;
888         elbeemSimulationSettings *fsset= MEM_callocN(sizeof(elbeemSimulationSettings), "Fluid sim settings");
889
890         fb= MEM_callocN(sizeof(FluidBakeJob), "fluid bake job");
891         
892         if (getenv(strEnvName)) {
893                 int dlevel = atoi(getenv(strEnvName));
894                 elbeemSetDebugLevel(dlevel);
895                 BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::msg: Debug messages activated due to envvar '%s'\n", strEnvName);
896                 elbeemDebugOut(debugStrBuffer);
897         }
898         
899         /* make sure it corresponds to startFrame setting (old: noFrames = scene->r.efra - scene->r.sfra +1) */;
900         noFrames = scene->r.efra - 0;
901         if (noFrames<=0) {
902                 BKE_report(reports, RPT_ERROR, "No frames to export - check your animation range settings");
903                 fluidbake_free_data(channels, fobjects, fsset, fb);
904                 return 0;
905         }
906         
907         /* check scene for sane object/modifier settings */
908         if (!fluid_validate_scene(reports, scene, fsDomain)) {
909                 fluidbake_free_data(channels, fobjects, fsset, fb);
910                 return 0;
911         }
912         
913         /* these both have to be valid, otherwise we wouldnt be here */
914         fluidmd = (FluidsimModifierData *)modifiers_findByType(fsDomain, eModifierType_Fluidsim);
915         domainSettings = fluidmd->fss;
916         mesh = fsDomain->data;
917         
918         domainSettings->bakeStart = 1;
919         domainSettings->bakeEnd = scene->r.efra;
920         
921         // calculate bounding box
922         fluid_get_bb(mesh->mvert, mesh->totvert, fsDomain->obmat, domainSettings->bbStart, domainSettings->bbSize);
923         
924         // reset last valid frame
925         domainSettings->lastgoodframe = -1;
926
927         /* delete old baked files */
928         fluidsim_delete_until_lastframe(domainSettings, relbase);
929         
930         /* rough check of settings... */
931         if (domainSettings->previewresxyz > domainSettings->resolutionxyz) {
932                 BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::warning - Preview (%d) >= Resolution (%d)... setting equal.\n", domainSettings->previewresxyz,  domainSettings->resolutionxyz);
933                 elbeemDebugOut(debugStrBuffer);
934                 domainSettings->previewresxyz = domainSettings->resolutionxyz;
935         }
936         // set adaptive coarsening according to resolutionxyz
937         // this should do as an approximation, with in/outflow
938         // doing this more accurate would be overkill
939         // perhaps add manual setting?
940         if (domainSettings->maxRefine <0) {
941                 if (domainSettings->resolutionxyz>128) {
942                         gridlevels = 2;
943                 }
944                 else
945                 if (domainSettings->resolutionxyz>64) {
946                         gridlevels = 1;
947                 }
948                 else {
949                         gridlevels = 0;
950                 }
951         }
952         else {
953                 gridlevels = domainSettings->maxRefine;
954         }
955         BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::msg: Baking %s, refine: %d\n", fsDomain->id.name, gridlevels);
956         elbeemDebugOut(debugStrBuffer);
957         
958         
959         
960         /* ******** prepare output file paths ******** */
961         outStringsChanged = fluid_init_filepaths(fsDomain, targetDir, targetFile, debugStrBuffer);
962         channels->length = scene->r.efra;
963         channels->aniFrameTime = (domainSettings->animEnd - domainSettings->animStart)/(double)noFrames;
964         
965         /* ******** initialize and allocate animation channels ******** */
966         fluid_init_all_channels(C, fsDomain, domainSettings, channels, fobjects);
967
968         /* reset to original current frame */
969         scene->r.cfra = origFrame;
970         ED_update_for_newframe(CTX_data_main(C), scene, CTX_wm_screen(C), 1);
971                 
972         /* ******** init domain object's matrix ******** */
973         copy_m4_m4(domainMat, fsDomain->obmat);
974         if (!invert_m4_m4(invDomMat, domainMat)) {
975                 BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::error - Invalid obj matrix?\n");
976                 elbeemDebugOut(debugStrBuffer);
977                 BKE_report(reports, RPT_ERROR, "Invalid object matrix"); 
978
979                 fluidbake_free_data(channels, fobjects, fsset, fb);
980                 return 0;
981         }
982
983         /* ********  start writing / exporting ******** */
984         // use .tmp, don't overwrite/delete original file
985         BLI_join_dirfile(targetFile, sizeof(targetFile), targetDir, suffixConfigTmp);
986         
987         // make sure these directories exist as well
988         if (outStringsChanged) {
989                 BLI_make_existing_file(targetFile);
990         }
991
992         /* ******** export domain to elbeem ******** */
993         elbeemResetSettings(fsset);
994         fsset->version = 1;
995
996         // setup global settings
997         copy_v3_v3(fsset->geoStart, domainSettings->bbStart);
998         copy_v3_v3(fsset->geoSize, domainSettings->bbSize);
999         
1000         // simulate with 50^3
1001         fsset->resolutionxyz = (int)domainSettings->resolutionxyz;
1002         fsset->previewresxyz = (int)domainSettings->previewresxyz;
1003
1004         fsset->realsize = get_fluid_size_m(scene, fsDomain, domainSettings);
1005         fsset->viscosity = get_fluid_viscosity(domainSettings);
1006         get_fluid_gravity(fsset->gravity, scene, domainSettings);
1007
1008         // simulate 5 frames, each 0.03 seconds, output to ./apitest_XXX.bobj.gz
1009         fsset->animStart = domainSettings->animStart;
1010         fsset->aniFrameTime = channels->aniFrameTime;
1011         fsset->noOfFrames = noFrames; // is otherwise subtracted in parser
1012
1013         BLI_join_dirfile(targetFile, sizeof(targetFile), targetDir, suffixSurface);
1014
1015         // defaults for compressibility and adaptive grids
1016         fsset->gstar = domainSettings->gstar;
1017         fsset->maxRefine = domainSettings->maxRefine; // check <-> gridlevels
1018         fsset->generateParticles = domainSettings->generateParticles; 
1019         fsset->numTracerParticles = domainSettings->generateTracers; 
1020         fsset->surfaceSmoothing = domainSettings->surfaceSmoothing; 
1021         fsset->surfaceSubdivs = domainSettings->surfaceSubdivs; 
1022         fsset->farFieldSize = domainSettings->farFieldSize; 
1023         BLI_strncpy(fsset->outputPath, targetFile, sizeof(fsset->outputPath));
1024
1025         // domain channels
1026         fsset->channelSizeFrameTime = 
1027         fsset->channelSizeViscosity = 
1028         fsset->channelSizeGravity = channels->length;
1029         fsset->channelFrameTime = channels->DomainTime;
1030         fsset->channelViscosity = channels->DomainViscosity;
1031         fsset->channelGravity = channels->DomainGravity;
1032         
1033         fsset->runsimCallback = &runSimulationCallback;
1034         fsset->runsimUserData = fb;
1035
1036         if (domainSettings->typeFlags & OB_FSBND_NOSLIP)                fsset->domainobsType = FLUIDSIM_OBSTACLE_NOSLIP;
1037         else if (domainSettings->typeFlags&OB_FSBND_PARTSLIP)   fsset->domainobsType = FLUIDSIM_OBSTACLE_PARTSLIP;
1038         else if (domainSettings->typeFlags&OB_FSBND_FREESLIP)   fsset->domainobsType = FLUIDSIM_OBSTACLE_FREESLIP;
1039         fsset->domainobsPartslip = domainSettings->partSlipValue;
1040
1041         /* use domainobsType also for surface generation flag (bit: >=64) */
1042         if (domainSettings->typeFlags & OB_FSSG_NOOBS)
1043                 fsset->mFsSurfGenSetting = FLUIDSIM_FSSG_NOOBS;
1044         else
1045                 fsset->mFsSurfGenSetting = 0; // "normal" mode
1046
1047         fsset->generateVertexVectors = (domainSettings->domainNovecgen==0);
1048
1049         // init blender domain transform matrix
1050         { int j; 
1051         for (i=0; i<4; i++) {
1052                 for (j=0; j<4; j++) {
1053                         fsset->surfaceTrafo[i*4+j] = invDomMat[j][i];
1054                 }
1055         } }
1056
1057         /* ******** init solver with settings ******** */
1058         elbeemInit();
1059         elbeemAddDomain(fsset);
1060         
1061         /* ******** export all fluid objects to elbeem ******** */
1062         export_fluid_objects(fobjects, scene, channels->length);
1063         
1064         /* custom data for fluid bake job */
1065         fb->settings = fsset;
1066         
1067         if (do_job) {
1068                 wmJob *steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Fluid Simulation", WM_JOB_PROGRESS);
1069
1070                 /* setup job */
1071                 WM_jobs_customdata(steve, fb, fluidbake_free);
1072                 WM_jobs_timer(steve, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
1073                 WM_jobs_callbacks(steve, fluidbake_startjob, NULL, NULL, fluidbake_endjob);
1074
1075                 WM_jobs_start(CTX_wm_manager(C), steve);
1076         }
1077         else {
1078                 short dummy_stop, dummy_do_update;
1079                 float dummy_progress;
1080
1081                 /* blocking, use with exec() */
1082                 fluidbake_startjob((void *)fb, &dummy_stop, &dummy_do_update, &dummy_progress);
1083                 fluidbake_endjob((void *)fb);
1084                 fluidbake_free((void *)fb);
1085         }
1086
1087         /* ******** free stored animation data ******** */
1088         fluidbake_free_data(channels, fobjects, NULL, NULL);
1089
1090         // elbeemFree();
1091         return 1;
1092 }
1093
1094 void fluidsimFreeBake(Object *UNUSED(ob))
1095 {
1096         /* not implemented yet */
1097 }
1098
1099 #else /* WITH_MOD_FLUID */
1100
1101 /* compile dummy functions for disabled fluid sim */
1102
1103 FluidsimSettings *fluidsimSettingsNew(Object *UNUSED(srcob))
1104 {
1105         return NULL;
1106 }
1107
1108 void fluidsimSettingsFree(FluidsimSettings *UNUSED(fss))
1109 {
1110 }
1111
1112 FluidsimSettings* fluidsimSettingsCopy(FluidsimSettings *UNUSED(fss))
1113 {
1114         return NULL;
1115 }
1116
1117 /* only compile dummy functions */
1118 static int fluidsimBake(bContext *UNUSED(C), ReportList *UNUSED(reports), Object *UNUSED(ob), short UNUSED(do_job))
1119 {
1120         return 0;
1121 }
1122
1123 #endif /* WITH_MOD_FLUID */
1124
1125 /***************************** Operators ******************************/
1126
1127 static int fluid_bake_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1128 {
1129         /* only one bake job at a time */
1130         if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
1131                 return OPERATOR_CANCELLED;
1132
1133         if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), TRUE))
1134                 return OPERATOR_CANCELLED;
1135
1136         return OPERATOR_FINISHED;
1137 }
1138
1139 static int fluid_bake_exec(bContext *C, wmOperator *op)
1140 {
1141         if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), FALSE))
1142                 return OPERATOR_CANCELLED;
1143
1144         return OPERATOR_FINISHED;
1145 }
1146
1147 void FLUID_OT_bake(wmOperatorType *ot)
1148 {
1149         /* identifiers */
1150         ot->name = "Fluid Simulation Bake";
1151         ot->description = "Bake fluid simulation";
1152         ot->idname = "FLUID_OT_bake";
1153         
1154         /* api callbacks */
1155         ot->invoke = fluid_bake_invoke;
1156         ot->exec = fluid_bake_exec;
1157         ot->poll = ED_operator_object_active_editable;
1158 }
1159