protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);            

            var grid = VertexGrid.CreateGrid(100, 100, 0.3f, 100, 100);
            
            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                new ClothMeshDescription(), grid.Points,grid.TextCoords,grid.Indices, "Textures//meiofio");

            var clothDesc = new ClothDescription()
            {
                Friction = 0.5f,
                ClothMesh = ClothModel.ClothMesh,
                Flags = ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization ,
                Thickness = 0.2f,                
                WindAcceleration = new StillDesign.PhysX.MathPrimitives.Vector3(10,0,10)
            };            
                        clothDesc.MeshData.AllocatePositions<Vector3>(grid.Points.Length );
            clothDesc.MeshData.AllocateIndices<int>(grid.Indices.Length );
            clothDesc.MeshData.AllocateNormals<Vector3>(grid.Points.Length );

            clothDesc.MeshData.MaximumVertices = grid.Points.Length ;
            clothDesc.MeshData.MaximumIndices = grid.Indices.Length ;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length ;
            clothDesc.MeshData.NumberOfIndices = grid.Indices.Length ;            
            
            PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0,10,0));

            
            ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
            ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader);
            IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);
            
            World.AddObject(IObject);
            
                ///pra preender            
                CapsuleShapeDescription CapsuleShapeDescription = new StillDesign.PhysX.CapsuleShapeDescription();
                CapsuleShapeDescription.Height = 100;
                CapsuleShapeDescription.Radius = 0.15f;
                CapsuleShapeDescription.LocalPosition = new StillDesign.PhysX.MathPrimitives.Vector3(0, 0.15f + 0.5f * 10, 0);
                
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(0,-0.2f,0),
                    Shapes = { CapsuleShapeDescription }
                };

                var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc);

                PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);                
            
                        
            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Esempio n. 2
0
		public void CheckValid()
		{
			// Some basic tests to make sure the CheckValid function is being called

			ClothDescription clothDesc = new ClothDescription();

			Assert.AreEqual( 2, clothDesc.CheckValid() );
			Assert.AreEqual( 2, ((Description)clothDesc).CheckValid() );

			//

			SphericalJointDescription sphericalJointDesc = new SphericalJointDescription();

			Assert.AreEqual( 1, sphericalJointDesc.CheckValid() );
			Assert.AreEqual( 1, ((JointDescription)sphericalJointDesc).CheckValid() );
			Assert.AreEqual( 1, ((Description)sphericalJointDesc).CheckValid() );
		}
Esempio n. 3
0
        public void CheckValid()
        {
            // Some basic tests to make sure the CheckValid function is being called

            ClothDescription clothDesc = new ClothDescription();

            Assert.AreEqual(2, clothDesc.CheckValid());
            Assert.AreEqual(2, ((Description)clothDesc).CheckValid());

            //

            SphericalJointDescription sphericalJointDesc = new SphericalJointDescription();

            Assert.AreEqual(1, sphericalJointDesc.CheckValid());
            Assert.AreEqual(1, ((JointDescription)sphericalJointDesc).CheckValid());
            Assert.AreEqual(1, ((Description)sphericalJointDesc).CheckValid());
        }
Esempio n. 4
0
		public void AllocateMeshData()
		{
			ClothDescription desc = new ClothDescription();

			desc.MeshData.AllocateParentIndices<int>( 100 );
		}
