Inheritance: System.IO.BinaryWriter
Exemple #1
0
        public void Save(string filename, IKn5TextureProvider textureProvider = null)
        {
            using (var writer = new Kn5Writer(File.Open(filename, FileMode.Create, FileAccess.ReadWrite))) {
                writer.Write(Header);

                writer.Write(Textures.Count);
                foreach (var texture in Textures.Values)
                {
                    if (TexturesData.TryGetValue(texture.Name, out var data) && data.Length > 0)
                    {
                        texture.Length = data.Length;
                        writer.Write(texture);
                        writer.Write(data);
                    }
                    else
                    {
                        textureProvider?.GetTexture(texture.Name, size => {
                            texture.Length = size;
                            writer.Write(texture);
                            writer.Flush();
                            return(writer.BaseStream);
                        });
                    }
                }

                writer.Write(Materials.Count);
                foreach (var material in Materials.Values)
                {
                    writer.Write(material);
                }

                Save_Node(writer, RootNode);
            }
        }
Exemple #2
0
        public void Save(string filename, bool saveNodes = false)
        {
            using (var writer = new Kn5Writer(filename)) {
                writer.Write(Header);

                writer.Write(Textures.Count);
                foreach (var texture in Textures.Values)
                {
                    var data = TexturesData[texture.Name];
                    texture.Length = data.Length;
                    writer.Write(texture);
                    writer.Write(data);
                }

                writer.Write(Materials.Count);
                foreach (var material in Materials.Values)
                {
                    writer.Write(material);
                }

                if (saveNodes)
                {
                    Save_Node(writer, RootNode);
                }
                else
                {
                    if (NodesBytes == null)
                    {
                        throw new Exception("NodesBytes = null");
                    }

                    writer.Write(NodesBytes);
                }
            }
        }
Exemple #3
0
 private static void Save_Node(Kn5Writer writer, Kn5Node node)
 {
     writer.Write(node);
     foreach (var t in node.Children)
     {
         Save_Node(writer, t);
     }
 }