1 //
2 // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty.  In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 //    claim that you wrote the original software. If you use this software
12 //    in a product, an acknowledgment in the product documentation would be
13 //    appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 //    misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18 
19 #ifndef INPUTGEOM_H
20 #define INPUTGEOM_H
21 
22 #include "ChunkyTriMesh.h"
23 #include "MeshLoaderObj.h"
24 
25 static const int MAX_CONVEXVOL_PTS = 12;
26 struct ConvexVolume
27 {
28 	float verts[MAX_CONVEXVOL_PTS*3];
29 	float hmin, hmax;
30 	int nverts;
31 	int area;
32 };
33 
34 struct BuildSettings
35 {
36 	// Cell size in world units
37 	float cellSize;
38 	// Cell height in world units
39 	float cellHeight;
40 	// Agent height in world units
41 	float agentHeight;
42 	// Agent radius in world units
43 	float agentRadius;
44 	// Agent max climb in world units
45 	float agentMaxClimb;
46 	// Agent max slope in degrees
47 	float agentMaxSlope;
48 	// Region minimum size in voxels.
49 	// regionMinSize = sqrt(regionMinArea)
50 	float regionMinSize;
51 	// Region merge size in voxels.
52 	// regionMergeSize = sqrt(regionMergeArea)
53 	float regionMergeSize;
54 	// Edge max length in world units
55 	float edgeMaxLen;
56 	// Edge max error in voxels
57 	float edgeMaxError;
58 	float vertsPerPoly;
59 	// Detail sample distance in voxels
60 	float detailSampleDist;
61 	// Detail sample max error in voxel heights.
62 	float detailSampleMaxError;
63 	// Partition type, see SamplePartitionType
64 	int partitionType;
65 	// Bounds of the area to mesh
66 	float navMeshBMin[3];
67 	float navMeshBMax[3];
68 	// Size of the tiles in voxels
69 	float tileSize;
70 };
71 
72 class InputGeom
73 {
74 	rcChunkyTriMesh* m_chunkyMesh;
75 	rcMeshLoaderObj* m_mesh;
76 	float m_meshBMin[3], m_meshBMax[3];
77 	BuildSettings m_buildSettings;
78 	bool m_hasBuildSettings;
79 
80 	/// @name Off-Mesh connections.
81 	///@{
82 	static const int MAX_OFFMESH_CONNECTIONS = 256;
83 	float m_offMeshConVerts[MAX_OFFMESH_CONNECTIONS*3*2];
84 	float m_offMeshConRads[MAX_OFFMESH_CONNECTIONS];
85 	unsigned char m_offMeshConDirs[MAX_OFFMESH_CONNECTIONS];
86 	unsigned char m_offMeshConAreas[MAX_OFFMESH_CONNECTIONS];
87 	unsigned short m_offMeshConFlags[MAX_OFFMESH_CONNECTIONS];
88 	unsigned int m_offMeshConId[MAX_OFFMESH_CONNECTIONS];
89 	int m_offMeshConCount;
90 	///@}
91 
92 	/// @name Convex Volumes.
93 	///@{
94 	static const int MAX_VOLUMES = 256;
95 	ConvexVolume m_volumes[MAX_VOLUMES];
96 	int m_volumeCount;
97 	///@}
98 
99 	bool loadMesh(class rcContext* ctx, const std::string& filepath);
100 	bool loadGeomSet(class rcContext* ctx, const std::string& filepath);
101 public:
102 	InputGeom();
103 	~InputGeom();
104 
105 
106 	bool load(class rcContext* ctx, const std::string& filepath);
107 	bool saveGeomSet(const BuildSettings* settings);
108 
109 	/// Method to return static mesh data.
getMesh()110 	const rcMeshLoaderObj* getMesh() const { return m_mesh; }
getMeshBoundsMin()111 	const float* getMeshBoundsMin() const { return m_meshBMin; }
getMeshBoundsMax()112 	const float* getMeshBoundsMax() const { return m_meshBMax; }
getNavMeshBoundsMin()113 	const float* getNavMeshBoundsMin() const { return m_hasBuildSettings ? m_buildSettings.navMeshBMin : m_meshBMin; }
getNavMeshBoundsMax()114 	const float* getNavMeshBoundsMax() const { return m_hasBuildSettings ? m_buildSettings.navMeshBMax : m_meshBMax; }
getChunkyMesh()115 	const rcChunkyTriMesh* getChunkyMesh() const { return m_chunkyMesh; }
getBuildSettings()116 	const BuildSettings* getBuildSettings() const { return m_hasBuildSettings ? &m_buildSettings : 0; }
117 	bool raycastMesh(float* src, float* dst, float& tmin);
118 
119 	/// @name Off-Mesh connections.
120 	///@{
getOffMeshConnectionCount()121 	int getOffMeshConnectionCount() const { return m_offMeshConCount; }
getOffMeshConnectionVerts()122 	const float* getOffMeshConnectionVerts() const { return m_offMeshConVerts; }
getOffMeshConnectionRads()123 	const float* getOffMeshConnectionRads() const { return m_offMeshConRads; }
getOffMeshConnectionDirs()124 	const unsigned char* getOffMeshConnectionDirs() const { return m_offMeshConDirs; }
getOffMeshConnectionAreas()125 	const unsigned char* getOffMeshConnectionAreas() const { return m_offMeshConAreas; }
getOffMeshConnectionFlags()126 	const unsigned short* getOffMeshConnectionFlags() const { return m_offMeshConFlags; }
getOffMeshConnectionId()127 	const unsigned int* getOffMeshConnectionId() const { return m_offMeshConId; }
128 	void addOffMeshConnection(const float* spos, const float* epos, const float rad,
129 							  unsigned char bidir, unsigned char area, unsigned short flags);
130 	void deleteOffMeshConnection(int i);
131 	void drawOffMeshConnections(struct duDebugDraw* dd, bool hilight = false);
132 	///@}
133 
134 	/// @name Box Volumes.
135 	///@{
getConvexVolumeCount()136 	int getConvexVolumeCount() const { return m_volumeCount; }
getConvexVolumes()137 	const ConvexVolume* getConvexVolumes() const { return m_volumes; }
138 	void addConvexVolume(const float* verts, const int nverts,
139 						 const float minh, const float maxh, unsigned char area);
140 	void deleteConvexVolume(int i);
141 	void drawConvexVolumes(struct duDebugDraw* dd, bool hilight = false);
142 	///@}
143 
144 private:
145 	// Explicitly disabled copy constructor and copy assignment operator.
146 	InputGeom(const InputGeom&);
147 	InputGeom& operator=(const InputGeom&);
148 };
149 
150 #endif // INPUTGEOM_H
151