private void LODcomboBox3_SelectedIndexChanged(object sender, EventArgs e) { BFRES.Mesh.LOD_Mesh msh = (BFRES.Mesh.LOD_Mesh)LODcomboBox3.SelectedItem; Mesh.DisplayLODIndex = LODcomboBox3.SelectedIndex; bfres.UpdateRenderMeshes(); PolyCountlabel3.Text = "Poly Count " + Mesh.lodMeshes[Mesh.DisplayLODIndex].displayFaceSize.ToString(); }
public static void WiiU2Switch(string FileName, int CurModel, BFRES b) { ResFile TargetWiiUBFRES = new ResFile(FileName); int CurMdl = 0; foreach (Model mdl in TargetWiiUBFRES.Models.Values) { int CurBn = 0; foreach (Syroot.NintenTools.Bfres.Bone bn in mdl.Skeleton.Bones.Values) { Bone bone = b.models[CurMdl].skeleton.bones[CurBn]; bone.scale[0] = bn.Scale.X; bone.scale[1] = bn.Scale.Y; bone.scale[2] = bn.Scale.Z; bone.rotation[0] = bn.Rotation.X; bone.rotation[1] = bn.Rotation.Y; bone.rotation[2] = bn.Rotation.Z; bone.rotation[3] = bn.Rotation.W; bone.position[0] = bn.Position.X; bone.position[1] = bn.Position.Y; bone.position[2] = bn.Position.Z; CurBn++; } b.models[CurMdl].skeleton.reset(); int CurShape = 0; foreach (Shape shp in mdl.Shapes.Values) { Mesh poly = b.models[CurMdl].poly[CurShape]; //Create a buffer instance which stores all the buffer data // VertexBufferHelperAttrib uv1 = helper["_u1"]; int TotalCount = poly.vertices.Count; int LODCount = 0; uint FaceCount = FaceCount = shp.Meshes[LODCount].IndexCount; uint[] indicesArray = shp.Meshes[LODCount].GetIndices().ToArray(); int TotalFaceCount = poly.lodMeshes[poly.DisplayLODIndex].faces.Count; poly.lodMeshes[poly.DisplayLODIndex].faces.Clear(); for (int face = 0; face < FaceCount; face++) { poly.lodMeshes[poly.DisplayLODIndex].faces.Add((int)indicesArray[face] + (int)shp.Meshes[LODCount].FirstVertex); } if (TotalFaceCount != poly.lodMeshes[poly.DisplayLODIndex].faces.Count) { MessageBox.Show("Error F"); } poly.vertices.Clear(); //Create a buffer instance which stores all the buffer data VertexBufferHelper helper = new VertexBufferHelper(mdl.VertexBuffers[shp.VertexBufferIndex], TargetWiiUBFRES.ByteOrder); //Set each array first from the lib if exist. Then add the data all in one loop Syroot.Maths.Vector4F[] vec4Positions = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4Normals = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4uv0 = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4uv1 = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4uv2 = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4c0 = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4t0 = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4b0 = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4w0 = new Syroot.Maths.Vector4F[0]; Syroot.Maths.Vector4F[] vec4i0 = new Syroot.Maths.Vector4F[0]; foreach (VertexAttrib att in mdl.VertexBuffers[shp.VertexBufferIndex].Attributes.Values) { Mesh.VertexAttribute attr = new Mesh.VertexAttribute(); attr.Name = att.Name; // attr.Format = att.Format; if (att.Name == "_p0") { vec4Positions = WiiUAttributeData(att, helper, "_p0"); } if (att.Name == "_n0") { vec4Normals = WiiUAttributeData(att, helper, "_n0"); } if (att.Name == "_u0") { vec4uv0 = WiiUAttributeData(att, helper, "_u0"); } if (att.Name == "_u1") { vec4uv1 = WiiUAttributeData(att, helper, "_u1"); } if (att.Name == "_u2") { vec4uv2 = WiiUAttributeData(att, helper, "_u2"); } if (att.Name == "_c0") { vec4c0 = WiiUAttributeData(att, helper, "_c0"); } if (att.Name == "_t0") { vec4t0 = WiiUAttributeData(att, helper, "_t0"); } if (att.Name == "_b0") { vec4b0 = WiiUAttributeData(att, helper, "_b0"); } if (att.Name == "_w0") { vec4w0 = WiiUAttributeData(att, helper, "_w0"); } if (att.Name == "_i0") { vec4i0 = WiiUAttributeData(att, helper, "_i0"); } poly.vertexAttributes.Add(attr); } for (int i = 0; i < vec4Positions.Length; i++) { Vertex v = new Vertex(); if (vec4Positions.Length > 0) { v.pos = new Vector3(vec4Positions[i].X, vec4Positions[i].Y, vec4Positions[i].Z); } if (vec4Normals.Length > 0) { v.nrm = new Vector3(vec4Normals[i].X, vec4Normals[i].Y, vec4Normals[i].Z); } if (vec4uv0.Length > 0) { v.uv0 = new Vector2(vec4uv0[i].X, vec4uv0[i].Y); } if (vec4uv1.Length > 0) { v.uv1 = new Vector2(vec4uv1[i].X, vec4uv1[i].Y); } if (vec4uv2.Length > 0) { v.uv2 = new Vector2(vec4uv2[i].X, vec4uv2[i].Y); } if (vec4w0.Length > 0) { v.boneWeights.Add(vec4w0[i].X); v.boneWeights.Add(vec4w0[i].Y); v.boneWeights.Add(vec4w0[i].Z); v.boneWeights.Add(vec4w0[i].W); } if (vec4i0.Length > 0) { v.boneIds.Add((int)vec4i0[i].X); v.boneIds.Add((int)vec4i0[i].Y); v.boneIds.Add((int)vec4i0[i].Z); v.boneIds.Add((int)vec4i0[i].W); } if (vec4t0.Length > 0) { v.tan = new Vector4(vec4t0[i].X, vec4t0[i].Y, vec4t0[i].Z, vec4t0[i].W); } if (vec4b0.Length > 0) { v.bitan = new Vector4(vec4b0[i].X, vec4b0[i].Y, vec4b0[i].Z, vec4b0[i].W); } if (vec4c0.Length > 0) { v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W); } poly.vertices.Add(v); } CurShape++; } CurMdl++; } b.UpdateRenderMeshes(); }