🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Direct3D11 Help understanding vertices indexes

Started by
1 comment, last by fleabay 2 years, 9 months ago

I have this obj file from blender.It is the default cube:

# Blender v2.82 (sub 7) OBJ File: ''
# www.blender.org
mtllib untitled.mtl
o Cube_Cube.002
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
vt 0.625000 0.000000
vt 0.375000 0.250000
vt 0.375000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.500000
vt 0.625000 0.500000
vt 0.375000 0.750000
vt 0.625000 0.750000
vt 0.375000 1.000000
vt 0.125000 0.750000
vt 0.125000 0.500000
vt 0.875000 0.500000
vt 0.625000 1.000000
vt 0.875000 0.750000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
usemtl None
s off
f 2/1/1 3/2/1 1/3/1
f 4/4/2 7/5/2 3/2/2
f 8/6/3 5/7/3 7/5/3
f 6/8/4 1/9/4 5/7/4
f 7/5/5 1/10/5 3/11/5
f 4/12/6 6/8/6 8/6/6
f 2/1/1 4/4/1 3/2/1
f 4/4/2 8/6/2 7/5/2
f 8/6/3 6/8/3 5/7/3
f 6/8/4 2/13/4 1/9/4
f 7/5/5 5/7/5 1/10/5
f 4/12/6 2/14/6 6/8/6

I set them in c# like this and it's working I have a cube.

Vector3[] verts =
            {
                new Vector3(-1f, -1f, 1f),
new Vector3(-1f, 1f, 1f),
new Vector3(-1f, -1f, -1f),
new Vector3(-1f, 1f, -1f),
new Vector3(1f, -1f, 1f),
new Vector3(1f, 1f, 1f),
new Vector3(1f, -1f, -1f),
new Vector3(1f, 1f, -1f),
            };
int[] tris =
            {
              1,2,0,
3,6,2,
7,4,6,
5,0,4,
6,0,2,
3,5,7,
1,3,2,
3,7,6,
7,5,4,
5,1,0,
6,4,0,
3,1,5,

            };

I don't unerstand the uv part.
1) As far as I understand
f 3/2/1 means:
use the 3rd element from position array as this vertex position

use the 2nd element from uv array as this vertex texture coordinate

use the 1st element from the normal array as this vertex normal

Then why there are more Vector2s in uvs array than Vector3s in positions array since a vertex has 1 position, 1 uv and 1 normal?
And if I use this method to index uvs can I send the uv indexes in the shader with the indexed positions?

Advertisement

bogdan7 said:
a vertex has 1 position, 1 uv and 1 normal

Each of the 8 corners of a cube has 1 of 8 positions.

There are 12 tris in a cube and every vert in those tris (36) can have it's own normal and uv (but only 1 of 8 possible positions).

Normals are generally the same for all verts on each face of a cube. So usually only 6 are needed.

UVs are generally shared on a cube face where the diagonal tris meet and also can be shared with other tris on other faces if the mapping is identical. If you wanted, you could apply the same texture to each side at 100% and only need 4 UVs to index from, one from each corner of the UV space. EG: 0,0 1,0 1,1 0,1

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

This topic is closed to new replies.

Advertisement