Beispiel #1
0
 private void PSKFReadMats(FileStream fs, PSKHeader PSKh)
 {
     PSK.Mats = new Material[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         PSK.Mats[i].name = "";
         byte b;
         for (int j = 0; j < 64; j++)
         {
             b = (byte)fs.ReadByte();
             if (b != 0)
             {
                 PSK.Mats[i].name += (char)b;
             }
         }
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Mats[i].texid = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].flags = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].matid = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].matflags = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].LODBias = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].LODStyle = BitConverter.ToInt32(buff, 0);
     }
 }
Beispiel #2
0
        private PSKHeader ReadHeader(FileStream fs)
        {
            PSKHeader res = new PSKHeader();

            res.name  = ReadFixedString(fs, 20);
            res.flags = Helpers.ReadInt(fs);
            res.size  = Helpers.ReadInt(fs);
            res.count = Helpers.ReadInt(fs);
            return(res);
        }
Beispiel #3
0
 private void PSKFReadWeights(FileStream fs, PSKHeader PSKh)
 {
     PSK.Weights = new Weight[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Weights[i].w = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Weights[i].pointid = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Weights[i].boneid = BitConverter.ToInt32(buff, 0);
     }
 }
Beispiel #4
0
 private void PSKFReadPoints(FileStream fs, PSKHeader PSKh)
 {
     PSK.Points = new Vector[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Points[i].x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Points[i].y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Points[i].z = BitConverter.ToSingle(buff, 0);
     }
 }
Beispiel #5
0
 private void PSKFReadBones(FileStream fs, PSKHeader PSKh)
 {
     PSK.Bones = new PSKBone[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         PSK.Bones[i].name = "";
         byte b;
         for (int j = 0; j < 64; j++)
         {
             b = (byte)fs.ReadByte();
             if (b != 0)
             {
                 PSK.Bones[i].name += (char)b;
             }
         }
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Bones[i].flags = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].childcount = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].parent = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.z = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.w = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].position.x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].position.y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].position.z = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].length = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].size.x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].size.y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].size.z = BitConverter.ToSingle(buff, 0);
     }
 }
Beispiel #6
0
 private void PSKFReadFaces(FileStream fs, PSKHeader PSKh)
 {
     PSK.Faces = new Face[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[2];
         fs.Read(buff, 0, 2);
         PSK.Faces[i].e0 = BitConverter.ToUInt16(buff, 0);
         fs.Read(buff, 0, 2);
         PSK.Faces[i].e1 = BitConverter.ToUInt16(buff, 0);
         fs.Read(buff, 0, 2);
         PSK.Faces[i].e2  = BitConverter.ToUInt16(buff, 0);
         PSK.Faces[i].mat = (byte)fs.ReadByte();
         fs.ReadByte();
         buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Faces[i].smooth = BitConverter.ToInt32(buff, 0);
     }
 }
Beispiel #7
0
 private void PSKFReadEdges(FileStream fs, PSKHeader PSKh)
 {
     PSK.Edges = new Edge[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[2];
         fs.Read(buff, 0, 2);
         PSK.Edges[i].index = BitConverter.ToInt16(buff, 0);
         fs.Read(buff, 0, 2);
         buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Edges[i].U = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Edges[i].V   = BitConverter.ToSingle(buff, 0);
         PSK.Edges[i].mat = fs.ReadByte();
         fs.ReadByte();
         fs.ReadByte();
         fs.ReadByte();
     }
 }
Beispiel #8
0
        private void ReadPSK(FileStream fileStream)
        {
            while (fileStream.Position < fileStream.Length)
            {
                PSKHeader PSKh = PSKFGetHeader(fileStream);
                switch (PSKh.name)
                {
                case "ACTRHEAD":
                    continue;

                case "PNTS0000":
                    PSKFReadPoints(fileStream, PSKh);
                    break;

                case "VTXW0000":
                    PSKFReadEdges(fileStream, PSKh);
                    break;

                case "FACE0000":
                    PSKFReadFaces(fileStream, PSKh);
                    break;

                case "MATT0000":
                    PSKFReadMats(fileStream, PSKh);
                    break;

                case "REFSKELT":
                    PSKFReadBones(fileStream, PSKh);
                    break;

                case "RAWWEIGHTS":
                    PSKFReadWeights(fileStream, PSKh);
                    break;

                default:
                    fileStream.Position = fileStream.Length;
                    break;
                }
            }
        }
