Adds types for Controls, Orbit, Events, Fog modules adds Object3D as type for camera #293

Former-commit-id: 947afff75e33030e75833ea32b1ac11df04a5455
This commit is contained in:
Hirako2000 2017-07-13 02:43:52 +07:00
parent 20d1d40009
commit f4f798a00f
12 changed files with 174 additions and 3 deletions

View File

@ -1 +1,3 @@
export * from './CubeCamera';
export * from './OrthographicCamera';
export * from './PerspectiveCamera';

View File

@ -1,5 +1,6 @@
import {Component} from './Component';
import {CompositionError} from '../core';
import {Object3D} from 'three';
export interface CameraComponentParams {
build?: boolean;
@ -24,7 +25,7 @@ export class CameraComponent extends Component {
*/
constructor(params?: CameraComponentParams, defaults?: CameraComponentParams, instructions?: object);
build(): CompositionError | any;
build(): CompositionError | Object3D;
wrap(): Promise<CameraComponent>;

1
types/index.d.ts vendored
View File

@ -4,6 +4,7 @@
export * from './core';
export * from './components';
export * from './modules';
// For UMD - global space
export as namespace WHS;

37
types/modules/app/ControlsModule.d.ts vendored Normal file
View File

@ -0,0 +1,37 @@
import {App, ModuleManager} from '../../core';
export class ControlsModule {
/**
* TODO define type for params
* @constructor Creates a controls module.
* @param params the parameters.
*/
constructor(params?: any);
/**
* TODO define type for params
* @param self this module
*/
integrate(self: ControlsModule): void;
/**
* TODO define type for params
* @param manager the manager
*/
manager(manager: ModuleManager): void;
/**
* TODO define type
* Sets controls
* @param controls - the controls
*/
setControls(controls?: any): void;
/**
* TODO define type
* Sets update
* @param update
*/
setUpdate(update?: any): ControlsModule;
}

15
types/modules/app/ElementModule.d.ts vendored Normal file
View File

@ -0,0 +1,15 @@
export class ElementModule {
/**
* @constructor Creates an element module.
* @param container dom element to use as context for rendering
*/
constructor(container: HTMLElement);
/**
* Creates a div element inside the container
*/
createElement(): void;
// TODO completes other methods
}

View File

@ -0,0 +1,26 @@
import {ModuleManager} from '../../core';
export class EventsPatchModule {
/**
* TODO define type for params
* @param manager the manager
*/
manager(manager?: ModuleManager): void;
/**
*
* @param originObject
* @param destObject
* @param events the array of events (e.g mouseup)
*/
patchEvents(originObject: any, destObject: any, events: Array<string>): void;
/**
* TODO define type for params
* @param self this module
*/
integrate(self: EventsPatchModule): void;
// TODO completes other methods
}

43
types/modules/app/FogModule.d.ts vendored Normal file
View File

@ -0,0 +1,43 @@
/**
* FogModule properties
*/
interface FogModuleParams {
/**
* Fog color. Example: If set to black, far away objects will be rendered black.
* Default is 0xefd1b5.
*/
color?: number,
/**
* Fog density defines how fast the fog will grow dense.
* Only applies to exp2 type of fog.
*
* Default is 0.02.
*/
density?: number,
/**
* The minimum distance to start applying fog.
* Objects that are less than 'near' units from the active camera won't be affected by fog.
* Default is 0.02.
*/
near?: number,
/**
* The maximum distance at which fog stops being calculated and applied.
* Objects that are more than 'far' units away from the active camera won't be affected by fog.
* Default is 1000.
*/
far?: number
}
export class FogModule {
/**
* @constructor Creates a fog module.
* @param params parameters
* @param type the type of fog, either 'linear' or 'exp2'. Default is exp2
*/
constructor(params?: FogModuleParams, type?: string);
}

View File

@ -0,0 +1,19 @@
import {ControlsModule} from '../ControlsModule';
import {ModuleManager} from '../../../core';
export class OrbitControlsModule extends ControlsModule {
/**
* TODO define type for params
* @constructor Creates a controls module.
* @param params the parameters.
*/
constructor(params?: any);
/**
* TODO define type for params
* @param manager the manager
*/
manager(manager?: ModuleManager): void;
}

1
types/modules/app/controls/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export * from './OrbitControlsModule';

5
types/modules/app/index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
export * from './controls/';
export * from './ControlsModule';
export * from './ElementModule';
export * from './EventsPatchModule';
export * from './FogModule';

View File

@ -1 +1,2 @@
export * from "./mesh";
export * from './app';
export * from './mesh';

View File

@ -31,6 +31,13 @@ import {
TextureModule,
} from './modules/mesh';
import {
ControlsModule,
ElementModule,
EventsPatchModule,
FogModule,
OrbitControlsModule
} from './modules/app';
// Core
const app = new App();
@ -167,4 +174,17 @@ textureModule = new TextureModule({
url: 'some/path',
type: 'bumpMap'
}
);
);
// app Modules
const controlsModule = new ControlsModule();
const orbitControlsModule = new OrbitControlsModule();
const elementModule = new ElementModule(document.getElementById('app'));
elementModule.createElement();
const eventsPatchModule = new EventsPatchModule();
eventsPatchModule.patchEvents(null, null, ['mouseup', 'mousedown']);
const fogModule = new FogModule({}, 'linear');