|
@@ -181,7 +181,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
break;
|
|
|
|
|
|
case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
|
|
|
- extensions[ extensionName ] = new GLTFMaterialsPbrSpecularGlossinessExtension();
|
|
|
+ extensions[ extensionName ] = new GLTFMaterialsPbrSpecularGlossinessExtension( json );
|
|
|
break;
|
|
|
|
|
|
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
|
@@ -189,7 +189,11 @@ THREE.GLTFLoader = ( function () {
|
|
|
break;
|
|
|
|
|
|
case EXTENSIONS.MSFT_TEXTURE_DDS:
|
|
|
- extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension();
|
|
|
+ extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension( json );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
|
|
|
+ extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] = new GLTFTextureTransformExtension( json );
|
|
|
break;
|
|
|
|
|
|
default:
|
|
@@ -282,6 +286,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
|
|
|
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
|
|
|
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
|
|
|
+ KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
|
|
|
MSFT_TEXTURE_DDS: 'MSFT_texture_dds'
|
|
|
};
|
|
|
|
|
@@ -409,7 +414,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
|
|
|
|
- pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture.index ) );
|
|
|
+ pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -563,6 +568,51 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Texture Transform Extension
|
|
|
+ *
|
|
|
+ * Specification:
|
|
|
+ */
|
|
|
+ function GLTFTextureTransformExtension( json ) {
|
|
|
+
|
|
|
+ this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ GLTFTextureTransformExtension.prototype.extendTexture = function ( texture, transform ) {
|
|
|
+
|
|
|
+ texture = texture.clone();
|
|
|
+
|
|
|
+ if ( transform.offset !== undefined ) {
|
|
|
+
|
|
|
+ texture.offset.fromArray( transform.offset );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( transform.rotation !== undefined ) {
|
|
|
+
|
|
|
+ texture.rotation = transform.rotation;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( transform.scale !== undefined ) {
|
|
|
+
|
|
|
+ texture.repeat.fromArray( transform.scale );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( transform.texCoord !== undefined ) {
|
|
|
+
|
|
|
+ console.warn( 'THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ texture.needsUpdate = true;
|
|
|
+
|
|
|
+ return texture;
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* Specular-Glossiness Extension
|
|
|
*
|
|
@@ -692,7 +742,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( pbrSpecularGlossiness.diffuseTexture !== undefined ) {
|
|
|
|
|
|
- pending.push( parser.assignTexture( params, 'map', pbrSpecularGlossiness.diffuseTexture.index ) );
|
|
|
+ pending.push( parser.assignTexture( params, 'map', pbrSpecularGlossiness.diffuseTexture ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -708,9 +758,9 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( pbrSpecularGlossiness.specularGlossinessTexture !== undefined ) {
|
|
|
|
|
|
- var specGlossIndex = pbrSpecularGlossiness.specularGlossinessTexture.index;
|
|
|
- pending.push( parser.assignTexture( params, 'glossinessMap', specGlossIndex ) );
|
|
|
- pending.push( parser.assignTexture( params, 'specularMap', specGlossIndex ) );
|
|
|
+ var specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
|
|
|
+ pending.push( parser.assignTexture( params, 'glossinessMap', specGlossMapDef ) );
|
|
|
+ pending.push( parser.assignTexture( params, 'specularMap', specGlossMapDef ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2146,15 +2196,29 @@ THREE.GLTFLoader = ( function () {
|
|
|
/**
|
|
|
* Asynchronously assigns a texture to the given material parameters.
|
|
|
* @param {Object} materialParams
|
|
|
- * @param {string} textureName
|
|
|
- * @param {number} textureIndex
|
|
|
- * @return {Promise<THREE.Texture>}
|
|
|
+ * @param {string} mapName
|
|
|
+ * @param {Object} mapDef
|
|
|
+ * @return {Promise}
|
|
|
*/
|
|
|
- GLTFParser.prototype.assignTexture = function ( materialParams, textureName, textureIndex ) {
|
|
|
+ GLTFParser.prototype.assignTexture = function ( materialParams, mapName, mapDef ) {
|
|
|
+
|
|
|
+ var parser = this;
|
|
|
+
|
|
|
+ return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
|
|
|
+
|
|
|
+ if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
|
|
|
+
|
|
|
+ var transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
|
|
|
|
|
|
- return this.getDependency( 'texture', textureIndex ).then( function ( texture ) {
|
|
|
+ if ( transform ) {
|
|
|
+
|
|
|
+ texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- materialParams[ textureName ] = texture;
|
|
|
+ materialParams[ mapName ] = texture;
|
|
|
|
|
|
} );
|
|
|
|
|
@@ -2213,7 +2277,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( metallicRoughness.baseColorTexture !== undefined ) {
|
|
|
|
|
|
- pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture.index ) );
|
|
|
+ pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2222,9 +2286,8 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
|
|
|
|
|
|
- var textureIndex = metallicRoughness.metallicRoughnessTexture.index;
|
|
|
- pending.push( parser.assignTexture( materialParams, 'metalnessMap', textureIndex ) );
|
|
|
- pending.push( parser.assignTexture( materialParams, 'roughnessMap', textureIndex ) );
|
|
|
+ pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
|
|
|
+ pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2256,7 +2319,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( materialDef.normalTexture !== undefined && materialType !== THREE.MeshBasicMaterial ) {
|
|
|
|
|
|
- pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture.index ) );
|
|
|
+ pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
|
|
|
|
|
|
materialParams.normalScale = new THREE.Vector2( 1, 1 );
|
|
|
|
|
@@ -2270,7 +2333,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( materialDef.occlusionTexture !== undefined && materialType !== THREE.MeshBasicMaterial ) {
|
|
|
|
|
|
- pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture.index ) );
|
|
|
+ pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
|
|
|
|
|
|
if ( materialDef.occlusionTexture.strength !== undefined ) {
|
|
|
|
|
@@ -2288,7 +2351,7 @@ THREE.GLTFLoader = ( function () {
|
|
|
|
|
|
if ( materialDef.emissiveTexture !== undefined && materialType !== THREE.MeshBasicMaterial ) {
|
|
|
|
|
|
- pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture.index ) );
|
|
|
+ pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture ) );
|
|
|
|
|
|
}
|
|
|
|