예제 #1
0
        public void ImportPSK(string path)
        {
            psk = new PSKContainer();
            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);
        }
예제 #2
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);
        }
예제 #3
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();
        }