IndexedPlaneGeometry5.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  4. */
  5. THREE.IndexedPlaneGeometry5 = function ( width, height, widthSegments, heightSegments ) {
  6. this.width = width;
  7. this.height = height;
  8. this.widthSegments = widthSegments || 1;
  9. this.heightSegments = heightSegments || 1;
  10. var width_half = width / 2;
  11. var height_half = height / 2;
  12. var gridX = this.widthSegments;
  13. var gridY = this.heightSegments;
  14. var gridX1 = gridX + 1;
  15. var gridY1 = gridY + 1;
  16. var segment_width = this.width / gridX;
  17. var segment_height = this.height / gridY;
  18. var indices = gridX * gridY * 6;
  19. var vertices = gridX1 * gridY1;
  20. THREE.IndexedGeometry5.call( this, indices, vertices );
  21. var offset = 0;
  22. for ( var iy = 0; iy < gridY1; iy ++ ) {
  23. var y = iy * segment_height - height_half;
  24. for ( var ix = 0; ix < gridX1; ix ++ ) {
  25. var x = ix * segment_width - width_half;
  26. this.vertices[ offset ].x = x;
  27. this.vertices[ offset ].y = - y;
  28. this.normals[ offset ].z = 1;
  29. this.uvs[ offset ].x = ix / gridX;
  30. this.uvs[ offset ].y = iy / gridY;
  31. offset ++;
  32. }
  33. }
  34. var offset = 0;
  35. for ( var iy = 0; iy < gridY; iy ++ ) {
  36. for ( var ix = 0; ix < gridX; ix ++ ) {
  37. var a = ix + gridX1 * iy;
  38. var b = ix + gridX1 * ( iy + 1 );
  39. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  40. var d = ( ix + 1 ) + gridX1 * iy;
  41. this.indices[ offset ] = a;
  42. this.indices[ offset + 1 ] = b;
  43. this.indices[ offset + 2 ] = d;
  44. this.indices[ offset + 3 ] = b;
  45. this.indices[ offset + 4 ] = c;
  46. this.indices[ offset + 5 ] = d;
  47. offset += 6;
  48. }
  49. }
  50. };
  51. THREE.IndexedPlaneGeometry5.prototype = Object.create( THREE.IndexedGeometry5.prototype );