From e6f6fcf608556f296f20dc917726ed63db998190 Mon Sep 17 00:00:00 2001 From: Hirako Date: Sat, 29 Jul 2017 16:08:33 +0700 Subject: [PATCH] Adds types for Polyhedron - #297 --- types/components/meshes/Polyhedron.d.ts | 71 +++++++++++++++++++++++++ types/components/meshes/index.d.ts | 1 + types/whs-tests.ts | 25 +++++++++ 3 files changed, 97 insertions(+) create mode 100644 types/components/meshes/Polyhedron.d.ts diff --git a/types/components/meshes/Polyhedron.d.ts b/types/components/meshes/Polyhedron.d.ts new file mode 100644 index 000000000..d4bcbf87d --- /dev/null +++ b/types/components/meshes/Polyhedron.d.ts @@ -0,0 +1,71 @@ +import { + MeshComponent, + MeshComponentParams +} from '../../core/MeshComponent'; + +import { + Mesh, + PolyhedronBufferGeometry, + PolyhedronGeometry +} from 'three'; + +interface PolyhedronParams extends MeshComponentParams { + + /** Geometry parameters */ + geometry?: { + + /** + * Array of points of the form [1,1,1, -1,-1,-1, ... ] + */ + verticesOfCube?: Array; + + /** + * Array of indices that make up the faces of the form [0,1,2, 2,3,0, ... ] + */ + indicesOfFaces?: Array; + + /** + * The radius of the final shape + * Default is 6. + */ + radius?: number; + + /** + * How many levels to subdivide the geometry. + * The more detail, the smoother the shape. + * Default is 2. + */ + detail?: number; + }; + + /** + * Sets whether to build a buffered geometry + * Default is false. + */ + buffer?: boolean; +} + +/** + * A polyhedron is a solid in three dimensions with flat faces. + * This component will take an array of vertices, project them onto a sphere, and then divide them up to the desired level of detail. + */ + export class Polyhedron extends MeshComponent { + + /** + * @constructor Creates a Polyhedron + * @param params parameters + */ + constructor(params?: PolyhedronParams); + + /** + * Build lifecycle creates a mesh using input params. + * @param params + */ + build(params?: PolyhedronParams): Mesh; + + /** + * Builds the geometry + * @param params + */ + buildGeometry(params?: PolyhedronParams): PolyhedronGeometry | PolyhedronBufferGeometry; +} diff --git a/types/components/meshes/index.d.ts b/types/components/meshes/index.d.ts index a792f16f6..e9757000b 100644 --- a/types/components/meshes/index.d.ts +++ b/types/components/meshes/index.d.ts @@ -11,6 +11,7 @@ export * from './Line'; export * from './Octahedron'; export * from './Parametric'; export * from './Plane'; +export * from './Polyhedron'; export * from './Sphere'; export * from './Text'; export * from './Tetrahedron'; diff --git a/types/whs-tests.ts b/types/whs-tests.ts index fc4be0822..484eac7a0 100644 --- a/types/whs-tests.ts +++ b/types/whs-tests.ts @@ -32,6 +32,7 @@ import { Octahedron, Parametric, Plane, + Polyhedron, OrthographicCamera, PerspectiveCamera, Sphere @@ -248,6 +249,30 @@ const plane = new Plane({ }); plane.addTo(app); +const polyhedron = new Polyhedron({ + geometry: { + verticesOfCube: [ + -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, + -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1 + ], + + indicesOfFaces: [ + 2, 1, 0, 0, 3, 2, + 0, 4, 7, 7, 3, 0, + 0, 1, 5, 5, 4, 0, + 1, 2, 6, 6, 5, 1, + 2, 3, 7, 7, 6, 2, + 4, 5, 6, 6, 7, 4 + ], + + detail: 6, + radius: 4, + }, + + buffer: true +}); +polyhedron.addTo(app); + // Cameras const cubeCamera = new CubeCamera({