//---------------------------------------------------------------------------------------------------------

    public MD2Frame[] GetAllFrames()
    {
        MD2Frame[] frames = new MD2Frame[GetFramesNo()];

        for (int frameNumber = 0; frameNumber < frames.Length; frameNumber++)
        {
            frames[frameNumber] = GetFrame(frameNumber);
        }

        return(frames);
    }
    //---------------------------------------------------------------------------------------------------------

    public unsafe MD2Frame GetFrame(int frameNumber)
    {
        MD2Frame frame = new MD2Frame();

        frame.Vertices = ExtractVerticesFromFrame(frameNumber);
        frame.Normals  = ExtractNormalsFromFrame(frameNumber);
        frame.UVs      = ExtractSTsFromFile();
        frame.Triagles = ExtractAllTringles();
        frame.Name     = ExtractNameFromFrame(frameNumber);
        return(frame);
    }
Ejemplo n.º 3
0
    //---------------------------------------------------------------------------------------------------------

    private unsafe Mesh ConvertFrameToMesh(MD2Frame frame)
    {
        List <Vector3> newVertices  = new List <Vector3>();
        List <Vector3> newNormals   = new List <Vector3>();
        List <Vector2> newUVs       = new List <Vector2>();
        List <int>     newTriangles = new List <int>();

        for (int t = 0; t < frame.Triagles.Length; t++)
        {
            MD2Triangle triagle = frame.Triagles[t];

            for (int i = 0; i < 3; i++)
            {
                Vector3 vertex = frame.Vertices[triagle.index_xyz[i]];
                Vector3 normal = frame.Normals[triagle.index_xyz[i]];
                Vector2 uv     = frame.UVs[triagle.index_st[i]];

                bool doesExistsSuchVertex = false;
                int  index = 0;

                for (index = 0; index < newVertices.Count; index++)
                {
                    if (newVertices[index] == vertex && newUVs[index] == uv && newNormals[index] == normal)
                    {
                        doesExistsSuchVertex = true;
                        break;
                    }
                }

                newTriangles.Add(index);

                if (doesExistsSuchVertex == false)
                {
                    newVertices.Add(vertex);
                    newNormals.Add(normal);
                    newUVs.Add(uv);
                }
            }
        }

        Mesh mesh = new Mesh();

        mesh.Clear();
        mesh.vertices  = newVertices.ToArray();
        mesh.normals   = newNormals.ToArray();
        mesh.uv        = newUVs.ToArray();
        mesh.triangles = newTriangles.ToArray();
        mesh.RecalculateBounds();
        mesh.name = frame.Name;

        return(mesh);
    }