From e5d64542ce7dcacbdc2f55cf153d5c77c3d6aafe Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Tue, 19 Feb 2019 15:40:45 -0500 Subject: [PATCH 1/2] Added definition for options type. Removed MTLLoader.materials - there is only MaterialCreator.materials, judging from the source code. --- types/three/three-mtlloader.d.ts | 46 ++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/types/three/three-mtlloader.d.ts b/types/three/three-mtlloader.d.ts index 33b4822432..e5151c66c5 100644 --- a/types/three/three-mtlloader.d.ts +++ b/types/three/three-mtlloader.d.ts @@ -5,14 +5,44 @@ import { Material } from "./three-core"; import {LoadingManager} from "./three-core"; import {EventDispatcher} from "./three-core"; import {BufferGeometry} from "./three-core"; +import {Side} from "./three-core"; import {Texture} from "./three-core"; +import {Wrapping} from "./three-core"; + +export interface MaterialCreatorOptions { + /** + * side: Which side to apply the material + * THREE.FrontSide (default), THREE.BackSide, THREE.DoubleSide + */ + side?: Side; + /* + * wrap: What type of wrapping to apply for textures + * THREE.RepeatWrapping (default), THREE.ClampToEdgeWrapping, THREE.MirroredRepeatWrapping + */ + wrap?: Wrapping; + /* + * normalizeRGB: RGBs need to be normalized to 0-1 from 0-255 + * Default: false, assumed to be already normalized + */ + normalizeRGB?: boolean; + /* + * ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's + * Default: false + */ + ignoreZeroRGBs?: boolean; + /* + * invertTrProperty: Use values 1 of Tr field for fully opaque. This option is useful for obj + * exported from 3ds MAX, vcglib or meshlab. + * Default: false + */ + invertTrProperty?: boolean; +} export class MTLLoader extends EventDispatcher { constructor(manager?: LoadingManager); manager: LoadingManager; - materialOptions: {}; - materials: Material[]; + materialOptions: MaterialCreatorOptions; path: string; texturePath: string; crossOrigin: boolean; @@ -23,26 +53,26 @@ export class MTLLoader extends EventDispatcher { setTexturePath(path: string) : void; setBaseUrl(path: string) : void; setCrossOrigin(value: boolean) : void; - setMaterialOptions(value: any) : void; + setMaterialOptions(value: MaterialCreatorOptions) : void; } export class MaterialCreator { - constructor(baseUrl?: string, options?: any); + constructor(baseUrl?: string, options?: MaterialCreatorOptions); baseUrl : string; - options : any; materialsInfo : any; materials : any; materialsArray : Material[]; nameLookup : any; - side : number; - wrap : number; + options : MaterialCreatorOptions; + side : Side; + wrap : Wrapping; setCrossOrigin( value: boolean ) : void; - setManager( value: any ) : void; setMaterials( materialsInfo: any ) : void; convert( materialsInfo: any ) : any; + setManager( value: LoadingManager ) : void; preload() : void; getIndex( materialName: string ) : Material; getAsArray() : Material[]; From f0f4c9fa698886c372f3e58d08d1d115854c2794 Mon Sep 17 00:00:00 2001 From: David Pritchard Date: Tue, 19 Feb 2019 15:45:50 -0500 Subject: [PATCH 2/2] Specified several "any" types within MaterialCreator; made a few loadTexture params optional. --- types/three/three-mtlloader.d.ts | 40 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/types/three/three-mtlloader.d.ts b/types/three/three-mtlloader.d.ts index e5151c66c5..c2dbd40c84 100644 --- a/types/three/three-mtlloader.d.ts +++ b/types/three/three-mtlloader.d.ts @@ -3,10 +3,12 @@ import { Material } from "./three-core"; import {LoadingManager} from "./three-core"; +import {Mapping} from "./three-core"; import {EventDispatcher} from "./three-core"; import {BufferGeometry} from "./three-core"; import {Side} from "./three-core"; import {Texture} from "./three-core"; +import {Vector2} from "./three-core"; import {Wrapping} from "./three-core"; export interface MaterialCreatorOptions { @@ -56,29 +58,51 @@ export class MTLLoader extends EventDispatcher { setMaterialOptions(value: MaterialCreatorOptions) : void; } +export interface MaterialInfo { + ks?: number[]; + kd?: number[]; + ke?: number[]; + map_kd?: string; + map_ks?: string; + map_ke?: string; + norm?: string; + map_bump?: string; + bump?: string; + map_d?: string; + ns?: number; + d?: number; + tr?: number; +} + +export interface TexParams { + scale: Vector2; + offset: Vector2; + url: string; +} + export class MaterialCreator { constructor(baseUrl?: string, options?: MaterialCreatorOptions); baseUrl : string; - materialsInfo : any; - materials : any; - materialsArray : Material[]; - nameLookup : any; options : MaterialCreatorOptions; + materialsInfo : {[key: string]: MaterialInfo}; + materials : {[key: string]: Material}; + private materialsArray : Material[]; + nameLookup : {[key: string]: number}; side : Side; wrap : Wrapping; setCrossOrigin( value: boolean ) : void; - setMaterials( materialsInfo: any ) : void; - convert( materialsInfo: any ) : any; setManager( value: LoadingManager ) : void; + setMaterials( materialsInfo: {[key: string]: MaterialInfo} ) : void; + convert( materialsInfo: {[key: string]: MaterialInfo} ) : {[key: string]: MaterialInfo}; preload() : void; getIndex( materialName: string ) : Material; getAsArray() : Material[]; create( materialName: string ) : Material; createMaterial_( materialName: string ) : Material; - getTextureParams( value: string, matParams: any ) : any; - loadTexture(url: string, mapping: any, onLoad: (bufferGeometry: BufferGeometry) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): Texture; + getTextureParams( value: string, matParams: any ) : TexParams; + loadTexture(url: string, mapping?: Mapping, onLoad?: (bufferGeometry: BufferGeometry) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): Texture; }