コード例 #1
0
ファイル: PSKFile.cs プロジェクト: tirnoney/DAIToolsWV
 public PSKFile(DAILibWV.Frostbite.Mesh m)
 {
     psk           = new PSKContainer();
     psk.materials = new List <PSKMaterial>();
     psk.points    = new List <PSKPoint>();
     psk.edges     = new List <PSKEdge>();
     psk.faces     = new List <PSKFace>();
     psk.bones     = new List <PSKBone>();
     psk.weights   = new List <PSKWeight>();
     psk.extrauv1  = new List <PSKExtraUV>();
     psk.extrauv2  = new List <PSKExtraUV>();
     psk.extrauv3  = new List <PSKExtraUV>();
     DAILibWV.Frostbite.Mesh.MeshLOD l = null;
     foreach (DAILibWV.Frostbite.Mesh.MeshLOD lod in m.header.LODs)
     {
         if (l == null)
         {
             foreach (DAILibWV.Frostbite.Mesh.MeshSection sec in lod.Sections)
             {
                 if (sec.VertexBuffer.Count != 0)
                 {
                     l = lod;
                     break;
                 }
             }
         }
     }
     if (l != null)
     {
         int  pointcount = 0;
         byte count      = 0;
         foreach (DAILibWV.Frostbite.Mesh.MeshSection sec in l.Sections)
         {
             psk.materials.Add(new PSKMaterial("Material" + count.ToString("d2"), count));
             int index = 0;
             foreach (DAILibWV.Frostbite.Mesh.Vertex v in sec.VertexBuffer)
             {
                 psk.points.Add(new PSKPoint(v.Position.x, v.Position.y, v.Position.z));
                 psk.edges.Add(new PSKEdge((short)(pointcount + index++), v.TexCoords.x, v.TexCoords.y, count));
             }
             foreach (DAILibWV.Frostbite.Mesh.Triangle t in sec.IndexBuffer)
             {
                 psk.faces.Add(new PSKFace(pointcount + t.i1, pointcount + t.i0, pointcount + t.i2, count));
             }
             pointcount += sec.VertexBuffer.Count;
             count++;
         }
     }
 }
コード例 #2
0
ファイル: PSKFile.cs プロジェクト: tirnoney/DAIToolsWV
 public PSKFile(DAILibWV.Frostbite.Mesh m)
 {
     psk = new PSKContainer();
     psk.materials = new List<PSKMaterial>();
     psk.points = new List<PSKPoint>();
     psk.edges = new List<PSKEdge>();
     psk.faces = new List<PSKFace>();
     psk.bones = new List<PSKBone>();
     psk.weights = new List<PSKWeight>();
     psk.extrauv1 = new List<PSKExtraUV>();
     psk.extrauv2 = new List<PSKExtraUV>();
     psk.extrauv3 = new List<PSKExtraUV>();
     DAILibWV.Frostbite.Mesh.MeshLOD l = null;
     foreach (DAILibWV.Frostbite.Mesh.MeshLOD lod in m.header.LODs)
         if(l == null)
         foreach(DAILibWV.Frostbite.Mesh.MeshSection sec in lod.Sections)
             if (sec.VertexBuffer.Count != 0)
             {
                 l = lod;
                 break;
             }
     if (l != null)
     {
         int pointcount = 0;
         byte count = 0;
         foreach (DAILibWV.Frostbite.Mesh.MeshSection sec in l.Sections)
         {
             psk.materials.Add(new PSKMaterial("Material" + count.ToString("d2"), count));
             int index = 0;
             foreach (DAILibWV.Frostbite.Mesh.Vertex v in sec.VertexBuffer)
             {
                 psk.points.Add(new PSKPoint(v.Position.x, v.Position.y, v.Position.z));
                 psk.edges.Add(new PSKEdge((short)(pointcount + index++), v.TexCoords.x, v.TexCoords.y, count));
             }
             foreach (DAILibWV.Frostbite.Mesh.Triangle t in sec.IndexBuffer)
                 psk.faces.Add(new PSKFace(pointcount + t.i1, pointcount + t.i0, pointcount + t.i2, count));
             pointcount += sec.VertexBuffer.Count;
             count++;
         }
     }
 }
コード例 #3
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);
        }
コード例 #4
0
ファイル: PSKFile.cs プロジェクト: tirnoney/DAIToolsWV
        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);
        }