3D_for_GML:_Basic_shape_models - hpgDesigns/hpgdesigns-dev.io GitHub Wiki
With GM you can draw polygons (see Polygons) to create any type of shape you want. But there are some built-in shapes that can be drawn without using polygons. The codes to draw these basic shapes are:
Shape |
Code |
---|---|
Cubes |
|
Cones |
|
Cylinders |
|
Balls |
|
Vertical Planes |
|
Horizontal Planes |
|
The values x1,y1,z1,x2,y2,z2 determine the dimensions of the basic shape, creating an invisible box that holds the basic shape, so to speak. This means you can even create slanted floors. The texid value sets the image you want to texture the basic shape. The values hrepeat and vrepeat determine how many times the texture image will be repeated on the basic shape, horizontally and vertically. The closed value in the cone and cylinder code determine whether the shape should be open at the ends or closed. Setting it to false means an open ended shape will be drawn. The Steps value used in the cone, cylinder and ellipsoid code sets the number of faces that will be used to draw the rounded sides of the basic shape. Setting it tolow number of sides means you can create shapes that are not rounded like pyramids or diamonds.
If you take a look at the gm6 file that comes with this tutorial and run it, you will see a simple head created by using textured basic shapes. By using the arrow keys you can rotate the model and zoom in and out. In the init_camera script culling has been set to false. When using basic shapes, back face culling can speed up the drawing process making your game faster but only if you know how to use it (see Backface Culling).
In the gm6 file transformation has been used to rotate the basic shape model around its z axis. The character’s head is drawn in the script draw_Character, using the rotation transformation. If you’re not familiar with transformation, I suggest you check out Rolling Ball. Creating 3D models with polygons manually (calculating all the values yourself) is not preferable. The same is true for basic shape models: it’s possible but not preferable. You’re probably better off creating a basic shape modeler for this purpose or use an existing one, created by someone else.