TrinityCore
Loading...
Searching...
No Matches
TerrainBuilder.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _MMAP_TERRAIN_BUILDER_H
19#define _MMAP_TERRAIN_BUILDER_H
20
21#include "MMapDefines.h"
22#include "WorldModel.h"
23#include <G3D/Vector3.h>
24#include <boost/filesystem/path.hpp>
25
26namespace VMAP
27{
28class VMapManager;
29}
30
32
33namespace MMAP
34{
35 enum Spot
36 {
37 TOP = 1,
38 RIGHT = 2,
39 LEFT = 3,
40 BOTTOM = 4,
41 ENTIRE = 5
42 };
43
44 enum Grid
45 {
48 };
49
50 static const int V9_SIZE = 129;
51 static const int V9_SIZE_SQ = V9_SIZE*V9_SIZE;
52 static const int V8_SIZE = 128;
53 static const int V8_SIZE_SQ = V8_SIZE*V8_SIZE;
54 static const float GRID_SIZE = 533.3333f;
55 static const float GRID_PART_SIZE = GRID_SIZE/V8_SIZE;
56
57 // see contrib/extractor/system.cpp, CONF_use_minHeight
58 static const float INVALID_MAP_LIQ_HEIGHT = -2000.f;
59 static const float INVALID_MAP_LIQ_HEIGHT_MAX = 5000.0f;
60
61 // see following files:
62 // contrib/extractor/system.cpp
63 // src/game/Map.cpp
64
65 struct MeshData
66 {
67 std::vector<float> solidVerts;
68 std::vector<int> solidTris;
69
70 std::vector<float> liquidVerts;
71 std::vector<int> liquidTris;
72 std::vector<uint8> liquidType;
73
74 // offmesh connection data
75 std::vector<float> offMeshConnections; // [p0y,p0z,p0x,p1y,p1z,p1x] - per connection
76 std::vector<float> offMeshConnectionRads;
77 std::vector<unsigned char> offMeshConnectionDirs;
78 std::vector<unsigned char> offMeshConnectionsAreas;
79 std::vector<unsigned short> offMeshConnectionsFlags;
80 };
81
83 {
84 public:
85 explicit TerrainBuilder(boost::filesystem::path const& inputDirectory, bool skipLiquid);
86
87 void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager);
88 bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager);
89 void loadVMapModel(VMAP::WorldModel const* worldModel, G3D::Vector3 const& position, G3D::Matrix3 const& rotation, float scale,
90 MeshData& meshData, VMAP::VMapManager* vmapManager);
91 void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, std::vector<OffMeshData> const& offMeshConnections);
92
93 bool usesLiquids() const { return !m_skipLiquid; }
94
95 // vert and triangle methods
96 static void transformVertices(std::vector<G3D::Vector3> const& source, std::vector<float>& dest,
97 float scale, G3D::Matrix3 const& rotation, G3D::Vector3 const& position);
98 static void copyIndices(std::vector<VMAP::MeshTriangle> const& source, std::vector<int>& dest, int offset, bool flip);
99 static void copyIndices(std::vector<int> const& source, std::vector<int>& dest, int offset);
100 static void cleanVertices(std::vector<float>& verts, std::vector<int>& tris);
101 private:
103 bool loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager, Spot portion);
104
106 static void getLoopVars(Spot portion, int& loopStart, int& loopEnd, int& loopInc);
107
108 boost::filesystem::path m_inputDirectory;
109
112
114 static void getHeightCoord(int index, Grid grid, float xOffset, float yOffset, float* coord, float* v);
115
117 static void getHeightTriangle(int square, Spot triangle, int* indices, int offset, bool liquid = false);
118
120 static bool isHole(int square, uint8 const (&holes)[16][16][8]);
121
123 static void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float* coord, float* v);
124
126 static map_liquidHeaderTypeFlags getLiquidType(int square, map_liquidHeaderTypeFlags const (&liquid_type)[16][16]);
127 };
128
129 TC_MMAPS_COMMON_API extern std::unique_ptr<VMAP::VMapManager> (*CreateVMapManager)(uint32 mapId);
130}
131
132#endif
uint8_t uint8
Definition Define.h:156
#define TC_MMAPS_COMMON_API
Definition Define.h:135
uint32_t uint32
Definition Define.h:154
map_liquidHeaderTypeFlags
Definition MapDefines.h:97
Definition Grid.h:42
bool m_skipLiquid
Controls whether liquids are loaded.
bool usesLiquids() const
boost::filesystem::path m_inputDirectory
static const float GRID_SIZE
static const float INVALID_MAP_LIQ_HEIGHT_MAX
static const int V9_SIZE
static const float GRID_PART_SIZE
static const float INVALID_MAP_LIQ_HEIGHT
std::unique_ptr< VMAP::VMapManager >(* CreateVMapManager)(uint32 mapId)
static const int V8_SIZE
static const int V9_SIZE_SQ
static const int V8_SIZE_SQ
std::vector< uint8 > liquidType
std::vector< float > liquidVerts
std::vector< unsigned short > offMeshConnectionsFlags
std::vector< float > solidVerts
std::vector< int > solidTris
std::vector< int > liquidTris
std::vector< float > offMeshConnections
std::vector< unsigned char > offMeshConnectionDirs
std::vector< float > offMeshConnectionRads
std::vector< unsigned char > offMeshConnectionsAreas