Пример #1
0
 void InitClusterCollide2()
 {
     for (int i = 0; i < 3; ++i)
     {
         SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);
         Material pm  = psb.AppendMaterial();
         pm.Flags -= FMaterial.DebugDraw;
         psb.GenerateBendingConstraints(2, pm);
         psb.Cfg.PIterations = 2;
         psb.Cfg.DF          = 1;
         psb.Cfg.SshrCl      = 1;
         psb.Cfg.SSSplitCl   = 0;
         psb.Cfg.SkhrCl      = 0.1f;
         psb.Cfg.SKSplitCl   = 1;
         psb.Cfg.Collisions  = FCollisions.CLSS | FCollisions.CLRS;
         psb.RandomizeConstraints();
         Matrix m = Matrix.RotationYawPitchRoll((float)Math.PI / 2 * (i & 1), (float)Math.PI / 2 * (1 - (i & 1)), 0)
                    * Matrix.Translation(3 * i, 2, 0);
         psb.Transform(m);
         psb.Scale(new Vector3(2, 2, 2));
         psb.SetTotalMass(50, true);
         psb.GenerateClusters(16);
         SoftWorld.AddSoftBody(psb);
     }
 }
Пример #2
0
        void InitSticks()
        {
            const int   n   = 16;
            const int   sg  = 4;
            const float sz  = 5;
            const float hg  = 4;
            const float inf = 1 / (float)(n - 1);

            for (int y = 0; y < n; ++y)
            {
                for (int x = 0; x < n; ++x)
                {
                    Vector3 org = new Vector3(-sz + sz * 2 * x * inf,
                                              -10, -sz + sz * 2 * y * inf);

                    SoftBody psb = SoftBodyHelpers.CreateRope(softBodyWorldInfo, org,
                                                              org + new Vector3(hg * 0.001f, hg, 0), sg, 1);

                    psb.Cfg.DP  = 0.005f;
                    psb.Cfg.Chr = 0.1f;
                    for (int i = 0; i < 3; ++i)
                    {
                        psb.GenerateBendingConstraints(2 + i);
                    }
                    psb.SetMass(1, 0);
                    psb.SetTotalMass(0.01f);
                    SoftWorld.AddSoftBody(psb);
                }
            }
            CreateBigBall(new Vector3(0, 13, 0));
        }
Пример #3
0
        void InitClusterCollide1()
        {
            const float s   = 8;
            SoftBody    psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, 0, -s),
                                                          new Vector3(+s, 0, -s),
                                                          new Vector3(-s, 0, +s),
                                                          new Vector3(+s, 0, +s),
                                                          17, 17,//9,9,//31,31,
                                                          1 + 2 + 4 + 8,
                                                          true);
            Material pm = psb.AppendMaterial();

            pm.Lst             = 0.4f;
            pm.Flags          -= FMaterial.DebugDraw;
            psb.Cfg.DF         = 1;
            psb.Cfg.SrhrCl     = 1;
            psb.Cfg.SRSplitCl  = 0;
            psb.Cfg.Collisions = FCollisions.CLSS | FCollisions.CLRS;
            psb.GenerateBendingConstraints(2, pm);

            psb.CollisionShape.Margin = 0.05f;
            psb.SetTotalMass(50);

            // pass zero in generateClusters to create  cluster for each tetrahedron or triangle
            psb.GenerateClusters(0);
            //psb.GenerateClusters(64);

            SoftWorld.AddSoftBody(psb);

            CreateRigidBodyStack(10);

            CullingEnabled = false;
        }
Пример #4
0
        protected void SetConfig(SoftBody sb)
        {
            sb.Cfg.AeroModel   = this.AeroModel;
            sb.Cfg.DF          = this.DynamicFrictionCoefficient;
            sb.Cfg.DP          = this.DampingCoefficient;
            sb.Cfg.PR          = this.PressureCoefficient;
            sb.Cfg.LF          = this.LiftCoefficient;
            sb.Cfg.VC          = this.VolumeConservation;
            sb.Cfg.Collisions |= FCollisions.VFSS;

            sb.Cfg.Chr = this.RigidContactHardness;
            sb.Cfg.Shr = this.SoftContactHardness;


            sb.Cfg.DG  = this.DragCoefficient;
            sb.Cfg.Ahr = this.AnchorHardness;
            if (this.IsVolumeMass)
            {
                sb.SetVolumeMass(this.Mass);
            }
            else
            {
                sb.SetTotalMass(this.Mass, false);
            }

            if (this.GenerateBendingConstraints)
            {
                sb.GenerateBendingConstraints(this.BendingDistance);
            }
        }
Пример #5
0
        SoftBody Init_ClusterRobot_CreateBall(Vector3 pos)
        {
            SoftBody psb = SoftBodyHelpers.CreateEllipsoid(softBodyWorldInfo, pos, new Vector3(1, 1, 1) * 3, 512);

            psb.Materials[0].Lst = 0.45f;
            psb.Cfg.VC           = 20;
            psb.SetTotalMass(50, true);
            psb.SetPose(true, false);
            psb.GenerateClusters(1);
            SoftWorld.AddSoftBody(psb);
            return(psb);
        }
Пример #6
0
        void InitBunnyMatch()
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, BunnyMesh.Vertices, BunnyMesh.Indices);

            psb.Cfg.DF          = 0.5f;
            psb.Cfg.MT          = 0.05f;
            psb.Cfg.PIterations = 5;
            psb.RandomizeConstraints();
            psb.Scale(new Vector3(6, 6, 6));
            psb.SetTotalMass(100, true);
            psb.SetPose(false, true);
            SoftWorld.AddSoftBody(psb);
        }
