public void Import(IAssetImportEnvironment env) { // Handle all available input. No need to filter or ask for this anymore, as // the preparation step already made a selection with AcceptsInput. We won't // get any input here that didn't match. foreach (AssetImportInput input in env.Input) { string ext = Path.GetExtension(input.Path); // Request a target Resource with a name matching the input IContentRef targetRef; if (string.Equals(ext, SourceFileExtVertex, StringComparison.InvariantCultureIgnoreCase)) { targetRef = env.GetOutput <VertexShader>(input.AssetName); } else { targetRef = env.GetOutput <FragmentShader>(input.AssetName); } // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { AbstractShader target = targetRef.Res as AbstractShader; // Update shader data from the input file target.Source = File.ReadAllText(input.Path); target.Compile(); // Add the requested output to signal that we've done something with it env.AddOutput(targetRef, input.Path); } } }
public void ReImportFile(ContentRef <Resource> r, string srcFile) { AbstractShader s = r.Res as AbstractShader; s.LoadSource(srcFile); s.Compile(); }
private void ActionShaderCreateProgram_Create(FragmentShader frag, VertexShader vert) { AbstractShader refShader = (vert != null) ? (AbstractShader)vert : (AbstractShader)frag; string nameTemp = refShader.Name; string dirTemp = Path.GetDirectoryName(refShader.Path); if (nameTemp.Contains("Shader")) { nameTemp = nameTemp.Replace("Shader", "Program"); } else if (nameTemp.Contains("Shader")) { nameTemp = nameTemp.Replace("shader", "program"); } else { nameTemp += "Program"; } string programPath = PathHelper.GetFreePath(Path.Combine(dirTemp, nameTemp), ShaderProgram.FileExt); ShaderProgram program = new ShaderProgram(vert, frag); program.Save(programPath); }
private void ActionAbstractShaderOpenRes(AbstractShader shader) { if (shader == null) { return; } FileImportProvider.OpenSourceFile(shader, shader is FragmentShader ? ".frag" : ".vert", shader.SaveSource); }
public void ReImportFile(ContentRef <Resource> r, string srcFile) { AbstractShader s = r.Res as AbstractShader; string sourceCode = File.ReadAllText(srcFile); s.Source = sourceCode; s.SourcePath = srcFile; s.Compile(); }
public override void Perform(Resource obj) { Pixmap pixmap = obj as Pixmap; AbstractShader shader = obj as AbstractShader; if (pixmap != null) { FileImportProvider.OpenSourceFile(pixmap, ".png", pixmap.SavePixelData); } else if (shader != null) { FileImportProvider.OpenSourceFile(shader, shader is FragmentShader ? ".frag" : shader is VertexShader ? ".vert" : ".geom", shader.SaveSource); } }
public void Export(IAssetExportEnvironment env) { // Determine input and output path AbstractShader input = env.Input as AbstractShader; string outputPath; if (env.Input is FragmentShader) { outputPath = env.AddOutputPath(input.Name + SourceFileExtFragment); } else { outputPath = env.AddOutputPath(input.Name + SourceFileExtVertex); } // Take the input Resource's TrueType font data and save it at the specified location File.WriteAllText(outputPath, input.Source); }
public override void Perform(Resource obj) { Pixmap pixmap = obj as Pixmap; AudioData audioData = obj as AudioData; AbstractShader shader = obj as AbstractShader; if (pixmap != null) { FileImportProvider.OpenSourceFile(pixmap, PixmapFileImporter.SourceFileExtPrimary, pixmap.SavePixelData); } else if (audioData != null) { FileImportProvider.OpenSourceFile(audioData, AudioDataFileImporter.SourceFileExtPrimary, audioData.SaveOggVorbisData); } else if (shader != null) { FileImportProvider.OpenSourceFile(shader, shader is FragmentShader ? ShaderFileImporter.SourceFileExtFragment : ShaderFileImporter.SourceFileExtVertex, shader.SaveSource); } }
public override void Perform(Resource obj) { Pixmap pixmap = obj as Pixmap; AudioData audioData = obj as AudioData; AbstractShader shader = obj as AbstractShader; if (pixmap != null) { FileImportProvider.OpenSourceFile(pixmap, ".png", pixmap.SavePixelData); } else if (audioData != null) { FileImportProvider.OpenSourceFile(audioData, ".ogg", audioData.SaveOggVorbisData); } else if (shader != null) { FileImportProvider.OpenSourceFile(shader, shader is FragmentShader ? ".frag" : ".vert", shader.SaveSource); } }
public override void Perform(Resource obj) { Pixmap pixmap = obj as Pixmap; AudioData audioData = obj as AudioData; AbstractShader shader = obj as AbstractShader; if (pixmap != null) { FileImportProvider.OpenSourceFile( pixmap, PixmapFileImporter.SourceFileExtPrimary, path => SavePixmapData(pixmap, path)); } else if (audioData != null) { FileImportProvider.OpenSourceFile( audioData, AudioDataFileImporter.SourceFileExtPrimary, path => SaveAudioData(audioData, path)); } else if (shader != null) { string fileExt; if (shader is FragmentShader) { fileExt = ShaderFileImporter.SourceFileExtFragment; } else { fileExt = ShaderFileImporter.SourceFileExtVertex; } FileImportProvider.OpenSourceFile( shader, fileExt, path => SaveShaderData(shader, path)); } }
private static void SaveShaderData(AbstractShader shader, string targetPath) { File.WriteAllText(targetPath, shader.Source); }