-
Notifications
You must be signed in to change notification settings - Fork 158
Utilities
In addition to the DirectXMesh library and meshconvert tool, this repro includes a few miscellaneous standalone utilities for working with meshes.
This is a simple reader for WaveFront OBJ mesh data files used by meshconvert and uvatlas, as well as a few samples.
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];
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.
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.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- Xbox Series X|S
- Windows Subsystem for Linux
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v19
- GCC 10.5, 11.4, 12.3, 13.3, 14.2
- MinGW 12.2, 13.2
- CMake 3.20
DirectX Tool Kit for DirectX 11