protected override int BeginQuads() { SgtHelper.BeginRandomSeed(seed); if (starColors == null) { starColors = SgtHelper.CreateGradient(Color.white); } return(starCount); }
protected override int BeginQuads() { SgtHelper.BeginRandomSeed(Seed); if (StarColors == null) { StarColors = SgtHelper.CreateGradient(Color.white); } armStep = 360.0f * SgtHelper.Reciprocal(ArmCount); twistStep = 360.0f * Twist; return(StarCount); }
public void UpdateTexture() { if (Width > 0 && Height > 0 && NoisePoints > 0) { // Destroy if invalid if (generatedTexture != null) { if (generatedTexture.width != Width || generatedTexture.height != Height || generatedTexture.format != Format) { generatedTexture = SgtHelper.Destroy(generatedTexture); } } // Create? if (generatedTexture == null) { generatedTexture = SgtHelper.CreateTempTexture2D("Aurora MainTex (Generated)", Width, Height, Format); generatedTexture.wrapMode = TextureWrapMode.Repeat; ApplyTexture(); } SgtHelper.BeginRandomSeed(NoiseSeed); { noisePoints.Clear(); for (var i = 0; i < NoisePoints; i++) { noisePoints.Add(1.0f - Random.Range(0.0f, NoiseStrength)); } } SgtHelper.EndRandomSeed(); var stepU = 1.0f / (Width - 1); var stepV = 1.0f / (Height - 1); for (var y = 0; y < Height; y++) { var v = stepV * y; for (var x = 0; x < Width; x++) { WritePixel(stepU * x, v, x, y); } } generatedTexture.Apply(); } }
private void UpdateTexture() { if (width > 0 && height > 0 && noisePoints > 0) { // Destroy if invalid if (generatedTexture != null) { if (generatedTexture.width != width || generatedTexture.height != height || generatedTexture.format != format) { generatedTexture = SgtHelper.Destroy(generatedTexture); } } // Create? if (generatedTexture == null) { generatedTexture = SgtHelper.CreateTempTexture2D("Aurora MainTex (Generated)", width, height, format); generatedTexture.wrapMode = TextureWrapMode.Repeat; } SgtHelper.BeginRandomSeed(noiseSeed); { tempPoints.Clear(); for (var i = 0; i < noisePoints; i++) { tempPoints.Add(1.0f - Random.Range(0.0f, noiseStrength)); } } SgtHelper.EndRandomSeed(); var stepU = 1.0f / (width - 1); var stepV = 1.0f / (height - 1); for (var y = 0; y < height; y++) { var v = stepV * y; for (var x = 0; x < width; x++) { WritePixel(stepU * x, v, x, y); } } generatedTexture.Apply(); } ApplyTexture(); }
protected override int BeginQuads() { SgtHelper.BeginRandomSeed(Seed); sourceTex2D = SourceTex as Texture2D; if (sourceTex2D != null && Samples > 0) { #if UNITY_EDITOR SgtHelper.MakeTextureReadable(sourceTex2D); SgtHelper.MakeTextureTruecolor(sourceTex2D); #endif halfSize = Size * 0.5f; return(StarCount); } return(0); }
protected virtual void OnEnable() { var parent = GetComponent <SgtFloatingObject>(); var parentPoint = parent.Point; BuildSpawnList(); SgtHelper.BeginRandomSeed(parent.Seed); { var rad = (double)Radius; for (var i = 0; i < Count; i++) { var position = parentPoint.Position; var direction = Random.onUnitSphere; var distance = Mathf.Lerp(Offset, 1.0f, Random.value); var offset = distance * direction; position.LocalX += offset.x * rad; position.LocalY += offset.y * rad; position.LocalZ += offset.z * rad; position.SnapLocal(); var clone = SpawnAt(position); if (VelocityScale > 0.0f) { var rigidbody = clone.GetComponent <Rigidbody>(); if (rigidbody != null) { var cross = Vector3.Cross(direction, Random.onUnitSphere).normalized; rigidbody.velocity = (cross * VelocityScale) / (distance * distance); } } } } SgtHelper.EndRandomSeed(); }
protected override void SpawnAll() { var parentPoint = CachedObject; BuildSpawnList(); SgtHelper.BeginRandomSeed(CachedObject.Seed); { var radMin = (double)radiusMin; var radMax = (double)radiusMax; var radRng = radMax - radMin; for (var i = 0; i < count; i++) { var radius = radMin + radRng * Random.value; var angle = Random.Range(0.0f, 360.0f); var tilt = new Vector3(Random.Range(-tiltMax, tiltMax), 0.0f, Random.Range(-tiltMax, tiltMax)); var oblateness = Random.Range(0.0f, oblatenessMax); var position = SgtFloatingOrbit.CalculatePosition(parentPoint, radius, angle, tilt, Vector3.zero, oblateness); var instance = SpawnAt(position, i); var orbit = instance.GetComponent <SgtFloatingOrbit>(); if (orbit == null) { orbit = instance.gameObject.AddComponent <SgtFloatingOrbit>(); } orbit.ParentPoint = parentPoint; orbit.Radius = radius; orbit.Angle = angle; orbit.Oblateness = oblateness; orbit.DegreesPerSecond = 1000.0 / radius; orbit.Tilt = tilt; } } SgtHelper.EndRandomSeed(); }
private void SpawnFace(SgtTerrainFace face) { var surface = FindSurface(face); if (surface != null) { surface.Clear(); } else { if (surfaces == null) { surfaces = new List <Surface>(); } surface = new Surface(); surface.Face = face; surfaces.Add(surface); } SgtHelper.BeginRandomSeed(face.GetHashCode()); { if (SpawnProbability > 0.0f && Depth == face.Depth) { for (var i = 0; i < SpawnCountMax; i++) { if (Random.value <= SpawnProbability) { AddObject(surface, face); } } } } SgtHelper.EndRandomSeed(); }
protected override int BeginQuads() { SgtHelper.BeginRandomSeed(seed); if (starColors == null) { starColors = SgtHelper.CreateGradient(Color.white); } sourceTex2D = sourceTex as Texture2D; if (sourceTex2D != null && samples > 0) { #if UNITY_EDITOR SgtHelper.MakeTextureReadable(sourceTex2D); SgtHelper.MakeTextureTruecolor(sourceTex2D); #endif halfSize = size * 0.5f; return(starCount); } return(0); }
public void UpdateMesh() { if (Detail > 2) { if (generatedMesh == null) { generatedMesh = SgtHelper.CreateTempMesh("Mesh (Generated)"); ApplyMesh(); } 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(); } // Write center vertices positions[0] = Vector3.zero; coords1[0] = Vector2.zero; // Write outer vertices for (var point = 0; point < Detail; point++) { 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 + NoisePhase; 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; } // Write outer vertices var v = point + 1; 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(); } }
protected override int BeginQuads() { SgtHelper.BeginRandomSeed(Seed); return(AsteroidCount); }
public void UpdateDebris() { if (Target != null && CellCount > 0.0f && Prefabs != null && DebrisCountTarget > 0) { var cellSize = (long)System.Math.Ceiling(HideDistance / CellCount); var worldPoint = Target.position - transform.position; var centerX = (long)System.Math.Round(worldPoint.x / cellSize); var centerY = (long)System.Math.Round(worldPoint.y / cellSize); var centerZ = (long)System.Math.Round(worldPoint.z / cellSize); var newBounds = new SgtBoundsL(centerX, centerY, centerZ, CellCount); if (newBounds != bounds) { var probability = DebrisCountTarget / (cellSize * cellSize * cellSize); var cellMin = cellSize * (0.5f - CellNoise); var cellMax = cellSize * (0.5f + CellNoise); for (var z = newBounds.minZ; z <= newBounds.maxZ; z++) { for (var y = newBounds.minY; y <= newBounds.maxY; y++) { for (var x = newBounds.minX; x <= newBounds.maxX; x++) { if (bounds.Contains(x, y, z) == false) { SgtHelper.BeginRandomSeed(Seed, x, y, z); { // Can debris potentially spawn in this cell? if (Random.value < probability) { var debrisPoint = default(Vector3); debrisPoint.x = x * cellSize + Random.Range(cellMin, cellMax); debrisPoint.y = y * cellSize + Random.Range(cellMin, cellMax); debrisPoint.z = z * cellSize + Random.Range(cellMin, cellMax); // Spawn everywhere, or only inside specified shapes? if (SpawnInside == null || Random.value < SpawnInside.GetDensity(debrisPoint)) { Spawn(x, y, z, debrisPoint); } } } SgtHelper.EndRandomSeed(); } } } } bounds = newBounds; if (spawnedDebris != null) { for (var i = spawnedDebris.Count - 1; i >= 0; i--) { var debris = spawnedDebris[i]; if (debris == null) { spawnedDebris.RemoveAt(i); } else if (bounds.Contains(debris.Cell) == false) { Despawn(debris, i); } } } } UpdateDebrisScale(Target.position); } else { ClearDebris(); } }
public void UpdateMeshesAndModels() { if (meshes == null) { meshes = new List <Mesh>(); } if (PathDetail > 0 && PathLengthMin > 0.0f && PathLengthMax > 0.0f) { var meshCount = 1; var mesh = GetMesh(0); var vertexCount = 0; SgtHelper.BeginRandomSeed(Seed); { for (var i = 0; i < PathCount; i++) { AddPath(ref mesh, ref meshCount, ref vertexCount); } } SgtHelper.EndRandomSeed(); BakeMesh(mesh); for (var i = meshes.Count - 1; i >= meshCount; i--) { var extraMesh = meshes[i]; if (extraMesh != null) { extraMesh.Clear(false); SgtObjectPool <Mesh> .Add(extraMesh); } meshes.RemoveAt(i); } } for (var i = 0; i < meshes.Count; i++) { var model = SgtHelper.GetIndex(ref models, i); if (model == null) { model = models[i] = SgtAuroraModel.Create(this); } model.SetMesh(meshes[i]); model.SetMaterial(material); } // Remove any excess if (models != null) { var min = Mathf.Max(0, meshes.Count); for (var i = models.Count - 1; i >= min; i--) { SgtAuroraModel.Pool(models[i]); models.RemoveAt(i); } } }