From 3161ba19195b79562c5d6d4dd03421a3cd81f339 Mon Sep 17 00:00:00 2001 From: "Lukaschenko, Konstantin" Date: Tue, 4 Dec 2018 17:23:02 +0100 Subject: [PATCH 1/2] added types for three-tds-loader. --- types/three-tds-loader/index.d.ts | 200 ++++++++++++++++++ .../three-tds-loader-tests.ts | 15 ++ types/three-tds-loader/tsconfig.json | 24 +++ types/three-tds-loader/tslint.json | 1 + 4 files changed, 240 insertions(+) create mode 100644 types/three-tds-loader/index.d.ts create mode 100644 types/three-tds-loader/three-tds-loader-tests.ts create mode 100644 types/three-tds-loader/tsconfig.json create mode 100644 types/three-tds-loader/tslint.json diff --git a/types/three-tds-loader/index.d.ts b/types/three-tds-loader/index.d.ts new file mode 100644 index 0000000000..379a2de8af --- /dev/null +++ b/types/three-tds-loader/index.d.ts @@ -0,0 +1,200 @@ +// Type definitions for three-tds-loader 1.1 +// Project: https://github.com/codetheorist/three-tds-loader +// Definitions by: Konstantin Lukaschenko +// Stefan Schönsee +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as THREE from 'three'; + +export default class TDSLoader { + constructor(three: typeof THREE); + + /** + * Load 3ds file from url. + * + * @param url URL for the file. + * @param onLoad onLoad callback, receives group object3D as argument. + * @param onProgress onProgress callback. + * @param onError onError callback. + */ + load: (url: string, onLoad: (object3D: THREE.Object3D) => void, onProgress?: (progress: ProgressEvent) => void, onError?: (event: ErrorEvent) => void) => void; + + /** + * Parse arraybuffer data and load 3ds file. + * + * @param arraybuffer Arraybuffer data to be loaded. + * @param path Path for external resources. + * @return Group loaded from 3ds file. + */ + parse: (arraybuffer: ArrayBuffer, path: string) => THREE.Object3D; + + /** + * Decode file content to read 3ds data. + * + * @param arraybuffer Arraybuffer data to be loaded. + */ + readFile: (arraybuffer: ArrayBuffer, path: string) => void; + + /** + * Read mesh data chunk. + * + * @param data Dataview in use. + */ + readMeshData: (data: DataView, path: string) => void; + + /** + * Read named object chunk. + * + * @param data Dataview in use. + */ + readNamedobject: (data: DataView) => void; + + /** + * Read material data chunk and add it to the material list. + * + * @param data Dataview in use. + */ + readMaterialEntry: (data: DataView, path: string) => void; + + /** + * Read mesh data chunk. + * + * @param data Dataview in use. + */ + readMesh: (data: DataView) => void; + + /** + * Read face array data chunk. + * + * @param data Dataview in use. + * @param mesh Mesh to be filled with the data read. + */ + readFaceArray: (data: DataView, mesh: THREE.Mesh) => void; + + /** + * Read texture map data chunk. + * + * @param data Dataview in use. + * @return Texture read from this data chunk. + */ + readMap: (data: DataView, path: string) => THREE.Texture; + + /** + * Read material group data chunk. + * + * @param data Dataview in use. + * @return object with name and index of the object. + */ + readMaterialGroup: (data: DataView) => object; + + /** + * Read a color value. + * + * @param data Dataview. + * @return Color value read.. + */ + readColor: (data: DataView) => THREE.Color; + + /** + * Read next chunk of data. + * + * @param data Dataview. + * @return Chunk of data read. + */ + readChunk: (data: DataView) => object; + + /** + * Set position to the end of the current chunk of data. + * + * @param chunk Data chunk. + */ + endChunk: (chunk: object) => void; + + /** + * Move to the next data chunk. + * + * @param data Dataview. + * @param chunk Data chunk. + */ + nextChunk: (data: DataView, chunk: object) => number; + + /** + * Reset dataview position. + */ + resetPosition: () => void; + + /** + * Read byte value. + * + * @param data Dataview to read data from. + * @return Data read from the dataview. + */ + readByte: (data: DataView) => number; + + /** + * Read 32 bit float value. + * + * @param data Dataview to read data from. + * @return Data read from the dataview. + */ + readFloat: (data: DataView) => number; + + /** + * Read 32 bit signed integer value. + * + * @param data Dataview to read data from. + * @return Data read from the dataview. + */ + readInt: (data: DataView) => number; + + /** + * Read 16 bit signed integer value. + * + * @param data Dataview to read data from. + * @return Data read from the dataview. + */ + readShort: (data: DataView) => number; + + /** + * Read 64 bit unsigned integer value. + * + * @param data Dataview to read data from. + * @return Data read from the dataview. + */ + readDWord: (data: DataView) => number; + + /** + * Read 32 bit unsigned integer value. + * + * @param data Dataview to read data from. + * @return Data read from the dataview. + */ + readWord: (data: DataView) => number; + + /** + * Read string value. + * + * @param data Dataview to read data from. + * @param maxLength Max size of the string to be read. + * @return Data read from the dataview. + */ + readString: (data: DataView, maxLength: number) => string; + + /** + * Set resource path used to determine the file path to attached resources. + * + * @param path Path to resources. + * @return Self for chaining. + */ + setPath: (path: string) => TDSLoader; + + /** + * Print debug message to the console. + * + * Is controlled by a flag to show or hide debug messages. + * + * @param message Debug message to print to the console. + */ + debugMessage: (message: string) => void; +} diff --git a/types/three-tds-loader/three-tds-loader-tests.ts b/types/three-tds-loader/three-tds-loader-tests.ts new file mode 100644 index 0000000000..f61eeb92e3 --- /dev/null +++ b/types/three-tds-loader/three-tds-loader-tests.ts @@ -0,0 +1,15 @@ +import * as THREE from 'three'; +import TDSLoader from 'three-tds-loader'; + +const loader = new TDSLoader(THREE); + +const onSuccess = (object3D: THREE.Object3D) => {}; +const onProgress = (progress: ProgressEvent) => {}; +const onError = (event: ErrorEvent) => {}; + +loader.load( + 'folder/file.3ds', + onSuccess, + onProgress, + onError +); diff --git a/types/three-tds-loader/tsconfig.json b/types/three-tds-loader/tsconfig.json new file mode 100644 index 0000000000..cab037513c --- /dev/null +++ b/types/three-tds-loader/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "three-tds-loader-tests.ts" + ] +} diff --git a/types/three-tds-loader/tslint.json b/types/three-tds-loader/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/three-tds-loader/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b7a61e55c8406749b2ef9ef32ed612b9c0dd96b6 Mon Sep 17 00:00:00 2001 From: Konstantin Lukaschenko Date: Tue, 4 Dec 2018 22:30:53 +0100 Subject: [PATCH 2/2] enhance module definition. --- types/three-tds-loader/index.d.ts | 4 +++- types/three-tds-loader/three-tds-loader-tests.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/types/three-tds-loader/index.d.ts b/types/three-tds-loader/index.d.ts index 379a2de8af..33e679a377 100644 --- a/types/three-tds-loader/index.d.ts +++ b/types/three-tds-loader/index.d.ts @@ -7,7 +7,9 @@ import * as THREE from 'three'; -export default class TDSLoader { +export = TDSLoader; + +declare class TDSLoader { constructor(three: typeof THREE); /** diff --git a/types/three-tds-loader/three-tds-loader-tests.ts b/types/three-tds-loader/three-tds-loader-tests.ts index f61eeb92e3..a4e9d61797 100644 --- a/types/three-tds-loader/three-tds-loader-tests.ts +++ b/types/three-tds-loader/three-tds-loader-tests.ts @@ -1,5 +1,5 @@ import * as THREE from 'three'; -import TDSLoader from 'three-tds-loader'; +import TDSLoader = require('three-tds-loader'); const loader = new TDSLoader(THREE);