- Title: TheSnidr's Geodesic Dome
- Description: Lets you create geodesic domes
- GM Version: Any (though, the example reqires GM 8.1)
- Registered: Yes
- File Type: .gm81
- File Size: 150kb
- File Link: Host-a | Yoyogames
- Required Extensions: None
- Required DLLs: None
- Credits: Please mention my name
Usually when working with 3D, the shape d3d_model_ellipsoid produces is enough for most uses. However if you, like me, find yourself in a situation where it simply isn't good enough, then this script will come very handy!
Why, you ask?
Well, let's start by looking at a regular sphere. It consists of rectangles that start out wide at the middle, and become thinner and thinner towards the poles.
This means a lot of excessive geometry is gathering at the poles, and you end up with a sphere where the quality of the geometry varies depending on what part you're looking at.
This won't really be a problem for most games - actually, when using a detailed texture, the extra ammount of geometry at the poles will provide a better solution than what I'm about to present.
However, if your main priority is the geometry itself, varying quality is not wanted.
There is one way to avoid this though - by using a geodesic dome.
Basically, a geodesic dome is a type of sphere where all triangles are (practically) the same size, and evenly distributed across the surface.
The bad thing about this is, as opposed to the ellipsoid, the few triangles at the poles will morph the texture ever so slightly.
However, in my opinion, the good things with this method completely weigh that one out:
- Less triangles for practically the same quality sphere
- Impossible to tell what part of the sphere you're looking at - triangles are evenly distributed
- Can be textured like a normal ellipsoid, with an equirectangular texture
- Can also repeat the same texture in all triangles
I'm using this shape in my current project
Creating the geodesic dome
Creating this bad boy isn't too easy, and would take very much time to do yourself (it sure did for me). There's no simple way of creating this with a single loop - we'll have to iterate our way towards a usable sphere!
An iteration basically means placing the result of a function back into the function. Here we're going to start with a basic shape - I've chosen the icosahedron - and run it through the script until it has the desired ammount of triangles.
For each iteration, we're going to halve every line between points - effectively multiplying the ammount of triangles by 4 for each iteration. See this picture:
An icosahedron has 20 faces, so the first iteration will do this process 20 times. We'll then go from this:
This new shape will then have 20 * 4 = 80 faces. If we now repeat this process with the new shape, we'll get one with 20 * 4 * 4 = 80 * 4 = 320 faces:
And voilà! As you can see, the more we iterate, the closer we get to a sphere!
The scripts support any number of iterations, though, keep in mind that the amount of triangles to be created, and thus the processing time, is quadrupled for each iteration. Four iterations produces a sphere with good enough quality for most uses. I would not recommend going over 7 iterations, as the script will then be very slow (and you'll get a hilarious amount of triangles)
Texturing the sphere
You'll have two options when texturing the sphere - equirectangular or repeating texture.
An equirectangular UV mapping is the most usual when texturing a sphere. This will morph the texture to fit the sphere by pushing it together at the top and bottom. Take the world map for example - on a sphere, the south pole isn't a looooong piece of land, but a round one.
To use this way of texturing the sphere, set the last argument, "UV mode", to 0.
The second option is to repeat the texture in every triangle. Nice and simple ^^
Set the UV mode to 1 for this option.
The example (see link at the top of the post) will show you how they both work.
I spent much time trying to find a good method for creating the base icosahedron - as I didn't find any, I ended up hardcoding each of the 20 faces. This took very long time, as I didn't only have to worry about the coordinates, but I had to define them in the correct order, to prevent them from becoming invisible when culling is turned on. So please, if you use these scripts, at least mention my name in the game.
There are two scrips here - both are needed for this to work. After it's added to the game maker file, you won't have to worry about the first one.
Use the second script like you would use d3d_model_ellipsoid.
Edited by TheSnidr, 11 March 2012 - 09:33 PM.