Game Development Reference
In-Depth Information
The face contains normal data per vertex. The final normal of the shared vertex has
contribution from each face. Hence, the normal of the vertex a is the vector sum of
NA , NB , and NC , as shown in the following diagram:
Vertex Normal
=NA+NB+NC
NC
C
NB
NA
B
A
The function morphedVertexNormalsFromObj calculates the final normal of each
vertex, as shown in the following code:
morphedVertexNormalsFromObj:function(){
var vertexVectors=[];
var normalVectors=[];
for(var i=0;i<this.faces.length;i=i+1){
//This condition checks if face normal is defined. Then, we
first clone the face normal for each vertex. The OBJ file
gives vertex normals.
if(!(this.faces[i].normal==undefined)&&this.faces[i].
vertexNormals.length==0){
this.faces[i].vertexNormals["a"]=vec3.clone
(this.faces[i].normal);
this.faces[i].vertexNormals["b"]=vec3.clone
(this.faces[i].normal);
this.faces[i].vertexNormals["c"]=vec3.clone
(this.faces[i].normal);
}
if(normalVectors[this.faces[i].a]===undefined)
{
normalVectors[this.faces[i].a]=vec3.clone
(this.faces[i].vertexNormals["a"]);
}
else{
vec3.add(normalVectors[this.faces[i].a],normalVectors
[this.faces[i].a],this.faces[i].vertexNormals["a"])
}
//Repeat the above code for b and c vertex as well.
 
Search WWH ::




Custom Search