Cube.js 928 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var Cube = function (width, height, depth) {
  2. THREE.Geometry.call(this);
  3. var scope = this,
  4. width_half = width / 2,
  5. height_half = height / 2,
  6. depth_half = depth / 2;
  7. v( width_half, height_half, -depth_half );
  8. v( width_half, -height_half, -depth_half );
  9. v( -width_half, -height_half, -depth_half );
  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. f4( 0, 1, 2, 3 );
  16. f4( 4, 7, 6, 5 );
  17. f4( 0, 4, 5, 1 );
  18. f4( 1, 5, 6, 2 );
  19. f4( 2, 6, 7, 3 );
  20. f4( 4, 0, 3, 7 );
  21. function v(x, y, z) {
  22. scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
  23. }
  24. function f4(a, b, c, d) {
  25. scope.faces.push( new THREE.Face4( a, b, c, d ) );
  26. }
  27. }
  28. Cube.prototype = new THREE.Geometry();
  29. Cube.prototype.constructor = Cube;