예제 #1
0
 public static void ConvertPSKto3DS(PSKFile f, string path)
 {
     Lib3dsFile res = EmptyFile();
     AddMeshTo3DS(res, f, Matrix.Identity);
     ClearFirstMesh(res);
     if (!LIB3DS.lib3ds_file_save(res, path))
         MessageBox.Show("Error!");
 }
예제 #2
0
        public static void AddMeshTo3DS(Lib3dsFile res, PSKFile f, Matrix m)
        {
            Lib3dsMesh mesh = new Lib3dsMesh();
            string     name = "Box00" + res.meshes.Count;

            mesh.name     = name;
            mesh.matrix   = Matrix2FA(Matrix.Identity);
            mesh.vertices = new List <Lib3dsVertex>();
            foreach (PSKFile.PSKPoint p in f.psk.points)
            {
                Vector3 v = p.ToVector3();
                v = Vector3.TransformCoordinate(v, m);
                mesh.vertices.Add(new Lib3dsVertex(v.X, -v.Y, v.Z));
            }
            mesh.texcos = new List <Lib3dsTexturecoordinate>();
            for (int i = 0; i < f.psk.points.Count; i++)
            {
                foreach (PSKFile.PSKEdge e in f.psk.edges)
                {
                    if (e.index == i)
                    {
                        mesh.texcos.Add(new Lib3dsTexturecoordinate(e.U, e.V));
                    }
                }
            }
            mesh.faces = new List <Lib3dsFace>();
            foreach (PSKFile.PSKFace face in f.psk.faces)
            {
                Lib3dsFace ff = new Lib3dsFace();
                ff.flags    = 6;
                ff.index    = new ushort[3];
                ff.index[0] = (ushort)f.psk.edges[face.v0].index;
                ff.index[1] = (ushort)f.psk.edges[face.v2].index;
                ff.index[2] = (ushort)f.psk.edges[face.v1].index;
                mesh.faces.Add(ff);
            }
            mesh.nfaces       = (ushort)mesh.faces.Count;
            mesh.nvertices    = (ushort)mesh.vertices.Count;
            mesh.map_type     = Lib3dsMapType.LIB3DS_MAP_NONE;
            mesh.object_flags = 0;
            mesh.color        = 128;
            res.meshes.Add(mesh);
            Lib3dsNode node = new Lib3dsMeshInstanceNode();

            node.matrixNode = Matrix2FA(Matrix.Identity);
            node.parent     = null;
            node.parent_id  = 0xffff;
            node.hasNodeID  = true;
            node.type       = Lib3dsNodeType.LIB3DS_NODE_MESH_INSTANCE;
            node.flags      = res.nodes[0].flags;
            node.node_id    = (ushort)(res.meshes.Count() - 1);
            node.name       = name;
            res.nodes.Add(node);
        }
예제 #3
0
        public static void ConvertPSKto3DS(PSKFile f, string path)
        {
            Lib3dsFile res = EmptyFile();

            AddMeshTo3DS(res, f, Matrix.Identity);
            ClearFirstMesh(res);
            if (!LIB3DS.lib3ds_file_save(res, path))
            {
                MessageBox.Show("Error!");
            }
        }
예제 #4
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog d = new OpenFileDialog();
     d.Filter = "*.psk|*.psk;*.pskx";
     if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string path = d.FileName;
         psk = new PSKFile();
         psk.ImportPSK(path);
         CurrFile = path;
         RefreshTree();
     }
 }
