public void Bind(List <Vector3> positions, BGCcMath math, Config config, List <BGCcSplitterPolyline.PolylinePoint> points)
        {
            positions.Clear();
            points.Clear();

            var tangentCalculated = math.IsCalculated(BGCurveBaseMath.Field.Tangent);
            var baseMath          = math.Math;
            var sectionsCount     = baseMath.SectionsCount;

            //count number of straight lines
            var straightLinesCount = 0;

            if (!config.DoNotOptimizeStraightLines)
            {
                //resize only if length < sectionsCount to reduce GC
                if (straightBits == null || straightBits.Length < sectionsCount)
                {
                    Array.Resize(ref straightBits, sectionsCount);
                }
                straightLinesCount = CountStraightLines(baseMath, straightBits);
            }


            //recalculate points
            InitProvider(ref positionsProvider, math, config).Build(positions, straightLinesCount, straightBits, points);

            if (!config.UseLocal)
            {
                return;
            }

            //slow convertion (world->local)
            var matrix = config.Transform.worldToLocalMatrix;
            var count  = positions.Count;

            for (var i = 0; i < count; i++)
            {
                var localPos = matrix.MultiplyPoint(positions[i]);
                positions[i] = localPos;

                var point = points[i];
                points[i] = new BGCcSplitterPolyline.PolylinePoint(localPos, point.Distance, tangentCalculated ? config.Transform.InverseTransformDirection(point.Tangent) : Vector3.zero);
            }
        }
Example #2
0
        public void Bind(List <Vector3> positions, BGCcMath math, Config config)
        {
            positions.Clear();

            var baseMath      = math.Math;
            var sectionsCount = baseMath.SectionsCount;

            //count number of straight lines
            var straightLinesCount = 0;

            if (!config.DoNotOptimizeStraightLines)
            {
                //resize only if length < sectionsCount to reduce GC
                if (straightBits == null || straightBits.Length < sectionsCount)
                {
                    Array.Resize(ref straightBits, sectionsCount);
                }
                straightLinesCount = CountStraightLines(baseMath, straightBits);
            }


            //recalculate points
            InitProvider(ref positionsProvider, math, config).Build(positions, straightLinesCount, straightBits);

            if (!config.UseLocal)
            {
                return;
            }

            //slow convertion (world->local)
            var matrix = config.Transform.worldToLocalMatrix;
            var count  = positions.Count;

            for (var i = 0; i < count; i++)
            {
                positions[i] = matrix.MultiplyPoint(positions[i]);
            }
        }
 public void Init(BGCcMath math, int partsPerSection)
 {
     base.Init(math);
     parts = partsPerSection;
 }
            public void Init(BGCcMath math, int parts)
            {
                base.Init(math);

                this.parts = parts;
            }
 public virtual void Init(BGCcMath math)
 {
     Math                = math;
     LastPointAdded      = false;
     calculatingTangents = Math.IsCalculated(BGCurveBaseMath.Field.Tangent);
 }
        //===============================================================================================
        //                                                    private methods
        //===============================================================================================
        //init required provider. Each mode has it's own provider
        private PositionsProvider InitProvider(ref PositionsProvider positionsProvider, BGCcMath math, Config config)
        {
            //assign positions provider if needed
            var mode             = config.SplitMode;
            var providerObsolete = positionsProvider == null || !positionsProvider.Comply(mode);

            switch (mode)
            {
            case BGCcSplitterPolyline.SplitModeEnum.PartsTotal:
                if (providerObsolete)
                {
                    if (providerTotalParts == null)
                    {
                        providerTotalParts = new PositionsProviderTotalParts();
                    }
                    positionsProvider = providerTotalParts;
                }

                providerTotalParts.Init(math, config.PartsTotal);
                break;

            case BGCcSplitterPolyline.SplitModeEnum.PartsPerSection:
                if (providerObsolete)
                {
                    if (providerPartsPerSection == null)
                    {
                        providerPartsPerSection = new PositionsProviderPartsPerSection();
                    }
                    positionsProvider = providerPartsPerSection;
                }

                providerPartsPerSection.Init(math, config.PartsPerSection);
                break;

            default:
                //                    case SplitModeEnum.UseMathData:
                if (providerObsolete)
                {
                    if (providerMath == null)
                    {
                        providerMath = new PositionsProviderMath();
                    }
                    positionsProvider = providerMath;
                }

                providerMath.Init(math);
                break;
            }

            if (config.DistanceMin > 0 || config.DistanceMax > 0)
            {
                //currently DistanceMin and DistanceMax supported by SplitModeEnum.UseMathData only
                if (mode != BGCcSplitterPolyline.SplitModeEnum.UseMathData)
                {
                    throw new Exception("DistanceMin and DistanceMax supported by SplitModeEnum.UseMathData mode only");
                }

                positionsProvider.DistanceMin = config.DistanceMin;
                positionsProvider.DistanceMax = config.DistanceMax;
            }

            return(positionsProvider);
        }
Example #7
0
 public virtual void Init(BGCcMath math)
 {
     Math           = math;
     LastPointAdded = false;
 }
 public void Init(BGCcMath ccMath)
 {
     InitInner(ccMath);
 }
 public void Init(BGCcMath math, int partsPerSection)
 {
     InitInner(math);
     parts = partsPerSection;
 }
            public void Init(BGCcMath math, int parts)
            {
                InitInner(math);

                this.parts = parts;
            }
 protected virtual void InitInner(BGCcMath math)
 {
     Math = math;
 }