Bill2462

Planetary Twister [V0.3] - Random Solar System Generator

Recommended Posts

Planetary Twister

What is this ?

Planetary Twister is a  solar system generator application for kerbal space program. 

It utilizes pseudo random number generator and coherent noise library (libnoise) to produce unique solar system each time you run it. 

Features :

  • Build-in terrain generator. 
  • Build in orbit parameters generator. 
  • Basic copernicus configuration generator. 
  • Build-in planet pack exporter. 

Planned features :

  • Advance map generator. 
  • Oceans generator. 
  • Atmosphere generator. 
  • Ring generator.
  • Surface texture generator. 

 

Note : This project is still in early alpha stage. 

Supported platforms

  • Linux

(Windows version is coming soon).

 

How to use?

Spoiler

Quick Start Guide for V0.3

Step 1 - Main configuration

Main configuration for the generator is stored in config/config.cfg file.

So far you can configure 4 parameters :

  • Number of planets in the system.
  • Maximum number of objects in the system (including planets).
  • Size of generated textures.
  • Optional stock system removal option.

Example of the main configuration :


[PlanetNumber] <2,3>
[max_objectNumber] <10>
[map_size] <4096,2048>
[remove_stock] <1>

NOTE : In general, all parameters in a Planetary Twister configuration are saved in this format :

[name] <parameter1,parameter2,...,some_parameter>

Note: There must be no space between "<" and a number and also no space between a number and data separator (","). Note2: When writing real numbers you must use "." instead of ",". Example : Correct form : 12.3 , Incorrect form : 12,3.

List of all main configuration parameters :

  • Planet number : [PlanetNumber] <min_number,max_number> -> Maximum and minimum number of planets in the solar system.
  • Maximum number of objects in the system : [max_objectNumber] <someNumber -> Maximum number of objects in the in the solar system (including moons). NOTE : This number must be at least higher than a max_number parameter.
  • Map size : [map_size] <X_size,Y_size> -> Output map size (in pixels).
  • Stock system removal option : [remove_stock] <1> -> 0 = disabled, 1 = enabled. When enabled this option will remove all stock planets except kerbin, moon and minimus.

Step 2 - Writing Copernicus configuration template

Next step is to write a Copernicus configuration template. To create a new template, first we have to create a text file in resources/templates directory. Every template file must have .template extension to be properly detected.

Next, we have to write a Copernicus mod configuration for our new object.

Here is an example configuration that I will use for this tutorial :


@Kopernicus:AFTER[Kopernicus]
{
    Body
    {
        name = Example_name

        Properties
        {
          radius = 22000
          geeASL = 0.1
          description = This is an example template. 
          timewarpAltitudeLimits = 0 4163 8325 16650 33300 66600 133200 266400
          rotationPeriod = 13000
          tidallyLocked = false
          initialRotation = 30
        }
        Orbit
        {
            referenceBody = Sun
            color = 0.3,0.1,0.5,1
            inclination = 10
            eccentricity = 0.1
            semiMajorAxis = 13132341453
            longitudeOfAscendingNode = 12
            argumentOfPeriapsis = 0
            meanAnomalyAtEpoch = 4.5
            epoch = 11.2
        }
        
        ScaledVersion
        {
        fadeStart = 111000    
        fadeEnd = 222000
            Material
            {    
           texture = somewhere/planet/color.png
           normals = somewhere/planet/normal.png
            }
        }

          PQS
        {

            Mods
            {

        VertexHeightMap
                {
                    map = somewhere/planet/heighmap.png
                     deformity = 12000
                     scaleDeformityByRadius = false
                     order = 20
                     enabled = true
                }    
        
                VertexColorMap
                {
                    map = somewhere/planet/color.png
                    order = 20
                    enabled = true
                }
            }
        }
     }
  }

Next, we have to add some variables to it. In the output configuration, each variable will be replaced with some value.

Variables are declared using "&" character :

Variable declaration syntax : &variable_name&

Example : Deformity = &deformity&

In this example, "&deformity&" will be replaced with some numeric value.

Note: Maximum value, minimum value, and type of each variable is defined inside template data file.

Special variables :

  • Planet name : &planetName& -> Randomly generated name of the object.
  • Height map patch : &heightmapPatch& -> Patch to height map.
  • texturePatch : &texturePatch& -> Patch to color map.
  • normalsPatch : &normalsPatch& -> Patch to normal map.
  • Reference body : &referenceBody& -> Name of the reference body.
  • radius : &radius& -> Object radius. %@
  • geeASL : &geeASL& -> Object surface gravity. %@
  • Semi Major Axis : &semiMajorAxis& -> Semi major axis of the object's orbit. *@

