Exemple #1
0
 public void ImportFromPsk(PSKFile.PSKObject PSK)
 {
     for (int i = 0; i < Mesh.LODs.Count; i++)
     {
         if (Mesh.LODs[i].points.Count == PSK.Points.Length)
         {
             for (int j = 0; j < PSK.Points.Length; j++)
             {
                 Mesh.LODs[i].points[j].X = PSK.Points[j].x;
                 Mesh.LODs[i].points[j].Y = PSK.Points[j].y;
                 Mesh.LODs[i].points[j].Z = PSK.Points[j].z;
             }
             return;
         }
     }
     MessageBox.Show("Found no LOD with same vertice count!");
 }
Exemple #2
0
        public PSKFile ExportToPSK(int LOD = 0)
        {
            PSKFile PSKf = new PSKFile();

            PSK = PSKf.PSK;
            LOD currLOD = Mesh.LODs[LOD];

            PSK.Points = new PSKFile.Vector[currLOD.points.Count];
            for (int i = 0; i < currLOD.points.Count; i++)
            {
                PSK.Points[i].x = currLOD.points[i].X;
                PSK.Points[i].y = currLOD.points[i].Y;
                PSK.Points[i].z = currLOD.points[i].Z;
            }
            PSK.Edges = new PSKFile.Edge[currLOD.points.Count];
            for (int i = 0; i < currLOD.points.Count; i++)
            {
                PSK.Edges[i].U     = currLOD.points[i].U;
                PSK.Edges[i].V     = currLOD.points[i].U;
                PSK.Edges[i].index = i;
            }
            PSK.Mats         = new PSKFile.Material[1];
            PSK.Mats[0].name = "";
            PSK.Faces        = new PSKFile.Face[currLOD.allFaces];
            int n = 0;

            for (int i = 0; i < currLOD.sections.Count; i++)
            {
                LODSection currSel = currLOD.sections[i];
                for (int j = 0; j < currSel.count; j++)
                {
                    PSK.Faces[n].e0 = currSel.Faces[j].e0;
                    PSK.Faces[n].e1 = currSel.Faces[j].e1;
                    PSK.Faces[n].e2 = currSel.Faces[j].e2;
                    n++;
                }
            }
            PSKWriteBones();
            PSKWriteWeights(LOD);
            PSKf.PSK = PSK;
            return(PSKf);
        }
Exemple #3
0
        public void ImportFromPSK(PSKFile.PSKObject PSK)
        {
            Vertices.Clear();
            //UVSets.Clear();
            RawFaces.Clear();
            int count = PSK.Points.Length;

            for (int i = 0; i < count; i++)
            {
                Vector v;
                v.x = PSK.Points[i].x;
                v.y = PSK.Points[i].y;
                v.z = PSK.Points[i].z;
                Vertices.Add(v);
            }
            //count = PSK.Edges.Length;
            //for (int i = 0; i < count; i++)
            //{
            //    int index = PSK.Edges[i].index;
            //    UVSet uv = new UVSet();
            //    uv.U = new float[1];
            //    uv.V = new float[1];
            //    uv.U[0] = PSK.Edges[i].U;
            //    uv.V[0] = PSK.Edges[i].V;
            //    UVSets.Add(uv);
            //}
            count = PSK.Faces.Length;
            for (int i = 0; i < count; i++)
            {
                RawFace f;
                f.e0 = PSK.Faces[i].e0;
                f.e1 = PSK.Faces[i].e1;
                f.e2 = PSK.Faces[i].e2;
                RawFaces.Add(f);
            }
            //Unknown1 = new byte[count / 4 + 8];
            //Unknown1[0] = 0x6;
            //byte[] buff = BitConverter.GetBytes((Int32)(count / 4));
            //for (int i = 0; i < 4; i++)
            //    Unknown1[4 + i] = buff[i];
        }
Exemple #4
0
        public PSKFile ExportToPsk()
        {
            PSKFile PSKf = new PSKFile();

            PSKFile.PSKObject PSK = PSKf.PSK;
            PSK.Points = new PSKFile.Vector[Vertices.Count];
            for (int i = 0; i < Vertices.Count; i++)
            {
                PSK.Points[i].x = Vertices[i].x;
                PSK.Points[i].y = Vertices[i].y;
                PSK.Points[i].z = Vertices[i].z;
            }
            PSK.Edges = new PSKFile.Edge[UVSets.Count];
            int subc = UVSets[0].U.Length - 1;

            for (int i = 0; i < UVSets.Count; i++)
            {
                PSK.Edges[i].index = i;
                PSK.Edges[i].mat   = 0;
                PSK.Edges[i].U     = UVSets[i].U[subc];
                PSK.Edges[i].V     = UVSets[i].U[subc];
            }
            PSK.Faces = new PSKFile.Face[RawFaces.Count];
            for (int i = 0; i < RawFaces.Count; i++)
            {
                PSK.Faces[i].e0 = RawFaces[i].e0;
                PSK.Faces[i].e1 = RawFaces[i].e1;
                PSK.Faces[i].e2 = RawFaces[i].e2;
            }
            PSK.Mats         = new PSKFile.Material[1];
            PSK.Mats[0].name = "";
            PSK.Bones        = new PSKFile.PSKBone[0];
            PSK.Weights      = new PSKFile.Weight[0];
            PSKf.PSK         = PSK;
            return(PSKf);
        }
