gwnavruntime/collision/indexedmeshblob.h Source File

indexedmeshblob.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 
14 
15 namespace Kaim
16 {
17 
18 class IndexedMeshBlob
19 {
20  KY_ROOT_BLOB_CLASS(CollisionData, IndexedMeshBlob, 0)
21  KY_CLASS_WITHOUT_COPY(IndexedMeshBlob)
22 public:
23  IndexedMeshBlob() {}
24 
25  KyUInt32 GetIndexStride() const { return 3*sizeof(KyUInt32); }
26  KyUInt32 GetVertexStride() const { return sizeof(Vec3f); }
27  const UByte * GetIndexBase() const { return (const UByte*)m_indices.GetValues(); }
28  const UByte * GetVertexBase() const { return (const UByte*)m_vertices.GetValues(); }
29 
30  KyUInt32 GetTriangleCount() const { return m_indices.GetCount() / 3; }
31 
32  BlobArray<Vec3f> m_vertices;
33  BlobArray<KyUInt32> m_indices;
34 };
35 
36 inline void SwapEndianness(Kaim::Endianness::Target e, IndexedMeshBlob& self)
37 {
38  SwapEndianness(e, self.m_vertices);
39  SwapEndianness(e, self.m_indices);
40 }
41 
42 class IndexedMeshBlobBuilder : public BaseBlobBuilder<IndexedMeshBlob>
43 {
44 public:
45  enum IndexedState
46  {
47  NotIndexed = 0,
48  Indexed = 1,
49  };
50 
51  IndexedMeshBlobBuilder() : m_indexedState(NotIndexed) {}
52 
53  void Clear();
54 
55  bool IsEmpty() { return m_indices.GetCount() == 0; }
56  void AddTriangle(const Vec3f& a, const Vec3f& b, const Vec3f& c);
57 
58  virtual void DoBuild();
59 
60 private:
61  void MakeIndexed();
62 
63  KyArrayPOD<KyUInt32> m_indices;
64  KyArray<Vec3f> m_vertices;
65  IndexedState m_indexedState;
66 };
67 
68 class IndexedMeshArrayBlob
69 {
70  KY_ROOT_BLOB_CLASS(CollisionData, IndexedMeshArrayBlob, 0)
71  KY_CLASS_WITHOUT_COPY(IndexedMeshArrayBlob)
72 
73 public:
74  IndexedMeshArrayBlob() {}
75  BlobArray<IndexedMeshBlob> m_meshParts;
76 };
77 
78 inline void SwapEndianness(Kaim::Endianness::Target e, IndexedMeshArrayBlob& self)
79 {
80  SwapEndianness(e, self.m_meshParts);
81 }
82 
83 }
84 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
std::uint8_t UByte
uint8_t
Definition: SF_Types.h:134
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17