Normals per index?
Posted
by
WarrenFaith
on Stack Overflow
See other posts from Stack Overflow
or by WarrenFaith
Published on 2011-01-02T21:47:59Z
Indexed on
2011/01/02
21:53 UTC
Read the original article
Hit count: 244
I have a pyramid which has 5 vertex and 18 indices. As I want to add normals to each face I just found solution for normals for each vertex. That means I can't use indices to define my pyramid I need to have 18 vertex (and 3 times the same vertex for the same point in space).
There must be a solution to use normals not on vertex base but on index base.
Some code (javascript):
var vertices = [
-half, -half, half, // 0 front left
half, -half, half, // 1 front right
half, -half, -half, // 2 back right
-half, -half, -half, // 3 back left
0.0, Math.sqrt((size * size) - (2 * (half * half))) - half, 0.0 // 4 top
];
var vertexNormals = [
// front face
normaleFront[0], normaleFront[1], normaleFront[2],
normaleFront[0], normaleFront[1], normaleFront[2],
normaleFront[0], normaleFront[1], normaleFront[2],
// back face
normaleBack[0], normaleBack[1], normaleBack[2],
normaleBack[0], normaleBack[1], normaleBack[2],
normaleBack[0], normaleBack[1], normaleBack[2],
// left face
normaleLeft[0], normaleLeft[1], normaleLeft[2],
normaleLeft[0], normaleLeft[1], normaleLeft[2],
normaleLeft[0], normaleLeft[1], normaleLeft[2],
// right face
normaleRight[0], normaleRight[1], normaleRight[2],
normaleRight[0], normaleRight[1], normaleRight[2],
normaleRight[0], normaleRight[1], normaleRight[2],
// bottom face
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
];
var pyramidVertexIndices = [
0, 1, 4, // Front face
2, 3, 4, // Back face
3, 0, 4, // Left face
1, 2, 4, // Right face
0, 1, 2, 2, 3, 0, // Bottom face
];
© Stack Overflow or respective owner