Cosmonium: A 3D astronomy and space exploration program

Yes, that’s the purpose of the application, a crossover between astronomy software, like Celestia and others, and space exploration. So an open-source SpaceEngine (well, after a few more years of development :blush: )

I already have the base to generate full scale procedural planet either with procedurally generated heightmap or procedurally generated textures.

Here is a crappy gif I just took, the camera starts from 2 meters above grounds and raises until being at 500,000km with tiles generated on the fly.


Water is not yet in but it’s on my short term todo list.

Spherical terrain is much more harder to implement than “flat” terrain and much less useful, unless you really want full scale planet. Usually you use flat terrain with a horizon cut off, some fog and a bit of distortion added in the shader to simulate the curvature.
Depending on how it is implemented you could use 6 Panda ShaderHeightmapTerrain to create a cube and apply the spherical distortion in the shader, but you will have to create the bounding volume yourself and I fear the LOD algorithm will no longer work as you displace the vertices in the shader (unless the lod is calculated in the shader, in that case it’s not a problem)

Caves are even harder to implement, usually you need voxels or sdf raymarching to implement them, but I haven’t even considered if I will ever implement them :slight_smile:

1 Like

Okay, thank you for those clarifications.
is your "crappy gif " included in your project on github? I’d like to test it and see how it was done.
Can you manage collisions with a physical engine such as bullet or ODE ?

I have a little criticism with your atmosphere (there is the same problem with the earth), when I have the camera sticking against the ground the sky is not blue enough, we can see the stars when it’s noon.

Yes, you can fly to that planet by pressing Enter,then type Planet Demo and press d to go to the planet.

Alternatively you can just load the procedural demo and start in front of the planet :

 ./ --main data/cosmonium-proc.yaml  --default 'Planet Demo'

The zoom out effect is simply done using the change altitude Home or End and using the function “center camera on selected object” c when high enough to automatically rotate the camera

I would say out of the box no, the generated heightmap is distorted according to the spherical coordinates used (UV, normalization, …) but the displacement is done following the sphere normal. Unless bullet or ODE have a spherical heightmap mode it won’t work. One workaround would be to generate another heightmap which include the projection on the sphere and that would work, I think, with the physic engine as a plain heightmap.

It’s a known problem :slight_smile: I’m using O’Neil atmospheric scattering and it has many limitations (one of them being the sky not blue enough when looking up, the atmosphere too saturated when the sun is in your back, …), in a future version I’ll switch to Bruneton scattering which is one of the best real-time atmospheric scattering. (To be honest, I spent so much time fine tuning the O’Neil scattering that I could have integrated Bruneton instead…)

The still visible stars is also a known problem :slight_smile: I need to implement brightness culling to ignore object not luminous enough and also apply the atmospheric scattering on far objects when looking through the atmosphere. But for that I need first a physically realistic scattering.

At last version 0.1.1 of Cosmonium is available :slight_smile:

Lots of bugfixes in this releases, though many are not directly visible, and a few new features, most notably :

  • Analytic shadows
  • Full menubar
  • Proper seam and crack removal algorithm for procedural planets
  • New noise functions
  • Improved performances
  • Fixed many procedural planet bugs
  • Better OpenGL capabilities detection
  • cel:// url support
  • Improved rendering
  • and so on :slight_smile:

See the changelog for the complete list.

Saturn with proper ring shadows :

An eclipse on the Earth :

The improved terrain :

And the Ralph demo with even more infinite terrain :slight_smile:

It’s still a long way to the final version of Cosmonium, but it’s great to (slowly) progress towards it! I must thanks all the people that tried and send me their comments and criticisms. Also, I must thank a lot rdb and Moguri for their work on Panda and their support :slight_smile:


do you think you can add 3d relief to the planets, with real satelite heightmap ?

It’s already possible with procedural heightmap, so I feel silly not having added support for data based heightmap :slight_smile: I have done the modifications and now (in the develop branch) you can have planet with real relief, if you have the right elevation map :stuck_out_tongue:

Here is Mars with the elevation map generated by the Mars Orbiter, it has a resolution of 563m and an uncertainty of ±3m (Well much worse here as I’m using a simple oblate spheroid and not the correct mars geodetic system). For fun, I used an exaggeration factor of 10x :slight_smile:

You can admire Olympus Mons (on the left), the Tharsis Montes (the three mons at the left of the center) and the impressive Valles Marineris :

And the same in 3D :

You can also add more precise elevation map for some place of interest, but for now on you need to convert the longitude, latitude to the patch coordinates (x, y and lod level) manually, which is cumbersome.

There is still a bug, I think, with the generated normals which shows artifacts when you get too close to the planet. Even with the b-spline interpolator they do not vanish, so probably I’m doing the calculation wrong. I hope to find it and fix it before the next release though :slight_smile:

1 Like

