Feb
2
GM6 D3D from the Ground Up - Chapter 8
2007 @ 06:49 PMChapter 8 - Models
Unfortunately, when you start drawing a lot of things in D3D every frame, things can slow down quite a bit. That's where Game Maker comes in with a bandwith saving feature -
models.
How To Create a Model
A model is basically a precompiled list of primitives to draw. Rather than executing every drawing command every step, it draws this saved information. Not only that, but you can save the model to a file and load it for future use!
To create a new model, call
d3d_model_create(). This function will create a new model resource and return a unique identifying ID. You should use this in conjunction with an assignment expression:
gun = d3d_model_create(); for example. When you are done with your model(at the end of the game or any other time), you should free the memory it used by calling
d3d_model_destroy(gun);
You can also save and load your model resource. Use
d3d_model_load(ID,filename) to load a model. The filename can be anything. It doesn't matter what extension the file uses. As long as it is a saved Game Maker model, it will work. The same applies for the
d3d_model_save(ID,filename) function, which saves the model to the specified file.
Composing and Drawing a Model
Every single drawing function we've used up until now also has a version that is made for models. The new function names always follow this naming convention:
d3d_model_... where ... is the rest of the function name. All of the vertex and built-in shapes follow this convention and can be used to construct models. They all have one extra argument, too. The first argument is now the index of the model. All of the old arguments follow this one as normal.
To draw the model, call
d3d_model_draw(ID,x,y,z,texid). This will draw the model relative to (x,y,z). If you do not want to use a texture, pass -1 as the argument for
texid. All transformations discussed earlier will affect the whole model as normal.
<< Previous Chapter Next Chapter >>
This article hasn't been commented yet.