AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
VMAP::WorldModel Class Reference

#include "WorldModel.h"

Public Member Functions

 WorldModel ()
 
void setGroupModels (std::vector< GroupModel > &models)
 pass group models to WorldModel and create BIH. Passed vector is swapped with old geometry! More...
 
void setRootWmoID (uint32 id)
 
bool IntersectRay (const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
 
bool IntersectPoint (const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const
 
bool GetLocationInfo (const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const
 
bool writeFile (const std::string &filename)
 
bool readFile (const std::string &filename)
 
void GetGroupModels (std::vector< GroupModel > &outGroupModels)
 

Public Attributes

uint32 Flags
 

Protected Attributes

uint32 RootWMOID {0}
 
std::vector< GroupModelgroupModels
 
BIH groupTree
 

Detailed Description

Holds a model (converted M2 or WMO) in its original coordinate space

Constructor & Destructor Documentation

◆ WorldModel()

VMAP::WorldModel::WorldModel ( )
inline
106{ }

Member Function Documentation

◆ GetGroupModels()

void VMAP::WorldModel::GetGroupModels ( std::vector< GroupModel > &  outGroupModels)
697 {
698 outGroupModels = groupModels;
699 }
std::vector< GroupModel > groupModels
Definition: WorldModel.h:120

References groupModels.

Referenced by MMAP::TerrainBuilder::loadVMap().

◆ GetLocationInfo()

bool VMAP::WorldModel::GetLocationInfo ( const G3D::Vector3 &  p,
const G3D::Vector3 &  down,
float &  dist,
LocationInfo info 
) const
601 {
602 if (groupModels.empty())
603 {
604 return false;
605 }
606
607 WModelAreaCallback callback(groupModels, down);
608 groupTree.intersectPoint(p, callback);
609 if (callback.hit != groupModels.end())
610 {
611 info.rootId = RootWMOID;
612 info.hitModel = &(*callback.hit);
613 dist = callback.zDist;
614 return true;
615 }
616 return false;
617 }
void intersectPoint(const G3D::Vector3 &p, IsectCallback &intersectCallback) const
Definition: BoundingIntervalHierarchy.h:284
BIH groupTree
Definition: WorldModel.h:121
uint32 RootWMOID
Definition: WorldModel.h:119

References groupModels, groupTree, VMAP::WModelAreaCallback::hit, VMAP::LocationInfo::hitModel, BIH::intersectPoint(), VMAP::LocationInfo::rootId, RootWMOID, and VMAP::WModelAreaCallback::zDist.

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

◆ IntersectPoint()

bool VMAP::WorldModel::IntersectPoint ( const G3D::Vector3 &  p,
const G3D::Vector3 &  down,
float &  dist,
AreaInfo info 
) const
580 {
581 if (groupModels.empty())
582 {
583 return false;
584 }
585
586 WModelAreaCallback callback(groupModels, down);
587 groupTree.intersectPoint(p, callback);
588 if (callback.hit != groupModels.end())
589 {
590 info.rootId = RootWMOID;
591 info.groupId = callback.hit->GetWmoID();
592 info.flags = callback.hit->GetMogpFlags();
593 info.result = true;
594 dist = callback.zDist;
595 return true;
596 }
597 return false;
598 }

References VMAP::AreaInfo::flags, VMAP::AreaInfo::groupId, groupModels, groupTree, VMAP::WModelAreaCallback::hit, BIH::intersectPoint(), VMAP::AreaInfo::result, VMAP::AreaInfo::rootId, RootWMOID, and VMAP::WModelAreaCallback::zDist.

Referenced by VMAP::ModelInstance::intersectPoint(), and GameObjectModel::IntersectPoint().

◆ IntersectRay()

bool VMAP::WorldModel::IntersectRay ( const G3D::Ray &  ray,
float &  distance,
bool  stopAtFirstHit,
ModelIgnoreFlags  ignoreFlags 
) const
518 {
519 // If the caller asked us to ignore certain objects we should check flags
520 if ((ignoreFlags & ModelIgnoreFlags::M2) != ModelIgnoreFlags::Nothing)
521 {
522 // M2 models are not taken into account for LoS calculation if caller requested their ignoring.
523 if (Flags & MOD_M2)
524 {
525 return false;
526 }
527 }
528
529 // small M2 workaround, maybe better make separate class with virtual intersection funcs
530 // in any case, there's no need to use a bound tree if we only have one submodel
531 if (groupModels.size() == 1)
532 {
533 return groupModels[0].IntersectRay(ray, distance, stopAtFirstHit);
534 }
535
536 WModelRayCallBack isc(groupModels);
537 groupTree.intersectRay(ray, isc, distance, stopAtFirstHit);
538 return isc.hit;
539 }
@ MOD_M2
Definition: ModelInstance.h:36
void intersectRay(const G3D::Ray &r, RayCallback &intersectCallback, float &maxDist, bool stopAtFirstHit) const
Definition: BoundingIntervalHierarchy.h:121
uint32 Flags
Definition: WorldModel.h:117

References Flags, groupModels, groupTree, VMAP::WModelRayCallBack::hit, BIH::intersectRay(), VMAP::M2, VMAP::MOD_M2, and VMAP::Nothing.

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

◆ readFile()

bool VMAP::WorldModel::readFile ( const std::string &  filename)
657 {
658 FILE* rf = fopen(filename.c_str(), "rb");
659 if (!rf)
660 {
661 return false;
662 }
663
664 bool result = true;
665 uint32 chunkSize = 0;
666 uint32 count = 0;
667 char chunk[8]; // Ignore the added magic header
668 if (!readChunk(rf, chunk, VMAP_MAGIC, 8)) { result = false; }
669
670 if (result && !readChunk(rf, chunk, "WMOD", 4)) { result = false; }
671 if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) { result = false; }
672 if (result && fread(&RootWMOID, sizeof(uint32), 1, rf) != 1) { result = false; }
673
674 // read group models
675 if (result && readChunk(rf, chunk, "GMOD", 4))
676 {
677 //if (fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false;
678
679 if (fread(&count, sizeof(uint32), 1, rf) != 1) { result = false; }
680 if (result) { groupModels.resize(count); }
681 //if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false;
682 for (uint32 i = 0; i < count && result; ++i)
683 {
684 result = groupModels[i].readFromFile(rf);
685 }
686
687 // read group BIH
688 if (result && !readChunk(rf, chunk, "GBIH", 4)) { result = false; }
689 if (result) { result = groupTree.readFromFile(rf); }
690 }
691
692 fclose(rf);
693 return result;
694 }
std::uint32_t uint32
Definition: Define.h:107
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
Definition: TileAssembler.cpp:40
const char VMAP_MAGIC[]
Definition: VMapDefinitions.h:25
bool readFromFile(FILE *rf)
Definition: BoundingIntervalHierarchy.cpp:287

References groupModels, groupTree, VMAP::readChunk(), BIH::readFromFile(), RootWMOID, and VMAP::VMAP_MAGIC.

Referenced by VMAP::VMapMgr2::acquireModelInstance().

◆ setGroupModels()

void VMAP::WorldModel::setGroupModels ( std::vector< GroupModel > &  models)

pass group models to WorldModel and create BIH. Passed vector is swapped with old geometry!

499 {
500 groupModels.swap(models);
501 groupTree.build(groupModels, BoundsTrait<GroupModel>::GetBounds, 1);
502 }
void build(const PrimArray &primitives, BoundsFunc &GetBounds, uint32 leafSize=3, bool printStats=false)
Definition: BoundingIntervalHierarchy.h:80

References BIH::build(), groupModels, and groupTree.

Referenced by VMAP::TileAssembler::convertRawFile().

◆ setRootWmoID()

void VMAP::WorldModel::setRootWmoID ( uint32  id)
inline
110{ RootWMOID = id; }

References RootWMOID.

Referenced by VMAP::TileAssembler::convertRawFile().

◆ writeFile()

bool VMAP::WorldModel::writeFile ( const std::string &  filename)
620 {
621 FILE* wf = fopen(filename.c_str(), "wb");
622 if (!wf)
623 {
624 return false;
625 }
626
627 uint32 chunkSize, count;
628 bool result = fwrite(VMAP_MAGIC, 1, 8, wf) == 8;
629 if (result && fwrite("WMOD", 1, 4, wf) != 4) { result = false; }
630 chunkSize = sizeof(uint32) + sizeof(uint32);
631 if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) { result = false; }
632 if (result && fwrite(&RootWMOID, sizeof(uint32), 1, wf) != 1) { result = false; }
633
634 // write group models
635 count = groupModels.size();
636 if (count)
637 {
638 if (result && fwrite("GMOD", 1, 4, wf) != 4) { result = false; }
639 //chunkSize = sizeof(uint32)+ sizeof(GroupModel)*count;
640 //if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
641 if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) { result = false; }
642 for (uint32 i = 0; i < groupModels.size() && result; ++i)
643 {
644 result = groupModels[i].writeToFile(wf);
645 }
646
647 // write group BIH
648 if (result && fwrite("GBIH", 1, 4, wf) != 4) { result = false; }
649 if (result) { result = groupTree.writeToFile(wf); }
650 }
651
652 fclose(wf);
653 return result;
654 }
bool writeToFile(FILE *wf) const
Definition: BoundingIntervalHierarchy.cpp:273

References groupModels, groupTree, RootWMOID, VMAP::VMAP_MAGIC, and BIH::writeToFile().

Referenced by VMAP::TileAssembler::convertRawFile().

Member Data Documentation

◆ Flags

uint32 VMAP::WorldModel::Flags

◆ groupModels

std::vector<GroupModel> VMAP::WorldModel::groupModels
protected

◆ groupTree

BIH VMAP::WorldModel::groupTree
protected

◆ RootWMOID

uint32 VMAP::WorldModel::RootWMOID {0}
protected