# Event handling
Simplygon uses an event system to report e.g. processing progress. By implementing and registering an event callback object, the calling function can receive event updates from the system.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include <string>
#include <stdlib.h>
#include <filesystem>
#include <future>
#include "SimplygonLoader.h"
class CustomObserver : public Simplygon::Observer
{
public:
bool OnProgress(Simplygon::spObject subject, Simplygon::real progressPercent) override
{
printf("Progress: %f\n", progressPercent);
// return false to abort the processing
return true;
}
} customObserver;
void RunReduction(Simplygon::ISimplygon* sg)
{
// Create the reduction pipeline.
Simplygon::spReductionPipeline sgReductionPipeline = sg->CreateReductionPipeline();
// Add the custom observer to the reduction pipeline.
sgReductionPipeline->AddObserver(&customObserver);
// Start the reduction pipeline.
sgReductionPipeline->RunSceneFromFile("../Assets/RiggedSimplygonMan/RiggedSimplygonMan.fbx", "output.fbx", Simplygon::EPipelineRunMode::RunInNewProcess);
}
void main()
{
Simplygon::ISimplygon* sg = NULL;
Simplygon::EErrorCodes initval = Simplygon::Initialize( &sg );
if( initval != Simplygon::EErrorCodes::NoError )
{
return;
}
RunReduction(sg);
Simplygon::Deinitialize(sg);
}
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using System.IO;
using System.Threading.Tasks;
public class CustomObserver : Simplygon.Observer
{
public override bool OnProgress(Simplygon.spObject subject, float progressPercent)
{
Console.WriteLine($"Progress: {progressPercent}");
// return false to abort the processing
return true;
}
}
public class Program
{
static private CustomObserver customObserver;
static void RunReduction(Simplygon.ISimplygon sg)
{
// Create the reduction pipeline.
using (Simplygon.spReductionPipeline sgReductionPipeline = sg.CreateReductionPipeline())
{
// Add the custom observer to the reduction pipeline.
sgReductionPipeline.AddObserver(customObserver);
// Start the reduction pipeline.
sgReductionPipeline.RunSceneFromFile("../Assets/RiggedSimplygonMan/RiggedSimplygonMan.fbx", "output.fbx", Simplygon.EPipelineRunMode.RunInNewProcess);
}
}
static void Main(string[] args)
{
using (var sg = Simplygon.Loader.InitSimplygon(out var errorCode, out var errorMessage))
{
if (errorCode != Simplygon.EErrorCodes.NoError)
return;
customObserver = new CustomObserver();
RunReduction(sg);
}
}
}
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import math
import os
import sys
import glob
import gc
import threading
from pathlib import Path
from simplygon import simplygon_loader
from simplygon import Simplygon
class CustomObserver(Simplygon.Observer):
def OnProgress(self, subject: Simplygon.spObject, progressPercent: float):
print("Progress: %f" %(progressPercent))
# return False to abort the processing
return True
customObserver = CustomObserver()
def RunReduction(sg: Simplygon.ISimplygon):
# Create the reduction pipeline.
sgReductionPipeline = sg.CreateReductionPipeline()
# Add the custom observer to the reduction pipeline.
sgReductionPipeline.AddObserver(customObserver)
# Start the reduction pipeline.
sgReductionPipeline.RunSceneFromFile("../Assets/RiggedSimplygonMan/RiggedSimplygonMan.fbx", "output.fbx", Simplygon.EPipelineRunMode_RunInNewProcess)
if __name__ == '__main__':
sg = simplygon_loader.init_simplygon()
RunReduction(sg)
sg = None
gc.collect()