public static IShape OffsetSingleShape(IConvexShape shape, Vector3?offset = null, Quaternion?rotation = null, bool kinematic = false) { if (offset.HasValue == false && rotation.HasValue == false) { return(shape); } if (shape is ICompoundShape) { throw new InvalidOperationException("Cannot offset a compound shape. Can't support nested compounds."); } using (var compoundBuilder = new CompoundBuilder(BepuSimulation.safeBufferPool, BepuSimulation.instance.internalSimulation.Shapes, 1)) { using (BepuSimulation.instance.simulationLocker.WriteLock()) { if (kinematic) { compoundBuilder.AddForKinematicEasy(shape, new BepuPhysics.RigidPose(ToBepu(offset ?? Vector3.Zero), ToBepu(rotation ?? Quaternion.Identity)), 1f); } else { compoundBuilder.AddEasy(shape, new BepuPhysics.RigidPose(ToBepu(offset ?? Vector3.Zero), ToBepu(rotation ?? Quaternion.Identity)), 1f); } return(compoundBuilder.BuildCompleteCompoundShape(BepuSimulation.instance.internalSimulation.Shapes, BepuSimulation.safeBufferPool, kinematic)); } } }
/// <summary> /// Easily makes a Compound shape for you, given a list of individual shapes and how they should be offset. /// </summary> /// <param name="shapes">List of convex shapes</param> /// <param name="offsets">Matching length list of offsets of bodies, can be null if nothing has an offset</param> /// <param name="rotations">Matching length list of rotations of bodies, can be null if nothing is rotated</param> /// <param name="isDynamic">True if intended to use in a dynamic situation, false if kinematic or static</param> /// <returns></returns> public static ICompoundShape MakeCompound(List <IConvexShape> shapes, List <Vector3> offsets = null, List <Quaternion> rotations = null, bool isDynamic = true, int bigThreshold = 5) { using (var compoundBuilder = new CompoundBuilder(BepuSimulation.safeBufferPool, BepuSimulation.instance.internalSimulation.Shapes, shapes.Count)) { bool allConvex = true; //All allocations from the buffer pool used for the final compound shape will be disposed when the demo is disposed. Don't have to worry about leaks in these demos. for (int i = 0; i < shapes.Count; i++) { if (shapes[i] is ICompoundShape) { throw new InvalidOperationException("Cannot include compounds in another compound shape."); } if (isDynamic) { compoundBuilder.AddEasy(shapes[i] as IConvexShape, new BepuPhysics.RigidPose(ToBepu(offsets?[i] ?? Vector3.Zero), ToBepu(rotations?[i] ?? Quaternion.Identity)), 1f); } else { if (shapes[i] is IConvexShape == false) { allConvex = false; } compoundBuilder.AddForKinematicEasy(shapes[i], new BepuPhysics.RigidPose(ToBepu(offsets?[i] ?? Vector3.Zero), ToBepu(rotations?[i] ?? Quaternion.Identity)), 1f); } } return(compoundBuilder.BuildCompleteCompoundShape(BepuSimulation.instance.internalSimulation.Shapes, BepuSimulation.safeBufferPool, isDynamic, allConvex ? bigThreshold : int.MaxValue)); } }