public void Update()
    {
        if (Application.isPlaying == true)
        {
            SGT_Helper.BeginRandomSeed(seed);
            {
                if (rotation == true)
                {
                    rotationChangeTime -= Time.deltaTime;

                    if (rotationChangeTime <= 0.0f)
                    {
                        rotationChangeTime = rotationChangeDelay;

                        targetBearing = Random.Range(-1.0f, 1.0f);
                    }

                    var dampenFactor = SGT_Helper.DampenFactor(rotationDampening, Time.deltaTime);

                    currentBearing = Mathf.Lerp(currentBearing, targetBearing, dampenFactor);

                    var dps = SGT_Helper.DegreesPerSecond(rotationPeriod);

                    transform.localRotation *= Quaternion.Euler(dps * currentBearing * Time.deltaTime, dps * Time.deltaTime, 0.0f);
                }

                if (scale == true)
                {
                    scaleChangeTime -= Time.deltaTime;

                    if (scaleChangeTime <= 0.0f)
                    {
                        scaleChangeTime = scaleChangeDelay;

                        targetScale = Random.Range(scaleMin, scaleMax);
                    }

                    var dampenFactor = SGT_Helper.DampenFactor(scaleDampening, Time.deltaTime);
                    var newScale     = Mathf.Lerp(UniformScale, targetScale, dampenFactor);

                    transform.localScale = new Vector3(newScale, newScale, newScale);
                }
            }
            seed = SGT_Helper.EndRandomSeed();
        }
    }
    public void Regenerate()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            packer.Pack();

            DestroyGeneratedMeshes();

            if (packer.OutputCount > 0)
            {
                SGT_Helper.BeginRandomSeed(starfieldSeed);
                {
                    var remainingStars = starfieldStarCount;
                    var starsPerMesh   = SGT_Helper.MeshVertexLimit / 4;
                    var newMeshes      = new MeshList();

                    while (remainingStars > 0)
                    {
                        var starsInMesh = Mathf.Min(remainingStars, starsPerMesh);

                        newMeshes.Add(GenerateStarMesh(starsInMesh));

                        remainingStars -= starsInMesh;
                    }

                    meshes = newMeshes.ToArray();

                    if (starfieldMultiMesh != null)
                    {
                        starfieldMultiMesh.ReplaceAll(meshes);
                        starfieldMultiMesh.Update();
                    }
                }
                SGT_Helper.EndRandomSeed();
            }

            MarkAsUnmodified();
        }
    }
    public void Regenerate()
    {
        if (modified == true)
        {
            DestroyGeneratedMeshes();

            if (starVariants.Count > 0)
            {
                SGT_Helper.BeginRandomSeed(starfieldSeed);
                {
                    RecalculateCoords();
                    RecalculateWeights();

                    var remainingStars = starfieldStarCount;
                    var starsPerMesh   = SGT_Helper.MeshVertexLimit / 4;
                    var newMeshes      = new MeshList();

                    while (remainingStars > 0)
                    {
                        var starsInMesh = Mathf.Min(remainingStars, starsPerMesh);

                        newMeshes.Add(GenerateStarMesh(starfieldStarCount - remainingStars, starsInMesh));

                        remainingStars -= starsInMesh;
                    }

                    meshes = newMeshes.ToArray();

                    if (starfieldMultiMesh != null)
                    {
                        starfieldMultiMesh.ReplaceAll(meshes);
                        starfieldMultiMesh.Update();
                    }
                }
                SGT_Helper.EndRandomSeed();
            }

            modified = false;
        }
    }
    public void Regenerate()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            modified = false;

            SGT_Helper.DestroyObjects(generatedMeshes);

            SGT_Helper.BeginRandomSeed(ringSeed);
            {
                var remainingAsteroids = ringAsteroidCount;
                var asteroidsPerMesh   = SGT_Helper.MeshVertexLimit / 4;
                var newMeshes          = new MeshList();

                while (remainingAsteroids > 0)
                {
                    var asteroidsInMesh = Mathf.Min(remainingAsteroids, asteroidsPerMesh);

                    newMeshes.Add(GenerateAsteroidMesh(asteroidsInMesh));

                    remainingAsteroids -= asteroidsInMesh;
                }

                generatedMeshes = newMeshes.ToArray();

                if (ringMultiMesh != null)
                {
                    ringMultiMesh.ReplaceAll(generatedMeshes);
                    ringMultiMesh.Update();
                }
            }
            SGT_Helper.EndRandomSeed();
        }
    }
