mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.74k stars 35.3k forks source link

LWOLoader: add support for Discontinuous UV maps #19385

Open looeee opened 4 years ago

looeee commented 4 years ago

Copied from https://github.com/threejs/lwoloader/issues/28, initially reported by @onthez (last one!):

Having used the loader over the past 6 months or so, the biggest pain point in authoring models that will successfully load is having to avoid discontinuous UV maps. When you create a uv map in Lightwave it will almost certainly default to being discontinuous.

There are some manual techniques and a 3rd party plugin that can correct those down to basic UV maps but then there is a nasty trade off that the geometry is no long continuous so if applied to curved surface there is a hard unsmoothed edge where there shouldn't be one.

@looeee looked into this quite a bit and determined it might require a fair amount of effort.

I thought I would compile some resources to reference:

Current SDK docs (For LWO3) http://static.lightwave3d.com/sdk/2019/html/filefmts/lwo3.html#c_VMAD

Old SDK docs (For LWO2, but may have info that is still relevant) http://static.lightwave3d.com/sdk/11-6/html/filefmts/lwo2.html#c_VMAD

https://forums.newtek.com/showthread.php?112873-Dev-Parser-UV-Atlas-Mapping

https://forums.newtek.com/showthread.php?106629-Native-LWO-support-in-Unity/page2

This thread discusses going the other direction - bringing a model into LW, but has some good information. Also a Lightwave dev chimed in to answer some questions which might be helpful. https://forums.newtek.com/showthread.php?106234-Discontinuous-UV-handling-for-ObjectLoader-(in-C)

looeee commented 4 years ago

My comment from that issue, lightly re-phrased:

The problem is UV seams, AKA discontinuities - that is, hard edge in UV maps. Lightwave and three.js handle these in very different ways.

three.js handles seams by duplicating vertices along discontinuities. Lightwave handles seams by creating multiple UV maps, one for each section.

This is further complicated by the fact that there are two kinds of UV maps in the LWO spec - I think they are called VMAPS (continuous UVs) and VMADs (discontinuous UVs). In the case of a cube, where every side of the cube is discontinuous, you would expect to find VMADS. But, as far as I recall, the UVs end up getting specified as a combination of VMAPs and VMADs.

To make this work, we'd have to duplicate vertices along seams, then figure out how to combine the multiple UV maps into a single map.