From 42ae78719bb131cc4b13090328fb816fa863078c Mon Sep 17 00:00:00 2001 From: Hirako Date: Sat, 29 Jul 2017 16:19:42 +0700 Subject: [PATCH] Adds types for Ring - #297 --- types/components/meshes/Ring.d.ts | 88 ++++++++++++++++++++++++++++++ types/components/meshes/index.d.ts | 1 + types/whs-tests.ts | 22 +++++++- 3 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 types/components/meshes/Ring.d.ts diff --git a/types/components/meshes/Ring.d.ts b/types/components/meshes/Ring.d.ts new file mode 100644 index 000000000..ad1568cc8 --- /dev/null +++ b/types/components/meshes/Ring.d.ts @@ -0,0 +1,88 @@ +import { + MeshComponent, + MeshComponentParams +} from '../../core/MeshComponent'; + +import { + Mesh, + RingGeometry, + RingBufferGeometry +} from 'three'; + +interface RingParams extends MeshComponentParams { + + /** Geometry parameters */ + geometry?: { + + /** + * Increase radius as it doesn't work right when innerRadius is set to 0. + * Default is 0. + */ + innerRadius?: number; + + /** + * + * Default is 50. + */ + outerRadius?: number; + + /** + * Number of segments. + * A higher number means the ring will be more round. Minimum is 3. + * Default is 8. + */ + thetaSegments?: number; + + /** + * Minimum is 1 + * Default is 8. + */ + phiSegments?: number; + + /** + * Starting angle + * Default is 0. + */ + thetaStart?: number; + + /** + * Central angle + * Default is Math.PI * 2. + */ + thetaLength?: number; + }; + + /** + * Sets whether to build a buffered geometry + * Default is false. + */ + buffer?: boolean; +} + +/** + * generating a two-dimensional ring geometry. + * + * @export + * @class Ring + * @extends {MeshComponent} + */ +export class Ring extends MeshComponent { + + /** + * @constructor Creates a Ring + * @param params parameters + */ + constructor(params?: RingParams); + + /** + * Build lifecycle creates a mesh using input params. + * @param params + */ + build(params?: RingParams): Mesh; + + /** + * Builds the geometry + * @param params + */ + buildGeometry(params?: RingParams): RingGeometry | RingBufferGeometry; +} diff --git a/types/components/meshes/index.d.ts b/types/components/meshes/index.d.ts index e9757000b..0d2d929ac 100644 --- a/types/components/meshes/index.d.ts +++ b/types/components/meshes/index.d.ts @@ -12,6 +12,7 @@ export * from './Octahedron'; export * from './Parametric'; export * from './Plane'; export * from './Polyhedron'; +export * from './Ring'; export * from './Sphere'; export * from './Text'; export * from './Tetrahedron'; diff --git a/types/whs-tests.ts b/types/whs-tests.ts index 484eac7a0..e69930535 100644 --- a/types/whs-tests.ts +++ b/types/whs-tests.ts @@ -22,7 +22,6 @@ import { import { Box, Cone, - CubeCamera, Extrude, Group, Icosahedron, @@ -33,10 +32,15 @@ import { Parametric, Plane, Polyhedron, + Sphere, + Ring +} from './components/meshes'; + +import { + CubeCamera, OrthographicCamera, PerspectiveCamera, - Sphere -} from './components'; +} from './components/cameras'; import { AmbientLight, @@ -273,6 +277,18 @@ const polyhedron = new Polyhedron({ }); polyhedron.addTo(app); +const ring = new Ring({ + geometry: { + innerRadius: 1, + outerRadius: 50, + phiSegments: 5, + thetaLength: Math.PI /3, + thetaSegments: 10, + thetaStart: 0 + } +}); +ring.addTo(app); + // Cameras const cubeCamera = new CubeCamera({