sphere.ts 670 B

123456789101112131415161718192021
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Polyhedron } from './polyhedron';
  7. import { Icosahedron } from './icosahedron';
  8. import { Primitive } from './primitive';
  9. const { vertices, indices } = Icosahedron();
  10. /** Calculate vertex count for subdived icosahedron */
  11. export function sphereVertexCount(detail: number) {
  12. return 10 * Math.pow(Math.pow(2, detail), 2) + 2;
  13. }
  14. /** Create sphere by subdividing an icosahedron */
  15. export function Sphere(detail: number): Primitive {
  16. return Polyhedron(vertices, indices, { detail, radius: 1 });
  17. }