Today I played around with Autodesk Mudbox/Maya and wanted to display a model that was exported to COLLADA from Maya with XNA using my ColladaImporter library. However, the material processor threw an (to me) unexpected exception: TIFF is not a supported image format.
I wonder why there is not TIFF content importer in XNA by default. After all the .NET framework itself can handle TIFF images. Hence, writing my own TIFF Image Content Importer for XNA wasn’t too hard:
[ContentImporter(".tif", ".tiff", DisplayName="TIFF Importer", DefaultProcessor="TextureProcessor")] public class TiffImporter : ContentImporter<Texture2DContent> { public override Texture2DContent Import(string filename, ContentImporterContext context) { Bitmap bitmap = Image.FromFile(filename) as Bitmap; var bitmapContent = new PixelBitmapContent<Microsoft.Xna.Framework.Color>(bitmap.Width, bitmap.Height); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { System.Drawing.Color from = bitmap.GetPixel(i, j); Microsoft.Xna.Framework.Color to = new Microsoft.Xna.Framework.Color(from.R, from.G, from.B, from.A); bitmapContent.SetPixel(i, j, to); } } return new Texture2DContent() { Mipmaps = new MipmapChain(bitmapContent) }; } }
Apart from that the COLLADA file exported by Maya looked slightly different than COLLADA files exported by 3ds max for some reason. While 3ds max exports triangles in form of <triangles>-tags, maya uses the <polygons>-tag for geometry, having only 3 vertices per polygon (i.e. triangles). I updated the geometry importer to account for this, since before today only <triangle>-tags were supported, as exported by 3ds max and OpenCOLLADA.
Hi! If u don’t care, I’m going to to use your TIFF Importer, but I’m having some problems to build it.
The compiler can’t find Bitmap or Image classes also Drawing namespace.
Hope u can help me soon.
By the way, good job!
Hello Fabricio!
You have to add the assembly “System.Drawing” to your project. Just right click on your project and choose “Add References”. In the new dialog you can search for “System.Drawing” and should be able to simply add it.
Hope that helps!
I’m glad someone else found it useful. You are of course free to use it! 🙂
Mathias,
Adding the “System.Drawing” solved that issues. After that I had a ‘.net framework target profile’ problem, related to the content.pipeline reference, but now is ok.
Thanks for your help!
I will grant u the credits for that! 😉
Simple and straight-forward, thank you. Has helped a lot.
Nice and simple. Well done.
Don’t forget to add the “using System.Drawing;” after you’ve referenced the library. It’s implied from above, but you might forget.