XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Loading non compiled Content.

Last post 6/8/2008 3:21 PM by Shawn Hargreaves. 4 replies.
  • 6/7/2008 4:41 PM

    Loading non compiled Content.

    Hi all.

     

    Okay, so im trying to extend my Pak system loader class as show below

        public class PContentManager : ContentManager  
        {  
            public string packname;  
            public string packdir;  
     
            Pak pak = new Pak();  
            public PContentManager(IServiceProvider serviceProvider)  
                : base(serviceProvider)  
            {  
            }  
     
            protected override Stream OpenStream(string assetName)  
            {  
                try 
                {  
                    pak.OpenPack("Data/" + packname);  
                    byte[ data = pak.GetFileData(assetName, packdir);  
                    pak.Dispose();  
     
                    MemoryStream stream = new MemoryStream(data);  
                    return stream;  
                }  
                catch (Exception error)  
                {  
                    throw new Exception(error.Message);  
                }  
            }  
        } 

     

    So that i can load jpg,png,xml,ect ect ect files directly without having to convert to xnb files first.

    This code above can load the xnb files from a pak file, but not non compiled files, and thats what i would like to do without having to make them xnb as temp store on disk ect first.

     

    Something like  :

    private PContentManager content;  
    Texture2D tex = content.Load<Texture2D>("demo.jpg"); 

     

    So do i change my PContentManager class and check wich file type im loading, then compile, then return data, or do i have to write a custom override importer for it, or, do i have to write a whole new Texture2D class for it (and same for fonts,models (using XSI mod tool for models)) ect ?

     

    What im going for is : Load Content from Pak (image.jpg for excample) -> Compile on fly in memory -> Return Texture2D (if Texture2D file)

     

    Im like totally lost on where to begin in this.

    I was beginning like this (am i on the right track here ?)

        [ContentImporter(new string[ { ".bmp"".dds"".dib"".hdr"".jpg"".pfm"".png"".ppm"".tga" }, DisplayName = "Texture - XNA Framework", DefaultProcessor = "SpriteTextureProcessor")]  
        public class Texture2D : ContentImporter<Texture2D>  
        {  
            public override Texture2D Import(string filename, ContentImporterContext context)  
            {             
                try 
                {  
                    // All Textures are in Data/Textures  
                    Texture2D textureContent = new Texture2D();  
     
                      
     
                     
                    // return content  
                    return textureContent;  
                }  
                catch (Exception error)  
                {  
                    throw (error);                 
                }  
            }         
        } 

     

    My guess is, i have to "compile the xnb" just AFTER i loaded the stream in PContentManager, and before i return it, and not in a class like i made above.

    Knowledge is power, power corrupts. Study hard, be evil.!
  • 6/8/2008 12:01 AM In reply to

    Re: Loading non compiled Content.

    Looking into this the idea of the content Texture2D override isnt what im looking for.

    My guess is, im gonna have to do something with the ContentWriter or ContentCompiler class ?

     

           protected override Stream OpenStream(string assetName)  
            {  
                try 
                {  
                    pak.OpenPack("Data/" + packname);  
                    byte[ data = pak.GetFileData(assetName, packdir);  
                    pak.Dispose();  
     
                    MemoryStream stream = new MemoryStream(data);  
     
                    // find out wich type loaded  
                    FileInfo info = new FileInfo(assetName);  
                    string type = info.Extension.Substring(1, info.Extension.Length - 1).ToLower();                  
     
                    // Check for type Texture / Image  
                    if (type.Equals("jpg") || type.Equals("bmp") || type.Equals("tga") || type.Equals("dds") || type.Equals("hdr"))  
                    {  
                          
                          
                    }  
                    // Check for type Text/XML file  
                    else if (type.Equals("xml"))  
                    {  
     
                    }  
                    // unknown file type  
                    else 
                    {  
                        throw new Exception("Unknown file type.");  
                    }  
     
                    // finally return data  
                    return stream;  
                }  
                catch (Exception error)  
                {  
                    throw new Exception(error.Message);  
                }  
            }              

     

    So after i load the stream data, then

    if(type.Equals("jpg")....

    {

        add something to compile the data here as Texture2D

        and ofc GenerateMipmaps() ect, what else is needed

        then add as new stream source

    }

    return the stream;

    is this closer to correct ?

    these content loader classes is a pain in the butt to override to change the way it loads data :P

    Knowledge is power, power corrupts. Study hard, be evil.!
  • 6/8/2008 4:18 AM In reply to

    Re: Loading non compiled Content.

    I don't understand why you are using the Content Pipeline at all here.

    The Content Pipeline is a system for precompiling game content into .xnb file format. It has many extensibility points for things like adding new data types, adding new data processing behaviors, and even changing where the .xnb files are read from via the OpenStream overload, but the system fundamentally assumes that you are compiling your content data into .xnb format ahead of time.

    If you aren't doing that, the Content Pipeline is irrelevant to your goal. You should just write your own code to load whatever files you like from disk and create whatever objects you like as a result of this loading. There's no need (and in fact no way) to hook this into classes such as the ContentManager.

    XNA Framework Developer - blog - homepage
  • 6/8/2008 10:05 AM In reply to

    Re: Loading non compiled Content.

    Dammit hehe

    Was kinda hoping to do this with as little code as possible and still be able to use the contentmanager.

    O well :)

    Knowledge is power, power corrupts. Study hard, be evil.!
  • 6/8/2008 3:21 PM In reply to

    Re: Loading non compiled Content.

    I'm afraid there is no way you can do this with a little amount of code. If you want to read unprocessed image formats such as JPG, you need code that will parse and decompress the JPG data. There is no such code built into the XNA Framework (other than as part of the content pipeline build process) so you will have to find or write that yourself. It's certainly possible, but it's going to be a lot of code, and not something that our content pipeline implementation will help you with at all.
    XNA Framework Developer - blog - homepage
Page 1 of 1 (5 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG