PlaneGeometry2.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.PlaneGeometry2 = function ( width, height, widthSegments, heightSegments ) {
  6. THREE.Geometry2.call( this, ( widthSegments * heightSegments ) * 2 * 3 );
  7. var vertices = this.vertices.array;
  8. var normals = this.normals.array;
  9. var uvs = this.uvs.array;
  10. this.width = width;
  11. this.height = height;
  12. this.widthSegments = widthSegments || 1;
  13. this.heightSegments = heightSegments || 1;
  14. var widthHalf = width / 2;
  15. var heightHalf = height / 2;
  16. var gridX = this.widthSegments;
  17. var gridY = this.heightSegments;
  18. var segmentWidth = this.width / gridX;
  19. var segmentHeight = this.height / gridY;
  20. var offset = 0;
  21. for ( var iy = 0; iy < gridY; iy ++ ) {
  22. var y1 = iy * segmentHeight - heightHalf;
  23. var y2 = ( iy + 1 ) * segmentHeight - heightHalf;
  24. for ( var ix = 0; ix < gridX; ix ++ ) {
  25. var x1 = ix * segmentWidth - widthHalf;
  26. var x2 = ( ix + 1 ) * segmentWidth - widthHalf;
  27. vertices[ offset + 0 ] = x1;
  28. vertices[ offset + 1 ] = y1;
  29. vertices[ offset + 3 ] = x2;
  30. vertices[ offset + 4 ] = y1;
  31. vertices[ offset + 6 ] = x1;
  32. vertices[ offset + 7 ] = y2;
  33. normals[ offset + 2 ] = 1;
  34. normals[ offset + 5 ] = 1;
  35. normals[ offset + 8 ] = 1;
  36. vertices[ offset + 9 ] = x2;
  37. vertices[ offset + 10 ] = y1;
  38. vertices[ offset + 12 ] = x2;
  39. vertices[ offset + 13 ] = y2;
  40. vertices[ offset + 15 ] = x1;
  41. vertices[ offset + 16 ] = y2;
  42. normals[ offset + 11 ] = 1;
  43. normals[ offset + 13 ] = 1;
  44. normals[ offset + 17 ] = 1;
  45. offset += 18;
  46. }
  47. }
  48. };
  49. THREE.PlaneGeometry2.prototype = Object.create( THREE.Geometry2.prototype );