the rendering is really good!
I have friends who teach high school and he was interested in visiting planets for her students
Would you know how to add an object to a planet ? for example apollo 11 lunar module at real coordonate ?
I’m not asking you to add it, just tell me how to add a bam/egg object has a precise coordinate ?

Other question, Is there a basic physics/collision of planets field? For example, to roll a rover to Mars on the field like your ralph example (but in mars and with a rover instead of a ralph)

I’m not asking you to add it, just tell me how to add a bam/egg object has a precise coordinate ?

I added this week-end a more user friendly frame to place object at the surface of a body, here is for the curiosity rover :

    name: Curiosity
    parent: Mars
    radius: 0.0015
      - shape:
          type: mesh
          model: models/vtad-curiosity.glb
          rotation: [0, -90, 0]
        lighting-model: pbr
        attribution: nasa-vtad
      type: surface
      long: 137.4417
      lat: -4.5895
        type: fixed
        position: [0, 0, 0]
        global: false
        type: fixed

And here is the result in app :

But as you see, the resolution of the global elevation map is to coarse and the terrain is almost flat except for a few mountains in the background… There are high resolution DEM available, but they’re huge (the raw DEM for the curiosity landing point is about 23GB) I will write a tool to extract part of them and align it on the low resolution map.

Other question, Is there a basic physics/collision of planets field? For example, to roll a rover to Mars on the field like your ralph example (but in mars and with a rover instead of a ralph)

Ah, well for that it’s not possible yet on a planet, but the building blocks are there : there is a nav mode to “walk” on a planet and follow the terrain, I need to modify it to move not only the camera but also a mesh.

I have friends who teach high school and he was interested in visiting planets for her students
Would you know how to add an object to a planet ? for example apollo 11 lunar module at real coordonate ?

With the latest develop version, it’s now possible :slight_smile: However, Cosmonium is still in heavy development and perhaps more mature tools would be better for your friend (Though I would be happy to learn from their usage and improve it :smiley: )

I looked at the example with Ralph, it looks like he’s not on a spherical planet but a rectangular map, am I wrong?

the interest I see with cosmonium is to be able to easily develop a small scene, like a rocket landing on mars for example.
you instantiate the object in a yaml file (vtad-curiosity.glb) but I would like to be able to manipulate it in python code, is that possible?
if I can manipulate it, I can move it forward or something, right? like any panda3d model?

Cosmonium benefits from the power of python, I have a lot of nice ideas, like developing a small artificial intelligence with genetic algorithm to move the martian rover, or do spaceship combat with tensorflow.

in which file did you add the code for the rover?
edit: I think I get it, we need to edit the mars.yaml file.
how do you add the heightmap?

Yes, The Ralph example uses flat geometry and equirectangular heightmap, it’s much easier to test and validate the terrain engine :slight_smile: The planets on the other hand are using heightmap with projection (either lambertian or spherical)

Well, currently the position of an object is defined by three things, its orbit its rotation and its reference frame. So to control an object you need to modify those. For example, the curiosity rover above has a fixed orbit and a fixed rotation with regard to its reference frame. To move it on the surface of the planet, you only need to change the centre of the surface reference frame. In this case, the orbit and rotation are like the position and orientation of a panda node wrt its parent.

So I need to reuse the code of the “walk” mode and modify it to update the reference frame of an object and you would be able to control any object as if it was on the surface.

That’s the great thing with Python and Panda3D, it’s very easy to program new thing or extend existing thing. Though, as Cosmonium is still in heavy development there is no stable API yet. But looking at new use case helps me to see what is useful from a user point of view and what can be kept internal.

Using the develop branch, you can simply add the file above in the extra directory, it will automatically add the body to the mars system.
Same for the heightmap, you can add an additional surface for any existing bodies, so you don’t need to modify the original file. Except that I just discovered that there is a limitation, the surface texture is not found as it resides in another directory.

Here is how to add a heightmap :

       type: texture
       max-height: 65535
       interpolator: bspline
         type: ctx
         root: textures/Mars_MGS_MOLA_DEM_mosaic_global_463m
         ext: png
         size: 1024

isn’t there a way to control an object as we would normally do with panda3d?
i want to call for example this code in cosmonium (after load rover object into json)

def move_rover(self, task):
    if self.keyMap["forward"]:
        myrover_objet.setY(myrover_objet.getY + 1)
    return task.cont

Moving an object is a bit more complicated than that, especially if you want to keep it on the surface of the planet. To help, I created helper classes to move bodies taking into account their reference frame and position with regard to their parent. I also added a controller class which can be used to add behavior to objects in the engine.Finally I added basic plugin support, so in the yaml file you can link a controller to a body.

Here as an example the Curiosity rover making a loop on the procedural planet demo :


The controller code is quite simple :

from cosmonium.controllers import BodyController
from cosmonium.astro import units

from math import pi

