| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  |  * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2005 by the Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Daniel Dunbar | 
					
						
							|  |  |  |  *                 Ton Roosendaal, | 
					
						
							|  |  |  |  *                 Ben Batt, | 
					
						
							|  |  |  |  *                 Brecht Van Lommel, | 
					
						
							|  |  |  |  *                 Campbell Barton | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 13:57:17 +00:00
										 |  |  | /** \file blender/modifiers/intern/MOD_fluidsim_util.c
 | 
					
						
							|  |  |  |  *  \ingroup modifiers | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 16:15:38 +00:00
										 |  |  | #include <stddef.h>
 | 
					
						
							| 
									
										
										
										
											2010-04-12 02:56:41 +00:00
										 |  |  | #include <zlib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 22:33:43 +00:00
										 |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							|  |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							|  |  |  | #include "DNA_object_fluidsim.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 01:26:56 +00:00
										 |  |  | #include "BLI_blenlib.h"
 | 
					
						
							|  |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-12 01:26:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | #include "BKE_fluidsim.h" /* ensure definitions here match */
 | 
					
						
							| 
									
										
										
										
											2010-04-12 01:26:56 +00:00
										 |  |  | #include "BKE_cdderivedmesh.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-18 06:41:16 +00:00
										 |  |  | #include "BKE_global.h" /* G.main->name only */
 | 
					
						
							| 
									
										
										
										
											2010-04-12 00:36:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | #include "MOD_fluidsim_util.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-12 00:36:50 +00:00
										 |  |  | #include "MOD_modifiertypes.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-12 22:33:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-12 00:36:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | // headers for fluidsim bobj meshes
 | 
					
						
							|  |  |  | #include "LBM_fluidsim.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-29 23:56:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | void fluidsim_init(FluidsimModifierData *fluidmd) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-29 23:56:07 +00:00
										 |  |  | #ifdef WITH_MOD_FLUID
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (fluidmd) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		FluidsimSettings *fss = MEM_callocN(sizeof(FluidsimSettings), "fluidsimsettings"); | 
					
						
							| 
									
										
										
										
											2011-11-20 14:38:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fluidmd->fss = fss; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		if (!fss) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		fss->fmd = fluidmd; | 
					
						
							|  |  |  | 		fss->type = OB_FLUIDSIM_ENABLE; | 
					
						
							| 
									
										
										
										
											2013-05-21 11:37:42 +00:00
										 |  |  | 		fss->threads = 0; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fss->show_advancedoptions = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		fss->resolutionxyz = 65; | 
					
						
							|  |  |  | 		fss->previewresxyz = 45; | 
					
						
							|  |  |  | 		fss->realsize = 0.5; | 
					
						
							|  |  |  | 		fss->guiDisplayMode = 2; // preview
 | 
					
						
							|  |  |  | 		fss->renderDisplayMode = 3; // render
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		fss->viscosityValue = 1.0; | 
					
						
							|  |  |  | 		fss->viscosityExponent = 6; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-06-12 23:51:30 +00:00
										 |  |  | 		fss->grav[0] = 0.0; | 
					
						
							|  |  |  | 		fss->grav[1] = 0.0; | 
					
						
							|  |  |  | 		fss->grav[2] = -9.81; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fss->animStart = 0.0;  | 
					
						
							|  |  |  | 		fss->animEnd = 4.0; | 
					
						
							| 
									
										
										
										
											2012-01-22 03:42:49 +00:00
										 |  |  | 		fss->animRate = 1.0; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fss->gstar = 0.005; // used as normgstar
 | 
					
						
							|  |  |  | 		fss->maxRefine = -1; | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 		/* maxRefine is set according to resolutionxyz during bake */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 		/* fluid/inflow settings
 | 
					
						
							|  |  |  | 		 * fss->iniVel --> automatically set to 0 */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-22 10:04:28 +00:00
										 |  |  | 		modifier_path_init(fss->surfdataPath, sizeof(fss->surfdataPath), "cache_fluid"); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 		/* first init of bounding box */ | 
					
						
							|  |  |  | 		/* no bounding box needed */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* todo - reuse default init from elbeem! */ | 
					
						
							| 
									
										
										
										
											2011-06-12 23:51:30 +00:00
										 |  |  | 		fss->typeFlags = OB_FSBND_PARTSLIP | OB_FSSG_NOOBS; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fss->domainNovecgen = 0; | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 		fss->volumeInitType = 1; /* volume */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fss->partSlipValue = 0.2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		fss->generateTracers = 0; | 
					
						
							|  |  |  | 		fss->generateParticles = 0.0; | 
					
						
							|  |  |  | 		fss->surfaceSmoothing = 1.0; | 
					
						
							|  |  |  | 		fss->surfaceSubdivs = 0.0; | 
					
						
							|  |  |  | 		fss->particleInfSize = 0.0; | 
					
						
							|  |  |  | 		fss->particleInfAlpha = 0.0; | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* init fluid control settings */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fss->attractforceStrength = 0.2; | 
					
						
							|  |  |  | 		fss->attractforceRadius = 0.75; | 
					
						
							|  |  |  | 		fss->velocityforceStrength = 0.2; | 
					
						
							|  |  |  | 		fss->velocityforceRadius = 0.75; | 
					
						
							|  |  |  | 		fss->cpsTimeStart = fss->animStart; | 
					
						
							|  |  |  | 		fss->cpsTimeEnd = fss->animEnd; | 
					
						
							|  |  |  | 		fss->cpsQuality = 10.0; // 1.0 / 10.0 => means 0.1 width
 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/*
 | 
					
						
							| 
									
										
										
										
											2012-03-09 18:28:30 +00:00
										 |  |  | 		 * BAD TODO: this is done in buttons_object.c in the moment | 
					
						
							|  |  |  | 		 * Mesh *mesh = ob->data; | 
					
						
							|  |  |  | 		 * // calculate bounding box
 | 
					
						
							|  |  |  | 		 * fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize); | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 		fss->meshVelocities = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		fss->lastgoodframe = -1; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		fss->flag |= OB_FLUIDSIM_ACTIVE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-10-16 14:32:17 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	(void)fluidmd; /* unused */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void fluidsim_free(FluidsimModifierData *fluidmd) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-08 00:23:28 +00:00
										 |  |  | 	if (fluidmd && fluidmd->fss) { | 
					
						
							|  |  |  | 		if (fluidmd->fss->meshVelocities) { | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 			MEM_freeN(fluidmd->fss->meshVelocities); | 
					
						
							|  |  |  | 			fluidmd->fss->meshVelocities = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		MEM_freeN(fluidmd->fss); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-10-16 14:32:17 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-29 23:56:07 +00:00
										 |  |  | #ifdef WITH_MOD_FLUID
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | /* read .bobj.gz file into a fluidsimDerivedMesh struct */ | 
					
						
							| 
									
										
										
										
											2012-02-03 01:30:21 +00:00
										 |  |  | static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_example) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-29 15:47:02 +00:00
										 |  |  | 	int wri = 0, i; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	int gotBytes; | 
					
						
							|  |  |  | 	gzFile gzf; | 
					
						
							|  |  |  | 	int numverts = 0, numfaces = 0; | 
					
						
							|  |  |  | 	DerivedMesh *dm = NULL; | 
					
						
							| 
									
										
										
										
											2012-02-02 20:58:56 +00:00
										 |  |  | 	MPoly *mp; | 
					
						
							|  |  |  | 	MLoop *ml; | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 	MVert *mv; | 
					
						
							|  |  |  | 	short *normals, *no_s; | 
					
						
							|  |  |  | 	float no[3]; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-03 01:30:21 +00:00
										 |  |  | 	const short mp_mat_nr = mp_example->mat_nr; | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	const char mp_flag =   mp_example->flag; | 
					
						
							| 
									
										
										
										
											2012-02-02 23:58:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* ------------------------------------------------
 | 
					
						
							|  |  |  | 	 * get numverts + numfaces first | 
					
						
							|  |  |  | 	 * ------------------------------------------------ */ | 
					
						
							| 
									
										
										
										
											2012-03-20 02:17:37 +00:00
										 |  |  | 	gzf = BLI_gzopen(filename, "rb"); | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (!gzf) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* read numverts */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	gotBytes = gzread(gzf, &wri, sizeof(wri)); | 
					
						
							|  |  |  | 	numverts = wri; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* skip verts */ | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 	gotBytes = gzseek(gzf, numverts * 3 * sizeof(float), SEEK_CUR) != -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* read number of normals */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (gotBytes) | 
					
						
							| 
									
										
										
										
											2011-01-13 10:10:13 +00:00
										 |  |  | 		gotBytes = gzread(gzf, &wri, sizeof(wri)); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* skip normals */ | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 	gotBytes = gzseek(gzf, numverts * 3 * sizeof(float), SEEK_CUR) != -1; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* get no. of triangles */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (gotBytes) | 
					
						
							| 
									
										
										
										
											2011-01-13 10:10:13 +00:00
										 |  |  | 		gotBytes = gzread(gzf, &wri, sizeof(wri)); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	numfaces = wri; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 19:09:01 +00:00
										 |  |  | 	gzclose(gzf); | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* ------------------------------------------------ */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (!numfaces || !numverts || !gotBytes) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-20 02:17:37 +00:00
										 |  |  | 	gzf = BLI_gzopen(filename, "rb"); | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (!gzf) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 20:58:56 +00:00
										 |  |  | 	dm = CDDM_new(numverts, 0, 0, numfaces * 3, numfaces); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (!dm) { | 
					
						
							| 
									
										
										
										
											2012-03-11 19:09:01 +00:00
										 |  |  | 		gzclose(gzf); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* read numverts */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	gotBytes = gzread(gzf, &wri, sizeof(wri)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* read vertex position from file */ | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 	mv = CDDM_get_verts(dm); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	for (i = 0; i < numverts; i++, mv++) | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 		gotBytes = gzread(gzf, mv->co, sizeof(float) * 3); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* should be the same as numverts */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	gotBytes = gzread(gzf, &wri, sizeof(wri)); | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (wri != numverts) { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		if (dm) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			dm->release(dm); | 
					
						
							| 
									
										
										
										
											2012-03-11 19:09:01 +00:00
										 |  |  | 		gzclose(gzf); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	normals = MEM_callocN(sizeof(short) * numverts * 3, "fluid_tmp_normals"); | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (!normals) { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		if (dm) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			dm->release(dm); | 
					
						
							| 
									
										
										
										
											2012-03-11 19:09:01 +00:00
										 |  |  | 		gzclose(gzf); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* read normals from file (but don't save them yet) */ | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	for (i = numverts, no_s = normals; i > 0; i--, no_s += 3) { | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 		gotBytes = gzread(gzf, no, sizeof(float) * 3); | 
					
						
							|  |  |  | 		normal_float_to_short_v3(no_s, no); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* read no. of triangles */ | 
					
						
							|  |  |  | 	gotBytes = gzread(gzf, &wri, sizeof(wri)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	if (wri != numfaces) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		printf("Fluidsim: error in reading data from file.\n"); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		if (dm) | 
					
						
							| 
									
										
										
										
											2010-11-24 10:56:15 +00:00
										 |  |  | 			dm->release(dm); | 
					
						
							| 
									
										
										
										
											2012-03-11 19:09:01 +00:00
										 |  |  | 		gzclose(gzf); | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 		MEM_freeN(normals); | 
					
						
							| 
									
										
										
										
											2010-11-24 10:56:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* read triangles from file */ | 
					
						
							| 
									
										
										
										
											2012-02-02 20:58:56 +00:00
										 |  |  | 	mp = CDDM_get_polys(dm); | 
					
						
							|  |  |  | 	ml = CDDM_get_loops(dm); | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	for (i = 0; i < numfaces; i++, mp++, ml += 3) { | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 		int face[3]; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-13 11:06:12 +00:00
										 |  |  | 		gotBytes = gzread(gzf, face, sizeof(int) * 3); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 23:58:46 +00:00
										 |  |  | 		/* initialize from existing face */ | 
					
						
							| 
									
										
										
										
											2012-02-03 01:30:21 +00:00
										 |  |  | 		mp->mat_nr = mp_mat_nr; | 
					
						
							|  |  |  | 		mp->flag =   mp_flag; | 
					
						
							| 
									
										
										
										
											2012-02-02 23:58:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 20:58:56 +00:00
										 |  |  | 		mp->loopstart = i * 3; | 
					
						
							|  |  |  | 		mp->totloop = 3; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ml[0].v = face[0]; | 
					
						
							|  |  |  | 		ml[1].v = face[1]; | 
					
						
							|  |  |  | 		ml[2].v = face[2]; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 19:09:01 +00:00
										 |  |  | 	gzclose(gzf); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 20:58:56 +00:00
										 |  |  | 	CDDM_calc_edges(dm); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CDDM_apply_vert_normals(dm, (short (*)[3])normals); | 
					
						
							|  |  |  | 	MEM_freeN(normals); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-20 13:25:54 +00:00
										 |  |  | 	// CDDM_calc_normals(result);
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	return dm; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:29:01 +00:00
										 |  |  | void fluid_get_bb(MVert *mvert, int totvert, float obmat[4][4], | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  |                   /*RET*/ float start[3], /*RET*/ float size[3]) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	float bbsx = 0.0, bbsy = 0.0, bbsz = 0.0; | 
					
						
							|  |  |  | 	float bbex = 1.0, bbey = 1.0, bbez = 1.0; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 	float vec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (totvert == 0) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		zero_v3(start); | 
					
						
							|  |  |  | 		zero_v3(size); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 01:26:56 +00:00
										 |  |  | 	copy_v3_v3(vec, mvert[0].co); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	mul_m4_v3(obmat, vec); | 
					
						
							|  |  |  | 	bbsx = vec[0]; bbsy = vec[1]; bbsz = vec[2]; | 
					
						
							|  |  |  | 	bbex = vec[0]; bbey = vec[1]; bbez = vec[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	for (i = 1; i < totvert; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-12 01:26:56 +00:00
										 |  |  | 		copy_v3_v3(vec, mvert[i].co); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		mul_m4_v3(obmat, vec); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 		if (vec[0] < bbsx) { bbsx = vec[0]; } | 
					
						
							|  |  |  | 		if (vec[1] < bbsy) { bbsy = vec[1]; } | 
					
						
							|  |  |  | 		if (vec[2] < bbsz) { bbsz = vec[2]; } | 
					
						
							|  |  |  | 		if (vec[0] > bbex) { bbex = vec[0]; } | 
					
						
							|  |  |  | 		if (vec[1] > bbey) { bbey = vec[1]; } | 
					
						
							|  |  |  | 		if (vec[2] > bbez) { bbez = vec[2]; } | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* return values... */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (start) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		start[0] = bbsx; | 
					
						
							|  |  |  | 		start[1] = bbsy; | 
					
						
							|  |  |  | 		start[2] = bbsz; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (size) { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 		size[0] = bbex - bbsx; | 
					
						
							|  |  |  | 		size[1] = bbey - bbsy; | 
					
						
							|  |  |  | 		size[2] = bbez - bbsz; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //-------------------------------------------------------------------------------
 | 
					
						
							|  |  |  | // old interface
 | 
					
						
							|  |  |  | //-------------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Mesh *mesh; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	value[0] = '\0'; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (ob->type == OB_MESH) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		/* use mesh bounding box and object scaling */ | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 		mesh = ob->data; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize); | 
					
						
							| 
									
										
										
										
											2012-04-29 15:47:02 +00:00
										 |  |  | 		elbeemEstimateMemreq(fss->resolutionxyz, fss->bbSize[0], fss->bbSize[1], fss->bbSize[2], fss->maxRefine, value); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */ | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int wri, i, j; | 
					
						
							|  |  |  | 	float wrf; | 
					
						
							|  |  |  | 	gzFile gzf; | 
					
						
							|  |  |  | 	FluidsimSettings *fss = fluidmd->fss; | 
					
						
							|  |  |  | 	int len = strlen(filename); | 
					
						
							|  |  |  | 	int totvert = dm->getNumVerts(dm); | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 	FluidVertexVelocity *velarray = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* mesh and vverts have to be valid from loading... */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (fss->meshVelocities) | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 		MEM_freeN(fss->meshVelocities); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (len < 7) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	if (fss->domainNovecgen > 0) return; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	fss->meshVelocities = MEM_callocN(sizeof(FluidVertexVelocity) * dm->getNumVerts(dm), "Fluidsim_velocities"); | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 	fss->totvert = totvert; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 	velarray = fss->meshVelocities; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* .bobj.gz, correct filename
 | 
					
						
							|  |  |  | 	 * 87654321 */ | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	filename[len - 6] = 'v'; | 
					
						
							|  |  |  | 	filename[len - 5] = 'e'; | 
					
						
							|  |  |  | 	filename[len - 4] = 'l'; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-20 02:17:37 +00:00
										 |  |  | 	gzf = BLI_gzopen(filename, "rb"); | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (!gzf) { | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 		MEM_freeN(fss->meshVelocities); | 
					
						
							|  |  |  | 		fss->meshVelocities = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-29 17:11:40 +00:00
										 |  |  | 	gzread(gzf, &wri, sizeof(wri)); | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (wri != totvert) { | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 		MEM_freeN(fss->meshVelocities); | 
					
						
							|  |  |  | 		fss->meshVelocities = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	for (i = 0; i < totvert; i++) { | 
					
						
							|  |  |  | 		for (j = 0; j < 3; j++) { | 
					
						
							| 
									
										
										
										
											2012-04-29 17:11:40 +00:00
										 |  |  | 			gzread(gzf, &wrf, sizeof(wrf)); | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 			velarray[i].vel[j] = wrf; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gzclose(gzf); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | static DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, | 
					
						
							|  |  |  |                                         FluidsimModifierData *fluidmd, int framenr, int useRenderParams) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int displaymode = 0; | 
					
						
							| 
									
										
										
										
											2012-11-23 05:00:07 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	int curFrame = framenr /* - 1 */ /*scene->r.sfra*/; /* start with 0 at start frame */  | 
					
						
							|  |  |  | 	/*  why start with 0 as start frame?? Animations + time are frozen for frame 0 anyway. (See physics_fluid.c for that. - DG */ | 
					
						
							|  |  |  | 	/* If we start with frame 0, we need to remap all animation channels, too, because they will all be 1 frame late if using frame-1! - DG */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-26 04:07:38 +00:00
										 |  |  | 	char targetFile[FILE_MAX]; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	FluidsimSettings *fss = fluidmd->fss; | 
					
						
							|  |  |  | 	DerivedMesh *dm = NULL; | 
					
						
							| 
									
										
										
										
											2012-02-02 20:58:56 +00:00
										 |  |  | 	MPoly *mpoly; | 
					
						
							| 
									
										
										
										
											2012-02-03 01:30:21 +00:00
										 |  |  | 	MPoly mp_example = {0}; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (!useRenderParams) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		displaymode = fss->guiDisplayMode; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		displaymode = fss->renderDisplayMode; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 14:38:11 +00:00
										 |  |  | 	switch (displaymode) { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 		case 1: | 
					
						
							|  |  |  | 			/* just display original object */ | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			/* use preview mesh */ | 
					
						
							|  |  |  | 			BLI_join_dirfile(targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_PREVIEW_OBJ_FNAME); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: /* 3 */ | 
					
						
							|  |  |  | 			/* 3. use final mesh */ | 
					
						
							|  |  |  | 			BLI_join_dirfile(targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_FINAL_OBJ_FNAME); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 15:58:26 +00:00
										 |  |  | 	/* offset baked frame */ | 
					
						
							|  |  |  | 	curFrame += fss->frameOffset; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 14:38:11 +00:00
										 |  |  | 	BLI_path_abs(targetFile, modifier_path_relbase(ob)); | 
					
						
							|  |  |  | 	BLI_path_frame(targetFile, curFrame, 0); // fixed #frame-no
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* assign material + flags to new dm
 | 
					
						
							|  |  |  | 	 * if there's no faces in original dm, keep materials and flags unchanged */ | 
					
						
							| 
									
										
										
										
											2012-02-03 01:30:21 +00:00
										 |  |  | 	mpoly = orgdm->getPolyArray(orgdm); | 
					
						
							|  |  |  | 	if (mpoly) { | 
					
						
							|  |  |  | 		mp_example = *mpoly; | 
					
						
							| 
									
										
										
										
											2012-02-02 23:58:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	/* else leave NULL'd */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-03 01:30:21 +00:00
										 |  |  | 	dm = fluidsim_read_obj(targetFile, &mp_example); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (!dm) { | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 		/* switch, abort background rendering when fluidsim mesh is missing */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 		if (G.background == 1) { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 			if (getenv(strEnvName2)) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				int elevel = atoi(getenv(strEnvName2)); | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 				if (elevel > 0) { | 
					
						
							|  |  |  | 					printf("Env. var %s set, fluid sim mesh '%s' not found, aborting render...\n", | 
					
						
							|  |  |  | 					       strEnvName2, targetFile); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 					exit(1); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 		/* display org. object upon failure which is in dm */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* load vertex velocities, if they exist...
 | 
					
						
							|  |  |  | 	 * TODO? use generate flag as loading flag as well? | 
					
						
							|  |  |  | 	 * warning, needs original .bobj.gz mesh loading filename */ | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	if (displaymode == 3) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		fluidsim_read_vel_cache(fluidmd, dm, targetFile); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		if (fss->meshVelocities) | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 			MEM_freeN(fss->meshVelocities); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-12 22:52:30 +00:00
										 |  |  | 		fss->meshVelocities = NULL; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return dm; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-10-29 23:56:07 +00:00
										 |  |  | #endif // WITH_MOD_FLUID
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-14 06:29:17 +00:00
										 |  |  | DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene, | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  |                                  Object *ob, | 
					
						
							|  |  |  |                                  DerivedMesh *dm, | 
					
						
							|  |  |  |                                  int useRenderParams, int UNUSED(isFinalCalc)) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-29 23:56:07 +00:00
										 |  |  | #ifdef WITH_MOD_FLUID
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	DerivedMesh *result = NULL; | 
					
						
							|  |  |  | 	int framenr; | 
					
						
							|  |  |  | 	FluidsimSettings *fss = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	framenr = (int)scene->r.cfra; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* only handle fluidsim domains */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (fluidmd && fluidmd->fss && (fluidmd->fss->type != OB_FLUIDSIM_DOMAIN)) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return dm; | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* sanity check */ | 
					
						
							| 
									
										
										
										
											2016-07-31 01:22:36 -04:00
										 |  |  | 	if (!fluidmd || !fluidmd->fss) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return dm; | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	fss = fluidmd->fss; | 
					
						
							| 
									
										
										
										
											2010-11-24 10:56:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* timescale not supported yet
 | 
					
						
							| 
									
										
										
										
											2012-10-26 04:14:10 +00:00
										 |  |  | 	 * clmd->sim_parms->timescale = timescale; */ | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* support reversing of baked fluid frames here */ | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 	if ((fss->flag & OB_FLUIDSIM_REVERSE) && (fss->lastgoodframe >= 0)) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		framenr = fss->lastgoodframe - framenr + 1; | 
					
						
							|  |  |  | 		CLAMP(framenr, 1, fss->lastgoodframe); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* try to read from cache */ | 
					
						
							| 
									
										
										
										
											2010-11-24 10:56:15 +00:00
										 |  |  | 	/* if the frame is there, fine, otherwise don't do anything */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if ((result = fluidsim_read_cache(ob, dm, fluidmd, framenr, useRenderParams))) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		return result; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return dm; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2010-10-16 14:32:17 +00:00
										 |  |  | 	/* unused */ | 
					
						
							|  |  |  | 	(void)fluidmd; | 
					
						
							|  |  |  | 	(void)scene; | 
					
						
							| 
									
										
										
										
											2011-11-27 23:41:01 +00:00
										 |  |  | 	(void)ob; | 
					
						
							| 
									
										
										
										
											2010-10-16 14:32:17 +00:00
										 |  |  | 	(void)dm; | 
					
						
							|  |  |  | 	(void)useRenderParams; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } |