|
Blender
V2.59
|
00001 /* 00002 * $Id: fluidsim.c 35247 2011-02-27 20:40:57Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) Blender Foundation 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #include <stddef.h> 00036 #include "BLI_storage.h" /* _LARGEFILE_SOURCE */ 00037 00038 #include "MEM_guardedalloc.h" 00039 00040 #include "DNA_mesh_types.h" 00041 #include "DNA_meshdata_types.h" 00042 #include "DNA_object_fluidsim.h" 00043 #include "DNA_object_force.h" // for pointcache 00044 #include "DNA_object_types.h" 00045 #include "DNA_particle_types.h" 00046 #include "DNA_scene_types.h" // N_T 00047 00048 #include "BLI_math.h" 00049 #include "BLI_blenlib.h" 00050 #include "BLI_utildefines.h" 00051 00052 #include "BKE_cdderivedmesh.h" 00053 #include "BKE_customdata.h" 00054 #include "BKE_DerivedMesh.h" 00055 #include "BKE_fluidsim.h" 00056 #include "BKE_global.h" 00057 #include "BKE_modifier.h" 00058 #include "BKE_mesh.h" 00059 00060 00061 // headers for fluidsim bobj meshes 00062 #include <stdlib.h> 00063 #include "LBM_fluidsim.h" 00064 #include <zlib.h> 00065 #include <string.h> 00066 #include <stdio.h> 00067 00068 /* ************************* fluidsim bobj file handling **************************** */ 00069 00070 00071 //------------------------------------------------------------------------------- 00072 // file handling 00073 //------------------------------------------------------------------------------- 00074 00075 void initElbeemMesh(struct Scene *scene, struct Object *ob, 00076 int *numVertices, float **vertices, 00077 int *numTriangles, int **triangles, 00078 int useGlobalCoords, int modifierIndex) 00079 { 00080 DerivedMesh *dm = NULL; 00081 MVert *mvert; 00082 MFace *mface; 00083 int countTris=0, i, totvert, totface; 00084 float *verts; 00085 int *tris; 00086 00087 dm = mesh_create_derived_index_render(scene, ob, CD_MASK_BAREMESH, modifierIndex); 00088 //dm = mesh_create_derived_no_deform(ob,NULL); 00089 00090 mvert = dm->getVertArray(dm); 00091 mface = dm->getFaceArray(dm); 00092 totvert = dm->getNumVerts(dm); 00093 totface = dm->getNumFaces(dm); 00094 00095 *numVertices = totvert; 00096 verts = MEM_callocN( totvert*3*sizeof(float), "elbeemmesh_vertices"); 00097 for(i=0; i<totvert; i++) { 00098 VECCOPY( &verts[i*3], mvert[i].co); 00099 if(useGlobalCoords) { mul_m4_v3(ob->obmat, &verts[i*3]); } 00100 } 00101 *vertices = verts; 00102 00103 for(i=0; i<totface; i++) { 00104 countTris++; 00105 if(mface[i].v4) { countTris++; } 00106 } 00107 *numTriangles = countTris; 00108 tris = MEM_callocN( countTris*3*sizeof(int), "elbeemmesh_triangles"); 00109 countTris = 0; 00110 for(i=0; i<totface; i++) { 00111 int face[4]; 00112 face[0] = mface[i].v1; 00113 face[1] = mface[i].v2; 00114 face[2] = mface[i].v3; 00115 face[3] = mface[i].v4; 00116 00117 tris[countTris*3+0] = face[0]; 00118 tris[countTris*3+1] = face[1]; 00119 tris[countTris*3+2] = face[2]; 00120 countTris++; 00121 if(face[3]) { 00122 tris[countTris*3+0] = face[0]; 00123 tris[countTris*3+1] = face[2]; 00124 tris[countTris*3+2] = face[3]; 00125 countTris++; 00126 } 00127 } 00128 *triangles = tris; 00129 00130 dm->release(dm); 00131 }