Thread: Generating an icosphere

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    Generating an icosphere

    Does anyone have any links for this? I used to but every time I google this I get stupid Photoshop, Blender, GIMP, or other tutorials for other apps that I could care less about.

    I know I can start with a geometric primitive like a tetrahedron, dodecahedron, cube, etc, and recursively split it to arrive at my sphere but I forget exactly how to do that.

    Code:
    void CIcoSphere::Split(Vertex &Result,Vertex v1,Vertex v2,Vertex v3)
    {
      D3DXVECTOR3 vec1=v1.Pos-v2.Pos;
      D3DXVECTOR3 vec2=v1.Pos-v3.Pos;
    
      D3DXVec3Lerp(&Result.Pos,&vec1,&vec2,0.5f);
    
      D3DXVECTOR2 vecU=v1.TexCoord1-v2.TexCoord1;
      D3DXVECTOR2 vecV=v1.TexCoord1-v3.TexCoord1;
    
      D3DXVec3Lerp(&Result.TexCoord1,&vecU,&vecV,0.5f);
    }
    Something like that maybe?

    I'm abandoning UV spheres in my game engine because texturing them is far too problematic.
    Last edited by VirtualAce; 07-22-2007 at 06:41 AM.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Update:

    I'm using an icosphere from Blender for my sphere and the texturing is still not working correctly. The only thing left for me is to render a skybox but use a cube texture to represent the environment or backdrop.

    It is simply mathematically impossible to wrap a rectangular 2:1 texture to a sphere, be it icosphere (geodesic), or a simple UV sphere. Distortion happens at the same exact place on both spheres regardless of vertex location.
    The singularities inherent in the trig functions and singularities at the poles of the sphere's is the problem.

    For a good illustration of this in Blender:

    • Create a UV sphere at 0,0,0
    • Split the viewport with left side as 3D view and right side as UV Image editor
    • Load your texture into the UV image editor
    • Press 1 while in the 3D view window - right side view
    • Switch to UV face select mode and press A to select all vertices.
    • Face->Unwrap UVs->Sphere from view
    • Zoom into the sphere and you will notice distortion at the poles.
    • Look at the UV image editor and you can see where the triangles map in relation to the texture
    Last edited by VirtualAce; 07-24-2007 at 11:11 PM.

  3. #3
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    If you are still interested in generating an icosphere instead of loading one, I wrote the following code back in the day. It's also tied into a heightmap (we wanted to wrap a planet around it). The heightmap section doesn't work quite right, because certain subdivided points won't line up, but if you replace heightmap[u][v] with 1, or just load an even heightmap, it will generate a perfect isosphere just fine.

    http://iost.googlecode.com/svn/trunk/sphere.cpp
    Programming Your Mom. http://www.dandongs.com/

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    43
    Why don't you unwrap the mesh and paint the texture onto that instead?
    Then you'll get rid of all apparent singularities that you get at the poles when you just apply a rectangular texture to a sphere. The problem is caused by the topology difference of the objects, there simply isn't a non-distorting way of mapping between a flat map and a sphere, but you can make the distortions arbitrarily small by increasing the tesselation.
    The painted map will of course become distorted but it will look good when you render it instead (the same way as is usually done with faces in FPS, also because of the round nature of heads)

    /f

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I've opted not to generate any texture coords or geometry. Instead I'm using an icosphere from Blender that has been cut apart at the equator. Then in GIMP I create a flat panorama of the system. The top half and bottom half are split and converted to polar coordinates. Then each half is placed on a new texture with a black background. This texture is then loaded into Blender and I place the two unwrapped portions of the sphere on the textured circles in the texture.

    What I end up with is a nearly perfect seamless textured sphere as long as the textures and UV mapping end up being fairly accurate in relation to one another.

    I have some other tricks I'd like to try as well that will place the poles or the most distortion of the spheres at the top and bottom of a spherical texture. Since this area will be very small on both spherical textures the resulting distortion will be minimal in the game world.

    I'm using several programs now to generate all of the in-game data:

    • Blender
    • Wings3D
    • GIMP 2
    • Paint Shop Pro X
    • SkyPaint Panorama Editor v1.10


    Wings3D does not have a blender export nor does it have an X file export. So I export it as a Wavefront OBJ file, import OBJ into Blender, and export from there to X file.

    I should have some in-game screenshots up soon. Modelling and texturing is the biggest obstacle to completing one complete sector for the demo. The code has been about 20% of the battle and the actual creation of game content has been the other 80%.

    This is the only new screenshot I have which doesn't show much more than before. But be assured there have been huge changes to the core engine code, level loading code, 3D orientation system, resource management, and several other systems.

    Also attached a model screenshot from Blender for a light fighter I'm working on.
    Last edited by VirtualAce; 03-12-2011 at 11:41 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating random 2D mountains/terrain
    By Flaug in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2009, 02:49 PM
  2. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  3. help with generating numbers
    By kurz7 in forum C Programming
    Replies: 8
    Last Post: 08-06-2003, 08:29 AM
  4. Generating a random character/letter, stuck!
    By DanFraser in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2003, 11:30 AM
  5. dynamically generating content from an ASP page:
    By edwardtisdale in forum Windows Programming
    Replies: 0
    Last Post: 11-22-2001, 02:44 PM