Ejemplo n.º 1
0
        Composite MakeSpinalComposite(float length, int boneNum, Vector2 rootPosition)
        {
            if (boneNum <= 1)
            {
                throw new System.ArgumentException("boneNUmは\"2\"以上に設定してください。");
            }
            float boneLength = length / (boneNum + 1);

            var        composite       = new Composite();
            List <int> particleIndices = new List <int>();
            List <int> springIndices   = new List <int>();

            var tp = new Particle(rootPosition);

            particleIndices.Add(composite.elemNum);
            composite.AddSimElement(tp, 0);

            for (int i = 1; i < boneNum; ++i)
            {
                var p = new Particle(rootPosition + new Vector2(0f, -boneLength * i));
                particleIndices.Add(composite.elemNum);
                composite.AddSimElement(p, 0);

                var s = new SpringConstraint(tp, p);
                springIndices.Add(composite.elemNum);
                composite.AddSimElement(s, 1);

                tp = p;
            }

            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(1, springIndices));
            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(0, particleIndices));

            return(composite);
        }
Ejemplo n.º 2
0
        Composite MakeTree(int depth, float branchLength)
        {
            composite             = new Composite();
            branchParticleIndices = new List <int>();
            springIndices         = new List <int>();
            leafSpringIndices     = new List <int>();

            Particle root = new Particle(Vector2.zero, particleDamping);

            branchParticleIndices.Add(composite.elemNum);
            composite.AddSimElement(root);
            PinConstraint rootPin = new PinConstraint(root);

            Particle      branch    = MakeBranch(root, depth, branchLength, Mathf.PI * 0.5f, angleStiffness);
            PinConstraint branchPin = new PinConstraint(branch);

            composite.AddSimElement(rootPin);
            composite.AddSimElement(branchPin);

            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(2, springIndices));
            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(0, branchParticleIndices));
            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(1, leafSpringIndices));

            return(composite);
        }
Ejemplo n.º 3
0
        Composite MakeSpinalComposite(float length, int rimbNum, Vector2 rootPosition, float angle)
        {
            if (rimbNum <= 1)
            {
                throw new System.ArgumentException("rimbNumは\"2\"以上に設定してください。");
            }
            float boneLength = length / (rimbNum + 1);
            var   composite  = new Composite();

            List <int> particleIndices = new List <int>();
            List <int> gravityIndices  = new List <int>();
            List <int> springIndices   = new List <int>();

            Vector2 direction = AngleToVec2(angle);

            var tp = new Particle(rootPosition);

            particleIndices.Add(composite.elemNum);
            composite.AddSimElement(tp, 0);

            var g = new ConstantForceConstraint(tp, gravity);

            gravityIndices.Add(composite.elemNum);
            composite.AddSimElement(g, 5);

            //var sinWave = new SinWaveForce(tp, Vector2.right, amplitude, timeScale, 0f);
            //composite.simElements.Add(sinWave);

            for (int i = 1; i < rimbNum; ++i)
            {
                var p = new Particle(rootPosition + direction * boneLength * i, damping);
                particleIndices.Add(composite.elemNum);
                composite.AddSimElement(p, 0);

                // var s = new SpringConstraint(tp, p);
                var s = new DistanceConstraint(tp, p);
                springIndices.Add(composite.elemNum);
                composite.AddSimElement(s, 1);

                g = new ConstantForceConstraint(p, gravity);
                gravityIndices.Add(composite.elemNum);
                composite.AddSimElement(g, 5);

                tp = p;
            }

            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(1, springIndices));
            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(2, gravityIndices));
            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(0, particleIndices));

            return(composite);
        }
Ejemplo n.º 4
0
        Composite MakeClothComposite(float rowSize, int row, float colSize, int col, float particleDamping, float springStiffness, Vector2 gravity, Vector2 rootPosition, Vector2 offset)
        {
            float rowCellSize = rowSize / row;
            float colCellSize = colSize / col;

            Particle[] rowParticles = new Particle[row];

            var        composite       = new Composite();
            List <int> particleIndices = new List <int>();
            List <int> springIndices   = new List <int>();

            for (var y = 0; y < col; ++y)
            {
                if (y == 0)
                {
                    for (var x = 0; x < row; ++x)
                    {
                        var p = new Particle(rootPosition + new Vector2(rowCellSize * x, -colCellSize * y) + offset, particleDamping);
                        particleIndices.Add(composite.elemNum);
                        composite.AddSimElement(p, 0);

                        var pc = new PinConstraint(p);
                        composite.AddSimElement(p, 10);

                        if (x != 0)
                        {
                            var s = new SpringConstraint(rowParticles[x - 1], p, springStiffness);
                            // var s = new DistanceConstraint(rowParticles[x - 1], p);
                            springIndices.Add(composite.elemNum);
                            composite.AddSimElement(s, 1);
                        }

                        rowParticles[x] = p;
                    }
                }
                else
                {
                    for (var x = 0; x < row; ++x)
                    {
                        var p = new Particle(rootPosition + new Vector2(rowCellSize * x, -colCellSize * y) + offset, particleDamping);
                        particleIndices.Add(composite.elemNum);
                        composite.AddSimElement(p, 0);

                        var cfc = new ConstantForceConstraint(p, gravity);
                        composite.AddSimElement(cfc, 5);

                        var s = new SpringConstraint(rowParticles[x], p, springStiffness);
                        // var s = new DistanceConstraint(rowParticles[x], p);
                        springIndices.Add(composite.elemNum);
                        composite.AddSimElement(s, 1);

                        if (x != 0)
                        {
                            s = new SpringConstraint(rowParticles[x - 1], p, springStiffness);
                            // s = new DistanceConstraint(rowParticles[x - 1], p);
                            springIndices.Add(composite.elemNum);
                            composite.AddSimElement(s, 1);
                        }

                        rowParticles[x] = p;
                    }
                }
            }

            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(1, springIndices));
            composite.AddRenderingGroup(new SimRenderer.SimRenderingGroup(0, particleIndices));

            return(composite);
        }