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
283 stars 59 forks source link

Add support for separating mesh indices by materials #48

Closed novalain closed 6 years ago

novalain commented 6 years ago

Currently the library requires the user to upload all material data to the shader and index the data by vertex-attribute-bound material id's.

The main problem with this is that obj's with several materials such as the crytek sponza contains lots of textures. This will quickly make the user run out of texture units when uploading all material data to the shader (which happens over >16 units on my machine). Texture arrays can't be used either if the images are not the same size, which is often the case.

This PR gives an option to divide the mesh indices into separate arrays which are accessed by the material indices. By doing this, the mesh is instead divided into sub-meshes that can have a separate shader per material. This resolves #44

frenchtoast747 commented 6 years ago

Thank you for your submission, @michaelnoven!