示例#1
0
    private void LoadMesh()
    {
        foreach (var meshFilter in m_Meshes)
        {
            Mesh          mesh     = meshFilter.mesh;
            ModelProperty property = meshFilter.GetComponent <ModelProperty>();

            int VBO = m_Rasterizer.GenVertexBuffer();
            int IBO = m_Rasterizer.GenIndexBuffer();
            m_Rasterizer.BindVertexBuffer(VBO);
            m_Rasterizer.BindIndexBuffer(IBO);

            Vector3[] vertices = mesh.vertices;
            int[]     indices  = mesh.triangles;
            Vector2[] uvs      = mesh.uv;
            Vector3[] normals  = mesh.normals;
            Vector4[] tangents = mesh.tangents;
            Color[]   colors   = mesh.colors;


            Vertex[] myVertices = new Vertex[vertices.Length];
            if (colors.Length > 0)
            {
                for (int i = 0; i < myVertices.Length; i++)
                {
                    myVertices[i] = new Vertex(vertices[i], uvs[i], normals[i], tangents[i], colors[i]);
                }
            }
            else
            {
                for (int i = 0; i < myVertices.Length; i++)
                {
                    myVertices[i] = new Vertex(vertices[i], uvs[i], normals[i], tangents[i], property.color);
                }
            }

            m_Rasterizer.SetVertexBufferData(myVertices);
            m_Rasterizer.SetIndexBufferData(indices);
            m_Rasterizer.UnBindVertexBuffer();
            m_Rasterizer.UnBindIndexBuffer();

            m_Models.Add(new BufferMeshMap(VBO, IBO, meshFilter, property));
        }
    }