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

Does this support colors #30

Closed fcpauldiaz closed 7 years ago

fcpauldiaz commented 7 years ago

Since mtl format is not supported I want to set a fixed color to my mesh. Would it work to create a new program with color shaders enable the attribute?

frenchtoast747 commented 7 years ago

Yes, solid colors are possible using the meshes loaded with webgl-obj-loader.

In the gh-pages page of this project there is an demo that uses this loader to load various OBJ models. One of the models that is loaded is the Blender monkey, Suzanne. While most of the other models have their texture files loaded in manually, the Suzanne model has a solid color.

I created a helper function in this demo project, drawObject(), that takes in an OBJ mesh created from this loader and draws the given mesh to the screen. There is an optional parameter, color, that takes in a 4 element vector that is passed in to the shader program as an attribute named modelColor. Later on, Suzanne is drawn to the screen here with the drawObject() function passing in a specific color (gold in this case).

You can do something similar in your own project so that you can map a solid color to your meshes.

fcpauldiaz commented 7 years ago

Thanks @frenchtoast747

frenchtoast747 commented 7 years ago

You're welcome, hope that helps!