Ejemplo n.º 1
0
        public void CreateFlag()
        {
            var clothGrid = new ClothTestGrid(10, 10);

            using (var physics = CreatePhysicsAndScene())
            {
                using (var cooking = physics.Physics.CreateCooking())
                {
                    var clothMeshDesc = new ClothMeshDesc()
                    {
                        Points    = clothGrid.Points,
                        Triangles = ArrayUtil.ToByteArray(clothGrid.Indices)
                    };

                    MemoryStream stream = new MemoryStream();

                    cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -9.81f, 0), stream);

                    // After cooking the fabric, we must put the position of the written stream back to 0
                    // so that it can be read from the beginning in the CreateClothFabric method
                    stream.Position = 0;

                    ClothFabric clothFabric = physics.Physics.CreateClothFabric(stream);

                    ClothParticle[] particles = clothGrid.Points.Select(p => new ClothParticle(p, 2)).ToArray();

                    Cloth cloth = physics.Physics.CreateCloth(Matrix4x4.Identity, clothFabric, particles, 0);
                }
            }
        }
Ejemplo n.º 2
0
        public void CreateFlag()
        {
            var clothGrid = new ClothTestGrid(10, 10);

            using (var physics = CreatePhysicsAndScene())
            {
                Cooking cooking = physics.Physics.CreateCooking();

                ClothMeshDesc clothMeshDesc = new ClothMeshDesc()
                {
                    Points    = clothGrid.Points,
                    Triangles = clothGrid.Indices
                };

                MemoryStream stream = new MemoryStream();

                bool result = cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -9.81f, 0), stream);

                ClothFabric clothFabric = physics.Physics.CreateClothFabric(stream);

                ClothParticle[] particles = clothGrid.Points.Select(p => new ClothParticle(p, 2)).ToArray();

                ClothCollisionData collision = new ClothCollisionData();

                Cloth cloth = physics.Physics.CreateCloth(Matrix.Identity, clothFabric, particles, collision, 0);
            }
        }
Ejemplo n.º 3
0
		public void CreateFlag()
		{
			var clothGrid = new ClothTestGrid(10, 10);

			using (var physics = CreatePhysicsAndScene())
			{
				Cooking cooking = physics.Physics.CreateCooking();

				ClothMeshDesc clothMeshDesc = new ClothMeshDesc()
				{
					Points = clothGrid.Points,
					Triangles = clothGrid.Indices
				};

				MemoryStream stream = new MemoryStream();

				bool result = cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -9.81f, 0), stream);

				ClothFabric clothFabric = physics.Physics.CreateClothFabric(stream);

				ClothParticle[] particles = clothGrid.Points.Select(p => new ClothParticle(p, 2)).ToArray();

				ClothCollisionData collision = new ClothCollisionData();

				Cloth cloth = physics.Physics.CreateCloth(Matrix.Identity, clothFabric, particles, collision, 0);
			}
		}
Ejemplo n.º 4
0
		public void CreateTriangleMeshShape()
		{
			var physics = CreatePhysicsAndScene();

			var material = physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f);

			var actor = physics.Physics.CreateRigidDynamic();

			var grid = new ClothTestGrid(10, 10);

			var triangleMeshDesc = new TriangleMeshDesc();
			triangleMeshDesc.Points = grid.Points;
			triangleMeshDesc.SetTriangles(grid.Indices);

			var cooking = physics.Physics.CreateCooking();

			var cookedStream = new MemoryStream();

			bool result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream);

			Assert.IsTrue(result);

			cookedStream.Position = 0;

			var triangleMesh = physics.Physics.CreateTriangleMesh(cookedStream);

			var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh);

			var shape = actor.CreateShape(triangleMeshGeometry, material);

			physics.Scene.AddActor(actor);
		}
Ejemplo n.º 5
0
		public void CreateFlag()
		{
			var clothGrid = new ClothTestGrid(10, 10);

			using (var physics = CreatePhysicsAndScene())
			{
				using (Cooking cooking = physics.Physics.CreateCooking())
				{
					var clothMeshDesc = new ClothMeshDesc()
					{
						Points = clothGrid.Points,
						Triangles = ArrayUtil.ToByteArray(clothGrid.Indices)
					};

					MemoryStream stream = new MemoryStream();

					cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -9.81f, 0), stream);

					// After cooking the fabric, we must put the position of the written stream back to 0
					// so that it can be read from the beginning in the CreateClothFabric method
					stream.Position = 0;

					ClothFabric clothFabric = physics.Physics.CreateClothFabric(stream);

					ClothParticle[] particles = clothGrid.Points.Select(p => new ClothParticle(p, 2)).ToArray();

					Cloth cloth = physics.Physics.CreateCloth(Matrix.Identity, clothFabric, particles, 0);
				}
			}
		}