Esempio n. 5
0
        public void AllocateMeshData()
        {
            ClothDescription desc = new ClothDescription();

            desc.MeshData.AllocateParentIndices <int>(100);
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);            

            int w = 25;
            int h = 25;

            float hw = w / 2.0f;
            float hh = h / 2.0f;

            Vector3 p = new Vector3(0, 20, 0);
            

            var grid = VertexGrid.CreateGrid(w, h);
            
            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                new ClothMeshDescription(), grid.Points,grid.TextCoords,grid.Indices, "Textures//meiofio");

            var clothDesc = new ClothDescription()
            {
                Friction = 0.5f,
                ClothMesh = ClothModel.ClothMesh,
                Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization ,
                Thickness = 0.2f,                
            };            
            
            clothDesc.MeshData.AllocatePositions<Vector3>(grid.Points.Length );
            clothDesc.MeshData.AllocateIndices<int>(grid.Indices.Length );
            clothDesc.MeshData.AllocateNormals<Vector3>(grid.Points.Length );

            clothDesc.MeshData.MaximumVertices = grid.Points.Length ;
            clothDesc.MeshData.MaximumIndices = grid.Indices.Length ;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length ;
            clothDesc.MeshData.NumberOfIndices = grid.Indices.Length ;            
            
            PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                Matrix.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p));
            ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
            ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader);
            IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);
            
            World.AddObject(IObject);



            // Four corner boxes to hold it in place
            var positions = new[]
			{
				new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, -hh), // Back
				new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, hh), // Front
				new StillDesign.PhysX.MathPrimitives.Vector3(-hw, 0, 0), // Left
				new StillDesign.PhysX.MathPrimitives.Vector3(hw, 0, 0), // Right
			};

            var sizes = new[]
			{
				new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Back
				new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1), // Front
				new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), // Left
				new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h), //Right
			};

            ///pra preender
            for (int i = 0; i < 2; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(positions[i] + p.AsPhysX()),
                    Shapes = { new BoxShapeDescription(sizes[i]) }
                };

                var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc);


                PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);                
            }
                        
            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Esempio n. 7
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);


            ///Cosntruct a grid of vertices to make a cloth
            int w = 50;
            int h = 50;

            float hw = w / 2.0f;
            float hh = h / 2.0f;

            Vector3 p = new Vector3(0, 70, 0);

            var grid = VertexGrid.CreateGrid(w, h);

            ///Cloth Model (Code inside the demo)
            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                                                                       new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//fabric");

            ///Cloth Description
            var clothDesc = new ClothDescription()
            {
                Friction  = 0.5f,
                ClothMesh = ClothModel.ClothMesh,
                Flags     = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.SelfCollision,
                Thickness = 0.5f,
            };

            ///Adding Cloth Vertices
            clothDesc.MeshData.AllocatePositions <Vector3>(grid.Points.Length);
            clothDesc.MeshData.AllocateIndices <int>(grid.Indices.Length);
            clothDesc.MeshData.AllocateNormals <Vector3>(grid.Points.Length);

            clothDesc.MeshData.MaximumVertices = grid.Points.Length;
            clothDesc.MeshData.MaximumIndices  = grid.Indices.Length;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
            clothDesc.MeshData.NumberOfIndices  = grid.Indices.Length;



            ///Cloth Physic Model
            PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                                                          Matrix.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p));



            ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
            ClothMaterial         ClothMaterial         = new ClothMaterial(ForwardXNABasicShader);
            IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);

            World.AddObject(IObject);


            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//table", "Textures//wood_dark");

                StillDesign.PhysX.Material material1 = PhysxPhysicWorld.CreatePhysicMaterial(
                    new StillDesign.PhysX.MaterialDescription()
                {
                    Restitution     = 0.3f,
                    DynamicFriction = 0.5f,
                    StaticFriction  = 1,
                }
                    );
                PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel,
                                                                Matrix.Identity, Vector3.One, 1, material1);

                ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
                shader.BasicEffect.EnableDefaultLighting();
            }
            {
                StillDesign.PhysX.Material material2 = PhysxPhysicWorld.CreatePhysicMaterial(
                    new StillDesign.PhysX.MaterialDescription()
                {
                    Restitution            = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    DynamicFriction        = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    StaticFriction         = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    RestitutionCombineMode = CombineMode.Max,
                }
                    );
                {
                    SimpleModel sm2 = new SimpleModel(factory, "Model\\ball");
                    sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green, false), TextureType.DIFFUSE);

                    ForwardXNABasicShader nd = new ForwardXNABasicShader();
                    IMaterial             m  = new ForwardMaterial(nd);

                    SphereShapeDescription SphereGeometry = new SphereShapeDescription(5);
                    SphereGeometry.Material = material2;

                    PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                                                                                0.5f, Matrix.CreateTranslation(new Vector3(0, 50, 0)), Vector3.One * 5f);

                    IObject o = new IObject(m, sm2, PhysxPhysicObject);
                    this.World.AddObject(o);
                    nd.BasicEffect.EnableDefaultLighting();
                    PhysxPhysicObject.isMotionLess = true;
                }
            }



            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);

            BallThrowBullet.ballSize = 1;
            BallThrowBullet.Speed    = 20;
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Esempio n. 8
0
        protected override void LoadPhysics(Scene scene)
        {
            int w = 26;
            int h = 26;

            float hw = w / 2.0f;
            float hh = h / 2.0f;

            Vector3 p = new Vector3(0, h + 1, 0);

            // Create a Grid of Points
            int vertices, indices;

            ClothMesh clothMesh;
            {
                var grid = VertexGrid.CreateGrid(w, h);

                vertices = grid.Points.Length;
                indices = grid.Indices.Length;

                ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
                clothMeshDesc.AllocateVertices<Vector3>(vertices);
                clothMeshDesc.AllocateTriangles<int>(indices / 3);

                clothMeshDesc.VertexCount = vertices;
                clothMeshDesc.TriangleCount = indices / 3;

                clothMeshDesc.VerticesStream.SetData(grid.Points);
                clothMeshDesc.TriangleStream.SetData(grid.Indices);

                // We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
                // 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
                clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
                clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);

                //var elements = new[]
                //{
                //new SlimDX.Direct3D10.InputElement("Position", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                //new SlimDX.Direct3D10.InputElement("Color", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 16, 0)
                //};
                //mesh = new SlimDX.Direct3D10.Mesh(Engine.GraphicsDevice, elements, "Position", vertices, indices / 3, SlimDX.Direct3D10.MeshFlags.Has32BitIndices);

                // Write the cooked data to memory
                using (var memoryStream = new MemoryStream())
                {
                    Cooking.InitializeCooking();
                    Cooking.CookClothMesh(clothMeshDesc, memoryStream);
                    Cooking.CloseCooking();

                    // Need to reset the position of the stream to the beginning
                    memoryStream.Position = 0;

                    clothMesh = Engine.Core.CreateClothMesh(memoryStream);
                }
            }

            //

            int j = vertices * 2;
            int k = indices * 3;

            var clothDesc = new ClothDescription()
            {
                ClothMesh = clothMesh,
                GlobalPose =
                    Matrix.RotationX((float)Math.PI / 2.0F) *
                    Matrix.Translation(-w - 1, 0, 0) *
                    Matrix.Translation(p),
                Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                BendingStiffness = 0.1f,
                TearFactor = 1.5f,
                WindAcceleration = new Vector3(windX, windY, windZ)
            };
            clothDesc.MeshData.AllocatePositions<Vector3>(j);
            clothDesc.MeshData.AllocateIndices<int>(k);
            clothDesc.MeshData.AllocateNormals<Vector3>(j);

            clothDesc.MeshData.MaximumVertices = j;
            clothDesc.MeshData.MaximumIndices = k;

            clothDesc.MeshData.NumberOfVertices = vertices;
            clothDesc.MeshData.NumberOfIndices = indices;

            _clothL = scene.CreateCloth(clothDesc);

            var clothDesc2 = new ClothDescription()
            {
                ClothMesh = clothMesh,
                GlobalPose =
                    Matrix.RotationX((float)Math.PI / 2.0F) *
                    Matrix.Translation(1, 0, 0) *
                    Matrix.Translation(p),
                Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                BendingStiffness = 0.1f,
                TearFactor = 1.5f,
                WindAcceleration = new Vector3(windX, windY, windZ)
            };
            clothDesc2.MeshData.AllocatePositions<Vector3>(j);
            clothDesc2.MeshData.AllocateIndices<int>(k);
            clothDesc2.MeshData.AllocateNormals<Vector3>(j);

            clothDesc2.MeshData.MaximumVertices = j;
            clothDesc2.MeshData.MaximumIndices = k;

            clothDesc2.MeshData.NumberOfVertices = vertices;
            clothDesc2.MeshData.NumberOfIndices = indices;

            _clothR = scene.CreateCloth(clothDesc2);
            //

            for (int i = 0; i <= w; i += 2)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(i - w - 1, 0, 0) + p),
                    Shapes = { new SphereShapeDescription(0.3F) },
                    BodyDescription = new BodyDescription(3)
                };
                var actor = scene.CreateActor(actorDesc);
                AnchorActorsL.Add(actor);
                _clothL.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
            }
            for (int i = 0; i <= w; i += 2)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(-i + w + 1, 0, 0) + p),
                    Shapes = { new SphereShapeDescription(0.3F) },
                    BodyDescription = new BodyDescription(3)
                };
                var actor = scene.CreateActor(actorDesc);
                AnchorActorsR.Add(actor);
                _clothR.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
            }
            for (int i = 0; i <= 1; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(0, -1,  0.2F * (float)Math.Pow(-1, i)) + p),
                    Shapes = { new BoxShapeDescription(new Vector3(2 * w + 4, 0.001F, 0.1F)) }
                };
                scene.CreateActor(actorDesc);
            }
            for (int i = 0; i <= 1; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(0, -1, 0.4F * (float)Math.Pow(-1, i)) + p),
                    Shapes = { new BoxShapeDescription(new Vector3(2 * w + 4, 1, 0.1F)) }
                };
                scene.CreateActor(actorDesc);
            }
            for (int i = 0; i <= 1; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3((w + 2.1F) * (float)Math.Pow(-1, i), -1, 0) + p),
                    Shapes = { new BoxShapeDescription(new Vector3(0.1F, 1, 1)) }
                };
                scene.CreateActor(actorDesc);
            }
        }
