12 KiB
Planck.js API Doc › Globals › Fixture
Class: Fixture
A fixture is used to attach a shape to a body for collision detection. A fixture inherits its transform from its parent. Fixtures hold additional non-geometric data such as friction, collision filters, etc.
To create a new Fixture use Body.createFixture.
Hierarchy
- Fixture
Index
Methods
- createProxies
- destroyProxies
- getAABB
- getBody
- getDensity
- getFilterCategoryBits
- getFilterGroupIndex
- getFilterMaskBits
- getFriction
- getMassData
- getNext
- getRestitution
- getShape
- getType
- getUserData
- isSensor
- rayCast
- refilter
- setDensity
- setFilterCategoryBits
- setFilterData
- setFilterGroupIndex
- setFilterMaskBits
- setFriction
- setRestitution
- setSensor
- setUserData
- shouldCollide
- synchronize
- testPoint
Methods
createProxies
▸ createProxies(broadPhase: BroadPhase, xf: Transform): void
Defined in src/dynamics/Fixture.ts:369
These support body activation/deactivation.
Parameters:
| Name | Type |
|---|---|
broadPhase |
BroadPhase |
xf |
Transform |
Returns: void
destroyProxies
▸ destroyProxies(broadPhase: BroadPhase): void
Defined in src/dynamics/Fixture.ts:382
Parameters:
| Name | Type |
|---|---|
broadPhase |
BroadPhase |
Returns: void
getAABB
▸ getAABB(childIndex: number): AABB
Defined in src/dynamics/Fixture.ts:361
Get the fixture's AABB. This AABB may be enlarge and/or stale. If you need a more accurate AABB, compute it using the shape and the body transform.
Parameters:
| Name | Type |
|---|---|
childIndex |
number |
Returns: AABB
getBody
▸ getBody(): Body
Defined in src/dynamics/Fixture.ts:277
Get the parent body of this fixture. This is null if the fixture is not attached.
Returns: Body
getDensity
▸ getDensity(): number
Defined in src/dynamics/Fixture.ts:291
Get the density of this fixture.
Returns: number
getFilterCategoryBits
▸ getFilterCategoryBits(): number
Defined in src/dynamics/Fixture.ts:435
Returns: number
getFilterGroupIndex
▸ getFilterGroupIndex(): number
Defined in src/dynamics/Fixture.ts:427
Returns: number
getFilterMaskBits
▸ getFilterMaskBits(): number
Defined in src/dynamics/Fixture.ts:443
Returns: number
getFriction
▸ getFriction(): number
Defined in src/dynamics/Fixture.ts:307
Get the coefficient of friction, usually in the range [0,1].
Returns: number
getMassData
▸ getMassData(massData: MassData): void
Defined in src/dynamics/Fixture.ts:353
Get the mass data for this fixture. The mass data is based on the density and the shape. The rotational inertia is about the shape's origin. This operation may be expensive.
Parameters:
| Name | Type |
|---|---|
massData |
MassData |
Returns: void
getNext
▸ getNext(): Fixture | null
Defined in src/dynamics/Fixture.ts:284
Get the next fixture in the parent body's fixture list.
Returns: Fixture | null
getRestitution
▸ getRestitution(): number
Defined in src/dynamics/Fixture.ts:322
Get the coefficient of restitution.
Returns: number
getShape
▸ getShape(): Shape
Defined in src/dynamics/Fixture.ts:229
Get the child shape. You can modify the child shape, however you should not change the number of vertices because this will crash some collision caching mechanisms. Manipulating the shape may lead to non-physical behavior.
Returns: Shape
getType
▸ getType(): ShapeType
Defined in src/dynamics/Fixture.ts:220
Get the type of the child shape. You can use this to down cast to the concrete shape.
Returns: ShapeType
getUserData
▸ getUserData(): unknown
Defined in src/dynamics/Fixture.ts:262
Get the user data that was assigned in the fixture definition. Use this to store your application specific data.
Returns: unknown
isSensor
▸ isSensor(): boolean
Defined in src/dynamics/Fixture.ts:237
A sensor shape collects contact information but never generates a collision response.
Returns: boolean
rayCast
▸ rayCast(output: RayCastOutput, input: RayCastInput, childIndex: number): boolean
Defined in src/dynamics/Fixture.ts:344
Cast a ray against this shape.
Parameters:
| Name | Type |
|---|---|
output |
RayCastOutput |
input |
RayCastInput |
childIndex |
number |
Returns: boolean
refilter
▸ refilter(): void
Defined in src/dynamics/Fixture.ts:455
Call this if you want to establish collision that was previously disabled by ContactFilter.
Returns: void
setDensity
▸ setDensity(density: number): void
Defined in src/dynamics/Fixture.ts:299
Set the density of this fixture. This will not automatically adjust the mass of the body. You must call Body.resetMassData to update the body's mass.
Parameters:
| Name | Type |
|---|---|
density |
number |
Returns: void
setFilterCategoryBits
▸ setFilterCategoryBits(categoryBits: number): void
Defined in src/dynamics/Fixture.ts:439
Parameters:
| Name | Type |
|---|---|
categoryBits |
number |
Returns: void
setFilterData
▸ setFilterData(filter: object): void
Defined in src/dynamics/Fixture.ts:420
Set the contact filtering data. This will not update contacts until the next time step when either parent body is active and awake. This automatically calls refilter.
Parameters:
▪ filter: object
| Name | Type |
|---|---|
categoryBits |
number |
groupIndex |
number |
maskBits |
number |
Returns: void
setFilterGroupIndex
▸ setFilterGroupIndex(groupIndex: number): void
Defined in src/dynamics/Fixture.ts:431
Parameters:
| Name | Type |
|---|---|
groupIndex |
number |
Returns: void
setFilterMaskBits
▸ setFilterMaskBits(maskBits: number): void
Defined in src/dynamics/Fixture.ts:447
Parameters:
| Name | Type |
|---|---|
maskBits |
number |
Returns: void
setFriction
▸ setFriction(friction: number): void
Defined in src/dynamics/Fixture.ts:315
Set the coefficient of friction. This will not change the friction of existing contacts.
Parameters:
| Name | Type |
|---|---|
friction |
number |
Returns: void
setRestitution
▸ setRestitution(restitution: number): void
Defined in src/dynamics/Fixture.ts:330
Set the coefficient of restitution. This will not change the restitution of existing contacts.
Parameters:
| Name | Type |
|---|---|
restitution |
number |
Returns: void
setSensor
▸ setSensor(sensor: boolean): void
Defined in src/dynamics/Fixture.ts:244
Set if this fixture is a sensor.
Parameters:
| Name | Type |
|---|---|
sensor |
boolean |
Returns: void
setUserData
▸ setUserData(data: unknown): void
Defined in src/dynamics/Fixture.ts:269
Set the user data. Use this to store your application specific data.
Parameters:
| Name | Type |
|---|---|
data |
unknown |
Returns: void
shouldCollide
▸ shouldCollide(that: Fixture): boolean
Defined in src/dynamics/Fixture.ts:496
Implement this method to provide collision filtering, if you want finer control over contact creation.
Return true if contact calculations should be performed between these two fixtures.
Warning: for performance reasons this is only called when the AABBs begin to overlap.
Parameters:
| Name | Type |
|---|---|
that |
Fixture |
Returns: boolean
synchronize
▸ synchronize(broadPhase: BroadPhase, xf1: Transform, xf2: Transform): void
Defined in src/dynamics/Fixture.ts:397
Updates this fixture proxy in broad-phase (with combined AABB of current and next transformation).
Parameters:
| Name | Type |
|---|---|
broadPhase |
BroadPhase |
xf1 |
Transform |
xf2 |
Transform |
Returns: void
testPoint
▸ testPoint(p: Vec2): boolean
Defined in src/dynamics/Fixture.ts:337
Test a point in world coordinates for containment in this fixture.
Parameters:
| Name | Type |
|---|---|
p |
Vec2 |
Returns: boolean