Legacy GM I need help with multiple textures in 3D

Hello, everyone knows theres a function in game maker which allows you to create a 3D block (d3d_draw_block) thats good if you want to create a block with only 1 texture. But in my case I want to create a block with multiple textures (different textures on each side). How do I do that? Thanks.
 

Binsk

Member
It is significantly more complicated because you will have to build the model yourself out of vertices and lay out the texture coordinates.

First, I'd say you won't be using DIFFERENT textures per side, that is a huge waste of VRAM and you'll need to make some custom shaders to do that. However, you can have it draw a different part of a single texture on each side which should effectively look like what you need.

I'm not going to step-by-step tell you how to do this; I'll give you the essentials and you can use the manual to teach yourself how to do this.

Lesson One:
Models are made out of triangles. A triangle is made out of 3 points defined in 3D space. A block has 6 sides meaning it has 12 triangles (two to make the square of each side) which means you need to define 36 points (three for each triangle) in space to make the shape of your cube. On top of this, you will need to specify which parts of the texture should be attached to each point so that the model can "stretch" the texture over the triangle.

Lesson Two:
Every single point will need what is called a UV coordinate, that is to say the location of the texture to attach to the point. UV coordinates range between [0..1] so if you have a 128x128 texture and one of your points has a UV definition of 0.5x0.25 then you will have the texture location of 64x32 attached to that point.

Lesson Three:
To create and store this data in GameMaker you will need two things; 1) a vertex buffer and 2) a vertex format. The vertex buffer essentially holds all the triangle point data and uv data for your model. The vertex format tells your graphics card how the data is laid out in the buffer. When your vertex buffer is built and ready to go then you tell the computer to draw it by using the function vertex_submit.

Important Notes:
If you have 3D lighting in your game then you will also need to define "normals" for every vertex as well as UV values. A normal is a unit vector (aka, vector with the length of 1) that tells the light hitting the vertex which way the vertex (or face) is facing so it knows how to bounce the light. If you don't have 3D lighting you don't need to define these.

If you are using backface culling (aka, the "inside" faces of the cube don't get drawn) then the order in which you define your triangles matters (since the "back" side won't be drawn you have to make sure you define the front to face outside the cube).

Welcome to the world of programming.
 

marasovec

Member
Using UV maps

You have 2 options
a) Using vertex buffers
b) Using a 3D model

3D model is the easier way. You can unwrap a 3D block in Blender, then paint the sides and export as a .d3d object with an UV map
Vertex buffers are pretty difficult if you don't know how UV works. You need to manually code triangles of the cube and assign correct coordinates to them
 

Binsk

Member
Using UV maps

You have 2 options
a) Using vertex buffers
b) Using a 3D model

3D model is the easier way. You can unwrap a 3D block in Blender, then paint the sides and export as a .d3d object with an UV map
Vertex buffers are pretty difficult if you don't know how UV works. You need to manually code triangles of the cube and assign correct coordinates to them
Are there extensions to export as d3d from Blender? I'm not familiar with them.
 
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_cube:
Variable obj_cube.z(100007, -2147483648) not set before reading it.
at gml_Object_obj_cube_DrawEvent_1 (line 1) - d3d_model_draw(model, x, y, z, uv);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_cube_DrawEvent_1 (line 1)


Edit: NVM I FIXED!!!! THANK YOU SO MUCH, NOW I ACTUALLY MANAGED TO DO SOMETHING WITH MY GAME
 
Top