private Mesh GetMesh(int index) { SgtHelper.ClearCapacity(positions, 1024); SgtHelper.ClearCapacity(coords0, 1024); SgtHelper.ClearCapacity(indices, 1024); SgtHelper.ClearCapacity(colors, 1024); SgtHelper.ClearCapacity(normals, 1024); if (index >= Meshes.Count) { var newMesh = SgtHelper.CreateTempMesh("Aurora Mesh (Generated)"); Meshes.Add(newMesh); return(newMesh); } var mesh = Meshes[index]; if (mesh == null) { mesh = Meshes[index] = SgtHelper.CreateTempMesh("Aurora Mesh (Generated)"); } return(mesh); }
public void UpdateMesh() { if (Mesh == null) { Mesh = SgtHelper.CreateTempMesh("Lightning"); } else { Mesh.Clear(false); } var detailAddOne = Detail + 1; var positions = new Vector3[detailAddOne * detailAddOne]; var coords = new Vector2[detailAddOne * detailAddOne]; var indices = new int[Detail * Detail * 6]; var invDetail = SgtHelper.Reciprocal(Detail); for (var y = 0; y < detailAddOne; y++) { for (var x = 0; x < detailAddOne; x++) { var vertex = x + y * detailAddOne; var fracX = x * invDetail; var fracY = y * invDetail; var angX = (fracX - 0.5f) * Size; var angY = (fracY - 0.5f) * Size; // TODO: Manually do this rotation positions[vertex] = Quaternion.Euler(angX, angY, 0.0f) * new Vector3(0.0f, 0.0f, Radius); coords[vertex] = new Vector2(fracX, fracY); } } for (var y = 0; y < Detail; y++) { for (var x = 0; x < Detail; x++) { var index = (x + y * Detail) * 6; var vertex = x + y * detailAddOne; indices[index + 0] = vertex; indices[index + 1] = vertex + 1; indices[index + 2] = vertex + detailAddOne; indices[index + 3] = vertex + detailAddOne + 1; indices[index + 4] = vertex + detailAddOne; indices[index + 5] = vertex + 1; } } Mesh.vertices = positions; Mesh.uv = coords; Mesh.triangles = indices; }
private Mesh GetOrNewMesh(SgtQuadsModel model) { var mesh = model.Mesh; if (mesh == null) { mesh = SgtHelper.CreateTempMesh("Quads Mesh (Generated)"); model.SetMesh(mesh); } else { mesh.Clear(false); } return(mesh); }
public void UpdateMesh() { updateMeshCalled = true; if (Mesh == null) { Mesh = SgtHelper.CreateTempMesh("Plane"); if (Planes != null) { for (var i = Planes.Count - 1; i >= 0; i--) { var plane = Planes[i]; if (plane != null) { plane.SetMesh(Mesh); } } } } else { Mesh.Clear(false); } if (PlaneDetail >= 2) { var detail = Mathf.Min(PlaneDetail, SgtHelper.QuadsPerMesh / 2); // Limit the amount of vertices that get made var positions = new Vector3[detail * 2 + 2]; var normals = new Vector3[detail * 2 + 2]; var coords1 = new Vector2[detail * 2 + 2]; var coords2 = new Vector2[detail * 2 + 2]; var indices = new int[detail * 6]; var angleStep = SgtHelper.Divide(Mathf.PI * 2.0f, detail); var coordStep = SgtHelper.Reciprocal(detail); for (var i = 0; i <= detail; i++) { var coord = coordStep * i; var angle = angleStep * i; var sin = Mathf.Sin(angle); var cos = Mathf.Cos(angle); var offV = i * 2; positions[offV + 0] = new Vector3(sin * InnerRadius, 0.0f, cos * InnerRadius); positions[offV + 1] = new Vector3(sin * OuterRadius, 0.0f, cos * OuterRadius); normals[offV + 0] = Vector3.up; normals[offV + 1] = Vector3.up; coords1[offV + 0] = new Vector2(0.0f, coord * InnerRadius); coords1[offV + 1] = new Vector2(1.0f, coord * OuterRadius); coords2[offV + 0] = new Vector2(InnerRadius, 0.0f); coords2[offV + 1] = new Vector2(OuterRadius, 0.0f); } for (var i = 0; i < detail; i++) { var offV = i * 2; var offI = i * 6; indices[offI + 0] = offV + 0; indices[offI + 1] = offV + 1; indices[offI + 2] = offV + 2; indices[offI + 3] = offV + 3; indices[offI + 4] = offV + 2; indices[offI + 5] = offV + 1; } Mesh.vertices = positions; Mesh.normals = normals; Mesh.uv = coords1; Mesh.uv2 = coords2; Mesh.triangles = indices; } }
public void UpdateMesh() { if (Detail > 2) { if (generatedMesh == null) { generatedMesh = SgtHelper.CreateTempMesh("Flare Mesh (Generated)"); UpdateApply(); } var total = Detail + 1; var positions = new Vector3[total]; var coords1 = new Vector2[total]; var indices = new int[Detail * 3]; var angleStep = (Mathf.PI * 2.0f) / Detail; var noiseStep = 0.0f; if (Noise == true && NoisePoints > 0) { SgtHelper.BeginRandomSeed(NoiseSeed); { points.Clear(); for (var i = 0; i < NoisePoints; i++) { points.Add(Random.value); } noiseStep = NoisePoints / (float)Detail; } SgtHelper.EndRandomSeed(); } for (var point = 0; point < Detail; point++) { var v = point + 1; var angle = angleStep * point; var x = Mathf.Sin(angle); var y = Mathf.Cos(angle); var r = Radius; if (Wave == true) { var waveAngle = (angle + WavePhase * Mathf.Deg2Rad) * WavePoints; r += Mathf.Pow(Mathf.Cos(waveAngle) * 0.5f + 0.5f, WavePower * WavePower) * WaveStrength; } if (Noise == true && NoisePoints > 0) { //var noise = Mathf.Repeat(noiseStep * point + NoisePhase, NoisePoints); var noise = point * noiseStep; var index = (int)noise; var frac = noise % 1.0f; var pointA = points[(index + 0) % NoisePoints]; var pointB = points[(index + 1) % NoisePoints]; var pointC = points[(index + 2) % NoisePoints]; var pointD = points[(index + 3) % NoisePoints]; r += SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * NoiseStrength; } positions[v] = new Vector3(x * r, y * r, 0.0f); coords1[v] = new Vector2(1.0f, 0.0f); } for (var tri = 0; tri < Detail; tri++) { var i = tri * 3; var v0 = tri + 1; var v1 = tri + 2; if (v1 >= total) { v1 = 1; } indices[i + 0] = 0; indices[i + 1] = v0; indices[i + 2] = v1; } generatedMesh.Clear(false); generatedMesh.vertices = positions; generatedMesh.uv = coords1; generatedMesh.triangles = indices; generatedMesh.RecalculateNormals(); generatedMesh.RecalculateBounds(); } }
public void UpdateMesh() { if (Segments > 0 && SegmentDetail > 0 && RadiusDetail > 0) { if (generatedMesh == null) { generatedMesh = SgtHelper.CreateTempMesh("Ring Mesh (Generated)"); UpdateApply(); } var slices = SegmentDetail + 1; var rings = RadiusDetail + 1; var total = slices * rings * 2; var positions = new Vector3[total]; var coords1 = new Vector2[total]; var coords2 = new Vector2[total]; var colors = new Color[total]; var indices = new int[SegmentDetail * RadiusDetail * 6]; var yawStep = (Mathf.PI * 2.0f) / Segments / SegmentDetail; var sliceStep = 1.0f / SegmentDetail; var ringStep = 1.0f / RadiusDetail; for (var slice = 0; slice < slices; slice++) { var a = yawStep * slice; var x = Mathf.Sin(a); var z = Mathf.Cos(a); for (var ring = 0; ring < rings; ring++) { var v = rings * slice + ring; var slice01 = sliceStep * slice; var ring01 = ringStep * ring; var radius = Mathf.Lerp(RadiusMin, RadiusMax, ring01); positions[v] = new Vector3(x * radius, 0.0f, z * radius); colors[v] = new Color(1.0f, 1.0f, 1.0f, 0.0f); coords1[v] = new Vector2(ring01, slice01); coords2[v] = new Vector2(radius, slice01 * radius); } } for (var slice = 0; slice < SegmentDetail; slice++) { for (var ring = 0; ring < RadiusDetail; ring++) { var i = (slice * RadiusDetail + ring) * 6; var v0 = slice * rings + ring; var v1 = v0 + rings; indices[i + 0] = v0 + 0; indices[i + 1] = v0 + 1; indices[i + 2] = v1 + 0; indices[i + 3] = v1 + 1; indices[i + 4] = v1 + 0; indices[i + 5] = v0 + 1; } } generatedMesh.Clear(false); generatedMesh.vertices = positions; generatedMesh.colors = colors; generatedMesh.uv = coords1; generatedMesh.uv2 = coords2; generatedMesh.triangles = indices; generatedMesh.RecalculateNormals(); generatedMesh.RecalculateBounds(); var bounds = generatedMesh.bounds; generatedMesh.bounds = SgtHelper.NewBoundsCenter(bounds, bounds.center + bounds.center.normalized * BoundsShift); } }