Ejemplo n.º 1
0
        public static bool SaveToStream(BinaryWriter outputWriter, Model model)
        {
            ModelStorage storage = new ModelStorage(string.Empty, model);

            if (!storage.Write(outputWriter))
            {
                Debug.Assert(false, "Cannot write a model file!");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static Model LoadFromStream(BinaryReader inputReader, string name)
        {
            ModelStorage storage = new ModelStorage();

            if (!storage.Parse(inputReader))
            {
                Debug.Assert(false, "Cannot parse a model file!");
                return(null);
            }

            return(new Model(name, storage.Blocks.ToArray()));
        }
Ejemplo n.º 3
0
        public static Model LoadFromFile(string fileName)
        {
            ModelStorage storage = new ModelStorage(fileName);

            using (FileStream stream = new FileStream(storage.LibraryPath, FileMode.Open))
            {
                using (BinaryReader inputReader = new BinaryReader(stream, storage.Encoding))
                {
                    if (!storage.Parse(inputReader))
                    {
                        Debug.Assert(false, "Cannot parse a model file!");
                        return(null);
                    }
                }
            }

            string name = Path.GetFileNameWithoutExtension(storage.LibraryPath);

            return(new Model(name, storage.Blocks.ToArray()));
        }
Ejemplo n.º 4
0
        public static bool SaveToFile(string filePath, Model model)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }

            ModelStorage storage = new ModelStorage(filePath, model);

            using (FileStream stream = new FileStream(storage.LibraryPath, FileMode.Create))
            {
                using (BinaryWriter outputWriter = new BinaryWriter(stream, storage.Encoding))
                {
                    if (!storage.Write(outputWriter))
                    {
                        Debug.Assert(false, "Cannot write a model file!");
                        return(false);
                    }
                }
            }

            return(true);
        }