[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16795] branches/soc-2008-mxcurioni: soc-2008-mxcurioni: missing merge files

Maxime Curioni maxime.curioni at gmail.com
Sun Sep 28 20:58:40 CEST 2008


Revision: 16795
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16795
Author:   mxcurioni
Date:     2008-09-28 20:58:40 +0200 (Sun, 28 Sep 2008)

Log Message:
-----------
soc-2008-mxcurioni: missing merge files

Added Paths:
-----------
    branches/soc-2008-mxcurioni/intern/elbeem/intern/controlparticles.cpp
    branches/soc-2008-mxcurioni/intern/elbeem/intern/controlparticles.h
    branches/soc-2008-mxcurioni/intern/elbeem/intern/elbeem_control.cpp
    branches/soc-2008-mxcurioni/intern/elbeem/intern/elbeem_control.h
    branches/soc-2008-mxcurioni/intern/elbeem/intern/mvmcoords.cpp
    branches/soc-2008-mxcurioni/intern/elbeem/intern/mvmcoords.h
    branches/soc-2008-mxcurioni/intern/elbeem/intern/solver_control.cpp
    branches/soc-2008-mxcurioni/intern/elbeem/intern/solver_control.h
    branches/soc-2008-mxcurioni/release/scripts/ms3d_import_ascii.py
    branches/soc-2008-mxcurioni/release/scripts/scripttemplate_gamelogic.py
    branches/soc-2008-mxcurioni/release/scripts/scripttemplate_gamelogic_basic.py
    branches/soc-2008-mxcurioni/source/blender/blenkernel/BKE_bullet.h
    branches/soc-2008-mxcurioni/source/blender/blenkernel/BKE_fluidsim.h
    branches/soc-2008-mxcurioni/source/blender/blenkernel/BKE_simple_deform.h
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/bullet.c
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/fluidsim.c
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/simple_deform.c
    branches/soc-2008-mxcurioni/source/blender/include/BIF_keyframing.h
    branches/soc-2008-mxcurioni/source/blender/src/keyframing.c

