Cosmonium: A 3D astronomy and space exploration program

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’

I can reprocduce your problem, the actual error is a few line before in the log :

 File textures/Mars_MGS_MOLA_DEM_mosaic_global_463m/level0/tx_1_0.png not found

That means you haven’t copied the heightmap virtual texture at the right place or with the wrong name.

Now the app you display an error to the user and use a default value for the heightmap instead of crashing like that… So many things to do, so few time :slight_smile:

I thank you for the api you added, I can do almost anything I want.
I was able to put an interactive lunar base.
I hope your program will meet with success, the possibilities of modding are enormous.

Thank you for the feedback, it’s nice to know I’m going in the right direction and what I’m doing is useful :slight_smile:

After more than a year, here is a new version of Cosmonium, v0.2.0 ! What started as a simple bugfix release ended up with tons of new features (and bugfixes too :slight_smile: )

The engine

The engine itself got many bugfixes and improvements, notably the most time consuming functions are now ported to C++, which gives a huge performance boost.
Basic support for object control with scripting is added. It’s now possible to add a cockpit on your screen or even a full ship and follow it around.
Procedural generation got some attention too, glitches and seams are mostly gone now, several more noise sources and functions are available. Rings can also be procedurally generated now.


The rendering engine got PBR support for the rendering of the glTF models.
The atmospheric scattering has been improved too and is much more realistic (though not yet perfect), it provides atmospheric extinction on all the objects seen through an atmosphere.

Eclipse shadows now also support non-spherical objects; object self shadowing is also improved with configurable bias and PCF filtering.
Stereoscopic rendering is available, full VR support is for the next release though.
As a proof of concept, there is also a volumetric raymarching engine, it can already be used to generate diffuse and emission nebulae.

User interface

The use interface has been greatly improved, thanks to the work of @Epihaius, @Moguri @Thaumaturge, @wolf. Using their libraries, you can now edit some of the parameters of the bodies and see the changes in real time! The application parameters can be edited from a window instead of modifying a hidden yaml file. You can also open a embedded browser to get more information about most of the object you see. And lastly, you have a file selector to load scripts or to select the screenshot directory.

It’s now also possible to select point-like objects with the mouse. There is internationalization support (with French now available).


Well, that’s the purpose of this app after all :slight_smile: The orbits and rotation models of all the main planets and moons of the solar system are now using accurate theories. This means their position and orientation should be much more realistic. The eclipses and transits in the app are now occurring at the correct time and with the right configuration.

Missing moons and newly discovered objects have been added.

Next steps

For the next release, I plan to redo the core engine and port more of the time consuming code, like the geometry generation, to C++; and make it more robust. This will allow adding many more stars and objects!
The rendering will get improvements with Bruneton atmospheric scattering, environment map, proper exposure correction, VR support, …

The new installers and binaries for Windows, Mac and Linux are available here. And for the curious, see the changelog for much more details.


This looks really impressive! It seems that you’ve improved upon the last version greatly! :slight_smile:

(And I’m glad that my contributions have been of service. ^_^)

1 Like