2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-07-25 18:57:16 +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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-07-25 18:57:16 +00:00
|
|
|
*
|
|
|
|
|
* 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 *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/fluidsim.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2012-03-27 00:17:57 +00:00
|
|
|
// headers for fluidsim bobj meshes
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <zlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
2009-06-22 18:19:18 +00:00
|
|
|
|
2008-07-25 18:57:16 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2009-07-02 19:41:31 +00:00
|
|
|
#include "DNA_object_fluidsim.h"
|
2012-10-23 03:38:26 +00:00
|
|
|
#include "DNA_object_force.h" // for pointcache
|
2009-07-02 19:41:31 +00:00
|
|
|
#include "DNA_object_types.h"
|
2008-07-25 18:57:16 +00:00
|
|
|
#include "DNA_particle_types.h"
|
|
|
|
|
#include "DNA_scene_types.h" // N_T
|
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2008-07-25 18:57:16 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2008-07-25 18:57:16 +00:00
|
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
|
#include "BKE_DerivedMesh.h"
|
|
|
|
|
#include "BKE_fluidsim.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_modifier.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2008-07-25 18:57:16 +00:00
|
|
|
/* ************************* fluidsim bobj file handling **************************** */
|
|
|
|
|
|
2011-05-09 06:53:39 +00:00
|
|
|
|
2008-07-25 18:57:16 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
|
// file handling
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
void initElbeemMesh(struct Scene *scene, struct Object *ob,
|
2012-10-23 03:38:26 +00:00
|
|
|
int *numVertices, float **vertices,
|
|
|
|
|
int *numTriangles, int **triangles,
|
|
|
|
|
int useGlobalCoords, int modifierIndex)
|
2008-07-25 18:57:16 +00:00
|
|
|
{
|
|
|
|
|
DerivedMesh *dm = NULL;
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
MFace *mface;
|
2012-10-23 03:38:26 +00:00
|
|
|
int countTris = 0, i, totvert, totface;
|
2008-07-25 18:57:16 +00:00
|
|
|
float *verts;
|
|
|
|
|
int *tris;
|
|
|
|
|
|
2009-01-04 14:14:06 +00:00
|
|
|
dm = mesh_create_derived_index_render(scene, ob, CD_MASK_BAREMESH, modifierIndex);
|
2012-05-04 08:00:55 +00:00
|
|
|
|
|
|
|
|
DM_ensure_tessface(dm);
|
2008-07-25 18:57:16 +00:00
|
|
|
|
|
|
|
|
mvert = dm->getVertArray(dm);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
mface = dm->getTessFaceArray(dm);
|
2008-07-25 18:57:16 +00:00
|
|
|
totvert = dm->getNumVerts(dm);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
totface = dm->getNumTessFaces(dm);
|
2008-07-25 18:57:16 +00:00
|
|
|
|
|
|
|
|
*numVertices = totvert;
|
2012-10-23 03:38:26 +00:00
|
|
|
verts = MEM_callocN(totvert * 3 * sizeof(float), "elbeemmesh_vertices");
|
|
|
|
|
for (i = 0; i < totvert; i++) {
|
|
|
|
|
copy_v3_v3(&verts[i * 3], mvert[i].co);
|
|
|
|
|
if (useGlobalCoords) { mul_m4_v3(ob->obmat, &verts[i * 3]); }
|
2008-07-25 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
*vertices = verts;
|
|
|
|
|
|
2012-10-23 03:38:26 +00:00
|
|
|
for (i = 0; i < totface; i++) {
|
2008-07-25 18:57:16 +00:00
|
|
|
countTris++;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (mface[i].v4) { countTris++; }
|
2008-07-25 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
*numTriangles = countTris;
|
2012-10-23 03:38:26 +00:00
|
|
|
tris = MEM_callocN(countTris * 3 * sizeof(int), "elbeemmesh_triangles");
|
2008-07-25 18:57:16 +00:00
|
|
|
countTris = 0;
|
2012-10-23 03:38:26 +00:00
|
|
|
for (i = 0; i < totface; i++) {
|
2008-07-25 18:57:16 +00:00
|
|
|
int face[4];
|
|
|
|
|
face[0] = mface[i].v1;
|
|
|
|
|
face[1] = mface[i].v2;
|
|
|
|
|
face[2] = mface[i].v3;
|
|
|
|
|
face[3] = mface[i].v4;
|
|
|
|
|
|
2012-10-23 03:38:26 +00:00
|
|
|
tris[countTris * 3 + 0] = face[0];
|
|
|
|
|
tris[countTris * 3 + 1] = face[1];
|
|
|
|
|
tris[countTris * 3 + 2] = face[2];
|
2008-07-25 18:57:16 +00:00
|
|
|
countTris++;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (face[3]) {
|
2012-10-23 03:38:26 +00:00
|
|
|
tris[countTris * 3 + 0] = face[0];
|
|
|
|
|
tris[countTris * 3 + 1] = face[2];
|
|
|
|
|
tris[countTris * 3 + 2] = face[3];
|
2008-07-25 18:57:16 +00:00
|
|
|
countTris++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*triangles = tris;
|
|
|
|
|
|
|
|
|
|
dm->release(dm);
|
|
|
|
|
}
|
2012-05-04 08:00:55 +00:00
|
|
|
|