Skip to content

Instantly share code, notes, and snippets.

@0xF6
Created November 3, 2022 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xF6/5403badbd3b18dcc7cc87b993cd6a6a9 to your computer and use it in GitHub Desktop.
Save 0xF6/5403badbd3b18dcc7cc87b993cd6a6a9 to your computer and use it in GitHub Desktop.
Generate grid and cast to cubesphere side
public void Generate(Vector3 localUp = Vector3.up)
{
var axisA = new Vector3(localUp.y, localUp.z, localUp.x);
var axisB = Vector3.Cross(localUp, axisA);
for (var y = 0; y < Resolution; y++)
for (var x = 0; x < Resolution; x++)
{
var percent = new Vector2(x, y) / (Resolution - 1);
var pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;
var pointOnUnitSphere = pointOnUnitCube.normalized;
SphereCube.Add(pointOnUnitCube * Resolution);
Sphere.Add(pointOnUnitSphere * Resolution);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment