Class CubeSphereCreator
-
Nested Class Summary
Nested classes/interfaces inherited from class ModelCreator
ModelCreator.Face, ModelCreator.IFaceModifier and TypeClassDescriptionclassContains the index info for a face.static interface -
Field Summary
Fields inherited from class ModelCreator
binormals, faces, flipNormals, hardEdges, index, name, normals, tangents, uv, vertices -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate(float radius, int divisions) Creates a cube-sphere model.create(float radius, int divisions, boolean flipNormals) Creates a cube-sphere model.create(float radius, int divisions, boolean flipNormals, boolean useBetterMapping) Creates a cube-sphere model with a choice of cube-to-sphere mapping.Methods inherited from class ModelCreator
addFace, addVertex, dumpObj, flipModifier and TypeMethodDescriptionprotected voidaddFace(List<ModelCreator.IFace> faces, boolean flipNormals, int... v) protected intaddVertex(com.badlogic.gdx.math.Vector3 p) Adds a vertex.voiddumpObj(OutputStream os) Exports the model to the .obj (Wavefront) format in the given output stream.protected int[]flip(int[] v, int startIndex)
-
Constructor Details
-
CubeSphereCreator
public CubeSphereCreator()
-
-
Method Details
-
create
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
Creates a cube-sphere model. Start with a cube where each face containsdivisions x divisionsquads, 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 viauseBetterMapping = 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
useBetterMappingis 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.
-