.[ ČeskéHry.cz ].
Mesh subsets

 
odeslat nové téma   Odpovědět na téma    Obsah fóra České-Hry.cz -> 3D API / 3D Enginy
Zobrazit předchozí téma :: Zobrazit následující téma  
Autor Zpráva
KuboSVK



Založen: 13. 03. 2008
Příspěvky: 40

PříspěvekZaslal: 20. březen 2008, 20:52:28    Předmět: Mesh subsets Odpovědět s citátem

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 ?
Návrat nahoru
Zobrazit informace o autorovi Odeslat soukromou zprávu Odeslat e-mail
Zobrazit příspěvky z předchozích:   
odeslat nové téma   Odpovědět na téma    Obsah fóra České-Hry.cz -> 3D API / 3D Enginy Časy uváděny v GMT + 1 hodina
Strana 1 z 1

 
Přejdi na:  
Nemůžete odesílat nové téma do tohoto fóra
Nemůžete odpovídat na témata v tomto fóru
Nemůžete upravovat své příspěvky v tomto fóru
Nemůžete mazat své příspěvky v tomto fóru
Nemůžete hlasovat v tomto fóru


Powered by phpBB © 2001, 2005 phpBB Group


Vzhled udelal powermac
Styl "vykraden" z phpBB stylu MonkiDream - upraveno by rezna