public override void LoadResource(Resource resource) { string pathAbs = path_cache + resource.Name; FileStream fs = new FileStream(pathAbs, FileMode.Open); DataStreamPtr stream = new DataStreamPtr(new ManagedDataStream(fs)); new SkeletonSerializer().ImportSkeleton(stream, (Skeleton)resource); stream.Close(); fs.Close(); }
public override void LoadResource(Resource resource) { string pathAbs = ThingPath.path_cache + resource.Name; FileStream fs = new FileStream(pathAbs, FileMode.Open); DataStreamPtr stream = new DataStreamPtr(new ManagedDataStream(fs)); //Mesh m = new Mesh(resource.Creator, resource.Name, 1234L, ""); new MeshSerializer().ImportMesh(stream, (Mesh)resource); stream.Close(); fs.Close(); // resource = m; }
public int Add(string pathRelFile) { string pathAbsImg = path_cache + pathRelFile; Mogre.Image image = new Mogre.Image(); FileStream fs = new FileStream(pathAbsImg, FileMode.Open); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(fs)); image.Load(fs2); TexturePtr texturePtr = TextureManager.Singleton.LoadImage(pathRelFile, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, image); fs2.Close(); fs.Close(); lock (allTextures) { return allTextures.Add(texturePtr); } }
//public unsafe void Replace3(Mogre.Image image, string textureName) //{ // if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); // TexturePtr pTexture = this[textureName]; // HardwarePixelBufferSharedPtr texBuffer = pTexture.GetBuffer(); // texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD); // PixelBox pb = texBuffer.CurrentLock; // PixelBox imagBox = image.GetPixelBox(); // imagBox.data // Marshal.Copy(bytes, 0, pb.data, bytes.Length); // texBuffer.Unlock(); // texBuffer.Dispose(); //} public byte[] ConvertImageToRgbValues(byte[] inBytes) { Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(inBytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); uint bytes = imagBox.GetConsecutiveSize(); byte[] rgbValues = new byte[bytes]; Marshal.Copy(imagBox.data, rgbValues, 0, (int)bytes); image.Dispose(); fs2.Close(); ms.Close(); return(rgbValues); }
public int Add(string pathRelFile) { string pathAbsImg = path_cache + pathRelFile; Mogre.Image image = new Mogre.Image(); FileStream fs = new FileStream(pathAbsImg, FileMode.Open); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(fs)); image.Load(fs2); TexturePtr texturePtr = TextureManager.Singleton.LoadImage(pathRelFile, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, image); fs2.Close(); fs.Close(); lock (allTextures) { return(allTextures.Add(texturePtr)); } }
public void ParseDotScene(String SceneName, String groupName, SceneManager yourSceneMgr, SceneNode pAttachNode, String sPrependNode) { // set up shared object values m_sGroupName = groupName; mSceneMgr = yourSceneMgr; m_sPrependNode = sPrependNode; this.StaticObjects = new List <string>(); this.DynamicObjects = new List <string>(); XmlDocument XMLDoc = null; XmlElement XMLRoot; DataStreamPtr pStream = ResourceGroupManager.Singleton.OpenResource(SceneName, groupName); String data = pStream.AsString; // Open the .scene File XMLDoc = new XmlDocument(); XMLDoc.LoadXml(data); pStream.Close(); // Validate the File XMLRoot = XMLDoc.DocumentElement; if (XMLRoot.Name != "scene") { LogManager.Singleton.LogMessage("[DotSceneLoader] Error: Invalid .scene File. Missing <scene>"); return; } // figure out where to attach any nodes we create mAttachNode = pAttachNode; if (mAttachNode == null) { mAttachNode = mSceneMgr.RootSceneNode; } // Process the scene processScene(XMLRoot); }
/************************************************************************/ /* read a resource completely as a byte array */ /************************************************************************/ public byte[] ReadResource(string _groupName, string _fileName) { // if the file does not exist there is no way to load it if (!CheckResourceExists(_groupName, _fileName)) { return(null); } // open resource for reading DataStreamPtr streamPtr = ResourceGroupManager.Singleton.OpenResource(_fileName, _groupName); uint length = streamPtr.Size(); uint readLength = 0; // create buffer to load resource into byte[] buffer = new byte[(int)length]; if (length != 0) { unsafe { fixed(byte *bufferPtr = &buffer[0]) { // read resource into buffer readLength = streamPtr.Read(bufferPtr, length); } } } // if reading the resource failed, just get rid of the buffer if (readLength != length) { buffer = null; } // close the resource stream streamPtr.Close(); // return buffer of loaded resource or null if failed return(buffer); }
public void Replace(byte[] bytes, string textureName) { if (this.IndexOf(textureName) < 0) { throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); } Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(bytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); TexturePtr pTexture = this[textureName]; TextureManager lTextureManager = TextureManager.Singleton; HardwarePixelBuffer buffer = pTexture.GetBuffer(); unsafe { buffer.BlitFromMemory(imagBox); } image.Dispose(); fs2.Close(); ms.Close(); }
public void Replace(byte[] bytes, string textureName) { if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(bytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); TexturePtr pTexture = this[textureName]; TextureManager lTextureManager = TextureManager.Singleton; HardwarePixelBuffer buffer = pTexture.GetBuffer(); unsafe { buffer.BlitFromMemory(imagBox); } image.Dispose(); fs2.Close(); ms.Close(); }
//public unsafe void Replace3(Mogre.Image image, string textureName) //{ // if (this.IndexOf(textureName) < 0) throw new ArgumentException("The texture \"" + textureName + "\"doesn't exist"); // TexturePtr pTexture = this[textureName]; // HardwarePixelBufferSharedPtr texBuffer = pTexture.GetBuffer(); // texBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD); // PixelBox pb = texBuffer.CurrentLock; // PixelBox imagBox = image.GetPixelBox(); // imagBox.data // Marshal.Copy(bytes, 0, pb.data, bytes.Length); // texBuffer.Unlock(); // texBuffer.Dispose(); //} public byte[] ConvertImageToRgbValues(byte[] inBytes) { Mogre.Image image = new Mogre.Image(); MemoryStream ms = new MemoryStream(inBytes); DataStreamPtr fs2 = new DataStreamPtr(new ManagedDataStream(ms)); image.Load(fs2); PixelBox imagBox = image.GetPixelBox(); uint bytes = imagBox.GetConsecutiveSize(); byte[] rgbValues = new byte[bytes]; Marshal.Copy(imagBox.data, rgbValues, 0, (int)bytes); image.Dispose(); fs2.Close(); ms.Close(); return rgbValues; }