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!
 
void setRootWmoID (uint32 id)
 
bool IntersectRay (const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
 
bool GetLocationInfo (const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, GroupLocationInfo &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
109{ }

Member Function Documentation

◆ GetGroupModels()

void VMAP::WorldModel::GetGroupModels ( std::vector< GroupModel > &  outGroupModels)
704 {
705 outGroupModels = groupModels;
706 }
std::vector< GroupModel > groupModels
Definition WorldModel.h:122

References groupModels.

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

◆ GetLocationInfo()

bool VMAP::WorldModel::GetLocationInfo ( const G3D::Vector3 &  p,
const G3D::Vector3 &  down,
float &  dist,
GroupLocationInfo info 
) const
595 {
596 if (groupModels.empty())
597 {
598 return false;
599 }
600
601 WModelAreaCallback callback(groupModels);
602 G3D::Ray r(p - down * 0.1f, down);
603 float zDist = groupTree.bound().extent().length();
604 groupTree.intersectRay(r, callback, zDist, false);
605 if (callback.hit[GroupModel::INSIDE])
606 {
607 info.rootId = RootWMOID;
608 info.hitModel = callback.hit[GroupModel::INSIDE];
609 dist = zDist;
610 return true;
611 }
612
613 // some group models don't have any floor to intersect with
614 // so we should attempt to intersect with a model part below the group `p` is in (stored in GroupModel::ABOVE)
615 // then find back where we originated from (GroupModel::MAYBE_INSIDE)
616 if (callback.hit[GroupModel::MAYBE_INSIDE] && callback.hit[GroupModel::ABOVE])
617 {
618 info.rootId = RootWMOID;
619 info.hitModel = callback.hit[GroupModel::MAYBE_INSIDE];
620 dist = zDist;
621 return true;
622 }
623 return false;
624 }
G3D::AABox const & bound() const
Definition BoundingIntervalHierarchy.h:120
void intersectRay(const G3D::Ray &r, RayCallback &intersectCallback, float &maxDist, bool stopAtFirstHit) const
Definition BoundingIntervalHierarchy.h:123
@ MAYBE_INSIDE
Definition WorldModel.h:85
@ ABOVE
Definition WorldModel.h:85
@ INSIDE
Definition WorldModel.h:85
BIH groupTree
Definition WorldModel.h:123
uint32 RootWMOID
Definition WorldModel.h:121

References VMAP::GroupModel::ABOVE, BIH::bound(), groupModels, groupTree, VMAP::WModelAreaCallback::hit, VMAP::GroupLocationInfo::hitModel, VMAP::GroupModel::INSIDE, BIH::intersectRay(), VMAP::GroupModel::MAYBE_INSIDE, VMAP::GroupLocationInfo::rootId, and RootWMOID.

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

◆ IntersectRay()

bool VMAP::WorldModel::IntersectRay ( const G3D::Ray &  ray,
float &  distance,
bool  stopAtFirstHit,
ModelIgnoreFlags  ignoreFlags 
) const
543 {
544 // If the caller asked us to ignore certain objects we should check flags
545 if ((ignoreFlags & ModelIgnoreFlags::M2) != ModelIgnoreFlags::Nothing)
546 {
547 // M2 models are not taken into account for LoS calculation if caller requested their ignoring.
548 if (Flags & MOD_M2)
549 {
550 return false;
551 }
552 }
553
554 // small M2 workaround, maybe better make separate class with virtual intersection funcs
555 // in any case, there's no need to use a bound tree if we only have one submodel
556 if (groupModels.size() == 1)
557 {
558 return groupModels[0].IntersectRay(ray, distance, stopAtFirstHit);
559 }
560
561 WModelRayCallBack isc(groupModels);
562 groupTree.intersectRay(ray, isc, distance, stopAtFirstHit);
563 return isc.hit;
564 }
uint32 Flags
Definition WorldModel.h:119
@ MOD_M2
Definition ModelInstance.h:36

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

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!

524 {
525 groupModels.swap(models);
526 groupTree.build(groupModels, BoundsTrait<GroupModel>::GetBounds, 1);
527 }
void build(const PrimArray &primitives, BoundsFunc &GetBounds, uint32 leafSize=3, bool printStats=false)
Definition BoundingIntervalHierarchy.h:81

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

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

◆ setRootWmoID()

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

References RootWMOID.

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

◆ writeFile()

bool VMAP::WorldModel::writeFile ( const std::string &  filename)
627 {
628 FILE* wf = fopen(filename.c_str(), "wb");
629 if (!wf)
630 {
631 return false;
632 }
633
634 uint32 chunkSize, count;
635 bool result = fwrite(VMAP_MAGIC, 1, 8, wf) == 8;
636 if (result && fwrite("WMOD", 1, 4, wf) != 4) { result = false; }
637 chunkSize = sizeof(uint32) + sizeof(uint32);
638 if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) { result = false; }
639 if (result && fwrite(&RootWMOID, sizeof(uint32), 1, wf) != 1) { result = false; }
640
641 // write group models
642 count = groupModels.size();
643 if (count)
644 {
645 if (result && fwrite("GMOD", 1, 4, wf) != 4) { result = false; }
646 //chunkSize = sizeof(uint32)+ sizeof(GroupModel)*count;
647 //if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
648 if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) { result = false; }
649 for (uint32 i = 0; i < groupModels.size() && result; ++i)
650 {
651 result = groupModels[i].writeToFile(wf);
652 }
653
654 // write group BIH
655 if (result && fwrite("GBIH", 1, 4, wf) != 4) { result = false; }
656 if (result) { result = groupTree.writeToFile(wf); }
657 }
658
659 fclose(wf);
660 return result;
661 }
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
121{0};

Referenced by GetLocationInfo(), readFile(), setRootWmoID(), and writeFile().


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