Mesh Data

The first part of our memblock contains some information about the mesh. It consists of 6 integers in this order:

  1. Bytes 0-3: Vertex count. This integer holds the number of vertices in the mesh. In our example, this would be set to 3
  2. Bytes 4-7: Index count. This integer holds the number of indices in the mesh. If it holds a 0, then every 3 vertices will make a triangle and no vertex will be shared with another triangle. If you have 1 or more here, then the indices define which vertices create each triangle. Our simple example doesn't need an index list, but I am including one in this tutorial so you can understand how it works.
  3. Bytes 8-11: Attribute count. This integer contains the number of attributes defining our vertices. There are 9 predefined attributes in AGK2. Our example uses 3; position, normal, and color.
  4. Bytes 12-15: Number of bytes per vertex: This can be calculated from the attributes, but is here for convenience. Our example uses 12 bytes for position, 12 bytes for normal, and 4 bytes for color totalling 28 bytes
  5. Bytes 16-19: Offset to vertex data. This integer points to the first byte of our vertex data.
  6. Bytes 20-23: Offset to index data. This integer points to the first byte of the index data

We will use the SetMemblockInt()command to write our data to the memblock. Just add these lines after the CreateMemblock() line we added earlier

//Now we need to fill it with mesh data
SetMemblockInt(memblock,0,3) //3 vertices
SetMemblockInt(memblock,4,3) //3 indices, not necissary for simple triangle, but we do it here for completeness
SetMemblockint(memblock,8,3) //Our mesh has 3 attributes, position, normal, color
Setmemblockint(memblock,12,28) //number of bytes each vertext takes up. x,y,z,nx,ny,nz,color * 4
SetMemblockInt(memblock,16,64) //offset to vertex data
SetMemblockInt(memblock,20,148) //offset to index data

Created with Tutorial Markup (c)2018 James Chamblin