public static M2 ReadM2(MpqLibrarian librarian, MapDoodadDefinition doodadDefinition) { var model = M2Reader.ReadM2(librarian, doodadDefinition.FilePath, false); var tempIndices = new List <int>(); foreach (var tri in model.BoundingTriangles) { tempIndices.Add(tri.Index0); tempIndices.Add(tri.Index1); tempIndices.Add(tri.Index2); } var currentM2 = TransformM2(model, tempIndices, doodadDefinition); currentM2.Bounds = new BoundingBox(currentM2.Vertices.ToArray()); return(currentM2); }
/// <summary> /// Adds a WMO to the manager /// </summary> public static WMORoot ReadWMO(MpqLibrarian librarian, MapObjectDefinition currentMODF) { // Parse the WMORoot var wmoRoot = WMOReader.ReadWMO(librarian, currentMODF.FilePath); // Parse the WMOGroups for (var wmoGroup = 0; wmoGroup < wmoRoot.Header.GroupCount; wmoGroup++) { var newFile = wmoRoot.FilePath.Substring(0, wmoRoot.FilePath.LastIndexOf('.')); var currentFilePath = String.Format("{0}_{1:000}.wmo", newFile, wmoGroup); var group = WMOGroupReader.Process(librarian, currentFilePath, wmoRoot, wmoGroup); wmoRoot.Groups[wmoGroup] = group; } //wmoRoot.DumpLiqChunks(); // Parse in the WMO's M2s var curDoodadSet = currentMODF.DoodadSetId; var setIndices = new List <int> { 0 }; if (curDoodadSet > 0) { setIndices.Add(curDoodadSet); } var setDefs = new List <DoodadSet>(setIndices.Count); foreach (var index in setIndices) { if (index >= wmoRoot.DoodadSets.Length) { log.Error("Invalid index {0} into wmoRoot.DoodadSet array with id", index, curDoodadSet); continue; } setDefs.Add(wmoRoot.DoodadSets[index]); } var m2List = new List <M2>(); foreach (var def in setDefs) { var doodadSetOffset = def.FirstInstanceIndex; var doodadSetCount = def.InstanceCount; for (var i = doodadSetOffset; i < (doodadSetOffset + doodadSetCount); i++) { var curDoodadDef = wmoRoot.DoodadDefinitions[i]; if (string.IsNullOrEmpty(curDoodadDef.FilePath)) { log.Error("Encountered Doodad with empty file path"); continue; } var curM2 = M2Reader.ReadM2(librarian, curDoodadDef.FilePath, true); var tempIndices = new List <int>(); for (var j = 0; j < curM2.BoundingTriangles.Length; j++) { var tri = curM2.BoundingTriangles[j]; tempIndices.Add(tri.Index2); tempIndices.Add(tri.Index1); tempIndices.Add(tri.Index0); } var rotatedM2 = TransformWMOM2(curM2, tempIndices, curDoodadDef); m2List.Add(rotatedM2); } } wmoRoot.WMOM2s = m2List.ToArray(); TransformWMO(currentMODF, wmoRoot); var bounds = new BoundingBox(wmoRoot.WmoVertices); wmoRoot.Bounds = bounds; return(wmoRoot); }