Ejemplo n.º 6
0
        public void CreateTriangleMeshShape()
        {
            var physics = CreatePhysicsAndScene();

            var material = physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f);

            var actor = physics.Physics.CreateRigidDynamic();

            var grid = new ClothTestGrid(10, 10);

            var triangleMeshDesc = new TriangleMeshDesc();

            triangleMeshDesc.Points = grid.Points;
            triangleMeshDesc.SetTriangles(grid.Indices);

            var cooking = physics.Physics.CreateCooking();

            var cookedStream = new MemoryStream();

            bool result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream);

            Assert.IsTrue(result);

            cookedStream.Position = 0;

            var triangleMesh = physics.Physics.CreateTriangleMesh(cookedStream);

            var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh);

            var shape = actor.CreateShape(triangleMeshGeometry, material);

            physics.Scene.AddActor(actor);
        }
Ejemplo n.º 7
0
        public void GetTriangleMeshGeometry()
        {
            var material = _physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f);

            var actor = _physics.Physics.CreateRigidDynamic();

            // Triangle mesh can only be created on a kinematic actor
            actor.RigidBodyFlags = RigidBodyFlag.Kinematic;

            var grid = new ClothTestGrid(10, 10);

            var triangleMeshDesc = new TriangleMeshDesc();

            triangleMeshDesc.Points = grid.Points;
            triangleMeshDesc.SetTriangles(grid.Indices);

            MemoryStream cookedStream;

            using (var cooking = _physics.Physics.CreateCooking())
            {
                cookedStream = new MemoryStream();

                var result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream);

                Assert.AreEqual(TriangleMeshCookingResult.Success, result);

                cookedStream.Position = 0;
            }

            var triangleMesh = _physics.Physics.CreateTriangleMesh(cookedStream);

            var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh);

            var shape = actor.CreateShape(triangleMeshGeometry, material);

            //

            var retrievedTriangleMeshGeom = shape.GetTriangleMeshGeometry();

            Assert.IsNotNull(retrievedTriangleMeshGeom);
            Assert.AreEqual(triangleMesh, retrievedTriangleMeshGeom.TriangleMesh);
            Assert.AreEqual(GeometryType.TriangleMesh, retrievedTriangleMeshGeom.Type);
            Assert.AreEqual(new MeshScale(new Vector3(1), Quaternion.Identity), retrievedTriangleMeshGeom.Scale);
            Assert.AreEqual((MeshGeometryFlag)0, retrievedTriangleMeshGeom.MeshFlags);
        }
Ejemplo n.º 8
0
        public void LockParticleDataToReadPositions()
        {
            var clothGrid = new ClothTestGrid(10, 10);

            using (var physics = CreatePhysicsAndScene())
            {
                using (var cooking = physics.Physics.CreateCooking())
                {
                    var clothMeshDesc = new ClothMeshDesc()
                    {
                        Points    = clothGrid.Points,
                        Triangles = ArrayUtil.ToByteArray(clothGrid.Indices)
                    };

                    MemoryStream stream = new MemoryStream();

                    cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -9.81f, 0), stream);

                    // After cooking the fabric, we must put the position of the written stream back to 0
                    // so that it can be read from the beginning in the CreateClothFabric method
                    stream.Position = 0;

                    ClothFabric clothFabric = physics.Physics.CreateClothFabric(stream);

                    ClothParticle[] particles = clothGrid.Points.Select(p => new ClothParticle(p, 2)).ToArray();

                    Cloth cloth = physics.Physics.CreateCloth(Matrix4x4.Identity, clothFabric, particles, 0);

                    var read = cloth.LockParticleData();

                    // Are the particle positions the right length
                    Assert.AreEqual(121, read.Particles.Length);

                    // And initially is what we read back the same as what we started with
                    for (int i = 0; i < 121; i++)
                    {
                        Assert.AreEqual(clothGrid.Points[i], read.Particles[i].Position);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void GetActors_Cloth()
        {
            using (var physics = CreatePhysicsAndScene())
            {
                PhysX.Cloth cloth;

                using (var cooking = physics.Physics.CreateCooking())
                {
                    var clothGrid = new ClothTestGrid(10, 10);

                    var clothMeshDesc = new ClothMeshDesc
                    {
                        Points    = clothGrid.Points,
                        Triangles = ArrayUtil.ToByteArray(clothGrid.Indices)
                    };

                    var stream = new MemoryStream();

                    cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -9.81f, 0), stream);

                    // After cooking the fabric, we must put the position of the written stream back to 0
                    // so that it can be read from the beginning in the CreateClothFabric method
                    stream.Position = 0;

                    var clothFabric = physics.Physics.CreateClothFabric(stream);

                    var particles = clothGrid.Points.Select(p => new ClothParticle(p, 2)).ToArray();

                    cloth = physics.Physics.CreateCloth(Matrix4x4.Identity, clothFabric, particles, 0);

                    physics.Scene.AddActor(cloth);
                }

                //

                var actors = physics.Scene.GetActors(ActorTypeSelectionFlag.Cloth);

                Assert.AreEqual(1, actors.Count);
                Assert.AreEqual(cloth, actors[0]);
            }
        }