Esempio n. 9
0
 public PhysxClothObject(ClothDescription ClothDesc, Matrix world)
 {
     Scale                     = Vector3.One;
     this.ClothDesc            = ClothDesc;
     this.ClothDesc.GlobalPose = world.AsPhysX();
 }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            var grid = VertexGrid.CreateGrid(100, 100, 0.3f, 100, 100);

            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                                                                       new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//meiofio");

            var clothDesc = new ClothDescription()
            {
                Friction         = 0.5f,
                ClothMesh        = ClothModel.ClothMesh,
                Flags            = ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                Thickness        = 0.2f,
                WindAcceleration = new StillDesign.PhysX.MathPrimitives.Vector3(10, 0, 10)
            };

            clothDesc.MeshData.AllocatePositions <Vector3>(grid.Points.Length);
            clothDesc.MeshData.AllocateIndices <int>(grid.Indices.Length);
            clothDesc.MeshData.AllocateNormals <Vector3>(grid.Points.Length);

            clothDesc.MeshData.MaximumVertices = grid.Points.Length;
            clothDesc.MeshData.MaximumIndices  = grid.Indices.Length;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
            clothDesc.MeshData.NumberOfIndices  = grid.Indices.Length;

            PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                                                          Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0, 10, 0));


            ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
            ClothMaterial         ClothMaterial         = new ClothMaterial(ForwardXNABasicShader);
            IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);

            World.AddObject(IObject);

            ///pra preender
            CapsuleShapeDescription CapsuleShapeDescription = new StillDesign.PhysX.CapsuleShapeDescription();

            CapsuleShapeDescription.Height        = 100;
            CapsuleShapeDescription.Radius        = 0.15f;
            CapsuleShapeDescription.LocalPosition = new StillDesign.PhysX.MathPrimitives.Vector3(0, 0.15f + 0.5f * 10, 0);

            var actorDesc = new ActorDescription()
            {
                GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(0, -0.2f, 0),
                Shapes     = { CapsuleShapeDescription }
            };

            var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc);

            PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);


            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);

            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Esempio n. 11
0
        protected override void LoadPhysics(Scene scene)
        {
            int w = 25;
            int h = 25;

            float hw = w / 2.0f;
            float hh = h / 2.0f;

            Vector3 p = new Vector3(0, 20, 0);

            // Create a Grid of Points
            int vertices, indices;

            ClothMesh clothMesh;
            {
                var grid = VertexGrid.CreateGrid(w, h);

                vertices = grid.Points.Length;
                indices  = grid.Indices.Length;

                ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
                clothMeshDesc.AllocateVertices <Vector3>(vertices);
                clothMeshDesc.AllocateTriangles <int>(indices / 3);

                clothMeshDesc.VertexCount   = vertices;
                clothMeshDesc.TriangleCount = indices / 3;

                clothMeshDesc.VerticesStream.SetData(grid.Points);
                clothMeshDesc.TriangleStream.SetData(grid.Indices);

                // We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
                // 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
                clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
                clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);

                // Write the cooked data to memory
                using (var memoryStream = new MemoryStream())
                {
                    Cooking.InitializeCooking();
                    Cooking.CookClothMesh(clothMeshDesc, memoryStream);
                    Cooking.CloseCooking();

                    // Need to reset the position of the stream to the beginning
                    memoryStream.Position = 0;

                    clothMesh = Engine.Core.CreateClothMesh(memoryStream);
                }
            }

            //

            int j = vertices * 2;
            int k = indices * 3;

            var clothDesc = new ClothDescription()
            {
                ClothMesh  = clothMesh,
                GlobalPose =
                    Matrix.Translation(-hw, 0, -hh) *
                    Matrix.Translation(p),
                Flags            = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Tearable,
                BendingStiffness = 0.1f,
                TearFactor       = 1.5f
            };

            clothDesc.MeshData.AllocatePositions <Vector3>(j);
            clothDesc.MeshData.AllocateIndices <int>(k);
            clothDesc.MeshData.AllocateNormals <Vector3>(j);

            clothDesc.MeshData.MaximumVertices = j;
            clothDesc.MeshData.MaximumIndices  = k;

            clothDesc.MeshData.NumberOfVertices = vertices;
            clothDesc.MeshData.NumberOfIndices  = indices;

            _cloth = scene.CreateCloth(clothDesc);

            //

            // Four corner boxes to hold it in place
            var positions = new[]
            {
                new Vector3(0, 0, -hh),                // Back
                new Vector3(0, 0, hh),                 // Front
                new Vector3(-hw, 0, 0),                // Left
                new Vector3(hw, 0, 0),                 // Right
            };

            var sizes = new[]
            {
                new Vector3(w, 1, 1),                 // Back
                new Vector3(w, 1, 1),                 // Front
                new Vector3(1, 1, h),                 // Left
                new Vector3(1, 1, h),                 //Right
            };

            for (int i = 0; i < 4; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(positions[i] + p),
                    Shapes     = { new BoxShapeDescription(sizes[i]) }
                };

                var actor = scene.CreateActor(actorDesc);

                _cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
            }

            //

            // Something to drop on it
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose      = Matrix.Translation(0, 100, 0),
                    Shapes          = { new SphereShapeDescription(2) },
                    BodyDescription = new BodyDescription(50)
                };

                var actor = scene.CreateActor(actorDesc);
            }
        }
