• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 [SOLVED] Multiple textures on a single vertex buffer

Zaid

Member
GMS2 IDE v2.2.1.375
GMS2 Runtime v2.2.1.291

Preface:
I have been briefly learning how 3D works within GMS2 and am trying to write a simple 3D game by scratch so I understand all of the ins-and-outs. No 3rd party extensions and 3rd party scripts are only allowed if I fully understand them. Just clarifying to avoid recommendations of extensions to download to do the same thing much quicker. I'm trying to take the long route.

Setup:
I am currently in the process of writing a Wavefront model loader (.obj/.mtl) so I can import external models into my game. Loading the .obj works fine. It saves the loaded model as a vertex buffer. Loading .mtl files, on the other hand, only works partially as of yet. For those who don't already know; an .mtl file is a Wavefront materials file which defines the textures, colors, etc of surfaces on the vertex buffer loaded from an associated .obj file. Currently only the material color and alpha values are loaded from the .mtl file and actually applied to the model vertex buffer.

Problem:
Since multiple different textures are defined within an .mtl file and used on the vertex buffer at different points... obviously this needs to be reflected in the model. Currently I am only aware of using 'vertex_submit(vbuff, pr_trianglelist, -1)' to actually render the model onto the screen. The problem arises from the fact that this function only allows for 1 texture to be applied to the entirety of the vertex buffer but as we already know, the .mtl file calls for multiple textures.

Question:
How would you recommend mapping multiple texture files onto a single model?

Are any of my ideas below on the right path? Why can I map colors to vertices in a vertex buffer but not textures?

Current ideas for possible solutions:
(A) Write a script to automatically map the multiple textures onto a single texture to use to wrap around the entire vertex buffer.

(B) Divide the model into multiple different vertex buffers based on texture used (or lack therefor of) and 'vertex_submit()' them all separately.

(C) Manually draw each vertex (Somehow. Unsure how this would be accomplished as of yet.) changing to the appropriate material/texture as needed.

Thanks in advance for any help! All suggestions, hints, pointers, tips, links to docs, etc are very appreciated!
 

Zaid

Member
Moving links because moderation or whatever:

So far everything I have been learning has been from various internet tutorials. None of which I have found yet have dove any further than where I am currently. The tutorials I've been using have been...

[GUIDE] Getting Started with 3D in GMS2 (Project Download) by MaddeMichael
YouTube: Using .OBJ 3D models in Game Maker Studio 2 [DOWNLOAD INCLUDED] by The Concept Boy
3D Games in Game Maker - Loading OBJ Models by DragoniteSpam
3D Games in Game Maker - Loading MTL Files by DragoniteSpam
 

Zaid

Member
As like most of my programming issues, I figured everything out shortly after reaching out for help.

For anyone interested the problem lied in the fact that I didn't really understand how UV mapping worked. Once I got a better grip on it, I realized that the UV values were just coordinates relative to the texture file being used as defined by the .mtl file.

So I opened up GIMP, packed the different texture files next to each other in a single image (kind of like how Minecraft's texture file works), opened up the .obj file in Blender and remapped all the UV values to be relative to the new image with multiple textures rather than each individual texture file. So all I really needed all along was a single texture, no unwrapping needed!
 
Top