Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,9 @@ class GLTFParser {

return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {

// TODO(mrdoob) Clean up
texture.userData._gltfTexCoord = mapDef.texCoord;

// Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
// However, we will copy UV set 0 to UV set 1 on demand for aoMap
if ( mapDef.texCoord !== undefined && mapDef.texCoord != 0 && ! ( mapName === 'aoMap' && mapDef.texCoord == 1 ) ) {
Expand Down Expand Up @@ -3174,11 +3177,28 @@ class GLTFParser {

}

// workarounds for mesh and geometry
// TODO(mrdoob) Clean up

if ( material.aoMap ) {

if ( geometry.attributes.uv2 === undefined ) {

if ( material.aoMap.userData._gltfTexCoord !== 0 && geometry.attributes.uv !== undefined ) {

if ( material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined ) {
geometry.setAttribute( 'uv2', geometry.attributes.uv );

geometry.setAttribute( 'uv2', geometry.attributes.uv );
}

} else {

if ( material.aoMap.userData._gltfTexCoord === 0 ) {

console.warn( 'THREE.GLTFLoader: Removed uv2 attribute as it\'s not being used.' );
geometry.deleteAttribute( 'uv2' );

}

}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would do it:

if ( material.aoMap ) {

	if ( material.aoMap.userData._gltfTexCoord === 0 && geometry.attributes.uv !== undefined ) {

		if ( geometry.attributes.uv2 !== undefined ) {

			console.warn( 'THREE.GLTFLoader: Removed unused uv2 attribute.' );

		}

		geometry.setAttribute( 'uv2', geometry.attributes.uv );

	}

}


}

Expand Down