Created
November 3, 2022 12:33
-
-
Save 0xF6/5403badbd3b18dcc7cc87b993cd6a6a9 to your computer and use it in GitHub Desktop.
Generate grid and cast to cubesphere side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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