public void UpdateUVs(ColourGenerator colourGenerator) { Vector2[] uv = mesh.uv; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) //Iterate over entire face { int i = x + y * resolution; Vector2 percent = new Vector2(x, y) / (resolution - 1); //Tells us how far through the loop we are Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB; Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; //used to go from a cube to a sphere uv[i].x = colourGenerator.BiomePercentFromPoint(pointOnUnitSphere); } } mesh.uv = uv; }
public void UpdateUVs(ColourGenerator colourGenerator) { Vector2[] uv = mesh.uv; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { int i = x + y * resolution; Vector2 percent = new Vector2(x, y) / (resolution - 1); Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB; Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; uv[i].x = colourGenerator.BiomePercentFromPoint(pointOnUnitSphere); } } mesh.uv = uv; }
public void UpdateUVs(ColourGenerator colourGenerator) { Vector2[] uv = new Vector2[_resolution * _resolution]; for (int i = 0; i < _resolution; i++) { for (int j = 0; j < _resolution; j++) { int loop = i + j * _resolution; Vector2 percent = new Vector2(i, j) / (_resolution - 1); Vector3 pointOnUnitCube = _localUp + (percent.x - 0.5f) * 2 * _axisA + (percent.y - 0.5f) * 2 * _axisB; Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; uv[i] = new Vector2(colourGenerator.BiomePercentFromPoint(pointOnUnitSphere), 0); } } _mesh.uv = uv; }
public void UpdateUVs(ColourGenerator colourGenerator) { var uv = mesh.uv; for (var y = 0; y < resolution; y++) { for (var x = 0; x < resolution; x++) { var i = x + y * resolution; var percent = new Vector2(x, y) / (resolution - 1); var pointOnCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB; var pointOnSphere = pointOnCube.normalized; uv[i].x = colourGenerator.BiomePercentFromPoint(pointOnSphere); } } mesh.uv = uv; }
// ********************************************************************** // public void UpdateUVs(ColourGenerator colourGenerator) { // keep everything that generates colours separate from mesh generation. This way we dont have to wait for mesh to regenerate when we update colours Vector2[] uv = mesh.uv; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { int i = x + y * resolution; // this is a counter, same as setting int i=0 outside y loop and incrementing on inner loop Vector2 percent = new Vector2(x, y) / (resolution - 1); Vector3 pointOnUnitCube = localUp + (percent.x - 0.5f) * 2 * axisA + (percent.y - 0.5f) * 2 * axisB; // geometry magic from youtube tutorial Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; uv[i].x = colourGenerator.BiomePercentFromPoint(pointOnUnitSphere); } } mesh.uv = uv; }
public void UpdateUVs(ColourGenerator colourGenerator) { Vector2[] uv = mesh.uv; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { int i = x + y * resolution; // how close to complete each of these loops is Vector2 percent = new Vector2(x, y) / (resolution - 1); Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB; // transform the current planar cube as a spherical/round plane Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; uv[i].x = colourGenerator.BiomePercentFromPoint(pointOnUnitSphere); } } mesh.uv = uv; }
public void UpdateUVs(ColourGenerator colourGenerator) { Vector2[] uv = mesh.uv; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { int i = x + y * resolution; // number of total iterations Vector2 percent = new Vector2(x, y) / (resolution - 1); // percent on the x-axis and y-axis, between 0 and 1 Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB; // sum of base vectors Vector3 pointOnUnitSphere = pointOnUnitCube.normalized; uv[i].x = colourGenerator.BiomePercentFromPoint(pointOnUnitSphere); } } // Update class parameter mesh.uv = uv; }