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); } }
private Cloth CreateCloth(Scene scene) { // Create a grid of triangles to be our cloth var clothGrid = new VertexGrid(25, 25); // Setup the grid for cooking var clothMeshDesc = new ClothMeshDesc() { Points = clothGrid.Points, Triangles = clothGrid.Indices }; // Cook var clothFabricStream = new MemoryStream(); using (var cooking = scene.Physics.CreateCooking()) { bool result = cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -1, 0), clothFabricStream); if (!result) { throw new Exception("Failed to cook deformable mesh"); } } // Reset the seek position of the stream so we can read it form the beginning clothFabricStream.Position = 0; var clothFabric = scene.Physics.CreateClothFabric(clothFabricStream); var collisionData = new ClothCollisionData(); var particles = from p in clothGrid.Points select new ClothParticle() { Position = p, InverseWeight = 0.1f }; // Create the cloth mesh from the cooked stream var cloth = scene.Physics.CreateCloth( Matrix.Identity, clothFabric, particles.ToArray(), collisionData, 0); scene.AddActor(cloth); return(cloth); }
private Cloth CreateCloth(Scene scene) { // Create a grid of triangles to be our cloth var clothGrid = new VertexGrid(25, 25); // Setup the grid for cooking var clothMeshDesc = new ClothMeshDesc() { Points = clothGrid.Points, Triangles = clothGrid.Indices }; // Cook var clothFabricStream = new MemoryStream(); using (var cooking = scene.Physics.CreateCooking()) { bool result = cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -1, 0), clothFabricStream); if (!result) throw new Exception("Failed to cook deformable mesh"); } // Reset the seek position of the stream so we can read it form the beginning clothFabricStream.Position = 0; var clothFabric = scene.Physics.CreateClothFabric(clothFabricStream); var collisionData = new ClothCollisionData(); var particles = from p in clothGrid.Points select new ClothParticle() { Position = p, InverseWeight = 0.1f }; // Create the cloth mesh from the cooked stream var cloth = scene.Physics.CreateCloth( Matrix.Identity, clothFabric, particles.ToArray(), collisionData, 0); scene.AddActor(cloth); return cloth; }