tools/navgenproj/NavGenProj.h Source File

NavGenProj.h
Go to the documentation of this file.
1 /*
2 * Copyright 2017 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
9 #include "labengine/base/filesystem.h"
11 #include "navgenproj/ProjConfig.h"
13 #include "navgenproj/ProjSector.h"
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 namespace LabEngine
22 {
23 class MirroredOBJProducer;
24 }
25 
26 namespace Kaim
27 {
28 
29 class ProjGeometry;
30 class ProjTagVolume;
31 class ProjClientInput;
32 class ProjMirrorOptions;
33 class ProjExclusiveGuids;
34 
38 {
39 public:
40  typedef LabEngine::PathUtilsString Path;
41 
42  // ------------------------------ Functions -----------------------------
43 
44  NavGenProj();
45  ~NavGenProj();
46 
48  void Clear();
49 
53  KyResult Load(const std::string& fileName);
54 
57  KyResult Save(const std::string& fileName);
58 
62  KyResult Generate(const std::string& forcedOutputBaseDir, const std::string& forcedRelativeOutputDir);
63 
64  void SetIterativeRebuildFromGenIOMode(const std::string& genIOFileName) { m_projConfig.m_genIOFileName = genIOFileName; }
65 
66  bool IsInIterativeRebuildFromGenIOMode() const { return !m_projConfig.m_genIOFileName.empty(); }
67 
68  void AddSector(std::unique_ptr<ProjSector> sector) { m_sectors.push_back(std::move(sector)); }
69 
79  KyResult AddTagVolume(const Vec3f* polylinePoints, int pointArraySize, const DynamicNavTag& navTag, float minAltitude, float maxAltitude);
80 
82  void AddSeedPoint(float x, float y, float z);
83 
85  void AddExclusiveGuids(const KyGuid* guids, KyUInt32 guidsCount);
86 
89  void AddSpecificCellToGenerate(int posx, int posy);
90 
93  void SetOutputDir(const char* outputBaseDir, const char* relativeOutputDir);
94 
95  std::string GetRelativeOutputDir() { return m_outputRelativeDir; }
96  std::string GetOutputBaseDir() { return m_outputBaseDir; }
97 
99  void SetDatabaseIndex(KyUInt32 dabaseIndex);
100  KyUInt32 GetDatabaseIndex() const;
101 
103  void SetConfig(const GeneratorParameters& params, const GeneratorRunOptions& runOptions, const CoordSystem& coordSystem);
104 
106  void SetAbstractGraphConfig(const GeneratorAbstractGraphParameters& abstractGraphParams);
107 
108  // MirrorOptions is not an SDK feature, this is an option of the NavGenProj to ease demoing/testing of large scale terrains.
109  // It emulates large scale terrain by mirroring either one sector and its geometry or only the geometry into this sector.
110  // SeedPoint and TagVolume are mirrored as well.
111  void AddMirrorOptions(const ProjMirrorOptions& mirrorOptions);
112 
113  std::string GetGeometryFileName (ProjSector* sector, int index) { return GetAbsolutePath(sector->GetGeometryFileName(index).c_str()); }
114  std::string GetClientInputFileName(ProjSector* sector, int index) { return GetAbsolutePath(sector->GetClientInputFileName(index).c_str()); }
115 
116  int GetSectorCount() const { return (int)m_sectors.size(); }
117  ProjSector* GetSector(int index) { return m_sectors[index].get(); }
118 
119  int GetSeedPointCount() const;
120  const ProjSeedPoint& GetSeedPoint(int index) const;
121 
122  // Sets the navGenProj absolute fileName. Used in GetAbsolutePath().
123  void SetNavGenProjAbsPath(const std::string& projAbsPath);
124 
125  // if path is relative then returns m_navGenProjDirectory/path or return path
126  std::string GetAbsolutePath(const std::string& path) const;
127 
128  std::string GetGenIOFileName()
129  {
130  if (m_projConfig.m_genIOFileName.empty())
131  return m_projPathStem + ".GenIO";
132  return m_projConfig.m_genIOFileName;
133  }
134 
135 public:
136  void ClearAllSpecificCellsToGenerate(); // For internal use.
137 
138  // Indicates if the NavGenProj is ready for mirroring the geometry which has to be a .obj file,
139  // the NavGenProj must contain one and only one sector which contains a ProjMirrorOptions
140  bool CanUseMirrorOptions() { return m_sectors.size() == 1 && m_mirrorOptions.m_enabled; }
141 
142  bool ReadProjectRoot(XmlNode root);
143 
144 private:
145  bool ReadOutputDir(XmlNode node);
146  bool ReadExclusiveSectors(XmlNode node);
147  bool ReadSectors(XmlNode node);
148  bool ReadSector(XmlNode node);
149  bool ReadTagVolumes(XmlNode node);
150  bool ReadTagVolume(XmlNode node);
151  bool ReadSeedPoints(XmlNode node);
152  bool ReadSeedPoint(XmlNode node);
153 
154  KyResult GenerateMirroredObj(const std::string& absoluteOutputBaseDir, const std::string& relativeOutputDir);
155  KyResult GenerateObj(const std::string& absoluteOutputBaseDir, const std::string& relativeOutputDir);
156  KyResult DoGenerate(Kaim::GeneratorInputProducer* producer, const std::string& absoluteOutputBaseDir, const std::string& relativeOutputDir);
157  Kaim::Ptr<Kaim::Generator> CreateGenerator(Kaim::Ptr<Kaim::GeneratorInputProducer> producer);
158  void InitSectorFromNavGenProj(Kaim::GeneratorSector* sector, const ProjSector* projSector);
159  void AddMirroredOBJProducerSeedPointsAndTagVolumes(ProjSector* navGenProjSector, LabEngine::MirroredOBJProducer* producer);
160  void GetValidGuid(Kaim::KyGuid& sectorGuid);
161  void InitGeneratorInputOutput(Kaim::GeneratorInputOutput& genIO, const std::string& absoluteOutputBaseDir, const std::string& relativeOutputDir);
162  KyResult RunGenerator(Kaim::Ptr<Kaim::Generator> generator, Kaim::GeneratorInputOutput& generatorInputOutput, const std::string& absoluteOutputBaseDir,
163  const std::string& relativeOutputDir);
164 
165 public:
166  // sectors, tagVolumes, arrayOfExclusiveSectors, seedPoints
167  // are maintained in these vectors instead of the m_navGenProjConfig.m_generatorInputOutput
168  std::vector<std::unique_ptr<ProjSector>> m_sectors;
169  std::vector<std::unique_ptr<ProjTagVolume>> m_tagVolumes;
170  std::vector<std::unique_ptr<ProjExclusiveGuids>> m_arrayOfExclusiveSectors;
171  std::vector<ProjSeedPoint> m_seedPoints;
172 
173  ProjConfig m_projConfig; // content of <config>
174 
175  ProjMirrorOptions m_mirrorOptions;
176 
177  KyUInt32 m_databaseIndex;
178 
179  std::string m_outputBaseDir; // content of <outputDir><baseDir> that is relative to m_navGenProjDirectory, or absolute
180  std::string m_outputRelativeDir; // content of <outputDir><relativeDir>> that is relative to <outputDir><baseDir>
181  std::string m_projAbsDir; // absolute directory of the NavGenProj file, all files in the navGenProj file are relative to this m_navGenProjDirectory
182  std::string m_projPathStem; // FileName without the directory and without the extension
183 };
184 }
185 
186 
This class is used by the NavGenProj to store configuration parameters required by the NavData genera...
Definition: ProjConfig.h:23
void SetAbstractGraphConfig(const GeneratorAbstractGraphParameters &abstractGraphParams)
Sets up the NavGenProjConfig that will be used when generating AbstractGraphs from this NavGenProj...
Definition: NavGenProj.cpp:243
KyResult Generate(const std::string &forcedOutputBaseDir, const std::string &forcedRelativeOutputDir)
Generates NavData NavGenProj.
Definition: NavGenProj.cpp:332
The NavGenProj class is a representation of the input data required for the standalone NavData genera...
Definition: NavGenProj.h:37
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
This class is used to store parameters if a sector must be mirrored cf. LabEngine::MirroredOBJProduce...
Definition: ProjMirrorOptions.h:15
This class maintains the mapping between the system of coordinate axes used by the client game engine...
Definition: coordsystem.h:119
The MirroredOBJProducer class is a concrete implementation of GeneratorInputProducer that can read th...
Definition: mirroredobjproducer.h:41
void SetDatabaseIndex(KyUInt32 dabaseIndex)
Set and get the database name and index for current generation.
Definition: NavGenProj.cpp:226
void AddExclusiveGuids(const KyGuid *guids, KyUInt32 guidsCount)
Add a exclusive guids.
Definition: NavGenProj.cpp:690
KyResult AddTagVolume(const Vec3f *polylinePoints, int pointArraySize, const DynamicNavTag &navTag, float minAltitude, float maxAltitude)
Adds a new tag volume to the NavGenProj.
Definition: NavGenProj.cpp:306
Navigation return code class.
Definition: types.h:108
An instance of this class is used to represent each input geometry file in a NavGenProj.
Definition: ProjSector.h:24
The GeneratorSector class provides a definition for a single sector to be treated by the Generator...
Definition: generatorsector.h:39
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
The KyGuid class represents a globally unique ID.
Definition: kyguid.h:20
The GeneratorInputOutput class is a central element of the generation.
Definition: generatorinputoutput.h:35
The GeneratorParameters class contains configuration parameters that control the characteristics of t...
Definition: generatorparameters.h:67
void AddSpecificCellToGenerate(int posx, int posy)
If at least one specific cell is added, the generation will only generate these cells.
Definition: NavGenProj.cpp:322
The GeneratorRunOptions class contains configuration parameters that control the way in which the Gen...
Definition: generatorrunoptions.h:43
void SetConfig(const GeneratorParameters &params, const GeneratorRunOptions &runOptions, const CoordSystem &coordSystem)
Sets up the NavGenProjConfig that will be used when generating NavData from this NavGenProj.
Definition: NavGenProj.cpp:236
The GeneratorInputProducer is an abstract base class for an object invoked by the NavData generation ...
Definition: generatorinputproducer.h:28
void AddSeedPoint(float x, float y, float z)
Add a seed point to the navGenProj.
Definition: NavGenProj.cpp:316
void SetOutputDir(const char *outputBaseDir, const char *relativeOutputDir)
Sets the outputDir, with a base path and a relative path, i.e where the Kaim::Generator outputs are w...
Definition: NavGenProj.cpp:220
std::string m_genIOFileName
.GenIO file to use based on the specified outputDir, m_generatorParams and m_generatorRunOptions will...
Definition: ProjConfig.h:34
KyResult Save(const std::string &fileName)
Saves the data in this NavGenProj object to a file on disk with the specified path and file name...
Definition: NavGenProj.cpp:245
void Clear()
Clears all information maintained by this object.
Definition: NavGenProj.cpp:48
KyResult Load(const std::string &fileName)
Loads the data contained in the .NavGenProj with the specified path and file name into this NavGenPro...
Definition: NavGenProj.cpp:198
3d vector using 32bits floating points.
Definition: vec3f.h:16
Definition: mirroredobjproducer.cpp:12