PlaneGeometry5.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.PlaneGeometry5 = function ( width, height, widthSegments, heightSegments ) {
  6. THREE.Geometry5.call( this, ( widthSegments * heightSegments ) * 2 * 3 );
  7. var vertices = this.vertices;
  8. var normals = this.normals;
  9. var uvs = this.uvs;
  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 ].set( x1, y1, 0 );
  28. vertices[ offset + 1 ].set( x2, y1, 0 );
  29. vertices[ offset + 2 ].set( x1, y2, 0 );
  30. normals[ offset + 0 ].z = 1;
  31. normals[ offset + 1 ].z = 1;
  32. normals[ offset + 2 ].z = 1;
  33. vertices[ offset + 3 ].set( x2, y1, 0 );
  34. vertices[ offset + 4 ].set( x2, y2, 0 );
  35. vertices[ offset + 5 ].set( x1, y2, 0 );
  36. normals[ offset + 3 ].z = 1;
  37. normals[ offset + 4 ].z = 1;
  38. normals[ offset + 5 ].z = 1;
  39. offset += 6;
  40. }
  41. }
  42. };
  43. THREE.PlaneGeometry5.prototype = Object.create( THREE.Geometry5.prototype );
  44. THREE.PlaneGeometry5.prototype.constructor = THREE.PlaneGeometry5;