DodecahedronGeometry.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { PolyhedronGeometry } from './PolyhedronGeometry.js';
  2. class DodecahedronGeometry extends PolyhedronGeometry {
  3. constructor( radius = 1, detail = 0 ) {
  4. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  5. const r = 1 / t;
  6. const vertices = [
  7. // (±1, ±1, ±1)
  8. - 1, - 1, - 1, - 1, - 1, 1,
  9. - 1, 1, - 1, - 1, 1, 1,
  10. 1, - 1, - 1, 1, - 1, 1,
  11. 1, 1, - 1, 1, 1, 1,
  12. // (0, ±1/φ, ±φ)
  13. 0, - r, - t, 0, - r, t,
  14. 0, r, - t, 0, r, t,
  15. // (±1/φ, ±φ, 0)
  16. - r, - t, 0, - r, t, 0,
  17. r, - t, 0, r, t, 0,
  18. // (±φ, 0, ±1/φ)
  19. - t, 0, - r, t, 0, - r,
  20. - t, 0, r, t, 0, r
  21. ];
  22. const indices = [
  23. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  24. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  25. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  26. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  27. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  28. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  29. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  30. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  31. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  32. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  33. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  34. 1, 12, 14, 1, 14, 5, 1, 5, 9
  35. ];
  36. super( vertices, indices, radius, detail );
  37. this.type = 'DodecahedronGeometry';
  38. this.parameters = {
  39. radius: radius,
  40. detail: detail
  41. };
  42. }
  43. static fromJSON( data ) {
  44. return new DodecahedronGeometry( data.radius, data.detail );
  45. }
  46. }
  47. export { DodecahedronGeometry };