public void Generate(int2 cellIndex) { parentCell = worley.GetCellProfile(cellIndex); vertices = new NativeList <float3>(Allocator.Temp); triangles = new NativeList <int>(Allocator.Temp); random = new Unity.Mathematics.Random((uint)(parentCell.data.value * 1000)); leaves = new Leaves(vertices, triangles); trunk = new Trunk(vertices, triangles, random); baseHeight = simplex.GetSimplex(parentCell.data.position.x, parentCell.data.position.z) * 15; DrawChildCells(worley.frequency * 2); //leaves.Draw(parentCellProfile, 0); trunk.DrawTrunk(parentCell); DrawCellSegments(parentCell); DrawCellLines(parentCell); MakeMesh(); vertices.Dispose(); triangles.Dispose(); }
public Trunk(NativeList <float3> vertices, NativeList <int> triangles, Random random) { this.vertices = vertices; this.triangles = triangles; this.random = random; this.parentCell = new WorleyNoise.CellProfile(); }
void DrawCellSegments(WorleyNoise.CellProfile cell) { for (int i = 0; i < cell.vertices.Length; i++) { UnityEngine.Debug.DrawLine(cell.vertices[i] + cell.data.position, cell.data.position, UnityEngine.Color.red, 100); } }
public WorleyNoise.CellProfile GetCellProfile(NativeArray <WorleyNoise.CellData> nineCells, WorleyNoise.CellData cell) { this.cellPosition = cell.position; this.triangles = bowyerWatson.Triangulate(nineCells); SortTrianglesClockwise(); this.cellVertices = new NativeList <float3>(Allocator.Temp); this.adjacentCells = new NativeList <WorleyNoise.CellDataX2>(Allocator.Temp); this.vertexRotations = new NativeList <float>(Allocator.Temp); GetCellVerticesAndAdjacentCells(); WorldToLocalVertexPositions(); var cellProfile = new WorleyNoise.CellProfile(); cellProfile.data = cell; cellProfile.vertices = new NineValues <float3>(cellVertices); cellProfile.adjacentCells = new NineValues <WorleyNoise.CellDataX2>(adjacentCells); cellProfile.vertexRotations = new NineValues <float>(vertexRotations); triangles.Dispose(); cellVertices.Dispose(); adjacentCells.Dispose(); return(cellProfile); }
void DrawCellLines(WorleyNoise.CellProfile cell) { for (int i = 0; i < cell.vertices.Length; i++) { int next = i == cell.vertices.Length - 1 ? 0 : i + 1; UnityEngine.Debug.DrawLine(cell.vertices[i] + cell.data.position, cell.vertices[next] + cell.data.position, UnityEngine.Color.green, 100); } }
public Leaves(NativeList <float3> vertices, NativeList <int> triangles) { this.vertices = vertices; this.triangles = triangles; this.offset = float3.zero; this.cell = new WorleyNoise.CellProfile(); this.center = float3.zero; this.height = 0; }
void DrawChildCells(float2 frequency) { WorleyNoise childWorley = worley; childWorley.frequency = frequency; float3 meanPointWorld = parentCell.data.position + vectorUtil.MeanPoint(parentCell.vertices); WorleyNoise.CellData startChild = childWorley.GetCellData(meanPointWorld); var checkNext = new NativeQueue <WorleyNoise.CellData>(Allocator.Temp); var alreadyChecked = new NativeList <int2>(Allocator.Temp); checkNext.Enqueue(startChild); alreadyChecked.Add(startChild.index); var children = new NativeList <WorleyNoise.CellProfile>(Allocator.Temp); while (checkNext.Count > 0) { WorleyNoise.CellData childData = checkNext.Dequeue(); WorleyNoise.CellData dataFromParent = worley.GetCellData(childData.position); bool childIsInParent = dataFromParent.index.Equals(parentCell.data.index); if (!childIsInParent) { continue; } WorleyNoise.CellProfile childProfile = childWorley.GetCellProfile(childData); float3 positionInParent = childProfile.data.position - parentCell.data.position; positionInParent.y += baseHeight; leaves.Draw(childProfile, positionInParent); children.Add(childProfile); for (int i = 0; i < childProfile.vertices.Length; i++) { WorleyNoise.CellData adjacent = childProfile.adjacentCells[i].c0; if (!alreadyChecked.Contains(adjacent.index)) { checkNext.Enqueue(adjacent); alreadyChecked.Add(adjacent.index); } } } checkNext.Dispose(); alreadyChecked.Dispose(); }
public void DrawTrunk(WorleyNoise.CellProfile parentCell) { this.parentCell = parentCell; float3 min = new float3(-1, 0, -1); float3 max = new float3(1, 0, 1); NativeArray <int> extruded = TrunkVertices(0.2f); extruded = ExtrudeTrunk(extruded, new float3(0, 1, 0), 0.4f); extruded = ExtrudeTrunk(extruded, random.NextFloat3(min, max) + new float3(0, 3, 0), 0.7f); extruded = ExtrudeTrunk(extruded, random.NextFloat3(min, max) + new float3(0, 3, 0), 0.7f); extruded = ExtrudeTrunk(extruded, random.NextFloat3(min, max) + new float3(0, 3, 0), 0.7f); extruded.Dispose(); }
public void Draw(WorleyNoise.CellProfile cellProfile, float3 offset) { this.offset = offset; this.cell = cellProfile; RemoveSmallSegments(); SoftenAcuteCorners(); this.height = FarthestVertexDistance(); this.center = vectorUtil.MeanPoint(this.cell.vertices); center.y += height * 1.2f; DrawCell(); }
public void AllVerticesAreUnique() { WorleyNoise.CellProfile cell = GetRandomCell(); bool foundMatch = false; for (int v = 0; v < cell.vertices.Length; v++) { for (int m = 0; m < cell.vertices.Length; m++) { if (v != m && cell.vertices[v].Equals(cell.vertices[m])) { foundMatch = true; } } } Assert.IsFalse(foundMatch); }