Exemple #5
0
    public void Regenerate()
    {
        if (dustModified == false)
        {
            CheckForModifications();
        }

        if (dustModified == true)
        {
            Validate();

            dustModified = false;

            var particles = new ParticleList();

            SGT_Helper.BeginRandomSeed(dustSeed);
            {
                for (var y = 0; y < dustCount; y++)
                {
                    var p    = new Particle();
                    var posX = Random.Range(0.0f, 1.0f);
                    var posY = Random.Range(0.0f, 1.0f);
                    var posZ = Random.Range(0.0f, 1.0f);

                    p.Position = new Vector3(posX, posY, posZ);
                    p.Size     = particleScale;
                    p.Colour   = Color.white * particleColour;
                    p.Angle    = Random.value * 360.0f;

                    particles.Add(p);
                }
            }
            SGT_Helper.EndRandomSeed();

            CreateMesh(particles);
        }
    }
    public void Regenerate()
    {
        if (modified == false)
        {
            CheckForModifications();
        }

        if (modified == true)
        {
            modified = false;

            SGT_Helper.BeginRandomSeed(meshSeed);
            {
                Quaternion[] rotations = null;

                switch (meshAlignment)
                {
                case Alignment.Billboard:
                {
                    rotations    = new Quaternion[1];
                    rotations[0] = Quaternion.identity;
                }
                break;

                case Alignment.AxisAlined:
                {
                    coronaGameObject.transform.localRotation = Quaternion.identity;

                    rotations    = new Quaternion[3];
                    rotations[0] = Quaternion.LookRotation(Vector3.right);
                    rotations[1] = Quaternion.LookRotation(Vector3.up);
                    rotations[2] = Quaternion.LookRotation(Vector3.forward);
                }
                break;

                case Alignment.Random:
                {
                    coronaGameObject.transform.localRotation = Quaternion.identity;

                    rotations = new Quaternion[meshPlaneCount];

                    for (var i = 0; i < rotations.Length; i++)
                    {
                        rotations[i] = Random.rotation;
                    }
                }
                break;
                }

                // Replace mesh
                SGT_Helper.DestroyObject(generatedMesh);

                switch (meshType)
                {
                case Type.Plane:
                {
                    GeneratePlane(rotations);
                }
                break;

                case Type.Ring:
                {
                    GenerateRing(rotations);
                }
                break;
                }

                if (coronaMesh != null)
                {
                    coronaMesh.SharedMesh = generatedMesh;
                }
            }
            SGT_Helper.EndRandomSeed();

            UpdateCoronaOffset();
        }
    }
Exemple #7
0
    public void Regenerate()
    {
        if (nebulaModified == false)
        {
            CheckForModifications();
        }

        if (nebulaModified == true)
        {
            Validate();

            nebulaModified = false;

            var particles = new ParticleList();

            SGT_Helper.BeginRandomSeed(nebulaSeed);
            {
                for (var y = 0; y < nebulaResolution; y++)
                {
                    for (var x = 0; x < nebulaResolution; x++)
                    {
                        if (nebulaTexture != null)
                        {
                            var u       = (float)x / (float)(nebulaResolution - 1);
                            var v       = (float)y / (float)(nebulaResolution - 1);
                            var noiseU  = Mathf.Clamp01(u + Random.Range(-heightNoise, heightNoise));
                            var noiseV  = Mathf.Clamp01(v + Random.Range(-heightNoise, heightNoise));
                            var jitterU = Mathf.Clamp01(u + Random.Range(-particleJitter, particleJitter));
                            var jitterV = Mathf.Clamp01(v + Random.Range(-particleJitter, particleJitter));
                            var colour  = nebulaTexture.GetPixelBilinear(noiseU, noiseV);
                            var height  = 0.0f;
                            var max     = Mathf.Max(Mathf.Max(colour.r, colour.g), colour.b);
                            var rot     = Random.value * 360.0f;
                            var offset  = heightOffset * nebulaSize;

                            for (var i = nebulaMirror == true ? 0 : 1; i < 2; i++)
                            {
                                if (Random.value < max)
                                {
                                    switch (heightSource)
                                    {
                                    case TextureHeightSource.Alpha: height = colour.a; break;

                                    case TextureHeightSource.Red:   height = colour.r; break;

                                    case TextureHeightSource.Green: height = colour.g; break;

                                    case TextureHeightSource.Blue:  height = colour.b; break;

                                    case TextureHeightSource.RGB:   height = (colour.r + colour.g + colour.b) / 3.0f; break;

                                    case TextureHeightSource.Min:   height = Mathf.Min(Mathf.Min(colour.r, colour.g), colour.b); break;

                                    case TextureHeightSource.Max:   height = max; break;
                                    }

                                    if (max > 0.0f)
                                    {
                                        var p    = new Particle();
                                        var posX = SGT_Helper.Remap(0.0f, 1.0f, jitterU, -nebulaSize, nebulaSize);
                                        var posZ = SGT_Helper.Remap(0.0f, 1.0f, jitterV, -nebulaSize, nebulaSize);
                                        var posY = (heightInvert == true ? 1.0f - height : height) * nebulaSize * heightScale + offset;

                                        p.Position = new Vector3(posX, i == 0 ? -posY : posY, posZ);
                                        p.Size     = (nebulaSize / (float)nebulaResolution) * particleScale * 2.0f;
                                        p.Colour   = colour;
                                        p.Angle    = rot;

                                        particles.Add(p);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            SGT_Helper.EndRandomSeed();

            CreateMesh(particles);
        }
    }