Skip to content

Commit

Permalink
Adds types for Importer - #297
Browse files Browse the repository at this point in the history
  • Loading branch information
hirako2000 committed Jul 29, 2017
1 parent fa06af3 commit b282c43
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
78 changes: 78 additions & 0 deletions types/components/meshes/Importer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
MeshComponent,
MeshComponentParams
} from '../../core/MeshComponent';

import {
Mesh,
Loader,
} from 'three';

interface ImporterParams extends MeshComponentParams {

/**
* Loader.
* Default to THREE.JSONLoader.
*/
loader?: Loader;

/**
* Specific parser function.
* Defaults is a geometry and material parser returning the native (Mesh) object.
*/
parser?: Function;

/**
* The URL of the model to import.
* Default is ''.
*/
url?: string;

/**
* Will be called when load starts.
* The default is a function with empty body.
*/
onLoad?: Function;

/**
* Will be called while load progresses.
* The default is a function with empty body.
*/
onProgress?: Function;

/**
* Will be called while load faces an error.
* The default is a function with empty body.
*/
onError?: Function;

/**
* Set the base path or URL from which to load files.
* This can be useful if you are loading many files from the same directory.
* Default is null.
*/
texturePath?: string;

/**
* Whether to use a custom material.
* Default is false.
*/
useCustomMaterial?: boolean,

}

export class Importer extends MeshComponent {

/**
* @constructor Creates an Importer
* @param params parameters
*/
constructor(params?: ImporterParams);

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

}
1 change: 1 addition & 0 deletions types/components/meshes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './Group';
export {Dodecahedron} from './Dodecahedron';
export * from './Extrude';
export {Icosahedron} from './Icosahedron';
export * from './Importer';
export * from './Sphere';
export * from './Text';
export * from './Tetrahedron';
Expand Down
29 changes: 29 additions & 0 deletions types/whs-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {
Geometry,
Material,
Mesh,
MeshStandardMaterial,
GLTF2Loader,
Shape,
Vector2
} from 'three';
Expand All @@ -20,6 +24,7 @@ import {
Extrude,
Group,
Icosahedron,
Importer,
OrthographicCamera,
PerspectiveCamera,
Sphere
Expand Down Expand Up @@ -158,6 +163,30 @@ const icosahedron = new Icosahedron({
});
icosahedron.addTo(app);

new Importer({
loader: new GLTF2Loader(),

url: 'some/path/model.gltf',

onLoad: () => {
console.log('on load');
},

onProgress: () => {
console.log('loading in progress');
},

onError: () => {
console.log('error loading with Importer');
},

parser(geometry: Geometry, material: Material) {
return new Mesh(geometry, material);
},

useCustomMaterial: false
}).addTo(app);

// Cameras

const cubeCamera = new CubeCamera({
Expand Down

0 comments on commit b282c43

Please sign in to comment.