AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
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!
 
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::AABox & GetBound () 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 {0}
 
uint32 iGroupWMOID {0}
 
std::vector< G3D::Vector3 > vertices
 
std::vector< MeshTriangletriangles
 
BIH meshTree
 
WmoLiquidiLiquid {nullptr}
 

Detailed Description

holding additional info for WMO group files

Constructor & Destructor Documentation

◆ GroupModel() [1/3]

VMAP::GroupModel::GroupModel ( )
inline
75{ }

◆ GroupModel() [2/3]

VMAP::GroupModel::GroupModel ( const GroupModel other)
314 :
315 iBound(other.iBound), iMogpFlags(other.iMogpFlags), iGroupWMOID(other.iGroupWMOID),
316 vertices(other.vertices), triangles(other.triangles), meshTree(other.meshTree), iLiquid(0)
317 {
318 if (other.iLiquid)
319 {
320 iLiquid = new WmoLiquid(*other.iLiquid);
321 }
322 }
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:98
BIH meshTree
Definition: WorldModel.h:100
WmoLiquid * iLiquid
Definition: WorldModel.h:101
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:99
uint32 iMogpFlags
Definition: WorldModel.h:96
uint32 iGroupWMOID
Definition: WorldModel.h:97
G3D::AABox iBound
Definition: WorldModel.h:95

References iLiquid.

◆ GroupModel() [3/3]

VMAP::GroupModel::GroupModel ( uint32  mogpFlags,
uint32  groupWMOID,
const G3D::AABox &  bound 
)
inline
77 :
78 iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(nullptr) { }

◆ ~GroupModel()

VMAP::GroupModel::~GroupModel ( )
inline
79{ delete iLiquid; }

References iLiquid.

Member Function Documentation

◆ GetBound()

const G3D::AABox & VMAP::GroupModel::GetBound ( ) const
inline

◆ GetLiquidLevel()

bool VMAP::GroupModel::GetLiquidLevel ( const G3D::Vector3 &  pos,
float &  liqHeight 
) const
472 {
473 if (iLiquid)
474 {
475 return iLiquid->GetLiquidHeight(pos, liqHeight);
476 }
477 return false;
478 }
bool GetLiquidHeight(const G3D::Vector3 &pos, float &liqHeight) const
Definition: WorldModel.cpp:166

References VMAP::WmoLiquid::GetLiquidHeight(), and iLiquid.

Referenced by VMAP::ModelInstance::GetLiquidLevel(), and GameObjectModel::GetLiquidLevel().

◆ GetLiquidType()

uint32 VMAP::GroupModel::GetLiquidType ( ) const
481 {
482 if (iLiquid)
483 {
484 return iLiquid->GetType();
485 }
486 return 0;
487 }
uint32 GetType() const
Definition: WorldModel.h:54

References VMAP::WmoLiquid::GetType(), and iLiquid.

Referenced by DynamicMapTree::GetAreaAndLiquidData(), VMAP::VMapMgr2::GetAreaAndLiquidData(), and VMAP::VMapMgr2::GetLiquidLevel().

◆ GetMeshData()

void VMAP::GroupModel::GetMeshData ( std::vector< G3D::Vector3 > &  outVertices,
std::vector< MeshTriangle > &  outTriangles,
WmoLiquid *&  liquid 
)
490 {
491 outVertices = vertices;
492 outTriangles = triangles;
493 liquid = iLiquid;
494 }

References iLiquid, triangles, and vertices.

◆ GetMogpFlags()

◆ GetWmoID()

uint32 VMAP::GroupModel::GetWmoID ( ) const
inline

◆ IntersectRay()

bool VMAP::GroupModel::IntersectRay ( const G3D::Ray &  ray,
float &  distance,
bool  stopAtFirstHit 
) const
443 {
444 if (triangles.empty())
445 {
446 return false;
447 }
448
449 GModelRayCallback callback(triangles, vertices);
450 meshTree.intersectRay(ray, callback, distance, stopAtFirstHit);
451 return callback.hit;
452 }
void intersectRay(const G3D::Ray &r, RayCallback &intersectCallback, float &maxDist, bool stopAtFirstHit) const
Definition: BoundingIntervalHierarchy.h:121

References VMAP::GModelRayCallback::hit, BIH::intersectRay(), meshTree, triangles, and vertices.

Referenced by IsInsideObject().

◆ IsInsideObject()

bool VMAP::GroupModel::IsInsideObject ( const G3D::Vector3 &  pos,
const G3D::Vector3 &  down,
float &  z_dist 
) const
455 {
456 if (triangles.empty() || !iBound.contains(pos))
457 {
458 return false;
459 }
460 Vector3 rPos = pos - 0.1f * down;
461 float dist = G3D::inf();
462 G3D::Ray ray(rPos, down);
463 bool hit = IntersectRay(ray, dist, false);
464 if (hit)
465 {
466 z_dist = dist - 0.1f;
467 }
468 return hit;
469 }
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
Definition: WorldModel.cpp:442

References iBound, IntersectRay(), and triangles.

◆ readFromFile()

