Skip to content

Commit

Permalink
fix fixture proxies reactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
shakiba committed Aug 17, 2023
1 parent 1d77eb8 commit 5dafb74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/dynamics/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class Body {
// Touch the proxies so that new contacts will be created (when appropriate)
const broadPhase = this.m_world.m_broadPhase;
for (let f = this.m_fixtureList; f; f = f.m_next) {
for (let i = 0; i < f.m_proxies.length; ++i) {
for (let i = 0; i < f.m_proxyCount; ++i) {
broadPhase.touchProxy(f.m_proxies[i].proxyId);
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/dynamics/Fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export class Fixture {
/** @internal */ m_shape: Shape;
/** @internal */ m_next: Fixture | null;
/** @internal */ m_proxies: FixtureProxy[];
// 0 indicates inactive state, this is not the same as m_proxies.length
/** @internal */ m_proxyCount: number;
/** @internal */ m_userData: unknown;

constructor(body: Body, def: FixtureDef);
Expand Down Expand Up @@ -162,7 +164,10 @@ export class Fixture {
this.m_next = null;

this.m_proxies = [];
this.m_proxyCount = 0;

// fixture proxies are created here,
// but they are activate in when a fixture is added to body
const childCount = this.m_shape.getChildCount();
for (let i = 0; i < childCount; ++i) {
this.m_proxies[i] = new FixtureProxy(this, i);
Expand Down Expand Up @@ -367,12 +372,12 @@ export class Fixture {
* These support body activation/deactivation.
*/
createProxies(broadPhase: BroadPhase, xf: TransformValue): void {
_ASSERT && console.assert(this.m_proxies.length == 0);
_ASSERT && console.assert(this.m_proxyCount == 0);

// Create proxies in the broad-phase.
const childCount = this.m_shape.getChildCount();
this.m_proxyCount = this.m_shape.getChildCount();

for (let i = 0; i < childCount; ++i) {
for (let i = 0; i < this.m_proxyCount; ++i) {
const proxy = this.m_proxies[i];
this.m_shape.computeAABB(proxy.aabb, xf, i);
proxy.proxyId = broadPhase.createProxy(proxy.aabb, proxy);
Expand All @@ -381,22 +386,21 @@ export class Fixture {

destroyProxies(broadPhase: BroadPhase): void {
// Destroy proxies in the broad-phase.
for (let i = 0; i < this.m_proxies.length; ++i) {
for (let i = 0; i < this.m_proxyCount; ++i) {
const proxy = this.m_proxies[i];
broadPhase.destroyProxy(proxy.proxyId);
proxy.proxyId = null;
proxy.fixture = null;
}

this.m_proxies.length = 0;
this.m_proxyCount = 0;
}

/**
* Updates this fixture proxy in broad-phase (with combined AABB of current and
* next transformation).
*/
synchronize(broadPhase: BroadPhase, xf1: TransformValue, xf2: TransformValue): void {
for (let i = 0; i < this.m_proxies.length; ++i) {
for (let i = 0; i < this.m_proxyCount; ++i) {
const proxy = this.m_proxies[i];
// Compute an AABB that covers the swept shape (may miss some rotation
// effect).
Expand Down Expand Up @@ -477,7 +481,7 @@ export class Fixture {

// Touch each proxy so that new pairs may be created
const broadPhase = world.m_broadPhase;
for (let i = 0; i < this.m_proxies.length; ++i) {
for (let i = 0; i < this.m_proxyCount; ++i) {
broadPhase.touchProxy(this.m_proxies[i].proxyId);
}
}
Expand Down

0 comments on commit 5dafb74

Please sign in to comment.