Esempio n. 12
0
		protected override void LoadPhysics(Scene scene)
		{
			int w = 25;
			int h = 25;

			float hw = w / 2.0f;
			float hh = h / 2.0f;

			Vector3 p = new Vector3(0, 20, 0);

			// Create a Grid of Points
			int vertices, indices;

			ClothMesh clothMesh;
			{
				var grid = VertexGrid.CreateGrid(w, h);

				vertices = grid.Points.Length;
				indices = grid.Indices.Length;

				ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
				clothMeshDesc.AllocateVertices<Vector3>(vertices);
				clothMeshDesc.AllocateTriangles<int>(indices / 3);

				clothMeshDesc.VertexCount = vertices;
				clothMeshDesc.TriangleCount = indices / 3;

				clothMeshDesc.VerticesStream.SetData(grid.Points);
				clothMeshDesc.TriangleStream.SetData(grid.Indices);

				// We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
				// 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
				clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
				clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);

				// Write the cooked data to memory
				using (var memoryStream = new MemoryStream())
				{
					Cooking.InitializeCooking();
					Cooking.CookClothMesh(clothMeshDesc, memoryStream);
					Cooking.CloseCooking();

					// Need to reset the position of the stream to the beginning
					memoryStream.Position = 0;

					clothMesh = Engine.Core.CreateClothMesh(memoryStream);
				}
			}

			//

			int j = vertices * 2;
			int k = indices * 3;

			var clothDesc = new ClothDescription()
			{
				ClothMesh = clothMesh,
				GlobalPose =
					Matrix.Translation(-hw, 0, -hh) *
					Matrix.Translation(p),
				Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Tearable,
				BendingStiffness = 0.1f,
				TearFactor = 1.5f
			};
			clothDesc.MeshData.AllocatePositions<Vector3>(j);
			clothDesc.MeshData.AllocateIndices<int>(k);
			clothDesc.MeshData.AllocateNormals<Vector3>(j);

			clothDesc.MeshData.MaximumVertices = j;
			clothDesc.MeshData.MaximumIndices = k;

			clothDesc.MeshData.NumberOfVertices = vertices;
			clothDesc.MeshData.NumberOfIndices = indices;

			_cloth = scene.CreateCloth(clothDesc);

			//

			// Four corner boxes to hold it in place
			var positions = new[]
			{
				new Vector3(0, 0, -hh), // Back
				new Vector3(0, 0, hh), // Front
				new Vector3(-hw, 0, 0), // Left
				new Vector3(hw, 0, 0), // Right
			};

			var sizes = new[]
			{
				new Vector3(w, 1, 1), // Back
				new Vector3(w, 1, 1), // Front
				new Vector3(1, 1, h), // Left
				new Vector3(1, 1, h), //Right
			};

			for (int i = 0; i < 4; i++)
			{
				var actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(positions[i] + p),
					Shapes = { new BoxShapeDescription(sizes[i]) }
				};

				var actor = scene.CreateActor(actorDesc);

				_cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
			}

			//

			// Something to drop on it
			{
				var actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(0, 100, 0),
					Shapes = { new SphereShapeDescription(2) },
					BodyDescription = new BodyDescription(50)
				};

				var actor = scene.CreateActor(actorDesc);
			}
		}
Esempio n. 13
0
        public static PhysX.Cloth FlagOfCloth(Scene scene)
        {
            Core core = scene.Core;

            // Create a Grid of Points
            VertexGrid grid = VertexGrid.CreateGrid(10, 10);

            ClothMeshDescription clothMeshDesc = new ClothMeshDescription();

            clothMeshDesc.AllocateVertices <Vector3>(grid.Points.Length);
            clothMeshDesc.AllocateTriangles <int>(grid.Indices.Length / 3);

            clothMeshDesc.VertexCount   = grid.Points.Length;
            clothMeshDesc.TriangleCount = grid.Indices.Length / 3;

            clothMeshDesc.VerticesStream.SetData(grid.Points);
            clothMeshDesc.TriangleStream.SetData(grid.Indices);

            // We are using 32 bit integers, so make sure the 16 bit flag is removed.
            // 32 bits are the default, so this isn't technically needed
            clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;

            // Write the cooked data to memory
            MemoryStream memoryStream = new MemoryStream();

            Cooking.InitializeCooking();
            Cooking.CookClothMesh(clothMeshDesc, memoryStream);
            Cooking.CloseCooking();

            // Need to reset the position of the stream to the beginning
            memoryStream.Position = 0;

            ClothMesh clothMesh = core.CreateClothMesh(memoryStream);

            //

            ClothDescription clothDesc = new ClothDescription()
            {
                ClothMesh  = clothMesh,
                Flags      = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                GlobalPose =
                    Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f) *
                    Matrix.Translation(0, 20, 0)
            };

            clothDesc.MeshData.AllocatePositions <Vector3>(grid.Points.Length);
            clothDesc.MeshData.AllocateIndices <int>(grid.Indices.Length);

            clothDesc.MeshData.MaximumVertices = grid.Points.Length;
            clothDesc.MeshData.MaximumIndices  = grid.Indices.Length;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
            clothDesc.MeshData.NumberOfIndices  = grid.Indices.Length;

            var flag = scene.CreateCloth(clothDesc);

            // Flag Pole
            ActorDescription flagPoleActorDesc = new ActorDescription()
            {
                GlobalPose = Matrix.Translation(0, 10, 0),
                Shapes     = { new BoxShapeDescription(1.0f, 20.0f, 1.0f) }
            };

            Actor flagPoleActor = scene.CreateActor(flagPoleActorDesc);

            flag.AttachToShape(flagPoleActor.Shapes[0], 0);
            flag.WindAcceleration = new Vector3(10, 10, 10);
            flag.BendingStiffness = 0.1f;

            return(flag);
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            int w = 25;
            int h = 25;

            float hw = w / 2.0f;
            float hh = h / 2.0f;

            Vector3 p = new Vector3(0, 20, 0);


            var grid = VertexGrid.CreateGrid(w, h);

            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                                                                       new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//meiofio");

            var clothDesc = new ClothDescription()
            {
                Friction  = 0.5f,
                ClothMesh = ClothModel.ClothMesh,
                Flags     = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                Thickness = 0.2f,
            };

            clothDesc.MeshData.AllocatePositions <Vector3>(grid.Points.Length);
            clothDesc.MeshData.AllocateIndices <int>(grid.Indices.Length);
            clothDesc.MeshData.AllocateNormals <Vector3>(grid.Points.Length);

            clothDesc.MeshData.MaximumVertices = grid.Points.Length;
            clothDesc.MeshData.MaximumIndices  = grid.Indices.Length;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
            clothDesc.MeshData.NumberOfIndices  = grid.Indices.Length;

            PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                                                          Matrix.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p));
            ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
            ClothMaterial         ClothMaterial         = new ClothMaterial(ForwardXNABasicShader);
            IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);

            World.AddObject(IObject);



            // Four corner boxes to hold it in place
            var positions = new[]
            {
                new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, -hh),                // Back
                new StillDesign.PhysX.MathPrimitives.Vector3(0, 0, hh),                 // Front
                new StillDesign.PhysX.MathPrimitives.Vector3(-hw, 0, 0),                // Left
                new StillDesign.PhysX.MathPrimitives.Vector3(hw, 0, 0),                 // Right
            };

            var sizes = new[]
            {
                new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1),                 // Back
                new StillDesign.PhysX.MathPrimitives.Vector3(w, 1, 1),                 // Front
                new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h),                 // Left
                new StillDesign.PhysX.MathPrimitives.Vector3(1, 1, h),                 //Right
            };

            ///pra preender
            for (int i = 0; i < 2; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = StillDesign.PhysX.MathPrimitives.Matrix.Translation(positions[i] + p.AsPhysX()),
                    Shapes     = { new BoxShapeDescription(sizes[i]) }
                };

                var actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc);


                PhysxClothObject.Cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
            }

            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);

            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Esempio n. 15
