public void ModelLoads() { Settings.initializeSettings(); String modelERFPath = "E:\\Program Files (x86)\\Steam\\steamapps\\common\\dragon age origins\\packages\\core\\data\\modelhierarchies.erf"; ERF models = new ERF(modelERFPath); models.readKeyData(); Assert.Greater(models.resourceCount, 0); int failures = 0; for (int i = 0; i < models.resourceCount; i++) { GFF temp = IO.findFile <GFF>(models.resourceNames[i]); Assert.NotNull(temp, "Not found: |" + models.resourceNames[i] + "|" + i); if (Path.GetExtension(models.resourceNames[i]) == ".mmh") { try { ModelHierarchy tempH = new ModelHierarchy(temp); } catch (Exception) { Console.WriteLine(models.resourceNames[i]); failures++; } } } Assert.AreEqual(0, failures); }
private void readScene(String path) { BinaryReader sceneReader = new BinaryReader(new FileStream(path + "\\job_scene.xml", FileMode.Open, FileAccess.Read, FileShare.Read)); String sceneXML = Encoding.UTF8.GetString(sceneReader.ReadBytes((int)sceneReader.BaseStream.Length)); sceneReader.Close(); XmlDocument sceneSpecification = new XmlDocument(); sceneSpecification.LoadXml(sceneXML); XmlNode scene = sceneSpecification.SelectSingleNode("RenderFarmScene"); foreach (XmlNode model in scene.ChildNodes) { String modelName = model.Attributes.GetNamedItem("Source").Value; String pathName = Path.GetDirectoryName(modelName); String filename = Path.GetFileName(modelName).ToLower(); modelName = pathName + "\\" + filename; ResourceManager.addFilePath(pathName); if (Path.GetFileName(modelName) == "prp_fertblsm_01.mmh") { continue; } GFF hierarchy = ResourceManager.findFile <GFF>(modelName); ModelHierarchy modelHierarchy = new ModelHierarchy(hierarchy); Model modelMesh = modelHierarchy.mesh.toModel(); foreach (XmlNode instance in model.ChildNodes) { String instanceName = instance.Attributes.GetNamedItem("Name").Value; Matrix4 transform = xmlToMatrix(instance.SelectSingleNode("Transform").Attributes); modelDictionary.Add(instanceName, new ModelInstance(instanceName, modelMesh, transform)); } ResourceManager.removeFilePath(pathName); } }
private void btn_load_Click(object sender, EventArgs e) { setButtons(false); String filePath = tb_path.Text; file = filePath; String extention = Path.GetExtension(filePath); List <Mesh> renderableMeshes = new List <Mesh>(); drawString = "File: " + file; updateBitmap(drawString); //Try and find the model file if (extention == ".mmh") { GFF tempGFF = new GFF(filePath); ModelHierarchy mh = new ModelHierarchy(tempGFF); currentlyShowing = Showing.Model; meshes = mh.mesh.toModel().meshes; setButtons(true); if (meshes.Length > 0) { setMeshNum(0); } } else if (extention == ".msh") { GFF tempGFF = new GFF(filePath); ModelMesh mm = new ModelMesh(tempGFF); currentlyShowing = Showing.Model; meshes = mm.toModel().meshes; setButtons(true); if (meshes.Length > 0) { setMeshNum(0); } } else if (extention == ".tga") { texture = new Targa(filePath); currentlyShowing = Showing.Texture; } else if (extention == ".lvl") { level = new LevelScene(filePath); currentlyShowing = Showing.Level; List <Patch> patchList = new List <Patch>(); List <Triangle> tris = new List <Triangle>(); foreach (ModelInstance m in level.lightmapModels) { for (int i = 0; i < m.meshes.Length; i++) { if (m.meshes[i].isLightmapped) { //Make the lightmap LightMap temp = new LightMap(m, m.meshes[i]); //For each patch instance in the lightmap foreach (Patch p in temp.patches) { patchList.Add(p); } } } if (m.baseModel.castsShadows) { tris.AddRange(m.tris); } } octree = new Octree(tris); patches = patchList.ToArray(); } else if (extention == ".xml") { level = new XMLScene(filePath); currentlyShowing = Showing.Level; List <Patch> patchList = new List <Patch>(); List <Triangle> tris = new List <Triangle>(); foreach (ModelInstance m in level.lightmapModels) { for (int i = 0; i < m.meshes.Length; i++) { if (m.meshes[i].isLightmapped) { //Make the lightmap LightMap temp = new LightMap(m, m.meshes[i]); //For each patch instance in the lightmap foreach (Patch p in temp.patches) { patchList.Add(p); } } } if (m.baseModel.castsShadows) { tris.AddRange(m.tris); } } octree = new Octree(tris); patches = patchList.ToArray(); } //If its not the right type of file then print an error else { drawString = "This is not a valid model (.mmh or .msh), texture (.tga), level (.lvl), or scene (.xml) file!"; } refreshView(); }
private void modelListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (modelListBox.SelectedItem != null) { String itemName = (String)modelListBox.SelectedItem; if (Path.GetExtension(itemName) == ".msh") { GFF tempGFF = ResourceManager.findFile <GFF>(itemName); if (tempGFF != null) { renderer.clearOverlays(); renderer.overlayText(tempGFF.path); renderer.showOverlays(); renderer.displayModel(new ModelMesh(tempGFF)); } else { Console.WriteLine("Couldn't find {0}", itemName); } } else if (Path.GetExtension(itemName) == ".mmh") { GFF tempGFF = ResourceManager.findFile <GFF>(itemName); if (tempGFF != null) { ModelHierarchy mh = new ModelHierarchy(tempGFF); if (mh.loadedMesh) { renderer.clearOverlays(); renderer.overlayText(mh.mmhName); renderer.showOverlays(); renderer.displayModel(mh.mesh); } else { Console.WriteLine("Couldn't load mesh {0} for {1}", mh.mshName, mh.mmhName); } } else { Console.WriteLine("Couldn't find {0}", itemName); } } else if (Path.GetExtension(itemName) == ".dds") { try { DDS texture = ResourceManager.findFile <DDS>(itemName); if (texture != null) { renderer.displayDDS(texture); } else { Console.WriteLine("Couldn't find {0}", itemName); } } catch (NotImplementedException ex) { Console.WriteLine(ex.Message); } } else if (Path.GetExtension(itemName) == ".mao") { MaterialObject mao = ResourceManager.findFile <MaterialObject>(itemName); } } }