Comment faire s'il vous plait?
J'ai cherche sur le net mais j ai pas trouvé..
...
int size;
VertexBuffer hmBuff; // buffer de vertex de la hm
IndexBuffer hmIndex; // buffer des index de la hm
int[] indices; // tableau contenant les indices des faces
void CreateStuff()
{
size = 256; //taille de la texture
int[] data = new int[(size*size)];
data = (int[])hm_tex.LockRectangle(typeof(int), 0, LockFlags.ReadOnly, (size * size));
hmBuff = new VertexBuffer(typeof(CustomVertex.PositionColored), size * size, _device, Usage.None, CustomVertex.PositionColored.Format, Pool.Default);
CustomVertex.PositionColored[] hmVert = new CustomVertex.PositionColored[size * size];
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
Color color = Color.FromArgb(data[(x * size) + y]);
hmVert[(x * size) + y] = new CustomVertex.PositionColored();
hmVert[(x * size) + y].Position = new Vector3(x * 2 - size, (int)(color.R * 2), y * 2 - size);
hmVert[(x * size) + y].Color = color.ToArgb();
}
}
hm_tex.UnlockRectangle(0);
hmBuff.SetData(hmVert, 0, LockFlags.None);
hmIndex = new IndexBuffer(typeof(int), (size - 1) * (size - 1) * 6, _device, Usage.WriteOnly, Pool.Default);
indices = new int[(size - 1) * (size - 1) * 6];
for (int x = 0; x < size - 1; x++)
{
for (int y = 0; y < size - 1; y++)
{
indices[(x + y * (size - 1)) * 6] = (x + 1) + (y + 1) * size;
indices[(x + y * (size - 1)) * 6 + 1] = (x + 1) + y * size;
indices[(x + y * (size - 1)) * 6 + 2] = x + y * size;
indices[(x + y * (size - 1)) * 6 + 3] = (x + 1) + (y + 1) * size;
indices[(x + y * (size - 1)) * 6 + 4] = x + y * size;
indices[(x + y * (size - 1)) * 6 + 5] = x + (y + 1) * size;
}
}
hmIndex.SetData(indices, 0, LockFlags.ReadOnly);
}
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 9 invités