Пример #7
0
        void InitVolume()
        {
            SoftBody psb = SoftBodyHelpers.CreateEllipsoid(softBodyWorldInfo, new Vector3(35, 25, 0),
                                                           new Vector3(1, 1, 1) * 3, 512);

            psb.Materials[0].Lst = 0.45f;
            psb.Cfg.VC           = 20;
            psb.SetTotalMass(50, true);
            psb.SetPose(true, false);
            SoftWorld.AddSoftBody(psb);

            CreateBigPlate();
            CreateStairs(10, Vector3.Zero, new Vector3(2, 1, 5));
        }
Пример #8
0
        void InitPressure()
        {
            SoftBody psb = SoftBodyHelpers.CreateEllipsoid(softBodyWorldInfo, new Vector3(35, 25, 0),
                                                           new Vector3(3, 3, 3), 512);

            psb.Materials[0].Lst = 0.1f;
            psb.Cfg.DF           = 1;
            psb.Cfg.DP           = 0.001f; // fun factor...
            psb.Cfg.PR           = 2500;
            psb.SetTotalMass(30, true);
            SoftWorld.AddSoftBody(psb);

            CreateBigPlate();
            CreateStairs(10, Vector3.Zero, new Vector3(2, 1, 5));
        }
Пример #9
0
        void InitTorusMatch()
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);

            psb.Materials[0].Lst = 0.1f;
            psb.Cfg.MT           = 0.05f;
            psb.RandomizeConstraints();
            Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) *
                       Matrix.Translation(0, 4, 0);

            psb.Transform(m);
            psb.Scale(new Vector3(2, 2, 2));
            psb.SetTotalMass(50, true);
            psb.SetPose(false, true);
            SoftWorld.AddSoftBody(psb);
        }
Пример #10
0
        void InitTorus()
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);

            psb.GenerateBendingConstraints(2);
            psb.Cfg.PIterations = 2;
            psb.RandomizeConstraints();
            Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) *
                       Matrix.Translation(0, 4, 0);

            psb.Transform(m);
            psb.Scale(new Vector3(2, 2, 2));
            psb.SetTotalMass(50, true);
            SoftWorld.AddSoftBody(psb);
            cutting = true;
        }
Пример #11
0
 void InitCollide()
 {
     for (int i = 0; i < 3; ++i)
     {
         SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);
         psb.GenerateBendingConstraints(2);
         psb.Cfg.PIterations = 2;
         psb.Cfg.Collisions |= FCollisions.VFSS;
         psb.RandomizeConstraints();
         Matrix m = Matrix.RotationYawPitchRoll((float)Math.PI / 2 * (i & 1), (float)Math.PI / 2 * (1 - (i & 1)), 0) *
                    Matrix.Translation(3 * i, 2, 0);
         psb.Transform(m);
         psb.Scale(new Vector3(2, 2, 2));
         psb.SetTotalMass(50, true);
         SoftWorld.AddSoftBody(psb);
     }
     cutting = true;
 }
Пример #12
0
        void InitBunny()
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, BunnyMesh.Vertices, BunnyMesh.Indices);
            Material pm  = psb.AppendMaterial();

            pm.Lst    = 0.5f;
            pm.Flags -= FMaterial.DebugDraw;
            psb.GenerateBendingConstraints(2, pm);
            psb.Cfg.PIterations = 2;
            psb.Cfg.DF          = 0.5f;
            psb.RandomizeConstraints();
            Matrix m = Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2, 0) *
                       Matrix.Translation(0, 4, 0);

            psb.Transform(m);
            psb.Scale(new Vector3(6, 6, 6));
            psb.SetTotalMass(100, true);
            SoftWorld.AddSoftBody(psb);
            cutting = true;
        }
Пример #13
0
        SoftBody CreateClusterTorus(Vector3 x, Vector3 a, Vector3 s)
        {
            SoftBody psb = SoftBodyHelpers.CreateFromTriMesh(softBodyWorldInfo, TorusMesh.Vertices, TorusMesh.Indices);
            Material pm  = psb.AppendMaterial();

            pm.Lst    = 1;
            pm.Flags -= FMaterial.DebugDraw;
            psb.GenerateBendingConstraints(2, pm);
            psb.Cfg.PIterations = 2;
            psb.Cfg.Collisions  = FCollisions.CLSS | FCollisions.CLRS;
            psb.RandomizeConstraints();
            psb.Scale(s);
            Matrix m = Matrix.RotationYawPitchRoll(a.X, a.Y, a.Z) * Matrix.Translation(x);

            psb.Transform(m);
            psb.SetTotalMass(50, true);
            psb.GenerateClusters(64);
            SoftWorld.AddSoftBody(psb);
            return(psb);
        }
Пример #14
0
        /// <summary>
        /// Apply these SoftBody settings to this SoftBody
        /// </summary>
        /// <param name="softBody"></param>
        public void ConfigureSoftBody(SoftBody softBody)
        {
            softBody.Scale(scale.ToBullet());

            BulletSharp.SoftBody.Material pm = softBody.Materials[0];

            sBMaterial.SetSBMaterial(pm);

            config.CopyToBulletSBConfig(softBody.Cfg);

            if (allNodeBendingConstraints)
            {
                for (int i = 0; i < softBody.Nodes.Count - 1; ++i)
                {
                    softBody.GenerateBendingConstraints(1 + i);
                }
            }
            else
            {
                softBody.GenerateBendingConstraints(bendingConstraintDistance, pm);
            }

            if (randomizeConstraints)
            {
                softBody.RandomizeConstraints();
            }

            if (generateClusters)
            {
                softBody.GenerateClusters(0);
            }

            softBody.SetTotalMass(totalMass, fromFaces);

            softBody.SetPose(bvolume, bframe);
        }