Skip to content

GLTFLoader: Remove uv2 attribute when not being used#23974

Closed
mrdoob wants to merge 1 commit intodevfrom
gltf
Closed

GLTFLoader: Remove uv2 attribute when not being used#23974
mrdoob wants to merge 1 commit intodevfrom
gltf

Conversation

@mrdoob
Copy link
Copy Markdown
Owner

@mrdoob mrdoob commented Apr 30, 2022

Description

This is a quick workaround until we improve the current uvset code (coming up soon in my todo list!)

Some gltf models may have second uv set but the aoMap may not use it, resulting in broken models.

Before After
Screen Shot 2022-04-30 at 4 37 24 PM Screen Shot 2022-04-30 at 4 35 11 PM

/cc @elalish @donmccurdy

@mrdoob mrdoob added this to the r140 milestone Apr 30, 2022
@mrdoob
Copy link
Copy Markdown
Owner Author

mrdoob commented Apr 30, 2022

@elalish

Meh... This breaks webgl_loader_gltf_compressed.
I'm afraid I'll have to leave it for r141 (or a point release if we figure out the fix).

@mrdoob mrdoob modified the milestones: r140, r141 Apr 30, 2022
@donmccurdy
Copy link
Copy Markdown
Collaborator

donmccurdy commented May 1, 2022

Probably these are the cases to consider:

aoMap.texCoord uv2 provided result
uv2 ok
uv2 invalid
uv1 rewrite and warn
uv1 rewrite

The only official glTF material texture that three.js allows to use uv2 is .aoMap, and so when AO would otherwise break, we'll copy uv to uv2 even if that requires overwriting an existing uv2 attribute. If there's no aoMap present, an unused uv2 will not be removed or overwritten.


}

}
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 );

	}

}

@mrdoob mrdoob modified the milestones: r141, r142 May 26, 2022
@mrdoob mrdoob modified the milestones: r142, r143 Jun 29, 2022
@mrdoob mrdoob modified the milestones: r143, r144 Jul 28, 2022
@mrdoob mrdoob modified the milestones: r144, r145 Aug 31, 2022
@mrdoob mrdoob modified the milestones: r145, r146 Sep 29, 2022
@mrdoob mrdoob modified the milestones: r146, r147 Oct 27, 2022
@mrdoob mrdoob modified the milestones: r147, r148 Nov 30, 2022
@mrdoob mrdoob modified the milestones: r148, r149 Dec 22, 2022
@elalish
Copy link
Copy Markdown
Contributor

elalish commented Jan 25, 2023

Any hope of merging this one since multi-UVs are delayed? Seems like Don's answer is a good one.

@mrdoob mrdoob modified the milestones: r149, r150 Jan 26, 2023
@mrdoob mrdoob modified the milestones: r150, r151 Feb 23, 2023
@mrdoob mrdoob removed this from the r151 milestone Mar 30, 2023
@mrdoob mrdoob modified the milestone: r152 Mar 30, 2023
@mrdoob
Copy link
Copy Markdown
Owner Author

mrdoob commented Apr 3, 2023

#25721 solved this.

@mrdoob mrdoob closed this Apr 3, 2023
@mrdoob mrdoob deleted the gltf branch April 3, 2023 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants