0

I want to be able to load OBJ files, including the vertex normal. But I quickly encountered a problem where Blender gives me 1 normal per face, and I don't understand how I can link that to my vertices.

Here's the obj file:

# Blender v2.78 (sub 0) OBJ File: ''
# www.blender.org
o Cube
v 1.000000 -1.000000 -0.555273
v 1.000000 -1.000000 1.444727
v -1.000000 -1.000000 1.444726
v -1.000000 -1.000000 -0.555274
v 1.000000 1.000000 -0.555273
v 0.999999 1.000000 1.444727
v -1.000000 1.000000 1.444726
v -1.000000 1.000000 -0.555273
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
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
s off
f 1//1 3//1 4//1
f 8//2 6//2 5//2
f 5//3 2//3 1//3
f 6//4 3//4 2//4
f 3//5 8//5 4//5
f 1//6 8//6 5//6
f 1//1 2//1 3//1
f 8//2 7//2 6//2
f 5//3 6//3 2//3
f 6//4 7//4 3//4
f 3//5 7//5 8//5
f 1//6 4//6 8//6

And the parameters The paramters to export to OBJ

Si Have a cube with 6 faces, 8 vertices, and 12 triangles and 6 vertex normal. How do I make the link between vertex and face. I thought it would be more straightforward with one VN per vertex. And in the examples I saw online it was.

But here I need to figure out how to make the link between the two, so I guess I'll have to duplicate the vertices two since for each face the normal will be different.

EDIT: Solved, I misunderstood the way a polygon was written Each couple, is a couple of vertex pos/vertex normal

genpfault
  • 51,148
  • 11
  • 85
  • 139
florent teppe
  • 529
  • 5
  • 13
  • 1
    I don't understand. If you want each vertex to have a unique normal, you'll have to make a unique vertex per face. So you'll need to have nFaces * 3 vertexes each with a position and normal. There's no way around it. – zero298 Aug 16 '17 at 16:03
  • You will need to transform this file in a memory layout that is suitable to your application, duplicating informations where it is necessary – Amadeus Aug 16 '17 at 16:06
  • @Rabbid76 Okay that IS the part that I missed I though it was supposed to show the order of the vertices. So I guess I will duplicate vertices when their normal change from one use to the other. Thanks a lot. – florent teppe Aug 16 '17 at 16:09

1 Answers1

0

Solved, I misunderstood the way a polygon was written Each couple, is a couple of vertex pos//vertex normal.

To build my model, I need to make new vertices when the same vertex has different normals to be able to send it to openGL properly.

Because in openGL one vertex has one normal, but not in a obj file. So it is up to me to adapt the OBJ file to my data model.

florent teppe
  • 529
  • 5
  • 13