private Cloth CreateCloth(Scene scene, RigidActor poleActor) { // Create a grid of triangles to be our cloth var clothGrid = VertexGrid.CreateGrid(40, 40, 0.4f); // Setup the grid for cooking var clothMeshDesc = new ClothMeshDesc() { Points = clothGrid.Points, Triangles = ArrayUtil.ToByteArray(clothGrid.Indices) }; // Cook var clothFabricStream = new MemoryStream(); using (var cooking = scene.Physics.CreateCooking()) { cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -1, 0), clothFabricStream); } // 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 poleBoxGeom = poleActor.GetShape(0).GetBoxGeometry(); var boxPosition = new Vector3(poleActor.GlobalPose.M41, poleActor.GlobalPose.M42, poleActor.GlobalPose.M43); var particles = from p in clothGrid.Points select new ClothParticle() { Position = p, // Setting the inverse weight of a particle to 0 will pin it in place, any other value will be its weight InverseWeight = IsPointInBox(poleBoxGeom, boxPosition, p) ? 0 : 1 }; // Create the cloth mesh from the cooked stream var cloth = scene.Physics.CreateCloth ( Matrix4x4.CreateTranslation(0, 30, 0), clothFabric, particles.ToArray(), 0 ); // Enable collision with other scene geometry //cloth.Flags |= ClothFlag.SceneCollision; // GPU cloth if desired // The Engine class needs to create a CudaContextManager for this to work. Define 'GPU' on // the Engine project to enable it. cloth.Flags |= ClothFlag.GPU; scene.AddActor(cloth); return(cloth); }
private Cloth CreateCloth(Scene scene, RigidActor poleActor) { // Create a grid of triangles to be our cloth var clothGrid = VertexGrid.CreateGrid(40, 40, 0.4f); // Setup the grid for cooking var clothMeshDesc = new ClothMeshDesc() { Points = clothGrid.Points, Triangles = ArrayUtil.ToByteArray(clothGrid.Indices) }; // Cook var clothFabricStream = new MemoryStream(); using (var cooking = scene.Physics.CreateCooking()) { cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -1, 0), clothFabricStream); } // 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 poleBoxGeom = poleActor.GetShape(0).GetBoxGeometry(); var boxPosition = new Vector3(poleActor.GlobalPose.M41, poleActor.GlobalPose.M42, poleActor.GlobalPose.M43); var particles = from p in clothGrid.Points select new ClothParticle() { Position = p, // Setting the inverse weight of a particle to 0 will pin it in place, any other value will be its weight InverseWeight = IsPointInBox(poleBoxGeom, boxPosition, p) ? 0 : 1 }; // Create the cloth mesh from the cooked stream var cloth = scene.Physics.CreateCloth ( Matrix4x4.CreateTranslation(0, 30, 0), clothFabric, particles.ToArray(), 0 ); // Enable collision with other scene geometry //cloth.Flags |= ClothFlag.SceneCollision; // GPU cloth if desired // The Engine class needs to create a CudaContextManager for this to work. Define 'GPU' on // the Engine project to enable it. cloth.Flags |= ClothFlag.GPU; scene.AddActor(cloth); return cloth; }
private void AddCollider(RigidActor actor, ICollider collider) { if (collider is AggregateCollider agg) { foreach (var c in agg.ColliderComponents) { AddCollider(actor, c); } } else if (collider is TriangleMeshCollider triCollider) { var desc = triCollider.GetDescriptor(GetMaterialIndices); // Avoiding offline cook path for now because // 1. Comments in Physx.Net imply memory leak using streams // 2. I don't want to deal with disk caching cooks yet var finalMesh = this.physxPhysics.CreateTriangleMesh(cooker, desc); var meshGeom = new TriangleMeshGeometry(finalMesh); RigidActorExt.CreateExclusiveShape(actor, meshGeom, globalMaterials, null); } else if (collider is TriangleModelCollider triModelCollider) { foreach (var mesh in triModelCollider.MeshColliders) { var desc = mesh.GetDescriptor(GetMaterialIndices); // Avoiding offline cook path for now because // 1. Comments in Physx.Net imply memory leak using streams // 2. I don't want to deal with disk caching cooks yet var finalMesh = this.physxPhysics.CreateTriangleMesh(cooker, desc); var meshGeom = new TriangleMeshGeometry(finalMesh); RigidActorExt.CreateExclusiveShape(actor, meshGeom, globalMaterials, null); } } else if (collider is IVertexBasedCollider vertCollider) { var desc = new ConvexMeshDesc() { Flags = ConvexFlag.ComputeConvex }; desc.SetPositions(vertCollider.GetTransformedVertices()); var mesh = this.physxPhysics.CreateConvexMesh(this.cooker, desc); var geom = new ConvexMeshGeometry(mesh); var mat = this.GetOrCreateMaterial(vertCollider.PhysicsMaterial); // TODO: re-use shared shapes instead of creating exclusive RigidActorExt.CreateExclusiveShape(actor, geom, mat); } else if (collider is ConvexModelCollider modelCollider) { foreach (var verts in modelCollider.Meshes) { var desc = new ConvexMeshDesc() { Flags = ConvexFlag.ComputeConvex }; desc.SetPositions(verts); var mesh = this.physxPhysics.CreateConvexMesh(this.cooker, desc); var geom = new ConvexMeshGeometry(mesh); var mat = this.GetOrCreateMaterial(modelCollider.PhysicsMaterial); // TODO: re-use shared shapes instead of creating exclusive RigidActorExt.CreateExclusiveShape(actor, geom, mat); } } }
/// <summary> /// A convenience/backwards-compatability method. /// </summary> public static Shape CreateShape(this RigidActor actor, PhysX.Geometry geometry, Material material) { return(RigidActorExt.CreateExclusiveShape(actor, geometry, material)); }
public void GetObjectHandlesNull() { RigidActor actor = ObjectTable.Instance.GetObject <RigidActor>(0); Assert.IsNull(actor); }