コード例 #1
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        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;
        }
コード例 #2
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
 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);
     }
 }
コード例 #3
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        void InitCloth()
        {
            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),
                                                       31, 31,
                                                       1 + 2 + 4 + 8, true);

            psb.CollisionShape.Margin = 0.5f;
            Material pm = psb.AppendMaterial();

            pm.Lst    = 0.4f;
            pm.Flags -= FMaterial.DebugDraw;
            psb.GenerateBendingConstraints(2, pm);
            psb.TotalMass = 150;
            SoftWorld.AddSoftBody(psb);

            CreateRigidBodyStack(10);
            cutting = true;

            CullingEnabled = false;
        }
コード例 #4
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        // Aerodynamic forces, 50x1g flyers
        void InitAero()
        {
            const float s        = 2;
            const int   segments = 6;
            const int   count    = 50;
            Random      random   = new Random();

            for (int i = 0; i < count; ++i)
            {
                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),
                                                           segments, segments, 0, true);
                Material pm = psb.AppendMaterial();
                pm.Flags -= FMaterial.DebugDraw;
                psb.GenerateBendingConstraints(2, pm);
                psb.Cfg.LF        = 0.004f;
                psb.Cfg.DG        = 0.0003f;
                psb.Cfg.AeroModel = AeroModel.VTwoSided;
                Matrix     trans = Matrix.Identity;
                Vector3    ra    = 0.1f * GetRandomVector(random);
                Vector3    rp    = 75 * GetRandomVector(random) + new Vector3(-50, 15, 0);
                Quaternion rot   = Quaternion.RotationYawPitchRoll(
                    (float)Math.PI / 8 + ra.X, (float)-Math.PI / 7 + ra.Y, ra.Z);
                trans *= Matrix.RotationQuaternion(rot);
                trans *= Matrix.Translation(rp);
                psb.Transform(trans);
                psb.TotalMass = 0.1f;
                psb.AddForce(new Vector3(0, (float)random.NextDouble(), 0), 0);
                SoftWorld.AddSoftBody(psb);
            }

            CullingEnabled = false;
        }
コード例 #5
0
ファイル: Physics.cs プロジェクト: diqost/bullet
 void Init_Collide3()
 {
     {
         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),
                                                       15, 15, 1 + 2 + 4 + 8, true);
         psb.Materials[0].Lst = 0.4f;
         psb.Cfg.Collisions  |= FCollisions.VFSS;
         psb.TotalMass        = 150;
         SoftWorld.AddSoftBody(psb);
     }
     {
         const float s   = 4;
         Vector3     o   = new Vector3(5, 10, 0);
         SoftBody    psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo,
                                                       new Vector3(-s, 0, -s) + o,
                                                       new Vector3(+s, 0, -s) + o,
                                                       new Vector3(-s, 0, +s) + o,
                                                       new Vector3(+s, 0, +s) + o,
                                                       7, 7, 0, true);
         Material pm = psb.AppendMaterial();
         pm.Lst    = 0.1f;
         pm.Flags -= FMaterial.DebugDraw;
         psb.GenerateBendingConstraints(2, pm);
         psb.Materials[0].Lst = 0.5f;
         psb.Cfg.Collisions  |= FCollisions.VFSS;
         psb.TotalMass        = 150;
         SoftWorld.AddSoftBody(psb);
         cutting = true;
     }
 }
コード例 #6
0
        SoftBody CreateFromIndexedMesh(Vector3Array vertexArray, IntArray triangleVertexIndexArray, bool createBendLinks)
        {
            SoftBody softBody           = new SoftBody(SoftWorld.WorldInfo, vertexArray, null);
            Material structuralMaterial = softBody.AppendMaterial();
            Material bendMaterial;

            if (createBendLinks)
            {
                bendMaterial     = softBody.AppendMaterial();
                bendMaterial.Lst = 0.7f;
            }
            else
            {
                bendMaterial = null;
            }
            structuralMaterial.Lst = 1.0f;


            int numVertices  = vertexArray.Count;
            int numTriangles = triangleVertexIndexArray.Count / 3;

            // List of values for each link saying which triangle is associated with that link
            // -1 to start. Once a value is entered we know the "other" triangle
            // and can add a link across the link
            AlignedIntArray triangleForLinks = new AlignedIntArray();

            triangleForLinks.Resize(numVertices * numVertices, -1);

            for (int triangle = 0; triangle < numTriangles; ++triangle)
            {
                int[] index = new int[] { triangleVertexIndexArray[triangle * 3], triangleVertexIndexArray[triangle * 3 + 1], triangleVertexIndexArray[triangle * 3 + 2] };
                softBody.AppendFace(index[0], index[1], index[2]);

                // Generate the structural links directly from the triangles
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[0], index[1], index[2], structuralMaterial, createBendLinks, bendMaterial);
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[1], index[2], index[0], structuralMaterial, createBendLinks, bendMaterial);
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[2], index[0], index[1], structuralMaterial, createBendLinks, bendMaterial);
            }

            return(softBody);
        }
コード例 #7
0
        void Init_Aero2()
        {
            const float s        = 5;
            const int   segments = 10;
            const int   count    = 5;
            Vector3     pos      = new Vector3(-s * segments, 0, 0);
            float       gap      = 0.5f;

            for (int i = 0; i < count; ++i)
            {
                SoftBody psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, 0, -s * 3),
                                                           new Vector3(+s, 0, -s * 3),
                                                           new Vector3(-s, 0, +s),
                                                           new Vector3(+s, 0, +s),
                                                           segments, segments * 3,
                                                           1 + 2, true);

                psb.CollisionShape.Margin = 0.5f;
                Material pm = psb.AppendMaterial();
                pm.Lst    = 0.0004f;
                pm.Flags -= FMaterial.DebugDraw;
                psb.GenerateBendingConstraints(2, pm);

                psb.Cfg.LF = 0.05f;
                psb.Cfg.DG = 0.01f;

                //psb.Cfg.LF = 0.004f;
                //psb.Cfg.DG = 0.0003f;

                psb.Cfg.PIterations = 2;
                psb.Cfg.AeroModel   = AeroModel.VTwoSidedLiftDrag;


                psb.WindVelocity = new Vector3(4, -12.0f, -25.0f);

                pos += new Vector3(s * 2 + gap, 0, 0);
                Matrix trs = Matrix.RotationX((float)Math.PI / 2) * Matrix.Translation(pos);
                psb.Transform(trs);
                psb.TotalMass = 2.0f;

                SoftBodyHelpers.ReoptimizeLinkOrder(psb);

                SoftWorld.AddSoftBody(psb);
            }

            Graphics.CullingEnabled = false;
        }
コード例 #8
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        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;
        }
コード例 #9
0
ファイル: SoftDemo.cs プロジェクト: superowner/BulletSharp
        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);
        }