Beispiel #9
0
        private PSKHeader PSKFGetHeader(FileStream fs)
        {
            PSKHeader ret = new PSKHeader();

            ret.name = "";
            byte b;

            for (int i = 0; i < 20; i++)
            {
                b = (byte)fs.ReadByte();
                if (b != 0)
                {
                    ret.name += (char)b;
                }
            }
            byte[] buff = new byte[4];
            fs.Read(buff, 0, 4);
            fs.Read(buff, 0, 4);
            ret.size = BitConverter.ToInt32(buff, 0);
            fs.Read(buff, 0, 4);
            ret.count = BitConverter.ToInt32(buff, 0);
            return(ret);
        }
Beispiel #10
0
        public PSKHeader ReadHeader(FileStream fs)
        {
            PSKHeader res = new PSKHeader();

            res.name = "";
            for (int i = 0; i < 20; i++)
            {
                byte b = (byte)fs.ReadByte();
                if (b != 0)
                {
                    res.name += (char)b;
                }
            }
            byte[] buff = new byte[4];
            fs.Read(buff, 0, 4);
            res.flags = BitConverter.ToInt32(buff, 0);
            buff      = new byte[4];
            fs.Read(buff, 0, 4);
            res.size = BitConverter.ToInt32(buff, 0);
            buff     = new byte[4];
            fs.Read(buff, 0, 4);
            res.count = BitConverter.ToInt32(buff, 0);
            return(res);
        }
Beispiel #11
0
 private PSKHeader PSKFGetHeader(FileStream fs)
 {
     PSKHeader ret = new PSKHeader();
     ret.name = "";
     byte b;
     for (int i = 0; i < 20; i++)
     {
         b = (byte)fs.ReadByte();
         if (b != 0) ret.name += (char)b;
     }
     byte[] buff = new byte[4];
     fs.Read(buff, 0, 4);
     fs.Read(buff, 0, 4);
     ret.size = BitConverter.ToInt32(buff, 0);
     fs.Read(buff, 0, 4);
     ret.count = BitConverter.ToInt32(buff, 0);
     return ret;
 }
Beispiel #12
0
 public PSKHeader ReadHeader(FileStream fs)
 {
     PSKHeader res = new PSKHeader();
     res.name = "";
     for (int i = 0; i < 20; i++)
     {
         byte b = (byte)fs.ReadByte();
         if(b!=0)
             res.name += (char)b;
     }
     byte[] buff = new byte[4];
     fs.Read(buff, 0, 4);
     res.flags = BitConverter.ToInt32(buff, 0);
     buff = new byte[4];
     fs.Read(buff, 0, 4);
     res.size = BitConverter.ToInt32(buff, 0);
     buff = new byte[4];
     fs.Read(buff, 0, 4);
     res.count = BitConverter.ToInt32(buff, 0);
     return res;
 }
