~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/physics/physics_fluid.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * fluidsim.c
3
 
 * 
4
 
 *
5
2
 * ***** BEGIN GPL LICENSE BLOCK *****
6
3
 *
7
4
 * This program is free software; you can redistribute it and/or
32
29
 *  \ingroup edphys
33
30
 */
34
31
 
35
 
 
36
 
 
37
 
 
38
32
#include <math.h>
39
33
#include <stdlib.h>
40
34
#include <string.h>
132
126
                float dim[3];
133
127
                float longest_axis;
134
128
                
135
 
                object_get_dimensions(domainob, dim);
136
 
                longest_axis = MAX3(dim[0], dim[1], dim[2]);
 
129
                BKE_object_dimensions_get(domainob, dim);
 
130
                longest_axis = max_fff(dim[0], dim[1], dim[2]);
137
131
                
138
132
                return longest_axis * scene->unit.scale_length;
139
133
        }
148
142
 
149
143
#if 0
150
144
/* helper function */
151
 
void fluidsimGetGeometryObjFilename(Object *ob, char *dst) { //, char *srcname)
 
145
void fluidsimGetGeometryObjFilename(Object *ob, char *dst)  //, char *srcname)
152
146
{
153
 
        //BLI_snprintf(dst,FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name);
154
 
        BLI_snprintf(dst,FILE_MAXFILE, "fluidcfgdata_%s.bobj.gz", ob->id.name);
 
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);
155
149
}
156
150
#endif
157
151
 
199
193
#if 0
200
194
static void fluidsimPrintChannel(FILE *file, float *channel, int paramsize, char *str, int entries) 
201
195
202
 
        int i,j; 
 
196
        int i, j;
203
197
        int channelSize = paramsize; 
204
198
 
205
 
        if (entries==3) {
206
 
                elbeemSimplifyChannelVec3( channel, &channelSize); 
 
199
        if (entries == 3) {
 
200
                elbeemSimplifyChannelVec3(channel, &channelSize);
207
201
        }
208
 
        else if (entries==1) {
209
 
                elbeemSimplifyChannelFloat( channel, &channelSize); 
 
202
        else if (entries == 1) {
 
203
                elbeemSimplifyChannelFloat(channel, &channelSize);
210
204
        }
211
205
        else {
212
 
                // invalid, cant happen?
 
206
                /* invalid, cant happen? */
213
207
        }
214
208
 
215
209
        fprintf(file, "      CHANNEL %s =\n", str);
216
 
        for (i=0; i<channelSize;i++) { 
217
 
                fprintf(file,"        ");  
218
 
                for (j=0;j<=entries;j++) {  // also print time value
219
 
                        fprintf(file," %f ", channel[i*(entries+1)+j] ); 
220
 
                        if (j==entries-1) { fprintf(file,"  "); }
221
 
                } 
222
 
                fprintf(file,"\n");
223
 
        } 
 
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
        }
224
218
 
225
 
        fprintf(file,  "      ;\n" );
 
219
        fprintf(file,  "      ;\n");
226
220
}
227
221
#endif
228
222
 
243
237
{
244
238
        int i;
245
239
        
246
 
        channels->timeAtFrame = MEM_callocN( (channels->length+1)*sizeof(float), "timeAtFrame channel");
 
240
        channels->timeAtFrame = MEM_callocN((channels->length + 1) * sizeof(float), "timeAtFrame channel");
247
241
        
248
242
        channels->timeAtFrame[0] = channels->timeAtFrame[1] = domainSettings->animStart; // start at index 1
249
243
        
250
244
        for (i=2; i <= channels->length; i++) {
251
 
                channels->timeAtFrame[i] = channels->timeAtFrame[i-1] + channels->aniFrameTime;
 
245
                channels->timeAtFrame[i] = channels->timeAtFrame[i - 1] + (float)channels->aniFrameTime;
252
246
        }
253
247
}
254
248
 
273
267
        FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
274
268
        float *verts;
275
269
        int *tris=NULL, numVerts=0, numTris=0;
276
 
        int modifierIndex = modifiers_indexInObject(ob, (ModifierData *)fluidmd);
 
