Skip to content

Commit

Permalink
WaveFrontReader: Ke, map_Ks, map_Kn/norm, map_Ke/map_emissive
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Jan 10, 2019
1 parent 73522f6 commit 77158e2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
48 changes: 38 additions & 10 deletions Meshconvert/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2276,20 +2276,48 @@ HRESULT Mesh::ExportToSDKMESH(const wchar_t* szFileName, size_t nMaterials, cons

memset(m, 0, sizeof(SDKMESH_MATERIAL));

int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->name.c_str(), -1,
m->Name, MAX_MATERIAL_NAME, nullptr, FALSE);
if (!result)
if (!m0->name.empty())
{
*m->Name = 0;
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->name.c_str(), -1,
m->Name, MAX_MATERIAL_NAME, nullptr, FALSE);
if (!result)
{
*m->Name = 0;
}
}

result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->texture.c_str(), -1,
m->DiffuseTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
if (!m0->texture.empty())
{
*m->DiffuseTexture = 0;
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->texture.c_str(), -1,
m->DiffuseTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
{
*m->DiffuseTexture = 0;
}
}

if (!m0->normalTexture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->normalTexture.c_str(), -1,
m->NormalTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
{
*m->NormalTexture = 0;
}
}

if (!m0->specularTexture.empty())
{
int result = WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS,
m0->specularTexture.c_str(), -1,
m->SpecularTexture, MAX_TEXTURE_NAME, nullptr, FALSE);
if (!result)
{
*m->SpecularTexture = 0;
}
}

m->Diffuse.x = m0->diffuseColor.x;
Expand Down
3 changes: 3 additions & 0 deletions Meshconvert/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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
43 changes: 28 additions & 15 deletions Meshconvert/MeshOBJ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 @@ -108,25 +130,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

0 comments on commit 77158e2

Please sign in to comment.