Skip to content

Commit

Permalink
Adds types for Icosahedron, fixes Dodecahedron as certain types are m…
Browse files Browse the repository at this point in the history
…issing from three.js - #297
  • Loading branch information
hirako2000 committed Jul 29, 2017
1 parent 8e52826 commit fa06af3
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
19 changes: 17 additions & 2 deletions types/components/meshes/Dodecahedron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@ import {

import {
DodecahedronGeometry,
DodecahedronBufferGeometry,
Geometry,
Mesh
} from 'three';

/**
* this is missing in @types from three.js :(
*
* @interface DodecahedronBufferGeometry
* @extends {Geometry}
*/
interface DodecahedronBufferGeometry extends Geometry {
constructor(radius: number, detail: number): DodecahedronBufferGeometry;

parameters: {
radius: number;
detail: number;
};
}

interface DodecahedronParams extends MeshComponentParams {

/** Geometry parameters */
Expand Down Expand Up @@ -38,7 +53,7 @@ interface DodecahedronParams extends MeshComponentParams {
* @constructor Creates a Dodecahedron
* @param params
*/
constructor(params?: SphereParams);
constructor(params?: DodecahedronParams);

/**
* Build lifecycle creates a mesh using input params.
Expand Down
62 changes: 62 additions & 0 deletions types/components/meshes/Icosahedron.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
MeshComponent,
MeshComponentParams
} from '../../core/MeshComponent';

import {
IcosahedronGeometry,
Mesh,
PolyhedronGeometry
} from 'three';

interface IcosahedronBufferGeometry extends PolyhedronGeometry {
constructor(radius: number, detail: number): IcosahedronBufferGeometry;
}

interface IcosahedronParams extends MeshComponentParams {

/** Geometry parameters */
geometry?: {

/**
* Radius
* Default is 1.
*/
radius?: number;

/**
* Detail level.
* Setting this to a value greater than 0 adds more vertices making it no longer an icosahedron.
* When detail is greater than 1, it's effectively a sphere.
* Default is 0.
*/
detail?: number;
};

/**
* Whether to create buffered geometry or not.
* Default is false.
*/
buffer?: boolean;
}

export class Icosahedron extends MeshComponent {

/**
* @constructor Creates an Icosahedron
* @param params
*/
constructor(params?: IcosahedronParams);

/**
* Build lifecycle creates a mesh using input params.
* @param params
*/
build(params?: IcosahedronParams): Mesh;

/**
* Build the geometry
* @param params
*/
buildGeometry(params?: IcosahedronParams): IcosahedronGeometry | IcosahedronBufferGeometry;
}
3 changes: 2 additions & 1 deletion types/components/meshes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export * from './Box';
export * from './Cone';
export * from './Cylinder';
export * from './Group';
export * from './Dodecahedron';
export {Dodecahedron} from './Dodecahedron';
export * from './Extrude';
export {Icosahedron} from './Icosahedron';
export * from './Sphere';
export * from './Text';
export * from './Tetrahedron';
Expand Down
9 changes: 9 additions & 0 deletions types/whs-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
CubeCamera,
Extrude,
Group,
Icosahedron,
OrthographicCamera,
PerspectiveCamera,
Sphere
Expand Down Expand Up @@ -149,6 +150,14 @@ sphere.addTo(group);

group = new Group(extrude, cone);

const icosahedron = new Icosahedron({
geometry: {
radius: 2,
detail: 0.2
}
});
icosahedron.addTo(app);

// Cameras

const cubeCamera = new CubeCamera({
Expand Down

0 comments on commit fa06af3

Please sign in to comment.