% -> This variable must be used in every template.

@ -> This variable must be also declared in the template data file. (But name must not be changed).

Example copernicus template :


@Kopernicus:AFTER[Kopernicus]
{
    Body
    {
        name = &planetName&

        Properties
        {
        radius = &radius&
        geeASL = &geeASL&
        description = This is an example template. 
        timewarpAltitudeLimits = 0 4163 8325 16650 33300 66600 133200 266400
        rotationPeriod = &rotationPeriod&
        tidallyLocked = &tidallyLocked&
        initialRotation = 30    
        }
    
        Orbit
        {
            referenceBody = &referenceBody&
            color = &R&,&G&,&B&,1
            inclination = &inclination&
            eccentricity = &eccentricity&
            semiMajorAxis = &semiMajorAxis&
            longitudeOfAscendingNode = &longitudeOfAscendingNode&
            argumentOfPeriapsis = &argumentOfPeriapsis&
            meanAnomalyAtEpoch = &meanAnomalyAtEpoch&
            epoch = &epoch&
        }
        
        ScaledVersion
        {
        fadeStart = 111000    
        fadeEnd = 222000
            Material
            {    
             texture = &texturePatch&
             normals = &normalsPatch&
            }
        }

          PQS
        {

            Mods
            {

        VertexHeightMap
                {
                    map = &heightmapPatch&
                     deformity = &deformity&
                     scaleDeformityByRadius = false
                     order = 20
                     enabled = true
                }    
        
                VertexColorMap
                {
                    map = &texturePatch&
                    order = 20
                    enabled = true
                }
            }
        }
     }
  }

Step 3 - Creating template data file

Next we have to setup template data file. It contains all information necessary for planet configuration to be generated. To create it, we have to create new text file in resources/data and name it : template_name.data. (template_name = name of the template = name of the copernicus configuration template)

Each template data file consists of three parts :

  • Variable declaration module. -> Contains declarations of all variables used in a template.
  • Color gradients list. -> Contains a list of color gradients used by map generator to create planet terrain color.
  • Moon override module. -> Contains settings applied when a template is used to generate moon.

Here is the structure of the template data file :


[variables]
{
}

[colors]
{

}

[moon]
{

}

First we will setup variable declarations. Every variable (except for some special ones) must be declared inside variable declaration module.

