1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
|
/**
* fluidsim.c
*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) Blender Foundation
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#ifdef WIN32 /* Windos */
#ifndef snprintf
#define snprintf _snprintf
#endif
#endif
#include "MEM_guardedalloc.h"
/* types */
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_object_fluidsim.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_lattice_types.h"
#include "DNA_scene_types.h"
#include "DNA_camera_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_ipo_types.h"
#include "DNA_key_types.h"
#include "BLI_blenlib.h"
#include "BLI_threads.h"
#include "BLI_arithb.h"
#include "BKE_blender.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_displist.h"
#include "BKE_effect.h"
#include "BKE_fluidsim.h"
#include "BKE_global.h"
#include "BKE_modifier.h"
#include "BKE_main.h"
#include "BKE_key.h"
#include "BKE_scene.h"
#include "BKE_object.h"
#include "BKE_softbody.h"
#include "BKE_DerivedMesh.h"
#include "BKE_ipo.h"
#include "PIL_time.h"
#include "LBM_fluidsim.h"
#include "BIF_gl.h"
#include "ED_anim_api.h"
#include "ED_fluidsim.h"
/* XXX */
/* from header info.c */
static int start_progress_bar(void) {return 0;};
static void end_progress_bar(void) {};
static void waitcursor() {};
static int progress_bar(float done, char *busy_info) {return 0;}
static int pupmenu() {return 0;}
/* XXX */
double fluidsimViscosityPreset[6] = {
-1.0, /* unused */
-1.0, /* manual */
1.0e-6, /* water */
5.0e-5, /* some (thick) oil */
2.0e-3, /* ca. honey */
-1.0 /* end */
};
char* fluidsimViscosityPresetString[6] = {
"UNUSED", /* unused */
"UNUSED", /* manual */
" = 1.0 * 10^-6", /* water */
" = 5.0 * 10^-5", /* some (thick) oil */
" = 2.0 * 10^-3", /* ca. honey */
"INVALID" /* end */
};
/* enable/disable overall compilation */
#ifndef DISABLE_ELBEEM
/* ********************** fluid sim settings struct functions ********************** */
/* helper function */
void fluidsimGetGeometryObjFilename(struct Object *ob, char *dst) { //, char *srcname) {
//snprintf(dst,FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name);
snprintf(dst,FILE_MAXFILE, "fluidcfgdata_%s.bobj.gz", ob->id.name);
}
/* ******************************************************************************** */
/* ********************** fluid sim channel helper functions ********************** */
/* ******************************************************************************** */
// no. of entries for the two channel sizes
#define CHANNEL_FLOAT 1
#define CHANNEL_VEC 3
#define FS_FREE_ONECHANNEL(c,str) { \
if(c){ MEM_freeN(c); c=NULL; } \
} // end ONE CHANN, debug: fprintf(stderr,"freeing " str " \n");
#define FS_FREE_CHANNELS { \
FS_FREE_ONECHANNEL(timeAtIndex,"timeAtIndex");\
FS_FREE_ONECHANNEL(timeAtFrame,"timeAtFrame");\
FS_FREE_ONECHANNEL(channelDomainTime,"channelDomainTime"); \
FS_FREE_ONECHANNEL(channelDomainGravity,"channelDomainGravity");\
FS_FREE_ONECHANNEL(channelDomainViscosity,"channelDomainViscosity");\
for(i=0;i<256;i++) { \
FS_FREE_ONECHANNEL(channelObjMove[i][0],"channelObjMove0"); \
FS_FREE_ONECHANNEL(channelObjMove[i][1],"channelObjMove1"); \
FS_FREE_ONECHANNEL(channelObjMove[i][2],"channelObjMove2"); \
FS_FREE_ONECHANNEL(channelObjInivel[i],"channelObjInivel"); \
FS_FREE_ONECHANNEL(channelObjActive[i],"channelObjActive"); \
FS_FREE_ONECHANNEL(channelAttractforceStrength[i],"channelAttractforceStrength"); \
FS_FREE_ONECHANNEL(channelAttractforceRadius[i],"channelAttractforceRadius"); \
FS_FREE_ONECHANNEL(channelVelocityforceStrength[i],"channelVelocityforceStrength"); \
FS_FREE_ONECHANNEL(channelVelocityforceRadius[i],"channelVelocityforceRadius"); \
} \
} // end FS FREE CHANNELS
// simplify channels before printing
// for API this is done anyway upon init
#if 0
static void fluidsimPrintChannel(FILE *file, float *channel, int paramsize, char *str, int entries)
{
int i,j;
int channelSize = paramsize;
if(entries==3) {
elbeemSimplifyChannelVec3( channel, &channelSize);
} else if(entries==1) {
elbeemSimplifyChannelFloat( channel, &channelSize);
} else {
// invalid, cant happen?
}
fprintf(file, " CHANNEL %s = \n", str);
for(i=0; i<channelSize;i++) {
fprintf(file," ");
for(j=0;j<=entries;j++) { // also print time value
fprintf(file," %f ", channel[i*(entries+1)+j] );
if(j==entries-1){ fprintf(file," "); }
}
fprintf(file," \n");
}
fprintf(file, " ; \n" );
}
#endif
static void fluidsimInitChannel(Scene *scene, float **setchannel, int size, float *time,
int *icuIds, float *defaults, Ipo* ipo, int entries)
{
#if 0
/* goes away completely */
int i,j;
IpoCurve* icus[3];
char *cstr = NULL;
float *channel = NULL;
float aniFrlen = scene->r.framelen;
int current_frame = scene->r.cfra;
if((entries<1) || (entries>3)) {
printf("fluidsimInitChannel::Error - invalid no. of entries: %d\n",entries);
entries = 1;
}
cstr = "fluidsiminit_channelfloat";
if(entries>1) cstr = "fluidsiminit_channelvec";
channel = MEM_callocN( size* (entries+1)* sizeof(float), cstr );
if(ipo) {
for(j=0; j<entries; j++) icus[j] = find_ipocurve(ipo, icuIds[j] );
} else {
for(j=0; j<entries; j++) icus[j] = NULL;
}
for(j=0; j<entries; j++) {
if(icus[j]) {
for(i=1; i<=size; i++) {
/* Bugfix to make python drivers working
// which uses Blender.get("curframe")
*/
scene->r.cfra = floor(aniFrlen*((float)i));
// XXX calc_icu(icus[j], aniFrlen*((float)i) );
channel[(i-1)*(entries+1) + j] = icus[j]->curval;
}
} else {
for(i=1; i<=size; i++) { channel[(i-1)*(entries+1) + j] = defaults[j]; }
}
//printf("fluidsimInitChannel entry:%d , ",j); for(i=1; i<=size; i++) { printf(" val%d:%f ",i, channel[(i-1)*(entries+1) + j] ); } printf(" \n"); // DEBUG
}
// set time values
for(i=1; i<=size; i++) {
channel[(i-1)*(entries+1) + entries] = time[i];
}
scene->r.cfra = current_frame;
*setchannel = channel;
#endif
}
static void fluidsimInitMeshChannel(bContext *C, float **setchannel, int size, Object *obm, int vertices,
float *time, int modifierIndex)
{
Scene *scene= CTX_data_scene(C);
float *channel = NULL;
int mallsize = size* (3*vertices+1);
int frame,i;
int numVerts=0, numTris=0;
int setsize = 3*vertices+1;
channel = MEM_callocN( mallsize* sizeof(float), "fluidsim_meshchannel" );
//fprintf(stderr,"\n\nfluidsimInitMeshChannel size%d verts%d mallsize%d \n\n\n",size,vertices,mallsize);
for(frame=1; frame<=size; frame++) {
float *verts=NULL;
int *tris=NULL;
scene->r.cfra = frame;
ED_update_for_newframe(C, 0);
initElbeemMesh(scene, obm, &numVerts, &verts, &numTris, &tris, 1, modifierIndex);
//fprintf(stderr,"\nfluidsimInitMeshChannel frame%d verts%d/%d \n\n",frame,vertices,numVerts);
for(i=0; i<3*vertices;i++) {
channel[(frame-1)*setsize + i] = verts[i];
//fprintf(stdout," frame%d vert%d=%f \n",frame,i,verts[i]);
//if(i%3==2) fprintf(stdout,"\n");
}
channel[(frame-1)*setsize + setsize-1] = time[frame];
MEM_freeN(verts);
MEM_freeN(tris);
}
*setchannel = channel;
}
/* ******************************************************************************** */
/* ********************** simulation thread ************************* */
/* ******************************************************************************** */
static volatile int globalBakeState = 0; // 0 everything ok, -1 abort simulation, -2 sim error, 1 sim done
static volatile int globalBakeFrame = 0;
static volatile int g_break= 0;
// run simulation in seperate thread
static void *fluidsimSimulateThread(void *unused) { // *ptr) {
//char* fnameCfgPath = (char*)(ptr);
int ret=0;
ret = elbeemSimulate();
BLI_lock_thread(LOCK_CUSTOM1);
if(globalBakeState==0) {
if(ret==0) {
// if no error, set to normal exit
globalBakeState = 1;
} else {
// simulation failed, display error
globalBakeState = -2;
}
}
BLI_unlock_thread(LOCK_CUSTOM1);
return NULL;
}
int runSimulationCallback(void *data, int status, int frame) {
//elbeemSimulationSettings *settings = (elbeemSimulationSettings*)data;
//printf("elbeem blender cb s%d, f%d, domainid:%d \n", status,frame, settings->domainId ); // DEBUG
int state = 0;
if(status==FLUIDSIM_CBSTATUS_NEWFRAME) {
BLI_lock_thread(LOCK_CUSTOM1);
globalBakeFrame = frame-1;
BLI_unlock_thread(LOCK_CUSTOM1);
}
//if((frameCounter==3) && (!frameStop)) { frameStop=1; return 1; }
BLI_lock_thread(LOCK_CUSTOM1);
state = globalBakeState;
BLI_unlock_thread(LOCK_CUSTOM1);
if(state!=0) {
return FLUIDSIM_CBRET_ABORT;
}
return FLUIDSIM_CBRET_CONTINUE;
}
/* ******************************************************************************** */
/* ********************** write fluidsim config to file ************************* */
/* ******************************************************************************** */
void fluidsimBake(bContext *C, struct Object *ob)
{
Scene *scene= CTX_data_scene(C);
FILE *fileCfg;
int i;
struct Object *fsDomain = NULL;
FluidsimSettings *domainSettings;
struct Object *obit = NULL; /* object iterator */
Base *base;
int origFrame = scene->r.cfra;
char debugStrBuffer[256];
int dirExist = 0;
int gridlevels = 0;
int simAborted = 0; // was the simulation aborted by user?
int doExportOnly = 0;
char *exportEnvStr = "BLENDER_ELBEEMEXPORTONLY";
const char *strEnvName = "BLENDER_ELBEEMDEBUG"; // from blendercall.cpp
//char *channelNames[3] = { "translation","rotation","scale" };
char *suffixConfig = "fluidsim.cfg";
char *suffixSurface = "fluidsurface";
char newSurfdataPath[FILE_MAXDIR+FILE_MAXFILE]; // modified output settings
char targetDir[FILE_MAXDIR+FILE_MAXFILE]; // store & modify output settings
char targetFile[FILE_MAXDIR+FILE_MAXFILE]; // temp. store filename from targetDir for access
int outStringsChanged = 0; // modified? copy back before baking
int haveSomeFluid = 0; // check if any fluid objects are set
// config vars, inited before either export or run...
double calcViscosity = 0.0;
int noFrames;
double aniFrameTime;
float aniFrlen;
int channelObjCount;
float *bbStart = NULL;
float *bbSize = NULL;
float domainMat[4][4];
float invDomMat[4][4];
// channel data
int allchannelSize; // fixed by no. of frames
int startFrame = 1; // dont use scene->r.sfra here, always start with frame 1
// easy frame -> sim time calc
float *timeAtFrame=NULL, *timeAtIndex=NULL;
// domain
float *channelDomainTime = NULL;
float *channelDomainViscosity = NULL;
float *channelDomainGravity = NULL;
// objects (currently max. 256 objs)
float *channelObjMove[256][3]; // object movments , 0=trans, 1=rot, 2=scale
float *channelObjInivel[256]; // initial velocities
float *channelObjActive[256]; // obj active channel
/* fluid control channels */
float *channelAttractforceStrength[256];
float *channelAttractforceRadius[256];
float *channelVelocityforceStrength[256];
float *channelVelocityforceRadius[256];
FluidsimModifierData *fluidmd = NULL;
Mesh *mesh = NULL;
if(getenv(strEnvName)) {
int dlevel = atoi(getenv(strEnvName));
elbeemSetDebugLevel(dlevel);
snprintf(debugStrBuffer,256,"fluidsimBake::msg: Debug messages activated due to envvar '%s'\n",strEnvName);
elbeemDebugOut(debugStrBuffer);
}
if(getenv(exportEnvStr)) {
doExportOnly = atoi(getenv(exportEnvStr));
snprintf(debugStrBuffer,256,"fluidsimBake::msg: Exporting mode set to '%d' due to envvar '%s'\n",doExportOnly, exportEnvStr);
elbeemDebugOut(debugStrBuffer);
}
// make sure it corresponds to startFrame setting
// old: noFrames = scene->r.efra - scene->r.sfra +1;
noFrames = scene->r.efra - 0;
if(noFrames<=0) {
pupmenu("Fluidsim Bake Error%t|No frames to export - check your animation range settings. Aborted%x0");
return;
}
/* no object pointer, find in selected ones.. */
if(!ob) {
for(base=scene->base.first; base; base= base->next) {
if ((base)->flag & SELECT)
{
FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(base->object, eModifierType_Fluidsim);
if(fluidmdtmp && (base->object->type==OB_MESH))
{
if(fluidmdtmp->fss->type == OB_FLUIDSIM_DOMAIN)
{
ob = base->object;
break;
}
}
}
}
// no domains found?
if(!ob) return;
}
channelObjCount = 0;
for(base=scene->base.first; base; base= base->next)
{
FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(base->object, eModifierType_Fluidsim);
obit = base->object;
if( fluidmdtmp &&
(obit->type==OB_MESH) &&
(fluidmdtmp->fss->type != OB_FLUIDSIM_DOMAIN) && // if has to match 3 places! // CHECKMATCH
(fluidmdtmp->fss->type != OB_FLUIDSIM_PARTICLE) )
{
channelObjCount++;
}
}
if (channelObjCount>=255) {
pupmenu("Fluidsim Bake Error%t|Cannot bake with more then 256 objects");
return;
}
/* check if there's another domain... */
for(base=scene->base.first; base; base= base->next)
{
FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(base->object, eModifierType_Fluidsim);
obit = base->object;
if( fluidmdtmp &&(obit->type==OB_MESH))
{
if(fluidmdtmp->fss->type == OB_FLUIDSIM_DOMAIN)
{
if(obit != ob)
{
pupmenu("Fluidsim Bake Error%t|There should be only one domain object! Aborted%x0");
return;
}
}
}
}
// check if theres any fluid
// abort baking if not...
for(base=scene->base.first; base; base= base->next)
{
FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(base->object, eModifierType_Fluidsim);
obit = base->object;
if( fluidmdtmp &&
(obit->type==OB_MESH) &&
((fluidmdtmp->fss->type == OB_FLUIDSIM_FLUID) ||
(fluidmdtmp->fss->type == OB_FLUIDSIM_INFLOW) ))
{
haveSomeFluid = 1;
break;
}
}
if(!haveSomeFluid) {
pupmenu("Fluidsim Bake Error%t|No fluid objects in scene... Aborted%x0");
return;
}
/* these both have to be valid, otherwise we wouldnt be here */
/* dont use ob here after...*/
fsDomain = ob;
fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
domainSettings = fluidmd->fss;
ob = NULL;
mesh = fsDomain->data;
// calculate bounding box
fluid_get_bb(mesh->mvert, mesh->totvert, fsDomain->obmat, domainSettings->bbStart, domainSettings->bbSize);
// reset last valid frame
domainSettings->lastgoodframe = -1;
/* rough check of settings... */
if(domainSettings->previewresxyz > domainSettings->resolutionxyz) {
snprintf(debugStrBuffer,256,"fluidsimBake::warning - Preview (%d) >= Resolution (%d)... setting equal.\n", domainSettings->previewresxyz , domainSettings->resolutionxyz);
elbeemDebugOut(debugStrBuffer);
domainSettings->previewresxyz = domainSettings->resolutionxyz;
}
// set adaptive coarsening according to resolutionxyz
// this should do as an approximation, with in/outflow
// doing this more accurate would be overkill
// perhaps add manual setting?
if(domainSettings->maxRefine <0) {
if(domainSettings->resolutionxyz>128) {
gridlevels = 2;
} else
if(domainSettings->resolutionxyz>64) {
gridlevels = 1;
} else {
gridlevels = 0;
}
} else {
gridlevels = domainSettings->maxRefine;
}
snprintf(debugStrBuffer,256,"fluidsimBake::msg: Baking %s, refine: %d\n", fsDomain->id.name , gridlevels );
elbeemDebugOut(debugStrBuffer);
// prepare names...
strncpy(targetDir, domainSettings->surfdataPath, FILE_MAXDIR);
strncpy(newSurfdataPath, domainSettings->surfdataPath, FILE_MAXDIR);
BLI_convertstringcode(targetDir, G.sce); // fixed #frame-no
strcpy(targetFile, targetDir);
strcat(targetFile, suffixConfig);
if(!doExportOnly) { strcat(targetFile,".tmp"); } // dont overwrite/delete original file
// make sure all directories exist
// as the bobjs use the same dir, this only needs to be checked
// for the cfg output
BLI_make_existing_file(targetFile);
// check selected directory
// simply try to open cfg file for writing to test validity of settings
fileCfg = fopen(targetFile, "w");
if(fileCfg) {
dirExist = 1; fclose(fileCfg);
// remove cfg dummy from directory test
if(!doExportOnly) { BLI_delete(targetFile, 0,0); }
}
if((strlen(targetDir)<1) || (!dirExist)) {
char blendDir[FILE_MAXDIR+FILE_MAXFILE], blendFile[FILE_MAXDIR+FILE_MAXFILE];
// invalid dir, reset to current/previous
strcpy(blendDir, G.sce);
BLI_splitdirstring(blendDir, blendFile);
if(strlen(blendFile)>6){
int len = strlen(blendFile);
if( (blendFile[len-6]=='.')&& (blendFile[len-5]=='b')&& (blendFile[len-4]=='l')&&
(blendFile[len-3]=='e')&& (blendFile[len-2]=='n')&& (blendFile[len-1]=='d') ){
blendFile[len-6] = '\0';
}
}
// todo... strip .blend ?
snprintf(newSurfdataPath,FILE_MAXFILE+FILE_MAXDIR,"//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name);
snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath);
elbeemDebugOut(debugStrBuffer);
outStringsChanged=1;
}
// check if modified output dir is ok
if(outStringsChanged) {
char dispmsg[FILE_MAXDIR+FILE_MAXFILE+256];
int selection=0;
strcpy(dispmsg,"Output settings set to: '");
strcat(dispmsg, newSurfdataPath);
strcat(dispmsg, "'%t|Continue with changed settings%x1|Discard and abort%x0");
// ask user if thats what he/she wants...
selection = pupmenu(dispmsg);
if(selection<1) return; // 0 from menu, or -1 aborted
strcpy(targetDir, newSurfdataPath);
strncpy(domainSettings->surfdataPath, newSurfdataPath, FILE_MAXDIR);
BLI_convertstringcode(targetDir, G.sce); // fixed #frame-no
}
// --------------------------------------------------------------------------------------------
// dump data for start frame
// CHECK more reasonable to number frames according to blender?
// dump data for frame 0
scene->r.cfra = startFrame;
ED_update_for_newframe(C, 0);
// init common export vars for both file export and run
for(i=0; i<256; i++) {
channelObjMove[i][0] = channelObjMove[i][1] = channelObjMove[i][2] = NULL;
channelObjInivel[i] = NULL;
channelObjActive[i] = NULL;
channelAttractforceStrength[i] = NULL;
channelAttractforceRadius[i] = NULL;
channelVelocityforceStrength[i] = NULL;
channelVelocityforceRadius[i] = NULL;
}
allchannelSize = scene->r.efra; // always use till last frame
aniFrameTime = (domainSettings->animEnd - domainSettings->animStart)/(double)noFrames;
// blender specific - scale according to map old/new settings in anim panel:
aniFrlen = scene->r.framelen;
if(domainSettings->viscosityMode==1) {
/* manual mode, visc=value/(10^-vexp) */
calcViscosity = (1.0/pow(10.0,domainSettings->viscosityExponent)) * domainSettings->viscosityValue;
} else {
calcViscosity = fluidsimViscosityPreset[ domainSettings->viscosityMode ];
}
bbStart = domainSettings->bbStart;
bbSize = domainSettings->bbSize;
// always init
{ int timeIcu[1] = { FLUIDSIM_TIME };
float timeDef[1] = { 1. };
int gravIcu[3] = { FLUIDSIM_GRAV_X, FLUIDSIM_GRAV_Y, FLUIDSIM_GRAV_Z };
float gravDef[3];
int viscIcu[1] = { FLUIDSIM_VISC };
float viscDef[1] = { 1. };
gravDef[0] = domainSettings->gravx;
gravDef[1] = domainSettings->gravy;
gravDef[2] = domainSettings->gravz;
// time channel is a bit special, init by hand...
timeAtIndex = MEM_callocN( (allchannelSize+1)*1*sizeof(float), "fluidsiminit_timeatindex");
for(i=0; i<=scene->r.efra; i++) {
timeAtIndex[i] = (float)(i-startFrame);
}
fluidsimInitChannel(scene, &channelDomainTime, allchannelSize, timeAtIndex, timeIcu,timeDef, domainSettings->ipo, CHANNEL_FLOAT ); // NDEB
// time channel is a multiplicator for aniFrameTime
if(channelDomainTime) {
for(i=0; i<allchannelSize; i++) {
channelDomainTime[i*2+0] = aniFrameTime * channelDomainTime[i*2+0];
if(channelDomainTime[i*2+0]<0.) channelDomainTime[i*2+0] = 0.;
}
}
timeAtFrame = MEM_callocN( (allchannelSize+1)*1*sizeof(float), "fluidsiminit_timeatframe");
timeAtFrame[0] = timeAtFrame[1] = domainSettings->animStart; // start at index 1
if(channelDomainTime) {
for(i=2; i<=allchannelSize; i++) {
timeAtFrame[i] = timeAtFrame[i-1]+channelDomainTime[(i-1)*2+0];
}
} else {
for(i=2; i<=allchannelSize; i++) { timeAtFrame[i] = timeAtFrame[i-1]+aniFrameTime; }
}
fluidsimInitChannel(scene, &channelDomainViscosity, allchannelSize, timeAtFrame, viscIcu,viscDef, domainSettings->ipo, CHANNEL_FLOAT ); // NDEB
if(channelDomainViscosity) {
for(i=0; i<allchannelSize; i++) { channelDomainViscosity[i*2+0] = calcViscosity * channelDomainViscosity[i*2+0]; }
}
fluidsimInitChannel(scene, &channelDomainGravity, allchannelSize, timeAtFrame, gravIcu,gravDef, domainSettings->ipo, CHANNEL_VEC );
} // domain channel init
// init obj movement channels
channelObjCount=0;
for(base=scene->base.first; base; base= base->next)
{
FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(base->object, eModifierType_Fluidsim);
obit = base->object;
if( fluidmdtmp &&
(obit->type==OB_MESH) &&
(fluidmdtmp->fss->type != OB_FLUIDSIM_DOMAIN) && // if has to match 3 places! // CHECKMATCH
(fluidmdtmp->fss->type != OB_FLUIDSIM_PARTICLE) ) {
// cant use fluidsimInitChannel for obj channels right now, due
// to the special DXXX channels, and the rotation specialities
IpoCurve *icuex[3][3];
//IpoCurve *par_icuex[3][3];
#if 0
int icuIds[3][3] = {
{OB_LOC_X, OB_LOC_Y, OB_LOC_Z},
{OB_ROT_X, OB_ROT_Y, OB_ROT_Z},
{OB_SIZE_X, OB_SIZE_Y, OB_SIZE_Z}
};
int icudIds[3][3] = {
{OB_DLOC_X, OB_DLOC_Y, OB_DLOC_Z},
{OB_DROT_X, OB_DROT_Y, OB_DROT_Z},
{OB_DSIZE_X, OB_DSIZE_Y, OB_DSIZE_Z}
};
#endif
// relative ipos
IpoCurve *icudex[3][3];
//IpoCurve *par_icudex[3][3];
int j,k;
float vals[3] = {0.0,0.0,0.0};
int o = channelObjCount;
int inivelIcu[3] = { FLUIDSIM_VEL_X, FLUIDSIM_VEL_Y, FLUIDSIM_VEL_Z };
float inivelDefs[3];
int activeIcu[1] = { FLUIDSIM_ACTIVE };
float activeDefs[1] = { 1 }; // default to on
inivelDefs[0] = fluidmdtmp->fss->iniVelx;
inivelDefs[1] = fluidmdtmp->fss->iniVely;
inivelDefs[2] = fluidmdtmp->fss->iniVelz;
// check & init loc,rot,size
for(j=0; j<3; j++) {
for(k=0; k<3; k++) {
// XXX icuex[j][k] = find_ipocurve(obit->ipo, icuIds[j][k] );
// XXX icudex[j][k] = find_ipocurve(obit->ipo, icudIds[j][k] );
// XXX lines below were already disabled!
//if(obit->parent) {
//par_icuex[j][k] = find_ipocurve(obit->parent->ipo, icuIds[j][k] );
//par_icudex[j][k] = find_ipocurve(obit->parent->ipo, icudIds[j][k] );
//}
}
}
for(j=0; j<3; j++) {
channelObjMove[o][j] = MEM_callocN( allchannelSize*4*sizeof(float), "fluidsiminit_objmovchannel");
for(i=1; i<=allchannelSize; i++) {
for(k=0; k<3; k++) {
if(icuex[j][k]) {
// IPO exists, use it ...
// XXX calc_icu(icuex[j][k], aniFrlen*((float)i) );
vals[k] = icuex[j][k]->curval;
if(obit->parent) {
// add parent transform, multiply scaling, add trafo&rot
//calc_icu(par_icuex[j][k], aniFrlen*((float)i) );
//if(j==2) { vals[k] *= par_icuex[j][k]->curval; }
//else { vals[k] += par_icuex[j][k]->curval; }
}
} else {
// use defaults from static values
float setval=0.0;
if(j==0) {
setval = obit->loc[k];
if(obit->parent){ setval += obit->parent->loc[k]; }
} else if(j==1) {
setval = ( 180.0*obit->rot[k] )/( 10.0*M_PI );
if(obit->parent){ setval = ( 180.0*(obit->rot[k]+obit->parent->rot[k]) )/( 10.0*M_PI ); }
} else {
setval = obit->size[k];
if(obit->parent){ setval *= obit->parent->size[k]; }
}
vals[k] = setval;
}
if(icudex[j][k]) {
// XXX calc_icu(icudex[j][k], aniFrlen*((float)i) );
//vals[k] += icudex[j][k]->curval;
// add transform, multiply scaling, add trafo&rot
if(j==2) { vals[k] *= icudex[j][k]->curval; }
else { vals[k] += icudex[j][k]->curval; }
if(obit->parent) {
// add parent transform, multiply scaling, add trafo&rot
//calc_icu(par_icuex[j][k], aniFrlen*((float)i) );
//if(j==2) { vals[k] *= par_icudex[j][k]->curval; }
//else { vals[k] += par_icudex[j][k]->curval; }
}
}
} // k
for(k=0; k<3; k++) {
float set = vals[k];
if(j==1) { // rot is downscaled by 10 for ipo !?
set = 360.0 - (10.0*set);
}
channelObjMove[o][j][(i-1)*4 + k] = set;
} // k
channelObjMove[o][j][(i-1)*4 + 3] = timeAtFrame[i];
}
}
{
int attrFSIcu[1] = { FLUIDSIM_ATTR_FORCE_STR };
int attrFRIcu[1] = { FLUIDSIM_ATTR_FORCE_RADIUS };
int velFSIcu[1] = { FLUIDSIM_VEL_FORCE_STR };
int velFRIcu[1] = { FLUIDSIM_VEL_FORCE_RADIUS };
float attrFSDefs[1];
float attrFRDefs[1];
float velFSDefs[1];
float velFRDefs[1];
attrFSDefs[0] = fluidmdtmp->fss->attractforceStrength;
attrFRDefs[0] = fluidmdtmp->fss->attractforceRadius;
velFSDefs[0] = fluidmdtmp->fss->velocityforceStrength;
velFRDefs[0] = fluidmdtmp->fss->velocityforceRadius;
fluidsimInitChannel(scene, &channelAttractforceStrength[o], allchannelSize, timeAtFrame, attrFSIcu,attrFSDefs, fluidmdtmp->fss->ipo, CHANNEL_FLOAT );
fluidsimInitChannel(scene, &channelAttractforceRadius[o], allchannelSize, timeAtFrame, attrFRIcu,attrFRDefs, fluidmdtmp->fss->ipo, CHANNEL_FLOAT );
fluidsimInitChannel(scene, &channelVelocityforceStrength[o], allchannelSize, timeAtFrame, velFSIcu,velFSDefs, fluidmdtmp->fss->ipo, CHANNEL_FLOAT );
fluidsimInitChannel(scene, &channelVelocityforceRadius[o], allchannelSize, timeAtFrame, velFRIcu,velFRDefs, fluidmdtmp->fss->ipo, CHANNEL_FLOAT );
}
fluidsimInitChannel(scene, &channelObjInivel[o], allchannelSize, timeAtFrame, inivelIcu,inivelDefs, fluidmdtmp->fss->ipo, CHANNEL_VEC );
fluidsimInitChannel(scene, &channelObjActive[o], allchannelSize, timeAtFrame, activeIcu,activeDefs, fluidmdtmp->fss->ipo, CHANNEL_FLOAT );
channelObjCount++;
}
}
// init trafo matrix
Mat4CpyMat4(domainMat, fsDomain->obmat);
if(!Mat4Invert(invDomMat, domainMat)) {
snprintf(debugStrBuffer,256,"fluidsimBake::error - Invalid obj matrix?\n");
elbeemDebugOut(debugStrBuffer);
// FIXME add fatal msg
FS_FREE_CHANNELS;
return;
}
// --------------------------------------------------------------------------------------------
// start writing / exporting
strcpy(targetFile, targetDir);
strcat(targetFile, suffixConfig);
if(!doExportOnly) { strcat(targetFile,".tmp"); } // dont overwrite/delete original file
// make sure these directories exist as well
if(outStringsChanged) {
BLI_make_existing_file(targetFile);
}
if(!doExportOnly) {
ListBase threads;
// perform simulation with El'Beem api and threads
elbeemSimulationSettings fsset;
elbeemResetSettings(&fsset);
fsset.version = 1;
// setup global settings
for(i=0 ; i<3; i++) fsset.geoStart[i] = bbStart[i];
for(i=0 ; i<3; i++) fsset.geoSize[i] = bbSize[i];
// simulate with 50^3
fsset.resolutionxyz = (int)domainSettings->resolutionxyz;
fsset.previewresxyz = (int)domainSettings->previewresxyz;
// 10cm water domain
fsset.realsize = domainSettings->realsize;
fsset.viscosity = calcViscosity;
// earth gravity
fsset.gravity[0] = domainSettings->gravx;
fsset.gravity[1] = domainSettings->gravy;
fsset.gravity[2] = domainSettings->gravz;
// simulate 5 frames, each 0.03 seconds, output to ./apitest_XXX.bobj.gz
fsset.animStart = domainSettings->animStart;
fsset.aniFrameTime = aniFrameTime;
fsset.noOfFrames = noFrames; // is otherwise subtracted in parser
strcpy(targetFile, targetDir);
strcat(targetFile, suffixSurface);
// defaults for compressibility and adaptive grids
fsset.gstar = domainSettings->gstar;
fsset.maxRefine = domainSettings->maxRefine; // check <-> gridlevels
fsset.generateParticles = domainSettings->generateParticles;
fsset.numTracerParticles = domainSettings->generateTracers;
fsset.surfaceSmoothing = domainSettings->surfaceSmoothing;
fsset.surfaceSubdivs = domainSettings->surfaceSubdivs;
fsset.farFieldSize = domainSettings->farFieldSize;
strcpy( fsset.outputPath, targetFile);
// domain channels
fsset.channelSizeFrameTime =
fsset.channelSizeViscosity =
fsset.channelSizeGravity = allchannelSize;
fsset.channelFrameTime = channelDomainTime;
fsset.channelViscosity = channelDomainViscosity;
fsset.channelGravity = channelDomainGravity;
fsset.runsimCallback = &runSimulationCallback;
fsset.runsimUserData = &fsset;
if( (domainSettings->typeFlags&OB_FSBND_NOSLIP)) fsset.domainobsType = FLUIDSIM_OBSTACLE_NOSLIP;
else if((domainSettings->typeFlags&OB_FSBND_PARTSLIP)) fsset.domainobsType = FLUIDSIM_OBSTACLE_PARTSLIP;
else if((domainSettings->typeFlags&OB_FSBND_FREESLIP)) fsset.domainobsType = FLUIDSIM_OBSTACLE_FREESLIP;
fsset.domainobsPartslip = domainSettings->partSlipValue;
fsset.generateVertexVectors = (domainSettings->domainNovecgen==0);
// init blender trafo matrix
// fprintf(stderr,"elbeemInit - mpTrafo:\n");
{ int j;
for(i=0; i<4; i++) {
for(j=0; j<4; j++) {
fsset.surfaceTrafo[i*4+j] = invDomMat[j][i];
// fprintf(stderr,"elbeemInit - mpTrafo %d %d = %f (%d) \n", i,j, fsset.surfaceTrafo[i*4+j] , (i*4+j) );
}
} }
// init solver with settings
elbeemInit();
elbeemAddDomain(&fsset);
// init objects
channelObjCount = 0;
for(base=scene->base.first; base; base= base->next) {
FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(base->object, eModifierType_Fluidsim);
obit = base->object;
//{ snprintf(debugStrBuffer,256,"DEBUG object name=%s, type=%d ...\n", obit->id.name, obit->type); elbeemDebugOut(debugStrBuffer); } // DEBUG
if( fluidmdtmp && // if has to match 3 places! // CHECKMATCH
(obit->type==OB_MESH) &&
(fluidmdtmp->fss->type != OB_FLUIDSIM_DOMAIN) &&
(fluidmdtmp->fss->type != OB_FLUIDSIM_PARTICLE))
{
float *verts=NULL;
int *tris=NULL;
int numVerts=0, numTris=0;
int o = channelObjCount;
int deform = (fluidmdtmp->fss->domainNovecgen); // misused value
// todo - use blenderInitElbeemMesh
int modifierIndex = modifiers_indexInObject(obit, (ModifierData *)fluidmdtmp);
elbeemMesh fsmesh;
elbeemResetMesh( &fsmesh );
fsmesh.type = fluidmdtmp->fss->type;
// get name of object for debugging solver
fsmesh.name = obit->id.name;
initElbeemMesh(scene, obit, &numVerts, &verts, &numTris, &tris, 0, modifierIndex);
fsmesh.numVertices = numVerts;
fsmesh.numTriangles = numTris;
fsmesh.vertices = verts;
fsmesh.triangles = tris;
fsmesh.channelSizeTranslation =
fsmesh.channelSizeRotation =
fsmesh.channelSizeScale =
fsmesh.channelSizeInitialVel =
fsmesh.channelSizeActive = allchannelSize;
fsmesh.channelTranslation = channelObjMove[o][0];
fsmesh.channelRotation = channelObjMove[o][1];
fsmesh.channelScale = channelObjMove[o][2];
fsmesh.channelActive = channelObjActive[o];
if( (fsmesh.type == OB_FLUIDSIM_FLUID) ||
(fsmesh.type == OB_FLUIDSIM_INFLOW)) {
fsmesh.channelInitialVel = channelObjInivel[o];
fsmesh.localInivelCoords = ((fluidmdtmp->fss->typeFlags&OB_FSINFLOW_LOCALCOORD)?1:0);
}
if( (fluidmdtmp->fss->typeFlags&OB_FSBND_NOSLIP)) fsmesh.obstacleType = FLUIDSIM_OBSTACLE_NOSLIP;
else if((fluidmdtmp->fss->typeFlags&OB_FSBND_PARTSLIP)) fsmesh.obstacleType = FLUIDSIM_OBSTACLE_PARTSLIP;
else if((fluidmdtmp->fss->typeFlags&OB_FSBND_FREESLIP)) fsmesh.obstacleType = FLUIDSIM_OBSTACLE_FREESLIP;
fsmesh.obstaclePartslip = fluidmdtmp->fss->partSlipValue;
fsmesh.volumeInitType = fluidmdtmp->fss->volumeInitType;
fsmesh.obstacleImpactFactor = fluidmdtmp->fss->surfaceSmoothing; // misused value
if(fsmesh.type == OB_FLUIDSIM_CONTROL)
{
// control fluids will get exported as whole
deform = 1;
fsmesh.cpsTimeStart = fluidmdtmp->fss->cpsTimeStart;
fsmesh.cpsTimeEnd = fluidmdtmp->fss->cpsTimeEnd;
fsmesh.cpsQuality = fluidmdtmp->fss->cpsQuality;
fsmesh.obstacleType = (fluidmdtmp->fss->flag & OB_FLUIDSIM_REVERSE);
fsmesh.channelSizeAttractforceRadius =
fsmesh.channelSizeVelocityforceStrength =
fsmesh.channelSizeVelocityforceRadius =
fsmesh.channelSizeAttractforceStrength = allchannelSize;
fsmesh.channelAttractforceStrength = channelAttractforceStrength[o];
fsmesh.channelAttractforceRadius = channelAttractforceRadius[o];
fsmesh.channelVelocityforceStrength = channelVelocityforceStrength[o];
fsmesh.channelVelocityforceRadius = channelVelocityforceRadius[o];
}
else
{
// set channels to 0
fsmesh.channelAttractforceStrength =
fsmesh.channelAttractforceRadius =
fsmesh.channelVelocityforceStrength =
fsmesh.channelVelocityforceRadius = NULL;
}
// animated meshes
if(deform) {
fsmesh.channelSizeVertices = allchannelSize;
fluidsimInitMeshChannel(C, &fsmesh.channelVertices, allchannelSize, obit, numVerts, timeAtFrame, modifierIndex);
scene->r.cfra = startFrame;
ED_update_for_newframe(C, 0);
// remove channels
fsmesh.channelTranslation =
fsmesh.channelRotation =
fsmesh.channelScale = NULL;
}
elbeemAddMesh(&fsmesh);
if(verts) MEM_freeN(verts);
if(tris) MEM_freeN(tris);
if(fsmesh.channelVertices) MEM_freeN(fsmesh.channelVertices);
channelObjCount++;
} // valid mesh
} // objects
//domainSettings->type = OB_FLUIDSIM_DOMAIN; // enable for bake display again
//fsDomain->fluidsimFlag = OB_FLUIDSIM_ENABLE; // disable during bake
// set to neutral, -1 means user abort, -2 means init error
globalBakeState = 0;
globalBakeFrame = 0;
BLI_init_threads(&threads, fluidsimSimulateThread, 1);
BLI_insert_thread(&threads, targetFile);
{
int done = 0;
float noFramesf = (float)noFrames;
float percentdone = 0.0;
int lastRedraw = -1;
g_break= 0;
G.afbreek= 0; /* blender_test_break uses this global */
start_progress_bar();
while(done==0) {
char busy_mess[80];
waitcursor(1);
// lukep we add progress bar as an interim mesure
percentdone = globalBakeFrame / noFramesf;
sprintf(busy_mess, "baking fluids %d / %d |||", globalBakeFrame, (int) noFramesf);
progress_bar(percentdone, busy_mess );
// longer delay to prevent frequent redrawing
PIL_sleep_ms(2000);
BLI_lock_thread(LOCK_CUSTOM1);
if(globalBakeState != 0) done = 1; // 1=ok, <0=error/abort
BLI_unlock_thread(LOCK_CUSTOM1);
if (!G.background) {
g_break= blender_test_break();
if(g_break)
{
// abort...
BLI_lock_thread(LOCK_CUSTOM1);
if(domainSettings)
domainSettings->lastgoodframe = startFrame+globalBakeFrame;
done = -1;
globalBakeFrame = 0;
globalBakeState = -1;
simAborted = 1;
BLI_unlock_thread(LOCK_CUSTOM1);
break;
}
}
// redraw the 3D for showing progress once in a while...
if(lastRedraw!=globalBakeFrame) {
#if 0
ScrArea *sa;
scene->r.cfra = startFrame+globalBakeFrame;
lastRedraw = globalBakeFrame;
ED_update_for_newframe(C, 0);
sa= G.curscreen->areabase.first;
while(sa) {
if(sa->spacetype == SPACE_VIEW3D) { scrarea_do_windraw(sa); }
sa= sa->next;
}
screen_swapbuffers();
#endif
} // redraw
}
end_progress_bar();
}
BLI_end_threads(&threads);
} // El'Beem API init, thread creation
// --------------------------------------------------------------------------------------------
else
{ // write config file to be run with command line simulator
pupmenu("Fluidsim Bake Message%t|Config file export not supported.%x0");
} // config file export done!
// --------------------------------------------------------------------------------------------
FS_FREE_CHANNELS;
// go back to "current" blender time
waitcursor(0);
if(globalBakeState >= 0)
{
if(domainSettings)
domainSettings->lastgoodframe = startFrame+globalBakeFrame;
}
scene->r.cfra = origFrame;
ED_update_for_newframe(C, 0);
if(!simAborted) {
char fsmessage[512];
char elbeemerr[256];
strcpy(fsmessage,"Fluidsim Bake Error: ");
// check if some error occurred
if(globalBakeState==-2) {
strcat(fsmessage,"Failed to initialize [Msg: ");
elbeemGetErrorString(elbeemerr);
strcat(fsmessage,elbeemerr);
strcat(fsmessage,"] |OK%x0");
pupmenu(fsmessage);
} // init error
}
// elbeemFree();
}
void fluidsimFreeBake(struct Object *ob)
{
/* not implemented yet */
}
#else /* DISABLE_ELBEEM */
/* compile dummy functions for disabled fluid sim */
FluidsimSettings *fluidsimSettingsNew(struct Object *srcob) {
return NULL;
}
void fluidsimSettingsFree(FluidsimSettings *fss) {
}
FluidsimSettings* fluidsimSettingsCopy(FluidsimSettings *fss) {
return NULL;
}
/* only compile dummy functions */
void fluidsimBake(bContext *C, struct Object *ob) {
}
void fluidsimFreeBake(struct Object *ob) {
}
#endif /* DISABLE_ELBEEM */
|