mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Tools/mmaps_generator: Added const on some functions interfacing with vmaps
This commit is contained in:
@@ -77,8 +77,8 @@ namespace VMAP
|
||||
void intersectPoint(G3D::Vector3 const& p, AreaInfo& info) const;
|
||||
bool GetLocationInfo(G3D::Vector3 const& p, LocationInfo& info) const;
|
||||
bool GetLiquidLevel(G3D::Vector3 const& p, LocationInfo& info, float& liqHeight) const;
|
||||
G3D::Matrix3 const& GetInvRot() { return iInvRot; }
|
||||
WorldModel* getWorldModel() { return iModel; }
|
||||
G3D::Matrix3 const& GetInvRot() const { return iInvRot; }
|
||||
WorldModel const* getWorldModel() const { return iModel; }
|
||||
protected:
|
||||
G3D::Matrix3 iInvRot;
|
||||
float iInvScale;
|
||||
|
||||
@@ -443,13 +443,6 @@ namespace VMAP
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GroupModel::getMeshData(std::vector<G3D::Vector3>& outVertices, std::vector<MeshTriangle>& outTriangles, WmoLiquid*& liquid)
|
||||
{
|
||||
outVertices = vertices;
|
||||
outTriangles = triangles;
|
||||
liquid = iLiquid;
|
||||
}
|
||||
|
||||
// ===================== WorldModel ==================================
|
||||
|
||||
void WorldModel::setGroupModels(std::vector<GroupModel>& models)
|
||||
@@ -633,9 +626,4 @@ namespace VMAP
|
||||
fclose(rf);
|
||||
return result;
|
||||
}
|
||||
|
||||
void WorldModel::getGroupModels(std::vector<GroupModel>& outGroupModels)
|
||||
{
|
||||
outGroupModels = groupModels;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,15 +33,11 @@ namespace VMAP
|
||||
struct GroupLocationInfo;
|
||||
enum class ModelIgnoreFlags : uint32;
|
||||
|
||||
class TC_COMMON_API MeshTriangle
|
||||
struct MeshTriangle
|
||||
{
|
||||
public:
|
||||
MeshTriangle() : idx0(0), idx1(0), idx2(0) { }
|
||||
MeshTriangle(uint32 na, uint32 nb, uint32 nc): idx0(na), idx1(nb), idx2(nc) { }
|
||||
|
||||
uint32 idx0;
|
||||
uint32 idx1;
|
||||
uint32 idx2;
|
||||
uint32 idx0;
|
||||
uint32 idx1;
|
||||
uint32 idx2;
|
||||
};
|
||||
|
||||
class TC_COMMON_API WmoLiquid
|
||||
@@ -55,6 +51,8 @@ namespace VMAP
|
||||
uint32 GetType() const { return iType; }
|
||||
float *GetHeightStorage() { return iHeight; }
|
||||
uint8 *GetFlagsStorage() { return iFlags; }
|
||||
float const* GetHeightStorage() const { return iHeight; }
|
||||
uint8 const* GetFlagsStorage() const { return iFlags; }
|
||||
uint32 GetFileSize();
|
||||
bool writeToFile(FILE* wf);
|
||||
static bool readFromFile(FILE* rf, WmoLiquid* &liquid);
|
||||
@@ -91,7 +89,9 @@ namespace VMAP
|
||||
const G3D::AABox& GetBound() const { return iBound; }
|
||||
uint32 GetMogpFlags() const { return iMogpFlags; }
|
||||
uint32 GetWmoID() const { return iGroupWMOID; }
|
||||
void getMeshData(std::vector<G3D::Vector3>& outVertices, std::vector<MeshTriangle>& outTriangles, WmoLiquid*& liquid);
|
||||
std::vector<G3D::Vector3> const& GetVertices() const { return vertices; }
|
||||
std::vector<MeshTriangle> const& GetTriangles() const { return triangles; }
|
||||
WmoLiquid const* GetLiquid() const { return iLiquid; }
|
||||
protected:
|
||||
G3D::AABox iBound;
|
||||
uint32 iMogpFlags;// 0x8 outdor; 0x2000 indoor
|
||||
@@ -116,7 +116,7 @@ namespace VMAP
|
||||
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);
|
||||
std::vector<GroupModel> const& getGroupModels() const { return groupModels; }
|
||||
std::string const& GetName() const { return name; }
|
||||
void SetName(std::string newName) { name = std::move(newName); }
|
||||
uint32 Flags;
|
||||
|
||||
@@ -609,18 +609,17 @@ namespace MMAP
|
||||
|
||||
for (uint32 i = 0; i < count; ++i)
|
||||
{
|
||||
ModelInstance instance = models[i];
|
||||
ModelInstance const& instance = models[i];
|
||||
|
||||
// model instances exist in tree even though there are instances of that model in this tile
|
||||
WorldModel* worldModel = instance.getWorldModel();
|
||||
WorldModel const* worldModel = instance.getWorldModel();
|
||||
if (!worldModel)
|
||||
continue;
|
||||
|
||||
// now we have a model to add to the meshdata
|
||||
retval = true;
|
||||
|
||||
std::vector<GroupModel> groupModels;
|
||||
worldModel->getGroupModels(groupModels);
|
||||
std::vector<GroupModel> const& groupModels = worldModel->getGroupModels();
|
||||
|
||||
// all M2s need to have triangle indices reversed
|
||||
bool isM2 = (instance.flags & MOD_M2) != 0;
|
||||
@@ -632,14 +631,12 @@ namespace MMAP
|
||||
position.x -= 32 * GRID_SIZE;
|
||||
position.y -= 32 * GRID_SIZE;
|
||||
|
||||
for (std::vector<GroupModel>::iterator it = groupModels.begin(); it != groupModels.end(); ++it)
|
||||
for (std::vector<GroupModel>::const_iterator it = groupModels.begin(); it != groupModels.end(); ++it)
|
||||
{
|
||||
std::vector<G3D::Vector3> tempVertices;
|
||||
std::vector<G3D::Vector3> const& tempVertices = it->GetVertices();
|
||||
std::vector<G3D::Vector3> transformedVertices;
|
||||
std::vector<MeshTriangle> tempTriangles;
|
||||
WmoLiquid* liquid = nullptr;
|
||||
|
||||
it->getMeshData(tempVertices, tempTriangles, liquid);
|
||||
std::vector<MeshTriangle> const& tempTriangles = it->GetTriangles();
|
||||
WmoLiquid const* liquid = it->GetLiquid();
|
||||
|
||||
// first handle collision mesh
|
||||
transform(tempVertices, transformedVertices, scale, rotation, position);
|
||||
@@ -659,8 +656,8 @@ namespace MMAP
|
||||
liquid->getPosInfo(tilesX, tilesY, corner);
|
||||
vertsX = tilesX + 1;
|
||||
vertsY = tilesY + 1;
|
||||
uint8* flags = liquid->GetFlagsStorage();
|
||||
float* data = liquid->GetHeightStorage();
|
||||
uint8 const* flags = liquid->GetFlagsStorage();
|
||||
float const* data = liquid->GetHeightStorage();
|
||||
uint8 type = NAV_AREA_EMPTY;
|
||||
|
||||
// convert liquid type to NavTerrain
|
||||
@@ -736,12 +733,13 @@ namespace MMAP
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
void TerrainBuilder::transform(std::vector<G3D::Vector3> &source, std::vector<G3D::Vector3> &transformedVertices, float scale, G3D::Matrix3 &rotation, G3D::Vector3 &position)
|
||||
void TerrainBuilder::transform(std::vector<G3D::Vector3> const& source, std::vector<G3D::Vector3>& transformedVertices, float scale, G3D::Matrix3 const& rotation, G3D::Vector3 const& position)
|
||||
{
|
||||
for (std::vector<G3D::Vector3>::iterator it = source.begin(); it != source.end(); ++it)
|
||||
transformedVertices.reserve(transformedVertices.size() + source.size());
|
||||
for (G3D::Vector3 const& vertex : source)
|
||||
{
|
||||
// apply tranform, then mirror along the horizontal axes
|
||||
G3D::Vector3 v((*it) * rotation * scale + position);
|
||||
G3D::Vector3 v(vertex * rotation * scale + position);
|
||||
v.x *= -1.f;
|
||||
v.y *= -1.f;
|
||||
transformedVertices.push_back(v);
|
||||
@@ -749,43 +747,46 @@ namespace MMAP
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
void TerrainBuilder::copyVertices(std::vector<G3D::Vector3> &source, G3D::Array<float> &dest)
|
||||
void TerrainBuilder::copyVertices(std::vector<G3D::Vector3> const& source, G3D::Array<float>& dest)
|
||||
{
|
||||
for (std::vector<G3D::Vector3>::iterator it = source.begin(); it != source.end(); ++it)
|
||||
dest.reserve(dest.size() + source.size() * 3);
|
||||
for (G3D::Vector3 const& vertex : source)
|
||||
{
|
||||
dest.push_back((*it).y);
|
||||
dest.push_back((*it).z);
|
||||
dest.push_back((*it).x);
|
||||
dest.push_back(vertex.y);
|
||||
dest.push_back(vertex.z);
|
||||
dest.push_back(vertex.x);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
void TerrainBuilder::copyIndices(std::vector<MeshTriangle> &source, G3D::Array<int> &dest, int offset, bool flip)
|
||||
void TerrainBuilder::copyIndices(std::vector<MeshTriangle> const& source, G3D::Array<int>& dest, int offset, bool flip)
|
||||
{
|
||||
dest.reserve(dest.size() + source.size() * 3);
|
||||
if (flip)
|
||||
{
|
||||
for (std::vector<MeshTriangle>::iterator it = source.begin(); it != source.end(); ++it)
|
||||
for (MeshTriangle const& triangle : source)
|
||||
{
|
||||
dest.push_back((*it).idx2+offset);
|
||||
dest.push_back((*it).idx1+offset);
|
||||
dest.push_back((*it).idx0+offset);
|
||||
dest.push_back(triangle.idx2 + offset);
|
||||
dest.push_back(triangle.idx1 + offset);
|
||||
dest.push_back(triangle.idx0 + offset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::vector<MeshTriangle>::iterator it = source.begin(); it != source.end(); ++it)
|
||||
for (MeshTriangle const& triangle : source)
|
||||
{
|
||||
dest.push_back((*it).idx0+offset);
|
||||
dest.push_back((*it).idx1+offset);
|
||||
dest.push_back((*it).idx2+offset);
|
||||
dest.push_back(triangle.idx0 + offset);
|
||||
dest.push_back(triangle.idx1 + offset);
|
||||
dest.push_back(triangle.idx2 + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
void TerrainBuilder::copyIndices(G3D::Array<int> &source, G3D::Array<int> &dest, int offset)
|
||||
void TerrainBuilder::copyIndices(G3D::Array<int> const& source, G3D::Array<int>& dest, int offset)
|
||||
{
|
||||
int* src = source.getCArray();
|
||||
int const* src = source.getCArray();
|
||||
dest.reserve(dest.size() + source.size());
|
||||
for (int32 i = 0; i < source.size(); ++i)
|
||||
dest.append(src[i] + offset);
|
||||
}
|
||||
|
||||
@@ -101,11 +101,11 @@ namespace MMAP
|
||||
bool usesLiquids() const { return !m_skipLiquid; }
|
||||
|
||||
// vert and triangle methods
|
||||
static void transform(std::vector<G3D::Vector3> &original, std::vector<G3D::Vector3> &transformed,
|
||||
float scale, G3D::Matrix3 &rotation, G3D::Vector3 &position);
|
||||
static void copyVertices(std::vector<G3D::Vector3> &source, G3D::Array<float> &dest);
|
||||
static void copyIndices(std::vector<VMAP::MeshTriangle> &source, G3D::Array<int> &dest, int offest, bool flip);
|
||||
static void copyIndices(G3D::Array<int> &src, G3D::Array<int> &dest, int offset);
|
||||
static void transform(std::vector<G3D::Vector3> const& source, std::vector<G3D::Vector3>& transformed,
|
||||
float scale, G3D::Matrix3 const& rotation, G3D::Vector3 const& position);
|
||||
static void copyVertices(std::vector<G3D::Vector3> const& source, G3D::Array<float>& dest);
|
||||
static void copyIndices(std::vector<VMAP::MeshTriangle> const& source, G3D::Array<int>& dest, int offset, bool flip);
|
||||
static void copyIndices(G3D::Array<int> const& source, G3D::Array<int>& dest, int offset);
|
||||
static void cleanVertices(G3D::Array<float> &verts, G3D::Array<int> &tris);
|
||||
private:
|
||||
/// Loads a portion of a map's terrain
|
||||
|
||||
Reference in New Issue
Block a user