TrinityCore
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 "PathCommon.h"
22#include "WorldModel.h"
23
24#include <G3D/Array.h>
25#include <G3D/Vector3.h>
26
28
29namespace MMAP
30{
31 enum Spot
32 {
33 TOP = 1,
34 RIGHT = 2,
35 LEFT = 3,
36 BOTTOM = 4,
37 ENTIRE = 5
38 };
39
40 enum Grid
41 {
44 };
45
46 static const int V9_SIZE = 129;
47 static const int V9_SIZE_SQ = V9_SIZE*V9_SIZE;
48 static const int V8_SIZE = 128;
49 static const int V8_SIZE_SQ = V8_SIZE*V8_SIZE;
50 static const float GRID_SIZE = 533.3333f;
51 static const float GRID_PART_SIZE = GRID_SIZE/V8_SIZE;
52
53 // see contrib/extractor/system.cpp, CONF_use_minHeight
54 static const float INVALID_MAP_LIQ_HEIGHT = -2000.f;
55 static const float INVALID_MAP_LIQ_HEIGHT_MAX = 5000.0f;
56
57 // see following files:
58 // contrib/extractor/system.cpp
59 // src/game/Map.cpp
60
62 {
66 float From[3];
67 float To[3];
69 float Radius;
72 };
73
74 struct MeshData
75 {
76 G3D::Array<float> solidVerts;
77 G3D::Array<int> solidTris;
78
79 G3D::Array<float> liquidVerts;
80 G3D::Array<int> liquidTris;
81 G3D::Array<uint8> liquidType;
82
83 // offmesh connection data
84 G3D::Array<float> offMeshConnections; // [p0y,p0z,p0x,p1y,p1z,p1x] - per connection
85 G3D::Array<float> offMeshConnectionRads;
86 G3D::Array<unsigned char> offMeshConnectionDirs;
87 G3D::Array<unsigned char> offMeshConnectionsAreas;
88 G3D::Array<unsigned short> offMeshConnectionsFlags;
89 };
90
92 {
93 public:
94 TerrainBuilder(bool skipLiquid);
96
97 void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData);
98 bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData);
99 void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, std::vector<OffMeshData> const& offMeshConnections);
100
101 bool usesLiquids() const { return !m_skipLiquid; }
102
103 // vert and triangle methods
104 static void transform(std::vector<G3D::Vector3> const& source, std::vector<G3D::Vector3>& transformed,
105 float scale, G3D::Matrix3 const& rotation, G3D::Vector3 const& position);
106 static void copyVertices(std::vector<G3D::Vector3> const& source, G3D::Array<float>& dest);
107 static void copyIndices(std::vector<VMAP::MeshTriangle> const& source, G3D::Array<int>& dest, int offset, bool flip);
108 static void copyIndices(G3D::Array<int> const& source, G3D::Array<int>& dest, int offset);
109 static void cleanVertices(G3D::Array<float> &verts, G3D::Array<int> &tris);
110 private:
112 bool loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, Spot portion);
113
115 void getLoopVars(Spot portion, int &loopStart, int &loopEnd, int &loopInc);
116
119
121 bool loadHeightMap(uint32 mapID, uint32 tileX, uint32 tileY, G3D::Array<float> &vertices, G3D::Array<int> &triangles, Spot portion);
122
124 void getHeightCoord(int index, Grid grid, float xOffset, float yOffset, float* coord, float* v);
125
127 void getHeightTriangle(int square, Spot triangle, int* indices, bool liquid = false);
128
130 bool isHole(int square, uint8 const holes[16][16][8]);
131
133 void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float* coord, float* v);
134
137
138 // hide parameterless and copy constructor
139 TerrainBuilder() = delete;
140 TerrainBuilder(TerrainBuilder const& tb) = delete;
141 };
142}
143
144#endif
uint8_t uint8
Definition: Define.h:144
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
map_liquidHeaderTypeFlags
Definition: MapDefines.h:97
uint8 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID][8]
Definition: System.cpp:439
T square(T x)
Definition: Util.h:103
Definition: Grid.h:46
TerrainBuilder(TerrainBuilder const &tb)=delete
void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, std::vector< OffMeshData > const &offMeshConnections)
bool isHole(int square, uint8 const holes[16][16][8])
Determines if the specific position's triangles should be rendered.
bool loadHeightMap(uint32 mapID, uint32 tileX, uint32 tileY, G3D::Array< float > &vertices, G3D::Array< int > &triangles, Spot portion)
Load the map terrain from file.
static void copyIndices(std::vector< VMAP::MeshTriangle > const &source, G3D::Array< int > &dest, int offset, bool flip)
static void cleanVertices(G3D::Array< float > &verts, G3D::Array< int > &tris)
bool m_skipLiquid
Controls whether liquids are loaded.
void getHeightTriangle(int square, Spot triangle, int *indices, bool liquid=false)
Get the triangle's vector indices for a specific position.
void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
bool usesLiquids() const
void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float *coord, float *v)
Get the liquid vector coordinate for a specific position.
static void transform(std::vector< G3D::Vector3 > const &source, std::vector< G3D::Vector3 > &transformed, float scale, G3D::Matrix3 const &rotation, G3D::Vector3 const &position)
bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
void getHeightCoord(int index, Grid grid, float xOffset, float yOffset, float *coord, float *v)
Get the vector coordinate for a specific position.
static void copyVertices(std::vector< G3D::Vector3 > const &source, G3D::Array< float > &dest)
void getLoopVars(Spot portion, int &loopStart, int &loopEnd, int &loopInc)
Sets loop variables for selecting only certain parts of a map's terrain.
map_liquidHeaderTypeFlags getLiquidType(int square, map_liquidHeaderTypeFlags const (&liquid_type)[16][16])
Get the liquid type for a specific position.
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
static const int V8_SIZE
static const int V9_SIZE_SQ
static const int V8_SIZE_SQ
G3D::Array< float > liquidVerts
G3D::Array< float > offMeshConnectionRads
G3D::Array< unsigned char > offMeshConnectionDirs
G3D::Array< float > offMeshConnections
G3D::Array< unsigned short > offMeshConnectionsFlags
G3D::Array< float > solidVerts
G3D::Array< int > liquidTris
G3D::Array< int > solidTris
G3D::Array< unsigned char > offMeshConnectionsAreas
G3D::Array< uint8 > liquidType