Skip to content

Commit

Permalink
SDKMESH2 export support for PBR materials
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Feb 9, 2019
1 parent 909a24e commit c250c3d
Show file tree
Hide file tree
Showing 9 changed files with 548 additions and 374 deletions.
508 changes: 153 additions & 355 deletions UVAtlasTool/Mesh.cpp

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion UVAtlasTool/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class Mesh
DirectX::XMFLOAT3 specularColor;
DirectX::XMFLOAT3 emissiveColor;
std::wstring texture;
std::wstring normalTexture;
std::wstring specularTexture;
std::wstring emissiveTexture;

Material() noexcept :
perVertexColor(false),
Expand Down Expand Up @@ -142,7 +145,7 @@ class Mesh

HRESULT ExportToVBO(_In_z_ const wchar_t* szFileName) const;
HRESULT ExportToCMO(_In_z_ const wchar_t* szFileName, _In_ size_t nMaterials, _In_reads_opt_(nMaterials) const Material* materials) const;
HRESULT ExportToSDKMESH(_In_z_ const wchar_t* szFileName, _In_ size_t nMaterials, _In_reads_opt_(nMaterials) const Material* materials, bool force32bit = false) const;
HRESULT ExportToSDKMESH(_In_z_ const wchar_t* szFileName, _In_ size_t nMaterials, _In_reads_opt_(nMaterials) const Material* materials, bool force32bit = false, bool version2 = false) const;

// Create mesh from file
static HRESULT CreateFromVBO(_In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<Mesh>& result);
Expand Down
43 changes: 28 additions & 15 deletions UVAtlasTool/MeshOBJ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@

using namespace DirectX;

namespace
{
std::wstring ProcessTextureFileName(const wchar_t* inName, bool dds)
{
if (!inName || !*inName)
return std::wstring();

wchar_t txext[_MAX_EXT] = {};
wchar_t txfname[_MAX_FNAME] = {};
_wsplitpath_s(inName, nullptr, 0, nullptr, 0, txfname, _MAX_FNAME, txext, _MAX_EXT);

if (dds)
{
wcscpy_s(txext, L".dds");
}

wchar_t texture[_MAX_PATH] = {};
_wmakepath_s(texture, nullptr, nullptr, txfname, txext);
return std::wstring(texture);
}
}

HRESULT LoadFromOBJ(
const wchar_t* szFilename,
std::unique_ptr<Mesh>& inMesh,
Expand Down Expand Up @@ -109,25 +131,16 @@ HRESULT LoadFromOBJ(
mtl.ambientColor = it->vAmbient;
mtl.diffuseColor = it->vDiffuse;
mtl.specularColor = (it->bSpecular) ? it->vSpecular : XMFLOAT3(0.f, 0.f, 0.f);
mtl.emissiveColor = XMFLOAT3(0.f, 0.f, 0.f);
mtl.emissiveColor = (it->bEmissive) ? it->vEmissive : XMFLOAT3(0.f, 0.f, 0.f);

wchar_t texture[_MAX_PATH] = {};
if (*it->strTexture)
mtl.texture = ProcessTextureFileName(it->strTexture, dds);
mtl.normalTexture = ProcessTextureFileName(it->strNormalTexture, dds);
mtl.specularTexture = ProcessTextureFileName(it->strSpecularTexture, dds);
if (it->bEmissive)
{
wchar_t txext[_MAX_EXT];
wchar_t txfname[_MAX_FNAME];
_wsplitpath_s(it->strTexture, nullptr, 0, nullptr, 0, txfname, _MAX_FNAME, txext, _MAX_EXT);

if (dds)
{
wcscpy_s(txext, L".dds");
}

_wmakepath_s(texture, nullptr, nullptr, txfname, txext);
mtl.emissiveTexture = ProcessTextureFileName(it->strEmissiveTexture, dds);
}

mtl.texture = texture;

inMaterial.push_back(mtl);
}
}
Expand Down
Loading

0 comments on commit c250c3d

Please sign in to comment.