private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.psk|*.psk;*.pskx"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string path = d.FileName; psk = new PSKFile(); psk.ImportPSK(path); CurrFile = path; RefreshTree(); } }
public void ImportFromPsk(string path) { psk = new PSKFile(); psk.ImportPSK(path); #region Vertices Mesh.Vertices = new Verts(); Mesh.Vertices.Points = new List<Vector3>(); for (int i = 0; i < psk.psk.edges.Count; i++) { int idx = psk.psk.edges[i].index; float valueX = psk.psk.points[idx].x; float valueY = psk.psk.points[idx].y; float valueZ = psk.psk.points[idx].z; Mesh.Vertices.Points.Add(new Vector3(valueX, valueY, valueZ)); } Mesh.Buffers.IndexBuffer = Mesh.Vertices.Points.Count(); byte[] buff = BitConverter.GetBytes((int)Mesh.Vertices.Points.Count()); for (int i = 0; i < 4; i++) Mesh.UnknownPart.data[24 + i] = buff[i]; #endregion #region materials Lod l = Mesh.Mat.Lods[0]; l.Sections = new List<Section>(); for (int i = 0; i < psk.psk.faces.Count; i++) { PSKFile.PSKFace e = psk.psk.faces[i]; int mat = e.material; if (mat >= l.Sections.Count()) { int min = i * 3; int minv = e.v0; if (e.v1 < minv) minv = e.v1; if (e.v2 < minv) minv = e.v2; int maxv = e.v0; if (e.v1 > maxv) maxv = e.v1; if (e.v2 > maxv) maxv = e.v2; Section s = new Section(); s.FirstIdx1 = min; s.FirstIdx2 = min; s.NumFaces1 = 1; s.NumFaces2 = 1; s.MatEff1 = minv; s.MatEff2 = maxv; s.Unk1 = 1; s.Unk2 = 1; s.Unk3 = 1; s.Unk4 = 0; s.Unk5 = 1; s.Unk6 = 0; l.Sections.Add(s); } else { Section s = l.Sections[mat]; int min = s.FirstIdx1 / 3; int max = s.NumFaces1; int minv = s.MatEff1; if (e.v1 < minv) minv = e.v1; if (e.v2 < minv) minv = e.v2; int maxv = s.MatEff2; if (e.v1 > maxv) maxv = e.v1; if (e.v2 > maxv) maxv = e.v2; if (i - s.FirstIdx1 / 3 + 1> max) max = i - s.FirstIdx1 / 3 + 1; if (i < min) min = i; s.FirstIdx1 = min * 3; s.FirstIdx2 = min * 3; s.NumFaces1 = max; s.NumFaces2 = max; s.MatEff1 = minv; s.MatEff2 = maxv; l.Sections[mat] = s; } } l.SectionCount = l.Sections.Count(); for (int i = 0; i < l.SectionCount; i++) { Select_Material selm = new Select_Material(); selm.hasSelected = false; selm.listBox1.Items.Clear(); selm.Objects = new List<int>(); for(int j =0;j<pcc.Exports.Count;j++) { PCCObject.ExportEntry e =pcc.Exports[j]; if (e.ClassName == "Material" || e.ClassName == "MaterialInstanceConstant") { selm.listBox1.Items.Add(j + "\t" + e.ClassName + " : " + e.ObjectName); selm.Objects.Add(j); } } selm.Show(); while (selm != null && !selm.hasSelected) { Application.DoEvents(); } Section s = l.Sections[i]; s.Name = selm.SelIndex + 1; l.Sections[i] = s; selm.Close(); } l.NumVert = psk.psk.points.Count(); Mesh.Mat.Lods[0] = l; #endregion #region Edges int oldcount = Mesh.Edges.UVSet[0].UVs.Count(); Mesh.Buffers.UV1 = oldcount; Mesh.Buffers.UV2 = oldcount * 4 + 8; Mesh.Edges = new Edges(); Mesh.Edges.UVSet = new List<UVSet>(); for (int i = 0; i < psk.psk.edges.Count; i++) { UVSet newSet = new UVSet(); newSet.UVs = new List<Vector2>(); for (int j = 0; j < oldcount; j++) newSet.UVs.Add(new Vector2(psk.psk.edges[i].U, psk.psk.edges[i].V)); newSet.x1 = 0; newSet.x2 = 0; newSet.y1 = 0; newSet.y2 = 0; newSet.z1 = 0; newSet.z2 = 0; newSet.w1 = 0; newSet.w2 = 0; Mesh.Edges.UVSet.Add(newSet); } Mesh.Edges.count = psk.psk.edges.Count; Mesh.Edges.size = 8 + 4 * oldcount; #endregion #region Faces Mesh.RawTris.RawTriangles = new List<RawTriangle>(); bool WithIndex = (Mesh.IdxBuf.Indexes.Count != 0); if (WithIndex) Mesh.IdxBuf.Indexes = new List<ushort>(); for (int i = 0; i < psk.psk.faces.Count; i++) { RawTriangle r = new RawTriangle(); PSKFile.PSKFace f = psk.psk.faces[i]; r.v0 = (Int16)f.v0; r.v1 = (Int16)f.v1; r.v2 = (Int16)f.v2; r.mat = f.material; Mesh.RawTris.RawTriangles.Add(r); if (WithIndex) { Mesh.IdxBuf.Indexes.Add((UInt16)f.v0); Mesh.IdxBuf.Indexes.Add((UInt16)f.v1); Mesh.IdxBuf.Indexes.Add((UInt16)f.v2); Mesh.IdxBuf.count = Mesh.IdxBuf.Indexes.Count(); } } CalcTangentSpace(); #endregion RecalculateBoundings(); GenerateMesh(); }