2 FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
3 Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
30 #include "mesh_info.h"
38 #define VERT_DELTA 10000
39 #define EDGE_DELTA 20000
40 #define FACE_DELTA 30000
60 char type; // 0 = vert, 1 = face
61 std::vector<PlyProperty> prop_list;
64 class Mesh : public GeomX, public MeshInfo {
68 //virtual objType GetType () { return 'mesh'; }
70 // Distributed functions
71 //virtual void onUpdate ( objData dat, mint::Event* e );
76 void DrawGL ( float* viewmat );
77 void DrawFaceGL ( float* viewmat );
79 Mesh& operator= ( Mesh& op2 );
82 void LoadPly ( char* fname, float s );
83 void AddPlyElement ( char typ, int n );
84 void AddPlyProperty ( char typ, std::string name );
87 int FindPlyElem ( char typ );
88 int FindPlyProp ( int elem, std::string name );
90 // Vertex, Face, Edge functions
91 xref AddVert (float x, float y, float z ) { return (this->*m_AddVertFunc) (x, y, z); }
92 xref AddFaceFast (xref v1, xref v2, xref v3 ) { return (this->*m_AddFaceFast3Func) (v1, v2, v3); }
93 xref AddFaceFast (xref v1, xref v2, xref v3, xref v4 ) { return (this->*m_AddFaceFast4Func) (v1, v2, v3, v4); }
94 xref (Mesh::*m_AddVertFunc) (float x, float y, float z);
95 xref (Mesh::*m_AddFaceFast3Func) (xref v1, xref v2, xref v3);
96 xref (Mesh::*m_AddFaceFast4Func) (xref v1, xref v2, xref v3, xref v4);
98 int NumVert () { return NumElem ( m_Vbuf ); }
99 int NumEdge () { return NumElem ( m_Ebuf ); }
100 int NumFace () { return NumElem ( m_Fbuf ); }
102 void IncFace ( int n ) { m_CurrF += n; }
105 // FVF - Face-Vertex-Face Mesh
109 xref AddVertFVF ( float x, float y, float z );
110 xref AddFaceFast3FVF ( xref v1, xref v2, xref v3 );
111 xref AddFaceFast4FVF ( xref v1, xref v2, xref v3, xref v4 );
112 VertFVF* GetVertFVF ( int n ) { return (VertFVF*) (mBuf[m_Vbuf].data + n*mBuf[m_Vbuf].stride); }
113 FaceFVF* GetFaceFVF ( int n ) { return (FaceFVF*) (mBuf[m_Fbuf].data + n*mBuf[m_Fbuf].stride); }
114 void* GetExtraFVF ( VertFVF* v ) { return ((char*) v + miBufSize[(int) FVF][BVert]); }
115 void ComputeNormalsFVF ();
116 void SetNormalFVF ( int n, Vector3DF norm );
117 void SetColorFVF ( int n, DWORD clr );
118 void SmoothFVF ( int iter );
120 void DrawVertsFVF ( float* viewmat, int a, int b );
121 void DrawFacesFVF ( float* viewmat, int a, int b );
123 // CM - Connected Mesh
126 xref AddVertCM ( float x, float y, float z );
127 xref AddFaceFast3CM ( xref v1, xref v2, xref v3 );
128 xref AddFaceFast4CM ( xref v1, xref v2, xref v3, xref v4 );
129 xref AddEdgeCM ( xref v1, xref v2 );
130 xref FindEdgeCM ( xref v1, xref v2 );
131 VertCM* GetVertCM ( int n ) { return (VertCM*) (mBuf[m_Vbuf].data + n*mBuf[m_Vbuf].stride); }
132 EdgeCM* GetEdgeCM ( int n ) { return (EdgeCM*) (mBuf[m_Ebuf].data + n*mBuf[m_Ebuf].stride); }
133 FaceCM* GetFaceCM ( int n ) { return (FaceCM*) (mBuf[m_Fbuf].data + n*mBuf[m_Fbuf].stride); }
134 void* GetExtraCM ( VertCM* v ) { return ((char*) v + miBufSize[(int) CM][BVert] ); }
136 void DrawVertsCM ( float* viewmat, int a, int b );
137 void DrawFacesCM ( float* viewmat, int a, int b );
138 void DrawEdgesCM ( float* viewmat, int a, int b );
140 MFormat GetMeshBufs ( char& v, char& e, char& f ) { v = m_Vbuf; e = m_Ebuf; f = m_Fbuf; return m_Mform; }
143 MFormat m_Mform; // Mesh format
150 std::vector< PlyElement* > m_Ply;
154 static bool mbInitStatic;