protected override void CalculateAsteroids(out List <SgtBeltAsteroid> asteroids, out bool pool) { asteroids = new List <SgtBeltAsteroid>(); pool = true; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < AsteroidCount; i++) { var variant = GetRandomAsteroidVariant(); if (variant != null) { var asteroid = SgtClassPool <SgtBeltAsteroid> .Pop() ?? new SgtBeltAsteroid(); asteroids.Add(asteroid); var distance01 = Random.value; asteroid.MainTex = variant.MainTex; asteroid.HeightTex = variant.HeightTex; asteroid.Color = Color.white; asteroid.Radius = Random.Range(AsteroidRadiusMin, AsteroidRadiusMax); asteroid.Height = Random.Range(-Thickness, Thickness); asteroid.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); asteroid.Spin = Random.Range(-AsteroidSpin, AsteroidSpin); asteroid.OrbitAngle = Random.Range(0.0f, Mathf.PI * 2.0f); asteroid.OrbitSpeed = Mathf.Lerp(InnerSpeed, OuterSpeed, distance01); asteroid.OrbitDistance = Mathf.Lerp(InnerRadius, OuterRadius, distance01); } } } SgtHelper.EndRandomSeed(); }
protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool) { stars = tempStars; tempStars.Clear(); pool = true; SgtHelper.BeginRandomSeed(Seed); { var armStep = 360.0f * SgtHelper.Reciprocal(ArmCount); var twistStep = 360.0f * Twist; for (var i = 0; i < StarCount; i++) { var star = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star); var position = Random.insideUnitSphere; var magnitude = 1 - (Random.insideUnitSphere).magnitude; position *= (1 - magnitude) * Thickness.Evaluate(Random.value); position += Quaternion.AngleAxis(i * armStep + magnitude * twistStep, Vector3.up) * Vector3.forward * magnitude; star.Sprite = GetRandomStarSprite(); star.Color = Color.white; star.Radius = Random.Range(StarRadiusMin, StarRadiusMax); star.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); star.Position = position * Radius; star.PulseRange = Random.value * StarPulseMax; star.PulseSpeed = Random.value; star.PulseOffset = Random.value; } } SgtHelper.EndRandomSeed(); }
protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool) { stars = tempStars; tempStars.Clear(); pool = true; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < StarCount; i++) { var star = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star); var position = default(Vector3); position.x = Random.Range(-Size.x, Size.x); position.y = Random.Range(-Size.y, Size.y); position.z = Random.Range(-Size.z, Size.z); star.Sprite = GetRandomStarSprite(); star.Color = Color.white; star.Radius = Random.Range(StarRadiusMin, StarRadiusMax); star.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); star.Position = position; star.PulseRange = Random.value * StarPulseMax; star.PulseSpeed = Random.value; star.PulseOffset = Random.value; } } SgtHelper.EndRandomSeed(); }
protected override void CalculateAsteroids(out List <SgtBeltAsteroid> asteroids, out bool pool) { asteroids = new List <SgtBeltAsteroid>(); pool = true; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < AsteroidCount; i++) { var variant = GetRandomAsteroidVariant(); if (variant != null) { var asteroid = SgtClassPool <SgtBeltAsteroid> .Pop() ?? new SgtBeltAsteroid(); asteroids.Add(asteroid); var distance01 = Random.value; var offset = SpeedNoiseDistribution.Evaluate(distance01); asteroid.MainTex = variant.MainTex; asteroid.HeightTex = variant.HeightTex; asteroid.Color = Color.white; asteroid.Radius = RadiusDistribution.Evaluate(Random.value); asteroid.Height = HeightDistribution.Evaluate(Random.value); asteroid.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); asteroid.Spin = SpinDistribution.Evaluate(Random.value); asteroid.OrbitAngle = Random.Range(0.0f, Mathf.PI * 2.0f); asteroid.OrbitSpeed = SpeedDistribution.Evaluate(distance01) + Random.Range(-offset, offset); asteroid.OrbitDistance = DistanceDistribution.Evaluate(distance01); } } } SgtHelper.EndRandomSeed(); }
public SgtCustomBelt MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale) { #if UNITY_EDITOR SgtHelper.BeginUndo("Create Editable Belt Copy"); #endif var gameObject = SgtHelper.CreateGameObject("Editable Belt Copy", layer, parent, localPosition, localRotation, localScale); var customBelt = SgtHelper.AddComponent <SgtCustomBelt>(gameObject, false); var quads = new List <SgtBeltAsteroid>(); var quadCount = BeginQuads(); for (var i = 0; i < quadCount; i++) { var asteroid = SgtClassPool <SgtBeltAsteroid> .Pop() ?? new SgtBeltAsteroid(); NextQuad(ref asteroid, i); quads.Add(asteroid); } EndQuads(); // Copy common settings if (Lights != null) { customBelt.Lights = new List <Light>(Lights); } if (Shadows != null) { customBelt.Shadows = new List <SgtShadow>(Shadows); } customBelt.Color = Color; customBelt.Brightness = Brightness; customBelt.MainTex = MainTex; customBelt.HeightTex = HeightTex; customBelt.Layout = Layout; customBelt.LayoutColumns = LayoutColumns; customBelt.LayoutRows = LayoutRows; if (Rects != null) { customBelt.Rects = new List <Rect>(Rects); } customBelt.RenderQueue = RenderQueue; customBelt.RenderQueueOffset = RenderQueueOffset; customBelt.OrbitOffset = OrbitOffset; customBelt.OrbitSpeed = OrbitSpeed; // Copy custom settings customBelt.Asteroids = quads; // Update customBelt.UpdateMaterial(); customBelt.UpdateMeshesAndModels(); return(customBelt); }
public SgtCustomStarfield MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale) { #if UNITY_EDITOR SgtHelper.BeginUndo("Create Editable Starfield Copy"); #endif var gameObject = SgtHelper.CreateGameObject("Editable Starfield Copy", layer, parent, localPosition, localRotation, localScale); var customStarfield = SgtHelper.AddComponent <SgtCustomStarfield>(gameObject, false); var quads = new List <SgtPointStar>(); var starCount = BeginQuads(); for (var i = 0; i < starCount; i++) { var quad = SgtClassPool <SgtPointStar> .Pop() ?? new SgtPointStar(); NextQuad(ref quad, i); quads.Add(quad); } EndQuads(); // Copy common settings customStarfield.Color = Color; customStarfield.Brightness = Brightness; customStarfield.MainTex = MainTex; customStarfield.Layout = Layout; customStarfield.LayoutColumns = LayoutColumns; customStarfield.LayoutRows = LayoutRows; customStarfield.RenderQueue = RenderQueue; customStarfield.RenderQueueOffset = RenderQueueOffset; customStarfield.FollowCameras = FollowCameras; customStarfield.Softness = Softness; customStarfield.Wrap = Wrap; customStarfield.WrapSize = WrapSize; customStarfield.Stretch = Stretch; customStarfield.StretchVector = StretchVector; customStarfield.StretchScale = StretchScale; customStarfield.FadeNear = FadeNear; customStarfield.FadeNearRadius = FadeNearRadius; customStarfield.FadeNearThickness = FadeNearThickness; customStarfield.FadeNearTex = FadeNearTex; customStarfield.FadeFar = FadeFar; customStarfield.FadeFarRadius = FadeFarRadius; customStarfield.FadeFarThickness = FadeFarThickness; customStarfield.FadeFarTex = FadeFarTex; customStarfield.Pulse = Pulse; customStarfield.PulseOffset = PulseOffset; customStarfield.PulseSpeed = PulseSpeed; // Copy custom settings customStarfield.Stars = quads; // Update customStarfield.UpdateMaterial(); customStarfield.UpdateMeshesAndModels(); return(customStarfield); }
public SgtCustomStarfield MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale) { #if UNITY_EDITOR SgtHelper.BeginUndo("Create Editable Starfield Copy"); #endif var gameObject = SgtHelper.CreateGameObject("Editable Starfield Copy", layer, parent, localPosition, localRotation, localScale); var customStarfield = SgtHelper.AddComponent <SgtCustomStarfield>(gameObject, false); var stars = default(List <SgtStarfieldStar>); var pool = default(bool); CalculateStars(out stars, out pool); if (stars != null) { if (pool == true) { customStarfield.Stars = stars; } else { for (var i = 0; i < stars.Count; i++) { var star = stars[i]; if (star != null) { var newStar = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); customStarfield.Stars.Add(star); newStar.CopyFrom(star); } } } } customStarfield.Color = Color; customStarfield.Brightness = Brightness; customStarfield.RenderQueue = RenderQueue; customStarfield.RenderQueueOffset = RenderQueueOffset; customStarfield.Age = Age; customStarfield.TimeScale = TimeScale; customStarfield.Softness = Softness; customStarfield.AutoRegenerate = AutoRegenerate; customStarfield.StretchToObservers = StretchToObservers; customStarfield.StretchOverride = StretchOverride; customStarfield.StretchVector = StretchVector; customStarfield.StretchScale = StretchScale; customStarfield.FadeNear = FadeNear; customStarfield.FadeNearRadius = FadeNearRadius; customStarfield.FadeNearThickness = FadeNearThickness; customStarfield.FadeFar = FadeFar; customStarfield.FadeFarRadius = FadeFarRadius; customStarfield.FadeFarThickness = FadeFarThickness; customStarfield.FollowObservers = FollowObservers; customStarfield.AllowPulse = AllowPulse; return(customStarfield); }
private void ClearShells() { for (var i = shells.Count - 1; i >= 0; i--) { SgtClassPool <Shell> .Add(shells[i]); } shells.Clear(); }
protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool) { var texture = SourceTex as Texture2D; stars = tempStars; tempStars.Clear(); pool = true; if (texture != null && Resolution > 0.0f && Resolution <= 1.0f) { #if UNITY_EDITOR SgtHelper.MakeTextureReadable(texture); SgtHelper.MakeTextureTruecolor(texture); #endif var samplesX = Mathf.FloorToInt(SourceTex.width * Resolution); var samplesY = Mathf.FloorToInt(SourceTex.height * Resolution); var stepX = SgtHelper.Reciprocal(samplesX); var stepY = SgtHelper.Reciprocal(samplesY); var halfSize = Size * 0.5f; var scale = SgtHelper.Divide(SourceTex.width, samplesX); SgtHelper.BeginRandomSeed(Seed); { for (var y = 0; y < samplesY; y++) { for (var x = 0; x < samplesX; x++) { var fracX = x * stepX; var fracY = y * stepY; var pixel = texture.GetPixelBilinear(fracX, fracY); var gray = pixel.grayscale; if (gray > Threshold) { var star = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star); var position = -halfSize + Random.insideUnitSphere * Jitter * StarRadiusMax * scale; position.x += Size.x * fracX; position.y += Size.y * GetHeight(pixel); position.z += Size.z * fracY; star.Sprite = GetRandomStarSprite(); star.Color = pixel; star.Radius = Random.Range(StarRadiusMin, StarRadiusMax) * scale; star.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); star.Position = position; star.PulseRange = Random.value * StarPulseMax; star.PulseSpeed = Random.value; star.PulseOffset = Random.value; } } } } SgtHelper.EndRandomSeed(); } }
private Shell AddShell(long detail) { var shell = SgtClassPool <Shell> .Pop() ?? new Shell(); shell.Detail = detail; shell.Inner = default(SgtBoundsL); shells.Add(shell); return(shell); }
protected override void OnDestroy() { base.OnDestroy(); if (Asteroids != null) { for (var i = Asteroids.Count - 1; i >= 0; i--) { SgtClassPool <SgtBeltAsteroid> .Add(Asteroids[i]); } } }
protected override void OnDestroy() { base.OnDestroy(); if (Stars != null) { for (var i = Stars.Count - 1; i >= 0; i--) { SgtClassPool <SgtPointStar> .Add(Stars[i]); } } }
public static void Clear <T>(List <T> cameraStates) where T : SgtCameraState { if (cameraStates != null) { for (var i = cameraStates.Count - 1; i >= 0; i--) { SgtClassPool <T> .Add(cameraStates[i]); } cameraStates.Clear(); } }
protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool) { stars = tempStars; tempStars.Clear(); pool = true; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < StarCount; i++) { var star = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star); var x = Random.Range(-0.5f, 0.5f); var y = Random.Range(-0.5f, 0.5f); var z = Random.Range(Offset * 0.5f, 0.5f); var position = default(Vector3); if (Random.value >= 0.5f) { z = -z; } switch (Random.Range(0, 3)) { case 0: position = new Vector3(z, x, y); break; case 1: position = new Vector3(x, z, y); break; case 2: position = new Vector3(x, y, z); break; } star.Sprite = GetRandomStarSprite(); star.Color = Color.white; star.Radius = Random.Range(StarRadiusMin, StarRadiusMax); star.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); star.Position = Vector3.Scale(position, Extents); star.PulseRange = Random.value * StarPulseMax; star.PulseSpeed = Random.value; star.PulseOffset = Random.value; } } SgtHelper.EndRandomSeed(); }
public SgtCustomStarfield MakeEditableCopy(Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale) { #if UNITY_EDITOR SgtHelper.BeginUndo("Create Editable Starfield Copy"); #endif var gameObject = SgtHelper.CreateGameObject("Editable Starfield Copy", parent, localPosition, localRotation, localScale); var customStarfield = SgtHelper.AddComponent <SgtCustomStarfield>(gameObject, false); var stars = default(List <SgtStarfieldStar>); var pool = default(bool); CalculateStars(out stars, out pool); if (stars != null) { if (pool == true) { customStarfield.Stars = stars; } else { for (var i = 0; i < stars.Count; i++) { var star = stars[i]; if (star != null) { var newStar = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); customStarfield.Stars.Add(star); newStar.CopyFrom(star); } } } } customStarfield.Color = Color; customStarfield.Brightness = Brightness; customStarfield.FollowObservers = FollowObservers; return(customStarfield); }
public SgtCustomBelt MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale) { #if UNITY_EDITOR SgtHelper.BeginUndo("Create Editable Belt Copy"); #endif var gameObject = SgtHelper.CreateGameObject("Editable Belt Copy", layer, parent, localPosition, localRotation, localScale); var customBelt = SgtHelper.AddComponent <SgtCustomBelt>(gameObject, false); var asteroids = default(List <SgtBeltAsteroid>); var pool = default(bool); CalculateAsteroids(out asteroids, out pool); if (asteroids != null) { if (pool == true) { customBelt.Asteroids = asteroids; } else { for (var i = 0; i < asteroids.Count; i++) { var asteroid = asteroids[i]; if (asteroid != null) { var newAsteroid = SgtClassPool <SgtBeltAsteroid> .Pop() ?? new SgtBeltAsteroid(); customBelt.Asteroids.Add(asteroid); newAsteroid.CopyFrom(asteroid); } } } } customBelt.Color = Color; customBelt.Brightness = Brightness; return(customBelt); }
protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool) { stars = tempStars; tempStars.Clear(); pool = true; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < StarCount; i++) { var star = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star); var position = Random.insideUnitSphere; position.y *= Symmetry; star.Sprite = GetRandomStarSprite(); star.Color = Color.white; star.Radius = Random.Range(StarRadiusMin, StarRadiusMax); star.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); star.Position = position.normalized * Radius; } } SgtHelper.EndRandomSeed(); }
public static T Save <T>(ref List <T> cameraStates, Camera camera) where T : SgtCameraState, new() { if (cameraStates == null) { cameraStates = new List <T>(); } for (var i = cameraStates.Count - 1; i >= 0; i--) { var cameraState = cameraStates[i]; if (cameraState == null) { cameraStates.RemoveAt(i); continue; } if (cameraState.Camera == null) { SgtClassPool <T> .Add(cameraState); cameraStates.RemoveAt(i); continue; } if (cameraState.Camera == camera) { return(cameraState); } } var newCameraState = SgtClassPool <T> .Pop() ?? new T(); newCameraState.Camera = camera; cameraStates.Add(newCameraState); return(newCameraState); }
protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool) { stars = tempStars; tempStars.Clear(); pool = true; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < StarCount; i++) { var star = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star); var position = Random.insideUnitSphere; var magnitude = Offset; if (Inverse == true) { magnitude += (1.0f - position.magnitude) * (1.0f - Offset); } else { magnitude += position.magnitude * (1.0f - Offset); } position.y *= Symmetry; star.Sprite = GetRandomStarSprite(); star.Color = Color.white; star.Radius = Random.Range(StarRadiusMin, StarRadiusMax); star.Angle = Random.Range(0.0f, Mathf.PI * 2.0f); star.Position = position.normalized * magnitude * Radius; star.PulseRange = Random.value * StarPulseMax; star.PulseSpeed = Random.value; star.PulseOffset = Random.value; } } SgtHelper.EndRandomSeed(); }
protected override 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 rotation = Quaternion.FromToRotation(Vector3.back, position.normalized) * Quaternion.Euler(0.0f, 0.0f, star.Angle); var up = rotation * Vector3.up * radius; var right = rotation * Vector3.right * radius; ExpandBounds(ref minMaxSet, ref min, ref max, position, radius); SgtProceduralMesh.PushPosition(position - up - right); SgtProceduralMesh.PushPosition(position - up + right); SgtProceduralMesh.PushPosition(position + up - right); SgtProceduralMesh.PushPosition(position + up + right); SgtProceduralMesh.PushColor(star.Color, 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); } 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; } } } } }
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; } } } }