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 :

spacecraft:
    name: Curiosity
    parent: Mars
    radius: 0.0015
    surfaces:
      - shape:
          type: mesh
          model: models/vtad-curiosity.glb
          rotation: [0, -90, 0]
        lighting-model: pbr
        attribution: nasa-vtad
    frame:
      type: surface
      long: 137.4417
      lat: -4.5895
    orbit:
        type: fixed
        position: [0, 0, 0]
        global: false
    rotation:
        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 :

    heightmap:
       type: texture
       max-height: 65535
       interpolator: bspline
       data:
         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)
        myrover_objet.loop("run")
    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 :

Imgur

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 :

    controller:
      name: turn
      file: modules/turn.py

(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 : https://github.com/cosmonium/cosmonium/blob/develop/cosmonium/controllers.py

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
cosmonium\data\curiosity.yaml
cosmonium\data\models
cosmonium\data\modules

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 README.md 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:
system:

system:
    name: Mars System
    orbit: mars
    children:
        - planet:
            name: Mars
            radius: 3396.2
            ellipticity: 0.00589
            albedo: 0.150
            point-color: [1, 0.75, 0.7]
            surfaces:
                - category: visible
                  appearance:
                      texture: textures/mars-surface-vanvliet/mars-surface-vanvliet.ctx
                      normalmap: textures/mars-normal-vanvliet/mars-normal-vanvliet.ctx
                      attribution: vanvliet
            rotation: mars
            heightmap:
               type: texture
               max-height: 65535
               interpolator: bspline
               data:
                 type: ctx
                 root: textures/Mars_MGS_MOLA_DEM_mosaic_global_463m.jpg
                 ext: png
                 size: 1024
        - moon:
            name: Phobos
            radius: 27
            albedo: 0.071
            surfaces:
                - category: visible
                  shape:
                      type: mesh
                      model: phobos-thomas.ply
                      attribution: [thomas, frieger]
                      create-uv: true
                  appearance:
                      texture: textures/phobos-bw-stooke.png
                      attribution: stooke
                  lighting-model: oren-nayar
                - category: topographic
                  appearance:
                      texture: textures/phobos-topographic-thomas.jpg
                      attribution: thomas
                  lighting-model: flat
            orbit: phobos
            rotation: phobos
        - moon:
            name: Deimos
            radius: 15
            albedo: 0.068
            surfaces:
                - category: visible
                  shape:
                      type: mesh
                      model: deimos-thomas.ply
                      attribution: [thomas, frieger]
                      create-uv: true
                  appearance:
                      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 : https://www.dropbox.com/s/214ufko7s6us324/Mars_MGS_MOLA_DEM_mosaic_global_463m.zip?dl=0

And here is the modified mars.yaml I’m using : https://www.dropbox.com/s/xenr5c88azcdr1m/mars.zip?dl=0

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\heightmap.py”, 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: