Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLY binary import/export #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions UVAtlas/isochart/UVAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ namespace

if (!adjacency)
{
wprintf(L"Input adjacency pointer cannot be nullptr. Use DirectXMesh to compute it\n");
DPF(0, "Input adjacency pointer cannot be nullptr. Use DirectXMesh to compute it");
return E_INVALIDARG;
}
Expand Down Expand Up @@ -305,6 +306,8 @@ namespace
if ((adjacency[i] == uint32_t(-1)) &&
(falseEdgeAdjacency[i] != uint32_t(-1)))
{

wprintf(L"False edge found on triangle with no adjacent triangle.\n");
DPF(0, "False edge found on triangle with no adjacent triangle.");
return HRESULT_E_INVALID_DATA;
}
Expand Down Expand Up @@ -333,6 +336,9 @@ namespace
size_t numCharts = 0;
float maxChartingStretch = 0.f;


wprintf(L"isochartpartition...\n");

hr = isochartpartition(positions,
nVerts,
sizeof(XMFLOAT3),
Expand All @@ -358,6 +364,9 @@ namespace
if (FAILED(hr))
return hr;


wprintf(L"isochartpartition: Done\n");

if (DXGI_FORMAT_R16_UINT == indexFormat)
assert(nFaces * 3 * sizeof(uint16_t) == vOutIndexBuffer.size());
else
Expand Down Expand Up @@ -673,6 +682,9 @@ HRESULT __cdecl DirectX::UVAtlasCreate(
std::vector<uint32_t> vFacePartitioning;
std::vector<uint32_t> vAdjacencyOut;


wprintf(L"UVAtlasPartitionInt .. \n");

HRESULT hr = UVAtlasPartitionInt(positions,
nVerts,
indices,
Expand All @@ -699,6 +711,9 @@ HRESULT __cdecl DirectX::UVAtlasCreate(
if (FAILED(hr))
return hr;


wprintf(L"UVAtlasPackInt .. \n");

hr = UVAtlasPackInt(vMeshOutVertexBuffer,
vMeshOutIndexBuffer,
indexFormat,
Expand All @@ -714,6 +729,9 @@ HRESULT __cdecl DirectX::UVAtlasCreate(
if (FAILED(hr))
return hr;


wprintf(L"pvFacePartitioning .. \n");

if (pvFacePartitioning)
{
std::swap(*pvFacePartitioning, vFacePartitioning);
Expand Down
18 changes: 16 additions & 2 deletions UVAtlas/isochart/UVAtlasRepacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,22 @@ void CUVAtlasRepacker::ComputeChartsLengthInPixel()
{
auto pPosInfo = reinterpret_cast<_PositionInfo*>(&(pCInfo->PosInfo[j]));

// verify ceilf doesnt give 'inf' values
int numX = int(0);
float diff1 = ceilf((pPosInfo->maxPoint.x - pPosInfo->minPoint.x) / m_PixelWidth);
if (diff1 != INFINITY) {
numX = int(diff1);
}

int numY = int(0);
float diff2 = ceilf((pPosInfo->maxPoint.y - pPosInfo->minPoint.y) / m_PixelWidth);
if (diff2 != INFINITY) {
numY = int(diff2);
}

// compute the width and height of current chart
int numX = int(ceilf((pPosInfo->maxPoint.x - pPosInfo->minPoint.x) / m_PixelWidth));
int numY = int(ceilf((pPosInfo->maxPoint.y - pPosInfo->minPoint.y) / m_PixelWidth));
//int numX = int(ceilf((pPosInfo->maxPoint.x - pPosInfo->minPoint.x) / m_PixelWidth));
//int numY = int(ceilf((pPosInfo->maxPoint.y - pPosInfo->minPoint.y) / m_PixelWidth));
if (!numX) numX++;
if (!numY) numY++;

Expand Down Expand Up @@ -476,6 +489,7 @@ void CUVAtlasRepacker::ComputeChartsLengthInPixel()
\***************************************************************************/
HRESULT CUVAtlasRepacker::PrepareRepack()
{

// debug use
CleanUp();

Expand Down
14 changes: 14 additions & 0 deletions UVAtlas/isochart/isochart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ HRESULT Isochart::isochartpartition(
DPF(0, "Vertex Number:%zu\n", VertexCount);
DPF(0, "Face Number:%zu\n", FaceCount);


wprintf(L"CreateIsochartEngine...\n");

// 2. Create isochart engine
auto pEngine = IIsochartEngine::CreateIsochartEngine();
if (!pEngine)
Expand All @@ -344,6 +347,9 @@ HRESULT Isochart::isochartpartition(
}
pEngine->SetStage(dwTotalStage, dwDoneStage);


wprintf(L"pEngine->Initialize...\n");

// 4. Initialize isochart engine
if (FAILED(hr = pEngine->Initialize(
pVertexArray,
Expand All @@ -361,6 +367,11 @@ HRESULT Isochart::isochartpartition(
}
pEngine->SetStage(dwTotalStage, dwDoneStage + 1);



wprintf(L"pEngine->Partition ...\n");


// 5. Partition
if (FAILED(hr = pEngine->Partition(
MaxChartNumber,
Expand All @@ -372,6 +383,9 @@ HRESULT Isochart::isochartpartition(
goto LEnd;
}


wprintf(L"ExportPartitionResult ...\n");

// 6. Export Partition Result
hr = pEngine->ExportPartitionResult(
pvVertexArrayOut,
Expand Down
104 changes: 96 additions & 8 deletions UVAtlas/isochart/isochartengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "isochart.h"
#include "isochartmesh.h"

#include <omp.h>


using namespace DirectX;
using namespace Isochart;

Expand Down Expand Up @@ -104,6 +107,9 @@ HRESULT CIsochartEngine::Initialize(
{
DPF(1, "Initialize...");


wprintf(L"CheckInitializeParameters...\n");

// 1. Check arguments and current state
if (!CheckInitializeParameters(
pVertexArray,
Expand All @@ -128,14 +134,18 @@ HRESULT CIsochartEngine::Initialize(
return E_UNEXPECTED;
}


// 2. Try to enter exclusive section
if (FAILED(hr = TryEnterExclusiveSection()))
{
return hr;
}
}

// 3. If engine is already initialized, return error code


wprintf(L"InitializeBaseInfo...\n");

// 4. Prepare global basic information table.
if (FAILED(hr = InitializeBaseInfo(
pVertexArray,
Expand All @@ -151,6 +161,9 @@ HRESULT CIsochartEngine::Initialize(
goto LEnd;
}


wprintf(L"ApplyInitEngine...\n");

// 5. Internal initialization. Prepare the initial charts to be partitioned.
if (FAILED(hr = ApplyInitEngine(
m_baseInfo,
Expand All @@ -172,7 +185,7 @@ HRESULT CIsochartEngine::Initialize(
m_state = ISOCHART_ST_UNINITILAIZED;
}

LeaveExclusiveSection();
LeaveExclusiveSection();

return hr;
}
Expand Down Expand Up @@ -1212,6 +1225,8 @@ HRESULT CIsochartEngine::InitializeBaseInfo(
// (3) Caculated vertex importance order for each initial charts
// returns S_OK if successful, else failure code

omp_lock_t my_lock;

HRESULT CIsochartEngine::ApplyInitEngine(
CBaseMeshInfo& baseInfo,
DXGI_FORMAT IndexFormat,
Expand Down Expand Up @@ -1239,6 +1254,8 @@ HRESULT CIsochartEngine::ApplyInitEngine(
{
if (hr != E_OUTOFMEMORY)
{

wprintf(L"Build Full Connection Faild, Non-manifold...\n");
DPF(3, "Build Full Connection Faild, Non-manifold...");
}
delete pRootChart;
Expand All @@ -1263,8 +1280,75 @@ HRESULT CIsochartEngine::ApplyInitEngine(
delete pRootChart;
return E_OUTOFMEMORY;
}


wprintf(L"while (!m_currentChartHeap.empty()) ...\n");

size_t dwTestVertexCount = 0;
size_t dwTestFaceCount = 0;



/* ori
while (!m_currentChartHeap.empty())
{
CIsochartMesh* pChart = m_currentChartHeap.cutTopData();
assert(pChart != nullptr);
_Analysis_assume_(pChart != nullptr);
assert(!pChart->IsImportanceCaculationDone());

if (FAILED(hr = pChart->PrepareProcessing(bIsForPartition)))
{
delete pChart;
return hr;
}

DPF(3, "Separate to %zu sub-charts", pChart->GetChildrenCount());
// if original mesh has multiple sub-charts or current chart
// has multiple boundaies it will generate children.

if (pChart->HasChildren())
{


for (uint32_t i = 0; i < pChart->GetChildrenCount(); i++)

{
CIsochartMesh* pChild = pChart->GetChild(i);
assert(pChild != nullptr);
assert(!pChild->IsImportanceCaculationDone());

if (!m_currentChartHeap.insertData(pChild, 0))
{
delete pChart;
return E_OUTOFMEMORY;
}
pChart->UnlinkChild(i);
}
delete pChart;
}
else
{
assert(pChart->IsImportanceCaculationDone()
|| !bIsForPartition);
try
{
m_initChartList.push_back(pChart);
}
catch (std::bad_alloc&)
{
delete pChart;
return E_OUTOFMEMORY;
}
dwTestVertexCount += pChart->GetVertexNumber();
dwTestFaceCount += pChart->GetFaceNumber();
}
}

*/

// faire marcher paralell

while (!m_currentChartHeap.empty())
{
CIsochartMesh* pChart = m_currentChartHeap.cutTopData();
Expand All @@ -1284,7 +1368,10 @@ HRESULT CIsochartEngine::ApplyInitEngine(

if (pChart->HasChildren())
{


for (uint32_t i = 0; i < pChart->GetChildrenCount(); i++)

{
CIsochartMesh* pChild = pChart->GetChild(i);
assert(pChild != nullptr);
Expand Down Expand Up @@ -1316,13 +1403,14 @@ HRESULT CIsochartEngine::ApplyInitEngine(
dwTestFaceCount += pChart->GetFaceNumber();
}
}

///////////


wprintf(L"while (!m_currentChartHeap.empty()) DONE \n");

DPF(3, "Old Vert Number is %zu, New Vert Number is %zu",
baseInfo.dwVertexCount,
dwTestVertexCount);
DPF(3, "Old Face Number is %zu, New Face Number is %zu",
baseInfo.dwFaceCount,
dwTestFaceCount);
DPF(3, "Old Vert Number is %zu, New Vert Number is %zu", baseInfo.dwVertexCount, dwTestVertexCount);
DPF(3, "Old Face Number is %zu, New Face Number is %zu", baseInfo.dwFaceCount, dwTestFaceCount);

hr = m_callbackSchemer.FinishWorkAdapt();

Expand Down
5 changes: 5 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 All @@ -160,6 +161,9 @@ class Mesh
// Create mesh from file
static HRESULT CreateFromVBO(_In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<Mesh>& result) noexcept;

// Create mesh from file
static HRESULT CreateFromPLY(_In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<Mesh>& result, bool preload_in_memory) noexcept;

private:
size_t mnFaces;
size_t mnVerts;
Expand All @@ -179,4 +183,5 @@ class Mesh
std::wstring mtlFileName;

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

};
Loading