Class CubeSphereCreator

java.lang.Object
gaiasky.render.gdx.creators.ModelCreator
gaiasky.render.gdx.creators.CubeSphereCreator

public class CubeSphereCreator extends ModelCreator
  • Constructor Details

    • CubeSphereCreator

      public CubeSphereCreator()
  • Method Details

    • create

      public CubeSphereCreator create(float radius, int divisions)
      Creates a cube-sphere model.
      Parameters:
      radius - The radius of the sphere.
      divisions - The number of subdivisions per face edge (must be > 0).
      Returns:
      This creator.
    • create

      public CubeSphereCreator create(float radius, int divisions, boolean flipNormals)
      Creates a cube-sphere model. Start with a cube where each face contains divisions x divisions quads, then project each vertex onto the sphere. By default uses Phil Nowell's mapping, which produces much more uniform triangle sizes than simple normalization. The old normalize-and-scale method is available via useBetterMapping = false.

      UVs are computed from the final spherical direction (longitude/colatitude), using the same convention as SphereCreator (u=1 at longitude 0, decreasing eastward; v=0 at the north pole, 1 at the south pole). This makes any standard equirectangular texture (e.g. a whole-Earth map) line up correctly, and lets a UV-sphere and cube-sphere share the same texture.

      Because a flat square face can span more than 180 degrees of longitude around the poles, three of the six faces (-X, +Y, -Y) cross the longitude seam (u wraps from ~1 back to ~0). Vertices along that seam are duplicated with u shifted by +-1 so no quad stretches across the whole texture.

      Parameters:
      radius - The radius of the sphere.
      divisions - The number of subdivisions per face edge (must be > 0).
      flipNormals - Whether to reverse triangle winding (flip normals).
      Returns:
      This creator.
    • create

      public CubeSphereCreator create(float radius, int divisions, boolean flipNormals, boolean useBetterMapping)
      Creates a cube-sphere model with a choice of cube-to-sphere mapping.

      When useBetterMapping is true, Phil Nowell's formula is used:

      s.x = x * sqrt(1 - y²/2 - z²/2 + y²z²/3)
      s.y = y * sqrt(1 - x²/2 - z²/2 + x²z²/3)
      s.z = z * sqrt(1 - x²/2 - y²/2 + x²y²/3)
      
      where (x,y,z) is the cube vertex in [-1,1]³. The result s is on the unit sphere, producing much more uniform triangle sizes.

      When false, the simple normalize-and-scale method is used.

      Parameters:
      radius - The radius of the sphere.
      divisions - The number of subdivisions per face edge (must be > 0).
      flipNormals - Whether to reverse triangle winding (flip normals).
      useBetterMapping - If true, use Phil Nowell's mapping; otherwise normalize-and-scale.
      Returns:
      This creator.