gwnavruntime/utils/objfilereader.h Source File

objfilereader.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 
8 // primary contact: JAPA - secondary contact: GUAL
9 #ifndef Navigatio_ObjFileReader_H
10 #define Navigatio_ObjFileReader_H
11 
17 
18 namespace Kaim
19 {
20 
21 class FileOpenerBase;
22 class CoordSystem;
23 
26 {
27  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
29 public:
30  ObjFileReader();
31 
32  ~ObjFileReader();
33 
34  KyResult ReadObjFile(Ptr<File> objFileToRead);
35 
36  // ---------------------------------- Parsed data ----------------------------------
37  KyUInt32 VerticesCount() const { return m_vertices.GetCount(); }
38  const Vec3f* Vertices() const { return m_vertices.GetDataPtr(); }
39 
40  KyUInt32 IndicesCount() const { return m_indices.GetCount(); }
41  const KyUInt32* Indices() const { return m_indices.GetDataPtr(); }
42 
43  KyUInt32 GetFacesCount() const { return m_facesCount; }
44  KyUInt32 GetFaceMinVertexCount() const { return m_faceMinVertexCount; }
45  KyUInt32 GetFaceMaxVertexCount() const { return m_faceMaxVertexCount; }
46 
47  // ---------------------------------- Misc ----------------------------------
48  void Clear();
49 
51  Box3f ComputeBoundingBox() const;
52  Box3f ComputeBoundingBox(const CoordSystem& coordSystem) const;
53 
54  const char* GetFileName() const { return m_file != KY_NULL ? m_file->GetFilePath() : KY_NULL; }
55 
56 private:
57  KyResult ReadPosition(const char* str, Vec3f& pos);
58  KyResult ReadFace(const char* str);
59  KyResult ReadFaceFast(const char* str);
60 
61  KyResult ReadContent();
62 
63  KyResult ReadNextChunk();
64  char* ReadLine();
65 
66 private:
67  char* m_line;
68  char* m_fileIOBuffer;
69  const char* m_endOfReadFileChunk;
70  char* m_currentPosInBuffer;
71  Ptr<File> m_file;
72 
73  const KyUInt32 m_maxLineSize;
74  const KyUInt32 m_maxBufferSize;
75 
76  KyUInt32 m_facesCount;
77  KyUInt32 m_faceMinVertexCount;
78  KyUInt32 m_faceMaxVertexCount;
79 
80  // current file data
81  KyArray<Vec3f> m_vertices;
82  KyArrayPOD<KyUInt32> m_indices;
83  KyArrayPOD<KyUInt32> m_faceIndices;
84 };
85 
86 
87 }
88 
89 
90 #endif // Navigatio_ObjFileReader_H
91 
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
This class maintains the mapping between the system of coordinate axes used internally within the gam...
Definition: coordsystem.h:144
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:118
#define KY_NULL
Null value.
Definition: types.h:247
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
A basic parser of .obj files in text format able to read triangles.
Definition: objfilereader.h:25
This class represents a three-dimensional axis-aligned bounding box whose dimensions are stored using...
Definition: box3f.h:25
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23
Box3f ComputeBoundingBox() const
Will browse all the vertices extracted from file and compute a bounding box from them.