Skip to content

Commit

Permalink
Adds types for Parametric - #297
Browse files Browse the repository at this point in the history
  • Loading branch information
hirako2000 committed Jul 29, 2017
1 parent 15195b6 commit 72b8251
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
61 changes: 61 additions & 0 deletions types/components/meshes/Parametric.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
MeshComponent,
MeshComponentParams
} from '../../core/MeshComponent';

import {
Mesh,
ParametricBufferGeometry,
ParametricGeometry,
} from 'three';

interface ParametricParams extends MeshComponentParams {

/** Geometry parameters */
geometry?: {

/**
* A function that takes in a u and v value each between 0 and 1 and returns a Vector3
* Default is (u, v) => new Vector3(u, v, 0)
*/
func?: Function;
/**
*
* Default is 10.
*/
slices?: number;

/**
*
* Default is 10.
*/
stacks?: number;
};

/**
* Sets whether to build a buffered geometry
* Default is false.
*/
buffer?: boolean;
}

export class Parametric extends MeshComponent {

/**
* @constructor Creates a Parametric
* @param params parameters
*/
constructor(params?: ParametricParams);

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

/**
* Builds the geometry
* @param params
*/
buildGeometry(params?: ParametricParams): ParametricGeometry | ParametricBufferGeometry;
}
1 change: 1 addition & 0 deletions types/components/meshes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './Importer';
export * from './Lathe';
export * from './Line';
export * from './Octahedron';
export * from './Parametric';
export * from './Sphere';
export * from './Text';
export * from './Tetrahedron';
Expand Down
16 changes: 16 additions & 0 deletions types/whs-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
Lathe,
Line,
Octahedron,
Parametric,
OrthographicCamera,
PerspectiveCamera,
Sphere
Expand Down Expand Up @@ -219,6 +220,21 @@ const octahedron = new Octahedron({
});
octahedron.addTo(app);

const createParametric = (u, v) => {
return new Vector3(u * 30, Math.random() * 5, v * 30);
};

const parametric = new Parametric({
geometry: {
func: createParametric,
slices: 5,
stacks: 8
},

buffer: true
});
parametric.addTo(app);

// Cameras

const cubeCamera = new CubeCamera({
Expand Down

0 comments on commit 72b8251

Please sign in to comment.