public override void OnNodeProcess() { if (chunkSizeHasChanged) output.Resize(chunkSize); //recalcul perlin noise values with new seed / position. if (needUpdate) { float scale = 40f; output.Foreach((x, y) => { float nx = (float)x * step + chunkPosition.x; float ny = (float)y * step + chunkPosition.z; float val = PerlinNoise2D.GenerateNoise(nx / scale, ny / scale, 2, 2, 1, 1, seed); for (int i = 0; i < octaves; i++) val *= 1.2f; return val; }); } }
static List <Vector2> GenerateRoomVertices(Vector2 p, ROOM_TYPE type) { List <Vector2> verts = new List <Vector2>(); float roomScale = 1; float noiseScale = 0.05f; int nVertices = 40; float degPadd = (360f / nVertices); float deg = 125; float rx = Random.Range(1f, 1.5f); float ry = Random.Range(1f, 1.5f); for (int i = 0; i < nVertices; i++, deg += degPadd) { float x = Mathf.Cos(deg * Mathf.Deg2Rad); float y = Mathf.Sin(deg * Mathf.Deg2Rad); Vector2 roomPoint = new Vector2(x * rx, y * ry); float noiseModifier = PerlinNoise2D.GenerateNoise(x + p.x, y + p.y, .05f, 2); noiseModifier = (noiseModifier - .5f) * 2 * noiseScale; verts.Add(p + roomPoint * roomScale + (roomPoint * noiseModifier)); } return(verts); }