internal static Effect ReadAndCompile(string filePath) { var fullPath = AssetManager.GetFullPath(filePath, ".fx"); if (!string.IsNullOrEmpty(fullPath)) { var importer = new EffectImporter(); var processor = new EffectProcessor(); var pipelineManager = new PipelineManager("", "", "") { Profile = Runner.Application.Game.Graphics.GraphicsProfile, Platform = GetTargetPlatform() }; var processorContext = new PipelineProcessorContext( pipelineManager, new PipelineBuildEvent()); var content = importer.Import(fullPath, null); var compiledContent = processor.Process(content, processorContext); var graphicsDevice = Runner.Application.Game.GraphicsDevice; return(new Effect(graphicsDevice, compiledContent.GetEffectCode())); } return(null); }
static void Main(string[] args) { Console.WriteLine("Starting"); var manager = new PipelineManager("", "../bin/Debug/Content", "obj") { Logger = new TestContentBuildLogger() }; var buildEvent = new PipelineBuildEvent(); var pipelineImporterContext = new PipelineImporterContext(manager); var pipelineProcessorContext = new PipelineProcessorContext(manager, buildEvent); Console.WriteLine("Running OepImporter"); OepImporter oepImporter = new OepImporter(); OepContent oepContent = oepImporter.Import( "..\\..\\levels\\new_version\\newProject.oep", pipelineImporterContext ); Console.WriteLine("Complete... Running OepProcessor"); OepProcessor oepProcessor = new OepProcessor(); oepProcessor.Process(oepContent, pipelineProcessorContext); Console.WriteLine("Complete... Running OelImporter"); OelImporter oelImporter = new OelImporter(); OelContent oelContent = oelImporter.Import( "..\\..\\levels\\new_version\\newLevel.oel", pipelineImporterContext ); Console.WriteLine("Complete... Running OelProcessor"); OelProcessor oelProcessor = new OelProcessor(); oelProcessor.Process(oelContent, pipelineProcessorContext); Console.ReadLine(); }
public TOutput Convert <TInput, TOutput>(TInput input, string processorName, OpaqueDataDictionary processorParameters) { try { var processor = ContentProcessors.FirstOrDefault(p => p.GetType().Name == processorName); if (processor == null) { throw new InvalidOperationException(string.Format("Cannot find processor {0}", processorName)); } ApplyParameters(processor, processorParameters); processorContext = processorContext ?? new PipelineProcessorContext(this); return((TOutput)processor.Process(input, processorContext)); } catch (Exception e) { Trace.TraceError("Error converting {0} with processor {1}", input.GetType().Name, processorName); Trace.WriteLine(e); throw new InvalidContentException("", e); } }
public void BuildContent(PipelineBuildEvent pipelineEvent, PipelineBuildEvent cachedEvent, string eventFilepath) { if (!File.Exists(pipelineEvent.SourceFile)) throw new PipelineException("The source file does not exist!"); Logger.PushFile(pipelineEvent.SourceFile); var rebuild = pipelineEvent.NeedsRebuild(cachedEvent); if (!rebuild) { // While this asset doesn't need to be rebuilt the dependent assets might. foreach (var asset in cachedEvent.BuildAsset) { string assetEventFilepath; var assetCachedEvent = LoadBuildEvent(asset, out assetEventFilepath); // If we cannot find the cached event for the dependancy // then we have to trigger a rebuild of the parent content. if (assetCachedEvent == null) { rebuild = true; break; } var depEvent = new PipelineBuildEvent { SourceFile = assetCachedEvent.SourceFile, DestFile = assetCachedEvent.DestFile, Importer = assetCachedEvent.Importer, Processor = assetCachedEvent.Processor, Parameters = assetCachedEvent.Parameters, }; // Give the asset a chance to rebuild. BuildContent(depEvent, assetCachedEvent, assetEventFilepath); } } // Do we need to rebuild? if (rebuild) { Logger.LogMessage("{0}", pipelineEvent.SourceFile); // Make sure we can find the importer and processor. var importer = CreateImporter(pipelineEvent.Importer); if (importer == null) throw new PipelineException("Failed to create importer '{0}'", pipelineEvent.Importer); var processor = CreateProcessor(pipelineEvent.Processor, pipelineEvent.Parameters); if (processor == null) throw new PipelineException("Failed to create processor '{0}'", pipelineEvent.Processor); // Try importing the content. object importedObject; try { var importContext = new PipelineImporterContext(this); importedObject = importer.Import(pipelineEvent.SourceFile, importContext); } catch (PipelineException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Importer '{0}' had unexpected failure!", pipelineEvent.Importer), inner); } // Make sure the input type is valid. if (!processor.InputType.IsAssignableFrom(importedObject.GetType())) { throw new PipelineException( string.Format("The type '{0}' cannot be processed by {1} as a {2}!", importedObject.GetType().FullName, pipelineEvent.Processor, processor.InputType.FullName)); } // Process the imported object. object processedObject; try { var processContext = new PipelineProcessorContext(this, pipelineEvent); processedObject = processor.Process(importedObject, processContext); } catch (PipelineException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Processor '{0}' had unexpected failure!", pipelineEvent.Processor), inner); } // Write the content to disk. WriteXnb(processedObject, pipelineEvent); // Store the new event into the intermediate folder. pipelineEvent.Save(eventFilepath); } else { Logger.LogMessage("Skipping {0}", pipelineEvent.SourceFile); } Logger.PopFile(); }