DodecahedronGeometry.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @author Abe Pazos / https://hamoid.com
  3. * @author Mugen87 / https://github.com/Mugen87
  4. */
  5. import { Geometry } from '../core/Geometry.js';
  6. import { PolyhedronBufferGeometry } from './PolyhedronGeometry.js';
  7. // DodecahedronGeometry
  8. function DodecahedronGeometry( radius, detail ) {
  9. Geometry.call( this );
  10. this.type = 'DodecahedronGeometry';
  11. this.parameters = {
  12. radius: radius,
  13. detail: detail
  14. };
  15. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16. this.mergeVertices();
  17. }
  18. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  19. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  20. // DodecahedronBufferGeometry
  21. function DodecahedronBufferGeometry( radius, detail ) {
  22. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23. var r = 1 / t;
  24. var vertices = [
  25. // (±1, ±1, ±1)
  26. - 1, - 1, - 1, - 1, - 1, 1,
  27. - 1, 1, - 1, - 1, 1, 1,
  28. 1, - 1, - 1, 1, - 1, 1,
  29. 1, 1, - 1, 1, 1, 1,
  30. // (0, ±1/φ, ±φ)
  31. 0, - r, - t, 0, - r, t,
  32. 0, r, - t, 0, r, t,
  33. // (±1/φ, ±φ, 0)
  34. - r, - t, 0, - r, t, 0,
  35. r, - t, 0, r, t, 0,
  36. // (±φ, 0, ±1/φ)
  37. - t, 0, - r, t, 0, - r,
  38. - t, 0, r, t, 0, r
  39. ];
  40. var indices = [
  41. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  42. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  43. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  44. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  45. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  46. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  47. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  48. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  49. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  50. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  51. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  52. 1, 12, 14, 1, 14, 5, 1, 5, 9
  53. ];
  54. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  55. this.type = 'DodecahedronBufferGeometry';
  56. this.parameters = {
  57. radius: radius,
  58. detail: detail
  59. };
  60. }
  61. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  62. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  63. export { DodecahedronGeometry, DodecahedronBufferGeometry };