Ejemplo n.º 1
0
        public void ReadRawTris(byte[] memory)
        {
            UnknownList l = new UnknownList();

            l.size     = BitConverter.ToInt32(memory, readerpos);
            l.count    = BitConverter.ToInt32(memory, readerpos + 4);
            readerpos += 8;
            int len = l.size * l.count;

            l.data = new byte[len];
            for (int i = 0; i < len; i++)
            {
                l.data[i] = memory[readerpos + i];
            }
            RawTriangles = new List <RawTriangle>();
            for (int i = 0; i < l.count; i++)
            {
                RawTriangle r = new RawTriangle();
                r.v0  = BitConverter.ToInt16(memory, readerpos);
                r.v1  = BitConverter.ToInt16(memory, readerpos + 2);
                r.v2  = BitConverter.ToInt16(memory, readerpos + 4);
                r.mat = BitConverter.ToInt16(memory, readerpos + 6);
                RawTriangles.Add(r);
                string s = "";
                for (int j = 0; j < l.size; j++)
                {
                    s += memory[readerpos].ToString("X2") + " ";
                    readerpos++;
                }
            }
            RawTris rt = new RawTris();

            rt.RawTriangles = RawTriangles;
            Mesh.RawTris    = rt;
        }
Ejemplo n.º 2
0
 public void ReadRawTris(byte[] memory)
 {
     TreeNode res = new TreeNode("Raw triangles pos: 0x" + readerpos.ToString("X4"));
     UnknownList l = new UnknownList();
     l.size = BitConverter.ToInt32(memory, readerpos);
     l.count = BitConverter.ToInt32(memory, readerpos + 4);
     readerpos += 8;
     int len = l.size * l.count;
     l.data = new byte[len];
     for (int i = 0; i < len; i++)
         l.data[i] = memory[readerpos + i];
     res.Nodes.Add(new TreeNode("Size : " + l.size.ToString()));
     res.Nodes.Add(new TreeNode("Count : " + l.count.ToString()));
     TreeNode t = new TreeNode("Data");
     RawTriangles = new List<RawTriangle>();
     for (int i = 0; i < l.count; i++)
     {
         RawTriangle r = new RawTriangle();
         r.v0 = BitConverter.ToInt16(memory, readerpos);
         r.v1 = BitConverter.ToInt16(memory, readerpos + 2);
         r.v2 = BitConverter.ToInt16(memory, readerpos + 4);
         r.mat = BitConverter.ToInt16(memory, readerpos + 6);
         RawTriangles.Add(r);
         string s = "";
         for (int j = 0; j < l.size; j++)
         {
             s += memory[readerpos].ToString("X2") + " ";
             readerpos++;
         }
         t.Nodes.Add(new TreeNode("#" + i.ToString("D4") + " : " + s));
     }
     res.Nodes.Add(t);
     RawTris rt = new RawTris();
     rt.RawTriangles = RawTriangles;
     rt.t = res;
     Mesh.RawTris = rt;
 }
Ejemplo n.º 3
0
        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();

        }
Ejemplo n.º 4
0
 public void ReadRawTris(byte[] memory)
 {
     UnknownList l = new UnknownList();
     l.size = BitConverter.ToInt32(memory, readerpos);
     l.count = BitConverter.ToInt32(memory, readerpos + 4);
     readerpos += 8;
     int len = l.size * l.count;
     l.data = new byte[len];
     for (int i = 0; i < len; i++)
         l.data[i] = memory[readerpos + i];
     RawTriangles = new List<RawTriangle>();
     for (int i = 0; i < l.count; i++)
     {
         RawTriangle r = new RawTriangle();
         r.v0 = BitConverter.ToInt16(memory, readerpos);
         r.v1 = BitConverter.ToInt16(memory, readerpos + 2);
         r.v2 = BitConverter.ToInt16(memory, readerpos + 4);
         r.mat = BitConverter.ToInt16(memory, readerpos + 6);
         RawTriangles.Add(r);
         string s = "";
         for (int j = 0; j < l.size; j++)
         {
             s += memory[readerpos].ToString("X2") + " ";
             readerpos++;
         }
     }
     RawTris rt = new RawTris();
     rt.RawTriangles = RawTriangles;
     Mesh.RawTris = rt;
 }