PlaneGeometry2b.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.PlaneGeometry2b = function ( width, height, widthSegments, heightSegments ) {
  6. THREE.Geometry2.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 index = 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. this.vertices.setXY( index + 0, x1, y1 );
  28. this.vertices.setXY( index + 1, x2, y1 );
  29. this.vertices.setXY( index + 2, x1, y2 );
  30. this.vertices.setXY( index + 3, x2, y1 );
  31. this.vertices.setXY( index + 4, x2, y2 );
  32. this.vertices.setXY( index + 5, x1, y2 );
  33. this.normals.setZ( index + 0, 1 );
  34. this.normals.setZ( index + 1, 1 );
  35. this.normals.setZ( index + 2, 1 );
  36. this.normals.setZ( index + 3, 1 );
  37. this.normals.setZ( index + 4, 1 );
  38. this.normals.setZ( index + 5, 1 );
  39. index += 6;
  40. }
  41. }
  42. };
  43. THREE.PlaneGeometry2b.prototype = Object.create( THREE.Geometry2.prototype );