public void MeshLoads() { Settings.initializeSettings(); String meshERFPath = "E:\\Program Files (x86)\\Steam\\steamapps\\common\\dragon age origins\\packages\\core\\data\\modelmeshdata.erf"; ERF meshes = new ERF(meshERFPath); meshes.readKeyData(); Assert.Greater(meshes.resourceCount, 0); int failures = 0; for (int i = 0; i < meshes.resourceCount; i++) { GFF temp = IO.findFile<GFF>(meshes.resourceNames[i]); Assert.NotNull(temp, "Not found: |" + meshes.resourceNames[i] + "|" + i); if (Path.GetExtension(meshes.resourceNames[i]) == ".msh") { try { ModelMesh tempH = new ModelMesh(temp); } catch (Exception) { Console.WriteLine(meshes.resourceNames[i]); failures++; } } } Assert.AreEqual(0, failures); }
public void readData() { BinaryReader file = binaryFile.openReader(); int reference; //Get the name of the mmh file file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[MMH_NAME_INDEX].index, SeekOrigin.Begin); mmhName = IOUtilities.readECString(file, binaryFile.dataOffset + file.ReadInt32()).ToLower(); //Get the name of the msh file file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[MSH_NAME_INDEX].index, SeekOrigin.Begin); mshName = IOUtilities.readECString(file, binaryFile.dataOffset + file.ReadInt32()).ToLower(); //Get the total number of bones in the mmh file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[TOTAL_BONES_INDEX].index, SeekOrigin.Begin); numBones = file.ReadInt32(); //Apparently fx models have an extra field... isFXModel = binaryFile.structs[0].fields.Length == 8; if (isFXModel) { file.Close(); return; } //Get the children list (should only contain GOB) file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[TOP_LEVEL_CHILDREN_INDEX].index, SeekOrigin.Begin); reference = file.ReadInt32(); file.BaseStream.Seek(binaryFile.dataOffset + reference, SeekOrigin.Begin); GenericList childrenList = new GenericList(file); //Get the children of the GOB object //Sometimes its a node struct, sometimes its a mshh struct . . . if ((int)(childrenList.type[0].id) == nodeStructIndex) { file.BaseStream.Seek(binaryFile.dataOffset + childrenList[0] + nodeStruct.fields[GOB_CHILDREN_INDEX].index, SeekOrigin.Begin); } else if ((int)(childrenList.type[0].id) == meshChunkInfoIndex) { file.BaseStream.Seek(binaryFile.dataOffset + childrenList[0] + meshChunkInfoStruct.fields[MSH_CHUNK_CHILDREN_INDEX].index, SeekOrigin.Begin); } reference = file.ReadInt32(); file.BaseStream.Seek(binaryFile.dataOffset + reference, SeekOrigin.Begin); childrenList = new GenericList(file); //Find the mesh GFF temp = ResourceManager.findFile<GFF>(mshName); //If its not there throw an exception cause we need it if (temp == null) { Console.WriteLine("Could not find mesh file \"{0}\".", mshName); file.Close(); return; //throw new Exception("COULD NOT FIND MESH FILE, LOOK AT CONSOLE!!!!!!"); } loadedMesh = true; //Make the mesh mesh = new ModelMesh(temp); //For each thing in the child list for (int i = 0; i < childrenList.length; i++) { //If the child is a mesh chunk info struct if ((int)childrenList.type[i].id == meshChunkInfoIndex) { //Fill in the missing mesh chunk info updateChunk(file, binaryFile.dataOffset + childrenList[i], new Vector3(), new Quaternion()); } } file.Close(); }
public ModelUploader(ModelMesh m) { model = m; }
public ModelUploader() { model = new ModelMesh(); }
public void readData() { BinaryReader file = binaryFile.openReader(); int reference; //Get the name of the mmh file file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[MMH_NAME_INDEX].index, SeekOrigin.Begin); mmhName = IOUtilities.readECString(file, binaryFile.dataOffset + file.ReadInt32()).ToLower(); //Get the name of the msh file file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[MSH_NAME_INDEX].index, SeekOrigin.Begin); mshName = IOUtilities.readECString(file, binaryFile.dataOffset + file.ReadInt32()).ToLower(); //Get the total number of bones in the mmh file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[TOTAL_BONES_INDEX].index, SeekOrigin.Begin); numBones = file.ReadInt32(); //Apparently fx models have an extra field... isFXModel = binaryFile.structs[0].fields.Length == 8; if (isFXModel) { file.Close(); return; } //Get the children list (should only contain GOB) file.BaseStream.Seek(binaryFile.dataOffset + binaryFile.structs[0].fields[TOP_LEVEL_CHILDREN_INDEX].index, SeekOrigin.Begin); reference = file.ReadInt32(); file.BaseStream.Seek(binaryFile.dataOffset + reference, SeekOrigin.Begin); GenericList childrenList = new GenericList(file); //Get the children of the GOB object //Sometimes its a node struct, sometimes its a mshh struct . . . if ((int)(childrenList.type[0].id) == nodeStructIndex) { file.BaseStream.Seek(binaryFile.dataOffset + childrenList[0] + nodeStruct.fields[GOB_CHILDREN_INDEX].index, SeekOrigin.Begin); } else if ((int)(childrenList.type[0].id) == meshChunkInfoIndex) { file.BaseStream.Seek(binaryFile.dataOffset + childrenList[0] + meshChunkInfoStruct.fields[MSH_CHUNK_CHILDREN_INDEX].index, SeekOrigin.Begin); } reference = file.ReadInt32(); file.BaseStream.Seek(binaryFile.dataOffset + reference, SeekOrigin.Begin); childrenList = new GenericList(file); //Find the mesh GFF temp = ResourceManager.findFile <GFF>(mshName); //If its not there throw an exception cause we need it if (temp == null) { Console.WriteLine("Could not find mesh file \"{0}\".", mshName); file.Close(); return; //throw new Exception("COULD NOT FIND MESH FILE, LOOK AT CONSOLE!!!!!!"); } loadedMesh = true; //Make the mesh mesh = new ModelMesh(temp); //For each thing in the child list for (int i = 0; i < childrenList.length; i++) { //If the child is a mesh chunk info struct if ((int)childrenList.type[i].id == meshChunkInfoIndex) { //Fill in the missing mesh chunk info updateChunk(file, binaryFile.dataOffset + childrenList[i], new Vector3(), new Quaternion()); } } file.Close(); }
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(); }