0
        private void LoadPhysics()
        {
            int w = 15;
            int h = 15;

            Vector3 p = new Vector3(0, 20, 0);

            // Create a Grid of Points
            int vertices, indices;

            ClothMesh clothMesh;
            {
                VertexGrid grid = VertexGrid.CreateGrid(w, h);

                vertices = grid.Points.Length;
                indices  = grid.Indices.Length;

                ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
                clothMeshDesc.AllocateVertices <Vector3>(vertices);
                clothMeshDesc.AllocateTriangles <int>(indices / 3);

                clothMeshDesc.VertexCount   = vertices;
                clothMeshDesc.TriangleCount = indices / 3;

                clothMeshDesc.VerticesStream.SetData(grid.Points);
                clothMeshDesc.TriangleStream.SetData(grid.Indices);

                // We are using 32 bit integers, so make sure the 16 bit flag is removed.
                // 32 bits are the default, so this isn't technically needed
                clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
                clothMeshDesc.Flags  = (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);

                // Write the cooked data to memory
                MemoryStream memoryStream = new MemoryStream();

                Cooking.InitializeCooking();
                Cooking.CookClothMesh(clothMeshDesc, memoryStream);
                Cooking.CloseCooking();

                // Need to reset the position of the stream to the beginning
                memoryStream.Position = 0;

                clothMesh = _core.CreateClothMesh(memoryStream);
            }

            //

            int v = vertices * 2;
            int i = indices * 3;

            ClothDescription clothDesc = new ClothDescription()
            {
                ClothMesh  = clothMesh,
                GlobalPose =
                    Matrix.CreateTranslation(-w / 2.0f, 0, -h / 2.0f) *
                    Matrix.CreateTranslation(p),
                Flags            = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Tearable,
                BendingStiffness = 0.1f
            };

            clothDesc.MeshData.AllocatePositions <Vector3>(v);
            clothDesc.MeshData.AllocateIndices <int>(i);
            clothDesc.MeshData.AllocateNormals <Vector3>(v);

            clothDesc.MeshData.MaximumVertices = v;
            clothDesc.MeshData.MaximumIndices  = i;

            clothDesc.MeshData.NumberOfVertices = vertices;
            clothDesc.MeshData.NumberOfIndices  = indices;

            _cloth = _scene.CreateCloth(clothDesc);

            //

            // Four corner boxes to hold it in place
            var positions = new[]
            {
                new Vector3(-w / 2.0f, 0, -h / 2.0f),                     // Left back
                new Vector3(-w / 2.0f, 0, h / 2.0f),                      // Left front
                new Vector3(w / 2.0f, 0, -h / 2.0f),                      // Right back
                new Vector3(w / 2.0f, 0, h / 2.0f),                       // Right front
            };

            for (int x = 0; x < 4; x++)
            {
                ActorDescription actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.CreateTranslation(positions[x] + p),
                    Shapes     = { new BoxShapeDescription(1.0f, 1.0f, 1.0f) }
                };

                Actor actor = _scene.CreateActor(actorDesc);

                _cloth.AttachToShape(actor.Shapes.Single(), 0);
            }

            //

            // Something to drop on it
            {
                ActorDescription actorDesc = new ActorDescription()
                {
                    GlobalPose      = Matrix.CreateTranslation(0, 100, 0),
                    Shapes          = { new SphereShapeDescription(2.0f) },
                    BodyDescription = new BodyDescription(50.0f)
                };

                Actor actor = _scene.CreateActor(actorDesc);
            }
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            for (int i = 0; i < 3; i++)
            {
                ClothMeshDescription ClothMeshDescription = new ClothMeshDescription();
                ClothMeshDescription.WeldingDistance = 0.0001f;
                ClothMeshDescription.Flags = (MeshFlag)(int)ClothMeshFlag.WeldVertices;


                ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                    ClothMeshDescription, "Model//ball", Vector3.One * 25, "Textures//meiofio");

                var clothDesc = new ClothDescription()
                {
                    Friction = 0.5f,
                    ClothMesh = ClothModel.ClothMesh,
                    Pressure = 0.9f,
                    Flags = ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Pressure | ClothFlag.Gravity | ClothFlag.SelfCollision | ClothFlag.TriangleCollision,
                    Thickness = 0.4f,
                };


                clothDesc.MeshData.AllocatePositions<Vector3>(ClothModel.VerticesNum);
                clothDesc.MeshData.AllocateIndices<int>(ClothModel.IndicesNum);
                clothDesc.MeshData.AllocateNormals<Vector3>(ClothModel.VerticesNum);

                clothDesc.MeshData.MaximumVertices = ClothModel.VerticesNum;
                clothDesc.MeshData.MaximumIndices = ClothModel.IndicesNum;

                clothDesc.MeshData.NumberOfVertices = ClothModel.VerticesNum;
                clothDesc.MeshData.NumberOfIndices = ClothModel.IndicesNum;

                PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                    Matrix.CreateTranslation(100, 50, i * 100));


                ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
                ClothMaterial ClothMaterial = new ClothMaterial(ForwardXNABasicShader);
                //ClothMaterial.RasterizerState.FillMode = FillMode.WireFrame;
                IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);
                World.AddObject(IObject);

                ForwardXNABasicShader.BasicEffect.EnableDefaultLighting();
            }

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Blue), TextureType.DIFFUSE);

                BoxShapeDescription SphereGeometry = new BoxShapeDescription(1000, 5, 1000);
                PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                    Matrix.Identity, new Vector3(1000, 5, 1000));

                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);

                shader.BasicEffect.EnableDefaultLighting();
            }


            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);

            for (int i = 0; i < 3; i++)
            {
                ///Different from others examples, we use a model to provide the vertices to the cloth
                ///Model must be "closed"
                ClothMeshDescription ClothMeshDescription = new ClothMeshDescription();
                ClothMeshDescription.WeldingDistance = 0.0001f;
                ClothMeshDescription.Flags           = (MeshFlag)(int)ClothMeshFlag.WeldVertices;


                ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                                                                           ClothMeshDescription, "Model//ball", Vector3.One * 25, "Textures//meiofio");

                var clothDesc = new ClothDescription()
                {
                    Friction  = 0.5f,
                    ClothMesh = ClothModel.ClothMesh,
                    Pressure  = 0.9f, ///experiment changing this =P
                    Flags     = ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Pressure | ClothFlag.Gravity | ClothFlag.SelfCollision | ClothFlag.TriangleCollision,
                    Thickness = 0.4f,
                };


                clothDesc.MeshData.AllocatePositions <Vector3>(ClothModel.VerticesNum);
                clothDesc.MeshData.AllocateIndices <int>(ClothModel.IndicesNum);
                clothDesc.MeshData.AllocateNormals <Vector3>(ClothModel.VerticesNum);

                clothDesc.MeshData.MaximumVertices = ClothModel.VerticesNum;
                clothDesc.MeshData.MaximumIndices  = ClothModel.IndicesNum;

                clothDesc.MeshData.NumberOfVertices = ClothModel.VerticesNum;
                clothDesc.MeshData.NumberOfIndices  = ClothModel.IndicesNum;

                PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                                                              Matrix.CreateTranslation(100, 50, i * 100));


                ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
                ClothMaterial         ClothMaterial         = new ClothMaterial(ForwardXNABasicShader);
                //ClothMaterial.RasterizerState.FillMode = FillMode.WireFrame;
                IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);
                World.AddObject(IObject);

                ForwardXNABasicShader.BasicEffect.EnableDefaultLighting();
            }

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Blue), TextureType.DIFFUSE);

                BoxShapeDescription SphereGeometry    = new BoxShapeDescription(1000, 5, 1000);
                PhysxPhysicObject   PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                                                                              Matrix.Identity, new Vector3(1000, 5, 1000));

                ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, PhysxPhysicObject);
                this.World.AddObject(obj);

                shader.BasicEffect.EnableDefaultLighting();
            }


            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);

            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Esempio n. 18
