Plasma Engine  2.0
Loading...
Searching...
No Matches
OBJLoader.h
1#pragma once
2
3#include <Foundation/Containers/Deque.h>
4#include <Foundation/Containers/Map.h>
5#include <Foundation/Strings/String.h>
6#include <Utilities/UtilitiesDLL.h>
7
16class PL_UTILITIES_DLL plOBJLoader
17{
18public:
21 {
22 FaceVertex();
23
24 plUInt32 m_uiPositionID;
25 plUInt32 m_uiNormalID;
26 plUInt32 m_uiTexCoordID;
27 };
28
41
43 struct Face
44 {
45 Face();
46
49
52
53 // These are only calculated on demand (through ComputeTangentSpaceVectors) and only if texture-coordinates are available.
54 // Useful, when doing normal-mapping in tangent-space.
55 plVec3 m_vTangent;
56 plVec3 m_vBiTangent;
57
60
62 PL_ALWAYS_INLINE bool operator<(const Face& rhs) const { return (m_uiMaterialID < rhs.m_uiMaterialID); }
63 };
64
67 void Clear();
68
70 bool HasTextureCoordinates() const { return (!m_TexCoords.IsEmpty()); }
71
73 bool HasVertexNormals() const { return (!m_Normals.IsEmpty()); }
74
76 void ComputeTangentSpaceVectors();
77
79 void SortFacesByMaterial();
80
84 plResult LoadOBJ(const char* szFile, bool bIgnoreMaterials = false);
85
92 plResult LoadMTL(const char* szFile, const char* szMaterialBasePath = "");
93
94
95 plMap<plString, Material> m_Materials;
96
97 plDeque<plVec3> m_Positions;
98 plDeque<plVec3> m_Normals;
99 plDeque<plVec3> m_TexCoords;
100 plDeque<Face> m_Faces;
101};
Definition Deque.h:270
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Map.h:408
A loader class for OBJ/MTL files.
Definition OBJLoader.h:17
bool HasVertexNormals() const
Returns whether vertex-normals are available for this mesh. Otherwise only face-normals are available...
Definition OBJLoader.h:73
bool HasTextureCoordinates() const
Returns whether texture-coordinates are available for this mesh.
Definition OBJLoader.h:70
Holds all data about one face (ie. polygon, not only triangles).
Definition OBJLoader.h:44
plUInt32 m_uiMaterialID
The ID of the material, that this face uses.
Definition OBJLoader.h:48
plVec3 m_vNormal
The face-normal, automatically computed.
Definition OBJLoader.h:51
plHybridArray< FaceVertex, 4 > m_Vertices
All vertices of the face.
Definition OBJLoader.h:59
PL_ALWAYS_INLINE bool operator<(const Face &rhs) const
Less-than operator is needed for sorting faces by material.
Definition OBJLoader.h:62
Stores the information for a vertex in a face.
Definition OBJLoader.h:21
plUInt32 m_uiNormalID
Index into the m_Normals array.
Definition OBJLoader.h:25
plUInt32 m_uiTexCoordID
Index into the m_TexCoords array.
Definition OBJLoader.h:26
plUInt32 m_uiPositionID
Index into the m_Positions array.
Definition OBJLoader.h:24
Holds the information about one Material.
Definition OBJLoader.h:34
plUInt32 m_uiMaterialID
The ID of this material.
Definition OBJLoader.h:39
plString m_sDiffuseTexture
The path to the diffuse texture of this material.
Definition OBJLoader.h:36
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54