From a20fee9d35612f735b9ddfb0dd6cdc930bfd1e81 Mon Sep 17 00:00:00 2001 From: Hirako Date: Sat, 29 Jul 2017 15:11:51 +0700 Subject: [PATCH] Adds types for Line - #297 --- types/components/meshes/Line.d.ts | 54 ++++++++++++++++++++++++++++++ types/components/meshes/index.d.ts | 1 + types/whs-tests.ts | 15 ++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 types/components/meshes/Line.d.ts diff --git a/types/components/meshes/Line.d.ts b/types/components/meshes/Line.d.ts new file mode 100644 index 000000000..9c7b131e6 --- /dev/null +++ b/types/components/meshes/Line.d.ts @@ -0,0 +1,54 @@ +import { + MeshComponent, + MeshComponentParams +} from '../../core/MeshComponent'; + +import { + BufferGeometry, + Geometry, + LineCurve3, + Mesh +} from 'three'; + +interface LineParams extends MeshComponentParams { + + /** Geometry parameters */ + geometry: { + + /** + * A LineCurve3 representing the curve to trace as a line + * @type {LineCurve3} + */ + curve: LineCurve3; + + /** + * Points is the number of pieces to divide the curve into. + * Default is 50. + */ + points?: number; + } + + /** Sets whether to build a buffered geometry */ + buffer?: boolean; +} + + export class Line extends MeshComponent { + + /** + * @constructor Creates a Line + * @param params parameters + */ + constructor(params?: LineParams); + + /** + * Build lifecycle creates a mesh using input params. + * @param params + */ + build(params?: LineParams): Mesh; + + /** + * Builds the geometry + * @param params + */ + buildGeometry(params?: LineParams): Geometry | BufferGeometry; +} diff --git a/types/components/meshes/index.d.ts b/types/components/meshes/index.d.ts index 5e5d3dc58..f20cd0e8d 100644 --- a/types/components/meshes/index.d.ts +++ b/types/components/meshes/index.d.ts @@ -7,6 +7,7 @@ export * from './Extrude'; export {Icosahedron} from './Icosahedron'; export * from './Importer'; export * from './Lathe'; +export * from './Line'; export * from './Sphere'; export * from './Text'; export * from './Tetrahedron'; diff --git a/types/whs-tests.ts b/types/whs-tests.ts index 5b68f5856..12a931b89 100644 --- a/types/whs-tests.ts +++ b/types/whs-tests.ts @@ -4,8 +4,10 @@ import { Mesh, MeshStandardMaterial, JSONLoader, + LineCurve3, Shape, - Vector2 + Vector2, + Vector3 } from 'three'; import { @@ -26,6 +28,7 @@ import { Icosahedron, Importer, Lathe, + Line, OrthographicCamera, PerspectiveCamera, Sphere @@ -195,6 +198,16 @@ const lathe = new Lathe({ }); lathe.addTo(app); +const line = new Line({ + geometry: { + curve: new LineCurve3(new Vector3(0, 0, 0), new Vector3(10, 0, 0)), + points: 5 + }, + + buffer: true +}); +line.addTo(app); + // Cameras const cubeCamera = new CubeCamera({