0
		public static PhysX.Cloth FlagOfCloth(Scene scene)
		{
			Core core = scene.Core;

			// Create a Grid of Points
			VertexGrid grid = VertexGrid.CreateGrid(10, 10);

			ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
			clothMeshDesc.AllocateVertices<Vector3>(grid.Points.Length);
			clothMeshDesc.AllocateTriangles<int>(grid.Indices.Length / 3);

			clothMeshDesc.VertexCount = grid.Points.Length;
			clothMeshDesc.TriangleCount = grid.Indices.Length / 3;

			clothMeshDesc.VerticesStream.SetData(grid.Points);
			clothMeshDesc.TriangleStream.SetData(grid.Indices);

			// We are using 32 bit integers, so make sure the 16 bit flag is removed.
			// 32 bits are the default, so this isn't technically needed
			clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;

			// Write the cooked data to memory
			MemoryStream memoryStream = new MemoryStream();

			Cooking.InitializeCooking();
			Cooking.CookClothMesh(clothMeshDesc, memoryStream);
			Cooking.CloseCooking();

			// Need to reset the position of the stream to the beginning
			memoryStream.Position = 0;

			ClothMesh clothMesh = core.CreateClothMesh(memoryStream);

			//

			ClothDescription clothDesc = new ClothDescription()
			{
				ClothMesh = clothMesh,
				Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
				GlobalPose =
					Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f) *
					Matrix.Translation(0, 20, 0)
			};
			clothDesc.MeshData.AllocatePositions<Vector3>(grid.Points.Length);
			clothDesc.MeshData.AllocateIndices<int>(grid.Indices.Length);

			clothDesc.MeshData.MaximumVertices = grid.Points.Length;
			clothDesc.MeshData.MaximumIndices = grid.Indices.Length;

			clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
			clothDesc.MeshData.NumberOfIndices = grid.Indices.Length;

			var flag = scene.CreateCloth(clothDesc);

			// Flag Pole
			ActorDescription flagPoleActorDesc = new ActorDescription()
			{
				GlobalPose = Matrix.Translation(0, 10, 0),
				Shapes = { new BoxShapeDescription(1.0f, 20.0f, 1.0f) }
			};

			Actor flagPoleActor = scene.CreateActor(flagPoleActorDesc);

			flag.AttachToShape(flagPoleActor.Shapes[0], 0);
			flag.WindAcceleration = new Vector3(10, 10, 10);
			flag.BendingStiffness = 0.1f;

			return flag;
		}
        /// <summary>Simple examples of all the PhysX bits running together</summary>
        private void LoadPhysics()
        {
            // The ground plane (if created) sould be the first actor
            _groundActor      = _scene.Actors.First();
            _groundActor.Name = "Default Ground Plane";

            //

            #region Some Boxes
            for (int x = 0; x < 5; x++)
            {
                BoxShapeDescription boxShapeDesc = new BoxShapeDescription(2, 3, 8);

                ActorDescription actorDesc = new ActorDescription()
                {
                    Name            = String.Format("Box {0}", x),
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.CreateTranslation(100, 15 + 3 * x, 20),
                    Shapes          = { boxShapeDesc }
                };

                Actor actor = _scene.CreateActor(actorDesc);
            }
            #endregion

            #region Cloth (Flag)
            {
                // Create a Grid of Points
                VertexGrid grid = VertexGrid.CreateGrid(10, 10);

                ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
                clothMeshDesc.AllocateVertices <Vector3>(grid.Points.Length);
                clothMeshDesc.AllocateTriangles <int>(grid.Indices.Length / 3);

                clothMeshDesc.VertexCount   = grid.Points.Length;
                clothMeshDesc.TriangleCount = grid.Indices.Length / 3;

                clothMeshDesc.VerticesStream.SetData(grid.Points);
                clothMeshDesc.TriangleStream.SetData(grid.Indices);

                // We are using 32 bit integers, so make sure the 16 bit flag is removed.
                // 32 bits are the default, so this isn't technically needed
                clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;

                // Write the cooked data to memory
                MemoryStream memoryStream = new MemoryStream();

                Cooking.InitializeCooking();
                Cooking.CookClothMesh(clothMeshDesc, memoryStream);
                Cooking.CloseCooking();

                // Need to reset the position of the stream to the beginning
                memoryStream.Position = 0;

                ClothMesh clothMesh = _core.CreateClothMesh(memoryStream);

                //

                ClothDescription clothDesc = new ClothDescription()
                {
                    ClothMesh  = clothMesh,
                    Flags      = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                    GlobalPose =
                        Matrix.CreateFromYawPitchRoll(0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f) *
                        Matrix.CreateTranslation(0, 20, 0)
                };
                clothDesc.MeshData.AllocatePositions <Vector3>(grid.Points.Length);
                clothDesc.MeshData.AllocateIndices <int>(grid.Indices.Length);

                clothDesc.MeshData.MaximumVertices = grid.Points.Length;
                clothDesc.MeshData.MaximumIndices  = grid.Indices.Length;

                clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
                clothDesc.MeshData.NumberOfIndices  = grid.Indices.Length;

                _flag = _scene.CreateCloth(clothDesc);

                // Flag Pole
                ActorDescription flagPoleActorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.CreateTranslation(0, 10, 0),
                    Shapes     = { new BoxShapeDescription(1.0f, 20.0f, 1.0f) }
                };

                Actor flagPoleActor = _scene.CreateActor(flagPoleActorDesc);

                _flag.AttachToShape(flagPoleActor.Shapes[0], 0);
                _flag.WindAcceleration = new Vector3(10, 10, 10);
                _flag.BendingStiffness = 0.1f;
            }
            #endregion

            #region Revolute Joint
            {
                BoxShapeDescription boxShapeDescA = new BoxShapeDescription(3, 3, 3);
                BoxShapeDescription boxShapeDescB = new BoxShapeDescription(3, 3, 3);

                ActorDescription actorDescA = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.CreateTranslation(75, 1.5f, 55),
                    Shapes          = { boxShapeDescA }
                };
                Actor actorA = _scene.CreateActor(actorDescA);

                ActorDescription actorDescB = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.CreateTranslation(70, 1.5f, 55),
                    Shapes          = { boxShapeDescB }
                };
                Actor actorB = _scene.CreateActor(actorDescB);

                //

                RevoluteJointDescription revoluteJointDesc = new RevoluteJointDescription()
                {
                    Actor1 = actorA,
                    Actor2 = actorB,
                    Motor  = new MotorDescription(20, 20.1f, true)
                };
                revoluteJointDesc.Flags |= RevoluteJointFlag.MotorEnabled;
                revoluteJointDesc.SetGlobalAnchor(new Vector3(73.5f, 1.5f, 55));
                revoluteJointDesc.SetGlobalAxis(new Vector3(1, 0, 0));

                RevoluteJoint revoluteJoint = _scene.CreateJoint(revoluteJointDesc) as RevoluteJoint;
            }
            #endregion

            #region Prismatic Joint with Limit
            {
                Actor actorA, actorB;
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                    BodyDescription bodyDesc = new BodyDescription(10.0f);
                    bodyDesc.BodyFlags |= BodyFlag.Kinematic;

                    ActorDescription actorDesc = new ActorDescription()
                    {
                        BodyDescription = bodyDesc,
                        GlobalPose      = Matrix.CreateTranslation(70, 25, 65),
                        Shapes          = { boxShapeDesc }
                    };
                    actorA = _scene.CreateActor(actorDesc);
                }
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                    ActorDescription actorDesc = new ActorDescription()
                    {
                        BodyDescription = new BodyDescription(10.0f),
                        GlobalPose      = Matrix.CreateTranslation(70, 15, 65),
                        Shapes          = { boxShapeDesc }
                    };
                    actorB = _scene.CreateActor(actorDesc);
                }

                PrismaticJointDescription prismaticJointDesc = new PrismaticJointDescription()
                {
                    Actor1 = actorA,
                    Actor2 = actorB,
                };
                prismaticJointDesc.SetGlobalAnchor(new Vector3(70, 20, 65));
                prismaticJointDesc.SetGlobalAxis(new Vector3(0, 1, 0));

                PrismaticJoint prismaticJoint = _scene.CreateJoint(prismaticJointDesc) as PrismaticJoint;

                LimitPlane limitPlane = new LimitPlane(new Vector3(0, 1, 0), new Vector3(-30, 8, -30), 0);
                prismaticJoint.AddLimitPlane(limitPlane);
            }
            #endregion

            #region Fluid
            {
                const int maximumParticles = 1000;

                FluidEmitterDescription fluidEmitterDesc = new FluidEmitterDescription()
                {
                    DimensionX   = 0.5f,
                    DimensionY   = 0.5f,
                    Rate         = 15,
                    RelativePose = Matrix.CreateTranslation(-40, 10, 50),
                    Shape        = EmitterShape.Rectangular,
                    Type         = EmitterType.ConstantFlowRate,
                    RandomAngle  = 0.5f
                };
                fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

                FluidDescription fluidDesc = new FluidDescription()
                {
                    Emitters         = { fluidEmitterDesc },
                    Flags            = FluidFlag.Enabled | FluidFlag.Visualization,
                    MaximumParticles = maximumParticles
                };
                fluidDesc.ParticleWriteData.AllocatePositionBuffer <Vector3>(maximumParticles);
                fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

                Fluid fluid = _scene.CreateFluid(fluidDesc);

                // Ledge
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);

                    ActorDescription drainActorDesc = new ActorDescription()
                    {
                        GlobalPose = Matrix.CreateRotationX(0.5f) * Matrix.CreateTranslation(-40, 5, 52),
                        Shapes     = { boxShapeDesc }
                    };

                    Actor drianActor = _scene.CreateActor(drainActorDesc);
                }

                // Drain
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                    boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

                    ActorDescription drainActorDesc = new ActorDescription()
                    {
                        GlobalPose = Matrix.CreateTranslation(-40, 0, 55),
                        Shapes     = { boxShapeDesc }
                    };

                    Actor drianActor = _scene.CreateActor(drainActorDesc);
                }
            }
            #endregion

            #region Force Field
            {
                BoxForceFieldShapeDescription boxForceFieldShapeDesc = new BoxForceFieldShapeDescription()
                {
                    Size = new Vector3(10, 10, 10)
                };

                ForceFieldLinearKernelDescription kernelDesc = new ForceFieldLinearKernelDescription()
                {
                    Constant = new Vector3(0, 100.0f, 0)
                };

                ForceFieldLinearKernel kernel = _scene.CreateForceFieldLinearKernel(kernelDesc);

                ForceFieldShapeGroupDescription shapeGroupDesc = new ForceFieldShapeGroupDescription()
                {
                    Shapes = { boxForceFieldShapeDesc }
                };

                ForceFieldShapeGroup shapeGroup = _scene.CreateForceFieldShapeGroup(shapeGroupDesc);

                BoxForceFieldShape boxForceFieldShape = shapeGroup.CreateShape(boxForceFieldShapeDesc) as BoxForceFieldShape;
                boxForceFieldShape.Pose = Matrix.CreateTranslation(30, 5, 0);

                ForceFieldDescription forceFieldDesc = new ForceFieldDescription()
                {
                    Kernel      = kernel,
                    ShapeGroups = { shapeGroup }
                };
                ForceField forceField = _scene.CreateForceField(forceFieldDesc);
            }
            #endregion

            #region Heightfield
            {
                int rows    = 25;
                int columns = 25;

                HeightFieldSample[] samples = new HeightFieldSample[rows * columns];
                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < columns; c++)
                    {
                        // Put a z and x curve together
                        double h = Math.Sin(c) * Math.Cos(r) * short.MaxValue;

                        HeightFieldSample sample = new HeightFieldSample();
                        sample.Height           = (short)h;
                        sample.MaterialIndex0   = 0;
                        sample.MaterialIndex1   = 1;
                        sample.TessellationFlag = 0;

                        samples[r * columns + c] = sample;
                    }
                }

                HeightFieldDescription heightFieldDesc = new HeightFieldDescription()
                {
                    NumberOfRows    = rows,
                    NumberOfColumns = columns,
                    Samples         = samples
                };

                HeightField heightField = _core.CreateHeightField(heightFieldDesc);

                //

                HeightFieldShapeDescription heightFieldShapeDesc = new HeightFieldShapeDescription()
                {
                    HeightField  = heightField,
                    HoleMaterial = 2,
                    // The max height of our samples is short.MaxValue and we want it to be 1
                    HeightScale = 1.0f / (float)short.MaxValue,
                    RowScale    = 3,
                    ColumnScale = 3
                };
                heightFieldShapeDesc.LocalPosition = new Vector3(-0.5f * rows * 1 * heightFieldShapeDesc.RowScale, 0, -0.5f * columns * 1 * heightFieldShapeDesc.ColumnScale);

                ActorDescription actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.CreateTranslation(100, 0, 0),
                    Shapes     = { heightFieldShapeDesc }
                };
                Actor actor = _scene.CreateActor(actorDesc);
            }
            #endregion

            #region Convex Mesh
            {
                ModelMesh mesh = _torusModel.Meshes.First();

                Matrix[] transforms = new Matrix[_torusModel.Bones.Count];
                _torusModel.CopyAbsoluteBoneTransformsTo(transforms);

                // Gets the vertices from the mesh
                VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[mesh.MeshParts[0].NumVertices];
                mesh.VertexBuffer.GetData <VertexPositionNormalTexture>(vertices);

                //

                // Allocate memory for the points and triangles
                var convexMeshDesc = new ConvexMeshDescription()
                {
                    PointCount = vertices.Length
                };
                convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
                convexMeshDesc.AllocatePoints <Vector3>(vertices.Length);

                // Write in the points and triangles
                // We only want the Position component of the vertex. Also scale down the mesh
                foreach (VertexPositionNormalTexture vertex in vertices)
                {
                    Vector3 position = Vector3.Transform(vertex.Position, Matrix.CreateScale(0.1f, 0.1f, 0.1f) * transforms[0]);

                    convexMeshDesc.PointsStream.Write(position);
                }

                //

                // Cook to memory or to a file
                MemoryStream stream = new MemoryStream();
                //FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

                Cooking.InitializeCooking(new ConsoleOutputStream());
                Cooking.CookConvexMesh(convexMeshDesc, stream);
                Cooking.CloseCooking();

                stream.Position = 0;

                ConvexMesh convexMesh = _core.CreateConvexMesh(stream);

                ConvexShapeDescription convexShapeDesc = new ConvexShapeDescription(convexMesh);

                ActorDescription actorDesc = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.CreateTranslation(30, 30, 0)
                };
                actorDesc.Shapes.Add(convexShapeDesc);

                _torusActor = _scene.CreateActor(actorDesc);
            }
            #endregion

            #region SoftBody
            if (false)              // Enable to view soft bodies, they run slowly
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("Teapot.xml");

                // Not how NxuStream are meant to used but what ever :S
                Vector3[] vertices          = ReadVertices(doc.SelectSingleNode("/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/vertices"));
                int[]     tetrahedraSingles = ReadTetrahedra(doc.SelectSingleNode("/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/tetrahedra"));

                var softBodyMeshDesc = new SoftBodyMeshDescription()
                {
                    VertexCount     = vertices.Length,
                    TetrahedraCount = tetrahedraSingles.Length / 4                     // Tetrahedras come in quadruples of ints
                };

                softBodyMeshDesc.AllocateVertices <Vector3>(softBodyMeshDesc.VertexCount);
                softBodyMeshDesc.AllocateTetrahedra <int>(softBodyMeshDesc.TetrahedraCount);                  // Note: T is an int. T is the type of each point

                softBodyMeshDesc.VertexStream.SetData(vertices);
                softBodyMeshDesc.TetrahedraStream.SetData(tetrahedraSingles);

                MemoryStream memoryStream = new MemoryStream();

                Cooking.InitializeCooking();
                Cooking.CookSoftBodyMesh(softBodyMeshDesc, memoryStream);
                Cooking.CloseCooking();

                memoryStream.Position = 0;

                SoftBodyMesh softBodyMesh = _core.CreateSoftBodyMesh(memoryStream);

                SoftBodyDescription desc = new SoftBodyDescription()
                {
                    GlobalPose   = Matrix.CreateTranslation(-30, 20, -30),
                    SoftBodyMesh = softBodyMesh
                };
                desc.Flags |= SoftBodyFlag.Visualization;

                desc.MeshData.AllocatePositions <Vector3>(vertices.Length);
                desc.MeshData.AllocateIndices <int>(tetrahedraSingles.Length);

                SoftBody softBody = _scene.CreateSoftBody(desc);
            }
            #endregion

            #region Reports
            // Contact report
            // When the capsule actor hits the ground make it bounce by using the conact report
            {
                CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription(1, 5);

                ActorDescription actorDesc = new ActorDescription()
                {
                    GlobalPose      = Matrix.CreateTranslation(-30, 20, 0),
                    BodyDescription = new BodyDescription(10.0f),
                    Name            = "Report Capsule",
                    Shapes          = { capsuleShapeDesc }
                };

                _contactReportActor = _scene.CreateActor(actorDesc);

                _scene.SetActorPairFlags(_contactReportActor, _groundActor, ContactPairFlag.All);

                _scene.UserContactReport = new ContactReport(this);
            }

            // Trigger Reports
            {
                BoxShapeDescription boxShapeDesc = new BoxShapeDescription(15, 8, 15);
                boxShapeDesc.Flags |= (ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave);

                ActorDescription actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.CreateTranslation(-30, 4, 0),
                    Shapes     = { boxShapeDesc }
                };
                _scene.CreateActor(actorDesc);

                _scene.UserTriggerReport = new TriggerReport(this);
            }

            _scene.UserNotify = new Notify(this);
            #endregion

            #region Wheel
            {
                _basicVehicle = new Vehicle(this);
            }
            #endregion

            #region Controller
            {
                ControllerManager manager = _scene.CreateControllerManager();

                CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription(4, 3)
                {
                    Callback = new ControllerHitReport()
                };

                CapsuleController capsuleController = manager.CreateController <CapsuleController>(capsuleControllerDesc);
                capsuleController.Position   = new Vector3(0, 1.5f + 2, -15);
                capsuleController.Actor.Name = "BoxController";
                capsuleController.SetCollisionEnabled(true);
            }
            #endregion
        }
 public PhysxClothObject(ClothDescription ClothDesc,Matrix world)
 {
     Scale = Vector3.One;
     this.ClothDesc = ClothDesc;
     this.ClothDesc.GlobalPose = world.AsPhysX();            
 }