KuboSVK
Založen: 13. 03. 2008 Příspěvky: 40
|
Zaslal: 20. březen 2008, 20:52:28 Předmět: Mesh subsets |
|
|
Zdar,
vytvoril som si Mesh kocky:
public static Mesh Cube(Device device)
{
short[] indices = {
0,1,2, //Left Face
2,3,0, //Left Face
4,5,6, //Top Face
6,7,4, //Top Face
8,9,10, //Right Face
10,11,8, //Right Face
12,13,14, //Bottom Face
14,15,12, //Bottom Face
16,17,18, //Back Face
18,19,16, //Back Face
20,21,22, //Front Face
22,23,20 //Fornt Face
};
Mesh cube = new Mesh(indices.Length / 3, 24, MeshFlags.SystemMemory, VertexFormats.PositionNormal, device);
VertexBuffer vertexBuffer = cube.VertexBuffer;
GraphicsStream graphicStream = vertexBuffer.Lock(0, 0, LockFlags.None);
//back wall of the cube
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(-1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(-1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(-1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, 1.0f, -1.0f), new Vector3(-1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, 1.0f, -1.0f), new Vector3(0.0f, 1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, 1.0f, -1.0f), new Vector3(0.0f, 1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, 1.0f, -1.0f), new Vector3(1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, -1.0f, -1.0f), new Vector3(1.0f, 0.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(0.0f, -1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, -1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, -1.0f, -1.0f), new Vector3(0.0f, -1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0.0f, -1.0f, 0.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 1.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 1.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 1.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 1.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, -1.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(-1.0f, 1.0f, -1.0f), new Vector3(0.0f, 0.0f, -1.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, 1.0f, -1.0f), new Vector3(0.0f, 0.0f, -1.0f)));
graphicStream.Write(new CustomVertex.PositionNormal(new Vector3(1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, -1.0f)));
vertexBuffer.Unlock();
IndexBuffer indexBuffer = cube.IndexBuffer;
indexBuffer.SetData(indices, 0, LockFlags.None);
return cube;
}
Dalej chcem definovat tzv. subsets pre funkciu Mesh.DrawSubset(int). Chcem mat 6 subsets(kazda strana kocky)
Zaujimalo by ma, ci nasledujuci kod je spravny pre definovanie subsets v Meshi kocky:
// Set attribute buffer data, setting the attribute
// ID (subset #) for each face in the attribute buffer
int[] attributeBuffer = temporaryMesh.LockAttributeBufferArray(LockFlags.None);
for (int i = 0; i < 12; i++)
{
attributeBuffer[i] = i / 2;
}
temporaryMesh.UnlockAttributeBuffer();
// Updating the attribute table id done automatically
// by optimizing the mesh in place
int[] adjacency = new int[12 * 3];
temporaryMesh.GenerateAdjacency(0.1f, adjacency);
temporaryMesh.OptimizeInPlace(MeshFlags.OptimizeAttributeSort, adjacency);
Dalsi moj dotaz je ten, ze ci funkcia Mesh.OptimizeInPlace() zabezpeci vytvorenie AttributeTable alebo to mam urobit ja sam ? |
|