예제 #5
0
 public static void AddMeshTo3DS(Lib3dsFile res, PSKFile f, Matrix m)
 {
     Lib3dsMesh mesh = new Lib3dsMesh();
     string name =  "Box00" + res.meshes.Count.ToString();
     mesh.name = name;
     mesh.matrix = Matrix2FA(Matrix.Identity);
     mesh.vertices = new List<Lib3dsVertex>();
     foreach (PSKFile.PSKPoint p in f.psk.points)
     {
         Vector3 v = p.ToVector3();
         v = Vector3.TransformCoordinate(v, m);
         mesh.vertices.Add(new Lib3dsVertex(v.X, -v.Y, v.Z));
     }
     mesh.texcos = new List<Lib3dsTexturecoordinate>();
     for (int i = 0; i < f.psk.points.Count; i++)
         foreach (PSKFile.PSKEdge e in f.psk.edges)
             if (e.index == i)
                 mesh.texcos.Add(new Lib3dsTexturecoordinate(e.U, e.V));
     mesh.faces = new List<Lib3dsFace>();
     foreach (PSKFile.PSKFace face in f.psk.faces)
     {
         Lib3dsFace ff = new Lib3dsFace();
         ff.flags = 6;
         ff.index = new ushort[3];
         ff.index[0] = (ushort)f.psk.edges[face.v0].index;
         ff.index[1] = (ushort)f.psk.edges[face.v2].index;
         ff.index[2] = (ushort)f.psk.edges[face.v1].index;
         mesh.faces.Add(ff);
     }
     mesh.nfaces = (ushort)mesh.faces.Count;
     mesh.nvertices = (ushort)mesh.vertices.Count;
     mesh.map_type = Lib3dsMapType.LIB3DS_MAP_NONE;
     mesh.object_flags = 0;
     mesh.color = 128;
     res.meshes.Add(mesh);
     Lib3dsNode node = new Lib3dsMeshInstanceNode();
     node.matrixNode = Matrix2FA(Matrix.Identity);
     node.parent = null;
     node.parent_id = 0xffff;
     node.hasNodeID = true;
     node.type = Lib3dsNodeType.LIB3DS_NODE_MESH_INSTANCE;
     node.flags = res.nodes[0].flags;
     node.node_id = (ushort)(res.meshes.Count() - 1);
     node.name = name;            
     res.nodes.Add(node);
 }