Beispiel #13
0
        public void ImportPSK(string path)
        {
            psk = new PSKContainer();
            BitConverter.IsLittleEndian = true;
            FileStream pskFile = new FileStream(path, FileMode.Open, FileAccess.Read);


            do
            {
                PSKHeader h = ReadHeader(pskFile);
                byte[]    buffer;
                switch (h.name)
                {
                case "ACTRHEAD":
                    break;

                case "PNTS0000":
                {
                    #region PNTS0000
                    psk.points = new List <PSKPoint>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKPoint pskPoint = new PSKPoint();
                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskPoint.x = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        pskPoint.y = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        pskPoint.z = BitConverter.ToSingle(buffer, 0);
                        psk.points.Add(pskPoint);
                    }
                    #endregion
                }; break;

                case "VTXW0000":
                {
                    #region VTXW0000
                    psk.edges = new List <PSKEdge>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKEdge pskEdge = new PSKEdge();

                        buffer = new byte[2];
                        pskFile.Read(buffer, 0, 2);
                        pskEdge.index = BitConverter.ToInt16(buffer, 0);

                        buffer = new byte[2];
                        pskFile.Read(buffer, 0, 2);
                        pskEdge.padding1 = BitConverter.ToInt16(buffer, 0);

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskEdge.U = BitConverter.ToSingle(buffer, 0);

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskEdge.V = BitConverter.ToSingle(buffer, 0);

                        pskEdge.material = (byte)pskFile.ReadByte();

                        pskEdge.reserved = (byte)pskFile.ReadByte();

                        buffer = new byte[2];
                        pskFile.Read(buffer, 0, 2);
                        pskEdge.padding2 = BitConverter.ToInt16(buffer, 0);

                        psk.edges.Add(pskEdge);
                    }
                    #endregion
                }; break;


                case "FACE0000":
                {
                    #region FACE0000
                    psk.faces = new List <PSKFace>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKFace pskFace = new PSKFace();
                        buffer = new byte[2];
                        pskFile.Read(buffer, 0, 2);
                        pskFace.v0 = BitConverter.ToInt16(buffer, 0);

                        buffer = new byte[2];
                        pskFile.Read(buffer, 0, 2);
                        pskFace.v1 = BitConverter.ToInt16(buffer, 0);

                        buffer = new byte[2];
                        pskFile.Read(buffer, 0, 2);
                        pskFace.v2 = BitConverter.ToInt16(buffer, 0);

                        pskFace.material = (byte)pskFile.ReadByte();

                        pskFace.auxmaterial = (byte)pskFile.ReadByte();

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskFace.smoothgroup = BitConverter.ToInt32(buffer, 0);

                        psk.faces.Add(pskFace);
                    }
                    #endregion
                }; break;

                case "MATT0000":
                {
                    #region MATT0000
                    psk.materials = new List <PSKMaterial>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKMaterial pskMaterial = new PSKMaterial();
                        buffer = new byte[64];
                        pskFile.Read(buffer, 0, 64);

                        pskMaterial.name = "";
                        for (int j = 0; j < 64; j++)
                        {
                            if (buffer[j] != 0)
                            {
                                pskMaterial.name += (char)buffer[j];
                            }
                        }

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskMaterial.texture = BitConverter.ToInt32(buffer, 0);

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskMaterial.polyflags = BitConverter.ToInt32(buffer, 0);

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskMaterial.auxmaterial = BitConverter.ToInt32(buffer, 0);

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskMaterial.auxflags = BitConverter.ToInt32(buffer, 0);

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskMaterial.LODbias = BitConverter.ToInt32(buffer, 0);

                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskMaterial.LODstyle = BitConverter.ToInt32(buffer, 0);

                        psk.materials.Add(pskMaterial);
                    }

                    #endregion
                }; break;

                case "REFSKELT":
                {
                    #region REFSKELT
                    psk.bones = new List <PSKBone>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKBone b = new PSKBone();
                        buffer = new byte[64];
                        pskFile.Read(buffer, 0, 64);
                        b.name = "";
                        for (int j = 0; j < 64; j++)
                        {
                            if (buffer[j] != 0)
                            {
                                b.name += (char)buffer[j];
                            }
                        }
                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        pskFile.Read(buffer, 0, 4);
                        b.childs = BitConverter.ToInt32(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.parent = BitConverter.ToInt32(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.rotation.x = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.rotation.y = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.rotation.z = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.rotation.w = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.location.x = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.location.y = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        b.location.z = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        pskFile.Read(buffer, 0, 4);
                        pskFile.Read(buffer, 0, 4);
                        pskFile.Read(buffer, 0, 4);
                        psk.bones.Add(b);
                    }

                    #endregion
                }; break;

                case "RAWWEIGHTS":
                {
                    psk.weights = new List <PSKWeight>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKWeight w = new PSKWeight();
                        buffer = new byte[4];
                        pskFile.Read(buffer, 0, 4);
                        w.weight = BitConverter.ToSingle(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        w.point = BitConverter.ToInt32(buffer, 0);
                        pskFile.Read(buffer, 0, 4);
                        w.bone = BitConverter.ToInt32(buffer, 0);
                        psk.weights.Add(w);
                    }
                }; break;

                    #region The rest

                case "EXTRAUVS0":
                {
                    psk.extrauv1 = new List <PSKExtraUV>();
                    buffer       = new byte[h.size * h.count];
                    pskFile.Read(buffer, 0, h.size * h.count);

                    //buffer = new byte[4];
                    //pskFile.Read(buffer, 0, 4);


                    //float size = BitConverter.ToInt32(buffer, 0);

                    //buffer = new byte[4];
                    //pskFile.Read(buffer, 0, 4);


                    //int count = BitConverter.ToInt32(buffer, 0);

                    //for (int i = 0; i < count; i++)
                    //{
                    //    PSKExtraUV uvSet = new PSKExtraUV();
                    //    buffer = new byte[4];
                    //    pskFile.Read(buffer, 0, 4);


                    //    uvSet.U = BitConverter.ToSingle(buffer, 0);

                    //    buffer = new byte[4];
                    //    pskFile.Read(buffer, 0, 4);


                    //    uvSet.V = BitConverter.ToSingle(buffer, 0);

                    //    psk.extrauv1.Add(uvSet);
                    //}
                }; break;
                    //yeah, so much about not typing too much :p
                    //Well you wrote everything in the cases, you could have easily used functions :p
                    #endregion
                }
            } while (pskFile.Position < pskFile.Length);
        }
