Texture2D AltGenTex(Vector3[] verts, ModuleBase module) { Texture2D tex = new Texture2D((int) Mathf.Sqrt(verts.Length), (int) Mathf.Sqrt(verts.Length)); int reso = (int) Mathf.Sqrt(verts.Length); int pixelx = 0; int pixely = 0; for (int i = 0; i < verts.Length; i++) { verts[i] = transform.TransformPoint(verts[i]); if (pixelx == reso) { pixelx = 0; pixely += 1; } float noiseval = (float) module.GetValue(verts[i]); noiseval = Mathf.Clamp(noiseval + 0.5f, 0f, 1f); Color pixelColor = new Color(noiseval, noiseval, noiseval, 0); tex.SetPixel(pixelx, pixely, pixelColor); tex.Apply(); pixelx += 1; } tex.Apply(); return tex; }
public bool ConditionMet(int x, int y, int z, ModuleBase noise) { if (y < 4) return false; if (z%4 != 0) return false; if (x%4 != 0) return false; return noise.GetValue(x/10.0, y/10.0, z/10.0) > 0.5; }
//Allows objects to be placed with ease by useing lat, long(-180, 180) public Vector3 SurfacePoint(float latitude, float longitude, float raddif, ModuleBase noi, GameObject planetObject) { GenerateNoise(); Mathf.Clamp(latitude, -90, 90); Mathf.Clamp(longitude, -180, 180); Vector3 spoint; float lat = latitude * Mathf.PI/180; float lon = longitude * Mathf.PI/180; float rad = radius; spoint.x = (-rad * Mathf.Cos(lat) * Mathf.Cos(lon)); spoint.y = (rad * Mathf.Sin(lat)); spoint.z = (rad * Mathf.Cos(lat) * Mathf.Sin(lon)); spoint = spoint + planetObject.transform.position; //cubedpoint = (cubizePoint2(spoint.normalized) * radius) + planetObject.transform.position; //((float) noi.GetValue((truevpos[i].normalized * radius) + planetPos)) * noisemod) //truevpos = position - planetpos //((truevpos[i].normalized * radius) + planetPos) //(float) noi.GetValue((truevpos[i].normalized * radius) + planetPos)) * noisemod) Vector3 trueplanetPos = spoint - planetPosition; raddif = (float) noi.GetValue(spoint); //Debug.Log(raddif); rad = radius + (raddif * noisemod); spoint.x = (-rad * Mathf.Cos(lat) * Mathf.Cos(lon)); spoint.y = (rad * Mathf.Sin(lat)); spoint.z = (rad * Mathf.Cos(lat) * Mathf.Sin(lon)); //noi.GetValue(truevpos[i])) * noisemod) //rad = (float) noise.GetValue((cubizePoint2(spoint.normalized) * radius) - transform.position); //Debug.Log(rad); return (spoint + planetObject.transform.position); }
Texture2D GenerateTexture(Vector3 start, Vector3 end, int resolution, ModuleBase noise) { Texture2D texture = new Texture2D(resolution, resolution); //since this is for square planes texture is always square texture.Apply(); //Cases for planes on a cube Vector3 testpoint = start; float addamount; if (start.x == end.x) //Then get y and z { Debug.Log(xc); int pixelx = 0; int pixely = 0; addamount = Mathf.Abs(start.y - end.y)/ resolution; //Gets the amount to add to testpoint for (int i = 0; i < resolution*resolution; i++) { if (pixelx == resolution) { pixelx = 0; pixely += 1; } if (pixely == resolution) { //This shouldn't happen ever but if it does add code to end loop } if (testpoint.y == end.y) { testpoint.y = start.y; testpoint.z += addamount; } if (testpoint.z == end.z) { //Shouldn't happen either, but in case add code to stop loop } if (testpoint.y < end.y) { //Do the getting value and setting value on texture, then //addamount to tespoint.y and +=1 on pixelx float pixelval = (float) noise.GetValue(testpoint); pixelval = Mathf.Clamp(pixelval + 0.5f, 0f, 1f); Color pixelColor = new Color(pixelval, pixelval, pixelval, 0); texture.SetPixel(pixelx, pixely, pixelColor); texture.Apply(); pixelx += 1; testpoint.y += addamount; } } } if (start.y == end.y) //Then get x and z { Debug.Log(yc); int pixelx = 0; int pixely = 0; addamount = Mathf.Abs(start.x - end.x)/ resolution; //Gets the amount to add to testpoint for (int i = 0; i < resolution*resolution; i++) { if (pixelx == resolution) { pixelx = 0; pixely += 1; } if (pixely == resolution) { //This shouldn't happen ever but if it does add code to end loop } if (testpoint.x == end.x) { testpoint.x = start.x; testpoint.z += addamount; } if (testpoint.z == end.z) { //Shouldn't happen either, but in case add code to stop loop } if (testpoint.x < end.x) { //Do the getting value and setting value on texture, then //addamount to tespoint.y and +=1 on pixelx float pixelval = (float) noise.GetValue(testpoint); pixelval = Mathf.Clamp(pixelval + 0.5f, 0f, 1f); Color pixelColor = new Color(pixelval, pixelval, pixelval, 0); texture.SetPixel(pixelx, pixely, pixelColor); texture.Apply(); pixelx += 1; testpoint.x += addamount; } } } if (start.z == end.z) //Then get x and y { Debug.Log(zc); int pixelx = 0; int pixely = 0; addamount = Mathf.Abs(start.x - end.x)/ resolution; //Gets the amount to add to testpoint for (int i = 0; i < resolution*resolution; i++) { if (pixelx == resolution) { pixelx = 0; pixely += 1; } if (pixely == resolution) { //This shouldn't happen ever but if it does add code to end loop } if (testpoint.x == end.x) { testpoint.x = start.x; testpoint.y += addamount; } if (testpoint.y == end.y) { //Shouldn't happen either, but in case add code to stop loop } if (testpoint.x < end.x) { //Do the getting value and setting value on texture, then //addamount to tespoint.y and +=1 on pixelx float pixelval = (float) noise.GetValue(testpoint); pixelval = Mathf.Clamp(pixelval + 0.5f, 0f, 1f); Color pixelColor = new Color(pixelval, pixelval, pixelval, 0); texture.SetPixel(pixelx, pixely, pixelColor); texture.Apply(); pixelx += 1; testpoint.x += addamount; } } } return texture; }
void Spherify(float radius, ModuleBase noi) { Vector3[] vertices = qMesh.vertices; Vector3[] verticesN = qMesh.vertices; Vector3[] normals = qMesh.normals; Vector3[] truevpos = qMesh.vertices; for (int i = 0; i < vertices.Length; i++) { truevpos[i] = (transform.TransformPoint(vertices[i])) - planetPos; verticesN[i] = (((truevpos[i].normalized) * (radius + (((float) noi.GetValue((truevpos[i].normalized * radius) + planetPos)) * noisemod)))) - (relativePos); //Debug.Log(planetMaker.name + (truevpos[i].normalized * radius)); } transform.rotation = Quaternion.Euler(0,0,0); qMesh.vertices = verticesN; qMesh.RecalculateNormals(); qMesh.RecalculateBounds(); }
Texture2D AltGenTex(Vector3[] verts, ModuleBase module) { Texture2D tex = new Texture2D((int) Mathf.Sqrt(verts.Length), (int) Mathf.Sqrt(verts.Length)); Vector3[] interpolatedPoints = new Vector3[verts.Length]; int reso = (int) Mathf.Sqrt(verts.Length); int pixelx = 0; int pixely = 0; for (int i = 0; i < verts.Length; i++) { if (i < verts.Length - 1) { interpolatedPoints[i] = ((verts[i] + verts[i+1])/2); } verts[i] = transform.TransformPoint(verts[i]) - planetPos; if (pixelx == reso) { pixelx = 0; pixely += 1; } float noiseval = (float) module.GetValue((verts[i].normalized * rad) + planetPos); noiseval = Mathf.Clamp((noiseval + 0.5f)/2f, 0f, 1f); Color pixelColor = new Color(noiseval, noiseval, noiseval, 0); tex.SetPixel(pixelx, pixely, pixelColor); tex.Apply(); pixelx += 1; } tex.wrapMode = TextureWrapMode.Clamp; tex.Apply(); return tex; }
// Use this for initialization void Start() { PerlinGenerator = new Perlin(); float random = UnityEngine.Random.Range(-99999f, 99999f); Debug.Log(string.Format("Accepted x:{0}, y:{1}, z:{2} and got {3}", random, random, random, PerlinGenerator.GetValue(new Vector3(random, random, random)))); int ChunkCount = Mathf.CeilToInt(Radius / Chunk.CHUNK_SIZE); for (int x = -ChunkCount; x < ChunkCount; x++) { Debug.Log(string.Format("Planet creation is on iteration x:{0}", x)); for (int y = -ChunkCount; y < ChunkCount; y++) { for (int z = -ChunkCount; z < ChunkCount; z++) { CreateChunk(x * 16, y * 16, z * 16); } } } GenerationComplete = true; }