From ea5996b6ae47e7ca80f9295a9823b0ac98b624d0 Mon Sep 17 00:00:00 2001 From: Hirako2000 Date: Sun, 2 Jul 2017 18:57:28 +0700 Subject: [PATCH 1/4] Adds types for Sphere and Box - adjusts MeshComponent and use inheritance for params - #267 --- types/components/index.d.ts | 1 + types/components/meshes/Box.d.ts | 21 ++++++++++++++ types/components/meshes/Sphere.d.ts | 21 ++++++++++++++ types/components/meshes/index.d.ts | 2 ++ types/core/MeshComponent.d.ts | 18 +++++++++++- types/index.d.ts | 8 +++--- types/whs-tests.ts | 44 +++++++++++++++++++++++------ 7 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 types/components/index.d.ts create mode 100644 types/components/meshes/Box.d.ts create mode 100644 types/components/meshes/Sphere.d.ts create mode 100644 types/components/meshes/index.d.ts diff --git a/types/components/index.d.ts b/types/components/index.d.ts new file mode 100644 index 00000000..ef9b0568 --- /dev/null +++ b/types/components/index.d.ts @@ -0,0 +1 @@ +export * from './meshes'; diff --git a/types/components/meshes/Box.d.ts b/types/components/meshes/Box.d.ts new file mode 100644 index 00000000..37955201 --- /dev/null +++ b/types/components/meshes/Box.d.ts @@ -0,0 +1,21 @@ +import {MeshComponent, MeshParameters} from '../../core/MeshComponent'; +import {Material} from 'three'; + +interface BoxParameters extends MeshParameters { + geometry?: { + width?: number; + height?: number; + depth?: number; + widthSegments?: number; + heightSegments?: number; + depthSegments?: number; + } +} + + export class Box extends MeshComponent { + + /** + * @param params + */ + constructor(params?: BoxParameters); +} diff --git a/types/components/meshes/Sphere.d.ts b/types/components/meshes/Sphere.d.ts new file mode 100644 index 00000000..632c9495 --- /dev/null +++ b/types/components/meshes/Sphere.d.ts @@ -0,0 +1,21 @@ +import {MeshComponent, MeshParameters} from '../../core/MeshComponent'; + +interface SphereParameter extends MeshParameters { + geometry?: { + radius?: number; + widthSegments?: number; + heightSegments?: number; + phiStart?: number; + phiLength?: number; + thetaStart?: number; + thetaLength?: number; + } +} + + export class Sphere extends MeshComponent { + + /** + * @param params + */ + constructor(params?: SphereParameter); +} diff --git a/types/components/meshes/index.d.ts b/types/components/meshes/index.d.ts new file mode 100644 index 00000000..264eac6c --- /dev/null +++ b/types/components/meshes/index.d.ts @@ -0,0 +1,2 @@ +export * from './Box'; +export * from './Sphere'; diff --git a/types/core/MeshComponent.d.ts b/types/core/MeshComponent.d.ts index eb1ed70b..cc01657c 100644 --- a/types/core/MeshComponent.d.ts +++ b/types/core/MeshComponent.d.ts @@ -1,11 +1,27 @@ import {Component} from './Component'; import {CompositionError} from './errors'; +import {Material} from 'three'; + +interface MeshParameters { + material?: Material, + + shadow?: { + receive?: boolean, + cast?: boolean + }, + + position?: { + x?: number, + y?: number, + z?: number + } +} export class MeshComponent extends Component { /** * TODO */ - constructor(params: object, defaults?: object, instructions?: object); + constructor(params?: MeshParameters, defaults?: object, instructions?: object); /** * TODO explain why error diff --git a/types/index.d.ts b/types/index.d.ts index aa14d30f..96bc5f7c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,9 +1,9 @@ -// Type definitions for WhitestormJs 2.0 -// Project: https://github.com/WhitestormJS/whitestorm.js +// Type definitions for WhitestormJS 2.0 +// Project: https://github.com/WhitestormJS/whs.js // Definitions by: Hirako -// Definitions: https://github.com//DefinitelyTyped -export * from "./core"; +export * from './core'; +export * from './components'; // For UMD - global space export as namespace WHS; diff --git a/types/whs-tests.ts b/types/whs-tests.ts index 84616571..7e98087d 100644 --- a/types/whs-tests.ts +++ b/types/whs-tests.ts @@ -1,19 +1,29 @@ -import * as WHS from "./core"; +import { + Loop, + Component, + App, + CameraComponent, + LightComponent, + MeshComponent +} from "./core"; +import {MeshStandardMaterial} from 'three'; -const app = new WHS.App(); +import {Box, Sphere} from './components'; + +const app = new App(); app.start(); -let loop = new WHS.Loop(() => {}); -loop = new WHS.Loop(() => {}, true); +let loop = new Loop(() => {}); +loop = new Loop(() => {}, true); loop.start(app); loop.stop(app); loop.execute(); -const component = new WHS.Component(); +const component = new Component(); component.addTo(app); component.clone(); -const component2 = new WHS.Component(); +const component2 = new Component(); component.copy(component2); // Testing parent of component (ModuleSystem) @@ -25,17 +35,33 @@ component.disposeModule(null); component.disposeModules(); component.module(null).disposeModules(); -const camera = new WHS.CameraComponent(); +const camera = new CameraComponent(); const clonedCamera = camera.clone(); -const light = new WHS.LightComponent({}); +const light = new LightComponent({}); const clonedLight = light.clone(); const copiedLight = light.copy(clonedLight); copiedLight.wrap(); copiedLight.addTo(app); -const mesh = new WHS.MeshComponent({}); +const mesh = new MeshComponent({}); mesh.addTo(app); mesh.clone(); mesh.copy({}); mesh.build(); + +const box = new Box({ + position: { + x: 1 + }, + material: new MeshStandardMaterial() +}); +box.addTo(app); + +const sphere = new Sphere({ + position: { + x: 1 + }, + material: new MeshStandardMaterial() +}); +sphere.addTo(app); From 880176cc7d14568e65968f876454af5c0deb2d9a Mon Sep 17 00:00:00 2001 From: Hirako2000 Date: Sun, 2 Jul 2017 23:50:27 +0700 Subject: [PATCH 2/4] Adds types for Cameras classes - #269 --- types/components/cameras/CubeCamera.d.ts | 22 ++++++++++ .../cameras/OrthographicCamera.d.ts | 25 +++++++++++ .../components/cameras/PerspectiveCamera.d.ts | 23 ++++++++++ types/components/cameras/index.d.ts | 1 + types/components/index.d.ts | 1 + types/core/CameraComponent.d.ts | 43 +++++++------------ types/core/Component.d.ts | 8 +--- types/whs-tests.ts | 31 ++++++++++++- 8 files changed, 120 insertions(+), 34 deletions(-) create mode 100644 types/components/cameras/CubeCamera.d.ts create mode 100644 types/components/cameras/OrthographicCamera.d.ts create mode 100644 types/components/cameras/PerspectiveCamera.d.ts create mode 100644 types/components/cameras/index.d.ts diff --git a/types/components/cameras/CubeCamera.d.ts b/types/components/cameras/CubeCamera.d.ts new file mode 100644 index 00000000..bb4b4819 --- /dev/null +++ b/types/components/cameras/CubeCamera.d.ts @@ -0,0 +1,22 @@ +import { + CameraComponent, + CameraComponentParams +} from '../../core'; + +import {CubeCamera as CubeCameraNative} from 'three'; + +interface CubeCameraParams extends CameraComponentParams { + near?: number, + far?: number, + cubeResolution?: number +} + + export class CubeCamera extends CameraComponent { + + /** + * @param params + */ + constructor(params?: CubeCameraParams); + + build(): CubeCameraNative; +} diff --git a/types/components/cameras/OrthographicCamera.d.ts b/types/components/cameras/OrthographicCamera.d.ts new file mode 100644 index 00000000..e5f42cb7 --- /dev/null +++ b/types/components/cameras/OrthographicCamera.d.ts @@ -0,0 +1,25 @@ +import { + CameraComponent, + CameraComponentParams +} from '../../core'; + +import {OrthographicCamera as OrthographicCameraNative} from 'three'; + +interface OrthographicCameraParams extends CameraComponentParams { + near?: number, + far?: number, + left?: number, + right?: number, + top?: number, + bottom?: number +} + + export class OrthographicCamera extends CameraComponent { + + /** + * @param params + */ + constructor(params?: OrthographicCameraParams); + + build(): OrthographicCameraNative; +} diff --git a/types/components/cameras/PerspectiveCamera.d.ts b/types/components/cameras/PerspectiveCamera.d.ts new file mode 100644 index 00000000..57d1efeb --- /dev/null +++ b/types/components/cameras/PerspectiveCamera.d.ts @@ -0,0 +1,23 @@ +import { + CameraComponent, + CameraComponentParams +} from '../../core'; + +import {PerspectiveCamera as PerspectiveCameraNative} from 'three'; + +interface PerspectiveCameraParams extends CameraComponentParams { + near?: number, + far?: number, + fov?: number, + aspect?: number +} + + export class PerspectiveCamera extends CameraComponent { + + /** + * @param params + */ + constructor(params?: PerspectiveCameraParams); + + build(): PerspectiveCameraNative; +} diff --git a/types/components/cameras/index.d.ts b/types/components/cameras/index.d.ts new file mode 100644 index 00000000..326df674 --- /dev/null +++ b/types/components/cameras/index.d.ts @@ -0,0 +1 @@ +export * from './CubeCamera'; diff --git a/types/components/index.d.ts b/types/components/index.d.ts index ef9b0568..ed8909c7 100644 --- a/types/components/index.d.ts +++ b/types/components/index.d.ts @@ -1 +1,2 @@ export * from './meshes'; +export * from './cameras'; diff --git a/types/core/CameraComponent.d.ts b/types/core/CameraComponent.d.ts index 4063f691..3f2fcb08 100644 --- a/types/core/CameraComponent.d.ts +++ b/types/core/CameraComponent.d.ts @@ -1,45 +1,34 @@ import {Component} from './Component'; +import {CompositionError} from '../core' -export interface defaults { - build: true; +export interface CameraComponentParams { + build?: boolean; - position: { - x: 0, - y: 0, - z: 0 + position?: { + x?: number, + y?: number, + z?: number }; - rotation: { - x: 0, - y: 0, - z: 0 + rotation?: { + x?: number, + y?: number, + z?: number }; } export class CameraComponent extends Component { /* * Creates a new CameraComponent - * TODO define params & instuctions interface + * TODO define instuctions interface */ - constructor(params?: object, defaults?: defaults, instructions?: object); + constructor(params?: CameraComponentParams, defaults?: CameraComponentParams, instructions?: object); - /* - * TODO - */ - build(): Error; + build(): CompositionError; - /* - * TODO - */ - wrap(): any; + wrap(): Promise; - /* - * TODO - */ - copy(source: Component): CameraComponent; + copy(source: CameraComponent): CameraComponent; - /* - * TODO - */ clone(): CameraComponent; } diff --git a/types/core/Component.d.ts b/types/core/Component.d.ts index ce8669b0..c6db78ba 100644 --- a/types/core/Component.d.ts +++ b/types/core/Component.d.ts @@ -1,10 +1,6 @@ import {ModuleSystem} from './ModuleSystem'; import {App} from './App'; -export class AddPromise { - // TODO -} - export class Component extends ModuleSystem { /** * @@ -16,12 +12,12 @@ export class Component extends ModuleSystem { * Notes: As we work in 3D space - we have an App and objects it contains. * The App is the parent, objects are its children. */ - addTo(parent: App): AddPromise; + addTo(parent: App): Promise; /** * TODO */ - add(object: object): AddPromise; + add(object: object): Promise; /** * TODO diff --git a/types/whs-tests.ts b/types/whs-tests.ts index 7e98087d..80e95414 100644 --- a/types/whs-tests.ts +++ b/types/whs-tests.ts @@ -8,7 +8,13 @@ import { } from "./core"; import {MeshStandardMaterial} from 'three'; -import {Box, Sphere} from './components'; +import { + Box, + Sphere, + CubeCamera, + OrthographicCamera, + PerspectiveCamera +} from './components'; const app = new App(); app.start(); @@ -65,3 +71,26 @@ const sphere = new Sphere({ material: new MeshStandardMaterial() }); sphere.addTo(app); + +const cubeCamera = new CubeCamera({ + build: false, + + position: { + x: 1, + y: 10, + z: 0 + } +}); +const nativeCubeCamera = cubeCamera.build(); + +const orthographicCamera = new OrthographicCamera({ + build: false, + far: 100 +}); +const orthographicCameraNative = orthographicCamera.build(); + +const perspectiveCamera = new PerspectiveCamera({ + build: false, + far: 100 +}); +const perspectiveCameraNative = orthographicCamera.build(); From 5eb6bb0ffcc72ee1df21b3a505fb8625e928ba2b Mon Sep 17 00:00:00 2001 From: Hirako Date: Mon, 3 Jul 2017 16:55:27 +0700 Subject: [PATCH 3/4] Adds back reference to external modules --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 55763652..aa4731df 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,26 @@ $ npm install whs * โœ”๏ธ **Integrated [Three.js](https://threejs.org/) rendering engine** * :revolving_hearts: Work with whs.js and Three.js at the same time +### External Modules + +|Name|Status|Description| +|:--:|:----:|:----------| +|[whs-module-statsjs][statsjs]|![statsjs-npm]|WhitestormJS module for JavaScript Performance Monitor โšกโŒ›| +|[whs-module-dat.gui][datgui]|![datgui-npm]|User Interface for runtime editing properties ๐Ÿ”‘๐Ÿ› ๐Ÿ”ฉ| +|[physics-module-ammonext][physics-ammonext]|![physics-ammonext-npm]|Physics module based on [Ammo.js](https://github.com/kripken/ammo.js/)| +|[whs-module-audio][audio]| WIP |Audio module for 3D positional sound ๐Ÿ”‰| +|[whs-vrkit][vrkit]|![physics-ammonext-npm]|Module for Virtual Reality| + +[statsjs]: https://github.com/WhitestormJS/whs.js/tree/dev/modules/whs-module-statsjs +[statsjs-npm]: https://img.shields.io/npm/v/whs-module-statsjs.svg?style=flat-square +[datgui]: https://github.com/WhitestormJS/whs.js/tree/dev/modules/whs-module-dat.gui +[datgui-npm]: https://img.shields.io/npm/v/whs-module-dat.gui.svg?style=flat-square +[physics-ammonext]: https://github.com/WhitestormJS/physics-module-ammonext +[physics-ammonext-npm]: https://img.shields.io/npm/v/physics-module-ammonext.svg?style=flat-square +[audio]: https://github.com/WhitestormJS/whs.js/tree/dev/modules/whs-module-audio +[vrkit]: https://github.com/WhitestormJS/whs.js/tree/dev/modules/whs-vrkit +[vrkit-npm]: https://img.shields.io/npm/v/whs-vrkit.svg?style=flat-square + ### Donate [![OpenCollective Backers][backer-badge]][backer-url] From 5800f608be69fbeea3e081966522bfff854c394f Mon Sep 17 00:00:00 2001 From: Alexander Buzin Date: Mon, 3 Jul 2017 15:03:27 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index aa4731df..6e83bdd7 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,6 @@ Community chat. [Join us!][discord-url] ### Basic setup -```bash -# Install npm version -$ npm install whs --save-dev -``` - Download the [minified library](https://raw.githubusercontent.com/WhitestormJS/whs.js/dev/build/whs.min.js) or link the one from [CDN](https://cdnjs.com/libraries/whitestorm.js) ```html