Recast Navigation
Navigation-mesh Toolset for Games
Loading...
Searching...
No Matches
Sample_TileMesh.h
Go to the documentation of this file.
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#pragma once
20
21#include "Recast.h"
22#include "Sample.h"
23
24#include <cstdint>
25
26class Sample_TileMesh : public Sample
27{
28private:
29 bool buildAll = true;
30 float totalBuildTimeMs = 0.0f;
31
32 // Recast state
33 rcConfig config{};
34 unsigned char* triareas = nullptr;
35 rcHeightfield* heightfield = nullptr;
36 rcCompactHeightfield* compactHeightfield = nullptr;
37 rcContourSet* contourSet = nullptr;
38 rcPolyMesh* polyMesh = nullptr;
39 rcPolyMeshDetail* detailPolyMesh = nullptr;
40
41 enum class DrawMode : uint8_t
42 {
43 MESH,
44 NAVMESH,
45 NAVMESH_INVIS,
46 NAVMESH_TRANS,
47 NAVMESH_BVTREE,
48 NAVMESH_NODES,
49 NAVMESH_PORTALS,
50 VOXELS,
51 VOXELS_WALKABLE,
52 COMPACT,
53 COMPACT_DISTANCE,
54 COMPACT_REGIONS,
55 REGION_CONNECTIONS,
56 RAW_CONTOURS,
57 BOTH_CONTOURS,
58 CONTOURS,
59 POLYMESH,
60 POLYMESH_DETAIL
61 };
62 DrawMode currentDrawMode = DrawMode::NAVMESH;
63 static const char* drawModeNames[];
64
65 int maxTiles = 0;
66 int maxPolysPerTile = 0;
68 int tileSize = 32;
69
70 unsigned int tileColor = duRGBA(0, 0, 0, 32);
71 float lastBuiltTileBoundsMin[3] = {0.0f, 0.0f, 0.0f};
72 float lastBuiltTileBoundsMax[3] = {0.0f, 0.0f, 0.0f};
73 float tileBuildTime = 0.0f;
74 float tileMemUsage = 0.0f;
75 int tileTriCount = 0;
76
77 unsigned char* buildTileMesh(int tileX, int tileY, const float* boundsMin, const float* boundsMax, int& outDataSize);
78
79 void cleanup();
80 void UI_DrawModeOption(DrawMode drawMode, bool enabled);
81
82public:
84 ~Sample_TileMesh() override;
89
90 // Sample methods
91 void drawSettingsUI() override;
92 void drawToolsUI() override;
93 void drawDebugUI() override;
94 void render() override;
95 void renderOverlay() override;
96 void onMeshChanged(InputGeom* geom) override;
97 bool build() override;
98 void collectSettings(BuildSettings& settings) override;
99
100 void getTilePos(const float* pos, int& outTileX, int& outTileY) const;
101
102 void buildTile(const float* pos);
103 void removeTile(const float* pos);
104 void buildAllTiles();
105 void removeAllTiles() const;
106};
unsigned int duRGBA(int r, int g, int b, int a)
Definition DebugDraw.h:76
Definition InputGeom.h:96
Definition Sample_TileMesh.h:27
Sample_TileMesh(const Sample_TileMesh &&)=delete
void renderOverlay() override
Definition Sample_TileMesh.cpp:522
void drawSettingsUI() override
Definition Sample_TileMesh.cpp:215
void getTilePos(const float *pos, int &outTileX, int &outTileY) const
Definition Sample_TileMesh.cpp:677
bool build() override
Definition Sample_TileMesh.cpp:568
~Sample_TileMesh() override
Definition Sample_TileMesh.cpp:192
void drawToolsUI() override
Definition Sample_TileMesh.cpp:278
Sample_TileMesh & operator=(const Sample_TileMesh &)=delete
Sample_TileMesh()
Definition Sample_TileMesh.cpp:186
void render() override
Definition Sample_TileMesh.cpp:348
Sample_TileMesh(const Sample_TileMesh &)=delete
void removeAllTiles() const
Definition Sample_TileMesh.cpp:780
void buildTile(const float *pos)
Definition Sample_TileMesh.cpp:627
void collectSettings(BuildSettings &settings) override
Definition Sample_TileMesh.cpp:620
void removeTile(const float *pos)
Definition Sample_TileMesh.cpp:691
void drawDebugUI() override
Definition Sample_TileMesh.cpp:321
void buildAllTiles()
Definition Sample_TileMesh.cpp:722
Sample_TileMesh & operator=(const Sample_TileMesh &&)=delete
void onMeshChanged(InputGeom *geom) override
Definition Sample_TileMesh.cpp:544
Definition Sample.h:116
Definition InputGeom.h:41
A compact, static heightfield representing unobstructed space.
Definition Recast.h:354
Specifies a configuration to use when performing Recast builds.
Definition Recast.h:217
Represents a group of related contours.
Definition Recast.h:433
A dynamic heightfield representing obstructed space.
Definition Recast.h:313
Contains triangle meshes that represent detailed height data associated with the polygons in its asso...
Definition Recast.h:487
Represents a polygon mesh suitable for use in building a navigation mesh.
Definition Recast.h:457