Beispiel #1
0
        void setupParticleSystem(Autodesk.Revit.DB.Face f, int uDiv, int vDiv, double springDampening, double springRestLength, double springConstant, double mass)
        {
            BoundingBoxUV bbox  = f.GetBoundingBox();
            double        uStep = (bbox.Max.U - bbox.Min.U) / uDiv;
            double        vStep = (bbox.Max.V - bbox.Min.V) / vDiv;

            for (int j = 0; j <= uDiv; j++) // Y axis is outer loop
            {
                double u = bbox.Min.U + uStep * j;

                for (int i = 0; i <= vDiv; i++) // X axis is inner loop
                {
                    double v = bbox.Min.V + vStep * i;

                    Particle a = ParticleSystem.makeParticle(mass, f.Evaluate(new UV(u, v)), false);
                    if (i > 0)
                    {
                        ParticleSystem.makeSpring(ParticleSystem.getParticle((i - 1) + (j * (vDiv + 1))), a, springRestLength, springConstant, springDampening);
                    }

                    if (j > 0)
                    {
                        Particle b = ParticleSystem.getParticle(i + ((j - 1) * (vDiv + 1)));
                        ParticleSystem.makeSpring(a, b, springRestLength, springConstant, springDampening);
                    }

                    if (i == 0 || i == vDiv || j == 0 || j == uDiv)
                    {
                        a.makeFixed();
                    }
                }
            }
        }
Beispiel #2
0
        void CreateChainWithTwoFixedEnds(ReferencePoint pt1, ReferencePoint pt2, int numX, double springDampening, double springRestLength, double springConstant, double mass)
        {
            Particle p;
            Particle p2;
            XYZ      partXYZ1 = pt1.Position;
            XYZ      partXYZ2 = pt2.Position;
            XYZ      lineVec  = partXYZ2 - partXYZ1;

            double stepSize = lineVec.GetLength() / numX;

            for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts
            {
                //double curveParam = 0;
                XYZ pointOnLine;

                if (j == 0)                                                // starting point
                {
                    p = ParticleSystem.makeParticle(mass, partXYZ1, true); // make first particle fixed
                }
                else if (j > 0 && j < numX - 1)                            // middle points
                {
                    pointOnLine = partXYZ1 + lineVec.Normalize() * (j * stepSize);
                    p           = ParticleSystem.makeParticle(mass, pointOnLine, false);                 // make a new particle along curve at j-th point on line
                    p2          = ParticleSystem.getParticle(j - 1);
                    ParticleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening); //make a new spring and connect it to the last-made point
                }
                else //last point - fixed
                {
                    p  = ParticleSystem.getParticle(j - 1);
                    p2 = ParticleSystem.makeParticle(mass, partXYZ2, true);                              // make last particle fixed
                    ParticleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening); //make a new spring and connect the j-th point to the fixed point
                }
            }
        }