class TurnBody(BodyController):

    def update(self, time, dt):
        self.mover.turn_relative(pi / 100 / units.Sec * dt)
        self.mover.step_relative(0.001 / units.Sec * dt)

ControllerClass = TurnBody

And in the curiosity yaml file I added the reference to the controller :

      name: turn
      file: modules/

(To be honest this is a bad example, the position is modified by delta so the errors will accumulate over time, especially if the simulation speed is increased. Instead one should keep a reference position and do updates relatives to it)

The new code is mostly there :

There is also now a hidden feature, select the object, type ‘Control-T’ and a debug nav mode will be created to control the displacement of the body using the keyboard (The camera will be stuck in place, I still need to add proper follow camera mode and so on)

1 Like

I don’t understand where I have to put the code.
I add a curiosity.yaml file in the data folder and I add the models and modules folder ?
but after this how can I go see my object on mars?

I looked at your last few commits, is cockpit class for the camera?

Exactly like that, you put the code in the modules directory and you put a reference in the yaml file, like the model actually. Here is a zip with everything included, you can extract it in the extra directory and it should be loaded when you start the app :

Note that you need the latest snapshot of the development branch.

That’s like any other objects, you can select them by pressing the Tab key then enter their name, then press G to go to them, or use the wheel to navigate to it. You can go to the help menu, you have the list of all the navigation shortcuts you can use.
Beware that you could end up upside down or under the surface (I still have to work on that), but you can orbit the camera around the object easily.

Yes, I’m working on adding spacecrafts and ships. The cockpit is used to attach elements to the node holding the camera when you’re inside the spacecraft (But there is still lots of work to do :slight_smile: )

thanks for your help but it’s not work for me, i extract zip files in data file

when i start cosmonium, cosmonium not load curiosity.yaml
I’m in windows 10, i use develop branch and i pull this branch.

data directory is extra directory ?

The data directory is not scanned recursively, to load add-ons you have to put them in the user extra directory, on Windows it should be C:\Users\AppData\Local\cosmonium\extra
You could also add them in data/extra in the Cosmonium directory (as the directory was empty it was not present in the git repository, I added a inside it now).

thank you very much, it works!

I dont’ undestand how add heightmap for Mars
i download Mars_MGS_MOLA_DEM_mosaic_global_463m heightmap jpg:

i copy this image in data/solar-system/mars/textures
i edit data/solar-system/mars/mars.yaml like this:

    name: Mars System
    orbit: mars
        - planet:
            name: Mars
            radius: 3396.2
            ellipticity: 0.00589
            albedo: 0.150
            point-color: [1, 0.75, 0.7]
                - category: visible
                      texture: textures/mars-surface-vanvliet/mars-surface-vanvliet.ctx
                      normalmap: textures/mars-normal-vanvliet/mars-normal-vanvliet.ctx
                      attribution: vanvliet
            rotation: mars
               type: texture
               max-height: 65535
               interpolator: bspline
                 type: ctx
                 root: textures/Mars_MGS_MOLA_DEM_mosaic_global_463m.jpg
                 ext: png
                 size: 1024
        - moon:
            name: Phobos
            radius: 27
            albedo: 0.071
                - category: visible
                      type: mesh
                      model: phobos-thomas.ply
                      attribution: [thomas, frieger]
                      create-uv: true
                      texture: textures/phobos-bw-stooke.png
                      attribution: stooke
                  lighting-model: oren-nayar
                - category: topographic
                      texture: textures/phobos-topographic-thomas.jpg
                      attribution: thomas
                  lighting-model: flat
            orbit: phobos
            rotation: phobos
        - moon:
            name: Deimos
            radius: 15
            albedo: 0.068
                - category: visible
                      type: mesh
                      model: deimos-thomas.ply
                      attribution: [thomas, frieger]
                      create-uv: true
                      texture: textures/deimos-bw-stooke.png
                  lighting-model: oren-nayar
            orbit: deimos
            rotation: deimos

can i use extra folder for add heightmap to mars ? or i must edit original mars.yaml file ?

You can use the extra folder to add a new surface to an existing body, but you can not reference the texture of another surface, which means you have to copy the texture to the extra directory. I should find a way to be able to link textures from other surfaces.

It can not work because your heightmap is a texture and you are using as the root directory of a virtual texture. You should simply set data to your file. Also, you should comment out the normalmap from the appearance, because it will conflict with the normals generated using the heightmap.

For reference, here is the full heightmap :

And here is the modified mars.yaml I’m using :

i replace mars.yaml with your file and add Mars_MGS_MOLA_DEM_mosaic_global_463m folder in /data/solar-system/mars/textures but i have an error when i go to Mars:
File “cosmonium\cosmonium\”, line 121, in copy_from
self.lod = heightmap_patch.lod
AttributeError: ‘NoneType’ object has no attribute ‘lod’