Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to toggle debugger on or off #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion dist/cannon-es-debugger.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function CannonDebugger(scene, world, _temp) {
onInit,
onUpdate
} = _temp === void 0 ? {} : _temp;
let _enabled = true;
const _meshes = [];

const _material = new three.MeshBasicMaterial({
Expand Down Expand Up @@ -258,6 +259,7 @@ function CannonDebugger(scene, world, _temp) {
}

function update() {
if (!_enabled) return;
const meshes = _meshes;
const shapeWorldPosition = _tempVec0;
const shapeWorldQuaternion = _tempQuat0;
Expand Down Expand Up @@ -294,8 +296,45 @@ function CannonDebugger(scene, world, _temp) {
meshes.length = meshIndex;
}

function toggle(value) {
const enabled = value !== null && value !== undefined ? !!value : !_enabled;

if (enabled) {
enable();
} else {
disable();
}
}

function enable() {
_enabled = true;
const meshes = _meshes;

for (let i = 0; i < meshes.length; i++) {
const mesh = meshes[i];

if (mesh) {
scene.add(mesh);
}
}
}

function disable() {
_enabled = false;
const meshes = _meshes;

for (let i = 0; i < meshes.length; i++) {
const mesh = meshes[i];

if (mesh) {
scene.remove(mesh);
}
}
}

return {
update
update,
toggle
};
}

Expand Down
1 change: 1 addition & 0 deletions dist/cannon-es-debugger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ declare module "cannon-es-debugger" {
};
export default function CannonDebugger(scene: Scene, world: World, { color, scale, onInit, onUpdate }?: DebugOptions): {
update: () => void;
toggle: (value?: boolean | undefined) => void;
};
}
41 changes: 40 additions & 1 deletion dist/cannon-es-debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function CannonDebugger(scene, world, _temp) {
onInit,
onUpdate
} = _temp === void 0 ? {} : _temp;
let _enabled = true;
const _meshes = [];

const _material = new MeshBasicMaterial({
Expand Down Expand Up @@ -256,6 +257,7 @@ function CannonDebugger(scene, world, _temp) {
}

function update() {
if (!_enabled) return;
const meshes = _meshes;
const shapeWorldPosition = _tempVec0;
const shapeWorldQuaternion = _tempQuat0;
Expand Down Expand Up @@ -292,8 +294,45 @@ function CannonDebugger(scene, world, _temp) {
meshes.length = meshIndex;
}

function toggle(value) {
const enabled = value !== null && value !== undefined ? !!value : !_enabled;

if (enabled) {
enable();
} else {
disable();
}
}

function enable() {
_enabled = true;
const meshes = _meshes;

for (let i = 0; i < meshes.length; i++) {
const mesh = meshes[i];

if (mesh) {
scene.add(mesh);
}
}
}

function disable() {
_enabled = false;
const meshes = _meshes;

for (let i = 0; i < meshes.length; i++) {
const mesh = meshes[i];

if (mesh) {
scene.remove(mesh);
}
}
}

return {
update
update,
toggle
};
}

Expand Down
Loading