top of page
Writer's picturewu iris

Load Meshes From Files

Downloadable

Controls:

Exit: ESC or click X

Pause/Resume: Space (hold)

Hide Mesh: Shift (hold)

Change Effect: Ctrl (hold)

Change Mesh: Enter (hold)

Move Object: Up/Down/Left/Right (hold)

Move Camera: W/A/S/D (hold)

Rotate Camera: Q/E (hold)

Key Point

Human-Readable Asset Files

There are many advantages of having human-readable asset files.

First of all, they are asset files, which means they can be changed separately. Since these changes will not affect game code, there is no need to rebuild MyGame. They are also human-readable, so it is easy to debug and maintain these files.

There are two things we need to move into mesh files. One is vertex data; the other is index data. Index data is relatively easy. It is just an array. Considering we might need to add more vertex information later, it might be better to let each vertex have its own table so that we can add more keys later easily. In this way, when rewriting the code that processes mesh files, we only need to add code instead of modifying code.

Here is my mesh format:

return{

vertices = {

{

position = { -1.0, 0.0, 0.0 },

},

{

position = { 0.0, 0.0, 0.0 },

},

{

position = { 0.0, -1.0, 0.0 },

},

},

indices = {

0, 1, 2,

},

}


Load Mesh Files

I think the most challenging part of this assignment is loading mesh files. Lua uses a stack structure. The current item is always at -1, and the previous one is at -2, so no matter whether we are looping through an array or getting a value in a dictionary, we can push an integer/string and get the value at -1. The array size can be obtained by calling luaL_len() instead of adding redundant data in mesh files. Even though we can use #, it just makes our files larger. In some other cases, redundant data means more things to be modified when modifying something related to that data.

Here is a screenshot of my game. Thanks to previous assignments, it is now much much more convenient to add a new game object.


Here is a screenshot of debugging build tools:


20 views0 comments

Recent Posts

See All

Audio Project v1.0

Downloadable See How to use it? for more information. What does the project do? This audio project is based on Windows XAudio2 library....

Komentar


bottom of page