public static bool loadModelFromDisk(string filename) { if (!File.Exists(filename)) { return(false); } ModelContainer model = new ModelContainer(); model.mGR2Name = filename; model.mVisualModel = GrannyBridge.LoadGR2FromFile(filename); mModels.Add(model); return(true); }
public static bool loadModelFromArchive(string filename, AbstractFolder folder) { AbstractFile file = folder.GetFile(filename); if (!file.Exists) { return(false); } ModelContainer model = new ModelContainer(); model.mGR2Name = filename; { //Since granny is unmanaged, we have to allocate a contiguous block of memory for this Stream stream = file.OpenRead(); BinaryReader br = new BinaryReader(stream); byte[] fullFule = br.ReadBytes((int)file.Size); br.Close(); stream.Close(); IntPtr pMarshaledIndexMem = System.Runtime.InteropServices.Marshal.AllocHGlobal(fullFule.Length); System.Runtime.InteropServices.Marshal.Copy(fullFule, 0, pMarshaledIndexMem, fullFule.Length); model.mVisualModel = GrannyBridge.LoadGR2FromIntPtr(pMarshaledIndexMem, fullFule.Length); System.Runtime.InteropServices.Marshal.FreeHGlobal(pMarshaledIndexMem); } mModels.Add(model); return(true); }