Dice.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var Dice = 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( 0.488325, 0.325550, 0.488325, 0.007784, 0.011675, 0.007784, 0.011675, 0.325550);
  14. f4( 4, 5, 3, 2, 0.000000, 0.000000, 1.000000 );
  15. uv( 0.988325, 0.325550, 0.988325, 0.007784, 0.511675, 0.007784, 0.511675, 0.325550);
  16. f4( 6, 7, 5, 4, 0.000000, 0.000000, 1.000000 );
  17. uv( 0.488325, 0.658883, 0.488325, 0.341117, 0.011675, 0.341117, 0.011675, 0.658883);
  18. f4( 0, 1, 7, 6, 0.000000, 0.000000, 1.000000 );
  19. uv( 0.988325, 0.658883, 0.988325, 0.341117, 0.511675, 0.341117, 0.511675, 0.658883);
  20. f4( 3, 5, 7, 1, -1.000000, 0.000000, 0.000000 );
  21. uv( 0.488325, 0.992216, 0.488325, 0.674450, 0.011675, 0.674450, 0.011675, 0.992216);
  22. f4( 4, 2, 0, 6, -1.000000, 0.000000, 0.000000 );
  23. uv( 0.988325, 0.992216, 0.988325, 0.674450, 0.511675, 0.674450, 0.511675, 0.992216);
  24. scope.autoColor = function(){
  25. this.colors = {};
  26. this.selections = {};
  27. var i = 0;
  28. this.colors[""] = 0xcccccc;
  29. for(var s in this.selections){
  30. for(i = 0 ; i < this.selections[s].length; i++) this.faces[this.selections[s][i]].material = [ new THREE.MeshColorFillMaterial( this.colors[s],1) ];
  31. }
  32. }
  33. function v( x, y, z ) {
  34. scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
  35. }
  36. function f3( a, b, c, nx, ny, nz ) {
  37. scope.faces.push( new THREE.Face3( a, b, c, nx && ny && nz ? new THREE.Vector3( nx, ny, nz ) : null ) );
  38. }
  39. function f4( a, b, c, d, nx, ny, nz ) {
  40. scope.faces.push( new THREE.Face4( a, b, c, d, nx && ny && nz ? new THREE.Vector3( nx, ny, nz ) : null ) );
  41. }
  42. function uv( u1, v1, u2, v2, u3, v3, u4, v4 ) {
  43. var uv = [];
  44. uv.push( new THREE.UV( u1, v1 ) );
  45. uv.push( new THREE.UV( u2, v2 ) );
  46. uv.push( new THREE.UV( u3, v3 ) );
  47. if ( u4 && v4 ) uv.push( new THREE.UV( u4, v4 ) );
  48. scope.uvs.push( uv );
  49. }
  50. }
  51. Dice.prototype = new THREE.Geometry();
  52. Dice.prototype.constructor = Dice;