bool VMAP::GroupModel::readFromFile ( FILE *  rf)
381 {
382 char chunk[8];
383 bool result = true;
384 uint32 chunkSize = 0;
385 uint32 count = 0;
386 triangles.clear();
387 vertices.clear();
388 delete iLiquid;
389 iLiquid = nullptr;
390
391 if (fread(&iBound, sizeof(G3D::AABox), 1, rf) != 1) { result = false; }
392 if (result && fread(&iMogpFlags, sizeof(uint32), 1, rf) != 1) { result = false; }
393 if (result && fread(&iGroupWMOID, sizeof(uint32), 1, rf) != 1) { result = false; }
394
395 // read vertices
396 if (result && !readChunk(rf, chunk, "VERT", 4)) { result = false; }
397 if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) { result = false; }
398 if (result && fread(&count, sizeof(uint32), 1, rf) != 1) { result = false; }
399 if (!count) // models without (collision) geometry end here, unsure if they are useful
400 {
401 return result;
402 }
403 if (result) { vertices.resize(count); }
404 if (result && fread(&vertices[0], sizeof(Vector3), count, rf) != count) { result = false; }
405
406 // read triangle mesh
407 if (result && !readChunk(rf, chunk, "TRIM", 4)) { result = false; }
408 if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) { result = false; }
409 if (result && fread(&count, sizeof(uint32), 1, rf) != 1) { result = false; }
410 if (result) { triangles.resize(count); }
411 if (result && fread(&triangles[0], sizeof(MeshTriangle), count, rf) != count) { result = false; }
412
413 // read mesh BIH
414 if (result && !readChunk(rf, chunk, "MBIH", 4)) { result = false; }
415 if (result) { result = meshTree.readFromFile(rf); }
416
417 // write liquid data
418 if (result && !readChunk(rf, chunk, "LIQU", 4)) { result = false; }
419 if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) { result = false; }
420 if (result && chunkSize > 0)
421 {
422 result = WmoLiquid::readFromFile(rf, iLiquid);
423 }
424 return result;
425 }
std::uint32_t uint32
Definition: Define.h:108
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
Definition: TileAssembler.cpp:40
bool readFromFile(FILE *rf)
Definition: BoundingIntervalHierarchy.cpp:287
static bool readFromFile(FILE *rf, WmoLiquid *&liquid)
Definition: WorldModel.cpp:265

References iBound, iGroupWMOID, iLiquid, iMogpFlags, meshTree, VMAP::readChunk(), BIH::readFromFile(), VMAP::WmoLiquid::readFromFile(), triangles, and vertices.

◆ setLiquidData()

void VMAP::GroupModel::setLiquidData ( WmoLiquid *&  liquid)
inline
83{ iLiquid = liquid; liquid = nullptr; }

References iLiquid.

◆ setMeshData()

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!

325 {
326 vertices.swap(vert);
327 triangles.swap(tri);
328 TriBoundFunc bFunc(vertices);
329 meshTree.build(triangles, bFunc);
330 }
void build(const PrimArray &primitives, BoundsFunc &GetBounds, uint32 leafSize=3, bool printStats=false)
Definition: BoundingIntervalHierarchy.h:80

References BIH::build(), meshTree, triangles, and vertices.

◆ writeToFile()

bool VMAP::GroupModel::writeToFile ( FILE *  wf)
333 {
334 bool result = true;
335 uint32 chunkSize, count;
336
337 if (fwrite(&iBound, sizeof(G3D::AABox), 1, wf) != 1) { result = false; }
338 if (result && fwrite(&iMogpFlags, sizeof(uint32), 1, wf) != 1) { result = false; }
339 if (result && fwrite(&iGroupWMOID, sizeof(uint32), 1, wf) != 1) { result = false; }
340
341 // write vertices
342 if (result && fwrite("VERT", 1, 4, wf) != 4) { result = false; }
343 count = vertices.size();
344 chunkSize = sizeof(uint32) + sizeof(Vector3) * count;
345 if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) { result = false; }
346 if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) { result = false; }
347 if (!count) // models without (collision) geometry end here, unsure if they are useful
348 {
349 return result;
350 }
351 if (result && fwrite(&vertices[0], sizeof(Vector3), count, wf) != count) { result = false; }
352
353 // write triangle mesh
354 if (result && fwrite("TRIM", 1, 4, wf) != 4) { result = false; }
355 count = triangles.size();
356 chunkSize = sizeof(uint32) + sizeof(MeshTriangle) * count;
357 if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) { result = false; }
358 if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) { result = false; }
359 if (result && fwrite(&triangles[0], sizeof(MeshTriangle), count, wf) != count) { result = false; }
360
361 // write mesh BIH
362 if (result && fwrite("MBIH", 1, 4, wf) != 4) { result = false; }
363 if (result) { result = meshTree.writeToFile(wf); }
364
365 // write liquid data
366 if (result && fwrite("LIQU", 1, 4, wf) != 4) { result = false; }
367 if (!iLiquid)
368 {
369 chunkSize = 0;
370 if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) { result = false; }
371 return result;
372 }
373 chunkSize = iLiquid->GetFileSize();
374 if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) { result = false; }
375 if (result) { result = iLiquid->writeToFile(wf); }
376
377 return result;
378 }
bool writeToFile(FILE *wf) const
Definition: BoundingIntervalHierarchy.cpp:273
uint32 GetFileSize()
Definition: WorldModel.cpp:233
bool writeToFile(FILE *wf)
Definition: WorldModel.cpp:241

References VMAP::WmoLiquid::GetFileSize(), iBound, iGroupWMOID, iLiquid, iMogpFlags, meshTree, triangles, vertices, VMAP::WmoLiquid::writeToFile(), and BIH::writeToFile().

Member Data Documentation

◆ iBound

G3D::AABox VMAP::GroupModel::iBound
protected

◆ iGroupWMOID

uint32 VMAP::GroupModel::iGroupWMOID {0}
protected

Referenced by GetWmoID(), readFromFile(), and writeToFile().

◆ iLiquid

WmoLiquid* VMAP::GroupModel::iLiquid {nullptr}
protected

◆ iMogpFlags

uint32 VMAP::GroupModel::iMogpFlags {0}
protected

◆ meshTree

BIH VMAP::GroupModel::meshTree
protected

◆ triangles

std::vector<MeshTriangle> VMAP::GroupModel::triangles
protected

◆ vertices

std::vector<G3D::Vector3> VMAP::GroupModel::vertices
protected