1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| var vertexArray = new Float32Array(numVerts*floatPerVert);
var indexArray = new Uint16Array(numIndex);
function addVector(arr,index,x,y,z,u,v,u2,v2) {
var i = index*floatPerVert;
arr[i+0] = x;
arr[i+1] = y;
arr[i+2] = z;
arr[i+3] = u;
arr[i+4] = v;
arr[i+5] = u2;
arr[i+6] = v2;
}
var cS = 32;
var ivert=0,iindex=0,offx,offy,offu,offv,uSz=1.0/numCol,vSz=1.0/numRow,msk=0;
for ( row = 0; row < numRow; row++ ) {
for ( col = 0; col < numCol; col++ ) {
// CREATE THE 4 VERTS
offx = (col - numCol/2);
offy = (row - numRow/2);
offu = col*uSz;
offv = row*vSz;
addVector( vertexArray, ivert+0, (offx+0)*cS, (offy+0)*cS, zmap[(row+0)*numCol+(col+0)]*cS, 0, 0, offu, offv );
addVector( vertexArray, ivert+1, (offx+1)*cS, (offy+0)*cS, zmap[(row+0)*numCol+(col+1)]*cS, 1, 0, offu+uSz, offv );
addVector( vertexArray, ivert+2, (offx+1)*cS, (offy+1)*cS, zmap[(row+1)*numCol+(col+1)]*cS, 1, 1, offu+uSz, offv+uSz );
addVector( vertexArray, ivert+3, (offx+0)*cS, (offy+1)*cS, zmap[(row+1)*numCol+(col+0)]*cS, 0, 1, offu, offv+uSz );
// CREATE THT 6 INDEXES
indexArray[iindex+0] = ivert + 0;
indexArray[iindex+1] = ivert + 1;
indexArray[iindex+2] = ivert + 2;
indexArray[iindex+3] = ivert + 0;
indexArray[iindex+4] = ivert + 2;
indexArray[iindex+5] = ivert + 3;
ivert += 4;
iindex += 6;
}
} |
Partager