36 bound(lowBound, highBound),
name(name_, nameLength) { }
42typedef std::unordered_map<uint32, GameobjectModelData>
ModelList;
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));
104 ModelList::const_iterator it =
model_list.find(modelOwner->GetDisplayId());
108 G3D::AABox mdl_box(it->second.bound);
110 if (mdl_box == G3D::AABox::zero())
112 TC_LOG_ERROR(
"misc",
"GameObject model {} has zero bounds, loading skipped", it->second.name);
121 iPos = modelOwner->GetPosition();
122 iScale = modelOwner->GetScale();
125 G3D::Matrix3 iRotation = modelOwner->GetRotation().toRotationMatrix();
128 mdl_box = AABox(mdl_box.low() *
iScale, mdl_box.high() *
iScale);
129 AABox rotated_bounds;
130 for (
int i = 0; i < 8; ++i)
131 rotated_bounds.merge(iRotation * mdl_box.corner(i));
136 for (
int i = 0; i < 8; ++i)
138 Vector3 pos(
iBound.corner(i));
139 modelOwner->DebugVisualizeCorner(pos);
143 owner = std::move(modelOwner);
150 if (!mdl->
initialize(std::move(modelOwner), dataPath))
169 if (!
owner->IsInPhase(phaseShift))
172 float time = ray.intersectionTime(
iBound);
173 if (time == G3D::finf())
178 Ray modRay(p,
iInvRot * ray.direction());
194 if (!
owner->IsInPhase(phaseShift))
197 if (!
iBound.contains(point))
202 Vector3 zDirModel =
iInvRot * Vector3(0.f, 0.f, -1.f);
208 Vector3 modelGround = pModel + zDist * zDirModel;
245 G3D::AABox mdl_box(it->second.bound);
247 if (mdl_box == G3D::AABox::zero())
249 TC_LOG_ERROR(
"misc",
"GameObject model {} has zero bounds, loading skipped", it->second.name);
255 G3D::Matrix3 iRotation =
owner->GetRotation().toRotationMatrix();
258 mdl_box = AABox(mdl_box.low() *
iScale, mdl_box.high() *
iScale);
259 AABox rotated_bounds;
260 for (
int i = 0; i < 8; ++i)
261 rotated_bounds.merge(iRotation * mdl_box.corner(i));
266 for (
int i = 0; i < 8; ++i)
268 Vector3 pos(
iBound.corner(i));
269 owner->DebugVisualizeCorner(pos);
std::unordered_map< uint32, GameobjectModelData > ModelList
bool LoadGameObjectModelList(std::string const &dataPath)
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_INFO(filterType__,...)
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
VMAP::WorldModel * iModel
bool intersectRay(G3D::Ray const &ray, float &maxDist, bool stopAtFirstHit, PhaseShift const &phaseShift, VMAP::ModelIgnoreFlags ignoreFlags) const
bool GetLocationInfo(G3D::Vector3 const &point, VMAP::LocationInfo &info, PhaseShift const &phaseShift) const
static GameObjectModel * Create(std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
bool isCollisionEnabled() const
bool GetLiquidLevel(G3D::Vector3 const &point, VMAP::LocationInfo &info, float &liqHeight) const
std::unique_ptr< GameObjectModelOwnerBase > owner
bool initialize(std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
bool GetLiquidLevel(const G3D::Vector3 &pos, float &liqHeight) const
static VMapManager2 * createOrGetVMapManager()
void releaseModelInstance(std::string const &filename)
WorldModel * acquireModelInstance(std::string const &basepath, std::string const &filename)
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
std::string const & GetName() const
bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, GroupLocationInfo &info) const
auto make_unique_ptr_with_deleter(T ptr, Del &&deleter)
const char GAMEOBJECT_MODELS[]
GameobjectModelData(char const *name_, uint32 nameLength, Vector3 const &lowBound, Vector3 const &highBound)
GroupModel const * hitModel