3D Models

This section details all the functions available to you for using and creating 3D models.

When you need to draw large models it is rather expensive to call all the different drawing functions again and again in every step, so to avoid this you can create models. A model consists of a number of primitives and shapes that are all drawn together as a whole. Once a model is created you can draw it at different places with just one function call, models can also be loaded or saved to a file. Using models can considerable speed up the graphics in your 3D games and you should use them whenever you can.

Before giving the different functions available there is one important point: the handling of textures. Textures are taken from sprites and backgrounds using the functions found in the section on 2D Primitives. The indices of the textures can be different at different moments, and as a result models do not contain any texture information. This means that only when you draw a model do you provide the texture, so you can only use one texture in a model. If you need more textures you must either combine them in one (and carefully deal with the texture coordinates) or you must use multiple models. The advantage of this is that you can draw the same model easily with different textures.

For creating, loading, saving, and drawing models, the following functions exist:

  1. d3d_model_create
  2. d3d_model_destroy
  3. d3d_model_clear
  4. d3d_model_save
  5. d3d_model_load
  6. d3d_model_draw

For each primitive function there is an equivalent to add it to a model. The functions have the same arguments as the 2D primitive functions, or the 3D normal equivalents, except that each has as a first argument the index of the model, and no texture information is provided.

  1. d3d_model_primitive_begin
  2. d3d_model_vertex
  3. d3d_model_vertex_colour
  4. d3d_model_vertex_texture
  5. d3d_model_vertex_texture_colour
  6. d3d_model_vertex_normal
  7. d3d_model_vertex_normal_colour
  8. d3d_model_vertex_normal_texture
  9. d3d_model_vertex_normal_texture_colour
  10. d3d_model_primitive_end

Besides primitives you can also add basic shapes to the models. Again the functions look almost the same as the drawing functions found in the 3D drawing section, but with a model index and without texture information:

  1. d3d_model_block
  2. d3d_model_cylinder
  3. d3d_model_cone
  4. d3d_model_ellipsoid
  5. d3d_model_wall
  6. d3d_model_floor


Back: Working With 3D
© Copyright YoYo Games Ltd. 2018 All Rights Reserved