Cube.js 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @author mr.doob / http://mrdoob.com/
  3. */
  4. var Cube = function (width, height, depth) {
  5. THREE.Geometry.call(this);
  6. var scope = this,
  7. width_half = width / 2,
  8. height_half = height / 2,
  9. depth_half = depth / 2;
  10. v( width_half, height_half, -depth_half );
  11. v( width_half, -height_half, -depth_half );
  12. v( -width_half, -height_half, -depth_half );
  13. v( -width_half, height_half, -depth_half );
  14. v( width_half, height_half, depth_half );
  15. v( width_half, -height_half, depth_half );
  16. v( -width_half, -height_half, depth_half );
  17. v( -width_half, height_half, depth_half );
  18. f4( 0, 1, 2, 3 );
  19. f4( 4, 7, 6, 5 );
  20. f4( 0, 4, 5, 1 );
  21. f4( 1, 5, 6, 2 );
  22. f4( 2, 6, 7, 3 );
  23. f4( 4, 0, 3, 7 );
  24. function v(x, y, z) {
  25. scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
  26. }
  27. function f4(a, b, c, d) {
  28. scope.faces.push( new THREE.Face4( a, b, c, d ) );
  29. }
  30. this.computeCentroids();
  31. this.computeNormals();
  32. }
  33. Cube.prototype = new THREE.Geometry();
  34. Cube.prototype.constructor = Cube;