Skip to content

Commit

Permalink
Adds types for Shape and a few adjustments to Polyhedron and Ring #297
Browse files Browse the repository at this point in the history
  • Loading branch information
hirako2000 committed Jul 29, 2017
1 parent 42ae787 commit b4e47aa
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 17 deletions.
8 changes: 3 additions & 5 deletions types/components/meshes/Polyhedron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ interface PolyhedronParams extends MeshComponentParams {
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
* @description 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.
* @constructor
* @param params parameters
*/
constructor(params?: PolyhedronParams);
Expand Down
10 changes: 2 additions & 8 deletions types/components/meshes/Ring.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,11 @@ interface RingParams extends MeshComponentParams {
buffer?: boolean;
}

/**
* generating a two-dimensional ring geometry.
*
* @export
* @class Ring
* @extends {MeshComponent}
*/
export class Ring extends MeshComponent {

/**
* @constructor Creates a Ring
* @description Creates a two-dimensional ring geometry
* @constructor
* @param params parameters
*/
constructor(params?: RingParams);
Expand Down
63 changes: 63 additions & 0 deletions types/components/meshes/Shape.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
MeshComponent,
MeshComponentParams
} from '../../core/MeshComponent';

import {
BufferGeometry,
Mesh,
Shape as ShapeNative,
ShapeGeometry
} from 'three';

interface ShapeBufferGeometry extends BufferGeometry {
constructor(shape: ShapeNative, options?: any);
constructor(shapes: ShapeNative[], options?: any);
}

interface ShapeParams extends MeshComponentParams {

/** Geometry parameters */
geometry: {

/**
* Array of shapes or a single shape.
*/
shapes: ShapeNative | Array<ShapeNative>;

/**
* Integer Number of segments per shape.
* Default is 12.
* FIXME, changing this will have no effect, it will always be 12.
*/
curveSegments?: number;
};

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

export class Shape extends MeshComponent {

/**
* @description Creates an one-sided polygonal geometry from one or more path shapes.
* @constructor
* @param params parameters
*/
constructor(params: ShapeParams);

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

/**
* Builds the geometry
* @param params
*/
buildGeometry(params?: ShapeParams): ShapeGeometry | ShapeBufferGeometry;
}
1 change: 1 addition & 0 deletions types/components/meshes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './Plane';
export * from './Polyhedron';
export * from './Ring';
export * from './Sphere';
export * from './Shape';
export * from './Text';
export * from './Tetrahedron';
export * from './Torus';
Expand Down
18 changes: 14 additions & 4 deletions types/whs-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MeshStandardMaterial,
JSONLoader,
LineCurve3,
Shape,
Shape as ShapeNative,
Vector2,
Vector3
} from 'three';
Expand Down Expand Up @@ -33,6 +33,7 @@ import {
Plane,
Polyhedron,
Sphere,
Shape,
Ring
} from './components/meshes';

Expand Down Expand Up @@ -127,7 +128,7 @@ const cone = new Cone({build: false});
cone.buildGeometry({buffer: true});
cone.addTo(app);

const shape = new Shape([
const shapeNative = new ShapeNative([
new Vector2(-4,-4),
new Vector2(-2,0),
new Vector2(-4,4),
Expand All @@ -141,7 +142,7 @@ const shape = new Shape([
let extrude = new Extrude({
build: false,
geometry: {
shapes: shape,
shapes: shapeNative,
options: {
bevelEnabled: false,
bevelSize: 0,
Expand All @@ -152,7 +153,7 @@ let extrude = new Extrude({

extrude = new Extrude({
geometry: {
shapes: [shape, shape],
shapes: [shapeNative, shapeNative],
options: {
bevelEnabled: false,
bevelSize: 0,
Expand Down Expand Up @@ -289,6 +290,15 @@ const ring = new Ring({
});
ring.addTo(app);

const shape = new Shape({
geometry: {
shapes: [new ShapeNative([new Vector2(2, 2), new Vector2(3, 3)])]
},

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

// Cameras

const cubeCamera = new CubeCamera({
Expand Down

0 comments on commit b4e47aa

Please sign in to comment.