Skip to content

Commit

Permalink
updating PLY code
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Kyles committed Sep 25, 2021
1 parent d458111 commit 4eaa857
Show file tree
Hide file tree
Showing 6 changed files with 1,707 additions and 1 deletion.
2 changes: 2 additions & 0 deletions UVAtlasTool/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Mesh
};

HRESULT ExportToOBJ(const wchar_t* szFileName, _In_ size_t nMaterials, _In_reads_opt_(nMaterials) const Material* materials) const;
HRESULT ExportToPLY(const wchar_t* szFileName/*, _In_ size_t nMaterials, _In_reads_opt_(nMaterials) const Material* materials*/) const;
HRESULT ExportToVBO(_In_z_ const wchar_t* szFileName) const noexcept;
HRESULT ExportToCMO(_In_z_ const wchar_t* szFileName, _In_ size_t nMaterials, _In_reads_opt_(nMaterials) const Material* materials) const noexcept;
HRESULT ExportToSDKMESH(_In_z_ const wchar_t* szFileName,
Expand Down Expand Up @@ -179,4 +180,5 @@ class Mesh
std::wstring mtlFileName;

void ExportToOBJ(std::wostream& os, _In_ size_t nMaterials, _In_reads_opt_(nMaterials) const Material* materials) const;

};
31 changes: 30 additions & 1 deletion UVAtlasTool/UVAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace
OPT_CMO,
OPT_VBO,
OPT_WAVEFRONT_OBJ,
OPT_PLY,
OPT_CLOCKWISE,
OPT_FORCE_32BIT_IB,
OPT_OVERWRITE,
Expand Down Expand Up @@ -172,6 +173,7 @@ namespace
{ L"cmo", OPT_CMO },
{ L"vbo", OPT_VBO },
{ L"wf", OPT_WAVEFRONT_OBJ },
{ L"ply", OPT_PLY},
{ L"cw", OPT_CLOCKWISE },
{ L"ib32", OPT_FORCE_32BIT_IB },
{ L"y", OPT_OVERWRITE },
Expand Down Expand Up @@ -224,6 +226,10 @@ HRESULT LoadFromOBJ(const wchar_t* szFilename,
std::unique_ptr<Mesh>& inMesh, std::vector<Mesh::Material>& inMaterial,
bool ccw, bool dds);


HRESULT LoadFromPLY(const wchar_t* szFilename,
std::unique_ptr<Mesh>& inMesh, const bool preload_into_memory = false);

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -879,6 +885,14 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
break;

case OPT_PLY:
if (dwOptions & (uint64_t(1) << OPT_SECOND_UV))
{
wprintf(L"-uv2 is not supported by PLY\n");
return 1;
}
break;

case OPT_SECOND_UV:
if (dwOptions & ((uint64_t(1) << OPT_VBO) | (uint64_t(1) << OPT_CMO) | (uint64_t(1) << OPT_WAVEFRONT_OBJ)))
{
Expand Down Expand Up @@ -1008,6 +1022,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wprintf(L"\nERROR: Autodesk FBX files not supported\n");
return 1;
}
else if (_wcsicmp(ext, L".ply") == 0)
{
LoadFromPLY(pConv->szSrc, inMesh);
hr = S_OK;
}
else
{
hr = LoadFromOBJ(pConv->szSrc, inMesh, inMaterial,
Expand Down Expand Up @@ -1072,7 +1091,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
// Adjacency
float epsilon = (dwOptions & (uint64_t(1) << OPT_GEOMETRIC_ADJ)) ? 1e-5f : 0.f;

hr = inMesh->GenerateAdjacency(epsilon);
hr = inMesh->GenerateAdjacency(epsilon); // here binary ply doesnt work ..?
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed generating adjacency (%08X%ls)\n",
Expand All @@ -1099,6 +1118,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else
{


size_t nNewVerts = inMesh->GetVertexCount();
if (nVerts != nNewVerts)
{
Expand Down Expand Up @@ -1495,6 +1516,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
wcscpy_s(outputExt, L".obj");
}
else if (dwOptions & (uint64_t(1) << OPT_PLY))
{
wcscpy_s(outputExt, L".ply");
}
else
{
wcscpy_s(outputExt, L".sdkmesh");
Expand Down Expand Up @@ -1567,6 +1592,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
{
hr = inMesh->ExportToOBJ(outputPath, inMaterial.size(), inMaterial.empty() ? nullptr : inMaterial.data());
}
else if (!_wcsicmp(outputExt, L".ply"))
{
hr = inMesh->ExportToPLY(outputPath);
}
else if (!_wcsicmp(outputExt, L".x"))
{
wprintf(L"\nERROR: Legacy Microsoft X files not supported\n");
Expand Down
1 change: 1 addition & 0 deletions UVAtlasTool/UVAtlasTool_2019.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="MeshOBJ.cpp" />
<ClCompile Include="tinyply.cpp" />
<ClCompile Include="UVAtlas.cpp" />
<ClCompile Include="Mesh.cpp" />
<CLInclude Include="Mesh.h" />
Expand Down
6 changes: 6 additions & 0 deletions UVAtlasTool/UVAtlasTool_2019.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<Filter Include="Wavefront OBJ">
<UniqueIdentifier>{c8076e0b-beef-46c6-8c4b-128ccc82a987}</UniqueIdentifier>
</Filter>
<Filter Include="Ply">
<UniqueIdentifier>{337c9091-8663-40bd-8058-df2e01b62f79}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="UVAtlas.cpp" />
Expand All @@ -16,6 +19,9 @@
<ClCompile Include="MeshOBJ.cpp">
<Filter>Wavefront OBJ</Filter>
</ClCompile>
<ClCompile Include="tinyply.cpp">
<Filter>Ply</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SDKMesh.h" />
Expand Down
Loading

0 comments on commit 4eaa857

Please sign in to comment.