I have trouble understanding the following Javascript code.It calculates, given a mesh described by its vertices vs and indices ind, the normals for each vertex. The mesh faces are a triangle list, and are oriented counterclockwise.utilsObject.prototype.calculateNormals = function(vs, ind){    var x=0;     var y=1;    var z=2;    var ns = [];    for(var i=0;i<vs.length;i++){ //for each vertex, initialize normal x, normal y, normal z        ns[i]=0.0;    }    for(var i=0;i<ind.length;i=i+3){ //we work on triads of vertices to calculate normals so i = i+3 (i = indices index)        var v1 = [];        var v2 = [];        var normal = [];        //p1 - p0        v1[x] = vs[3*ind[i+1]+x] - vs[3*ind[i]+x];        v1[y] = vs[3*ind[i+1]+y] - vs[3*ind[i]+y];        v1[z] = vs[3*ind[i+1]+z] - vs[3*ind[i]+z];        // p0 - p1        v2[x] = vs[3*ind[i+2]+x] - vs[3*ind[i+1]+x];        v2[y] = vs[3*ind[i+2]+y] - vs[3*ind[i+1]+y];        v2[z] = vs[3*ind[i+2]+z] - vs[3*ind[i+1]+z];                    //cross product by Sarrus Rule        normal[x] = v1[y]*v2[z] - v1[z]*v2[y];        normal[y] = v1[z]*v2[x] - v1[x]*v2[z];        normal[z] = v1[x]*v2[y] - v1[y]*v2[x];        for(j=0;j<3;j++){ //update the normals of that triangle: sum of vectors            ns[3*ind[i+j]+x] =  ns[3*ind[i+j]+x] + normal[x];            ns[3*ind[i+j]+y] =  ns[3*ind[i+j]+y] + normal[y];            ns[3*ind[i+j]+z] =  ns[3*ind[i+j]+z] + normal[z];        }    }How does this function work? For example, could you explain the use of indices in the instruction:v1[x] = vs[3*ind[i+1]+x] - vs[3*ind[i]+x];Rather than a high-level explanation, I am interested in the logic of the implementation details.
How does this function calculate normals of a mesh?
shader;computational geometry;webgl