public static Kn5 FromFile(string filename, IKn5TextureLoader textureLoader = null, IKn5MaterialLoader materialLoader = null, IKn5NodeLoader nodeLoader = null) { if (!File.Exists(filename)) { throw new FileNotFoundException(filename); } var kn5 = new Kn5(filename); (textureLoader = textureLoader ?? DefaultKn5TextureLoader.Instance).OnNewKn5(filename); (materialLoader = materialLoader ?? DefaultKn5MaterialLoader.Instance).OnNewKn5(filename); (nodeLoader = nodeLoader ?? DefaultKn5NodeLoader.Instance).OnNewKn5(filename); using (var reader = new Kn5Reader(filename)) { kn5.FromFile_Header(reader); kn5.FromFile_Textures(reader, textureLoader); if (nodeLoader != SkippingNodeLoader.Instance || materialLoader != SkippingMaterialLoader.Instance) { kn5.FromFile_Materials(reader, materialLoader); kn5.FromFile_Nodes(reader, nodeLoader); } } return(kn5); }
public static Kn5 FromFile(string filename, bool skipTextures, bool readNodesAsBytes = true) { if (!File.Exists(filename)) { throw new FileNotFoundException(filename); } var kn5 = new Kn5(filename); using (var reader = new Kn5Reader(filename)) { kn5.FromFile_Header(reader); if (skipTextures) { kn5.FromFile_Textures(reader, BlankKn5TextureLoader.Instance); } else { kn5.FromFile_Textures(reader, DefaultKn5TextureLoader.Instance); } kn5.FromFile_Materials(reader); kn5.FromFile_Nodes(reader, readNodesAsBytes); } return(kn5); }
public static Kn5 FromStream(Stream entry, IKn5TextureLoader textureLoader = null) { var kn5 = new Kn5(string.Empty); using (var reader = new Kn5Reader(entry)) { kn5.FromFile_Header(reader); kn5.FromFile_Textures(reader, textureLoader ?? DefaultKn5TextureLoader.Instance); kn5.FromFile_Materials(reader); kn5.FromFile_Nodes(reader, false); } return(kn5); }
private void FromFile_Nodes(Kn5Reader reader, bool readAsBytes) { if (readAsBytes) { var nodesStart = reader.BaseStream.Position; var nodesLength = reader.BaseStream.Length - nodesStart; NodesBytes = reader.ReadBytes((int)nodesLength); reader.BaseStream.Seek(nodesStart, SeekOrigin.Begin); } try { RootNode = FromFile_Node(reader); } catch (NotImplementedException) { RootNode = null; } }
private void FromFile_Materials(Kn5Reader reader) { try { var count = reader.ReadInt32(); Materials = new Dictionary <string, Kn5Material>(count); for (var i = 0; i < count; i++) { var material = reader.ReadMaterial(); Materials[material.Name] = material; } } catch (NotImplementedException) { Materials = null; } }
private static Kn5Node SkipNode(Kn5Reader reader) { var node = reader.ReadNodeHierarchy(); var capacity = node.Children.Capacity; try { for (var i = 0; i < capacity; i++) { node.Children.Add(SkipNode(reader)); } } catch (EndOfStreamException) { node.Children.Capacity = node.Children.Count; } return(node); }
private Kn5Node FromFile_Node(Kn5Reader reader) { var node = reader.ReadNode(); var capacity = node.Children.Capacity; try { for (var i = 0; i < capacity; i++) { node.Children.Add(FromFile_Node(reader)); } } catch (EndOfStreamException) { node.Children.Capacity = node.Children.Count; } return(node); }
public static Kn5 FromStream(Stream entry, IKn5TextureLoader textureLoader = null, IKn5MaterialLoader materialLoader = null, IKn5NodeLoader nodeLoader = null) { var kn5 = new Kn5(string.Empty); using (var reader = new Kn5Reader(entry)) { kn5.FromFile_Header(reader); kn5.FromFile_Textures(reader, textureLoader ?? DefaultKn5TextureLoader.Instance); if (nodeLoader != SkippingNodeLoader.Instance || materialLoader != SkippingMaterialLoader.Instance) { kn5.FromFile_Materials(reader, materialLoader ?? DefaultKn5MaterialLoader.Instance); kn5.FromFile_Nodes(reader, nodeLoader ?? DefaultKn5NodeLoader.Instance); } } return(kn5); }
public static Kn5 FromFile(string filename, IKn5TextureLoader textureLoader = null) { if (!File.Exists(filename)) { throw new FileNotFoundException(filename); } var kn5 = new Kn5(filename); using (var reader = new Kn5Reader(filename)) { kn5.FromFile_Header(reader); kn5.FromFile_Textures(reader, textureLoader ?? DefaultKn5TextureLoader.Instance); kn5.FromFile_Materials(reader); kn5.FromFile_Nodes(reader, false); } return(kn5); }
public static Kn5 FromStream(Stream entry, bool skipTextures = false) { var kn5 = new Kn5(string.Empty); using (var reader = new Kn5Reader(entry)) { kn5.FromFile_Header(reader); if (skipTextures) { kn5.FromFile_SkipTextures(reader); } else { kn5.FromFile_Textures(reader); } kn5.FromFile_Materials(reader); kn5.FromFile_Nodes(reader); } return kn5; }
private void FromFile_Textures(Kn5Reader reader, [NotNull] IKn5TextureLoader textureLoader) { try { var count = reader.ReadInt32(); Textures = new Dictionary <string, Kn5Texture>(count); TexturesData = new Dictionary <string, byte[]>(count); for (var i = 0; i < count; i++) { var texture = reader.ReadTexture(); if (texture.Length > 0) { Textures[texture.Name] = texture; TexturesData[texture.Name] = textureLoader.LoadTexture(texture.Name, reader.BaseStream, texture.Length) ?? new byte[0]; } } } catch (NotImplementedException) { Textures = null; TexturesData = null; } }
public static Kn5 FromFile(string filename, bool skipTextures = false) { if (!File.Exists(filename)) { throw new FileNotFoundException(filename); } var kn5 = new Kn5(filename); using (var reader = new Kn5Reader(filename)) { kn5.FromFile_Header(reader); if (skipTextures) { kn5.FromFile_SkipTextures(reader); } else { kn5.FromFile_Textures(reader); } kn5.FromFile_Materials(reader); kn5.FromFile_Nodes(reader); } return kn5; }
private void FromFile_Header(Kn5Reader reader) { Header = reader.ReadHeader(); }
private Kn5Node FromFile_Node(Kn5Reader reader) { var node = reader.ReadNode(); var capacity = node.Children.Capacity; try { for (var i = 0; i < capacity; i++) { node.Children.Add(FromFile_Node(reader)); } } catch (EndOfStreamException) { node.Children.Capacity = node.Children.Count; } return node; }
private void FromFile_Materials(Kn5Reader reader) { try { var count = reader.ReadInt32(); Materials = new Dictionary<string, Kn5Material>(count); for (var i = 0; i < count; i++) { var material = reader.ReadMaterial(); Materials[material.Name] = material; } } catch (NotImplementedException) { Materials = null; } }
private void FromFile_Textures(Kn5Reader reader) { try { var count = reader.ReadInt32(); Textures = new Dictionary<string, Kn5Texture>(count); TexturesData = new Dictionary<string, byte[]>(count); for (var i = 0; i < count; i++) { var texture = reader.ReadTexture(); if (!Textures.ContainsKey(texture.Name)) { Textures[texture.Name] = texture; TexturesData[texture.Name] = reader.ReadBytes(texture.Length); } else { reader.BaseStream.Seek(texture.Length, SeekOrigin.Current); } } } catch (NotImplementedException) { Textures = null; TexturesData = null; } }
public void LoadTexturesFrom(string filename) { using (var reader = new Kn5Reader(filename)) { reader.ReadHeader(); FromFile_Textures(reader); } }
private void FromFile_Nodes(Kn5Reader reader, [NotNull] IKn5NodeLoader nodeLoader) { NodeLoader = nodeLoader; RootNode = nodeLoader.LoadNode(reader); }
private void FromFile_Nodes(Kn5Reader reader) { var nodesStart = reader.BaseStream.Position; var nodesLength = reader.BaseStream.Length - nodesStart; NodesBytes = reader.ReadBytes((int)nodesLength); reader.BaseStream.Seek(nodesStart, SeekOrigin.Begin); try { RootNode = FromFile_Node(reader); } catch (NotImplementedException) { RootNode = null; } }