Beispiel #14
0
 private void PSKFReadBones(FileStream fs, PSKHeader PSKh)
 {
     PSK.Bones = new PSKBone[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         PSK.Bones[i].name = "";
         byte b;
         for (int j = 0; j < 64; j++)
         {
             b = (byte)fs.ReadByte();
             if (b != 0) PSK.Bones[i].name += (char)b;
         }
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Bones[i].flags = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].childcount = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].parent = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.z = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].orientation.w = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].position.x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].position.y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].position.z = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].length = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].size.x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].size.y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Bones[i].size.z = BitConverter.ToSingle(buff, 0);
     }
 }
Beispiel #15
0
 private void PSKFReadWeights(FileStream fs, PSKHeader PSKh)
 {
     PSK.Weights = new Weight[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Weights[i].w = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Weights[i].pointid = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Weights[i].boneid = BitConverter.ToInt32(buff, 0);
     }
 }
Beispiel #16
0
 private void PSKFReadMats(FileStream fs, PSKHeader PSKh)
 {
     PSK.Mats = new Material[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         PSK.Mats[i].name = "";
         byte b;
         for (int j = 0; j < 64; j++)
         {
             b = (byte)fs.ReadByte();
             if (b != 0) PSK.Mats[i].name += (char)b;
         }
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Mats[i].texid = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].flags = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].matid = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].matflags = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].LODBias = BitConverter.ToInt32(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Mats[i].LODStyle = BitConverter.ToInt32(buff, 0);
     }
 }
Beispiel #17
0
 private void PSKFReadFaces(FileStream fs, PSKHeader PSKh)
 {
     PSK.Faces = new Face[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[2];
         fs.Read(buff, 0, 2);
         PSK.Faces[i].e0 = BitConverter.ToUInt16(buff, 0);
         fs.Read(buff, 0, 2);
         PSK.Faces[i].e1 = BitConverter.ToUInt16(buff, 0);
         fs.Read(buff, 0, 2);
         PSK.Faces[i].e2 = BitConverter.ToUInt16(buff, 0);
         PSK.Faces[i].mat = (byte)fs.ReadByte();
         fs.ReadByte();
         buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Faces[i].smooth = BitConverter.ToInt32(buff, 0);
     }
 }
