ezEngine  Milestone 7
OBJLoader.h
1 #pragma once
2 
3 #include <CoreUtils/Basics.h>
4 #include <Foundation/Strings/String.h>
5 
14 class EZ_COREUTILS_DLL ezOBJLoader
15 {
16 public:
17 
19  struct FaceVertex
20  {
21  FaceVertex();
22 
23  ezUInt32 m_uiPositionID;
24  ezUInt32 m_uiNormalID;
25  ezUInt32 m_uiTexCoordID;
26  };
27 
32  struct Material
33  {
36 
38  ezUInt32 m_uiMaterialID;
39  };
40 
42  struct Face
43  {
44  Face();
45 
47  ezUInt32 m_uiMaterialID;
48 
51 
52  // These are only calculated on demand (through ComputeTangentSpaceVectors) and only if texture-coordinates are available.
53  // Useful, when doing normal-mapping in tangent-space.
54  ezVec3 m_vTangent;
55  ezVec3 m_vBiTangent;
56 
59 
61  EZ_FORCE_INLINE bool operator< (const Face& rhs) const
62  {
63  return (m_uiMaterialID < rhs.m_uiMaterialID);
64  }
65  };
66 
68  void Clear();
69 
71  bool HasTextureCoordinates() const { return (!m_TexCoords.IsEmpty()); }
72 
74  bool HasVertexNormals() const { return (!m_Normals.IsEmpty()); }
75 
77  void ComputeTangentSpaceVectors();
78 
80  void SortFacesByMaterial();
81 
85  ezResult LoadOBJ(const char* szFile, bool bIgnoreMaterials = false);
86 
93  ezResult LoadMTL(const char* szFile, const char* szMaterialBasePath = "");
94 
95 
96  ezMap<ezString, Material> m_Materials;
97 
98  ezDeque<ezVec3> m_Positions;
99  ezDeque<ezVec3> m_Normals;
100  ezDeque<ezVec3> m_TexCoords;
101  ezDeque<Face> m_Faces;
102 };
103 
104 
105 
106