- (sphere-mesh RADIUS RESOLUTION [type: TYPE] [normals? NORMALS?] [texture-width: TEXTURE-WIDTH] [texture-height: TEXTURE-HEIGHT] [texture-offset: TEXTURE-OFFSET] [cube-map? CUBE-MAP?] [texture: TEXTURE] [color: COLOR] [winding: WINDING] [mode: MODE] [texture-type: TEXTURE-TYPE] [color-type: COLOR-TYPE] [index-type: INDEX-TYPE])procedure
Create a spherical mesh of RADIUS with the centre of the sphere at the origin. Depending on TYPE, the way the sphere is created will differ: #:uv will create a UV sphere – with vertices positioned on longitude/latitude points – #:cube will create a cube sphere – with vertices positioned on a deformed cube. The former is useful for 2D texture mapping, but will necessarily have increasingly large deformation towards the poles, and lower resolution near the equator. The latter is useful for a cube-mapped texture, for minimal deformation. The images below illustrates a UV sphere and cube sphere, respectively.
For the UV sphere, RESOLUTION sets the number of longitudinal subdivisions, half of which is the number of latitudinal subdivisions (RESOLUTION must be a factor of 2). Setting both TEXTURE-WIDTH and TEXTURE-HEIGHT for a UV sphere causes 2 element texture coordinates to be added to the mesh, with TEXTURE-OFFSET representing the upper left corner of the texture, defaulting to (0 0). The texture’s upper left corner is mapped to the left side of the sphere, wrapping counter-clockwise such that the left half of the texture corresponds to the front half of the sphere. Alternately, TEXTURE may be supplied, which expects a function of one argument: the index of a vertex. This texture function should return a two element list of the texture coordinate at that index. The cube mesh vertices are ordered as a rectangular array with RESOLUTION + 1 columns and RESOLUTION/2 + 1 rows. The first row corresponds to the “north” pole, while the last corresponds to the “south” pole. The first column has the same position as the last. This array is wrapped counter-clockwise around the sphere, starting on the left. Likewise, COLOR expects a similar function that accepts one index as an argument, but should return a three element list of colour values.
For the cube sphere, RESOLUTION sets the number of vertical and horizontal subdivision of each face of the cube. Like the cube mesh, each face of the cube has a unique set of vertices – i.e. no face shares vertices. When CUBE-MAP? is #t, three element texture coordinates are added to the mesh, corresponding to a unit-sphere. Alternately, TEXTURE may be supplied, which expects a function of one argument: the index of a vertex. This texture function should return a three element list of the texture coordinate at that index. The cube mesh vertices are ordered as follows: each face is a rectangular array of RESOLUTION + 1 by RESOLUTION + 1 points, and the faces are ordered (front right back left top bottom), the same as the cube-mesh faces. Likewise, COLOR expects a similar function that accepts one index as an argument, but should return a three element list of colour values.
For both types of spheres, when NORMALS? is #t, normals are added to the mesh. WINDING controls the direction of the vertex winding, either counter-clockwise (#:ccw, the default), or clockwise (#:cw). MODE should be a valid argument to mode->gl, defaulting to #:triangles. TEXTURE-TYPE, COLOUR-TYPE, and INDEX-TYPE control the in-memory type of the texture attribute, the color attribute, and the index, and should be a valid argument to type->gl. TEXTURE-TYPE defaults to #:float for cube spheres and #:ushort for UV spheres, while COLOUR-TYPE and INDEX-TYPE default to #:ushort.