예제 #6
0
        public void ImportFromPsk(string path)
        {
            psk = new PSKFile();
            psk.ImportPSK(path);
#region Vertices
            Mesh.Vertices = new Verts();
            Mesh.Vertices.Points = new List<Vector3>();
            for (int i = 0; i < psk.psk.edges.Count; i++)
            {
                int idx = psk.psk.edges[i].index;
                float valueX = psk.psk.points[idx].x;
                float valueY = psk.psk.points[idx].y;
                float valueZ = psk.psk.points[idx].z;
                Mesh.Vertices.Points.Add(new Vector3(valueX, valueY, valueZ));

            }
            Mesh.Buffers.IndexBuffer = Mesh.Vertices.Points.Count();
            byte[] buff = BitConverter.GetBytes((int)Mesh.Vertices.Points.Count());
            for (int i = 0; i < 4; i++)
                Mesh.UnknownPart.data[24 + i] = buff[i];
            #endregion
#region materials
            Lod l = Mesh.Mat.Lods[0];
            l.Sections = new List<Section>();
            for (int i = 0; i < psk.psk.faces.Count; i++)
            {
                PSKFile.PSKFace e = psk.psk.faces[i];
                int mat = e.material;
                
                if (mat >= l.Sections.Count())
                {
                    int min = i * 3;
                    int minv = e.v0;
                    if (e.v1 < minv)
                        minv = e.v1;
                    if (e.v2 < minv)
                        minv = e.v2;
                    int maxv = e.v0;
                    if (e.v1 > maxv)
                        maxv = e.v1;
                    if (e.v2 > maxv)
                        maxv = e.v2;
                    Section s = new Section();
                    s.FirstIdx1 = min;
                    s.FirstIdx2 = min;
                    s.NumFaces1 = 1;
                    s.NumFaces2 = 1;
                    s.MatEff1 = minv;
                    s.MatEff2 = maxv;
                    s.Unk1 = 1;
                    s.Unk2 = 1;
                    s.Unk3 = 1;
                    s.Unk4 = 0;
                    s.Unk5 = 1;
                    s.Unk6 = 0;
                    l.Sections.Add(s);
                }
                else
                {
                    Section s = l.Sections[mat];
                    int min = s.FirstIdx1 / 3;
                    int max = s.NumFaces1;
                    int minv = s.MatEff1;
                    if (e.v1 < minv)
                        minv = e.v1;
                    if (e.v2 < minv)
                        minv = e.v2;
                    int maxv = s.MatEff2;
                    if (e.v1 > maxv)
                        maxv = e.v1;
                    if (e.v2 > maxv)
                        maxv = e.v2;
                    if (i - s.FirstIdx1 / 3  + 1> max)
                        max = i - s.FirstIdx1 / 3 + 1;
                    if (i < min)
                        min = i;
                    s.FirstIdx1 = min * 3;
                    s.FirstIdx2 = min * 3;
                    s.NumFaces1 = max;
                    s.NumFaces2 = max;
                    s.MatEff1 = minv;
                    s.MatEff2 = maxv;
                    l.Sections[mat] = s;
                }
            }
            l.SectionCount = l.Sections.Count();
            for (int i = 0; i < l.SectionCount; i++)
            {
                Select_Material selm = new Select_Material();
                selm.hasSelected = false;
                selm.listBox1.Items.Clear();
                selm.Objects = new List<int>();
                for(int j =0;j<pcc.Exports.Count;j++)
                {
                    PCCObject.ExportEntry e =pcc.Exports[j];
                    if (e.ClassName == "Material" || e.ClassName == "MaterialInstanceConstant")
                    {
                        selm.listBox1.Items.Add(j + "\t" + e.ClassName + " : " + e.ObjectName);
                        selm.Objects.Add(j);
                    }
                }
                selm.Show();
                while (selm != null && !selm.hasSelected)
                {
                    Application.DoEvents();
                }
                Section s = l.Sections[i];
                s.Name = selm.SelIndex + 1;
                l.Sections[i] = s;
                selm.Close();
            }
            l.NumVert = psk.psk.points.Count();
            Mesh.Mat.Lods[0] = l;
#endregion
#region Edges
            int oldcount = Mesh.Edges.UVSet[0].UVs.Count();
            Mesh.Buffers.UV1 = oldcount;
            Mesh.Buffers.UV2 = oldcount * 4 + 8;
            Mesh.Edges = new Edges();
            Mesh.Edges.UVSet = new List<UVSet>();
            for (int i = 0; i < psk.psk.edges.Count; i++)
            {
                UVSet newSet = new UVSet();
                newSet.UVs = new List<Vector2>();
                for (int j = 0; j < oldcount; j++)
                    newSet.UVs.Add(new Vector2(psk.psk.edges[i].U, psk.psk.edges[i].V));
                newSet.x1 = 0;
                newSet.x2 = 0;
                newSet.y1 = 0;
                newSet.y2 = 0;
                newSet.z1 = 0;
                newSet.z2 = 0;
                newSet.w1 = 0;
                newSet.w2 = 0;
                Mesh.Edges.UVSet.Add(newSet);
            }            
            Mesh.Edges.count = psk.psk.edges.Count;
            Mesh.Edges.size = 8 + 4 * oldcount;
#endregion
#region Faces
            Mesh.RawTris.RawTriangles = new List<RawTriangle>();
            bool WithIndex = (Mesh.IdxBuf.Indexes.Count != 0);
            if (WithIndex)
                Mesh.IdxBuf.Indexes = new List<ushort>();
            for (int i = 0; i < psk.psk.faces.Count; i++)
            {
                RawTriangle r = new RawTriangle();
                PSKFile.PSKFace f = psk.psk.faces[i];
                r.v0 = (Int16)f.v0;
                r.v1 = (Int16)f.v1;
                r.v2 = (Int16)f.v2;
                r.mat = f.material;
                Mesh.RawTris.RawTriangles.Add(r);
                if (WithIndex)
                {
                    Mesh.IdxBuf.Indexes.Add((UInt16)f.v0);
                    Mesh.IdxBuf.Indexes.Add((UInt16)f.v1);
                    Mesh.IdxBuf.Indexes.Add((UInt16)f.v2);
                    Mesh.IdxBuf.count = Mesh.IdxBuf.Indexes.Count();
                }               
            }
            CalcTangentSpace();
#endregion
            RecalculateBoundings();
            GenerateMesh();

        }
