Содержание
Utilities |
---|
This is a simple reader for WaveFront OBJ mesh data files used by meshconvert and uvatlas, as well as a few samples.
Header
#include "WaveFrontReader.h"
Namespace
The template class in this header is in the global C++ namespace.
Template class
template<class index_t> class WaveFrontReader;
Methods
-
Load: Loads the given WaveFront OBJ file into the reader instance. If the parameter ccw is true (the default), then the face-winding is flipped. This is useful for dealing with models designed for left/right-handed view, but the rendering is using the opposite.
-
LoadMTL: This loads the
mtl
material file associated with the WaveFront OBJ file. This method is invoked if themtllib
element is found in the OBJ file. -
Clear: This clears all data from the instance.
-
LoadVBO: This loads a
vbo
binary file (a simple format created for samples) into the instance. This creates a since default material sincevbo
contains only an IB (16-bit) and a VB.
Member variables
-
vertices: This is a vector of
Vertex
instances. See remarks for details. -
indices: A vector of indices which is
3 *
the number of faces in length. -
attributes: A vector with one entry for each face indicating the material.
-
materials: A Vector of
Material
information. See remarks for details. -
name: This is set to the root filename of the loaded file (if any).
-
bounds: Bounding box of vertex locations computed by the loader.
Remarks
Vertex data is limited to the following structure (hasNormals
and hasTexcoords
member variables indicate if the relevant vertex data is valid):
struct Vertex
{
DirectX::XMFLOAT3 position;
DirectX::XMFLOAT3 normal;
DirectX::XMFLOAT2 textureCoordinate;
};
This reader returns all vertex/index data as a single object as it ignores the g
group name elements. All polygons are triangulated.
The WaveFrontReader
supports both 16-bit and 32-bit indices via a C++ template:
WaveFrontReader<uint16_t> wfReader;
HRESULT hr = wfReader.Load(L"cup.obj");
if (FAILED(hr))
WaveFrontReader<uint32_t> wfReader;
HRESULT hr = wfReader.Load(L"cup.obj");
if (FAILED(hr))
The attributes
member provides the material index for each triangular face in the loaded mesh. Materials data is returned in the following structure. The materials file parsing supports a few 'unofficial extensions': Ke
, map_Ks
, map_Ke
, map_RMA
, map_ORM
.
struct Material
{
DirectX::XMFLOAT3 vAmbient; // Ka
DirectX::XMFLOAT3 vDiffuse; // Kd
DirectX::XMFLOAT3 vSpecular; // Ks
DirectX::XMFLOAT3 vEmissive; // Ke
uint32_t nShininess; // Ns
float fAlpha; // d or Tr
bool bSpecular; // True if illum=2
bool bEmissive; // True if Ke or map_Ke was found
wchar_t strName[MAX_PATH]; // newmtl
wchar_t strTexture[MAX_PATH]; // map_Kd
wchar_t strNormalTexture[MAX_PATH]; // map_Kn
wchar_t strSpecularTexture[MAX_PATH]; // map_Ks
wchar_t strEmissiveTexture[MAX_PATH]; // map_Ke
wchar_t strRMATexture[MAX_PATH]; // map_RMA or map_ORM
};
The original code for the reader was created for the MeshFromOBJ legacy DirectX SDK sample DX9 / DX10.
For Use
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Windows 7 Service Pack 1
- Xbox One
- Xbox Series X|S
- Windows Subsystem for Linux
Architecture
- x86
- x64
- ARM64
For Development
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- GCC 10.5, 11.4, 12.3
- MinGW 12.2, 13.2
- CMake 3.20
Related Projects
DirectX Tool Kit for DirectX 11
DirectX Tool Kit for DirectX 12
Tools
See also
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.