frenchtoast747 / webgl-obj-loader

A simple OBJ model loader to help facilitate the learning of WebGL.
http://frenchtoast747.github.io/webgl-obj-loader/
MIT License
281 stars 59 forks source link

obj texturecoordinates #42

Closed pandrr closed 6 years ago

pandrr commented 6 years ago

Hi,

thank you for your nice script.

i now encountered obj files exported from cinema 4d which have 3 numbers per texturecoordinate, which does not make sense for 2d textures. all the indices for texture coordinates are wrong when loading this .obj file.

i fixed it by checking the number of elements and reducing it to 2 if >2

do you want me to create a pull request for this ?

frenchtoast747 commented 6 years ago

Hi @pandrr.

Thanks for reporting this bug!

Actually, the OBJ format apparently supports an optional w coordinate on textures which allows for fancy transformations of the textures themselves. See the OBJ spec here: https://en.wikipedia.org/wiki/Wavefront_.obj_file#File_format And an explanation of the w coordinate here: https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Workbench/!FME_Geometry/Texture_Coordinates.htm

Instead of limiting to the u and v coordinates, the loader really needs to be aware of the possibility of the optional w coordinate and adjust accordingly. I will go ahead and make a fix and get back with you.

Thanks again!

frenchtoast747 commented 6 years ago

@pandrr, I have pushed a proposed fix to the branch features/w-texture-coord . Could you try out webgl-obj-loader.min.js in the dist/ folder on that branch and let me know if that works for your Cinema 4D exported model?

@qtip, if you have time, would you mind reviewing the changes on that branch and let me know what you think?

pandrr commented 6 years ago

@frenchtoast747 yeah that works perfectly! thanks for responding so fast!