Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTFLoader's aoMap uv not match Blender exported and other GLTFViewers. #21641

Closed
gonnavis opened this issue Apr 13, 2021 · 2 comments
Closed

Comments

@gonnavis
Copy link
Contributor

Describe the bug

This glb file sofa.zip which made and exported from Blender, has diffuseMap and aoMap.

When loaded to threejs scene using GLTFLoader, the aoMap display incorret.
image

I guess they has different uvs and tried to add this line sofa.geometry.attributes.uv2.copy(sofa.geometry.attributes.uv) then display correct.
image

I also tried https://threejs.org/editor/ and https://modelviewer.dev/editor/ ( which I heard also based on threejs ), all has the same problem.
image
image

But with https://sandbox.babylonjs.com/ , https://playcanvas.com/viewer and Win10 3D Viewer, display all ok.
image
image
image

Is the problem of threejs's GLTFLoader?

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://threejs.org/editor/
  2. Click on File -> Import, chose the glb file, and add a AmbientLight
  3. See error

Code

let loader=new GLTFLoader()
loader.load('./sofa.glb',gltf=>{
  scene.add(gltf.scene)
  let sofa=gltf.scene.children[0]
  // sofa.geometry.attributes.uv2.copy(sofa.geometry.attributes.uv)
})

Live example

See above metioned gltf viewer and load the glb model.

Expected behavior

Display correct aoMap with this glb model like in https://sandbox.babylonjs.com/ , https://playcanvas.com/viewer and Win10 3D Viewer.

Screenshots

See above.

Platform:

  • Device: [Desktop]
  • OS: [Windows]
  • Browser: [Chrome]
  • Three.js version: [r127]
@donmccurdy
Copy link
Collaborator

While the glTF specification allows any material texture slot to use any UV channel, three.js requires most material texture slots to use UV1, and requires AO textures or lightmaps to use UV2. If the model only has one UV channel, GLTFLoader will automatically duplicate it if needed for an AO texture:

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

However, it skips that if doing so would overwrite an existing UV channel, and in this case the model already has a second (unused) UV channel. Potentially that could be fixed, but there are a lot of messy edge cases involved in doing so.

The easier workaround is to remove the unused UV channel in Blender. The better, long-term solution is #12608.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 13, 2021

In this case, the issue can be merged in #12608.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants