Example #1
0
        /// <summary>
        /// Adds a new spring to the model.
        /// </summary>
        public Spring AddSpring(double stiffness, double shearStiffness, double rotationalStiffness, Node n1, Node n2)
        {
            Spring n = new Spring(stiffness, shearStiffness, rotationalStiffness, n1, n2);

            Springs.Add(n);
            return(n);
        }
Example #2
0
        public Object Clone()
        {
            StyleCollection res = new StyleCollection();

            List <StyleObject> allStyles = new List <StyleObject>();

            res.AllStyles = allStyles;

            res.Poles = Poles.Clone() as PoleStyle;
            allStyles.Add(res.Poles);

            res.Tubes = Tubes.Clone() as TubeStyle;
            allStyles.Add(res.Tubes);

            res.Chromosomes = Chromosomes.Clone() as ChromosomeStyle;
            allStyles.Add(res.Chromosomes);

            res.Springs = Springs.Clone() as SpringStyle;
            allStyles.Add(res.Springs);

            res.Cell = Cell.Clone() as CellStyle;
            allStyles.Add(res.Cell);

            return(res);
        }
 public void Dispose()
 {
     Springs.Dispose();
     Joints.Dispose();
     BlittableTransforms.Dispose();
     Colliders.Dispose();
     Logics.Dispose();
 }
 public AbstractWidget(int size, bool isSmall)
 {
     this._size    = size;
     this._isSmall = isSmall;
     _gears        = new Gears();
     _springs      = new Springs();
     _levers       = new Levers();
 }
Example #5
0
 public Widget2(float price)
 {
     _Price   = price;
     _Gears   = new Gears();
     _Springs = new Springs();
     _Levers  = new Levers();
     _painted = new Painted();
 }
Example #6
0
        public void AddSpring(IVehicleComponent component)
        {
            if (SpringNeedsToAdd && component.Type == VehicleComponentType.Spring)
            {
                Springs.Add(component);

                SpringNeedsToAdd = false;
            }
        }
        public AbstractWidget(int size, WidgetColor color)

        {
            this._size   = size;
            this._color1 = color;
            _springs     = new Springs();
            _levers      = new Levers();
            _gears       = new Gears();
        }
        /// <summary>
        /// Removes a given spring joint from the world if it exists.
        /// </summary>
        /// <param name="_joint"></param>
        public void RemoveSpringJoint(ABSpringJoint _joint)
        {
            if (Springs.Contains(_joint))
            {
                Springs.Remove(_joint);
                return;
            }

            Debug.LogWarning("Attempted to remove a spring joint from world that didn't exist.");
        }
        public void AddSpringJoint(ABSpringJoint _joint)
        {
            if (Springs.Contains(_joint))
            {
                Debug.LogWarning("Can't add duplicate spring joints!");
                return;
            }

            Springs.Add(_joint);
        }
Example #10
0
        /// <summary>
        /// Sorts all springs according to their coordinates.
        /// </summary>
        public void SortSprings()
        {
            Springs.Sort((f1, f2) =>
            {
                Node a = f1.Centroid;
                Node b = f2.Centroid;
                return(Math.Abs(a.Z - b.Z) < float.Epsilon ? (a.X < b.X ? -1 : 1) : (a.Z < b.Z ? -1 : 1));
            });

            AssignSpringIndices();
        }
Example #11
0
 public void Dispose()
 {
     if (IsDisposed)
     {
         return;
     }
     IsDisposed = true;
     Springs.Dispose();
     Joints.Dispose();
     BlittableTransforms.Dispose();
     Colliders.Dispose();
     Logics.Dispose();
 }
Example #12
0
        /// <summary>
        /// Erases all model items.
        /// </summary>
        public void ResetModel()
        {
            ResetLastStiffnessMatrix();

            Nodes.Clear();
            Materials.Clear();
            FrameSections.Clear();
            Frames.Clear();
            Springs.Clear();

            AnalysisCases.Clear();
            Combinations.Clear();
        }
Example #13
0
 public SolutionPointModel(bool zero = false)
 {
     if (zero)
     {
         Chosen          = false;
         UpperSpringBool = false;
         LowerSpringBool = false;
         XPosition       = 0;
         YPosition       = 0;
         Springs.Add(new SpringModel(true));
         Springs.Add(new SpringModel(true));
     }
 }
Example #14
0
        public Spring AddSpring(int start, int duration, float springSize, float preSpringSize, float postSpringSize)
        {
            Spring spring;

            if (!Springs.ContainsKey(start))
            {
                spring = new Spring();
                spring.TimePosition     = start;
                spring.SmallestDuration = duration;
                spring.LongestDuration  = duration;
                spring.SpringWidth      = springSize;
                spring.PreSpringWidth   = preSpringSize;
                spring.PostSpringWidth  = postSpringSize;
                Springs[start]          = spring;
            }
            else
            {
                spring = Springs[start];
                if (spring.SpringWidth < springSize)
                {
                    spring.SpringWidth = springSize;
                }
                if (spring.PreSpringWidth < preSpringSize)
                {
                    spring.PreSpringWidth = preSpringSize;
                }
                if (spring.PostSpringWidth < postSpringSize)
                {
                    spring.PostSpringWidth = postSpringSize;
                }
                if (duration < spring.SmallestDuration)
                {
                    spring.SmallestDuration = duration;
                }
                if (duration > spring.LongestDuration)
                {
                    spring.LongestDuration = duration;
                }
            }

            if (duration < SmallestDuration)
            {
                SmallestDuration = duration;
            }

            return(spring);
        }
