public override void CreateLightningBolt(LightningBoltParameters parameters)
        {
            if (meshHelper == null)
            {
                return;
            }

            Generations = parameters.Generations = Mathf.Clamp(Generations, 1, LightningSplineScript.MaxSplineGenerations);
            LightningBoltPathParameters pathParameters = parameters as LightningBoltPathParameters;

            sourcePoints.Clear();
            PopulateSourcePoints(sourcePoints);
            if (sourcePoints.Count > 1)
            {
                if (Spline && sourcePoints.Count > 3)
                {
                    pathParameters.Points = new List <Vector3>(sourcePoints.Count * Generations);
                    LightningSplineScript.PopulateSpline(pathParameters.Points, sourcePoints, Generations, DistancePerSegmentHint, Camera);
                    pathParameters.SmoothingFactor = (pathParameters.Points.Count - 1) / sourcePoints.Count;
                }
                else
                {
                    pathParameters.Points          = new List <Vector3>(sourcePoints);
                    pathParameters.SmoothingFactor = 1;
                }
                base.CreateLightningBolt(pathParameters);
            }
        }
Exemplo n.º 2
0
        public override void CreateLightningBolt(LightningBoltParameters parameters)
        {
            if (LightningPath == null || LightningPath.List == null)
            {
                return;
            }

            sourcePoints.Clear();
            try
            {
                foreach (GameObject obj in LightningPath.List)
                {
                    if (obj != null)
                    {
                        sourcePoints.Add(obj.transform.position);
                    }
                }
            }
            catch (System.NullReferenceException)
            {
                return;
            }

            if (sourcePoints.Count < PathGenerator.MinPointsForSpline)
            {
                Debug.LogError("To create spline lightning, you need a lightning path with at least " + PathGenerator.MinPointsForSpline + " points.");
            }

            Generations = parameters.Generations = Mathf.Clamp(Generations, 1, MaxSplineGenerations);
            LightningBoltPathParameters sp = parameters as LightningBoltPathParameters;

            if (previousGenerations != Generations || previousDistancePerSegment != DistancePerSegmentHint || SourceChanged())
            {
                previousGenerations        = Generations;
                previousDistancePerSegment = DistancePerSegmentHint;
                sp.Points = new List <Vector3>(sourcePoints.Count * Generations);
                PopulateSpline(sp.Points, sourcePoints, Generations, DistancePerSegmentHint, Camera);
                prevSourcePoints.Clear();
                prevSourcePoints.AddRange(sourcePoints);
                savedSplinePoints = sp.Points;
            }
            else
            {
                sp.Points = savedSplinePoints;
            }
            sp.SmoothingFactor = (sp.Points.Count - 1) / sourcePoints.Count;

            base.CreateLightningBolt(parameters);
        }
Exemplo n.º 3
0
        public void GenerateLightningBoltPath(LightningBoltPathParameters p)
        {
            if (p.Points.Count < 2)
            {
                Debug.LogError("Lightning path should have at least two points");
                return;
            }

            int   generation = p.Generations;
            int   totalGenerations = generation;
            float offsetAmount, d;
            int   smoothingFactor = p.SmoothingFactor - 1;
            bool  is3D            = (CurrentBolt.Camera == null || !CurrentBolt.Camera.orthographic);

            p.Start = p.Points[0];
            p.End   = p.Points[p.Points.Count - 1];
            Vector3 end = p.Start;
            Vector3 start, distance, randomVector;
            LightningBoltSegmentGroup group = p.Generator.CreateGroup();

            group.LineWidth          = p.TrunkWidth;
            group.Generation         = generation--;
            group.EndWidthMultiplier = p.EndWidthMultiplier;
            group.Color = Color.white;

            for (int i = 1; i < p.Points.Count; i++)
            {
                start    = end;
                end      = p.Points[i];
                distance = (end - start);
                d        = PathGenerator.SquareRoot(distance.sqrMagnitude);
                if (p.ChaosFactor > 0.0f)
                {
                    if (is3D)
                    {
                        end += (d * p.ChaosFactor * RandomDirection3D(p.Random));
                    }
                    else
                    {
                        end += (Vector3)(d * p.ChaosFactor * RandomDirection2D(p.Random));
                    }
                    distance = (end - start);
                }
                group.Segments.Add(new LightningBoltSegment {
                    Start = start, End = end
                });

                offsetAmount = d * p.ChaosFactor;
                RandomVector(ref start, ref end, offsetAmount, p.Random, out randomVector);

                if (ShouldCreateFork(p, generation, totalGenerations))
                {
                    Vector3 branchVector = distance * p.ForkMultiplier() * smoothingFactor * 0.5f;
                    Vector3 forkEnd      = end + branchVector + randomVector;
                    GenerateLightningBoltStandard(start, forkEnd, generation, totalGenerations, 0.0f, p);
                }

                if (--smoothingFactor == 0)
                {
                    smoothingFactor = p.SmoothingFactor - 1;
                }
            }
        }
Exemplo n.º 4
0
        public void GenerateLightningBoltPath(LightningBoltPathParameters p)
        {
            if (p.Points.Count < 2)
            {
                Debug.LogError("Lightning path should have at least two points");
                return;
            }

            int generation = p.Generations;
            int totalGenerations = generation;
            float offsetAmount, d;
            int smoothingFactor = p.SmoothingFactor - 1;
            bool is3D = (CurrentBolt.Camera == null || !CurrentBolt.Camera.orthographic);
            p.Start = p.Points[0];
            p.End = p.Points[p.Points.Count - 1];
            Vector3 end = p.Start;
            Vector3 start, distance, randomVector;
            LightningBoltSegmentGroup group = p.Generator.CreateGroup();
            group.LineWidth = p.TrunkWidth;
            group.Generation = generation--;
            group.EndWidthMultiplier = p.EndWidthMultiplier;
            group.Color = Color.white;

            for (int i = 1; i < p.Points.Count; i++)
            {
                start = end;
                end = p.Points[i];
                distance = (end - start);
                d = PathGenerator.SquareRoot(distance.sqrMagnitude);
                if (p.ChaosFactor > 0.0f)
                {
                    if (is3D)
                    {
                        end += (d * p.ChaosFactor * RandomDirection3D(p.Random));
                    }
                    else
                    {
                        end += (Vector3)(d * p.ChaosFactor * RandomDirection2D(p.Random));
                    }
                    distance = (end - start);
                }
                group.Segments.Add(new LightningBoltSegment { Start = start, End = end });

                offsetAmount = d * p.ChaosFactor;
                RandomVector(ref start, ref end, offsetAmount, p.Random, out randomVector);

                if (ShouldCreateFork(p, generation, totalGenerations))
                {
                    Vector3 branchVector = distance * p.ForkMultiplier() * smoothingFactor * 0.5f;
                    Vector3 forkEnd = end + branchVector + randomVector;
                    GenerateLightningBoltStandard(start, forkEnd, generation, totalGenerations, 0.0f, p);
                }

                if (--smoothingFactor == 0)
                {
                    smoothingFactor = p.SmoothingFactor - 1;
                }
            }
        }