Class GalaxyGenerator

java.lang.Object
gaiasky.scene.record.GalaxyGenerator

public class GalaxyGenerator extends Object
Generates galaxies as lists of BillboardDataset objects.
  • Constructor Details

    • GalaxyGenerator

      public GalaxyGenerator()
  • Method Details

    • generateGalaxyName

      public static String generateGalaxyName()
    • generateGalaxy

      public Pair<BillboardDataset[], BillboardDataset[]> generateGalaxy(GalaxyGenerator.GalaxyMorphology gm, long seed)
      Generates galaxies given a morphology, as billboard datasets only.
      Parameters:
      gm - The galaxy morphology.
      seed - The RNG seed.
      Returns:
      A couple of BillboardDataset arrays, the first being the full-resolution channel, and the second being the half-resolution channel.
    • generateGalaxySpec

      public GalaxySpec generateGalaxySpec(GalaxyGenerator.GalaxyMorphology gm, long seed)
      Generates the complete description of a galaxy given a morphology: its billboard datasets and the volume fields that describe the same gas, bulge and dust analytically.

      Both come from a single seeded draw, so the volume of a hybrid galaxy is the one its billboards describe. No extra random numbers are consumed when building the volume fields - they are copies of the descriptors this draw already produced - which is why a seed yields the same billboards as it did before the volume path existed.

      Parameters:
      gm - The galaxy morphology. If null, one is picked at random and recorded in the spec.
      seed - The RNG seed.
      Returns:
      The spec, which is never null.
    • getRandomColors

      public double[] getRandomColors(double[][] colorMatrix)
    • convertToJson

      public com.badlogic.gdx.utils.JsonValue convertToJson(com.badlogic.ashley.core.Entity full, com.badlogic.ashley.core.Entity half)
    • convertToHybridJson

      public com.badlogic.gdx.utils.JsonValue convertToHybridJson(com.badlogic.ashley.core.Entity billboard, com.badlogic.ashley.core.Entity volume)
      Converts a hybrid galaxy into a JSON descriptor: the billboard entity with its compact emitters, and the child volume entity that carries the density fields of the diffuse channels.
      Parameters:
      billboard - The billboard entity of the pair.
      volume - The child volume entity of the pair.
      Returns:
      The descriptor, ready to be printed.
    • convertVolumeToJson

      public com.badlogic.gdx.utils.JsonValue convertVolumeToJson(com.badlogic.ashley.core.Entity e)
      Converts the volume half of a hybrid galaxy into a JSON object.

      A volume entity is a plain Volume archetype: a unit sphere scaled by the body size, with the galaxy shader and the field list that VolumeInitializer voxelises at load time. No material is written: a procedural volume without one gets a default material, which is exactly what this galaxy was built with.

      Parameters:
      e - The volume entity.
      Returns:
      The descriptor of the entity.
    • toJsonString

      public static String toJsonString(com.badlogic.gdx.utils.JsonValue json)
      Serialises a descriptor for export.

      Deliberately not JsonValue.toJson(JsonWriter.OutputType): that path prints a whole double as an integer literal (0.0 becomes 0, see JsonValue.toJson(OutputType, Writer)), so positionPc and every other double attribute comes back from the file as a Long/int[] and the loader finds no setPositionPc(double[]). Pretty printing keeps the decimal point, and is easier to read and hand-edit besides.

      Parameters:
      json - The descriptor.
      Returns:
      The JSON text.
    • fieldsToJson

      public static com.badlogic.gdx.utils.JsonValue fieldsToJson(GalaxyAttributes[] fields)
    • convertToJson

      public com.badlogic.gdx.utils.JsonValue convertToJson(com.badlogic.ashley.core.Entity e)