Plane.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @author mr.doob / http://mrdoob.com/
  3. * based on Papervision3D's Plane.as
  4. */
  5. var Plane = function ( width, height, segments_width, segments_height ) {
  6. THREE.Geometry.call( this );
  7. var scope = this,
  8. width_half = width / 2,
  9. height_half = height / 2,
  10. gridX = segments_width || 1,
  11. gridY = segments_height || 1,
  12. gridX1 = gridX + 1,
  13. gridY1 = gridY + 1,
  14. segment_width = width / gridX,
  15. segment_height = height / gridY;
  16. for(var iy = 0; iy < gridY1; iy++) {
  17. for( var ix = 0; ix < gridX1; ix++ ) {
  18. var x = ix * segment_width - width_half;
  19. var y = iy * segment_height - height_half;
  20. this.vertices.push( new THREE.Vertex( new THREE.Vector3( x, -y, 0 ) ) );
  21. }
  22. }
  23. for( iy = 0; iy < gridY; iy++ ) {
  24. for( ix = 0; ix < gridX; ix++ ) {
  25. var a = ix + gridX1 * iy;
  26. var b = ix + gridX1 * ( iy + 1 );
  27. var c = ( ix + 1 ) + gridX1 * iy;
  28. this.faces.push( new THREE.Face3( a, b, c ) );
  29. this.uvs.push( [
  30. new THREE.Vector2( ix / gridX, iy / gridY ),
  31. new THREE.Vector2( ix / gridX, ( iy + 1 ) / gridY ),
  32. new THREE.Vector2( ( ix + 1 ) / gridX, iy / gridY )
  33. ] );
  34. a = ( ix + 1 ) + gridX1 * ( iy + 1 );
  35. b = ( ix + 1 ) + gridX1 * iy;
  36. c = ix + gridX1 * ( iy + 1 );
  37. this.faces.push( new THREE.Face3( a, b, c ) );
  38. this.uvs.push( [
  39. new THREE.Vector2( ( ix + 1 ) / gridX, ( iy + 1 ) / gridY ),
  40. new THREE.Vector2( ( ix + 1 ) / gridX, iy / gridY ),
  41. new THREE.Vector2( ix / gridX, ( iy + 1 ) / gridY )
  42. ] );
  43. }
  44. }
  45. }
  46. Plane.prototype = new THREE.Geometry();
  47. Plane.prototype.constructor = Plane;