Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // loop over u and v to define per-vertex attributes
  2. var maxindex = 0;
  3. for(var i=0; i<=uSegments; i++) {
  4.     for(var j=0; j<=vSegments; j++) {
  5.  
  6.         // current position (u,v) on the surface
  7.         var u = uMin + i * (uMax-uMin) / uSegments;
  8.         var v = vMin + j * (vMax-vMin) / vSegments;
  9.  
  10.         // current index into the vertex buffers
  11.         var vindex = i*(vSegments+1) + j;
  12.        
  13.         var p = definition.position(u,v);
  14.         vposition[vindex*3]   = p[0];
  15.         vposition[vindex*3+1] = p[1];
  16.         vposition[vindex*3+2] = p[2];
  17.        
  18.         // index inside the
  19.         var iindex = i*vSegments + j;
  20.        
  21.         // indices for drawing two triangles per patch
  22.         if(i<uSegments && j<vSegments) {
  23.             var ii = iindex*6;
  24.             triangles[ii++] = vindex;
  25.             triangles[ii++] = vindex+(vSegments+1);
  26.             triangles[ii++] = vindex+(vSegments+1)+1;
  27.             triangles[ii++] = vindex+(vSegments+1)+1;
  28.             triangles[ii++] = vindex+1;
  29.             triangles[ii++] = vindex;
  30.         };
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement