Skip to content

Commit

Permalink
Merge pull request #74 from Cloud9c/master
Browse files Browse the repository at this point in the history
Add removeShape method to Body
  • Loading branch information
marcofugaro authored Feb 3, 2021
2 parents 81ec98b + 52db2e9 commit 8ff3e32
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/objects/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,34 @@ export class Body extends EventTarget {
return this
}

/**
* Remove a shape from the body.
* @method removeShape
* @param {Shape} shape
* @return {Body} The body object, for chainability.
*/
removeShape(shape: Shape): Body {

const index = this.shapes.indexOf(shape)

if (index === -1) {
console.warn('Shape does not belong to the body');
return this;
}

this.shapes.splice(index, 1)
this.shapeOffsets.splice(index, 1)
this.shapeOrientations.splice(index, 1)
this.updateMassProperties()
this.updateBoundingRadius()

this.aabbNeedsUpdate = true

shape.body = null

return this
}

/**
* Update the bounding radius of the body. Should be done if any of the shapes are changed.
* @method updateBoundingRadius
Expand Down

0 comments on commit 8ff3e32

Please sign in to comment.