private static void ExtractM2Model(string filePath) { if (string.IsNullOrEmpty(filePath)) { return; } if (TileExtractor.ModelsToIgnore.Contains(filePath)) { return; } if (LoadedM2Models.ContainsKey(filePath)) { return; } var m2Model = M2ModelParser.Process(WDTExtractor.MpqManager, filePath); if (m2Model == null) { return; } if (m2Model.BoundingVertices.IsNullOrEmpty()) { TileExtractor.ModelsToIgnore.Add(filePath); return; } LoadedM2Models.Add(filePath, m2Model); }
private static void PrepareChunkInfo(MpqManager manager, ADT adt) { for (var chunkX = 0; chunkX < TerrainConstants.ChunksPerTileSide; chunkX++) { for (var chunkY = 0; chunkY < TerrainConstants.ChunksPerTileSide; chunkY++) { var chunk = adt.MapChunks[chunkY, chunkX]; foreach (var dRefId in chunk.DoodadRefs) { var dRef = adt.DoodadDefinitions[dRefId]; if (dRef == null) { continue; } if (ModelsToIgnore.Contains(dRef.FilePath)) { continue; } if (LoadedM2Ids.Contains(dRef.UniqueId)) { continue; } M2Model model; if (!WorldObjectExtractor.LoadedM2Models.TryGetValue(dRef.FilePath, out model)) { model = M2ModelParser.Process(manager, dRef.FilePath); WorldObjectExtractor.LoadedM2Models.Add(dRef.FilePath, model); } // This model may have no collision information. If so there is no point saving the data. if (model.BoundingVertices.IsNullOrEmpty()) { // This model has no collision information. We'll ignore it. ModelsToIgnore.Add(dRef.FilePath); WorldObjectExtractor.LoadedM2Models.Remove(dRef.FilePath); } // At this point, we're using the model for collision stuff PrepareM2Info(dRef, model); LoadedM2Ids.Add(dRef.UniqueId); } foreach (var oRefId in chunk.ObjectRefs) { var oRef = adt.ObjectDefinitions[oRefId]; if (oRef == null) { continue; } LoadWMO(manager, oRef); } PrepareChunk(adt, chunkX, chunkY); } } }
private static M2Model ExtractM2Model(string filePath) { if (Path.GetExtension(filePath).ToLower().Equals(".mdx") || Path.GetExtension(filePath).ToLower().Equals(".mdl")) { filePath = filePath.Substring(0, filePath.LastIndexOf('.')) + ".m2"; } var m2model = M2ModelParser.Process(manager, filePath); if (m2model == null) { Console.WriteLine("Invalid M2Model returned."); return(null); } return(m2model); }
/// <summary> /// Adds a WMO to the manager /// </summary> /// <param name="currentMODF">MODF (placement information for this WMO)</param> public void AddWMO(MapObjectDefinition currentMODF) { _fileNames.Add(currentMODF.FilePath); // Parse the WMORoot var wmoRoot = WMORootParser.Process(MpqTerrainManager.MpqManager, 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 = WMOGroupParser.Process(MpqTerrainManager.MpqManager, 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); } foreach (var index in setIndices) { var doodadSetOffset = wmoRoot.DoodadSets[index].FirstInstanceIndex; var doodadSetCount = wmoRoot.DoodadSets[index].InstanceCount; wmoRoot.WMOM2s = new List <M2.M2>((int)doodadSetCount); for (var i = doodadSetOffset; i < (doodadSetOffset + doodadSetCount); i++) { var curDoodadDef = wmoRoot.DoodadDefinitions[i]; var curM2 = M2ModelParser.Process(MpqTerrainManager.MpqManager, curDoodadDef.FilePath); 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); wmoRoot.WMOM2s.Add(rotatedM2); } } TransformWMO(currentMODF, wmoRoot); var bounds = new BoundingBox(wmoRoot.WmoVertices); wmoRoot.Bounds = bounds; WMOs.Add(wmoRoot); }