# 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 CustomErrorHandler(Simplygon.ErrorHandler):
    def HandleError(self, object: Simplygon.spObject, interfaceName: str, methodName: str, errorType: int, errorText: str):
        print("Error (%s:%s): %s" %(interfaceName, methodName, errorText))

customErrorHandler = CustomErrorHandler()

def RunReduction(sg: Simplygon.ISimplygon):
    # Set the custom error handler to the Simplygon interface. 
    sg.SetErrorHandler(customErrorHandler)
    # Create the reduction pipeline. 
    sgReductionPipeline = sg.CreateReductionPipeline()

    # Start the reduction pipeline with a faulty input file path. 
    sgReductionPipeline.RunSceneFromFile("Foo.bar", "output.fbx", Simplygon.EPipelineRunMode_RunInNewProcess)


if __name__ == '__main__':
    sg = simplygon_loader.init_simplygon()

    RunReduction(sg)

    sg = None
    gc.collect()

