/// <summary> /// Called by the framework when importing a game asset. This is the method called by XNA when an asset is to be imported into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>Resulting game asset.</returns> object IContentImporter.Import(string filename, ContentImporterContext context) { if (filename == null) { throw new ArgumentNullException(nameof(filename)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } return(Import(filename, context)); }
/// <summary> /// Called by the framework when importing a .spritefont file to be used as a game asset. /// This is the method called by the framework when an asset is to be /// imported into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>Resulting game asset.</returns> public override FontDescription Import(string filename, ContentImporterContext context) { FontDescription fontDescription = null; using (var input = XmlReader.Create(filename)) fontDescription = IntermediateSerializer.Deserialize <FontDescription>(input, filename); fontDescription.Identity = new ContentIdentity( new FileInfo(filename).FullName, nameof(FontDescriptionImporter)); return(fontDescription); }
public override NodeContent Import(string filename, ContentImporterContext context) { if (filename == null) { throw new ArgumentNullException(nameof(filename)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } var importer = new OpenAssetImporter("FbxImporter", true); return(importer.Import(filename, context)); }
/// <summary> /// Called by the XNA Framework when importing an MP3 audio file to be used as a game asset. This is the method called by the XNA Framework when an asset is to be imported into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>Resulting game asset.</returns> public override AudioContent Import(string filename, ContentImporterContext context) { if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException(nameof(filename)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } if (!File.Exists(filename)) { throw new FileNotFoundException(string.Format("Could not locate audio file {0}.", Path.GetFileName(filename))); } var content = new AudioContent(filename, AudioFileType.Mp3); return(content); }
/// <summary> /// This is the method called by the XNA Framework when an asset is to be /// imported into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>Resulting game asset.</returns> public override TextureContent Import(string filename, ContentImporterContext context) { // Special case for loading some formats switch (Path.GetExtension(filename).ToUpperInvariant()) { case ".DDS": return(DdsLoader.Import(filename, context)); } var output = new Texture2DContent { Identity = new ContentIdentity(filename) }; var format = FreeImage.GetFileType(filename, 0); var fBitmap = FreeImage.Load(format, filename, 0); //if freeimage can not recognize the image type if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN) { throw new ContentLoadException("TextureImporter failed to load '" + filename + "'"); } //if freeimage can recognize the file headers but can't read its contents else if (fBitmap == IntPtr.Zero) { throw new InvalidContentException( "TextureImporter couldn't understand the contents of '" + filename + "'", output.Identity); } var height = (int)FreeImage.GetHeight(fBitmap); var width = (int)FreeImage.GetWidth(fBitmap); var imageType = FreeImage.GetImageType(fBitmap); // Swizzle channels and expand to include an alpha channel fBitmap = ConvertAndSwapChannels(fBitmap, imageType); // The bits per pixel and image type may have changed imageType = FreeImage.GetImageType(fBitmap); uint bpp = FreeImage.GetBPP(fBitmap); var pitch = (int)FreeImage.GetPitch(fBitmap); var redMask = FreeImage.GetRedMask(fBitmap); var greenMask = FreeImage.GetGreenMask(fBitmap); var blueMask = FreeImage.GetBlueMask(fBitmap); // Create the byte array for the data byte[] bytes = new byte[((width * height * bpp - 1) / 8) + 1]; // Converts the pixel data to bytes, do not try to use this call to // switch the color channels because that only works for 16bpp bitmaps FreeImage.ConvertToRawBits(bytes, fBitmap, pitch, bpp, redMask, greenMask, blueMask, true); // Create the Pixel bitmap content depending on the image type BitmapContent face; switch (imageType) { case FREE_IMAGE_TYPE.FIT_RGBAF: face = new PixelBitmapContent <RgbaVector>(width, height); break; case FREE_IMAGE_TYPE.FIT_RGBA16: face = new PixelBitmapContent <Rgba64>(width, height); break; //case FREE_IMAGE_TYPE.FIT_BITMAP: default: face = new PixelBitmapContent <Color>(width, height); break; } FreeImage.Unload(fBitmap); face.SetPixelData(bytes); output.Faces[0].Add(face); return(output); }
internal static TextureContent Import(string filename, ContentImporterContext context) { var identity = new ContentIdentity(filename); TextureContent output = null; using (var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read)) using (var reader = new BinaryReader(fileStream)) { // Signature ("DDS ") if (reader.ReadByte() != 0x44 || reader.ReadByte() != 0x44 || reader.ReadByte() != 0x53 || reader.ReadByte() != 0x20) { throw new ContentLoadException("Invalid file signature"); } var header = new DdsHeader { // Read DDS_HEADER dwSize = reader.ReadUInt32() }; if (header.dwSize != 124) { throw new ContentLoadException("Invalid DDS_HEADER dwSize value"); } header.dwFlags = (Ddsd)reader.ReadUInt32(); header.dwHeight = reader.ReadUInt32(); header.dwWidth = reader.ReadUInt32(); header.dwPitchOrLinearSize = reader.ReadUInt32(); header.dwDepth = reader.ReadUInt32(); header.dwMipMapCount = reader.ReadUInt32(); // The next 11 DWORDs are reserved and unused for (int i = 0; i < 11; ++i) { reader.ReadUInt32(); } // Read DDS_PIXELFORMAT header.ddspf.dwSize = reader.ReadUInt32(); if (header.ddspf.dwSize != 32) { throw new ContentLoadException("Invalid DDS_PIXELFORMAT dwSize value"); } header.ddspf.dwFlags = (Ddpf)reader.ReadUInt32(); header.ddspf.dwFourCC = (FourCC)reader.ReadUInt32(); header.ddspf.dwRgbBitCount = reader.ReadUInt32(); header.ddspf.dwRBitMask = reader.ReadUInt32(); header.ddspf.dwGBitMask = reader.ReadUInt32(); header.ddspf.dwBBitMask = reader.ReadUInt32(); header.ddspf.dwABitMask = reader.ReadUInt32(); // Continue reading DDS_HEADER header.dwCaps = (DdsCaps)reader.ReadUInt32(); header.dwCaps2 = (DdsCaps2)reader.ReadUInt32(); reader.ReadUInt32(); // dwCaps3 unused reader.ReadUInt32(); // dwCaps4 unused reader.ReadUInt32(); // dwReserved2 unused // Check for the existence of the DDS_HEADER_DXT10 struct next if (header.ddspf.dwFlags == Ddpf.FourCC && header.ddspf.dwFourCC == FourCC.Dx10) { throw new ContentLoadException("Unsupported DDS_HEADER_DXT10 struct found"); } int faceCount = 1; int mipMapCount = (int)(header.dwCaps.HasFlag(DdsCaps.MipMap) ? header.dwMipMapCount : 1); if (header.dwCaps2.HasFlag(DdsCaps2.Cubemap)) { if (!header.dwCaps2.HasFlag(DdsCaps2.CubemapAllFaces)) { throw new ContentLoadException("Incomplete cubemap in DDS file"); } faceCount = 6; output = new TextureCubeContent() { Identity = identity }; } else { output = new Texture2DContent() { Identity = identity }; } var format = GetSurfaceFormat(ref header.ddspf, out bool rbSwap); for (int f = 0; f < faceCount; ++f) { int w = (int)header.dwWidth; int h = (int)header.dwHeight; var mipMaps = new MipmapChain(); for (int m = 0; m < mipMapCount; ++m) { var content = CreateBitmapContent(format, w, h); var byteCount = GetBitmapSize(format, w, h); // A 24-bit format is slightly different if (header.ddspf.dwRgbBitCount == 24) { byteCount = 3 * w * h; } var bytes = reader.ReadBytes(byteCount); if (rbSwap) { switch (format) { case SurfaceFormat.Bgr565: ByteSwapBGR565(bytes); break; case SurfaceFormat.Bgra4444: ByteSwapBGRA4444(bytes); break; case SurfaceFormat.Bgra5551: ByteSwapBGRA5551(bytes); break; case SurfaceFormat.Rgba32: if (header.ddspf.dwRgbBitCount == 32) { ByteSwapRGBX(bytes); } else if (header.ddspf.dwRgbBitCount == 24) { ByteSwapRGB(bytes); } break; } } if ((format == SurfaceFormat.Rgba32) && header.ddspf.dwFlags.HasFlag(Ddpf.Rgb) && !header.ddspf.dwFlags.HasFlag(Ddpf.AlphaPixels)) { // Fill or add alpha with opaque if (header.ddspf.dwRgbBitCount == 32) { ByteFillAlpha(bytes); } else if (header.ddspf.dwRgbBitCount == 24) { ByteExpandAlpha(ref bytes); } } content.SetPixelData(bytes); mipMaps.Add(content); w = Math.Max(1, w / 2); h = Math.Max(1, h / 2); } output.Faces[f] = mipMaps; } } return(output); }
/// <summary> /// Called by the framework when importing a game asset. This is the method called by XNA when an asset is to be imported into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>Resulting game asset.</returns> public abstract T Import(string filename, ContentImporterContext context);
/// <summary> /// Called by the XNA Framework when importing a .x file to be used as a game asset. This is the method called by the XNA Framework when an asset is to be imported into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>Resulting game asset.</returns> public override NodeContent Import(string filename, ContentImporterContext context) { var importer = new OpenAssetImporter("XImporter", true); return(importer.Import(filename, context)); }
/// <summary> /// Called by the XNA Framework when importing an intermediate file to be used as a game /// asset. This is the method called by the XNA Framework when an asset is to be imported /// into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>The imported game asset.</returns> public override object Import(string filename, ContentImporterContext context) { using (var reader = XmlReader.Create(filename)) return(IntermediateSerializer.Deserialize <object>(reader, filename)); }
/// <summary> /// Called by the XNA Framework when importing a .wmv file to be used as a game asset. This is the method called by the XNA Framework when an asset is to be imported into an object that can be recognized by the Content Pipeline. /// </summary> /// <param name="filename">Name of a game asset file.</param> /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param> /// <returns>Resulting game asset.</returns> public override VideoContent Import(string filename, ContentImporterContext context) { var content = new VideoContent(filename); return(content); }