This example shows how to do batch processing using Simplygon Grid.

// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license. 

#include <string>
#include <stdlib.h>
#include <filesystem>
#include <future>
#include "SimplygonLoader.h"


void RunReduction(Simplygon::ISimplygon* sg, std::string inputFile, std::string outputFile)
{
	// Create the reduction pipeline. 
	Simplygon::spReductionPipeline sgReductionPipeline = sg->CreateReductionPipeline();

	Simplygon::spReductionSettings sgReductionSettings = sgReductionPipeline->GetReductionSettings();

	// Set reduction target to triangle ratio with a ratio of 50%. 
	sgReductionSettings->SetReductionTargets( Simplygon::EStopCondition::All, true, false, false, false );
	sgReductionSettings->SetReductionTargetTriangleRatio( 0.5f );

	// Start the reduction pipeline. 
	sgReductionPipeline->RunSceneFromFile(inputFile.c_str(), outputFile.c_str(), Simplygon::EPipelineRunMode::RunDistributedUsingSimplygonGrid);

}

int main()
{
	Simplygon::ISimplygon* sg = NULL;
	Simplygon::EErrorCodes initval = Simplygon::Initialize( &sg );
	if( initval != Simplygon::EErrorCodes::NoError )
	{
		return int(initval);
	}

	std::vector<std::future<void>> jobs;
	for(auto& itr: std::filesystem::recursive_directory_iterator("../Assets/"))
	{
		if (itr.path().extension().compare(".gltf") != 0)
			continue;
		std::string inputFile = itr.path().generic_u8string();
		std::string outputFile = itr.path().stem().concat("_LOD").concat( itr.path().extension().generic_u8string() ).generic_u8string();

		jobs.push_back( std::async( [](Simplygon::ISimplygon * sg, std::string inputFile, std::string outputFile)
		{
			RunReduction(sg, inputFile, outputFile);
		}, sg, inputFile, outputFile ));

	}
	for(auto& job: jobs)
	{
		job.wait();
	}

	Simplygon::Deinitialize(sg);

	return 0;
}