I have a box model in my DirectX application, stored as 8 vertices:
MyVertex vertices[] =
{
{ DirectX::XMFLOAT3( - 1.0f, + 1.0f, - 1.0f ), /*,tex coord...*/}, //0
{ DirectX::XMFLOAT3( + 1.0f, + 1.0f, - 1.0f ), /*,tex coord...*/}, //1
{ DirectX::XMFLOAT3( + 1.0f, + 1.0f, + 1.0f ), /*,tex coord...*/}, //2
{ DirectX::XMFLOAT3( - 1.0f, + 1.0f, + 1.0f ), /*,tex coord...*/}, //3
{ DirectX::XMFLOAT3( - 1.0f, - 1.0f, - 1.0f ), /*,tex coord...*/}, //4
{ DirectX::XMFLOAT3( + 1.0f, - 1.0f, - 1.0f ), /*,tex coord...*/}, //5
{ DirectX::XMFLOAT3( + 1.0f, - 1.0f, + 1.0f ), /*,tex coord...*/}, //6
{ DirectX::XMFLOAT3( - 1.0f, - 1.0f, + 1.0f ), /*,tex coord...*/}, //7
};
And for the index buffer I use:
WORD indices[] = {
3,1,0,2,1,3, //top
0,5,4,1,5,0,
3,4,7,0,4,3,
1,6,5,2,6,1,
2,7,6,3,7,2,
6,4,5,7,4,6,
};
It works just fine, but now I want to add a texture to the faces of my box.
Which would be the best approach?
The options I see:
- Use 24 instead of 8 vertices -- four for each of the box's six faces. Some of these will have the same position/normals, but different texture coordinates.
- Use 8 vertices and texture coordinates like here:
- MAYBE there is a way to provide different sets of texture coordinates for a single vertex, so I can provide different texture coordinates on different faces of the box? If so, how can I do that?
The disadvantages (for the options with the same numbers):
- 16 additional vertices (3 as many), all the benefits of using a index buffer to have less vertices are wasted - maybe this means I shouldn't use an index buffer at all, under this approach?
- Texture with odd proportion (2:3), texture must be six times the size for the same resolution.
- None?
In option 2. I can use one texture to create different images on each box's face, but I'm not interested in that benefit.
Additional question (!!!):
How is this done in 3d software and mesh formats?
When I create a box in 3ds Max, create a material with a texture and apply it to the box, each side of box has the same texture (like option #1), with good texture coordinates (impossible to achieve with 8 vertices and a single square texture?), and the statistics says "8 VERTEXES".
How is it possible? Did they achieve option #3?