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 PrepareImport(IAssetImportEnvironment env) { foreach (AssetImportInput input in env.HandleAllInput(AcceptsInput)) { env.AddOutput <PythonScript>(input.AssetName, input.Path); } }
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 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. BaseAssetImporter.Import <JsonData>(env); }
public void PrepareImport(IAssetImportEnvironment env) { // Ask to handle all input that matches the conditions in AcceptsInput foreach (AssetImportInput input in env.HandleAllInput(this.AcceptsInput)) { // For all handled input items, specify which Resource the importer intends to create / modify env.AddOutput <DualityFont>(input.AssetName, input.Path); } }
public void PrepareImport(IAssetImportEnvironment env) { // Ask to handle all input that matches the conditions in AcceptsInput foreach (AssetImportInput input in env.HandleAllInput(this.AcceptsInput)) { // For all handled input items, specify which Resource the importer intends to create / modify env.AddOutput<Pixmap>(input.AssetName, input.Path); } }
public void PrepareImport(IAssetImportEnvironment env) { // Ask to handle all input that matches the conditions in AcceptsInput foreach (AssetImportInput input in env.HandleAllInput(this.AcceptsInput)) { // For all handled input items, specify which Resource the importer intends to create / modify env.AddOutput <PlainTextData>(input.AssetName, input.Path); global::Duality.Log.Editor.WriteWarning(""); } }
/// <summary> /// Retrieves the value of an import parameter for the specified <see cref="Resource"/>. /// If the parameter was undefined, it will be (persistently) initialized with the specified default value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="env"></param> /// <param name="resource">A reference to the <see cref="Duality.Resource"/> that is parameterized.</param> /// <param name="parameterName">The name of the parameter.</param> /// <param name="defaultValue">If the value wasn't defined for the given Resource, the default value will be used instead.</param> /// <returns>The retrieved value, or the default value that was specified.</returns> public static T GetOrInitParameter <T>(this IAssetImportEnvironment env, IContentRef resource, string parameterName, T defaultValue) { T value; if (env.GetParameter <T>(resource, parameterName, out value)) { return(value); } env.SetParameter <T>(resource, parameterName, defaultValue); return(defaultValue); }
/// <summary> /// This is a shortcut method for interating over the available input and ask to handle each item /// that matches the specified predicate. If no predicate is specified, this method will try to handle /// all available input. /// </summary> /// <param name="env"></param> /// <param name="predicate"></param> /// <returns>Enumerates all input items which the requesting importer is allowed to handle.</returns> public static IEnumerable <AssetImportInput> HandleAllInput(this IAssetImportEnvironment env, Predicate <AssetImportInput> predicate) { List <AssetImportInput> handledInput = new List <AssetImportInput>(); foreach (AssetImportInput input in env.Input) { if (predicate(input) && env.HandleInput(input.Path)) { handledInput.Add(input); } } return(handledInput); }
public void PrepareImport(IAssetImportEnvironment env) { // Ask to handle all input that matches the conditions in AcceptsInput foreach (AssetImportInput input in env.HandleAllInput(this.AcceptsInput)) { // For all handled input items, specify which Resource the importer intends to create / modify string ext = Path.GetExtension(input.Path); if (string.Equals(ext, SourceFileExtVertex, StringComparison.InvariantCultureIgnoreCase)) env.AddOutput<VertexShader>(input.AssetName, input.Path); else env.AddOutput<FragmentShader>(input.AssetName, input.Path); } }
public void PrepareImport(IAssetImportEnvironment env) { // File all fnt files with allocated png files var importFiles = from file in env.HandleAllInput(f => Path.GetExtension(f.Path).ToLower() == ".fnt" || Path.GetExtension(f.Path).ToLower() == ".xml") select file; foreach (var input in importFiles) { var fileFormat = FigureOutFontFileFormat(input.Path); switch (fileFormat) { case FontFileFormat.None: { // Not a file format we support, ignore continue; } case FontFileFormat.BMFont: { var fontData = LoadBMFontData(input.Path); if (fontData.Pages.Count() > 1) { Log.Editor.WriteError("Only single page bitmap font files are allowed"); continue; //skip this file } env.AddOutput <Duality.Resources.Font>(input.AssetName, input.Path); foreach (var page in fontData.Pages) { var fullPath = Path.Combine(Path.GetDirectoryName(input.Path), page.File); if (File.Exists(fullPath)) { env.AddOutput <Pixmap>(input.AssetName, fullPath); } else { Log.Editor.WriteError("Corresponding bitmap font page file '{0}' not found ", fullPath); continue; //skip this file } } break; } } } }
public void Import(IAssetImportEnvironment env) { foreach (AssetImportInput input in env.Input) { ContentRef <PythonScript> targetRef = env.GetOutput <PythonScript>(input.AssetName); if (targetRef.IsAvailable) { PythonScript target = targetRef.Res; string fileData = File.ReadAllText(input.Path); target.UpdateContent(fileData); env.AddOutput(targetRef, input.Path); } } }
public void PrepareImport(IAssetImportEnvironment env) { // Ask to handle all input that matches the conditions in AcceptsInput foreach (AssetImportInput input in env.HandleAllInput(this.AcceptsInput)) { // For all handled input items, specify which Resource the importer intends to create / modify string ext = Path.GetExtension(input.Path); if (string.Equals(ext, SourceFileExtVertex, StringComparison.InvariantCultureIgnoreCase)) { env.AddOutput <VertexShader>(input.AssetName, input.Path); } else { env.AddOutput <FragmentShader>(input.AssetName, input.Path); } } }
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) { // Request a target Resource with a name matching the input ContentRef <DualityFont> targetRef = env.GetOutput <DualityFont>(input.AssetName); // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { DualityFont target = targetRef.Res; // Retrieve import parameters float size = env.GetOrInitParameter(targetRef, "Size", 16.0f); FontStyle style = env.GetOrInitParameter(targetRef, "Style", FontStyle.Regular); string extendedCharSet = env.GetOrInitParameter(targetRef, "ExtendedCharSet", string.Empty); bool antialiasing = env.GetOrInitParameter(targetRef, "AntiAlias", true); bool monospace = env.GetOrInitParameter(targetRef, "Monospace", false); // Load the TrueType Font and render all the required glyphs byte[] trueTypeData = File.ReadAllBytes(input.Path); RenderedFontData fontData = this.RenderGlyphs( trueTypeData, size, style, !string.IsNullOrEmpty(extendedCharSet) ? new FontCharSet(extendedCharSet) : null, antialiasing, monospace); // Transfer our rendered Font data to the Font Resource target.SetGlyphData( fontData.Bitmap, fontData.Atlas, fontData.GlyphData, fontData.Metrics); // Add the requested output to signal that we've done something with it env.AddOutput(targetRef, input.Path); } } }
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) { // Request a target Resource with a name matching the input ContentRef<DualityFont> targetRef = env.GetOutput<DualityFont>(input.AssetName); // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { DualityFont target = targetRef.Res; // Retrieve import parameters float size = env.GetOrInitParameter(targetRef, "Size" , 16.0f ); FontStyle style = env.GetOrInitParameter(targetRef, "Style" , FontStyle.Regular); string extendedCharSet = env.GetOrInitParameter(targetRef, "ExtendedCharSet", string.Empty ); bool antialiasing = env.GetOrInitParameter(targetRef, "AntiAlias" , true ); bool monospace = env.GetOrInitParameter(targetRef, "Monospace" , false ); // Load the TrueType Font and render all the required glyphs byte[] trueTypeData = File.ReadAllBytes(input.Path); RenderedFontData fontData = this.RenderGlyphs( trueTypeData, size, style, !string.IsNullOrEmpty(extendedCharSet) ? new FontCharSet(extendedCharSet) : null, antialiasing, monospace); // Transfer our rendered Font data to the Font Resource target.SetGlyphData( fontData.Bitmap, fontData.Atlas, fontData.GlyphData, fontData.Metrics); // Add the requested output to signal that we've done something with it env.AddOutput(targetRef, input.Path); } } }
public void Import(IAssetImportEnvironment env) { foreach (AssetImportInput input in env.Input) { // Request a target Resource with a name matching the input ContentRef <Duality.Resources.Font> targetRef = env.GetOutput <Duality.Resources.Font>(input.AssetName); // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { Duality.Resources.Font target = targetRef.Res; var fileFormat = FigureOutFontFileFormat(input.Path); switch (fileFormat) { case FontFileFormat.BMFont: { var fontData = LoadBMFontData(input.Path); var textureData = LoadPixelData(fontData, Path.GetFullPath(Path.GetDirectoryName(input.Path))); target.SetGlyphData(textureData, fontData.Atlas.ToArray(), fontData.Glyps.ToArray(), fontData.Height, fontData.Ascent, fontData.BodyAscent, fontData.Descent, fontData.Baseline); target.Size = fontData.Size; //target.Kerning = true; env.AddOutput(targetRef, input.Path); break; } } } } }
void IAssetImporter.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) { // Request a target Resource with a name matching the input ContentRef <T> targetRef = env.GetOutput <T>(this.GetResourceNameFromInput(input)); // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { this.ImportResource(targetRef, input, env); // Add the requested output to signal that we've done something with it env.AddOutput(targetRef, input.Path); } } }
internal static void Import <T>(IAssetImportEnvironment env) where T : TextFile, new() { foreach (AssetImportInput input in env.Input) { ContentRef <T> targetRef = env.GetOutput <T>(input.AssetName); if (targetRef.IsAvailable) { T target = targetRef.Res; if (!String.IsNullOrWhiteSpace(input.Path)) { using (System.IO.StreamReader sr = new StreamReader(input.Path)) { string content = sr.ReadToEnd(); target.SetData(content, sr.CurrentEncoding.GetByteCount(content), sr.CurrentEncoding); } } env.AddOutput(targetRef, input.Path); } } }
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) { // Request a target Resource with a name matching the input ContentRef <AudioData> targetRef = env.GetOutput <AudioData>(input.AssetName); // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { AudioData target = targetRef.Res; // Update audio data from the input file target.OggVorbisData = File.ReadAllBytes(input.Path); // Add the requested output to signal that we've done something with it env.AddOutput(targetRef, input.Path); } } }
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) { // Request a target Resource with a name matching the input ContentRef<AudioData> targetRef = env.GetOutput<AudioData>(input.AssetName); // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { AudioData target = targetRef.Res; // Update audio data from the input file target.OggVorbisData = File.ReadAllBytes(input.Path); // Add the requested output to signal that we've done something with it env.AddOutput(targetRef, input.Path); } } }
public void PrepareImport(IAssetImportEnvironment env) { //env.HandleAllInput }
protected override void ImportResource(ContentRef <AudioData> resourceRef, AssetImportInput input, IAssetImportEnvironment env) { AudioData resource = resourceRef.Res; // Update audio data from the input file resource.OggVorbisData = File.ReadAllBytes(input.Path); }
protected override void ImportResource(ContentRef <Pixmap> resourceRef, AssetImportInput input, IAssetImportEnvironment env) { Pixmap resource = resourceRef.Res; // Retrieve import parameters int sheetCols = env.GetOrInitParameter(resourceRef, "SpriteSheetColumns", 0); int sheetRows = env.GetOrInitParameter(resourceRef, "SpriteSheetRows", 0); int frameBorder = env.GetOrInitParameter(resourceRef, "SpriteFrameBorder", 0); // Clamp import parameters if (sheetCols < 0) { sheetCols = 0; } if (sheetRows < 0) { sheetRows = 0; } if (frameBorder < 0) { frameBorder = 0; } env.SetParameter(resourceRef, "SpriteSheetColumns", sheetCols); env.SetParameter(resourceRef, "SpriteSheetRows", sheetRows); env.SetParameter(resourceRef, "SpriteFrameBorder", frameBorder); // Update pixel data from the input file PixelData pixelData = this.LoadPixelData(input.Path); resource.MainLayer = pixelData; // Generate a sprite sheet atlas if (sheetCols > 0 && sheetRows > 0) { this.GenerateSpriteSheetAtlas(resource, sheetCols, sheetRows, frameBorder); } }
/// <summary> /// Submits the specified <see cref="Duality.Resource"/> as a generated output of the current importer. /// </summary> /// <param name="resource">A reference to the generated output <see cref="Duality.Resource"/>.</param> /// <param name="inputPath">The input path that is used to generate this output <see cref="Duality.Resource"/>.</param> public static void AddOutput(this IAssetImportEnvironment env, IContentRef resource, string inputPath) { env.AddOutput(resource, new string[] { inputPath }); }
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) { // Request a target Resource with a name matching the input ContentRef <DualityFont> targetRef = env.GetOutput <DualityFont>(input.AssetName); // If we successfully acquired one, proceed with the import if (targetRef.IsAvailable) { DualityFont target = targetRef.Res; // Retrieve import parameters float size = env.GetOrInitParameter(targetRef, "Size", 16.0f); FontStyle style = env.GetOrInitParameter(targetRef, "Style", FontStyle.Regular); string customCharSet = env.GetOrInitParameter(targetRef, "CustomCharSet", string.Empty); List <UnicodeBlock> unicodeBlocks = env.GetOrInitParameter(targetRef, "UnicodeBlocks", new List <UnicodeBlock>(DefaultBlocks)); bool antialiasing = env.GetOrInitParameter(targetRef, "AntiAlias", true); bool monospace = env.GetOrInitParameter(targetRef, "Monospace", false); HashSet <char> fullCharSet = new HashSet <char>(); if (!string.IsNullOrWhiteSpace(customCharSet)) { string[] blocks = customCharSet.Split(','); ulong start = 0; ulong end = 0; foreach (string block in blocks) { string[] limits = block.Split(new[] { '-' }, 3); if (!ulong.TryParse(limits[0], NumberStyles.HexNumber, null, out start)) { Log.Editor.WriteError("Cannot parse value " + limits[0] + "; CustomCharSet will be ignored. Please verify the value and repeat the import."); } if (limits.Length == 1) { end = start; } else { if (limits.Length == 2 && !ulong.TryParse(limits[1], NumberStyles.HexNumber, null, out end)) { Log.Editor.WriteError("Cannot parse value " + limits[1] + "; CustomCharSet will be ignored. Please verify the value and repeat the import."); } else if (limits.Length > 2) { Log.Editor.WriteError("Unexpected values " + limits[2] + " in range " + block + " will be ignored. Please verify the value and repeat the import."); } if (start > end) { Log.Editor.WriteWarning(start + " is bigger than " + end + "; block will be ignored. Please verify the value and repeat the import."); } } for (char c = (char)start; c <= (char)end; c++) { if (!char.IsControl(c)) { fullCharSet.Add(c); } } } } if (unicodeBlocks != null) { Type unicodeBlockType = typeof(UnicodeBlock); Type unicodeRangeAttrType = typeof(UnicodeRangeAttribute); foreach (UnicodeBlock block in unicodeBlocks) { UnicodeRangeAttribute range = unicodeBlockType.GetMember(block.ToString()) .First() .GetCustomAttributes(unicodeRangeAttrType, false) .FirstOrDefault() as UnicodeRangeAttribute; if (range != null) { for (char c = (char)range.CharStart; c <= (char)range.CharEnd; c++) { if (!char.IsControl(c)) { fullCharSet.Add(c); } } } } } // Load the TrueType Font and render all the required glyphs byte[] trueTypeData = File.ReadAllBytes(input.Path); RenderedFontData fontData = this.RenderGlyphs( trueTypeData, size, style, new FontCharSet(new string(fullCharSet.ToArray())), antialiasing, monospace); // Transfer our rendered Font data to the Font Resource target.SetGlyphData( fontData.Bitmap, fontData.Atlas, fontData.GlyphData, fontData.Metrics); // Add the requested output to signal that we've done something with it env.AddOutput(targetRef, input.Path); } } }
/// <summary> /// Specifies that the current importer will create or modify a <see cref="Duality.Resource"/> with /// the specified name (see <see cref="Duality.Editor.AssetManagement.AssetImportInput.AssetName"/>). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="assetName">The name of the generated output <see cref="Duality.Resource"/> (see <see cref="Duality.Editor.AssetManagement.AssetImportInput.AssetName"/>).</param> /// <param name="inputPath">The input path that is used to generate this output <see cref="Duality.Resource"/>.</param> public static void AddOutput <T>(this IAssetImportEnvironment env, string assetName, string inputPath) where T : Resource { env.AddOutput <T>(assetName, new string[] { inputPath }); }
protected override void ImportResource(ContentRef <Pixmap> resourceRef, AssetImportInput input, IAssetImportEnvironment env) { Pixmap resource = resourceRef.Res; // Update pixel data from the input file PixelData pixelData = this.LoadPixelData(input.Path); resource.MainLayer = pixelData; }
public void Import(IAssetImportEnvironment env) { }
protected override void ImportResource(ContentRef <DualityFont> resourceRef, AssetImportInput input, IAssetImportEnvironment env) { DualityFont resource = resourceRef.Res; // Retrieve import parameters float size = env.GetOrInitParameter(resourceRef, "Size", 16.0f); FontStyle style = env.GetOrInitParameter(resourceRef, "Style", FontStyle.Regular); string customCharSet = env.GetOrInitParameter(resourceRef, "CustomCharSet", string.Empty); List <UnicodeBlock> unicodeBlocks = env.GetOrInitParameter(resourceRef, "UnicodeBlocks", new List <UnicodeBlock>(DefaultBlocks)); bool antialiasing = env.GetOrInitParameter(resourceRef, "AntiAlias", true); bool monospace = env.GetOrInitParameter(resourceRef, "Monospace", false); HashSet <char> fullCharSet = new HashSet <char>(); if (!string.IsNullOrWhiteSpace(customCharSet)) { string[] blocks = customCharSet.Split(','); ulong start = 0; ulong end = 0; foreach (string block in blocks) { string[] limits = block.Split(new[] { '-' }, 3); if (!ulong.TryParse(limits[0], NumberStyles.HexNumber, null, out start)) { Log.Editor.WriteError("Cannot parse value " + limits[0] + "; CustomCharSet will be ignored. Please verify the value and repeat the import."); } if (limits.Length == 1) { end = start; } else { if (limits.Length == 2 && !ulong.TryParse(limits[1], NumberStyles.HexNumber, null, out end)) { Log.Editor.WriteError("Cannot parse value " + limits[1] + "; CustomCharSet will be ignored. Please verify the value and repeat the import."); } else if (limits.Length > 2) { Log.Editor.WriteError("Unexpected values " + limits[2] + " in range " + block + " will be ignored. Please verify the value and repeat the import."); } if (start > end) { Log.Editor.WriteWarning(start + " is bigger than " + end + "; block will be ignored. Please verify the value and repeat the import."); } } for (char c = (char)start; c <= (char)end; c++) { if (!char.IsControl(c)) { fullCharSet.Add(c); } } } } if (unicodeBlocks != null) { Type unicodeBlockType = typeof(UnicodeBlock); Type unicodeRangeAttrType = typeof(UnicodeRangeAttribute); foreach (UnicodeBlock block in unicodeBlocks) { UnicodeRangeAttribute range = unicodeBlockType.GetMember(block.ToString()) .First() .GetCustomAttributes(unicodeRangeAttrType, false) .FirstOrDefault() as UnicodeRangeAttribute; if (range != null) { for (char c = (char)range.CharStart; c <= (char)range.CharEnd; c++) { if (!char.IsControl(c)) { fullCharSet.Add(c); } } } } } // Load the TrueType Font and render all the required glyphs byte[] trueTypeData = File.ReadAllBytes(input.Path); RenderedFontData fontData = this.RenderGlyphs( trueTypeData, size, style, new FontCharSet(new string(fullCharSet.ToArray())), antialiasing, monospace); // Transfer our rendered Font data to the Font Resource resource.SetGlyphData( fontData.Bitmap, fontData.Atlas, fontData.GlyphData, fontData.Metrics); }
/// <summary> /// Performs the import operation for a resource. /// </summary> /// <param name="resourceRef">A <see cref="ContentRef{T}"/> pointing to the resource being imported.</param> /// <param name="input">The input information for the import operation.</param> /// <param name="env">The input environment in which the import is taking place.</param> protected abstract void ImportResource(ContentRef <T> resourceRef, AssetImportInput input, IAssetImportEnvironment env);