WaveFrontReader: Ke, map_Ks, map_Kn/norm, map_Ke/map_emissive
This commit is contained in:
Родитель
73522f621a
Коммит
150bcac5ba
|
@ -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;
|
||||
|
|
|
@ -95,6 +95,9 @@ public:
|
|||
DirectX::XMFLOAT3 specularColor;
|
||||
DirectX::XMFLOAT3 emissiveColor;
|
||||
std::wstring texture;
|
||||
std::wstring normalTexture;
|
||||
std::wstring specularTexture;
|
||||
std::wstring emissiveTexture;
|
||||
|
||||
Material() noexcept :
|
||||
perVertexColor(false),
|
||||
|
|
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -375,7 +375,6 @@ public:
|
|||
|
||||
wchar_t szPath[MAX_PATH] = {};
|
||||
_wmakepath_s(szPath, MAX_PATH, drive, dir, fname, ext);
|
||||
|
||||
HRESULT hr = LoadMTL(szPath);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
@ -448,6 +447,17 @@ public:
|
|||
InFile >> r >> g >> b;
|
||||
curMaterial->vSpecular = XMFLOAT3(r, g, b);
|
||||
}
|
||||
else if (0 == wcscmp(strCommand.c_str(), L"Ke"))
|
||||
{
|
||||
// Emissive color
|
||||
float r, g, b;
|
||||
InFile >> r >> g >> b;
|
||||
curMaterial->vEmissive = XMFLOAT3(r, g, b);
|
||||
if (r > 0.f || g > 0.f || b > 0.f)
|
||||
{
|
||||
curMaterial->bEmissive = true;
|
||||
}
|
||||
}
|
||||
else if (0 == wcscmp(strCommand.c_str(), L"d"))
|
||||
{
|
||||
// Alpha
|
||||
|
@ -478,9 +488,27 @@ public:
|
|||
}
|
||||
else if (0 == wcscmp(strCommand.c_str(), L"map_Kd"))
|
||||
{
|
||||
// Texture
|
||||
// Diffuse texture
|
||||
InFile >> curMaterial->strTexture;
|
||||
}
|
||||
else if (0 == wcscmp(strCommand.c_str(), L"map_Ks"))
|
||||
{
|
||||
// Specular texture
|
||||
InFile >> curMaterial->strSpecularTexture;
|
||||
}
|
||||
else if (0 == wcscmp(strCommand.c_str(), L"map_Kn")
|
||||
|| 0 == wcscmp(strCommand.c_str(), L"norm"))
|
||||
{
|
||||
// Normal texture
|
||||
InFile >> curMaterial->strNormalTexture;
|
||||
}
|
||||
else if (0 == wcscmp(strCommand.c_str(), L"map_Ke")
|
||||
|| 0 == wcscmp(strCommand.c_str(), L"map_emissive"))
|
||||
{
|
||||
// Emissive texture
|
||||
InFile >> curMaterial->strEmissiveTexture;
|
||||
curMaterial->bEmissive = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unimplemented or unrecognized command
|
||||
|
@ -574,23 +602,33 @@ public:
|
|||
DirectX::XMFLOAT3 vAmbient;
|
||||
DirectX::XMFLOAT3 vDiffuse;
|
||||
DirectX::XMFLOAT3 vSpecular;
|
||||
DirectX::XMFLOAT3 vEmissive;
|
||||
uint32_t nShininess;
|
||||
float fAlpha;
|
||||
|
||||
bool bSpecular;
|
||||
bool bEmissive;
|
||||
|
||||
wchar_t strName[MAX_PATH];
|
||||
wchar_t strTexture[MAX_PATH];
|
||||
wchar_t strNormalTexture[MAX_PATH];
|
||||
wchar_t strSpecularTexture[MAX_PATH];
|
||||
wchar_t strEmissiveTexture[MAX_PATH];
|
||||
|
||||
Material() noexcept :
|
||||
vAmbient(0.2f, 0.2f, 0.2f),
|
||||
vDiffuse(0.8f, 0.8f, 0.8f),
|
||||
vSpecular(1.0f, 1.0f, 1.0f),
|
||||
vEmissive(0.f, 0.f, 0.f),
|
||||
nShininess(0),
|
||||
fAlpha(1.f),
|
||||
bSpecular(false),
|
||||
bEmissive(false),
|
||||
strName{},
|
||||
strTexture{}
|
||||
strTexture{},
|
||||
strNormalTexture{},
|
||||
strSpecularTexture{},
|
||||
strEmissiveTexture{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче