public static ContentCompilerResult CompileFromFile(string fileName, ModelCompilerOptions compilerOptions) { using (var stream = new NativeFileStream(fileName, NativeFileMode.Open, NativeFileAccess.Read)) { return(Compile(stream, fileName, compilerOptions)); } }
protected override Diagnostics.Logger ProcessFileAndGetLogResults(string inputFilePath, string outputFilePath, string dependencyFilePath, TkItem item) { var compilerOptions = new ModelCompilerOptions() { DependencyFile = dependencyFilePath, Quality = Debug ? ModelRealTimeQuality.Low : ModelRealTimeQuality.Maximum }; var compilerResult = ModelCompiler.CompileAndSave(inputFilePath, outputFilePath, compilerOptions); return compilerResult.Logger; }
private ContentCompilerResult CompileFromFileInternal(string fileName, ModelCompilerOptions compilerOptions) { logger = new Logger(); var result = new ContentCompilerResult() { Logger = logger }; modelFilePath = fileName; modelDirectory = Path.GetDirectoryName(modelFilePath); // Preload AssimpLibrary if not already loaded if (!AssimpLibrary.Instance.IsLibraryLoaded) { var rootPath = Path.GetDirectoryName(typeof(AssimpLibrary).Assembly.Location); AssimpLibrary.Instance.LoadLibrary(Path.Combine(rootPath, AssimpLibrary.Instance.DefaultLibraryPath32Bit), Path.Combine(rootPath, AssimpLibrary.Instance.DefaultLibraryPath64Bit)); } var importer = new AssimpContext(); importer.SetConfig(new Assimp.Configs.MaxBoneCountConfig(72)); //importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); // Steps for Direct3D Right-Handed, should we make this configurable? var steps = PostProcessSteps.FlipUVs | PostProcessSteps.FlipWindingOrder | PostProcessSteps.LimitBoneWeights | PostProcessSteps.SplitByBoneCount; // Setup quality switch (compilerOptions.Quality) { case ModelRealTimeQuality.Low: steps |= PostProcessPreset.TargetRealTimeFast; break; case ModelRealTimeQuality.Maximum: steps |= PostProcessPreset.TargetRealTimeMaximumQuality; break; default: steps |= PostProcessPreset.TargetRealTimeQuality; break; } scene = importer.ImportFile(fileName, steps); model = new ModelData(); ProcessScene(); result.IsContentGenerated = true; result.ModelData = model; return(result); }
public static ContentCompilerResult CompileAndSave(string fileName, string outputFile, ModelCompilerOptions compilerOptions) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (outputFile == null) { throw new ArgumentNullException("outputFile"); } if (compilerOptions == null) { throw new ArgumentNullException("compilerOptions"); } bool contentToUpdate = true; if (compilerOptions.DependencyFile != null) { if (!FileDependencyList.CheckForChanges(compilerOptions.DependencyFile)) { contentToUpdate = false; } } var result = new ContentCompilerResult { Logger = new Logger() }; if (contentToUpdate) { try { result = CompileFromFile(fileName, compilerOptions); if (result.HasErrors) { return(result); } var modelData = result.ModelData; // Make sure that directory name doesn't collide with filename var directoryName = Path.GetDirectoryName(outputFile + ".tmp"); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // Save the model modelData.Save(outputFile); if (compilerOptions.DependencyFile != null) { // Save the dependency var dependencyList = new FileDependencyList(); dependencyList.AddDefaultDependencies(); dependencyList.AddDependencyPath(fileName); dependencyList.Save(compilerOptions.DependencyFile); } result.IsContentGenerated = true; } catch (Exception ex) { result.Logger.Error("Unexpected exception while converting {0} : {1}", fileName, ex.ToString()); } } return(result); }
public static ContentCompilerResult CompileFromFile(string fileName, ModelCompilerOptions compilerOptions) { var modelCompiler = new ModelCompiler(); return(modelCompiler.CompileFromFileInternal(fileName, compilerOptions)); }
void Run(string[] args) { // Print the exe header PrintHeader(); // Parse the command line if (!ParseCommandLine(args)) Environment.Exit(-1); var options = this; bool hasErrors = false; // ---------------------------------------------------------------- // Process model file // ---------------------------------------------------------------- var filePath = Path.Combine(Environment.CurrentDirectory, ModelFile); if (!File.Exists(filePath)) { ErrorColor(); Console.Error.WriteLine("File [{0}] does not exist", filePath); ResetColor(); Environment.Exit(-1); } var defaultOutputFile = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); // Compiles to SpriteData OutputFile = OutputFile ?? defaultOutputFile; string dependencyFile = null; if (CompileOnlyIfNewer) { dependencyFile = Path.Combine(OutputDependencyDirectory, FileDependencyList.GetDependencyFileNameFromSourcePath(Path.GetFileName(filePath))); } Console.WriteLine("Compile Model from File [{0}] => {1}", filePath, OutputFile); var compilerOptions = new ModelCompilerOptions() { DependencyFile = dependencyFile, Quality = FastQuality ? ModelRealTimeQuality.Low : ModelRealTimeQuality.Maximum }; var result = ModelCompiler.CompileAndSave(filePath, OutputFile, compilerOptions); if (result.HasErrors) { ErrorColor(); Console.Error.WriteLine("Compilation has errors. Process aborted."); ResetColor(); Environment.Exit(-1); } if (result.IsContentGenerated) { Console.WriteLine("Successful"); } else { Console.WriteLine("Nothing to generate. Model and Compiled Model are in sync"); } }
/// <summary>Compiles the and save.</summary> /// <param name="fileName">Name of the file.</param> /// <param name="outputFile">The output file.</param> /// <param name="compilerOptions">The compiler options.</param> /// <returns>ContentCompilerResult.</returns> /// <exception cref="System.ArgumentNullException"> /// fileName /// or /// outputFile /// or /// compilerOptions /// </exception> public static ContentCompilerResult CompileAndSave(string fileName, string outputFile, ModelCompilerOptions compilerOptions) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (outputFile == null) { throw new ArgumentNullException("outputFile"); } if (compilerOptions == null) { throw new ArgumentNullException("compilerOptions"); } bool contentToUpdate = true; if (compilerOptions.DependencyFile != null) { if (!FileDependencyList.CheckForChanges(compilerOptions.DependencyFile)) { contentToUpdate = false; } } var result = new ContentCompilerResult { Logger = new Logger() }; if (contentToUpdate) { try { result = CompileFromFile(fileName, compilerOptions); if (result.HasErrors) { return result; } var modelData = result.ModelData; // Make sure that directory name doesn't collide with filename var directoryName = Path.GetDirectoryName(outputFile + ".tmp"); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // Save the model modelData.Save(outputFile); if (compilerOptions.DependencyFile != null) { // Save the dependency var dependencyList = new FileDependencyList(); dependencyList.AddDefaultDependencies(); dependencyList.AddDependencyPath(fileName); dependencyList.Save(compilerOptions.DependencyFile); } result.IsContentGenerated = true; } catch (Exception ex) { result.Logger.Error("Unexpected exception while converting {0} : {1}", fileName, ex.ToString()); } } return result; }
private ContentCompilerResult CompileFromFileInternal(string fileName, ModelCompilerOptions compilerOptions) { logger = new Logger(); var result = new ContentCompilerResult() { Logger = logger }; modelFilePath = fileName; modelDirectory = Path.GetDirectoryName(modelFilePath); // Preload AssimpLibrary if not already loaded if (!AssimpLibrary.Instance.LibraryLoaded) { var rootPath = Path.GetDirectoryName(typeof(AssimpLibrary).Assembly.Location); AssimpLibrary.Instance.LoadLibrary(Path.Combine(rootPath, AssimpLibrary.Instance.DefaultLibraryPath32Bit), Path.Combine(rootPath, AssimpLibrary.Instance.DefaultLibraryPath64Bit)); } var importer = new AssimpImporter(); //importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); // Steps for Direct3D, should we make this configurable? var steps = PostProcessSteps.FlipUVs | PostProcessSteps.FlipWindingOrder | PostProcessSteps.MakeLeftHanded; // Setup quality switch (compilerOptions.Quality) { case ModelRealTimeQuality.Low: steps |= PostProcessPreset.TargetRealTimeFast; break; case ModelRealTimeQuality.Maximum: steps |= PostProcessPreset.TargetRealTimeMaximumQuality; break; default: steps |= PostProcessPreset.TargetRealTimeQuality; break; } scene = importer.ImportFile(fileName, steps); model = new ModelData(); ProcessScene(); result.IsContentGenerated = true; result.ModelData = model; return result; }
/// <summary>Compiles from file.</summary> /// <param name="fileName">Name of the file.</param> /// <param name="compilerOptions">The compiler options.</param> /// <returns>ContentCompilerResult.</returns> public static ContentCompilerResult CompileFromFile(string fileName, ModelCompilerOptions compilerOptions) { var modelCompiler = new ModelCompiler(); return modelCompiler.CompileFromFileInternal(fileName, compilerOptions); }
public static ContentCompilerResult Compile(Stream modelStream, string fileName, ModelCompilerOptions compilerOptions) { var compiler = new ModelCompiler(); return(compiler.CompileFromStream(modelStream, fileName, compilerOptions)); }
public static ContentCompilerResult Compile(Stream modelStream, string fileName, ModelCompilerOptions compilerOptions) { var compiler = new ModelCompiler(); return compiler.CompileFromStream(modelStream, fileName, compilerOptions); }
public static ContentCompilerResult CompileFromFile(string fileName, ModelCompilerOptions compilerOptions) { using (var stream = new NativeFileStream(fileName, NativeFileMode.Open, NativeFileAccess.Read)) { return Compile(stream, fileName, compilerOptions); } }