private void GenerateCactusClusters() { for (int i = 0; i < cactusCluster.subclusters; i++) { Vector3 subPos = cactusCluster.location.position + Random.insideUnitSphere * cactusCluster.radius;//y coord doesn't matter subPos.y = 0; List <Vector2> points = UniformPoissonDiskSampler.SampleCircle(new Vector2(subPos.x, subPos.z), cactusCluster.subclusterRadius, cactusCluster.objectRadius); for (int j = 0; j < points.Count; j++) { Vector3 treePos = new Vector3(points[j].x, 0, points[j].y); RaycastHit hit; if (!Physics.Raycast(treePos + Vector3.up * 200, Vector3.down, out hit, 250, groundMask)) { return; } treePos.y = hit.point.y; //if (Physics.OverlapSphere(treePos, treeRadius, resourceMask).Length > 0)continue; if (Random.value > cactusCluster.objectProbability) { continue; } GameObject go = Instantiate(GetRandom(cactusCluster.objectPrefab), treePos, Quaternion.identity); float scaleFactor = (Vector3.Distance(subPos, treePos) / cactusCluster.subclusterRadius) * Random.Range(1f, 2f); go.transform.localScale = go.transform.localScale * Mathf.Max(0.5f, scaleFactor); go.transform.localRotation = Quaternion.Euler(0, Random.Range(0, 360f), 0); cacti.Add(go); } } }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) { points.Clear(); Clear(); } if (Input.GetKeyDown(KeyCode.Return)) { Clear(); var sampler = UniformPoissonDiskSampler.SampleCircle(Vector2.zero, generationSize, generationMinDistance); points = sampler.Select(point => new Vector2(point.x, point.y)).ToPoints().ToList(); Debug.Log($"Generated Points Count {points.Count}"); Create(); return; } if (!Input.GetMouseButtonDown(0)) { return; } var target = Camera.main.ScreenToWorldPoint(Input.mousePosition); points.Add(new Point(target.x, target.y)); Create(); }
public void GenerateMap(float mapSize, float delaunayRMin) { blueNoisePoints = UniformPoissonDiskSampler.SampleCircle(Vector2.zero, mapSize / 2, delaunayRMin); delaunator = new Delaunator(blueNoisePoints.ToPoints()); DrawDelaunay(); DrawVoronoi(); // fill heightmap into y coordinates cellPoints = HeightField.PerlinIsland(blueNoisePoints, mapSize, 0.1f, 0.7f, 4f, 3f, 6); map = new Map(cellPoints.Count); SpawnCells(delaunator, cellPoints); var camHeight = mapSize * 0.5f / Mathf.Tan(Camera.main.fieldOfView * 0.5f * Mathf.Deg2Rad); Camera.main.transform.position = new Vector3(0, camHeight * 1.1f, 0); }
private void GenerateRockClusters() { for (int i = 0; i < rockCluster.subclusters; i++) { Vector3 subPos = rockCluster.location.position + Random.insideUnitSphere * rockCluster.radius;//y coord doesn't matter subPos.y = 0; List <Vector2> points = UniformPoissonDiskSampler.SampleCircle(new Vector2(subPos.x, subPos.z), rockCluster.subclusterRadius, rockCluster.objectRadius); // Debug.Log(points.Count); for (int j = 0; j < points.Count; j++) { Vector3 treePos = new Vector3(points[j].x, 0, points[j].y); treePos += (treePos - subPos) * UniformPoissonDiskSampler.NextGaussian(); RaycastHit hit; if (!Physics.Raycast(treePos + Vector3.up * 200, Vector3.down, out hit, 250, groundMask)) { return; } treePos.y = hit.point.y; //if (Physics.OverlapSphere(treePos, treeRadius, resourceMask).Length > 0)continue; if (Random.value > rockCluster.objectProbability) { continue; } GameObject go = Instantiate(GetRandom(rockCluster.objectPrefab), treePos, Quaternion.identity); float scaleFactor = (1 / (1 + 0.1f * Vector3.Distance(treePos, subPos))); go.transform.localScale = go.transform.localScale * scaleFactor * Random.Range(0.7f, 1f); go.transform.localRotation = Quaternion.Euler(0, Random.Range(0, 360f), 0); rocks.Add(go); } } }
private void InitializeAccumulationDof() { _lazyAccumulationDofPoissonDiskSamples = Lazier.Create(() => Reorder(UniformPoissonDiskSampler.SampleCircle(_accumulationDofIterations))); _lazyAccumulationDofPoissonSquareSamples = Lazier.Create(() => UniformPoissonDiskSampler.SampleSquare(_accumulationDofIterations, false).ToArray()); }
private void GenerateGeneralCluster() { List <Vector2> points = UniformPoissonDiskSampler.SampleCircle(new Vector2(generalCluster.location.position.x, generalCluster.location.position.z), generalCluster.radius, generalCluster.objectRadius); // Debug.Log("Success " + points.Count); for (int j = 0; j < points.Count; j++) { Vector3 treePos = new Vector3(points[j].x, 0, points[j].y); treePos += treePos * (1 - UniformPoissonDiskSampler.NextGaussian()); RaycastHit hit; if (!Physics.Raycast(treePos + Vector3.up * 200, Vector3.down, out hit, 250, groundMask)) { continue; } treePos.y = hit.point.y; // if (Physics.OverlapSphere(treePos, generalCluster.objectRadius, resourceMask).Length > 0)continue; if (Random.value > generalCluster.objectProbability) { continue; } GameObject go = Instantiate(GetRandom(generalCluster.objectPrefab), treePos, Quaternion.identity); float scaleFactor = 1; go.transform.localScale = go.transform.localScale * scaleFactor * Random.Range(0.7f, 1f); go.transform.localRotation = Quaternion.Euler(0, Random.Range(0, 360f), 0); general.Add(go); } /*for (int i = 0; i < generalCluster.subclusters; i++) * { * Vector3 subPos = generalCluster.location.position + Random.insideUnitSphere * generalCluster.radius;//y coord doesn't matter * subPos.y = 0; * * List<Vector2> points = UniformPoissonDiskSampler.SampleCircle(new Vector2(subPos.x, subPos.z), generalCluster.subclusterRadius, generalCluster.objectRadius); * Debug.Log(points.Count); * * for (int j = 0; j < points.Count; j++) * { * Vector3 treePos = new Vector3(points[j].x, 0, points[j].y); * treePos += (treePos - subPos) * UniformPoissonDiskSampler.NextGaussian(); * * RaycastHit hit; * if (!Physics.Raycast(treePos + Vector3.up * 200, Vector3.down, out hit, 250, groundMask)) return; * treePos.y = hit.point.y; * * if (Physics.OverlapSphere(treePos, generalCluster.objectRadius, resourceMask).Length > 0)continue; * if (Random.value > generalCluster.objectProbability) continue; * * GameObject go = Instantiate(GetRandom(generalCluster.objectPrefab), treePos, Quaternion.identity); * float scaleFactor = 1; * go.transform.localScale = go.transform.localScale * scaleFactor * Random.Range(0.7f, 1f); * go.transform.localRotation = Quaternion.Euler(0, Random.Range(0, 360f), 0); * * general.Add(go); * } * }*/ }