Example #15
0
    void Start()
    {
        //Setting the size of the mesh, specially the density
        //int gridSize = gridSizeNew + (gridSizeNew - 1);
        int gridSize = gridSizeNew + gridSizeNew * (gridSizeNew - 1);

        //Initialice the list of particles, springs and triangles.
        _particles = new List <Particles>();
        _springs   = new List <Springs>();
        _triangles = new List <Triangles>();
        _sphere    = new List <GameObject>();
        _edges     = new List <Edges>();

        //To be able to change the size of the sphere
        sphereControl.transform.localScale = new Vector3(sphereScale, sphereScale, sphereScale);

        //In the editor to have a parent of all the particles
        var particleParent = new GameObject("particleParent");

        //Calcule the area of the cloth
        float area = 0.2f * (gridSize - 1) * 0.2f * (gridSize - 1);

        //Calcule the total mass of the cloth with the density
        float massTotal = clothDensity * area;
        //Calcule the mass of each particle
        float mass = massTotal / (gridSize * gridSize);

        //Instantiate the position of the particles and the gameobject.
        float jP = 0;
        float iP = 0;
        int   pi = 0;
        int   pj = 0;

        for (int i = 0; i < gridSize; i++)
        {
            for (int j = 0; j < gridSize; j++)
            {
                jP = j * 0.1f;
                iP = i * 0.1f;

                var newP = ParticlesBehaviour.Create(transform.position + new Vector3(jP, 0.0f, iP), mass, pi, pj, sphereControl);
                newP.transform.SetParent(particleParent.transform, false);
                newP.transform.localPosition = (new Vector3(jP, 0.0f, iP) + transform.position);
                newP.particles.Position      = newP.transform.position;
                _particles.Add(newP.particles);
                pi++;
            }
            pj++;
        }

        int edgesCount = 0;

        //Instntiate all the springs and all the edges to
        //be able to check collisions (just edges that mades all the triangles)
        //Springs
        //Structural Horizontal - Right
        for (int j = 0; j < gridSize; j++)
        {
            for (int i = 0; i < gridSize - 1; i++)
            {
                var index = j * gridSize + i;
                var c     = _particles[index];
                var right = _particles[index + 1];
                var re    = new Springs(c, right, elasticConstantStructural, dampingConstant, 1);
                _springs.Add(re);
                var ed = new Edges(index, index + 1, edgesCount);
                edgesCount++;
                ed.PosEdges(c.Position, right.Position);
                _edges.Add(ed);
            }
        }

        //Structural Vertical - Bot
        for (int j = 0; j < gridSize - 1; j++)
        {
            for (int i = 0; i < gridSize; i++)
            {
                var index_1 = j * gridSize + i;
                var index_2 = (j + 1) * gridSize + i;
                var c       = _particles[index_1];
                var right   = _particles[index_2];
                var re      = new Springs(c, right, elasticConstantStructural, dampingConstant, 1);
                _springs.Add(re);
                var ed = new Edges(index_1, index_2, edgesCount);
                edgesCount++;
                ed.PosEdges(c.Position, right.Position);
                _edges.Add(ed);
            }
        }

        //Shear - \ - Down
        for (int j = 0; j < gridSize - 1; j++)
        {
            for (int i = 0; i < gridSize - 1; i++)
            {
                var index_1 = j * gridSize + i;
                var index_2 = (j + 1) * gridSize + i + 1;
                var c       = _particles[index_1];
                var bot     = _particles[index_2];
                var re      = new Springs(c, bot, elasticConstantShear, dampingConstant, 2);
                _springs.Add(re);
                var ed = new Edges(index_1, index_2, edgesCount);
                edgesCount++;
                ed.PosEdges(c.Position, bot.Position);
                _edges.Add(ed);
            }
        }

        //Shear - / - Down
        for (int j = 0; j < gridSize - 1; j++)
        {
            for (int i = 1; i < gridSize; i++)
            {
                var index_1 = j * gridSize + i;
                var index_2 = (j + 1) * gridSize + i - 1;
                var c       = _particles[index_1];
                var top     = _particles[index_2];
                var re      = new Springs(c, top, elasticConstantShear, dampingConstant, 2);
                _springs.Add(re);
            }
        }

        //Bend - Left
        for (int j = 0; j < gridSize; j++)
        {
            for (int i = 0; i < gridSize - 2; i++)
            {
                var index_1 = j * gridSize + i;
                var index_2 = j * gridSize + i + 2;
                var c       = _particles[index_1];
                var left    = _particles[index_2];
                var re      = new Springs(c, left, elasticConstantBend, dampingConstant, 3);
                _springs.Add(re);
            }
        }

        //Bend - Down
        for (int j = 0; j < gridSize - 2; j++)
        {
            for (int i = 0; i < gridSize; i++)
            {
                var index_1 = j * gridSize + i;
                var index_2 = (j + 2) * gridSize + i;
                var c       = _particles[index_1];
                var left    = _particles[index_2];
                var re      = new Springs(c, left, elasticConstantBend, dampingConstant, 3);
                _springs.Add(re);
            }
        }

        //Fix two particles
        _particles[0].isActive            = false;
        _particles[gridSize - 1].isActive = false;

        Vector3.Normalize(normalSecondPlane);

        //Calcule a part of the wind force and call the simulation script to incitialize it with all the needed information
        winddirectiondensity = windDirection * windModule * clothDensity;
        simulator            = new Simulate(_particles, _springs, _triangles, _edges, winddirectiondensity, plane, secondPlane, normalSecondPlane, gridSize, frictionConstPlane, dissipationConstPlane, frictionConstCloth, dissipationConstCloth, drawSprings, EdgeOrPointCheck, SphereRightHand, frictionConstShpereHand, dissipationConstSphereHand, SphereLeftHand);

        //Creating the mess
        mesh = new Mesh();
        GetComponent <MeshFilter>().mesh = mesh;
        CreateShape();
        UpdateMesh();
        UpdateEdges();
    }