# TheSnidrs Geodesic Dome

9 replies to this topic

### #1 TheSnidr

TheSnidr

That guy

• Global Moderators
• 2724 posts
• Version:GM:Studio

Posted 09 July 2011 - 06:46 PM

• 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
Summary
Introduction
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!

Explanation
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:

to 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.

The scripts
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.
Spoiler

Spoiler

Edited by TheSnidr, 11 March 2012 - 09:19 PM.

• 1

### #2 Nocturne

Nocturne

Nocturne Games

• 18741 posts
• Version:GM:Studio

Posted 09 July 2011 - 08:49 PM

Nicely written tutorial TheSnidr! Staff picked for quality...

• 0

### #3 TheSnidr

TheSnidr

That guy

• Global Moderators
• 2724 posts
• Version:GM:Studio

Posted 09 July 2011 - 11:30 PM

Sweet, never been a staff choice before ^^

I'm quite impulsive, which often leads to topics being posted before I'm really done writing them. That's why I love the edit button!
• 0

### #4 njp

njp

Panda

• GMC Member
• 2333 posts
• Version:GM8

Posted 23 July 2011 - 01:08 AM

Sweet, never been a staff choice before ^^

I'm quite impulsive, which often leads to topics being posted before I'm really done writing them. That's why I love the edit button!

please make a gmk version. quite a few gm users still use gm 8.0 id like to try this
• 0

### #5 Rani_sputnik

Rani_sputnik

GMC Member

• GMC Member
• 353 posts

Posted 23 July 2011 - 02:27 AM

This is really great, I tried this out a while ago but I never followed through with it. Great to see such a fantastic tutorial on this sort of thing. I've been reading your blog on this for a while, I was secretly hoping you might release some sort of example
• 0

### #6 TheSnidr

TheSnidr

That guy

• Global Moderators
• 2724 posts
• Version:GM:Studio

Posted 23 July 2011 - 07:08 AM

Nic James - Sure, I'll have one ready when I get back from work! (I'll be here for a long time today though...)

And Rani_sputnik, it looks to me like you managed to make it? You have the icosahedron and you have the iteration script. By the way, there is an example available for download at the beginning of the post

Edited by TheSnidr, 23 July 2011 - 12:32 PM.

• 0

### #7 Rani_sputnik

Rani_sputnik

GMC Member

• GMC Member
• 353 posts

Posted 24 July 2011 - 06:52 AM

Oh yeah sorry no I worded that wrong,

I had been secretly hoping you might release some sort of example

Haha didn't realise I'd written that all wrong and yeah I managed to make it, but I couldn't get a good way to texture it or a good way to orbit around it. Very impressed nice work man.
• 0

### #8 sneaky666

sneaky666

536e65616b79

• GMC Member
• 1041 posts
• Version:GM:Studio

Posted 09 January 2012 - 12:02 AM

Can you make an argument that determines if the normals are outward or inward? This would be useful if using lighting with it, and the camera will always be inside.
• 0

### #9 Zesterer

Zesterer

Professor of Articul

• GMC Member
• 1042 posts
• Version:GM8

Posted 26 February 2012 - 02:24 PM

VERY nice. Thanks, this is perfect for making a sky-sphere without the annoying texture stretching at the poles. I imported it into my game, and it works perfectly, and at high speed too.
• 1

### #10 creators124

creators124

awesomeliciousmember

• GMC Member
• 866 posts
• Version:GM8

Posted 19 June 2012 - 12:03 PM

pretty nice job TheSnidr!

I wonder if I put the iteration to 8.
I just did!
wire on, pic:

wire off, pic:

it took a little while but it loaded fine and spinning freely!
so many triangles that it covers the whole globe in black!
I love this geodesic dome tut!
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users