Beispiel #18
0
 private void PSKFReadEdges(FileStream fs, PSKHeader PSKh)
 {
     PSK.Edges = new Edge[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[2];
         fs.Read(buff, 0, 2);
         PSK.Edges[i].index = BitConverter.ToInt16(buff, 0);
         fs.Read(buff, 0, 2);
         buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Edges[i].U = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Edges[i].V = BitConverter.ToSingle(buff, 0);
         PSK.Edges[i].mat = fs.ReadByte();
         fs.ReadByte();
         fs.ReadByte();
         fs.ReadByte();
     }
 }
Beispiel #19
0
 private void PSKFReadPoints(FileStream fs, PSKHeader PSKh)
 {
     PSK.Points = new Vector[PSKh.count];
     for (int i = 0; i < PSKh.count; i++)
     {
         byte[] buff = new byte[4];
         fs.Read(buff, 0, 4);
         PSK.Points[i].x = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Points[i].y = BitConverter.ToSingle(buff, 0);
         fs.Read(buff, 0, 4);
         PSK.Points[i].z = BitConverter.ToSingle(buff, 0);
     }
 }
Beispiel #20
0
        public PSKFile(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);

            while (fs.Position < fs.Length)
            {
                PSKHeader h = ReadHeader(fs);
                switch (h.name)
                {
                case "PNTS0000":
                {
                    points = new List <PSKPoint>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKPoint pskPoint = new PSKPoint();
                        pskPoint.x = Helpers.ReadFloat(fs);
                        pskPoint.z = Helpers.ReadFloat(fs);
                        pskPoint.y = Helpers.ReadFloat(fs);
                        points.Add(pskPoint);
                    }
                }; break;

                case "VTXW0000":
                {
                    edges = new List <PSKEdge>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKEdge pskEdge = new PSKEdge();
                        pskEdge.index = Helpers.ReadUShort(fs);
                        Helpers.ReadUShort(fs);
                        pskEdge.U        = Helpers.ReadFloat(fs);
                        pskEdge.V        = Helpers.ReadFloat(fs);
                        pskEdge.material = (byte)fs.ReadByte();
                        fs.ReadByte();
                        Helpers.ReadUShort(fs);
                        edges.Add(pskEdge);
                    }
                }; break;

                case "FACE0000":
                {
                    faces = new List <PSKFace>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKFace pskFace = new PSKFace(Helpers.ReadUShort(fs), Helpers.ReadUShort(fs), Helpers.ReadUShort(fs), (byte)fs.ReadByte());
                        fs.ReadByte();
                        Helpers.ReadInt(fs);
                        faces.Add(pskFace);
                    }
                }; break;

                case "MATT0000":
                {
                    materials = new List <PSKMaterial>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKMaterial pskMaterial = new PSKMaterial();
                        pskMaterial.name    = ReadFixedString(fs, 64);
                        pskMaterial.texture = Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        materials.Add(pskMaterial);
                    }
                }; break;

                case "REFSKELT":
                {
                    bones = new List <PSKBone>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKBone b = new PSKBone();
                        b.name = ReadFixedString(fs, 64);
                        Helpers.ReadInt(fs);
                        b.childs     = Helpers.ReadInt(fs);
                        b.parent     = Helpers.ReadInt(fs);
                        b.rotation.x = Helpers.ReadFloat(fs);
                        b.rotation.z = Helpers.ReadFloat(fs);
                        b.rotation.y = Helpers.ReadFloat(fs);
                        b.rotation.w = Helpers.ReadFloat(fs);
                        b.location.x = Helpers.ReadFloat(fs);
                        b.location.z = Helpers.ReadFloat(fs);
                        b.location.y = Helpers.ReadFloat(fs);
                        Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        Helpers.ReadInt(fs);
                        bones.Add(b);
                    }
                }; break;

                case "RAWWEIGHTS":
                {
                    weights = new List <PSKWeight>();
                    for (int i = 0; i < h.count; i++)
                    {
                        PSKWeight w = new PSKWeight(Helpers.ReadFloat(fs), Helpers.ReadInt(fs), Helpers.ReadInt(fs));
                        weights.Add(w);
                    }
                }; break;

                default:
                    fs.Seek(h.size * h.count, SeekOrigin.Current);
                    break;
                }
            }
            fs.Close();
        }