Variable declaration syntax : [variable_name] <variable_type,variable_minimum_value,variable_maximum_value>

  • Variable_name -> Name of the variable.
  • Variable_type -> Type of the variable, they are 3 types available :
    • integer -> Returns integer type value ( it can return numbers from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
    • real -> Returns real type value (it can return numbers from 2.2250738585072014e-308 to 1.7976931348623158e+308, but keep in mind that it also has 15 digits of precision)
    • bool -> It can return true or false.
  • variable_minimum_value -> Minimum value of the variable.
  • variable_maximum_value -> Maximum value of the variable.

Generator will pick a random numeric value between variable_minimum_value and variable_maximum_value.

When using bool type you can skip minimum and maximum value declaration. In this case syntax will look like this : [variable_name] <bool,>.

Example :


[variables]
{

    [radius] <integer,90000,200000>
    [geeASL] <real,0.2,0.6>
    [rotationPeriod] <integer,21600,345600>
    [tidallyLocked] <bool,>

    [R] <real,0,1>
    [G] <real,0,1>
    [B] <real,0,1>
    [inclination] <real,0,25>
    [eccentricity] <real,0.01,0.2>     
    [semiMajorAxis] <integer,9000000000,40000000000>
    [longitudeOfAscendingNode] <real,0,10>
    [argumentOfPeriapsis] <real,0,10>
    [meanAnomalyAtEpoch] <real,0,10>
    [epoch] <real,0,10>

    [deformity] <integer,9000,11000>
}

Next we will create the list of color gradients. Those gradients are used by the map generator to create terrain color map.

syntax :


    [color]
    {
        <R,G,B>// color used for the highest parts of the terrain 
        <R,G,B>
        <R,G,B>
        <R,G,B>
        <R,G,B>
        <R,G,B>
        <R,G,B>
        <R,G,B>// color used for the lowest parts of the terrain 
    }

Each gradient consists of eight colors enclosed between {}.
Each color is written in RGB format (R = Red, G = Green, B = Blue).

Note: Each template data file must contain at least one color gradient (maximum number is unlimited). Note2: Generator always uses a random gradient from the list.

Example of the complete color gradient list :


[colors]
{
    [color]
    {
        <142,142,123>//highest terrain color 
        <148,148,131>
        <154,154,140>
        <160,160,149>
        <166,166,157>
        <172,172,166>
        <178,114,175>
        <184,178,184>//lowest terrain color 
    }

    [color]
    {
        <186,157,74>
        <193,165,89>
        <200,173,105>
        <208,181,121>
        <215,189,137>
        <223,197,153>
        <230,205,169>
        <238,214,185>
    }


    [color]
    {
        <201,201,201>
        <192,191,191>
        <183,182,182>
        <219,217,217>
        <232,228,228>
        <201,201,201>
        <188,139,109>
        <199,145,123>
    }

}

Next we have to create moon override module. It contains settings used for moon generation.

Syntax :


[moon]
{
    [max_radius] <MAX_RADIUS>
    [min_radius] <MIN_RADIUS>
    [max_SMA] <MAX_SMA> 
    [min_SMA] <MIN_SMA> 
    [max_gASL] <MAX_GASL>
    [min_gASL] <MIN_GASL>
}
  • MAX_RADIUS -> Maximum moon radius ( 1 = 100 % of the planet's radius, 0 = 0% of planet's radius).
  • MIN_RADIUS -> Minimum moon radius ( 1 = 100 % of the planet's radius, 0 = 0% of planet's radius).
  • MAX_SMA -> Maximum semi major axis of the moon's orbit (1 = 100 % of the planet's SOI, 0 = 0% of planet's SOI).
  • MIN_SMA -> Minimum semi major axis of the moon's orbit (1 = 100 % of the planet's SOI, 0 = 0% of planet's SOI).
  • MAX_GASL -> Maximum moonar surface gravity (1 = 100 % of the planet's surface gravity, 0 = 0% of planet'surface gravity)
  • MIN_GASL -> Minimum moonar surface gravity (1 = 100 % of the planet's surface gravity, 0 = 0% of planet'surface gravity)

Example :


[moon]
{
    [max_radius] <0.5> //50% of a mother object radius
    [min_radius] <0.1> // 10% o a mother object radius 
    [max_SMA] <0.6> //90% of a planet SOI 
    [min_SMA] <0.09> //9% of a planet SOI
    [max_gASL] <0.4> //40% of a mother object gravity
    [min_gASL] <0.1> //3% of a motherf object gravity
}

Step 4 - Creating terrain data file

Next we have to create terrain data file. It contains all settings for map generator. To create it we have to create a text file in resources/terrains and name it : template_name.terrain (template_name = name of the template).

File syntax :


//base terrain is generated using perlin noise module 
module[base_terrain]
{
    //terrain settings 
    [frequency] <0.3>
    [lacunarity] <2.0>
    [octaveCount] <6>
    [persistence] <0.5>

    //scale settings 
    [bias] <0> //bias
    [scale] <0.5> //scale 
}

module[bumps]
{
    //terrain settings 
    [frequency] <0.3>
    [lacunarity] <2.0>
    [octaveCount] <7>
    [persistence] <0.5>

    //scale settings 
    [bias] <0> //bias
    [scale] <0.2> //scale 
}


//bumps are generated using rigged multifractal module 
module[mountains]
{
    //terrain settings 
    [frequency] <0.4>
    [lacunarity] <2.0>
    [octaveCount] <7>

    //scale settings 
    [bias] <0.1> //bias
    [scale] <1> //scale 
}

As you can see it contains three modules. Each module is responsible for one layer of the heightmap :

  • base_terrain -> Contains settings for noise map used to generate base terrain. (Base terrain uses Perlin noise module)
  • bumps -> Contains settings for noise map used to generate some small terrain bumps. (Bumps are generated using Perlin noise module)
  • mountains -> Contains settings for noise map used to generate mountains. (Mountains are generated using rigged multifractal noise).

Each layer of the map is scaled using scale bias module and then added to the final map using libnoise add module.

For documentation of each parameter please refer to the libnoise doc:http://libnoise.sourceforge.net/docs/classnoise_1_1module_1_1Module.html

Step 4 - Creating name list

The last thing that we have to do is to create name list. It's just a text file (in resources/name.list) used as a source for object names.

Syntax :


[name]
  • Name -> Name

Example :


[Nemesis]
[Vulcan]
[Tycho]
[Cyran]

Step 5 - Final steps

After configuration setup it's time to generate our solar system. To do that we have open terminal and :

  1. Change the working directory to Planetary Twister using cd command.
  2. Run the executable using ./planetaryTwister command.
  3. Wait until the generation process is completed. Note: This might take a while.

Next, it's time to import generated solar system into the game.

To do that, first we have to install Copernicus mod (https://forum.kerbalspaceprogram.com/index.php?/topic/140580-131-kopernicus-release-2-oct-07/) and then move contents of resoults/gameData directory into gameMainDirectory/gameDatadirectory. After this step, when we launch the game, we should see new planets in the tracking station.

Screenshots

Example solar system generated from default configuration  : 

qHIumiL.png

jX5Hvje.png

ia8UISY.png

 

Installation 

  1. Go to https://github.com/Bill2462/Planetary-Twister/releases and download the latest release.
  2. Unzip downloaded file.

 

Changelog

Spoiler

Changelog

V0.3

  • Added moon generation.
  • Added tutorial.md
  • Added makefile
  • Added stock system removal option.
  • Major code cleanup.

V0.2

  • Improved template configuration system.
  • Improved configuration
  • Added basic map generator configuration.
  • Improved examples.
  • Better console output.

V0.1

  • Initial release.

Source Code 

The source code is available on Github : 

https://github.com/Bill2462/Planetary-Twister

 

Licensing

This project is distributed under GNU General Public License v3.0.

Edited by Bill2462

Share this post


Link to post
Share on other sites

New version is coming soon!

Major changes : 

  • Ability to create custom settings for each planet template. 
  • Basic control over map generation process. 
  • Redesigned configuration system (one configuration file per template). 
  • Major code cleanup (including some changes needed for future implementation of multithreading). 
  • More example templates and configs. 

Share this post


Link to post
Share on other sites

Version V0.2 was released!

Changelog:

  • Changed template configuration system.
  • Added ability to add different configuration for each template.
  • Added basic map generator configuration.
  • Improved examples.
  • Better console output.
     

Share this post


Link to post
Share on other sites

Awesome, I was just searching for a mod to do random star systems in KSP. Are you also planning to add some options to also generate different starting worlds in the future instead of preserving the Kerbin system?

 

Would it be possible to integrate this into the game at some point? I don't know much about how the KSP engine works and when the system is generated (during the loading screen? after loading a savegame?), but it would be awesome to have a different map for each savegame (or the same ones if you choose the same seed).

Edited by Lord Aurelius

Share this post


Link to post
Share on other sites
On 16.11.2017 at 3:49 AM, Lord Aurelius said:

Awesome, I was just searching for a mod to do random star systems in KSP. Are you also planning to add some options to also generate different starting worlds in the future instead of preserving the Kerbin system?

 

Would it be possible to integrate this into the game at some point? I don't know much about how the KSP engine works and when the system is generated (during the loading screen? after loading a savegame?), but it would be awesome to have a different map for each savegame (or the same ones if you choose the same seed).

Yes, I'm planning to add different starting world option but there is still a lot of work to do beforehand. Now I'm working on a better terrain generator and improved configuration system. This will take a while.

Unfortunately ksp does not allow for having different solar system in each save. And because of that there is no point in integrating this into the game.

 

Share this post


Link to post
Share on other sites

Man, looking forward to the Windows version. :D I hope we'll see planets with seas too. I was waiting for such mod so long, I requested it in the past.

I noticed you also made a topic on polish forums. Gratulacje! :wink:

Share this post


Link to post
Share on other sites

This is.....I am speechless

Awesum?  Im not sure that is good enough.

what language is it written in?

Share this post


Link to post
Share on other sites
2 minutes ago, linuxgurugamer said:

what language is it written in?

If you look at the source, you can see that it's written in C++.

Also, this mod is amazing!

On 11/25/2017 at 7:00 AM, Bill2462 said:

Unfortunately ksp does not allow for having different solar system in each save. And because of that there is no point in integrating this into the game.

There is Planetary Diversity, which has a different seed for each save and generates random systems before your save can be played...

https://github.com/StollD/Planetary-Diversity

Share this post


Link to post
Share on other sites

@Bill2462 Please keep on this mod, it's exactly what I have been wanting that Planetary Diversity and other RNG solar system mods could never provide; planets that are actually different from stock.

I am really looking forward to seeing atmosphere, ocean, and gas giant generation soon (not necessarily rings, those are overrated) as well as unique terrain prefabs like a "Potatus" planet! At least, I hope that's possible...

Maybe we can get a CKAN release once some of those features come? :wink:

Edited by Pavel ☭

Share this post


Link to post
Share on other sites

Hey i would like to talk to you mod dev if you can talk ot me on discord @zaos#0340 that would be great

 

Share this post


Link to post
Share on other sites
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.