public SphFile(IntermediateNode root, ILibFile library) { if (root == null) { throw new ArgumentNullException("root"); } if (library == null) { throw new ArgumentNullException("materialLibrary"); } materialsAccessor = new SphMaterials(this); ready = false; this.library = library; sideMaterialNames = new List <string>(); bool sphereSet = false; foreach (Node node in root) { switch (node.Name.ToLowerInvariant()) { case "sphere": if (sphereSet) { throw new Exception("Multiple sphere nodes"); } sphereSet = true; var sphereNode = (IntermediateNode)node; foreach (LeafNode sphereSubNode in sphereNode) { string name = sphereSubNode.Name.ToLowerInvariant(); if (name.StartsWith("m", StringComparison.OrdinalIgnoreCase)) { sideMaterialNames.Add(sphereSubNode.StringData); } else if (name == "radius") { Radius = sphereSubNode.SingleArrayData[0]; } else if (name == "sides") { int count = sphereSubNode.Int32ArrayData[0]; if (count != sideMaterialNames.Count) { throw new Exception("Invalid number of sides in " + node.Name + ": " + count); } } else { throw new Exception("Invalid node in " + node.Name + ": " + sphereSubNode.Name); } } break; case "vmeshlibrary": IntermediateNode vMeshLibraryNode = node as IntermediateNode; if (VMeshLibrary == null) { VMeshLibrary = new VmsFile(vMeshLibraryNode, library); } else { throw new Exception("Multiple vmeshlibrary nodes in 3db root"); } break; case "material library": IntermediateNode materialLibraryNode = node as IntermediateNode; if (MaterialLibrary == null) { MaterialLibrary = new MatFile(materialLibraryNode, library); } else { throw new Exception("Multiple material library nodes in 3db root"); } break; case "texture library": IntermediateNode textureLibraryNode = node as IntermediateNode; if (TextureLibrary == null) { TextureLibrary = new TxmFile(textureLibraryNode); } else { throw new Exception("Multiple texture library nodes in 3db root"); } break; } } }