示例#1
0
    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();
        }
    }
示例#2
0
 protected override void EndQuads()
 {
     SgtHelper.EndRandomSeed();
 }
示例#3
0
    public void UpdateMeshesAndModels()
    {
        updateMeshesAndModelsCalled = true;

        if (Meshes == null)
        {
            Meshes = new List <Mesh>();
        }

        if (Models == null)
        {
            Models = new List <SgtAuroraModel>();
        }

        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 = GetOrAddModel(i);

            model.SetMesh(Meshes[i]);
        }

        // 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);
            }
        }
    }