Beispiel #3
0
        void CreateChainWithOneFixedEnd(ReferencePoint pt1, int numX, double springDampening, double springRestLength, double springConstant, double mass)
        {
            Particle p;

            XYZ      partXYZ1   = pt1.Position;
            Particle fixedPart1 = ParticleSystem.makeParticleFromElementID(pt1.Id, mass, pt1.Position, true); // true means 'make fixed'

            XYZ partXYZ2 = partXYZ1 + new XYZ(10, 0, 0);
            //Line tempLine = this.UIDocument.Application.Application.Create.NewLineBound(partXYZ1, partXYZ2);
            XYZ vector = partXYZ2 - partXYZ1;
            XYZ step   = vector.Divide(numX);

            for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts
            {
                //double curveParam = 0;
                XYZ pointOnLine;

                pointOnLine = partXYZ1 + step.Multiply(j);

                if (j == 0) // starting point
                {
                    //curveParam = (double)j / numX;
                    //pointOnLine = tempLine.Evaluate(curveParam, true);
                    p = ParticleSystem.makeParticle(mass, pointOnLine, true); // make first particle fixed
                }
                else // middle points
                {
                    //curveParam = (double)j / numX;
                    //pointOnLine = tempLine.Evaluate(curveParam, true);
                    p = ParticleSystem.makeParticle(mass, pointOnLine, false);                                                            // make a new particle along curve at j-th point on line
                    ParticleSystem.makeSpring(ParticleSystem.getParticle((j - 1)), p, springRestLength, springConstant, springDampening); //make a new spring and connect it to the last-made point
                }
            }
        }
        private void CreateSpringsFromCurves(IEnumerable <Value> curves, IEnumerable <Value> points)
        {
            //create all the fixed points first
            foreach (var pt in points)
            {
                var xyz = (XYZ)((Value.Container)pt).Item;
                ParticleSystem.makeParticle(_m, xyz, true);
            }

            //create all the springs, checking for existing particles
            foreach (var crv in curves)
            {
                var curve = (Curve)((Value.Container)crv).Item;
                XYZ start = curve.get_EndPoint(0);
                XYZ end   = curve.get_EndPoint(1);

                //find an existing particle to use
                Particle a = ParticleSystem.getParticleByXYZ(start);
                Particle b = ParticleSystem.getParticleByXYZ(end);

                //if not, create a particle
                if (a == null)
                {
                    a = ParticleSystem.makeParticle(_m, start, false);
                }
                if (b == null)
                {
                    b = ParticleSystem.makeParticle(_m, end, false);
                }

                if (_useRl)
                {
                    ParticleSystem.makeSpring(a, b, _r, _s, _d);
                }
                else
                {
                    double restLength = start.DistanceTo(end) * _rlf;
                    ParticleSystem.makeSpring(a, b, restLength, _s, _d);
                }
            }
        }
Beispiel #5
0
        private void CreateSpringsFromCurves(IEnumerable <Curve> curves, IEnumerable <XYZ> points)
        {
            //create all the fixed points first
            foreach (var pt in points)
            {
                ParticleSystem.makeParticle(m, pt, true);
            }

            //create all the springs, checking for existing particles
            foreach (var curve in curves)
            {
                XYZ start = curve.get_EndPoint(0);
                XYZ end   = curve.get_EndPoint(1);

                //find an existing particle to use
                Particle a = ParticleSystem.getParticleByXYZ(start);
                Particle b = ParticleSystem.getParticleByXYZ(end);

                //if not, create a particle
                if (a == null)
                {
                    a = ParticleSystem.makeParticle(m, start, false);
                }
                if (b == null)
                {
                    b = ParticleSystem.makeParticle(m, end, false);
                }

                if (useRl)
                {
                    ParticleSystem.makeSpring(a, b, r, s, d);
                }
                else
                {
                    double restLength = start.DistanceTo(end) * rlf;
                    ParticleSystem.makeSpring(a, b, restLength, s, d);
                }
            }
        }
        void setupLineTest(int maxPartX, int maxPartY, double springDampening, double springRestLength, double springConstant, double mass)
        {
            XYZ    partXYZ;
            double stepSize = 20;

            for (int j = 0; j < maxPartY; j++)     // Y axis is outer loop
            {
                for (int i = 0; i < maxPartX; i++) // X axis is inner loop
                {
                    if (i == 0)
                    {
                        partXYZ = new XYZ(0, j * stepSize, 0);
                        Particle a = ParticleSystem.makeParticle(mass, partXYZ, true);
                    }
                    else
                    {
                        partXYZ = new XYZ(i * stepSize, j * stepSize, 0);
                        Particle b = ParticleSystem.makeParticle(mass, partXYZ, false);
                        ParticleSystem.makeSpring(ParticleSystem.getParticle((i - 1) + (j * maxPartX)), b, springRestLength, springConstant, springDampening);
                    }
                    if (i == maxPartX - 1)
                    {
                        ParticleSystem.getParticle(i + (j * maxPartX)).makeFixed();
                    }
                }

                if (j > 0) // thread multple chains together along Y axis
                {
                    for (int i = 0; i < maxPartX; i++)
                    {
                        Particle a = ParticleSystem.getParticle(i + (j * maxPartX));
                        Particle b = ParticleSystem.getParticle(i + ((j - 1) * maxPartX));

                        ParticleSystem.makeSpring(a, b, springRestLength, springConstant, springDampening);
                    }
                }
            }
        }