Exemple #5
0
        public byte[] InjectFromPSK(PSKFile.PSKObject PSK)
        {
            byte[] buff = new byte[0];
            if (offFace == -1 || offIndex == -1 || offUV == -1 || offVert == -1 || offUnk == -1)
            {
                return(buff);
            }
            List <InjectOffset> l = new List <InjectOffset>();
            MemoryStream        m = new MemoryStream();

            l.Add(newInject(offFace, 0));
            l.Add(newInject(offIndex, 1));
            l.Add(newInject(offUV, 2));
            l.Add(newInject(offVert, 3));
            l.Add(newInject(offUnk, 4));
            bool run = true;

            while (run)
            {
                run = false;
                for (int i = 0; i < 4; i++)
                {
                    if (l[i].off > l[i + 1].off)
                    {
                        InjectOffset t = l[i];
                        l[i]     = l[i + 1];
                        l[i + 1] = t;
                        run      = true;
                    }
                }
            }
            int nextoff = l[0].off;
            int pos     = 0;
            int size;
            int count;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < nextoff - pos; j++)
                {
                    m.WriteByte(memory[pos + j]);
                }
                switch (l[i].type)
                {
                    #region Faces
                case 0:
                    count = PSK.Faces.Length;
                    buff  = BitConverter.GetBytes((Int32)8);
                    m.Write(buff, 0, 4);
                    buff = BitConverter.GetBytes((Int32)count);
                    m.Write(buff, 0, 4);
                    for (int j = 0; j < count; j++)
                    {
                        buff = BitConverter.GetBytes((UInt16)PSK.Faces[j].e0);
                        m.Write(buff, 0, 2);
                        buff = BitConverter.GetBytes((UInt16)PSK.Faces[j].e1);
                        m.Write(buff, 0, 2);
                        buff = BitConverter.GetBytes((UInt16)PSK.Faces[j].e2);
                        m.Write(buff, 0, 2);
                        buff = BitConverter.GetBytes((UInt16)0);
                        m.Write(buff, 0, 2);
                    }
                    break;
                    #endregion

                    #region IndexBuffer
                case 1:
                    ushort[] Indexes = new ushort[PSK.Faces.Length * 3];
                    int      n       = 0;
                    for (int j = 0; j < PSK.Faces.Length; j++)
                    {
                        Indexes[n] = PSK.Faces[j].e0;
                        n++;
                        Indexes[n] = PSK.Faces[j].e1;
                        n++;
                        Indexes[n] = PSK.Faces[j].e2;
                        n++;
                    }
                    count = Indexes.Length;
                    buff  = BitConverter.GetBytes((Int32)2);
                    m.Write(buff, 0, 4);
                    buff = BitConverter.GetBytes((Int32)count);
                    m.Write(buff, 0, 4);
                    for (int j = 0; j < count; j++)
                    {
                        buff = BitConverter.GetBytes((UInt16)Indexes[j]);
                        m.Write(buff, 0, 2);
                    }
                    break;
                    #endregion

                    #region UV
                case 2:
                    size  = BitConverter.ToInt32(memory, l[i].off);
                    count = BitConverter.ToInt32(memory, l[i].off);
                    int subc = size / 4;
                    count = PSK.Edges.Length;
                    buff  = BitConverter.GetBytes((Int32)size);
                    m.Write(buff, 0, 4);
                    buff = BitConverter.GetBytes((Int32)count);
                    m.Write(buff, 0, 4);
                    for (int j = 0; j < count; j++)
                    {
                        for (int k = 0; k < subc; k++)
                        {
                            buff = BitConverter.GetBytes(FloatToHalf(PSK.Edges[j].U));
                            m.Write(buff, 0, 2);
                            buff = BitConverter.GetBytes(FloatToHalf(PSK.Edges[j].V));
                            m.Write(buff, 0, 2);
                        }
                    }
                    break;
                    #endregion

                    #region Verts
                case 3:
                    count = PSK.Edges.Length;
                    buff  = BitConverter.GetBytes((Int32)12);
                    m.Write(buff, 0, 4);
                    buff = BitConverter.GetBytes((Int32)count);
                    m.Write(buff, 0, 4);
                    for (int j = 0; j < count; j++)
                    {
                        buff = BitConverter.GetBytes(PSK.Points[PSK.Edges[j].index].x);
                        m.Write(buff, 0, 4);
                        buff = BitConverter.GetBytes(PSK.Points[PSK.Edges[j].index].y);
                        m.Write(buff, 0, 4);
                        buff = BitConverter.GetBytes(PSK.Points[PSK.Edges[j].index].z);
                        m.Write(buff, 0, 4);
                    }
                    break;
                    #endregion

                    #region Unkown
                case 4:
                    size  = BitConverter.ToInt32(memory, nextoff);
                    count = BitConverter.ToInt32(memory, nextoff + 4);
                    if (size == 6)
                    {
                        buff = BitConverter.GetBytes((Int32)size);
                        m.Write(buff, 0, 4);
                        count = 1;
                        while (count * 8 <= PSK.Faces.Length)
                        {
                            count *= 2;
                        }
                        buff = BitConverter.GetBytes((Int32)count);
                        m.Write(buff, 0, 4);
                        for (int j = 0; j < size * count; j++)
                        {
                            m.WriteByte(0);
                        }
                    }
                    else
                    {
                        m.Write(Unknown1, 0, Unknown1.Length);
                    }
                    break;
                    #endregion
                }
                if (i < 4)
                {
                    pos     = nextoff;
                    nextoff = l[i + 1].off;
                    //if (l[i + 1].type == 3)
                    //{
                    //    size = BitConverter.ToInt32(memory, nextoff - 12);
                    //    if (size == 12)
                    //    {
                    //        buff = BitConverter.GetBytes((Int32)PSK.Edges.Length);
                    //        for (int j = 0; j < 4; j++)
                    //            memory[nextoff - 8 + j] = buff[j];
                    //    }
                    //}
                    //if (l[i + 1].type == 2)
                    //{
                    //    size = BitConverter.ToInt32(memory, nextoff - 16);
                    //    if (size == 12)
                    //    {
                    //        buff = BitConverter.GetBytes((Int32)PSK.Edges.Length);
                    //        for (int j = 0; j < 4; j++)
                    //            memory[nextoff - 12 + j] = buff[j];
                    //    }
                    //}
                    //if (l[i + 1].type == 1)
                    //{
                    //    buff = BitConverter.GetBytes((Int32)PSK.Faces.Length * 3);
                    //    for (int j = 0; j < 4; j++)
                    //        memory[nextoff - 4 + j] = buff[j];
                    //}
                    size  = BitConverter.ToInt32(memory, pos);
                    count = BitConverter.ToInt32(memory, pos + 4);
                    pos  += size * count + 8;
                }
                else
                {
                    pos     = l[i].off;
                    size    = BitConverter.ToInt32(memory, pos);
                    count   = BitConverter.ToInt32(memory, pos + 4);
                    pos    += size * count + 8;
                    nextoff = memsize;
                    for (int j = 0; j < nextoff - pos; j++)
                    {
                        m.WriteByte(memory[pos + j]);
                    }
                }
            }
            //SaveFileDialog d = new SaveFileDialog();
            //d.Filter = "*.bin|*.bin";
            //buff = m.ToArray();
            //if (d.ShowDialog() == DialogResult.OK)
            //{
            //    FileStream fs = new FileStream(d.FileName, FileMode.Create, FileAccess.Write);
            //    fs.Write(buff,0,buff.Length);
            //    fs.Close();
            //    MessageBox.Show("Done.");
            //}
            return(m.ToArray());
        }