Skip to main content
GeometricMesh         Creating various geometric/geodesic shapes

The tutorial and the code are written by User:sphinkie.

You can also react to this article in the forum

Credits

Thanks to Snowblind for the ManualSphereMeshes and its "shape to mesh" algorithm.

Thanks to Richard J. Bono for the geodesic algorithm (GNU licence) and the
winDome utility.

Download

 Plugin disabled
Plugin attach cannot be executed.

Presentation

In this article, I will present a way to generate various geometric shapes. This article gives information about the library, the concept, and how to use it.


The UV mapping applied on all shapes is a spherical mapping. The library can be upgraded for bugfix, optimization and adding new shapes.

All the sources can be found at the end of the article.

How to use the library

The API is quite simple, and you can built it using the utility doxygen (as the source files are doxygen compatible).
When you create the object, you give the parameters needed: usually radius, and some others. It depend of the kind of shape you are creating. Then you call the createMesh method, giving the name of the mesh. You will use the same name when creating your Ogre entity.

  • Example 1: creating a cube with a halfside of 100 units:

Copy to clipboard
#include "Mesh_Cube.h" ... Mesh_Cube M(100); M.createMesh("myMesh"); mEntity = mSceneMgr->createEntity(mName, "myMesh"); mNode->attachObject(mEntity);

Geometrik_cube.jpg : A textured cube

  • Example 2: creating a geosphere with a radius of 800 units:

Copy to clipboard
#include "Mesh_geosphere.h" ... Mesh_Geosphere M(800); // radius 800 - default frequency - default class 1 // Mesh_Geosphere M(800, 4, true); // radius 800 - frequency 4 - class 2 M.createMesh("myMesh"); ... // extra functions available for geodesic shapes: M.dumpData(); // write data inthe log file M.createDXF("geosphere.dxf"); // create a DXF file M.createDXFwireframe("geosphere_WF.dxf"); // create a DXF file ... mEntity = mSceneMgr->createEntity(mName, "myMesh"); mNode->attachObject(mEntity);

For geodesic shapes, you have some more functions in the API that allow you to dump geometrical data in the log file, and to create a DXF file, so you can preview the shape in your favorite 3D modeler (ie: blender3D).

Geometrik_planet.jpg : A textured geosphere

  • Example 3: creating a sphere with a radius of 800 units.:

Copy to clipboard
#include "Mesh_sphere.h" ... Mesh_Sphere M(800); M.createMesh("myMesh"); mEntity = mSceneMgr->createEntity(mName, "myMesh"); mNode->attachObject(mEntity);

Geometrik_sphere.jpg : A wireframe sphere

GeometricMesh

The library is based on 2 generic classes : GeometricMesh and Geodesic.

GeometricMesh allows you to create geometric meshes, when given a certain number of vertices and triangles.

The GeometricMesh class itself cannot create any meshes. This class should be derived from, with a function fillMesh() defining the positions of all vertices.

Existing derived class are: Mesh_Cube, Mesh_Icosa, Mesh_Sphere.
New classes can be easily added (cylinder, etc).

  • In a Cube, or an Icosahedron, there is a small number of vertices (around 10 or 20), so the list of vertices can be manually defined.
  • In a Sphere, a simple function can be use to define all the vertex positions (thanks to the 'snowblind' equation). A function also allows you to create spheres with a parameterizable number of vertices.
  • But to create a geosphere, a more complex function is needed, and we will need another class (Geodesic) to generate the list of vertices for these shapes.

Geodesic

Geodesic shapes a large family of shapes, usually used in architecture for domes, honeycomb, etc. For us, we are only interrested a the subfamily based on assembly of triangles. (you can also have assembly of hexagons or pentagons).
The Geodesic class itself gives you no shape: it has to derived into classes that define the equation of the points of the shapes.
Existing class are Mesh_geosphere and Mesh_geoellipse.
New classes can be added, but it is not so easy...

Geosphere is a good shape for planets, as is has less texture distortion at the pole (like the usual sphere has).

Geoellipse allow you to create Zeppelin shapes, flying saucers, eggs...

geometrik_geosphere_c1.jpg Class 1 geosphere

geometrik_geosphere_c2.jpg Class 2 geosphere

geometrik_geoellipse_c2.jpg Class 2 geoellipse

Bibliography

Source files

This is 1.1 version. All source files are in this zip file:

 Plugin disabled
Plugin attach cannot be executed.


The API can be found here Dead Link


To compile you may need these lines in your macros.h.

Copy to clipboard
#define DEBUG_LOG(X) Ogre::LogManager::getSingleton().logMessage(X) #define TRACE(X) Ogre::LogManager::getSingleton().logMessage(X)

Or these lines, if you want to disable the debug log.

Copy to clipboard
#define DEBUG_LOG(X) #define TRACE(X) Ogre::LogManager::getSingleton().logMessage(X)

known bugs:

  • odd frequency with a class 2 geosphere give strange results.



Todo list

For the moment, if you want to add/modify the source code, please send me your files and I will update the zip file, or use the Discussion tab of this page.

These functionnalities are not implemented yet in the library:

  • Une the new MeshFactory, available in the 'Dagon' version of Ogre3D.
  • Optimization of the vertex number. When the vertice list is defined by a function, it usually creates several vertices for the same point. ie: if a point belongs to 5 triangles, 5 vertices are usually generated for this point.
  • New shape : A Cylinder
  • New shape : A Torus
  • In the geosphere, there are 2 points with X=0 and Z=0 (the poles). This makes the calculation of U coordinate difficult. The solution is maybe to pitch a bit the shape before transforming it into a mesh.


See also