Google

How to get a Stream object from a Mogre resource [SOLVED]

Discussion regarding the Managed .Net Wrapper for Ogre, MOGRE (http://sourceforge.net/projects/mogre)

Moderators: OGRE Team, MOGRE Moderators

How to get a Stream object from a Mogre resource [SOLVED]

Postby Aralox » Sun Jan 29, 2012 10:05 am

Hey there, i'm trying to figure out how to get a Stream (http://msdn.microsoft.com/en-us/library/system.io.stream.aspx) object from a resource loaded in Mogre,
such as a text file, and would appreciate any help.

Thanks! :)
Aralox

Edit: After some searching, i found http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=10413 where he had the same (unsolved) problem,
And http://www.ogre3d.org/addonforums/viewtopic.php?f=8&p=21661#p21661, which had the solution :P

In a nutshell, here it is:
Code: Select all
    //DataStreamPtr dataPtr = ResourceGroupManager.Singleton.OpenResource("my resource");

    public MemoryStream DataPtrToStream(DataStreamPtr dataPtr)
    {
        if (dataPtr.Size() != 0)
        {
            byte[] buffer = new byte[dataPtr.Size()];

            unsafe
            {
                //Get the pointer to the first element of our buffer of bytes (in C++, can just use 'buffer')
                fixed (byte* bufferPtr = &buffer[0])
                {
                    //Read buffer.Length amount of data into bufferPtr
                    dataPtr.Read(bufferPtr, (uint)buffer.Length);
                }
            }

            MemoryStream stream = new MemoryStream(buffer);
           
            return stream;

        }
        return null;
    }


Thanks to bekas and Madmark for coming up with the above method, I just sort of put it together.
User avatar
Aralox
Halfling
 
Posts: 54
Kudos: 12
Joined: 08 Jan 2012
Location: Melbourne, Australia

Re: How to get a Stream object from a Mogre resource [SOLVED

Postby zarfius » Tue Jan 31, 2012 6:02 am

I wonder if Mogre could be adapted to do this automatically for you. Just a thought.
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
zarfius
Goblin
 
Posts: 234
Kudos: 24
Joined: 09 Jul 2008
Location: Brisbane, Australia

Re: How to get a Stream object from a Mogre resource [SOLVED

Postby Aralox » Tue Jan 31, 2012 6:18 am

Seems easy enough to do, t'would be a good suggestion for the next release
User avatar
Aralox
Halfling
 
Posts: 54
Kudos: 12
Joined: 08 Jan 2012
Location: Melbourne, Australia


Return to MOGRE

Who is online

Users browsing this forum: No registered users and 1 guest