// 运行 Console.WriteLine("Start the reduction process."); sgReductionProcessor.RunProcessing();
// 保存模型,通过修改后缀可以实现导出obj, fbx, usd等类型的模型 Console.WriteLine("Save processed scene."); SaveScene(sg, sgScene, "Output.obj"); Console.WriteLine("Check log for any warnings or errors."); CheckLog(sg); }
static Simplygon.spScene LoadScene(Simplygon.ISimplygon sg, string path) { // Create scene importer using Simplygon.spSceneImporter sgSceneImporter = sg.CreateSceneImporter(); sgSceneImporter.SetImportFilePath(path);
// Run scene importer. var importResult = sgSceneImporter.Run(); if (Simplygon.Simplygon.Failed(importResult)) { thrownew System.Exception("Failed to load scene."); } Simplygon.spScene sgScene = sgSceneImporter.GetScene(); return sgScene; }
// Run scene exporter. var exportResult = sgSceneExporter.Run(); if (Simplygon.Simplygon.Failed(exportResult)) { thrownew System.Exception("Failed to save scene."); } }
staticvoidCheckLog(Simplygon.ISimplygon sg) { // Check if any errors occurred. bool hasErrors = sg.ErrorOccurred(); if (hasErrors) { Simplygon.spStringArray errors = sg.CreateStringArray(); sg.GetErrorMessages(errors); var errorCount = errors.GetItemCount(); if (errorCount > 0) { Console.WriteLine("Errors:"); for (uint errorIndex = 0; errorIndex < errorCount; ++errorIndex) { string errorString = errors.GetItem((int)errorIndex); Console.WriteLine(errorString); } sg.ClearErrorMessages(); } } else { Console.WriteLine("No errors."); }
// Check if any warnings occurred. bool hasWarnings = sg.WarningOccurred(); if (hasWarnings) { Simplygon.spStringArray warnings = sg.CreateStringArray(); sg.GetWarningMessages(warnings); var warningCount = warnings.GetItemCount(); if (warningCount > 0) { Console.WriteLine("Warnings:"); for (uint warningIndex = 0; warningIndex < warningCount; ++warningIndex) { string warningString = warnings.GetItem((int)warningIndex); Console.WriteLine(warningString); } sg.ClearWarningMessages(); } } else { Console.WriteLine("No warnings."); }
// Error out if Simplygon has errors. if (hasErrors) { thrownew System.Exception("Processing failed with an error"); } }