Ejemplo n.º 10
0
		public void LockParticleDataToReadPositions()
		{
			var clothGrid = new ClothTestGrid(10, 10);

			using (var physics = CreatePhysicsAndScene())
			{
				using (Cooking cooking = physics.Physics.CreateCooking())
				{
					var clothMeshDesc = new ClothMeshDesc()
					{
						Points = clothGrid.Points,
						Triangles = ArrayUtil.ToByteArray(clothGrid.Indices)
					};

					MemoryStream stream = new MemoryStream();

					cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -9.81f, 0), stream);

					// After cooking the fabric, we must put the position of the written stream back to 0
					// so that it can be read from the beginning in the CreateClothFabric method
					stream.Position = 0;

					ClothFabric clothFabric = physics.Physics.CreateClothFabric(stream);

					ClothParticle[] particles = clothGrid.Points.Select(p => new ClothParticle(p, 2)).ToArray();

					Cloth cloth = physics.Physics.CreateCloth(Matrix4x4.Identity, clothFabric, particles, 0);

					var read = cloth.LockParticleData();

					// Are the particle positions the right length
					Assert.AreEqual(121, read.Particles.Length);

					// And initially is what we read back the same as what we started with
					for (int i = 0; i < 121; i++)
					{
						Assert.AreEqual(clothGrid.Points[i], read.Particles[i].Position);
					}
				}
			}
		}
Ejemplo n.º 11
0
        public void CreateTriangleMeshShape()
        {
            using (var physics = CreatePhysicsAndScene())
            {
                var material = physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f);

                var actor = physics.Physics.CreateRigidDynamic();

                // Triangle mesh can only be created on a kinematic actor
                actor.RigidBodyFlags = RigidBodyFlag.Kinematic;

                var grid = new ClothTestGrid(10, 10);

                var triangleMeshDesc = new TriangleMeshDesc();
                triangleMeshDesc.Points = grid.Points;
                triangleMeshDesc.SetTriangles(grid.Indices);

                using (var cooking = physics.Physics.CreateCooking())
                {
                    var cookedStream = new MemoryStream();

                    var result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream);

                    Assert.AreEqual(TriangleMeshCookingResult.Success, result);

                    cookedStream.Position = 0;

                    var triangleMesh = physics.Physics.CreateTriangleMesh(cookedStream);

                    var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh);

                    var shape = actor.CreateShape(triangleMeshGeometry, material);

                    physics.Scene.AddActor(actor);
                }
            }
        }
Ejemplo n.º 12
0
		public void GetTriangleMeshGeometry()
		{
			var material = _physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f);

			var actor = _physics.Physics.CreateRigidDynamic();

			// Triangle mesh can only be created on a kinematic actor
			actor.Flags = RigidDynamicFlags.Kinematic;

			var grid = new ClothTestGrid(10, 10);

			var triangleMeshDesc = new TriangleMeshDesc();
			triangleMeshDesc.Points = grid.Points;
			triangleMeshDesc.SetTriangles(grid.Indices);

			MemoryStream cookedStream;
			using (var cooking = _physics.Physics.CreateCooking())
			{
				cookedStream = new MemoryStream();

				bool result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream);

				Assert.IsTrue(result);

				cookedStream.Position = 0;
			}

			var triangleMesh = _physics.Physics.CreateTriangleMesh(cookedStream);

			var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh);

			var shape = actor.CreateShape(triangleMeshGeometry, material);

			//

			var retrievedTriangleMeshGeom = shape.GetTriangleMeshGeometry();

			Assert.IsNotNull(retrievedTriangleMeshGeom);
			Assert.AreEqual(triangleMesh, retrievedTriangleMeshGeom.TriangleMesh);
			Assert.AreEqual(GeometryType.TriangleMesh, retrievedTriangleMeshGeom.Type);
			Assert.AreEqual(new MeshScale(new Vector3(1), Quaternion.Identity), retrievedTriangleMeshGeom.Scale);
			Assert.AreEqual((MeshGeometryFlag)0, retrievedTriangleMeshGeom.MeshFlags);
		}