-
Notifications
You must be signed in to change notification settings - Fork 18
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
🔫 Remove autoUpdate option #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import { | |
BufferGeometry, | ||
Float32BufferAttribute, | ||
} from 'three' | ||
import type { Body } from 'cannon-es' | ||
import type { Body, World } from 'cannon-es' | ||
import type { Scene, Color } from 'three' | ||
|
||
type ComplexShape = Shape & { geometryId?: number } | ||
|
@@ -30,13 +30,12 @@ export type DebugOptions = { | |
scale?: number | ||
onInit?: (body: Body, mesh: Mesh, shape: Shape) => void | ||
onUpdate?: (body: Body, mesh: Mesh, shape: Shape) => void | ||
autoUpdate?: Boolean | ||
} | ||
|
||
export default function cannonDebugger( | ||
scene: Scene, | ||
bodies: Body[], | ||
{ color = 0x00ff00, scale = 1, onInit, onUpdate, autoUpdate }: DebugOptions = {} | ||
world: World, | ||
{ color = 0x00ff00, scale = 1, onInit, onUpdate }: DebugOptions = {} | ||
) { | ||
const _meshes: Mesh[] = [] | ||
const _material = new MeshBasicMaterial({ color: color ?? 0x00ff00, wireframe: true }) | ||
|
@@ -179,7 +178,7 @@ export default function cannonDebugger( | |
break | ||
} | ||
case BOX: { | ||
mesh.scale.copy(((shape as Box).halfExtents as unknown) as ThreeVector3) | ||
mesh.scale.copy((shape as Box).halfExtents as unknown as ThreeVector3) | ||
mesh.scale.multiplyScalar(2 * scale) | ||
break | ||
} | ||
|
@@ -195,7 +194,7 @@ export default function cannonDebugger( | |
break | ||
} | ||
case TRIMESH: { | ||
mesh.scale.copy(((shape as Trimesh).scale as unknown) as ThreeVector3).multiplyScalar(scale) | ||
mesh.scale.copy((shape as Trimesh).scale as unknown as ThreeVector3).multiplyScalar(scale) | ||
break | ||
} | ||
case HEIGHTFIELD: { | ||
|
@@ -240,7 +239,7 @@ export default function cannonDebugger( | |
|
||
let meshIndex = 0 | ||
|
||
for (const body of bodies) { | ||
for (const body of world.bodies) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering that you only use the world to access the bodies, it seems a bit overkill to bring the entire world into the debugger. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I preferred matching the signature to the original CannonDebugRenderer. We can just mock the world (like we're doing now) in use-cannon. |
||
for (let i = 0; i !== body.shapes.length; i++) { | ||
const shape = body.shapes[i] | ||
const didCreateNewMesh = updateMesh(meshIndex, shape) | ||
|
@@ -255,8 +254,8 @@ export default function cannonDebugger( | |
body.quaternion.mult(body.shapeOrientations[i], shapeWorldQuaternion) | ||
|
||
// Copy to meshes | ||
mesh.position.copy((shapeWorldPosition as unknown) as ThreeVector3) | ||
mesh.quaternion.copy((shapeWorldQuaternion as unknown) as ThreeQuaternion) | ||
mesh.position.copy(shapeWorldPosition as unknown as ThreeVector3) | ||
mesh.quaternion.copy(shapeWorldQuaternion as unknown as ThreeQuaternion) | ||
|
||
if (didCreateNewMesh && onInit instanceof Function) onInit(body, mesh, shape) | ||
if (!didCreateNewMesh && onUpdate instanceof Function) onUpdate(body, mesh, shape) | ||
|
@@ -272,9 +271,7 @@ export default function cannonDebugger( | |
} | ||
|
||
meshes.length = meshIndex | ||
if (autoUpdate !== false) requestAnimationFrame(update) | ||
} | ||
|
||
if (autoUpdate !== false) requestAnimationFrame(update) | ||
return { update } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not match what is in the README:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're using this pattern because we don't want to expose the private variables, we can switch to a class when we can ship private class fields