ClickCube.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @author mr.doob / http://mrdoob.com/
  3. */
  4. var ClickCube = function (width, height, depth, onSelect) {
  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( 2, 6, 7, 3 );
  22. f4( 1, 5, 6, 2 );
  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. var f = new THREE.SelectableFace4( a, b, c, d, onSelect );
  29. scope.faces.push(f);
  30. }
  31. this.computeCentroids();
  32. this.computeNormals();
  33. };
  34. ClickCube.prototype = new THREE.Geometry();
  35. ClickCube.prototype.constructor = ClickCube;