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