1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
using System;
using System.Collections.Generic;
using System.Text;
namespace Examples.Shapes
{
public class Chunk
{
public VertexT2dN3dV3d[] Vertices;
public uint[] Indices;
public uint VertexCount
{
get
{
return (uint)Vertices.Length;
}
}
public uint IndexCount
{
get
{
return (uint)Indices.Length;
}
}
public Chunk( uint vertexcount, uint indexcount )
{
Vertices = new VertexT2dN3dV3d[vertexcount];
Indices = new uint[indexcount];
}
public Chunk( ref VertexT2dN3dV3d[] vbo, ref uint[] ibo )
{
Vertices = new VertexT2dN3dV3d[vbo.Length];
for ( int i = 0; i < Vertices.Length; i++ )
{
Vertices[i] = vbo[i];
}
Indices = new uint[ibo.Length];
for ( int i = 0; i < Indices.Length; i++ )
{
Indices[i] = ibo[i];
}
}
public static void GetArray( ref List<Chunk> c, out VertexT2dN3dV3d[] vbo, out uint[] ibo )
{
uint VertexCounter = 0;
uint IndexCounter = 0;
foreach ( Chunk ch in c )
{
VertexCounter += ch.VertexCount;
IndexCounter += ch.IndexCount;
}
vbo = new VertexT2dN3dV3d[VertexCounter];
ibo = new uint[IndexCounter];
VertexCounter = 0;
IndexCounter = 0;
foreach ( Chunk ch in c )
{
for ( int i = 0; i < ch.Vertices.Length; i++ )
{
vbo[VertexCounter + i] = ch.Vertices[i];
}
for ( int i = 0; i < ch.Indices.Length; i++ )
{
ibo[IndexCounter + i] = ch.Indices[i] + VertexCounter;
}
VertexCounter += (uint)ch.VertexCount;
IndexCounter += (uint)ch.IndexCount;
}
}
}
}
|