Ejemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var points          = new List <GH_Point>();
            var vectors         = new List <GH_Vector>();
            var surface         = new GH_Surface();
            var dynamicsWrapped = new List <GH_ObjectWrapper>();

            if (DA.GetDataList(0, points) && points == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid point list. Operation canceled.");
                return;
            }

            if (DA.GetDataList(1, vectors) && vectors == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid vector list. Operation canceled.");
                return;
            }

            // if vec field is empty, create parallel list of 0 vectors
            if (vectors.Count == 0)
            {
                for (int i = 0; i < points.Count; i++)
                {
                    vectors.Add(new GH_Vector());
                }
            }

            if (DA.GetDataList(2, dynamicsWrapped) && dynamicsWrapped == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid dynamics list. Operation canceled.");
                return;
            }

            if (DA.GetData(3, ref surface) && surface == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid surface. Operation canceled.");
                return;
            }

            var dynamics = new List <IDynamic>();

            foreach (var d in dynamicsWrapped)
            {
                dynamics.Add(d.Value as IDynamic);
            }
            Algos.SortDynamicsByPriority(dynamics);

            Algos.ClearDynamics(dynamics);

            foreach (var d in dynamics)
            {
                Algos.ProcessDynamics(d, points, vectors, surface);
            }

            Algos.RealignAccelerationVectors(dynamics, vectors);

            DA.SetDataList(0, points);
            DA.SetDataList(1, vectors);
        }
Ejemplo n.º 2
0
        private void UpdateWithDynamics(List <IDynamic> dynamics, DynamicSettings settings)
        {
            var points  = new List <GH_Point>(particles.Count);
            var vectors = new List <GH_Vector>(particles.Count);

            for (int i = 0; i < particles.Count; i++)
            {
                points.Add(particles[i].Current.Point);
                vectors.Add(new GH_Vector());
            }

            foreach (var d in dynamics)
            {
                // we need a new list of vectors each way through, which we add seperately to an end result
                // otherwise acceleration can apply across dynamics in unintended ways
                var tempVectors = new List <GH_Vector>(particles.Count);
                for (int i = 0; i < particles.Count; i++)
                {
                    tempVectors.Add(new GH_Vector());
                }

                // post processes use the cumulative vector list
                // pre processes use the temporary empty vector list
                if (d.PostProcess)
                {
                    // vectors is modified inline so we don't need to update as below
                    Algos.ProcessDynamics(d, points, vectors, settings.surface);
                }
                else
                {
                    Algos.ProcessDynamics(d, points, tempVectors, settings.surface);

                    for (int i = 0; i < particles.Count; i++)
                    {
                        vectors[i].Value += tempVectors[i].Value;
                    }
                }
            }

            Algos.RealignAccelerationVectors(dynamics, vectors);

            for (int i = 0; i < points.Count; i++)
            {
                points[i].Value += vectors[i].Value;

                // update particles from resultant p/v's above
                particles[i].Current.Point  = points[i];
                particles[i].Current.Vector = vectors[i];
            }
        }
Ejemplo n.º 3
0
        public static GH_Point GetPointModifiedByDynamics(GH_Point traveller, Basis outBasis, List <IDynamic> dynamics, StaticSettings spm_settings)
        {
            var output = new GH_Point();

            foreach (var d in dynamics)
            {
                var p = new List <GH_Point>();
                p.Add(traveller);

                var v = new List <GH_Vector>();

                if (d.PostProcess)
                {
                    v.Add(outBasis.Vector);
                }
                else
                {
                    v.Add(new GH_Vector());
                }

                ProcessDynamics(d, p, v, spm_settings.surface);

                if (d.PostProcess)
                {
                    outBasis.Vector.Value = v[0].Value;
                }
                else
                {
                    outBasis.Vector.Value += v[0].Value;
                }
            }

            // realign acceleration if necessary
            var outVec = new List <GH_Vector>()
            {
                outBasis.Vector
            };

            Algos.RealignAccelerationVectors(dynamics, outVec);
            outBasis.Vector = outVec[0];

            // compute our resultant point via the traveller + resultant vectors
            var res = traveller.Value + (outBasis.Vector.Value);

            return(new GH_Point(res));
        }