Skip to content

Commit

Permalink
Adds types for Polyhedron - #297
Browse files Browse the repository at this point in the history
  • Loading branch information
hirako2000 committed Jul 29, 2017
1 parent eaacfe2 commit e6f6fcf
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
71 changes: 71 additions & 0 deletions types/components/meshes/Polyhedron.d.ts
Original file line number Diff line number Diff line change
@@ -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<number>;

/**
* Array of indices that make up the faces of the form [0,1,2, 2,3,0, ... ]
*/
indicesOfFaces?: Array<number>;

/**
* 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;
}
1 change: 1 addition & 0 deletions types/components/meshes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
25 changes: 25 additions & 0 deletions types/whs-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
Octahedron,
Parametric,
Plane,
Polyhedron,
OrthographicCamera,
PerspectiveCamera,
Sphere
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit e6f6fcf

Please sign in to comment.