#include "../Common/Example.h"
void RunChartAggregation(const std::string& readFrom,
const std::string& writeToUnWeighted,
const std::string& writeToAreaWeighted,
const std::string& writeToOriginalTextureWeighted,
const std::string& writeToPreserveOriginalUVDensity);
int main(int argc, char* argv[])
{
try
{
InitExample();
std::string assetPath = GetAssetPath();
RunChartAggregation(assetPath + "TexturedPlanes/texturedplanes.obj", "result_unweighted", "result_areaWeighted", "result_originalTextureWeighted", "result_PreserveOriginalUVDensity");
DeinitExample();
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return -1;
}
return 0;
}
void RunChartAggregation(const std::string& readFrom,
const std::string& writeToUnWeighted,
const std::string& writeToAreaWeighted,
const std::string& writeToOriginalTextureWeighted,
const std::string& writeToPreserveOriginalUVDensity
)
{
std::string exePath = GetExecutablePath();
std::string output_unweighted_filename = exePath + writeToUnWeighted + ".obj";
std::string output_areaweighted_filename = exePath + writeToAreaWeighted + ".obj";
std::string output_textureweighted_filename = exePath + writeToOriginalTextureWeighted + ".obj";
std::string output_preservedpixeldensity_filename = exePath + writeToPreserveOriginalUVDensity + ".obj";
spWavefrontImporter objReader = sg->CreateWavefrontImporter();
objReader->SetExtractGroups(false);
objReader->SetImportFilePath(readFrom.c_str());
if (!objReader->RunImport())
throw std::exception("Failed to load input file!");
spScene scene = objReader->GetScene();
spSceneMesh sceneMesh = SafeCast<ISceneMesh>(scene->GetRootNode()->GetChild(0));
spGeometryData originalGeometry = sceneMesh->GetGeometry();
spChartAggregator chartAggregator = sg->CreateChartAggregator();
chartAggregator->SetSeparateOverlappingCharts(true);
chartAggregator->SetMaterialTable(scene->GetMaterialTable());
chartAggregator->SetTextureTable(scene->GetTextureTable());
chartAggregator->SetTexCoordLevel(0);
chartAggregator->SetTextureWidth(1024);
chartAggregator->SetTextureHeight(1024);
chartAggregator->SetGutterSpace(4);
spWavefrontExporter objExporter = sg->CreateWavefrontExporter();
spGeometryData workingGeometry = originalGeometry->NewCopy(true);
chartAggregator->SetChartAggregatorMode(SG_CHARTAGGREGATORMODE_UVSIZEPROPORTIONS);
chartAggregator->Parameterize(workingGeometry, workingGeometry->GetTexCoords(0));
sceneMesh->SetGeometry(workingGeometry);
objExporter->SetExportFilePath(output_unweighted_filename.c_str());
objExporter->SetScene(scene);
objExporter->RunExport();
workingGeometry = originalGeometry->NewCopy(true);
chartAggregator->SetChartAggregatorMode(SG_CHARTAGGREGATORMODE_SURFACEAREA);
chartAggregator->Parameterize(workingGeometry, workingGeometry->GetTexCoords(0));
sceneMesh->SetGeometry(workingGeometry);
objExporter = sg->CreateWavefrontExporter();
objExporter->SetExportFilePath(output_areaweighted_filename.c_str());
objExporter->SetScene(scene);
objExporter->RunExport();
workingGeometry = originalGeometry->NewCopy(true);
chartAggregator->SetChartAggregatorMode(SG_CHARTAGGREGATORMODE_TEXTURESIZEPROPORTIONS);
chartAggregator->Parameterize(workingGeometry, workingGeometry->GetTexCoords(0));
sceneMesh->SetGeometry(workingGeometry);
objExporter = sg->CreateWavefrontExporter();
objExporter->SetExportFilePath(output_textureweighted_filename.c_str());
objExporter->SetScene(scene);
objExporter->RunExport();
workingGeometry = originalGeometry->NewCopy(true);
chartAggregator->SetChartAggregatorMode(SG_CHARTAGGREGATORMODE_ORIGINALPIXELDENSITY);
chartAggregator->Parameterize(workingGeometry, workingGeometry->GetTexCoords(0));
sceneMesh->SetGeometry(workingGeometry);
objExporter = sg->CreateWavefrontExporter();
objExporter->SetExportFilePath(output_preservedpixeldensity_filename.c_str());
objExporter->SetScene(scene);
objExporter->RunExport();
}