Box6.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var Box6 = function () {
  2. var scope = this;
  3. THREE.Geometry.call(this);
  4. v( -100.000000, 100.000000, -100.000000 );
  5. v( -100.000000, -100.000000, -100.000000 );
  6. v( 100.000000, 100.000000, -100.000000 );
  7. v( 100.000000, -100.000000, -100.000000 );
  8. v( 100.000000, 100.000000, 100.000000 );
  9. v( 100.000000, -100.000000, 100.000000 );
  10. v( -100.000000, 100.000000, 100.000000 );
  11. v( -100.000000, -100.000000, 100.000000 );
  12. f4( 2, 3, 1, 0, 0.000000, 0.000000, 1.000000 );
  13. uv( 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000);
  14. f4( 4, 5, 3, 2, 0.000000, 0.000000, 1.000000 );
  15. uv( 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000);
  16. f4( 6, 7, 5, 4, 0.000000, 0.000000, 1.000000 );
  17. uv( 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000);
  18. f4( 0, 1, 7, 6, 0.000000, 0.000000, 1.000000 );
  19. uv( 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000);
  20. f4( 3, 5, 7, 1, -1.000000, 0.000000, 0.000000 );
  21. uv( 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000);
  22. f4( 4, 2, 0, 6, -1.000000, 0.000000, 0.000000 );
  23. uv( 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000);
  24. scope.colors = {};
  25. scope.selections = {};
  26. scope.selections["top"] = [4];
  27. scope.selections["bottom"] = [5];
  28. scope.selections["front"] = [2];
  29. scope.selections["back"] = [0];
  30. scope.selections["left"] = [3];
  31. scope.selections["right"] = [1];
  32. scope.colors["top"] = 0xb20000;
  33. scope.colors["bottom"] = 0x00b200;
  34. scope.colors["front"] = 0x0000b2;
  35. scope.colors["back"] = 0x00b2b2;
  36. scope.colors["left"] = 0xb200b2;
  37. scope.colors["right"] = 0xb2b200;
  38. scope.autoColor = function(){
  39. for(var s in this.selections){
  40. for(var i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshBasicMaterial( { color: this.colors[s], wireframe: false } ) ];
  41. }
  42. }
  43. scope.getPosition = function(){ return new THREE.Vector3(0.0, 0.0, 0.0); }
  44. scope.getRotation = function(){ return new THREE.Vector3(0.0, 0.0, 0.0); }
  45. scope.getScale = function(){ return new THREE.Vector3(1.0, 1.0, 1.0); }
  46. function v( x, y, z ) {
  47. scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
  48. }
  49. function f3( a, b, c, nx, ny, nz ) {
  50. scope.faces.push( new THREE.Face3( a, b, c, nx && ny && nz ? new THREE.Vector3( nx, ny, nz ) : null ) );
  51. }
  52. function f4( a, b, c, d, nx, ny, nz ) {
  53. scope.faces.push( new THREE.Face4( a, b, c, d, nx && ny && nz ? new THREE.Vector3( nx, ny, nz ) : null ) );
  54. }
  55. function uv( u1, v1, u2, v2, u3, v3, u4, v4 ) {
  56. var uv = [];
  57. uv.push( new THREE.UV( u1, v1 ) );
  58. uv.push( new THREE.UV( u2, v2 ) );
  59. uv.push( new THREE.UV( u3, v3 ) );
  60. if ( u4 && v4 ) uv.push( new THREE.UV( u4, v4 ) );
  61. scope.uvs.push( uv );
  62. }
  63. }
  64. Box6.prototype = new THREE.Geometry();
  65. Box6.prototype.constructor = Box6;