# 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()

