gwnavruntime/world/tagvolume.h Source File

tagvolume.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 
13 
14 namespace Kaim
15 {
16 
17 class TagVolumeBlob;
18 class BoxObstacle;
19 class CylinderObstacle;
20 class Color;
21 class Bot;
22 
25 {
29 };
30 
35 {
36 public:
37  // ---------------------------------- Main API Functions ----------------------------------
38 
40 
42  void SetDefaults()
43  {
44  m_points.Clear();
45  m_navTag.Clear();
46  m_world = nullptr;
47  m_databaseBinding = nullptr;
48  m_altitudeMin = 0.0f;
49  m_altitudeMax = 0.0f;
51  }
52 
53  // ---------------------------------- Initialization ----------------------------------
54 
56  void SetContour(const Vec2f* points, KyUInt32 pointCount);
57 
58  void InitFromTagVolumeBlob(const TagVolumeBlob& blob);
59 
65  void Init4PointsContour(const Vec2f& center, const Vec2f& edge1, const Vec2f& edge2);
66 
76  void Init6PointsContour(const Vec2f& center, const Vec2f& edge1, const Vec2f& edge2, const Vec2f& edge3);
77 
80  void InitFromBox(const Transform& transform, const Vec3f& localCenter, const Vec3f& localHalfExtents, DatabaseBinding* databaseBinding);
81 
82  void SetAltitudeRange(KyFloat32 altitudeMin, KyFloat32 altitudeMax)
83  {
84  m_altitudeMin = altitudeMin;
85  m_altitudeMax = altitudeMax;
86  }
87 
88 public:
89  // ---------------------------------- Public Data Members ----------------------------------
90 
93 
96  Ptr<DatabaseBinding> m_databaseBinding;
97 
99  DynamicNavTag m_navTag;
100 
104 
105  KyFloat32 m_altitudeMin;
106  KyFloat32 m_altitudeMax;
107 
108  TagVolumeExtendOptions m_extendOptions;
109 };
110 
111 
119 class TagVolume : public WorldElement
120 {
121  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_TagVolume)
123 
124 public:
125  enum WorldStatus
126  {
127  WorldStatus_NotInit = 0,
128  WorldStatus_Added,
129  WorldStatus_NotAdded,
130  WorldStatus_Unknown
131  };
132 
133  enum IntegrationStatus
134  {
135  IntegrationStatus_NotIntegrated = 0,
136  IntegrationStatus_ToBeIntegrated,
137  IntegrationStatus_IntegrationInProcess,
138  IntegrationStatus_Integrated,
139  IntegrationStatus_ToBeDeintegrated,
140  IntegrationStatus_DeintegrationInProcess
141  };
142 
143  enum ObstacleType
144  {
145  ObstacleType_Undefined = 0,
146  ObstacleType_BoxObstacle,
147  ObstacleType_CylinderObstacle,
148  ObstacleType_Bot,
149  };
150 
151 public:
152  static WorldElementType GetStaticType() { return TypeTagVolume; }
153  virtual WorldElementType GetType() const { return TypeTagVolume; }
154 
155  virtual const char* GetTypeName() const { return "TagVolume"; }
156 
157  static const char* GetWorldStatusDescription(WorldStatus status);
158  static const char* GetIntegrationStatusDescription(IntegrationStatus status);
159  static const char* GetObstacleTypeName(ObstacleType obstacleType);
160 
161  TagVolume();
162  ~TagVolume();
163 
170  KyResult Init(const TagVolumeInitConfig& initConfig);
171 
179  void AddToWorld();
180 
186  void RemoveFromWorld();
187 
188 
189  // ---------------------------------- Getters ----------------------------------
190 
191  const Box3f& GetAABB() const { return m_aabb; }
192  KyFloat32 GetAltitudeMin() const { return m_aabb.m_min.z; }
193  KyFloat32 GetAltitudeMax() const { return m_aabb.m_max.z; }
194  KyUInt32 GetPointCount() const { return m_points.GetCount(); }
195  const Vec2f* GetPoints() const { return m_points.GetDataPtr(); }
196  const Vec2f& GetPoint(KyUInt32 i) const { return m_points[i]; }
197  const DynamicNavTag& GetNavTag() const { return m_navTag; }
198  WorldStatus GetWorldStatus() const { return m_currentWorldStatus; }
199  IntegrationStatus GetIntegrationStatus() const { return m_integrationStatus; }
200  ObstacleType GetObstacleType() const { return m_obstacleType; }
201  void* GetObstacleRawPtr() const { return m_obstacleRawPtr; }
202  TagVolumeExtendOptions GetTagVolumeExtendOptions() const { return m_extendOptions; }
203  const DatabaseBinding* GetDatabaseBinding() const { return GetTagVolumeDatabaseData().m_databaseBinding; }
204  BoxObstacle* GetBoxObstacle() const { return ((m_obstacleType == ObstacleType_BoxObstacle) ? (BoxObstacle*)m_obstacleRawPtr : nullptr); }
205  CylinderObstacle* GetCylinderObstacle() const { return ((m_obstacleType == ObstacleType_CylinderObstacle) ? (CylinderObstacle*)m_obstacleRawPtr : nullptr); }
206  Bot* GetBot() const { return ((m_obstacleType == ObstacleType_Bot) ? (Bot*)m_obstacleRawPtr : nullptr); }
207 
208 
209 public: // internal
210  virtual void DoSendVisualDebug(VisualDebugServer& server, VisualDebugSendChangeEvent changeEvent); // Inherited from WorldElement
211  void SetObstacle(BoxObstacle* obstacle);
212  void SetObstacle(CylinderObstacle* obstacle);
213  void SetObstacle(Bot* bot);
214  void ResetObstacle();
215 
216  void OnIntegrationStart();
217  void OnDeIntegrationStart();
218 
219  void OnIntegrationDone();
220  void OnDeIntegrationDone();
221 
222  void OnIntegrationCancelled();
223  void OnDeIntegrationCancelled();
224 
225  const TagVolumeDatabaseData& GetTagVolumeDatabaseData() const { return m_tagVolumeDatabaseData; }
226  TagVolumeDatabaseData& GetTagVolumeDatabaseData() { return m_tagVolumeDatabaseData; }
227 
228  KyResult GetExpandedContour(KyFloat32 radius, KyFloat32 mergePointDistance, KyArray<Vec2f>& expandedContour) const;
229 
230  void SetWorld(World* world) { m_world = world; }
231 
232 private:
233  void SetContourFromInitConfigAccordingToWinding(const TagVolumeInitConfig& initConfig);
234 
235  // AABB & point array are private to force PushPoint(...) usage to ensure coherency.
236  // AABB, point array and NavTag are private to trigger an update when modified.
237  // TagVolumeSpatialization is private to force read-only access.
238  Box3f m_aabb;
240  DynamicNavTag m_navTag;
241 
242  TagVolumeDatabaseData m_tagVolumeDatabaseData;
243  TagVolumeExtendOptions m_extendOptions;
244 
245  ObstacleType m_obstacleType;
246  void* m_obstacleRawPtr;
247  TagVolumeCylinderExpander m_cylinderExpander;
248  TagVolumeBoxExpander m_boxExpander;
249 
250 public: // For internal use only
251  WorldStatus m_currentWorldStatus;
252  WorldStatus m_nextWorldStatus;
253  IntegrationStatus m_integrationStatus;
254 
255  // visual debug
256  bool m_needToSendNewContextBlob;
257  bool m_needToSendTagVolumeBlob;
258 };
259 
260 
261 } // namespace Kaim
262 
263 
TagVolumeInitConfig provides TagVolume initialization parameters.
Definition: tagvolume.h:34
CylinderObstacles represent dynamic objects of your game engine that prevent your Bots from moving fr...
Definition: cylinderobstacle.h:76
This class is the world element that represent an active character in Autodesk Navigation.
Definition: bot.h:128
void InitFromTagVolumeBlob(const TagVolumeBlob &blob)
neither the World nor the DatabaseBinding are set
Definition: tagvolume.cpp:39
Indicates the altitude tolerance of the database will be removed from Zmin.
Definition: tagvolume.h:28
void Init6PointsContour(const Vec2f &center, const Vec2f &edge1, const Vec2f &edge2, const Vec2f &edge3)
Writes 6(+1) pos in m_points with points[last] == points[0].
Definition: tagvolume.cpp:53
DynamicNavTag m_navTag
This DynamicNavTag will be translated as NavTag in the DynamicNavMesh floors generated in the TagVolu...
Definition: tagvolume.h:99
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
void AddToWorld()
Adds the TagVolume to the World.
Definition: tagvolume.cpp:199
KyResult Init(const TagVolumeInitConfig &initConfig)
Initialize the TagVolume accordingly to the informations passed through the TagVolumeInitConfig.
Definition: tagvolume.cpp:144
void SetDefaults()
Sets all members to their default value.
Definition: tagvolume.h:42
Indicates the altitude tolerance of the database will be added to Zmax.
Definition: tagvolume.h:26
KyArray< Vec2f > m_points
m_points respect points[last] = points[last] m_points can be CW or CCW, TagVolume::Init() will make t...
Definition: tagvolume.h:103
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:162
TagVolumeExtendOptions
TagVolumeExtendOptions.
Definition: tagvolume.h:24
void InitFromBox(const Transform &transform, const Vec3f &localCenter, const Vec3f &localHalfExtents, DatabaseBinding *databaseBinding)
If the oriented box 2d projection is a 4 points shape, writes 4(+1) points.
Definition: tagvolume.cpp:82
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
This class is a runtime container for Autodesk Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:52
Ptr< DatabaseBinding > m_databaseBinding
Defines the Databases in which the TagVolume will be spatialized.
Definition: tagvolume.h:96
Indicates the altitude tolerance of the database will be removed from Zmin.
Definition: tagvolume.h:27
void Init4PointsContour(const Vec2f &center, const Vec2f &edge1, const Vec2f &edge2)
Writes 4(+1) pos in m_points with m_points[last] == m_points[0].
Definition: tagvolume.cpp:48
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
void SetWorld(World *world)
WARNING Very internal. Used only internally during the generation process.
Definition: tagvolume.h:230
This class represents runtime-defined volumes with customized NavTag.
Definition: tagvolume.h:119
3d axis aligned box of 32bits floating points
Definition: box3f.h:16
2d vector using KyFloat32.
Definition: vec2f.h:18
Navigation return code class.
Definition: types.h:108
DatabaseBinding is a collection of the databases to be used for world elements spatialization.
Definition: databasebinding.h:21
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:13
Base internal class used to represent elements that can be added to a World, such as instances of Dat...
Definition: worldelement.h:41
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
void SetContour(const Vec2f *points, KyUInt32 pointCount)
Writes points in m_points plus potentially one additional point to make sure m_points[last] == m_poin...
Definition: tagvolume.cpp:21
World * m_world
Mandatory: you must provide a World when calling TagVolume::Init().
Definition: tagvolume.h:92
Each TagVolume instance aggregates one instance of this class to maintain its spatialization informat...
Definition: tagvolumespatialization.h:42
Matrix3x3f rotation and Vec3f translation.
Definition: transform.h:16
Each instance of the BoxObstacle class represents a dynamic, physical object in your game engine that...
Definition: boxobstacle.h:127
void RemoveFromWorld()
Removes the TagVolume from the World.
Definition: tagvolume.cpp:283
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16