270
        int modifierIndex = BLI_findindex(&ob->modifiers, fluidmd);
277
271
        int framesize = (3*fobj->numVerts) + 1;
278
272
        int j;
279
273
        
361
355
        init_time(domainSettings, channels);
362
356
        
363
357
        /* allocate domain animation channels */
364
 
        channels->DomainGravity = MEM_callocN( length * (CHANNEL_VEC+1) * sizeof(float), "channel DomainGravity");
365
 
        channels->DomainViscosity = MEM_callocN( length * (CHANNEL_FLOAT+1) * sizeof(float), "channel DomainViscosity");
366
 
        channels->DomainTime = MEM_callocN( length * (CHANNEL_FLOAT+1) * sizeof(float), "channel DomainTime");
 
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");
367
361
        
368
362
        /* allocate fluid objects */
369
363
        for (base=scene->base.first; base; base= base->next) {
379
373
                                continue;
380
374
                        }
381
375
                        
382
 
                        fobj->Translation = MEM_callocN( length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject Translation");
383
 
                        fobj->Rotation = MEM_callocN( length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject Rotation");
384
 
                        fobj->Scale = MEM_callocN( length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject Scale");
385
 
                        fobj->Active = MEM_callocN( length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject Active");
386
 
                        fobj->InitialVelocity = MEM_callocN( length * (CHANNEL_VEC+1) * sizeof(float), "fluidobject InitialVelocity");
 
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");
387
381
                        
388
382
                        if (fluidmd->fss->type == OB_FLUIDSIM_CONTROL) {
389
 
                                fobj->AttractforceStrength = MEM_callocN( length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject AttractforceStrength");
390
 
                                fobj->AttractforceRadius = MEM_callocN( length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject AttractforceRadius");
391
 
                                fobj->VelocityforceStrength = MEM_callocN( length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject VelocityforceStrength");
392
 
                                fobj->VelocityforceRadius = MEM_callocN( length * (CHANNEL_FLOAT+1) * sizeof(float), "fluidobject VelocityforceRadius");
 
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");
393
387
                        }
394
388
                        
395
389
                        if (fluid_is_animated_mesh(fluidmd->fss)) {
396
390
                                float *verts=NULL;
397
 
                                int *tris=NULL, modifierIndex = modifiers_indexInObject(ob, (ModifierData *)fluidmd);
 
391
                                int *tris=NULL, modifierIndex = BLI_findindex(&ob->modifiers, (ModifierData *)fluidmd);
398
392
 
399
393
                                initElbeemMesh(scene, ob, &fobj->numVerts, &verts, &fobj->numTris, &tris, 0, modifierIndex);
400
 
                                fobj->VertexCache = MEM_callocN( length *((fobj->numVerts*CHANNEL_VEC)+1) * sizeof(float), "fluidobject VertexCache");
 
394
                                fobj->VertexCache = MEM_callocN(length *((fobj->numVerts*CHANNEL_VEC)+1) * sizeof(float), "fluidobject VertexCache");
401
395
                                
402
396
                                MEM_freeN(verts);
403
397
                                MEM_freeN(tris);
408
402
        }
409
403
        
410
404
        /* now we loop over the frames and fill the allocated channels with data */
411
 
        for (i=0; i<channels->length; i++) {
 
405
        for (i=0; i < channels->length; i++) {
412
406
                FluidObject *fobj;
413
407
                float viscosity, gravity[3];
414
408
                float timeAtFrame, time;
425
419
                /* Modifying the global scene isn't nice, but we can do it in 
426
420
                 * this part of the process before a threaded job is created */
427
421
                scene->r.cfra = (int)eval_time;
428
 
                ED_update_for_newframe(CTX_data_main(C), scene, CTX_wm_screen(C), 1);
 
422
                ED_update_for_newframe(CTX_data_main(C), scene, 1);
429
423
                
430
424
                /* now scene data should be current according to animation system, so we fill the channels */
431
425
                
432
426
                /* Domain time */
433
427
                // TODO: have option for not running sim, time mangling, in which case second case comes in handy
434
428
                if (channels->DomainTime) {
435
 
                        time = get_fluid_rate(domainSettings) * channels->aniFrameTime;
 
429
                        time = get_fluid_rate(domainSettings) * (float)channels->aniFrameTime;
436
430
                        timeAtFrame = channels->timeAtFrame[i] + time;
437
431
                        
438
432
                        channels->timeAtFrame[i+1] = timeAtFrame;
452
446
                for (fobj=fobjects->first; fobj; fobj=fobj->next) {
453
447
                        Object *ob = fobj->object;
454
448
                        FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
455
 
                        float active= (float)(fluidmd->fss->flag & OB_FLUIDSIM_ACTIVE);
 
449
                        float active= (float) ((fluidmd->fss->flag & OB_FLUIDSIM_ACTIVE) > 0 ? 1 : 0);
456
450
                        float rot_d[3] = {0.f, 0.f, 0.f}, old_rot[3] = {0.f, 0.f, 0.f};
457
451
                        
458
452
                        if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE))
462
456
                        /* get the rotation from ob->obmat rather than ob->rot to account for parent animations */
463
457
                        if (i) {
464
458
                                copy_v3_v3(old_rot, fobj->Rotation + 4*(i-1));
465
 
                                mul_v3_fl(old_rot, -M_PI/180.f);
 
459
                                mul_v3_fl(old_rot, (float)-M_PI / 180.f);
466
460
                        }
467
461
 
468
462
                        mat4_to_compatible_eulO(rot_d, old_rot, 0, ob->obmat);
469
 
                        mul_v3_fl(rot_d, -180.f/M_PI);
 
463
                        mul_v3_fl(rot_d, -180.0f / (float)M_PI);
470
464
                        
471
465
                        set_channel(fobj->Translation, timeAtFrame, ob->loc, i, CHANNEL_VEC);
472
466
                        set_channel(fobj->Rotation, timeAtFrame, rot_d, i, CHANNEL_VEC);
473
467
                        set_channel(fobj->Scale, timeAtFrame, ob->size, i, CHANNEL_VEC);
474
468
                        set_channel(fobj->Active, timeAtFrame, &active, i, CHANNEL_FLOAT);
475
469
                        set_channel(fobj->InitialVelocity, timeAtFrame, &fluidmd->fss->iniVelx, i, CHANNEL_VEC);
 
470
 
 
471
                        // printf("Active: %f, Frame: %f\n", active, timeAtFrame);
476
472
                        
477
473
                        if (fluidmd->fss->type == OB_FLUIDSIM_CONTROL) {
478
474
                                set_channel(fobj->AttractforceStrength, timeAtFrame, &fluidmd->fss->attractforceStrength, i, CHANNEL_FLOAT);
495
491
        for (fobj=fobjects->first; fobj; fobj=fobj->next) {
496
492
                Object *ob = fobj->object;
497
493
                FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
498
 
                int modifierIndex = modifiers_indexInObject(ob, (ModifierData *)fluidmd);
 
494
                int modifierIndex = BLI_findindex(&ob->modifiers, fluidmd);
499
495
                
500
496
                float *verts=NULL;
501
497
                int *tris=NULL;
507
503
                if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE))
508
504
                        continue;
509
505
                
510
 
                elbeemResetMesh( &fsmesh );
 
506
                elbeemResetMesh(&fsmesh);
511
507
                
512
508
                fsmesh.type = fluidmd->fss->type;
513
509
                fsmesh.name = ob->id.name;
533
529
                if ( ELEM(fsmesh.type, OB_FLUIDSIM_FLUID, OB_FLUIDSIM_INFLOW)) {
534
530
                        fsmesh.channelInitialVel = fobj->InitialVelocity;
535
531
                        fsmesh.localInivelCoords = ((fluidmd->fss->typeFlags & OB_FSINFLOW_LOCALCOORD)?1:0);
536
 
                } 
 
532
                }
537
533
                
538
534
                if (fluidmd->fss->typeFlags & OB_FSBND_NOSLIP)
539
535
                        fsmesh.obstacleType = FLUIDSIM_OBSTACLE_NOSLIP;
546
542
                fsmesh.volumeInitType = fluidmd->fss->volumeInitType;
547
543
                fsmesh.obstacleImpactFactor = fluidmd->fss->surfaceSmoothing; // misused value
548
544
                
549
 
                if (fsmesh.type == OB_FLUIDSIM_CONTROL) {
 
545
                if (fsmesh.type == OB_FLUIDSIM_CONTROL) {
550
546
                        fsmesh.cpsTimeStart = fluidmd->fss->cpsTimeStart;
551
547
                        fsmesh.cpsTimeEnd = fluidmd->fss->cpsTimeEnd;
552
548
                        fsmesh.cpsQuality = fluidmd->fss->cpsQuality;
573
569
                if (deform) {
574
570
                        fsmesh.channelSizeVertices = length;
575
571
                        fsmesh.channelVertices = fobj->VertexCache;
576
 
                                
577
 
                        // remove channels
 
572
                        
 
573
                        /* remove channels */
578
574
                        fsmesh.channelTranslation      = 
579
575
                        fsmesh.channelRotation         = 
580
 
                        fsmesh.channelScale            = NULL; 
 
576
                        fsmesh.channelScale            = NULL;
 
577
                        
 
578
                        /* Override user settings, only noslip is supported here! */
 
579
                        if (fsmesh.type != OB_FLUIDSIM_CONTROL)
 
580
                                fsmesh.obstacleType = FLUIDSIM_OBSTACLE_NOSLIP;
581
581
                }
582
582
                
583
583
                elbeemAddMesh(&fsmesh);
594
594
        int channelObjCount = 0;
595
595
        int fluidInputCount = 0;
596
596
 
597
 
        for (base=scene->base.first; base; base= base->next)
598
 
        {
 
597
        for (base=scene->base.first; base; base= base->next) {
599
598
                Object *ob = base->object;
600
 
                FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);                    
 
599
                FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
601
600
 
602
601
                /* only find objects with fluid modifiers */
603
602
                if (!fluidmdtmp || ob->type != OB_MESH) continue;
631
630
                return 0;
632
631
        }
633
632
        
634
 
        if (channelObjCount>=255) {
 
633
        if (channelObjCount >= 255) {
635
634
                BKE_report(reports, RPT_ERROR, "Cannot bake with more then 256 objects");
636
635
                return 0;
637
636
        }
652
651
static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetFile, char *debugStrBuffer)
653
652
{
654
653
        FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsDomain, eModifierType_Fluidsim);
655
 
        FluidsimSettings *domainSettings= fluidmd->fss; 
 
654
        FluidsimSettings *domainSettings= fluidmd->fss;
656
655
        FILE *fileCfg;
657
656
        int dirExist = 0;
658
 
        char newSurfdataPath[FILE_MAX]; // modified output settings
 
657
        char newSurfdataPath[FILE_MAX]; /* modified output settings */
659
658
        const char *suffixConfigTmp = FLUID_SUFFIX_CONFIG_TMP;
660
659
        int outStringsChanged = 0;
661
660
 
662
 
        // prepare names...
 
661
        /* prepare names... */
663
662
        const char *relbase= modifier_path_relbase(fsDomain);
664
663
 
665
664
        BLI_strncpy(targetDir, domainSettings->surfdataPath, FILE_MAXDIR);
666
665
        BLI_strncpy(newSurfdataPath, domainSettings->surfdataPath, FILE_MAXDIR); /* if 0'd out below, this value is never used! */
667
 
        BLI_path_abs(targetDir, relbase); // fixed #frame-no
 
666
        BLI_path_abs(targetDir, relbase); /* fixed #frame-no */
668
667
 
669
668
        /* .tmp: don't overwrite/delete original file */
670
669
        BLI_join_dirfile(targetFile, FILE_MAX, targetDir, suffixConfigTmp);
677
676
        // check selected directory
678
677
        // simply try to open cfg file for writing to test validity of settings
679
678
        fileCfg = BLI_fopen(targetFile, "w");
680
 
        if (fileCfg) { 
 
679
        if (fileCfg) {
681
680
                dirExist = 1; fclose(fileCfg); 
682
681
                // remove cfg dummy from  directory test
683
 
                BLI_delete(targetFile, 0,0);
 
682
                BLI_delete(targetFile, 0, 0);
684
683
        }
685
684
        
686
685
        if (targetDir[0] == '\0' || (!dirExist)) {
692
691
                BLI_splitdirstring(blendDir, blendFile);
693
692
                BLI_replace_extension(blendFile, FILE_MAX, ""); /* strip .blend */
694
693
 
695
 
                BLI_snprintf(newSurfdataPath, FILE_MAX ,"//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name);
 
694
                BLI_snprintf(newSurfdataPath, FILE_MAX, "//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name);
696
695
                
697
696
                BLI_snprintf(debugStrBuffer, 256, "fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath);
698
697
                elbeemDebugOut(debugStrBuffer);
699
698
                outStringsChanged=1;
700
699
        }
701
700
        
702
 
        // check if modified output dir is ok
 
701
        /* check if modified output dir is ok */
703
702
#if 0
704
703
        if (outStringsChanged) {
705
704
                char dispmsg[FILE_MAX+256];
706
705
                int  selection=0;
707
 
                BLI_strncpy(dispmsg,"Output settings set to: '", sizeof(dispmsg));
 
706
                BLI_strncpy(dispmsg, "Output settings set to: '", sizeof(dispmsg));
708
707
                strcat(dispmsg, newSurfdataPath);
709
 
                strcat(dispmsg, "'%t|Continue with changed settings%x1|Discard and abort%x0");
 
708
                strcat(dispmsg, "'%t|Continue with changed settings %x1|Discard and abort %x0");
710
709
                
711
 
                // ask user if thats what he/she wants...
 
710
                /* ask user if thats what he/she wants... */
712
711
                selection = pupmenu(dispmsg);
713
 
                if (selection<1) return 0; // 0 from menu, or -1 aborted
 
712
                if (selection < 1) return 0; /* 0 from menu, or -1 aborted */
714
713
                BLI_strncpy(targetDir, newSurfdataPath, sizeof(targetDir));
715
714
                strncpy(domainSettings->surfdataPath, newSurfdataPath, FILE_MAXDIR);
716
 
                BLI_path_abs(targetDir, G.main->name); // fixed #frame-no 
 
715
                BLI_path_abs(targetDir, G.main->name); /* fixed #frame-no */
717
716
        }
718
 
#endif  
 
717
#endif
719
718
        return outStringsChanged;
720
719
}
721
720
 
749
748
        /* this is not nice yet, need to make the jobs list template better 
750
749
         * for identifying/acting upon various different jobs */
751
750
        /* but for now we'll reuse the render break... */
752
 
        return (G.afbreek);
 
751
        return (G.is_break);
753
752
}
754
753
 
755
754
/* called by fluidbake, wmJob sends notifier */
757
756
{
758
757
        FluidBakeJob *fb= (FluidBakeJob *)customdata;
759
758
        
760
 
        *(fb->do_update)= 1;
761
 
        *(fb->progress)= progress;
 
759
        *(fb->do_update) = TRUE;
 
760
        *(fb->progress) = progress;
762
761
}
763
762
 
764
763
static void fluidbake_startjob(void *customdata, short *stop, short *do_update, float *progress)
769
768
        fb->do_update = do_update;
770
769
        fb->progress = progress;
771
770
        
772
 
        G.afbreek= 0;   /* XXX shared with render - replace with job 'stop' switch */
 
771
        G.is_break = FALSE;  /* XXX shared with render - replace with job 'stop' switch */
773
772
        
774
773
        elbeemSimulate();
775
 
        *do_update= 1;
 
774
        *do_update = TRUE;
776
775
        *stop = 0;
777
776
}
778
777
 
786
785
        }
787
786
}
788
787
 
789
 
int runSimulationCallback(void *data, int status, int frame)
 
788
static int runSimulationCallback(void *data, int status, int frame)
790
789
{
791
790
        FluidBakeJob *fb = (FluidBakeJob *)data;
792
791
        elbeemSimulationSettings *settings = fb->settings;
793
792
        
794
793
        if (status == FLUIDSIM_CBSTATUS_NEWFRAME) {
795
794
                fluidbake_updatejob(fb, frame / (float)settings->noOfFrames);
796
 
                //printf("elbeem blender cb s%d, f%d, domainid:%d noOfFrames: %d\n", status,frame, settings->domainId, settings->noOfFrames ); // DEBUG
 
795
                //printf("elbeem blender cb s%d, f%d, domainid:%d noOfFrames: %d\n", status, frame, settings->domainId, settings->noOfFrames ); // DEBUG
797
796
        }
798
797
        
799
798
        if (fluidbake_breakjob(fb)) {
899
898
        if (getenv(strEnvName)) {
900
899
                int dlevel = atoi(getenv(strEnvName));
901
900
                elbeemSetDebugLevel(dlevel);
902
 
                BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer),"fluidsimBake::msg: Debug messages activated due to envvar '%s'\n",strEnvName);
 
901
                BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::msg: Debug messages activated due to envvar '%s'\n", strEnvName);
903
902
                elbeemDebugOut(debugStrBuffer);
904
903
        }
905
904
        
906
905
        /* make sure it corresponds to startFrame setting (old: noFrames = scene->r.efra - scene->r.sfra +1) */;
907
906
        noFrames = scene->r.efra - 0;
908
907
        if (noFrames<=0) {
909
 
                BKE_report(reports, RPT_ERROR, "No frames to export - check your animation range settings");
 
908
                BKE_report(reports, RPT_ERROR, "No frames to export (check your animation range settings)");
910
909
                fluidbake_free_data(channels, fobjects, fsset, fb);
911
910
                return 0;
912
911
        }
917
916
                return 0;
918
917
        }
919
918
        
920
 
        /* these both have to be valid, otherwise we wouldnt be here */
 
919
        /* these both have to be valid, otherwise we wouldn't be here */
921
920
        fluidmd = (FluidsimModifierData *)modifiers_findByType(fsDomain, eModifierType_Fluidsim);
922
921
        domainSettings = fluidmd->fss;
923
922
        mesh = fsDomain->data;
936
935
        
937
936
        /* rough check of settings... */
938
937
        if (domainSettings->previewresxyz > domainSettings->resolutionxyz) {
939
 
                BLI_snprintf(debugStrBuffer,sizeof(debugStrBuffer),"fluidsimBake::warning - Preview (%d) >= Resolution (%d)... setting equal.\n", domainSettings->previewresxyz ,  domainSettings->resolutionxyz);
 
938
                BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::warning - Preview (%d) >= Resolution (%d)... setting equal.\n", domainSettings->previewresxyz,  domainSettings->resolutionxyz);
940
939
                elbeemDebugOut(debugStrBuffer);
941
940
                domainSettings->previewresxyz = domainSettings->resolutionxyz;
942
941
        }
948
947
                if (domainSettings->resolutionxyz>128) {
949
948
                        gridlevels = 2;
950
949
                }
951
 
                else
952
 
                if (domainSettings->resolutionxyz>64) {
 
950
                else if (domainSettings->resolutionxyz > 64) {
953
951
                        gridlevels = 1;
954
952
                }
955
953
                else {
959
957
        else {
960
958
                gridlevels = domainSettings->maxRefine;
961
959
        }
962
 
        BLI_snprintf(debugStrBuffer,sizeof(debugStrBuffer),"fluidsimBake::msg: Baking %s, refine: %d\n", fsDomain->id.name , gridlevels );
 
960
        BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::msg: Baking %s, refine: %d\n", fsDomain->id.name, gridlevels);
963
961
        elbeemDebugOut(debugStrBuffer);
964
962
        
965
963
        
966
964
        
967
965
        /* ******** prepare output file paths ******** */
968
966
        outStringsChanged = fluid_init_filepaths(fsDomain, targetDir, targetFile, debugStrBuffer);
969
 
        channels->length = scene->r.efra;
970
 
        channels->aniFrameTime = (domainSettings->animEnd - domainSettings->animStart)/(double)noFrames;
 
967
        channels->length = scene->r.efra; // DG TODO: why using endframe and not "noFrames" here? .. because "noFrames" is buggy too? (not using sfra)
 
968
        channels->aniFrameTime = (double)((double)domainSettings->animEnd - (double)domainSettings->animStart) / (double)noFrames;
971
969
        
972
970
        /* ******** initialize and allocate animation channels ******** */
973
971
        fluid_init_all_channels(C, fsDomain, domainSettings, channels, fobjects);
974
972
 
975
973
        /* reset to original current frame */
976
974
        scene->r.cfra = origFrame;
977
 
        ED_update_for_newframe(CTX_data_main(C), scene, CTX_wm_screen(C), 1);
 
975
        ED_update_for_newframe(CTX_data_main(C), scene, 1);
978
976
                
979
977
        /* ******** init domain object's matrix ******** */
980
978
        copy_m4_m4(domainMat, fsDomain->obmat);
981
979
        if (!invert_m4_m4(invDomMat, domainMat)) {
982
 
                BLI_snprintf(debugStrBuffer,sizeof(debugStrBuffer),"fluidsimBake::error - Invalid obj matrix?\n");
 
980
                BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "fluidsimBake::error - Invalid obj matrix?\n");
983
981
                elbeemDebugOut(debugStrBuffer);
984
982
                BKE_report(reports, RPT_ERROR, "Invalid object matrix"); 
985
983
 
1054
1052
        fsset->generateVertexVectors = (domainSettings->domainNovecgen==0);
1055
1053
 
1056
1054
        // init blender domain transform matrix
1057
 
        { int j; 
 
1055
        { int j;
1058
1056
        for (i=0; i<4; i++) {
1059
1057
                for (j=0; j<4; j++) {
1060
1058
                        fsset->surfaceTrafo[i*4+j] = invDomMat[j][i];
1072
1070
        fb->settings = fsset;
1073
1071
        
1074
1072
        if (do_job) {
1075
 
                wmJob *steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Fluid Simulation", WM_JOB_PROGRESS);
 
1073
                wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Fluid Simulation",
 
1074
                                            WM_JOB_PROGRESS, WM_JOB_TYPE_OBJECT_SIM_FLUID);
1076
1075
 
1077
1076
                /* setup job */
1078
 
                WM_jobs_customdata(steve, fb, fluidbake_free);
1079
 
                WM_jobs_timer(steve, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
1080
 
                WM_jobs_callbacks(steve, fluidbake_startjob, NULL, NULL, fluidbake_endjob);
 
1077
                WM_jobs_customdata_set(wm_job, fb, fluidbake_free);
 
1078
                WM_jobs_timer(wm_job, 0.1, NC_SCENE|ND_FRAME, NC_SCENE|ND_FRAME);
 
1079
                WM_jobs_callbacks(wm_job, fluidbake_startjob, NULL, NULL, fluidbake_endjob);
1081
1080
 
1082
 
                WM_jobs_start(CTX_wm_manager(C), steve);
 
1081
                WM_jobs_start(CTX_wm_manager(C), wm_job);
1083
1082
        }
1084
1083
        else {
1085
1084
                short dummy_stop, dummy_do_update;
1098
1097
        return 1;
1099
1098
}
1100
1099
 
1101
 
void fluidsimFreeBake(Object *UNUSED(ob))
 
1100
static void UNUSED_FUNCTION(fluidsimFreeBake)(Object *UNUSED(ob))
1102
1101
{
1103
1102
        /* not implemented yet */
1104
1103
}
1116
1115
{
1117
1116
}
1118
1117
 
1119
 
FluidsimSettings* fluidsimSettingsCopy(FluidsimSettings *UNUSED(fss))
 
1118
FluidsimSettings *fluidsimSettingsCopy(FluidsimSettings *UNUSED(fss))
1120
1119
{
1121
1120
        return NULL;
1122
1121
}
1134
1133
static int fluid_bake_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1135
1134
{
1136
1135
        /* only one bake job at a time */
1137
 
        if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C)))
 
1136
        if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_SIM_FLUID))
1138
1137
                return OPERATOR_CANCELLED;
1139
1138
 
1140
1139
        if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), TRUE))