[11-6-17] Making 3D object using Blitz3D script.

Blitz3D is a really old language for making games, but it has all kinds of useful perks that I enjoy that make it worth putting up with having to inform users to enable DirectPlay. But with all of the easy and useful features, there are a few that prove to be very hard. One such feature is custom script-based meshes in 3D games. What follows is a tutorial to the arduous process of making a mesh.

Fair warning: This tutorial expects that you have experience with the 3D functions of Blitz3D, as I will go into little detail explaining anything other than mesh-related functions. This isn't as much a real tutorial as it is an explaination of how hard it is to make Blitz3D meshes.

Step 1: Concept

A good place to start is with an image of the mesh you want to make, and where all of the edges and vetexes will be. Keep in mind while doing this that the faces can only be triangles, meaning three vertexes/edges to a face. For this tutorial, I'll be making a spaceship.

Step 2: Starting the .bb file and the mesh

I assume that if you're reading this tutorial, you've already downloaded Blitz3D (if not, look it up on Itch.io). The first thing to do is to set the 3D graphics mode, which is what tells the program how, what, and where to draw.

Graphics3D 800, 600

Next, we should start the mesh so that we have some sort of reference. Create a simple function like the one below (don't forget "End Function"!). Using a function will make it easy to replicate our spaceship mesh on the fly.

Function Starship(ship_r, ship_b, ship_g)

We'll want to make sure our frames cap so the game runs at a predictable speed on faster machines. Add this timer to your script under the "Graphics3D" statement:


After that is done, we'll want some way to sample our spaceship and to see how everything looks as we put it together. Use this code to make a simple 3D space, spawn in the starship mesh, and make the ship rotate until the user hits 'esc'.

Try reloading to view image.

If you were to run that now, it would probably throw a ton of errors since we haven't made our starship mesh yet. Let's get on with that...

Step 3: Brushes and surfaces (materials)

As with "real" art, you need to get the materials before you can start making your masterpiece. In Blitz3D, you do this using brushes. You then assign the brush to a surface, which you will see in the next step. You use surfaces when adding faces to a mesh. Assigned to faces when the faces are created, surfaces allow you to choose the color, material, shading, etc. of different faces. For our spaceship: we'll be using these brushes:

Try reloading to view image.

Just place that code at the start of your mesh-spawning function.

Step 4: Making the mesh

Now comes the tedious part: the part where you have to define every vertex and face. When you do this, you have to be careful not to make your faces invert, or you'll see through your mesh. Usually, you would have to do this yourself, but I've already gotten everything done for this tutorial. Just copy this code into your mesh function:

First, we start a new mesh:

ship = CreateMesh()

Now, to make a face, we add out vertexes to a surface. As we add vertexes, they will be assigned an identifier that is exclusive to that vertex on that surface (the vertex IDs are seperate on seperate surfaces). You then take the IDs of the vertexes, then use three to add a face between them.

Make the ship's body:

Try reloading to view image

And the window:

Try reloading to view image

And the wings:

Try reloading to view image

Step 5: Wrapping up

Now, to finalize our mesh, we have to update our normals. This would usually take many lines of code, but Blitz has a nice feature for that:


Lastly, we'll want to return our ship so that our program will actually use the mesh it just assembled:

Return ship

Step6: We're done!

Now save the program, run it, and you should get this:

Picture of finished ship

I encourage you to poke around at the code and see what you can do. I hope that by reading this, you realize how convenient it is that 3D design software exists so that we don't get carpal-tunnel typing in the vertexes for a single low-poly mesh.

If you can't get it to work or are too lazy to do all of that typing, click here to download the finished file.