private void Replace(object sender, EventArgs args) { BNTX bn = this; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Supported Formats|*.bntx;|" + "All files(*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { byte[] newBntx = File.ReadAllBytes(ofd.FileName); FileData f = new FileData(newBntx); f.Endian = Endianness.Little; bn.Nodes.Clear(); bn.ReadBNTX(f); } }
public void Read(ResFile TargetSwitchBFRES, FileData f) { Nodes.Add(TModels); Nodes.Add(TMaterialAnim); Nodes.Add(TVisualAnim); Nodes.Add(TShapeAnim); Nodes.Add(TSceneAnim); Nodes.Add(TEmbedded); ImageKey = "bfres"; SelectedImageKey = "bfres"; FSKACount = TargetSwitchBFRES.SkeletalAnims.Count; FVISCount = TargetSwitchBFRES.BoneVisibilityAnims.Count; FMAACount = TargetSwitchBFRES.MaterialAnims.Count; Console.WriteLine("Name = " + TargetSwitchBFRES.Name); foreach (ExternalFile ext in TargetSwitchBFRES.ExternalFiles) { f = new FileData(ext.Data); f.Endian = Endianness.Little; string EmMagic = f.readString(f.pos(), 4); if (EmMagic.Equals("BNTX")) //Textures { int temp = f.pos(); BNTX t = new BNTX(); t.ReadBNTX(f); TEmbedded.Nodes.Add(t); } } int ModelCur = 0; //FMDLs -Models- foreach (Model mdl in TargetSwitchBFRES.Models) { FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff model.Text = mdl.Name; TModels.Nodes.Add(model); ReadSkeleton(model, mdl); model.skeleton.reset(); model.skeleton.update(); //MeshTime!! foreach (Shape shp in mdl.Shapes) { Mesh poly = new Mesh(); poly.Text = shp.Name; poly.MaterialIndex = shp.MaterialIndex; poly.matrFlag = shp.VertexSkinCount; poly.fsklindx = shp.BoneIndex; TModels.Nodes[ModelCur].Nodes.Add(poly); ReadVertexBuffer(mdl, shp, poly); // int LODCount = shp.Meshes.Count - 1; //For going to the lowest poly LOD mesh int LODCount = 0; uint FaceCount = FaceCount = shp.Meshes[LODCount].IndexCount; uint[] indicesArray = shp.Meshes[LODCount].GetIndices().ToArray(); poly.BoundingCount = shp.SubMeshBoundings.Count; for (int face = 0; face < FaceCount; face++) { poly.faces.Add((int)indicesArray[face] + (int)shp.Meshes[LODCount].FirstVertex); } foreach (Bounding bnd in shp.SubMeshBoundings) { Mesh.BoundingBox box = new Mesh.BoundingBox(); box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z); box.Extent = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z); poly.boundingBoxes.Add(box); //Each box is by LOD mesh. This will be in a seperate class later so only one will be added } foreach (float r in shp.RadiusArray) { poly.radius.Add(r); } // Read materials Material mat = mdl.Materials[shp.MaterialIndex]; poly.material.Name = mat.Name; ReadTextureRefs(mat, poly); ReadShaderParams(mat, poly); ReadRenderInfo(mat, poly); foreach (Sampler smp in mdl.Materials[shp.MaterialIndex].Samplers) { SamplerInfo s = new SamplerInfo(); s.WrapModeU = (int)smp.WrapModeU; s.WrapModeV = (int)smp.WrapModeV; s.WrapModeW = (int)smp.WrapModeW; poly.material.samplerinfo.Add(s); } model.poly.Add(poly); } models.Add(model); ModelCur++; } }