Added: branches/soc-2008-mxcurioni/intern/elbeem/intern/controlparticles.cpp
===================================================================
--- branches/soc-2008-mxcurioni/intern/elbeem/intern/controlparticles.cpp	                        (rev 0)
+++ branches/soc-2008-mxcurioni/intern/elbeem/intern/controlparticles.cpp	2008-09-28 18:58:40 UTC (rev 16795)
@@ -0,0 +1,1461 @@
+// --------------------------------------------------------------------------
+//
+// El'Beem - the visual lattice boltzmann freesurface simulator
+// All code distributed as part of El'Beem is covered by the version 2 of the 
+// GNU General Public License. See the file COPYING for details.  
+//
+// Copyright 2008 Nils Thuerey , Richard Keiser, Mark Pauly, Ulrich Ruede
+//
+// implementation of control particle handling
+//
+// --------------------------------------------------------------------------
+
+// indicator for LBM inclusion
+#include "ntl_geometrymodel.h"
+#include "ntl_world.h"
+#include "solver_class.h"
+#include "controlparticles.h"
+#include "mvmcoords.h"
+#include <zlib.h>
+
+#ifndef sqrtf
+#define sqrtf sqrt
+#endif
+
+// brute force circle test init in initTimeArray
+// replaced by mDebugInit
+//#define CP_FORCECIRCLEINIT 0
+
+
+void ControlParticles::initBlenderTest() {
+	mPartSets.clear();
+
+	ControlParticleSet cps;
+	mPartSets.push_back(cps);
+	int setCnt = mPartSets.size()-1;
+	ControlParticle p; 
+
+	// set for time zero
+	mPartSets[setCnt].time = 0.;
+
+	// add single particle 
+	p.reset();
+	p.pos = LbmVec(0.5, 0.5, -0.5);
+	mPartSets[setCnt].particles.push_back(p);
+
+	// add second set for animation
+	mPartSets.push_back(cps);
+	setCnt = mPartSets.size()-1;
+	mPartSets[setCnt].time = 0.15;
+
+	// insert new position
+	p.reset();
+	p.pos = LbmVec(-0.5, -0.5, 0.5);
+	mPartSets[setCnt].particles.push_back(p);
+
+	// applyTrafos();
+	initTime(0. , 1.);
+}
+
+// blender control object gets converted to mvm flui control object
+int ControlParticles::initFromObject(ntlGeometryObjModel *model) {
+	vector<ntlTriangle> triangles;
+	vector<ntlVec3Gfx> vertices;
+	vector<ntlVec3Gfx> normals;
+	
+	/*
+	model->loadBobjModel(string(infile));
+	
+	model->setLoaded(true);
+	
+	model->setGeoInitId(gid);
+	
+	
+	printf("a animated? %d\n", model->getIsAnimated());
+	printf("b animated? %d\n", model->getMeshAnimated());
+	*/
+	
+	model->setGeoInitType(FGI_FLUID);
+	
+	model->getTriangles(mCPSTimeStart, &triangles, &vertices, &normals, 1 ); 
+	// model->applyTransformation(mCPSTimeStart, &vertices, &normals, 0, vertices.size(), true);
+	
+	// valid mesh?
+	if(triangles.size() <= 0) {
+		return 0;
+	}
+
+	ntlRenderGlobals *glob = new ntlRenderGlobals;
+	ntlScene *genscene = new ntlScene( glob, false );
+	genscene->addGeoClass(model);
+	genscene->addGeoObject(model);
+	genscene->buildScene(0., false);
+	char treeFlag = (1<<(4+model->getGeoInitId()));
+
+	ntlTree *tree = new ntlTree( 
+	15, 8,  // TREEwarning - fixed values for depth & maxtriangles here...
+	genscene, treeFlag );
+
+	// TODO? use params
+	ntlVec3Gfx start,end;
+	model->getExtends(start,end);
+	/*
+	printf("start - x: %f, y: %f, z: %f\n", start[0], start[1], start[2]);
+	printf("end   - x: %f, y: %f, z: %f\n", end[0], end[1], end[2]);
+	printf("mCPSWidth: %f\n");
+*/
+	LbmFloat width = mCPSWidth;
+	if(width<=LBM_EPSILON) { errMsg("ControlParticles::initFromMVMCMesh","Invalid mCPSWidth! "<<mCPSWidth); width=mCPSWidth=0.1; }
+	ntlVec3Gfx org = start+ntlVec3Gfx(width*0.5);
+	gfxReal distance = -1.;
+	vector<ntlVec3Gfx> inspos;
+	
+	// printf("distance: %f, width: %f\n", distance, width);
+	
+	while(org[2]<end[2]) {
+		while(org[1]<end[1]) {
+			while(org[0]<end[0]) {
+				if(checkPointInside(tree, org, distance)) {
+					inspos.push_back(org);
+				}
+				// TODO optimize, use distance
+				org[0] += width;
+			}
+			org[1] += width;
+			org[0] = start[0];
+		}
+		org[2] += width;
+		org[1] = start[1];
+	}
+	
+	// printf("inspos.size(): %d\n", inspos.size());
+
+	MeanValueMeshCoords mvm;
+	mvm.calculateMVMCs(vertices,triangles, inspos, mCPSWeightFac);
+	vector<ntlVec3Gfx> ninspos;
+	mvm.transfer(vertices, ninspos);
+
+	// init first set, check dist
+	ControlParticleSet firstcps; //T
+	mPartSets.push_back(firstcps);
+	mPartSets[mPartSets.size()-1].time = mCPSTimeStart;
+	vector<bool> useCP;
+
+	for(int i=0; i<(int)inspos.size(); i++) {
+		ControlParticle p; p.reset();
+		p.pos = vec2L(inspos[i]);
+		
+		bool usecpv = true;
+
+		mPartSets[mPartSets.size()-1].particles.push_back(p);
+		useCP.push_back(usecpv);
+	}
+
+	// init further sets, temporal mesh sampling
+	double tsampling = mCPSTimestep;
+	// printf("tsampling: %f, ninspos.size(): %d, mCPSTimeEnd: %f\n", tsampling, ninspos.size(), mCPSTimeEnd);
+	
+	int tcnt=0;
+	for(double t=mCPSTimeStart+tsampling; ((t<mCPSTimeEnd) && (ninspos.size()>0.)); t+=tsampling) {
+		ControlParticleSet nextcps; //T
+		mPartSets.push_back(nextcps);
+		mPartSets[mPartSets.size()-1].time = (gfxReal)t;
+
+		vertices.clear(); triangles.clear(); normals.clear();
+		model->getTriangles(t, &triangles, &vertices, &normals, 1 );
+		mvm.transfer(vertices, ninspos);
+		
+		tcnt++;
+		for(size_t i=0; i < ninspos.size(); i++) {
+			
+			if(useCP[i]) {
+				ControlParticle p; p.reset();
+				p.pos = vec2L(ninspos[i]);
+				mPartSets[mPartSets.size()-1].particles.push_back(p);
+			}
+		}
+	}
+	
+	model->setGeoInitType(FGI_CONTROL);
+
+	delete tree;
+	delete genscene;
+	delete glob;
+	
+	// do reverse here
+	if(model->getGeoPartSlipValue())
+	{
+		mirrorTime();
+	}
+	
+	return 1;
+}
+
+
+// init all zero / defaults for a single particle
+void ControlParticle::reset() {
+	pos = LbmVec(0.,0.,0.);
+	vel = LbmVec(0.,0.,0.);
+	influence = 1.;
+	size = 1.;
+#ifndef LBMDIM
+#ifdef MAIN_2D
+	rotaxis = LbmVec(0.,1.,0.); // SPH xz
+#else // MAIN_2D
+	// 3d - roate in xy plane, vortex
+	rotaxis = LbmVec(0.,0.,1.);
+	// 3d - rotate for wave
+	//rotaxis = LbmVec(0.,1.,0.);
+#endif // MAIN_2D
+#else // LBMDIM
+	rotaxis = LbmVec(0.,1.,0.); // LBM xy , is swapped afterwards
+#endif // LBMDIM
+
+	density = 0.;
+	densityWeight = 0.;
+	avgVelAcc = avgVel = LbmVec(0.);
+	avgVelWeight = 0.;
+}
+
+
+// default preset/empty init
+ControlParticles::ControlParticles() :
+	_influenceTangential(0.f),
+	_influenceAttraction(0.f),
+	_influenceVelocity(0.f),
+	_influenceMaxdist(0.f),
+	_radiusAtt(1.0f),
+	_radiusVel(1.0f),
+	_radiusMinMaxd(2.0f),
+	_radiusMaxd(3.0f),
+	_currTime(-1.0), _currTimestep(1.),
+	_initTimeScale(1.), 
+	_initPartOffset(0.), _initPartScale(1.),
+	_initLastPartOffset(0.), _initLastPartScale(1.),
+	_initMirror(""),
+	_fluidSpacing(1.), _kernelWeight(-1.),
+	_charLength(1.), _charLengthInv(1.),
+	mvCPSStart(-10000.), mvCPSEnd(10000.),
+	mCPSWidth(0.1), mCPSTimestep(0.02), // was 0.05
+	mCPSTimeStart(0.), mCPSTimeEnd(0.5), mCPSWeightFac(1.),
+	mDebugInit(0)
+{
+	_radiusAtt = 0.15f;
+	_radiusVel = 0.15f;
+	_radiusMinMaxd = 0.16f;
+	_radiusMaxd = 0.3;
+
+	_influenceAttraction = 0.f;
+	_influenceTangential = 0.f;
+	_influenceVelocity = 0.f;
+	// 3d tests */
+}
+
+
+ 
+ControlParticles::~ControlParticles() {
+	// nothing to do...
+}
+
+LbmFloat ControlParticles::getControlTimStart() {
+	if(mPartSets.size()>0) { return mPartSets[0].time; }
+	return -1000.;
+}
+LbmFloat ControlParticles::getControlTimEnd() {
+	if(mPartSets.size()>0) { return mPartSets[mPartSets.size()-1].time; }
+	return -1000.;
+}
+
+// calculate for delta t
+void ControlParticles::setInfluenceVelocity(LbmFloat set, LbmFloat dt) {
+	const LbmFloat dtInter = 0.01;
+	LbmFloat facFv = 1.-set; //cparts->getInfluenceVelocity();
+	// mLevel[mMaxRefine].timestep
+	LbmFloat facNv = (LbmFloat)( 1.-pow( (double)facFv, (double)(dt/dtInter)) );
+	//errMsg("vwcalc","ts:"<<dt<< " its:"<<(dt/dtInter) <<" fv"<<facFv<<" nv"<<facNv<<" test:"<< pow( (double)(1.-facNv),(double)(dtInter/dt))	);
+	_influenceVelocity = facNv;
+}
+
+int ControlParticles::initExampleSet()
+{
+	// unused
+	return 0;
+}
+
+int ControlParticles::getTotalSize()
+{
+	int s=0;
+	for(int i=0; i<(int)mPartSets.size(); i++) {
+		s+= mPartSets[i].particles.size();
+	}
+	return s;
+}
+
+// --------------------------------------------------------------------------
+// load positions & timing from text file
+// WARNING - make sure file has unix format, no win/dos linefeeds...
+#define LINE_LEN 100
+int ControlParticles::initFromTextFile(string filename)
+{
+	/*
+	const bool debugRead = false;
+	char line[LINE_LEN];
+	line[LINE_LEN-1] = '\0';
+	mPartSets.clear();
+	if(filename.size()<2) return 0;
+
+	// HACK , use "cparts" suffix as old
+	// e.g. "cpart2" as new
+	if(filename[ filename.size()-1 ]=='s') {
+		return initFromTextFileOld(filename);
+	}
+
+	FILE *infile = fopen(filename.c_str(), "r");
+	if(!infile) {
+		errMsg("ControlParticles::initFromTextFile","unable to open '"<<filename<<"' " );
+		// try to open as gz sequence
+		if(initFromBinaryFile(filename)) { return 1; }
+		// try mesh MVCM generation
+		if(initFromMVCMesh(filename)) { return 1; }
+		// failed...
+		return 0;
+	}
+
+	int haveNo = false;
+	int haveScale = false;
+	int haveTime = false;
+	int noParts = -1;
+	int partCnt = 0;
+	int setCnt = 0;
+	//ControlParticle p; p.reset();
+	// scale times by constant factor while reading
+	LbmFloat timeScale= 1.0;
+	int lineCnt = 0;
+	bool abortParse = false;
+#define LASTCP mPartSets[setCnt].particles[ mPartSets[setCnt].particles.size()-1 ]
+
+	while( (!feof(infile)) && (!abortParse)) {
+		lineCnt++;
+		fgets(line, LINE_LEN, infile);
+
+		//if(debugRead) printf("\nDEBUG%d r '%s'\n",lineCnt, line);
+		if(!line) continue;
+		size_t len = strlen(line);
+
+		// skip empty lines and comments (#,//)
+		if(len<1) continue;
+		if( (line[0]=='#') || (line[0]=='\n') ) continue;
+		if((len>1) && (line[0]=='/' && line[1]=='/')) continue;
+
+		// debug remove newline
+		if((len>=1)&&(line[len-1]=='\n')) line[len-1]='\0';
+
+		switch(line[0]) {
+
+		case 'N': { // total number of particles, more for debugging...
+			noParts = atoi(line+2);
+			if(noParts<=0) {
+				errMsg("ControlParticles::initFromTextFile","file '"<<filename<<"' - invalid no of particles "<<noParts);
+				mPartSets.clear(); fclose(infile); return 0;
+			}
+			if(debugRead) printf("CPDEBUG%d no parts '%d'\n",lineCnt, noParts );
+			haveNo = true;
+			} break;
+
+		case 'T': { // global time scale
+			timeScale *= (LbmFloat)atof(line+2);
+			if(debugRead) printf("ControlParticles::initFromTextFile - line %d , set timescale '%f', org %f\n",lineCnt, timeScale , _initTimeScale);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list