static void UpdateShapes(ref RigidbodyInternal rb) { if (rb.ownsCollisionShape && rb.CollisionShape != null) { rb.CollisionShape.Dispose(); } CollisionShape resultShape; var collisionShapes = rb.CollisionShapes; if (collisionShapes.Count == 0) { //EmptyShape resultShape = new EmptyShape(); } else { //CompoundShape var compoundShape = new CompoundShape(); for (int i = 0; i < collisionShapes.Count; i++) { compoundShape.AddChildShape(Matrix4x4.Identity, collisionShapes[i]); } resultShape = compoundShape; } rb.ownsCollisionShape = true; rb.BulletRigidbody.CollisionShape = resultShape; rb.updateShapes = false; rb.updateMass = true; }
protected internal override void FixedUpdate() { if (!World.Has <WorldPhysics>()) { return; } var physics = World.Get <WorldPhysics>(); foreach (var message in ReadMessages <RemoveCollisionShapeMessage>()) { if (!message.Entity.Has <RigidbodyInternal>()) { continue; } message.Entity.Get <RigidbodyInternal>().CollisionShapes.Remove(message.CollisionShape); } foreach (var message in ReadMessages <AddCollisionShapeMessage>()) { if (!message.Entity.Has <RigidbodyInternal>()) { message.Entity.Set(RigidbodyInternal.Create()); } message.Entity.Get <RigidbodyInternal>().CollisionShapes.Add(message.CollisionShape); } foreach (var entity in entities.ReadEntities()) { ref var rb = ref entity.Get <RigidbodyInternal>(); rb.MotionState ??= new RigidbodyMotionState(entity); rb.CollisionShape ??= new EmptyShape();