TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VMAP::GroupModel Class Reference

#include <WorldModel.h>

Public Member Functions

 GroupModel ()
 
 GroupModel (const GroupModel &other)
 
 GroupModel (uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox &bound)
 
 ~GroupModel ()
 
void setMeshData (std::vector< G3D::Vector3 > &vert, std::vector< MeshTriangle > &tri)
 pass mesh data to object and create BIH. Passed vectors get get swapped with old geometry! More...
 
void setLiquidData (WmoLiquid *&liquid)
 
bool IntersectRay (const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
 
bool IsInsideObject (const G3D::Vector3 &pos, const G3D::Vector3 &down, float &z_dist) const
 
bool GetLiquidLevel (const G3D::Vector3 &pos, float &liqHeight) const
 
uint32 GetLiquidType () const
 
bool writeToFile (FILE *wf)
 
bool readFromFile (FILE *rf)
 
const G3D::AABoxGetBound () const
 
uint32 GetMogpFlags () const
 
uint32 GetWmoID () const
 
void getMeshData (std::vector< G3D::Vector3 > &outVertices, std::vector< MeshTriangle > &outTriangles, WmoLiquid *&liquid)
 

Protected Attributes

G3D::AABox iBound
 
uint32 iMogpFlags
 
uint32 iGroupWMOID
 
std::vector< G3D::Vector3vertices
 
std::vector< MeshTriangletriangles
 
BIH meshTree
 
WmoLiquidiLiquid
 

Detailed Description

holding additional info for WMO group files

Constructor & Destructor Documentation

VMAP::GroupModel::GroupModel ( )
inline
76 : iBound(), iMogpFlags(0), iGroupWMOID(0), iLiquid(NULL) { }
arena_t NULL
Definition: jemalloc_internal.h:624
G3D::AABox iBound
Definition: WorldModel.h:96
uint32 iMogpFlags
Definition: WorldModel.h:97
WmoLiquid * iLiquid
Definition: WorldModel.h:102
uint32 iGroupWMOID
Definition: WorldModel.h:98
VMAP::GroupModel::GroupModel ( const GroupModel other)
262  :
263  iBound(other.iBound), iMogpFlags(other.iMogpFlags), iGroupWMOID(other.iGroupWMOID),
264  vertices(other.vertices), triangles(other.triangles), meshTree(other.meshTree), iLiquid(nullptr)
265  {
266  if (other.iLiquid)
267  iLiquid = new WmoLiquid(*other.iLiquid);
268  }
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
BIH meshTree
Definition: WorldModel.h:101
G3D::AABox iBound
Definition: WorldModel.h:96
uint32 iMogpFlags
Definition: WorldModel.h:97
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99
WmoLiquid * iLiquid
Definition: WorldModel.h:102
uint32 iGroupWMOID
Definition: WorldModel.h:98
VMAP::GroupModel::GroupModel ( uint32  mogpFlags,
uint32  groupWMOID,
const G3D::AABox bound 
)
inline
78  :
79  iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(NULL) { }
arena_t NULL
Definition: jemalloc_internal.h:624
G3D::AABox iBound
Definition: WorldModel.h:96
uint32 iMogpFlags
Definition: WorldModel.h:97
WmoLiquid * iLiquid
Definition: WorldModel.h:102
uint32 iGroupWMOID
Definition: WorldModel.h:98
VMAP::GroupModel::~GroupModel ( )
inline
80 { delete iLiquid; }
WmoLiquid * iLiquid
Definition: WorldModel.h:102

Member Function Documentation

const G3D::AABox& VMAP::GroupModel::GetBound ( ) const
inline
91 { return iBound; }
G3D::AABox iBound
Definition: WorldModel.h:96

+ Here is the caller graph for this function:

bool VMAP::GroupModel::GetLiquidLevel ( const G3D::Vector3 pos,
float &  liqHeight 
) const
407  {
408  if (iLiquid)
409  return iLiquid->GetLiquidHeight(pos, liqHeight);
410  return false;
411  }
bool GetLiquidHeight(const G3D::Vector3 &pos, float &liqHeight) const
Definition: WorldModel.cpp:149
WmoLiquid * iLiquid
Definition: WorldModel.h:102

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 VMAP::GroupModel::GetLiquidType ( ) const
414  {
415  if (iLiquid)
416  return iLiquid->GetType();
417  return 0;
418  }
WmoLiquid * iLiquid
Definition: WorldModel.h:102
uint32 GetType() const
Definition: WorldModel.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VMAP::GroupModel::getMeshData ( std::vector< G3D::Vector3 > &  outVertices,
std::vector< MeshTriangle > &  outTriangles,
WmoLiquid *&  liquid 
)
421  {
422  outVertices = vertices;
423  outTriangles = triangles;
424  liquid = iLiquid;
425  }
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99
WmoLiquid * iLiquid
Definition: WorldModel.h:102
uint32 VMAP::GroupModel::GetMogpFlags ( ) const
inline
92 { return iMogpFlags; }
uint32 iMogpFlags
Definition: WorldModel.h:97

+ Here is the caller graph for this function:

uint32 VMAP::GroupModel::GetWmoID ( ) const
inline
93 { return iGroupWMOID; }
uint32 iGroupWMOID
Definition: WorldModel.h:98

+ Here is the caller graph for this function:

bool VMAP::GroupModel::IntersectRay ( const G3D::Ray ray,
float &  distance,
bool  stopAtFirstHit 
) const
383  {
384  if (triangles.empty())
385  return false;
386 
387  GModelRayCallback callback(triangles, vertices);
388  meshTree.intersectRay(ray, callback, distance, stopAtFirstHit);
389  return callback.hit;
390  }
double distance(double x, double y)
Definition: g3dmath.h:731
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
BIH meshTree
Definition: WorldModel.h:101
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99
void intersectRay(const G3D::Ray &r, RayCallback &intersectCallback, float &maxDist, bool stopAtFirst=false) const
Definition: BoundingIntervalHierarchy.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool VMAP::GroupModel::IsInsideObject ( const G3D::Vector3 pos,
const G3D::Vector3 down,
float &  z_dist 
) const
393  {
394  if (triangles.empty() || !iBound.contains(pos))
395  return false;
396  GModelRayCallback callback(triangles, vertices);
397  Vector3 rPos = pos - 0.1f * down;
398  float dist = G3D::finf();
399  G3D::Ray ray(rPos, down);
400  bool hit = IntersectRay(ray, dist, false);
401  if (hit)
402  z_dist = dist - 0.1f;
403  return hit;
404  }
float finf()
Definition: g3dmath.cpp:71
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
Definition: WorldModel.cpp:382
bool contains(const AABox &other) const
Definition: AABox.h:238
Definition: Vector3.h:58
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
Definition: Ray.h:24
G3D::AABox iBound
Definition: WorldModel.h:96
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99

+ Here is the call graph for this function:

bool VMAP::GroupModel::readFromFile ( FILE *  rf)
325  {
326  char chunk[8];
327  bool result = true;
328  uint32 chunkSize = 0;
329  uint32 count = 0;
330  triangles.clear();
331  vertices.clear();
332  delete iLiquid;
333  iLiquid = NULL;
334 
335  if (result && fread(&iBound, sizeof(G3D::AABox), 1, rf) != 1) result = false;
336  if (result && fread(&iMogpFlags, sizeof(uint32), 1, rf) != 1) result = false;
337  if (result && fread(&iGroupWMOID, sizeof(uint32), 1, rf) != 1) result = false;
338 
339  // read vertices
340  if (result && !readChunk(rf, chunk, "VERT", 4)) result = false;
341  if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false;
342  if (result && fread(&count, sizeof(uint32), 1, rf) != 1) result = false;
343  if (!count) // models without (collision) geometry end here, unsure if they are useful
344  return result;
345  if (result) vertices.resize(count);
346  if (result && fread(&vertices[0], sizeof(Vector3), count, rf) != count) result = false;
347 
348  // read triangle mesh
349  if (result && !readChunk(rf, chunk, "TRIM", 4)) result = false;
350  if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false;
351  if (result && fread(&count, sizeof(uint32), 1, rf) != 1) result = false;
352  if (result) triangles.resize(count);
353  if (result && fread(&triangles[0], sizeof(MeshTriangle), count, rf) != count) result = false;
354 
355  // read mesh BIH
356  if (result && !readChunk(rf, chunk, "MBIH", 4)) result = false;
357  if (result) result = meshTree.readFromFile(rf);
358 
359  // write liquid data
360  if (result && !readChunk(rf, chunk, "LIQU", 4)) result = false;
361  if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false;
362  if (result && chunkSize > 0)
363  result = WmoLiquid::readFromFile(rf, iLiquid);
364  return result;
365  }
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: adtfile.h:57
Definition: Vector3.h:58
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
Definition: TileAssembler.cpp:40
uint32_t uint32
Definition: Define.h:150
Definition: AABox.h:32
bool readFromFile(FILE *rf)
Definition: BoundingIntervalHierarchy.cpp:261
BIH meshTree
Definition: WorldModel.h:101
G3D::AABox iBound
Definition: WorldModel.h:96
uint32 iMogpFlags
Definition: WorldModel.h:97
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99
WmoLiquid * iLiquid
Definition: WorldModel.h:102
static bool readFromFile(FILE *rf, WmoLiquid *&liquid)
Definition: WorldModel.cpp:225
uint32 iGroupWMOID
Definition: WorldModel.h:98

+ Here is the call graph for this function:

void VMAP::GroupModel::setLiquidData ( WmoLiquid *&  liquid)
inline
84 { iLiquid = liquid; liquid = NULL; }
arena_t NULL
Definition: jemalloc_internal.h:624
WmoLiquid * iLiquid
Definition: WorldModel.h:102
void VMAP::GroupModel::setMeshData ( std::vector< G3D::Vector3 > &  vert,
std::vector< MeshTriangle > &  tri 
)

pass mesh data to object and create BIH. Passed vectors get get swapped with old geometry!

271  {
272  vertices.swap(vert);
273  triangles.swap(tri);
274  TriBoundFunc bFunc(vertices);
275  meshTree.build(triangles, bFunc);
276  }
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
BIH meshTree
Definition: WorldModel.h:101
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99
void build(const PrimArray &primitives, BoundsFunc &getBounds, uint32 leafSize=3, bool printStats=false)
Definition: BoundingIntervalHierarchy.h:84

+ Here is the call graph for this function:

bool VMAP::GroupModel::writeToFile ( FILE *  wf)
279  {
280  bool result = true;
281  uint32 chunkSize, count;
282 
283  if (result && fwrite(&iBound, sizeof(G3D::AABox), 1, wf) != 1) result = false;
284  if (result && fwrite(&iMogpFlags, sizeof(uint32), 1, wf) != 1) result = false;
285  if (result && fwrite(&iGroupWMOID, sizeof(uint32), 1, wf) != 1) result = false;
286 
287  // write vertices
288  if (result && fwrite("VERT", 1, 4, wf) != 4) result = false;
289  count = vertices.size();
290  chunkSize = sizeof(uint32)+ sizeof(Vector3)*count;
291  if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
292  if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
293  if (!count) // models without (collision) geometry end here, unsure if they are useful
294  return result;
295  if (result && fwrite(&vertices[0], sizeof(Vector3), count, wf) != count) result = false;
296 
297  // write triangle mesh
298  if (result && fwrite("TRIM", 1, 4, wf) != 4) result = false;
299  count = triangles.size();
300  chunkSize = sizeof(uint32)+ sizeof(MeshTriangle)*count;
301  if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
302  if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
303  if (result && fwrite(&triangles[0], sizeof(MeshTriangle), count, wf) != count) result = false;
304 
305  // write mesh BIH
306  if (result && fwrite("MBIH", 1, 4, wf) != 4) result = false;
307  if (result) result = meshTree.writeToFile(wf);
308 
309  // write liquid data
310  if (result && fwrite("LIQU", 1, 4, wf) != 4) result = false;
311  if (!iLiquid)
312  {
313  chunkSize = 0;
314  if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
315  return result;
316  }
317  chunkSize = iLiquid->GetFileSize();
318  if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
319  if (result) result = iLiquid->writeToFile(wf);
320 
321  return result;
322  }
bool writeToFile(FILE *wf)
Definition: WorldModel.cpp:206
bool writeToFile(FILE *wf) const
Definition: BoundingIntervalHierarchy.cpp:247
Definition: Vector3.h:58
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
uint32 GetFileSize()
Definition: WorldModel.cpp:198
uint32_t uint32
Definition: Define.h:150
Definition: AABox.h:32
BIH meshTree
Definition: WorldModel.h:101
G3D::AABox iBound
Definition: WorldModel.h:96
uint32 iMogpFlags
Definition: WorldModel.h:97
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99
WmoLiquid * iLiquid
Definition: WorldModel.h:102
uint32_t uint32
Definition: g3dmath.h:168
uint32 iGroupWMOID
Definition: WorldModel.h:98

+ Here is the call graph for this function:

Member Data Documentation

G3D::AABox VMAP::GroupModel::iBound
protected
uint32 VMAP::GroupModel::iGroupWMOID
protected
WmoLiquid* VMAP::GroupModel::iLiquid
protected
uint32 VMAP::GroupModel::iMogpFlags
protected
BIH VMAP::GroupModel::meshTree
protected
std::vector<MeshTriangle> VMAP::GroupModel::triangles
protected
std::vector<G3D::Vector3> VMAP::GroupModel::vertices
protected

The documentation for this class was generated from the following files: