Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
NavMeshLoader.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
33//
34// This software is provided 'as-is', without any express or implied
35// warranty. In no event will the authors be held liable for any damages
36// arising from the use of this software.
37// Permission is granted to anyone to use this software for any purpose,
38// including commercial applications, and to alter it and redistribute it
39// freely, subject to the following restrictions:
40// 1. The origin of this software must not be misrepresented; you must not
41// claim that you wrote the original software. If you use this software
42// in a product, an acknowledgment in the product documentation would be
43// appreciated but is not required.
44// 2. Altered source versions must be plainly marked as such, and must not be
45// misrepresented as being the original software.
46// 3. This notice may not be removed or altered from any source distribution.
47//
48// Changes, Additions and Refactoring : Copyright (c) 2010-2011 Lethal Concept,
49// LLC
50// Changes, Additions and Refactoring Author: Simon Wittenberg (MD)
51// The above license is fully inherited.
52
53#pragma once
54#ifndef DVD_NAVIGATION_MESH_LOADER_H_
55#define DVD_NAVIGATION_MESH_LOADER_H_
56
57#include "NavMeshConfig.h"
60
61namespace Divide {
62namespace AI {
63namespace Navigation {
64
65// This struct contains the vertices and triangles in recast coords
67 friend class NavigationMesh;
68
69 public:
70 NavModelData() = default;
71
72 void clear()
73 {
74 _valid = false;
75
79 _vertices.clear();
80 _triangles.clear();
81 _normals.clear();
82 _triangleAreaType.clear();
83 name("");
84 }
85
86 [[nodiscard]] const F32* getVerts() const noexcept { return _vertices.empty() ? nullptr : _vertices.data(); }
87 [[nodiscard]] const F32* getNormals() const noexcept { return _normals.empty() ? nullptr : _normals.data(); }
88 [[nodiscard]] const I32* getTris() const noexcept { return _triangles.empty() ? nullptr : _triangles.data(); }
89 [[nodiscard]] U32 getVertCount() const noexcept { return _vertexCount; }
90 [[nodiscard]] U32 getTriCount() const noexcept { return _triangleCount; }
91
92 [[nodiscard]] vector<SamplePolyAreas>& getAreaTypes() noexcept { return _triangleAreaType; }
93
97
102
104 PROPERTY_R_IW(bool, valid, false);
105
106 private:
108};
109
110namespace NavigationMeshLoader {
111enum class MeshDetailLevel : U8 {
112 MAXIMUM = 0,
113 BOUNDINGBOX = 1
114};
115
117[[nodiscard]] bool LoadMeshFile(NavModelData& outData, const ResourcePath& filePath, const char* fileName);
119[[nodiscard]] bool SaveMeshFile(const NavModelData& inData, const ResourcePath& filePath, const char* filename);
121[[nodiscard]] NavModelData MergeModels(NavModelData& a, NavModelData& b, bool delOriginals = false);
123[[nodiscard]] bool Parse(const BoundingBox& box, NavModelData& outData, SceneGraphNode* sgn);
124
125void AddVertex(NavModelData* modelData, const vec3<F32>& vertex);
126
127void AddTriangle(NavModelData* modelData, const vec3<U32>& triangleIndices,
128 U32 triangleIndexOffset = 0,
130
131[[nodiscard]] char* ParseRow(char* buf, const char* const bufEnd, char* row, I32 len) noexcept;
132
133[[nodiscard]] I32 ParseFace(char* row, I32* data, I32 n, I32 vcnt) noexcept;
134}
135} // namespace Navigation
136} // namespace AI
137} // namespace Divide
138
139#endif //DVD_NAVIGATION_MESH_LOADER_H_
const F32 * getVerts() const noexcept
Definition: NavMeshLoader.h:86
vector< SamplePolyAreas > & getAreaTypes() noexcept
Definition: NavMeshLoader.h:92
PROPERTY_RW(Str< 256 >, name, "")
vector< SamplePolyAreas > _triangleAreaType
const F32 * getNormals() const noexcept
Definition: NavMeshLoader.h:87
const I32 * getTris() const noexcept
Definition: NavMeshLoader.h:88
bool SaveMeshFile(const NavModelData &inData, const ResourcePath &filePath, const char *filename)
Save the navigation input geometry in Wavefront OBJ format.
void AddVertex(NavModelData *modelData, const vec3< F32 > &vertex)
char * ParseRow(char *buf, const char *const bufEnd, char *row, I32 len) noexcept
bool LoadMeshFile(NavModelData &outData, const ResourcePath &filePath, const char *fileName)
Load the input geometry from file (Wavefront OBJ format) and save it in 'outData'.
bool Parse(const BoundingBox &box, NavModelData &outData, SceneGraphNode *sgn)
Parsing method that calls itself recursively until all geometry has been parsed.
NavModelData MergeModels(NavModelData &a, NavModelData &b, bool delOriginals=false)
Merge the data from two navigation geometry sources.
I32 ParseFace(char *row, I32 *data, I32 n, I32 vcnt) noexcept
void AddTriangle(NavModelData *modelData, const vec3< U32 > &triangleIndices, U32 triangleIndexOffset=0, const SamplePolyAreas &areaType=SamplePolyAreas::SAMPLE_POLYAREA_GROUND)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
uint32_t U32