[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18652] branches/blender2.5/blender/source /blender/editors: 2.5

Ton Roosendaal ton at blender.org
Sat Jan 24 15:25:00 CET 2009


Revision: 18652
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18652
Author:   ton
Date:     2009-01-24 15:24:59 +0100 (Sat, 24 Jan 2009)

Log Message:
-----------
2.5

- writeimage.c back, put in space_file now...
- renamed fluidsim.c to distinguish from bke version

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/space_file/Makefile
    branches/blender2.5/blender/source/blender/editors/space_file/SConscript

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/editors/physics/ed_fluidsim.c
    branches/blender2.5/blender/source/blender/editors/space_file/writeimage.c

Removed Paths:
-------------
    branches/blender2.5/blender/source/blender/editors/physics/fluidsim.c

Copied: branches/blender2.5/blender/source/blender/editors/physics/ed_fluidsim.c (from rev 18650, branches/blender2.5/blender/source/blender/editors/physics/fluidsim.c)
===================================================================
--- branches/blender2.5/blender/source/blender/editors/physics/ed_fluidsim.c	                        (rev 0)
+++ branches/blender2.5/blender/source/blender/editors/physics/ed_fluidsim.c	2009-01-24 14:24:59 UTC (rev 18652)
@@ -0,0 +1,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;
+}
+
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list