36 bound(lowBound, highBound),
name(name_, nameLength) { }
42typedef std::unordered_map<uint32, GameobjectModelData>
ModelList;
49 auto model_list_file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen((dataPath +
"vmaps/" +
VMAP::GAMEOBJECT_MODELS).c_str(),
"rb"));
57 if (fread(magic, 1, 8, model_list_file.get()) != 8
64 uint32 name_length, displayId;
69 if (fread(&displayId,
sizeof(
uint32), 1, model_list_file.get()) != 1)
70 if (feof(model_list_file.get()))
73 if (fread(&name_length,
sizeof(
uint32), 1, model_list_file.get()) != 1
74 || name_length >=
sizeof(buff)
75 || fread(&buff,
sizeof(
char), name_length, model_list_file.get()) != name_length
76 || fread(&
v1,
sizeof(Vector3), 1, model_list_file.get()) != 1
77 || fread(&
v2,
sizeof(Vector3), 1, model_list_file.get()) != 1)
83 if (
v1.isNaN() ||
v2.isNaN())
89 model_list.emplace(std::piecewise_construct, std::forward_as_tuple(displayId), std::forward_as_tuple(&buff[0], name_length,
v1,
v2));
100 ModelList::const_iterator it =
model_list.find(modelOwner->GetDisplayId());
104 G3D::AABox mdl_box(it->second.bound);
106 if (mdl_box == G3D::AABox::zero())
108 TC_LOG_ERROR(
"misc",
"GameObject model {} has zero bounds, loading skipped", it->second.name);
117 iPos = modelOwner->GetPosition();
118 iScale = modelOwner->GetScale();
121 G3D::Matrix3 iRotation = modelOwner->GetRotation().toRotationMatrix();
124 mdl_box = AABox(mdl_box.low() *
iScale, mdl_box.high() *
iScale);
125 AABox rotated_bounds = G3D::AABox::empty();
126 for (
int i = 0; i < 8; ++i)
127 rotated_bounds.merge(iRotation * mdl_box.corner(i));
132 for (
int i = 0; i < 8; ++i)
134 Vector3 pos(
iBound.corner(i));
135 modelOwner->DebugVisualizeCorner(pos);
139 owner = std::move(modelOwner);
143std::unique_ptr<GameObjectModel>
GameObjectModel::Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string
const& dataPath)
146 if (!mdl->initialize(std::move(modelOwner), dataPath))
162 if (!
owner->IsInPhase(phaseShift))
165 float time = ray.intersectionTime(
iBound);
166 if (time == G3D::finf())
171 Ray modRay(p,
iInvRot * ray.direction());
173 bool hit =
iModel->IntersectRay(modRay, distance, stopAtFirstHit, ignoreFlags);
187 if (!
owner->IsInPhase(phaseShift))
190 if (!
iBound.contains(point))
195 Vector3 zDirModel =
iInvRot * Vector3(0.f, 0.f, -1.f);
199 if (
iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
201 Vector3 modelGround = pModel + zDist * zDirModel;
237 G3D::AABox mdl_box(it->second.bound);
239 if (mdl_box == G3D::AABox::zero())
241 TC_LOG_ERROR(
"misc",
"GameObject model {} has zero bounds, loading skipped", it->second.name);
247 G3D::Matrix3 iRotation =
owner->GetRotation().toRotationMatrix();
250 mdl_box = AABox(mdl_box.low() *
iScale, mdl_box.high() *
iScale);
251 AABox rotated_bounds = G3D::AABox::empty();
252 for (
int i = 0; i < 8; ++i)
253 rotated_bounds.merge(iRotation * mdl_box.corner(i));
258 for (
int i = 0; i < 8; ++i)
260 Vector3 pos(
iBound.corner(i));
261 owner->DebugVisualizeCorner(pos);
std::unordered_map< uint32, GameobjectModelData > ModelList
bool LoadGameObjectModelList(std::string const &dataPath)
#define TC_LOG_ERROR(filterType__, message__,...)
#define TC_LOG_INFO(filterType__, message__,...)
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
std::shared_ptr< VMAP::WorldModel > iModel
bool IsCollisionEnabled() const
bool GetLocationInfo(G3D::Vector3 const &point, VMAP::LocationInfo &info, PhaseShift const &phaseShift) const
bool GetLiquidLevel(G3D::Vector3 const &point, VMAP::LocationInfo &info, float &liqHeight) const
static std::unique_ptr< GameObjectModel > Create(std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
std::unique_ptr< GameObjectModelOwnerBase > owner
bool IntersectRay(G3D::Ray const &ray, float &maxDist, bool stopAtFirstHit, PhaseShift const &phaseShift, VMAP::ModelIgnoreFlags ignoreFlags) const
bool initialize(std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
bool GetLiquidLevel(const G3D::Vector3 &pos, float &liqHeight) const
static VMapManager * createOrGetVMapManager()
std::shared_ptr< WorldModel > acquireModelInstance(std::string const &basepath, std::string const &filename)
const char GAMEOBJECT_MODELS[]
GameobjectModelData(char const *name_, uint32 nameLength, Vector3 const &lowBound, Vector3 const &highBound)
GroupModel const * hitModel