Code review ported over from meshconvert

This commit is contained in:
Chuck Walbourn 2020-02-13 17:10:32 -08:00
parent 2bbef8687c
commit 4f56640015
2 changed files with 29 additions and 25 deletions

View File

@ -16,7 +16,6 @@
#define NOMINMAX
#define NODRAWTEXT
#define NOGDI
#define NOBITMAP
#define NOMCX
#define NOSERVICE
#define NOHELP

View File

@ -173,7 +173,7 @@ namespace
using ScopedFindHandle = std::unique_ptr<void, find_closer>;
#ifdef _PREFAST_
#ifdef __PREFAST__
#pragma prefast(disable : 26018, "Only used with static internal arrays")
#endif
@ -288,7 +288,7 @@ namespace
wprintf(L" -sdkmesh DirectX SDK .sdkmesh format (default)\n");
wprintf(L" -sdkmesh2 .sdkmesh format version 2 (PBR materials)\n");
wprintf(L" -cmo Visual Studio Content Pipeline .cmo format\n");
wprintf(L" -vbo Vertex Buffer Object (.vbo) format\n\n");
wprintf(L" -vbo Vertex Buffer Object (.vbo) format\n");
wprintf(L" -wf WaveFront Object (.obj) format\n\n");
wprintf(L" -r wildcard filename search is recursive\n");
wprintf(L" -q <level> sets quality level to DEFAULT, FAST or QUALITY\n");
@ -354,7 +354,7 @@ extern HRESULT LoadFromOBJ(const wchar_t* szFilename, std::unique_ptr<Mesh>& inM
//--------------------------------------------------------------------------------------
// Entry-point
//--------------------------------------------------------------------------------------
#ifdef _PREFAST_
#ifdef __PREFAST__
#pragma prefast(disable : 28198, "Command-line tool, frees all memory on exit")
#endif
@ -376,7 +376,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr))
{
wprintf(L"Failed to initialize COM (%08X)\n", hr);
wprintf(L"Failed to initialize COM (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
@ -738,7 +738,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
if (FAILED(hr))
{
wprintf(L" FAILED (%08X)\n", hr);
wprintf(L" FAILED (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
@ -761,7 +761,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->InvertUTexCoord();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed inverting u texcoord (%08X)\n", hr);
wprintf(L"\nERROR: Failed inverting u texcoord (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@ -771,7 +771,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->InvertVTexCoord();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed inverting v texcoord (%08X)\n", hr);
wprintf(L"\nERROR: Failed inverting v texcoord (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@ -781,7 +781,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ReverseHandedness();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed reversing handedness (%08X)\n", hr);
wprintf(L"\nERROR: Failed reversing handedness (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@ -794,7 +794,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->GenerateAdjacency(epsilon);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed generating adjacency (%08X)\n", hr);
wprintf(L"\nERROR: Failed generating adjacency (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
@ -804,14 +804,14 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!msgs.empty())
{
wprintf(L"\nWARNING: \n");
wprintf(msgs.c_str());
wprintf(L"%ls", msgs.c_str());
}
// Clean
hr = inMesh->Clean(true);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed mesh clean (%08X)\n", hr);
wprintf(L"\nERROR: Failed mesh clean (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
else
@ -858,7 +858,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ComputeNormals(flags);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed computing normals (flags:%1X, %08X)\n", flags, hr);
wprintf(L"\nERROR: Failed computing normals (flags:%lX, %08X)\n", flags, static_cast<unsigned int>(hr));
return 1;
}
}
@ -875,7 +875,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ComputeTangentFrame((dwOptions & (DWORD64(1) << OPT_CTF)) ? true : false);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed computing tangent frame (%08X)\n", hr);
wprintf(L"\nERROR: Failed computing tangent frame (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@ -921,7 +921,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
if (FAILED(hr))
{
wprintf(L"\nWARNING: Failed to load texture for IMT (%08X):\n%ls\n", hr, szTexFile);
wprintf(L"\nWARNING: Failed to load texture for IMT (%08X):\n%ls\n", static_cast<unsigned int>(hr), szTexFile);
}
else
{
@ -934,7 +934,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
img = nullptr;
wprintf(L"\nWARNING: Failed converting texture for IMT (%08X):\n%ls\n", hr, szTexFile);
wprintf(L"\nWARNING: Failed converting texture for IMT (%08X):\n%ls\n", static_cast<unsigned int>(hr), szTexFile);
}
else
{
@ -959,7 +959,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
IMTData.reset();
wprintf(L"WARNING: Failed to compute IMT from texture (%08X):\n%ls\n", hr, szTexFile);
wprintf(L"WARNING: Failed to compute IMT from texture (%08X):\n%ls\n", static_cast<unsigned int>(hr), szTexFile);
}
}
}
@ -1025,7 +1025,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
IMTData.reset();
wprintf(L"WARNING: Failed to compute IMT from channel %ls (%08X)\n", szChannel, hr);
wprintf(L"WARNING: Failed to compute IMT from channel %ls (%08X)\n", szChannel, static_cast<unsigned int>(hr));
}
}
}
@ -1063,7 +1063,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else
{
wprintf(L"\nERROR: Failed creating isocharts (%08X)\n", hr);
wprintf(L"\nERROR: Failed creating isocharts (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@ -1077,14 +1077,14 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->UpdateFaces(nFaces, reinterpret_cast<const uint32_t*>(ib.data()));
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed applying atlas indices (%08X)\n", hr);
wprintf(L"\nERROR: Failed applying atlas indices (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
hr = inMesh->VertexRemap(vertexRemapArray.data(), vertexRemapArray.size());
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed applying atlas vertex remap (%08X)\n", hr);
wprintf(L"\nERROR: Failed applying atlas vertex remap (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
@ -1164,7 +1164,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->UpdateAttributes(nFaces, attr.get());
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed applying atlas attributes (%08X)\n", hr);
wprintf(L"\nERROR: Failed applying atlas attributes (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@ -1174,7 +1174,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ReverseWinding();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed reversing winding (%08X)\n", hr);
wprintf(L"\nERROR: Failed reversing winding (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@ -1282,7 +1282,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed write (%08X):-> '%ls'\n", hr, outputPath);
wprintf(L"\nERROR: Failed write (%08X):-> '%ls'\n", static_cast<unsigned int>(hr), outputPath);
return 1;
}
@ -1304,6 +1304,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
_wmakepath_s(outputPath, nullptr, nullptr, uvFilename, outputExt);
hr = E_NOTIMPL;
if (!_wcsicmp(outputExt, L".vbo"))
{
hr = inMesh->ExportToVBO(outputPath);
@ -1320,9 +1321,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
hr = inMesh->ExportToCMO(outputPath, inMaterial.size(), inMaterial.empty() ? nullptr : inMaterial.data());
}
else if (!_wcsicmp(outputExt, L".obj") || !_wcsicmp(outputExt, L"._obj"))
{
wprintf(L"\nWARNING: WaveFront Object (.obj) not supported for UV visualization (requires Vertex Colors)\n");
}
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed uv mesh write (%08X):-> '%ls'\n", hr, outputPath);
wprintf(L"\nERROR: Failed uv mesh write (%08X):-> '%ls'\n", static_cast<unsigned int>(hr), outputPath);
return 1;
}
wprintf(L"uv mesh visualization '%ls'\n", outputPath);