protected virtual void RegenerateMeshes() { var stars = default(List <SgtStarfieldStar>); var pool = default(bool); CalculateStars(out stars, out pool); if (stars != null) { // Sort stars into groups for (var i = stars.Count - 1; i >= 0; i--) { var star = stars[i]; if (star != null) { var group = GetGroup(star.Sprite); group.Stars.Add(star); } } // Pool stars? if (pool == true) { SgtClassPool <SgtStarfieldStar> .Add(stars); } // Build groups for (var i = groups.Count - 1; i >= 0; i--) { var group = groups[i]; if (group.Stars.Count > 0) { var groupStars = group.Stars; var minMaxSet = false; var min = default(Vector3); var max = default(Vector3); SgtProceduralMesh.Clear(); for (var j = groupStars.Count - 1; j >= 0; j--) { var star = groupStars[j]; var position = star.Position; var radius = star.Radius; var uv = SgtHelper.CalculateSpriteUV(star.Sprite); var angle = star.Angle / Mathf.PI; ExpandBounds(ref minMaxSet, ref min, ref max, position, radius); SgtProceduralMesh.PushPosition(position, 4); SgtProceduralMesh.PushColor(star.Color, 4); SgtProceduralMesh.PushNormal(-1.0f, 1.0f, angle); SgtProceduralMesh.PushNormal(1.0f, 1.0f, angle); SgtProceduralMesh.PushNormal(-1.0f, -1.0f, angle); SgtProceduralMesh.PushNormal(1.0f, -1.0f, angle); SgtProceduralMesh.PushTangent(star.PulseOffset, star.PulseSpeed, star.PulseRange, 0.0f, 4); SgtProceduralMesh.PushCoord1(uv.x, uv.y); SgtProceduralMesh.PushCoord1(uv.z, uv.y); SgtProceduralMesh.PushCoord1(uv.x, uv.w); SgtProceduralMesh.PushCoord1(uv.z, uv.w); SgtProceduralMesh.PushCoord2(radius, 0.5f); SgtProceduralMesh.PushCoord2(radius, -0.5f); SgtProceduralMesh.PushCoord2(radius, 0.5f); SgtProceduralMesh.PushCoord2(radius, -0.5f); } var bounds = SgtHelper.NewBoundsFromMinMax(min, max); SgtProceduralMesh.SplitQuads(HideFlags.DontSave); var meshCount = SgtProceduralMesh.Count; // Copy meshes for (var j = 0; j < meshCount; j++) { var mesh = SgtProceduralMesh.Pop(); var model = group.Models.Count > j ? group.Models[j] : SgtStarfieldModel.Create(group); mesh.bounds = bounds; model.Mesh = mesh; } } } } }
private void RegenerateMeshes() { var asteroids = default(List <SgtBeltAsteroid>); var pool = default(bool); CalculateAsteroids(out asteroids, out pool); if (asteroids != null) { // Sort asteroids into groups for (var i = asteroids.Count - 1; i >= 0; i--) { var asteroid = asteroids[i]; if (asteroid != null) { var group = GetGroup(asteroid.MainTex, asteroid.HeightTex); group.Asteroids.Add(asteroid); } } // Pool asteroids? if (pool == true) { SgtClassPool <SgtBeltAsteroid> .Add(asteroids); } // Build groups for (var i = groups.Count - 1; i >= 0; i--) { var group = groups[i]; var groupAsteroids = group.Asteroids; var maxWidth = 0.0f; var maxHeight = 0.0f; SgtProceduralMesh.Clear(); for (var j = groupAsteroids.Count - 1; j >= 0; j--) { var asteroid = groupAsteroids[j]; var radius = asteroid.Radius; var distance = asteroid.OrbitDistance; var height = asteroid.Height; var uv = SgtHelper.CalculateSpriteUV(asteroid.MainTex); maxWidth = Mathf.Max(maxWidth, distance + radius); maxHeight = Mathf.Max(maxHeight, height + radius); SgtProceduralMesh.PushPosition(asteroid.OrbitAngle, distance, asteroid.OrbitSpeed, 4); SgtProceduralMesh.PushColor(asteroid.Color, 4); SgtProceduralMesh.PushNormal(-1.0f, 1.0f, 0.0f); SgtProceduralMesh.PushNormal(1.0f, 1.0f, 0.0f); SgtProceduralMesh.PushNormal(-1.0f, -1.0f, 0.0f); SgtProceduralMesh.PushNormal(1.0f, -1.0f, 0.0f); SgtProceduralMesh.PushTangent(asteroid.Angle / Mathf.PI, asteroid.Spin / Mathf.PI, 0.0f, 0.0f, 4); SgtProceduralMesh.PushCoord1(uv.x, uv.y); SgtProceduralMesh.PushCoord1(uv.z, uv.y); SgtProceduralMesh.PushCoord1(uv.x, uv.w); SgtProceduralMesh.PushCoord1(uv.z, uv.w); SgtProceduralMesh.PushCoord2(radius, height, 4); } var bounds = new Bounds(Vector3.zero, new Vector3(maxWidth * 2.0f, maxHeight * 2.0f, maxWidth * 2.0f)); SgtProceduralMesh.SplitQuads(HideFlags.DontSave); var meshCount = SgtProceduralMesh.Count; // Copy meshes for (var j = 0; j < meshCount; j++) { var mesh = SgtProceduralMesh.Pop(); var model = group.Models.Count > j ? group.Models[j] : SgtBeltModel.Create(group); mesh.bounds = bounds; model.Mesh = mesh; } } } }