Beispiel #1
0
        public void CreateFromContentEntity(IPackContentEntity[] __contentEntities)
        {
            if (!Disposed)
                Dispose();

            ContentMesh[] buffers = new ContentMesh[__contentEntities.Length];
            for (int i = 0; i < __contentEntities.Length; i++)
            {
                ContentMesh mesh = __contentEntities[i] as ContentMesh;
                if (mesh == null)
                    throw new Exception("wrong object in EngineMesh.CreateFromContentEntity");
                buffers[i] = mesh;
            }

            Vertex[] vertices;
            ushort[] indices;
            int indicescount = 0, verticescount = 0;
            for (int i = 0; i < buffers.Length; i++)
            {
                verticescount += buffers[i].vertices.Length;
                indicescount += buffers[i].indices.Length;

            }

            vertices = new Vertex[verticescount];
            indices = new ushort[indicescount];
            int vertexoffset = 0;
            int indexoffset = 0;
            for (int i = 0; i < buffers.Length; i++)
            {
                ContentMesh cm = buffers[i];
                int currentvert = cm.vertices.Length;
                int currentindx = cm.indices.Length;

                for (int ci = 0; ci < currentvert; ci++)
                {
                    vertices[ci + vertexoffset] = new Vertex(cm.vertices[ci].position, cm.vertices[ci].normal, cm.vertices[ci].textureCoordinate);
                    vertices[ci + vertexoffset].textureCoordinate.Y = 1.0f - vertices[ci + vertexoffset].textureCoordinate.Y;
                }

                for (int ci = 0; ci < currentindx; ci++)
                    indices[ci + indexoffset] = Convert.ToUInt16(cm.indices[ci] + vertexoffset);

                vertexoffset += currentvert;
                indexoffset += currentindx;
            }

            vertexBuffer = new VertexBuffer(MyGame.Device, typeof(Vertex), vertices.Length, BufferUsage.None);
            vertexBuffer.SetData<Vertex>(vertices);

            indexBuffer = new IndexBuffer(MyGame.Device, IndexElementSize.SixteenBits, indices.Length, BufferUsage.None);
            indexBuffer.SetData<ushort>(indices);

            Disposed = false;
        }
Beispiel #2
0
 public virtual void Unload()
 {
     _contentObject = null;
 }
Beispiel #3
0
 public void CreateFromContentEntity(IPackContentEntity[] __contentEntities)
 {
     //looks like dont need...
 }