public CmpFile(IntermediateNode rootnode, ILibFile additionalLibrary) { this.additionalLibrary = additionalLibrary; Models = new Dictionary <string, ModelFile>(); Cameras = new Dictionary <string, CmpCameraInfo>(); Constructs = new ConstructCollection(); Parts = new List <Part>(); List <string> modelNames = new List <string>(); foreach (Node node in rootnode) { switch (node.Name.ToLowerInvariant()) { case "exporter version": break; case "vmeshlibrary": IntermediateNode vMeshLibraryNode = node as IntermediateNode; if (VMeshLibrary == null) { VMeshLibrary = new VmsFile(vMeshLibraryNode, this); } else { throw new Exception("Multiple vmeshlibrary nodes in cmp root"); } break; case "animation": IntermediateNode animationNode = node as IntermediateNode; if (Animation == null) { Animation = new AnmFile(animationNode, Constructs); } else { throw new Exception("Multiple animation nodes in cmp root"); } break; case "material library": IntermediateNode materialLibraryNode = node as IntermediateNode; if (MaterialLibrary == null) { MaterialLibrary = new MatFile(materialLibraryNode, this); } else { throw new Exception("Multiple material library nodes in cmp 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 cmp root"); } break; case "cmpnd": IntermediateNode cmpndNode = node as IntermediateNode; foreach (Node SubNode in cmpndNode) { if (SubNode is LeafNode) { continue; } var cmpndSubNode = (IntermediateNode)SubNode; if (cmpndSubNode.Name.Equals("cons", StringComparison.OrdinalIgnoreCase)) { Constructs.AddNode(cmpndSubNode); } else if ( cmpndSubNode.Name.StartsWith("part_", StringComparison.OrdinalIgnoreCase) || cmpndSubNode.Name.Equals("root", StringComparison.OrdinalIgnoreCase) ) { string objectName = string.Empty, fileName = string.Empty; foreach (LeafNode partNode in cmpndSubNode) { switch (partNode.Name.ToLowerInvariant()) { case "object name": objectName = partNode.StringData; break; case "file name": fileName = partNode.StringData; break; case "index": break; default: FLLog.Error("Cmp", "Invalid node in " + cmpndSubNode.Name + ": " + partNode.Name); break; } } Parts.Add(new Part(objectName, fileName, Models, Cameras, Constructs)); } else { throw new Exception("Invalid node in " + cmpndNode.Name + ": " + cmpndSubNode.Name); } } break; case "materialanim": MaterialAnim = new MaterialAnimCollection((IntermediateNode)node); break; default: if (node is IntermediateNode) { var im = (IntermediateNode)node; if (im.Any(x => x.Name.Equals("vmeshpart", StringComparison.OrdinalIgnoreCase) || x.Name.Equals("multilevel", StringComparison.OrdinalIgnoreCase))) { ModelFile m = new ModelFile(im, this); m.Path = node.Name; Models.Add(node.Name, m); modelNames.Add(node.Name); break; } else if (im.Any(x => x.Name.Equals("camera", StringComparison.OrdinalIgnoreCase))) { var cam = new CmpCameraInfo(im); Cameras.Add(im.Name, cam); break; } } FLLog.Error("Cmp", Path ?? "Utf" + ": Invalid Node in cmp root: " + node.Name); break; } } //FL handles cmpnd nodes that point to non-existant models: fix up here List <Part> broken = new List <Part>(); for (int i = 0; i < Parts.Count; i++) { if (Parts[i].IsBroken()) { broken.Add(Parts[i]); } } foreach (var b in broken) { Parts.Remove(b); } }
public CmpFile(IntermediateNode rootnode, ILibFile additionalLibrary) { this.additionalLibrary = additionalLibrary; Models = new Dictionary <string, ModelFile>(); Constructs = new ConstructCollection(); Parts = new Dictionary <int, Part>(); foreach (Node node in rootnode) { switch (node.Name.ToLowerInvariant()) { case "exporter version": break; case "vmeshlibrary": IntermediateNode vMeshLibraryNode = node as IntermediateNode; if (VMeshLibrary == null) { VMeshLibrary = new VmsFile(vMeshLibraryNode, this); } else { throw new Exception("Multiple vmeshlibrary nodes in cmp root"); } break; case "animation": IntermediateNode animationNode = node as IntermediateNode; if (Animation == null) { Animation = new AnmFile(animationNode, Constructs); } else { throw new Exception("Multiple animation nodes in cmp root"); } break; case "material library": IntermediateNode materialLibraryNode = node as IntermediateNode; if (MaterialLibrary == null) { MaterialLibrary = new MatFile(materialLibraryNode, this); } else { throw new Exception("Multiple material library nodes in cmp 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 cmp root"); } break; case "cmpnd": IntermediateNode cmpndNode = node as IntermediateNode; int maxIndices = int.MaxValue; foreach (Node SubNode in cmpndNode) { if (SubNode is LeafNode) { continue; } var cmpndSubNode = (IntermediateNode)SubNode; if (cmpndSubNode.Name.Equals("cons", StringComparison.OrdinalIgnoreCase)) { Constructs.AddNode(cmpndSubNode); } else if ( cmpndSubNode.Name.StartsWith("part_", StringComparison.OrdinalIgnoreCase) || cmpndSubNode.Name.Equals("root", StringComparison.OrdinalIgnoreCase) ) { string objectName = string.Empty, fileName = string.Empty; int index = -1; foreach (LeafNode partNode in cmpndSubNode) { switch (partNode.Name.ToLowerInvariant()) { case "object name": objectName = partNode.StringData; break; case "file name": fileName = partNode.StringData; break; case "index": if (partNode.Int32Data != null) { index = partNode.Int32Data.Value; } else { index = partNode.Int32ArrayData [0]; } break; default: throw new Exception("Invalid node in " + cmpndSubNode.Name + ": " + partNode.Name); } } if (Parts.ContainsKey(index)) { FLLog.Error("Cmp", "Duplicate index"); Parts.Add(maxIndices--, new Part(objectName, fileName, Models, Constructs)); } else { Parts.Add(index, new Part(objectName, fileName, Models, Constructs)); } } else { throw new Exception("Invalid node in " + cmpndNode.Name + ": " + cmpndSubNode.Name); } } break; case "materialanim": MaterialAnim = new MaterialAnimCollection((IntermediateNode)node); break; default: if (node.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase)) { ModelFile m = new ModelFile(node as IntermediateNode, this); m.Path = node.Name; Models.Add(node.Name, m); } else { FLLog.Error("Cmp", Path ?? "Utf" + ": Invalid Node in cmp root: " + node.Name); } break; } } }