-fliptc removed; added -flipv and -flipz

This commit is contained in:
Chuck Walbourn 2015-11-20 17:42:43 -08:00
Родитель 61a4c2f84b
Коммит 30c0696ac4
3 изменённых файлов: 72 добавлений и 28 удалений

Просмотреть файл

@ -707,7 +707,7 @@ HRESULT Mesh::Optimize( uint32_t vertexCache, uint32_t restart )
//--------------------------------------------------------------------------------------
HRESULT Mesh::ReverseWinding(bool texcoords)
HRESULT Mesh::ReverseWinding()
{
if (!mIndices || !mnFaces)
return E_UNEXPECTED;
@ -719,12 +719,44 @@ HRESULT Mesh::ReverseWinding(bool texcoords)
iptr += 3;
}
if (texcoords && mTexCoords)
return S_OK;
}
//--------------------------------------------------------------------------------------
HRESULT Mesh::InvertVTexCoord()
{
if (!mTexCoords)
return E_UNEXPECTED;
auto tptr = mTexCoords.get();
for (size_t j = 0; j < mnVerts; ++j, ++tptr)
{
auto tptr = mTexCoords.get();
for (size_t j = 0; j < mnVerts; ++j, ++tptr)
tptr->y = 1.f - tptr->y;
}
return S_OK;
}
//--------------------------------------------------------------------------------------
HRESULT Mesh::ReverseHandedness()
{
if (!mPositions)
return E_UNEXPECTED;
auto ptr = mPositions.get();
for (size_t j = 0; j < mnVerts; ++j, ++ptr)
{
ptr->z = -ptr->z;
}
if (mNormals)
{
auto nptr = mNormals.get();
for (size_t j = 0; j < mnVerts; ++j, ++nptr)
{
tptr->x = 1.f - tptr->x;
nptr->z = -nptr->z;
}
}

Просмотреть файл

@ -62,7 +62,11 @@ public:
HRESULT Optimize( _In_ uint32_t vertexCache = DirectX::OPTFACES_V_DEFAULT, _In_ uint32_t restart = DirectX::OPTFACES_R_DEFAULT );
HRESULT ReverseWinding( bool texcoords );
HRESULT ReverseWinding();
HRESULT InvertVTexCoord();
HRESULT ReverseHandedness();
// Accessors
const uint32_t* GetAttributeBuffer() const { return mAttributes.get(); }

Просмотреть файл

@ -41,7 +41,8 @@ enum OPTIONS // Note: dwOptions below assumes 32 or less options.
OPT_OVERWRITE,
OPT_NODDS,
OPT_FLIP,
OPT_FLIPTC,
OPT_FLIPV,
OPT_FLIPZ,
OPT_NOLOGO,
OPT_MAX
};
@ -82,7 +83,8 @@ SValue g_pOptions[] =
{ L"y", OPT_OVERWRITE },
{ L"nodds", OPT_NODDS },
{ L"flip", OPT_FLIP },
{ L"fliptc", OPT_FLIPTC },
{ L"flipv", OPT_FLIPV },
{ L"flipz", OPT_FLIPZ },
{ L"nologo", OPT_NOLOGO },
{ nullptr, 0 }
};
@ -142,7 +144,9 @@ void PrintUsage()
wprintf( L" -ta | -ga generate topological vs. geometric adjancecy (def: ta)\n");
wprintf( L" -sdkmesh|-cmo|-vbo output file type\n");
wprintf( L" -nodds prevents extension renaming in exported materials\n");
wprintf( L" -flip | -fliptc reverse winding of faces and/or flips texcoords\n");
wprintf( L" -flip reverse winding of faces\n");
wprintf( L" -flipv inverts the v texcoords\n");
wprintf( L" -flipz flips the handedness of the positions/normals\n");
wprintf( L" -o <filename> output filename\n");
wprintf( L" -y overwrite existing output file (if any)\n");
wprintf( L" -nologo suppress copyright message\n");
@ -297,7 +301,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if ( OPT_NOLOGO != dwOption && OPT_OVERWRITE != dwOption
&& OPT_CLOCKWISE != dwOption && OPT_NODDS != dwOption
&& OPT_FLIP != dwOption && OPT_FLIPTC != dwOption
&& OPT_FLIP != dwOption && OPT_FLIPV != dwOption && OPT_FLIPZ != dwOption
&& OPT_NORMALS != dwOption && OPT_WEIGHT_BY_AREA != dwOption && OPT_WEIGHT_BY_EQUAL != dwOption
&& OPT_TANGENTS != dwOption && OPT_CTF != dwOption
&& OPT_OPTIMIZE != dwOption && OPT_CLEAN != dwOption
@ -381,22 +385,6 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
return 1;
}
break;
case OPT_FLIP:
if ( dwOptions & (1 << OPT_FLIPTC) )
{
wprintf(L"Can only use flip or fliptc\n");
return 1;
}
break;
case OPT_FLIPTC:
if (dwOptions & (1 << OPT_FLIP))
{
wprintf(L"Can only use flip or fliptc\n");
return 1;
}
break;
}
}
else
@ -482,6 +470,26 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wprintf( L"\n%Iu vertices, %Iu faces", nVerts, nFaces );
if (dwOptions & (1 << OPT_FLIPV))
{
hr = inMesh->InvertVTexCoord();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed inverting v texcoord (%08X)\n", hr);
return 1;
}
}
if (dwOptions & (1 << OPT_FLIPZ))
{
hr = inMesh->ReverseHandedness();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed reversing handedness (%08X)\n", hr);
return 1;
}
}
// Prepare mesh for processing
if ( dwOptions & ( (1 << OPT_OPTIMIZE) | (1 << OPT_CLEAN) ) )
{
@ -595,9 +603,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
}
if (dwOptions & ((1 << OPT_FLIP) | (1 << OPT_FLIPTC)))
if (dwOptions & (1 << OPT_FLIP))
{
hr = inMesh->ReverseWinding( (dwOptions & (1 << OPT_FLIPTC)) ? true : false );
hr = inMesh->ReverseWinding();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed reversing winding (%08X)\n", hr);