Open rohanjulka19 opened 4 weeks ago
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!
Hi, sorry for the delay in reviewing this! I'm leaving a comment here to bump this to the top of my pile, I'll get back to you shortly!
Resolves #6924
Changes: This change allows to render diffuse textures specified in the .mtl files while rendering the model. To implement this, a JS object has been added to the Geometry class which maps each material name to a texture (p5.Img object) and the faces to which the texture has to be applied. While rendering the model first it is checked if the model has textures, if it does then for each texture the index buffer is updated with face indices for that texture and rendered. This runs in a loop until all the textures have been rendered.
I have moved out from the logic for creating and updating indexBuffer from the createBuffers function to updateIndexBuffer function because I only wanted to update the index buffer again and again without deleting and initializing other buffers.
Screenshots of the change:
The mario obj file in the sample sketch specified in the issue have negative texture coordinates. Due to that it does not render correctly. Only when V coordinate is not inversed and texture wrapping mode is changed from clamp to repeat the model renders correctly. Now I am not sure exactly why this is working. For wrapping modes I understand why repeat mode should work but I am not sure how, not inversing the V coordinate is fixing the problem.
PR Checklist
npm run lint
passesPS: I am not sure if this was the exepcted implementation. If this looks fine I will add unit tests for this.