예제 #7
0
        public PSKFile ExportToPsk()
        {
            PSKFile psk = new PSKFile();
            PSKFile.PSKContainer pskc = new PSKFile.PSKContainer();
            pskc.points = new List<PSKFile.PSKPoint>();
            foreach (Vector3 v in Mesh.Vertices.Points)
                pskc.points.Add(new PSKFile.PSKPoint(v));
            pskc.edges = new List<PSKFile.PSKEdge>();
            for (int i = 0; i < Mesh.Edges.UVSet.Count(); i++)
            {
                UVSet s = Mesh.Edges.UVSet[i];
                pskc.edges.Add(new PSKFile.PSKEdge((short)i, s.UVs[0], GetMaterial(i)));
            }
            pskc.faces = new List<PSKFile.PSKFace>();
            if (Mesh.IdxBuf.Indexes != null && Mesh.IdxBuf.Indexes.Count() != 0)
            {
                for (int i = 0; i < Mesh.IdxBuf.Indexes.Count() / 3; i++)
                {
                    int v0 = Mesh.IdxBuf.Indexes[i * 3];
                    int v1 = Mesh.IdxBuf.Indexes[i * 3 + 1];
                    int v2 = Mesh.IdxBuf.Indexes[i * 3 + 2];
                    byte material = GetMaterial(i * 3);
                    pskc.faces.Add(new PSKFile.PSKFace(v0, v1, v2, material));
                    PSKFile.PSKEdge e = pskc.edges[v0];
                    e.material = material;
                    pskc.edges[v0] = e;
                    e = pskc.edges[v1];
                    e.material = material;
                    pskc.edges[v1] = e;
                    e = pskc.edges[v2];
                    e.material = material;
                    pskc.edges[v2] = e;
                }
            }

            {
                for (int i = 0; i < Mesh.RawTris.RawTriangles.Count(); i++)
                {
                    RawTriangle r = Mesh.RawTris.RawTriangles[i];
                    byte material = GetMaterial(i * 3);
                    pskc.faces.Add(new PSKFile.PSKFace(r.v0, r.v1, r.v2, material));
                    PSKFile.PSKEdge e = pskc.edges[r.v0];
                    e.material = material;
                    pskc.edges[r.v0] = e;
                    e = pskc.edges[r.v1];
                    e.material = material;
                    pskc.edges[r.v1] = e;
                    e = pskc.edges[r.v2];
                    e.material = material;
                    pskc.edges[r.v2] = e;
                }
            }
            pskc.materials = new List<PSKFile.PSKMaterial>();
            foreach (Section s in Mesh.Mat.Lods[0].Sections)
                pskc.materials.Add(new PSKFile.PSKMaterial(pcc.getObjectName(s.Name), 0));
            pskc.bones = new List<PSKFile.PSKBone>();
            pskc.weights = new List<PSKFile.PSKWeight>();
            psk = new PSKFile();
            psk.psk = pskc;
            return psk;
        }
예제 #8
0
 public Vector3[] ToVec3(PSKFile.PSKPoint[] points)
 {
     Vector3[] v = new Vector3[points.Count()];
     int count = 0;
     foreach (PSKFile.PSKPoint p in points)
     {
         v[count] = new Vector3(p.x, p.y, p.z);
         count++;
     }
     return v;
 }
예제 #9
0
 public Vector3 ToVec3(PSKFile.PSKPoint p)
 {
     return new Vector3(p.x, p.y, p.z);
 }