Skip to content

Commit

Permalink
Merge pull request #82 from LeXXik/debug-draw
Browse files Browse the repository at this point in the history
Fix debug draw
  • Loading branch information
LeXXik authored Sep 2, 2024
2 parents c684b80 + 7655df9 commit 7876fe9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
26 changes: 3 additions & 23 deletions src/physics/jolt/back/operators/creator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class Creator {

if ($_DEBUG) {
body.debugDrawDepth = cb.read(BUFFER_READ_BOOL);
this._addDebugDraw(cb.read(BUFFER_READ_BOOL), body);
body.debugDraw = cb.read(BUFFER_READ_BOOL) && !backend.config.useWebWorker;
}

// Destroy shape settings after body is created:
Expand Down Expand Up @@ -584,7 +584,7 @@ class Creator {

if ($_DEBUG) {
body.debugDrawDepth = cb.read(BUFFER_READ_BOOL);
this._addDebugDraw(cb.read(BUFFER_READ_BOOL), body);
body.debugDraw = cb.read(BUFFER_READ_BOOL) && !backend.config.useWebWorker;
}

// Destroy shape settings after body is created:
Expand Down Expand Up @@ -714,7 +714,7 @@ class Creator {

if ($_DEBUG) {
character.debugDrawDepth = cb.read(BUFFER_READ_BOOL);
this._addDebugDraw(cb.read(BUFFER_READ_BOOL), character);
character.debugDraw = cb.read(BUFFER_READ_BOOL) && !config.useWebWorker;
}

if (backend.config.useMotionStates && useMotionState) {
Expand All @@ -736,26 +736,6 @@ class Creator {
return true;
}

// TODO move to tracker
_addDebugDraw(requested, body) {
const backend = this._backend;
const debugBodies = backend.tracker.debug;
const isWorker = backend.config.useWebWorker;

if (requested && isWorker) {
Debug.warn('Debug draw was requested, but it is not supported, when running in ' +
'WebWorker. Disable WebWorker (useWebWorker option) when you need to ' +
'debug draw.');
debugBodies.delete(body);
} else {
if (requested) {
debugBodies.add(body);
} else {
debugBodies.delete(body);
}
}
}

static createSoftBodyShapeSettings(cb, meshBuffers, Jolt) {
// scale
const useScale = cb.read(BUFFER_READ_BOOL);
Expand Down
6 changes: 0 additions & 6 deletions src/physics/jolt/back/operators/modifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,6 @@ class Modifier {
try {
bodyInterface.SetMotionType(body.GetID(), jType, Jolt.EActivation_Activate);
tracker.update(body, index);

// TODO move to tracker
if ($_DEBUG && body.debugDrawData) {
tracker.debug.add(body);
}

} catch (e) {
if ($_DEBUG) {
Debug.error(e);
Expand Down
4 changes: 4 additions & 0 deletions src/physics/jolt/back/operators/tracker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class Tracker {
}
}

if ($_DEBUG && body.debugDraw) {
this._debug.add(body);
}

this._idxMap.set(Jolt.getPointer(body), index);
this._bodyMap.set(index, body);
}
Expand Down

0 comments on commit 7876fe9

Please sign in to comment.