diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index 406724874e9e32275befad5919b0ed6e50a1d7ea..09407ba575c0f87226734fdbdc40a4bb6c4ac349 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -12,6 +12,7 @@ THREE.GLTFLoader = ( function () { this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; this.dracoLoader = null; + this.ddsLoader = null; } @@ -124,6 +125,13 @@ THREE.GLTFLoader = ( function () { }, + setDDSLoader: function ( ddsLoader ) { + + this.ddsLoader = ddsLoader; + return this; + + }, + parse: function ( data, path, onLoad, onError ) { var content; @@ -195,7 +203,7 @@ THREE.GLTFLoader = ( function () { break; case EXTENSIONS.MSFT_TEXTURE_DDS: - extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension(); + extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension( this.ddsLoader ); break; case EXTENSIONS.KHR_TEXTURE_TRANSFORM: @@ -287,16 +295,16 @@ THREE.GLTFLoader = ( function () { * https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds * */ - function GLTFTextureDDSExtension() { + function GLTFTextureDDSExtension( ddsLoader ) { - if ( ! THREE.DDSLoader ) { + if ( ! ddsLoader ) { throw new Error( 'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader' ); } this.name = EXTENSIONS.MSFT_TEXTURE_DDS; - this.ddsLoader = new THREE.DDSLoader(); + this.ddsLoader = ddsLoader; } @@ -855,7 +863,7 @@ THREE.GLTFLoader = ( function () { }, // Here's based on refreshUniformsCommon() and refreshUniformsStandard() in WebGLRenderer. - refreshUniforms: function ( renderer, scene, camera, geometry, material, group ) { + refreshUniforms: function ( renderer, scene, camera, geometry, material ) { if ( material.isGLTFSpecularGlossinessMaterial !== true ) { @@ -2549,7 +2557,7 @@ THREE.GLTFLoader = ( function () { ? new THREE.SkinnedMesh( geometry, material ) : new THREE.Mesh( geometry, material ); - if ( mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized ) { + if ( mesh.isSkinnedMesh === true && ! mesh.geometry.attributes.skinWeight.normalized ) { // we normalize floating point skin weight array to fix malformed assets (see #15319) // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs @@ -2837,7 +2845,7 @@ THREE.GLTFLoader = ( function () { for ( var j = 0, jl = outputArray.length; j < jl; j ++ ) { - scaled[j] = outputArray[j] * scale; + scaled[ j ] = outputArray[ j ] * scale; } diff --git a/examples/jsm/loaders/GLTFLoader.d.ts b/examples/jsm/loaders/GLTFLoader.d.ts index d09bd6895ff8d7d4d4c37b04fa1e946f129919a7..0222c47b62c860291bfb82911f5757e5b4890a53 100644 --- a/examples/jsm/loaders/GLTFLoader.d.ts +++ b/examples/jsm/loaders/GLTFLoader.d.ts @@ -5,6 +5,9 @@ import { Scene } from '../../../src/Three'; +import { DRACOLoader } from './DRACOLoader'; +import { DDSLoader } from './DDSLoader'; + export interface GLTF { animations: AnimationClip[]; scene: Scene; @@ -16,12 +19,17 @@ export interface GLTF { export class GLTFLoader { constructor(manager?: LoadingManager); manager: LoadingManager; + dracoLoader: DRACOLoader | null; + ddsLoader: DDSLoader | null; path: string; + crossOrigin: string; + resourcePath: string; load(url: string, onLoad: (gltf: GLTF) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void) : void; setPath(path: string) : GLTFLoader; setResourcePath(path: string) : GLTFLoader; setCrossOrigin(value: string): GLTFLoader; - setDRACOLoader(dracoLoader: object): GLTFLoader; + setDRACOLoader(dracoLoader: DRACOLoader): GLTFLoader; + setDDSLoader(ddsLoader: DDSLoader): GLTFLoader; parse(data: ArrayBuffer | string, path: string, onLoad: (gltf: GLTF) => void, onError?: (event: ErrorEvent) => void) : void; } diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index 404abfe0dda52c26d773e9cc8849f28e9a4a1887..8368fb51b71b2ef9a5d504b652d82b7d8d854d43 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -61,7 +61,6 @@ import { Skeleton, SkinnedMesh, SpotLight, - Texture, TextureLoader, TriangleFanDrawMode, TriangleStripDrawMode, @@ -78,6 +77,7 @@ var GLTFLoader = ( function () { this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager; this.dracoLoader = null; + this.ddsLoader = null; } @@ -190,6 +190,13 @@ var GLTFLoader = ( function () { }, + setDDSLoader: function ( ddsLoader ) { + + this.ddsLoader = ddsLoader; + return this; + + }, + parse: function ( data, path, onLoad, onError ) { var content; @@ -261,7 +268,7 @@ var GLTFLoader = ( function () { break; case EXTENSIONS.MSFT_TEXTURE_DDS: - extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension(); + extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension( this.ddsLoader ); break; case EXTENSIONS.KHR_TEXTURE_TRANSFORM: @@ -353,16 +360,16 @@ var GLTFLoader = ( function () { * https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds * */ - function GLTFTextureDDSExtension() { + function GLTFTextureDDSExtension( ddsLoader ) { - if ( ! THREE.DDSLoader ) { + if ( ! ddsLoader ) { - throw new Error( 'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader' ); + throw new Error( 'THREE.GLTFLoader: Attempting to load .dds texture without importing DDSLoader' ); } this.name = EXTENSIONS.MSFT_TEXTURE_DDS; - this.ddsLoader = new THREE.DDSLoader(); + this.ddsLoader = ddsLoader; } @@ -921,7 +928,7 @@ var GLTFLoader = ( function () { }, // Here's based on refreshUniformsCommon() and refreshUniformsStandard() in WebGLRenderer. - refreshUniforms: function ( renderer, scene, camera, geometry, material, group ) { + refreshUniforms: function ( renderer, scene, camera, geometry, material ) { if ( material.isGLTFSpecularGlossinessMaterial !== true ) { @@ -1719,7 +1726,7 @@ var GLTFLoader = ( function () { * Requests the specified dependency asynchronously, with caching. * @param {string} type * @param {number} index - * @return {Promise} + * @return {Promise} */ GLTFParser.prototype.getDependency = function ( type, index ) { @@ -2008,7 +2015,7 @@ var GLTFLoader = ( function () { /** * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures * @param {number} textureIndex - * @return {Promise} + * @return {Promise} */ GLTFParser.prototype.loadTexture = function ( textureIndex ) { @@ -2615,7 +2622,7 @@ var GLTFLoader = ( function () { ? new SkinnedMesh( geometry, material ) : new Mesh( geometry, material ); - if ( mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized ) { + if ( mesh.isSkinnedMesh === true && ! mesh.geometry.attributes.skinWeight.normalized ) { // we normalize floating point skin weight array to fix malformed assets (see #15319) // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs @@ -2903,7 +2910,7 @@ var GLTFLoader = ( function () { for ( var j = 0, jl = outputArray.length; j < jl; j ++ ) { - scaled[j] = outputArray[j] * scale; + scaled[ j ] = outputArray[ j ] * scale; } diff --git a/examples/webgl_loader_gltf_extensions.html b/examples/webgl_loader_gltf_extensions.html index e8a7874af4c467f8351e196c224a907fa399caad..482b5bfab6dff24cc766e8c296bc4f1d4ecdeaa5 100644 --- a/examples/webgl_loader_gltf_extensions.html +++ b/examples/webgl_loader_gltf_extensions.html @@ -269,6 +269,7 @@ THREE.DRACOLoader.setDecoderPath( 'js/libs/draco/gltf/' ); loader.setDRACOLoader( new THREE.DRACOLoader() ); + loader.setDDSLoader( new THREE.DDSLoader() ); var url = sceneInfo.url.replace( /%s/g, state.extension ); diff --git a/utils/modularize.js b/utils/modularize.js index 85f0bd595323704a78112400cb80f833c8a4fb22..81cae2fc87452950f8f76799a3525f973ad71cf4 100644 --- a/utils/modularize.js +++ b/utils/modularize.js @@ -90,7 +90,7 @@ var files = [ { path: 'loaders/EquirectangularToCubeGenerator.js', dependencies: [], ignoreList: [] }, { path: 'loaders/FBXLoader.js', dependencies: [ { name: 'Zlib', path: 'libs/inflate.min.js' }, { name: 'TGALoader', path: 'loaders/TGALoader.js' }, { name: 'NURBSCurve', path: 'curves/NURBSCurve.js' } ], ignoreList: [] }, { path: 'loaders/GCodeLoader.js', dependencies: [], ignoreList: [] }, - { path: 'loaders/GLTFLoader.js', dependencies: [], ignoreList: [ 'NoSide', 'Matrix2', 'DDSLoader', 'Camera' ] }, + { path: 'loaders/GLTFLoader.js', dependencies: [], ignoreList: [ 'NoSide', 'Matrix2', 'Camera', 'Texture' ] }, { path: 'loaders/HDRCubeTextureLoader.js', dependencies: [ { name: 'RGBELoader', path: 'loaders/RGBELoader.js' } ], ignoreList: [] }, { path: 'loaders/KMZLoader.js', dependencies: [ { name: 'ColladaLoader', path: 'loaders/ColladaLoader.js' } ], ignoreList: [] }, { path: 'loaders/LDrawLoader.js', dependencies: [], ignoreList: [ 'Cache', 'Material', 'Object3D' ] },