Cannon world as class example?

Im trying to become more familiar with classes, and wondering if there is an example somewhere of cannon physics separated out as a simple class, or if someone can show me how I can set it up? Thanks!

It seems to me you would already learn a lot just by trying it. If you understand class basics go ahead and try to wrap a rigid body into a class whose children you tie into the physics world.

The problem in general is that classes are mostly good for data storage, OOP is not an adequate model for orchetrating apps, entities with lifecycles, visuals and behaviour. In your case especially you need to be able to communicate with the physics provider and all that will have to be injection and leaky internals.

Either way, i’d probably extend Object3D so that you can add it to the scene:

class RigidBody extends THREE.Object3D {
  constructor(world, type, collider) {
    this.type = type
    this.collider = collider
    this.onAfterRender = () => {
      // sync this.children to world

const body = new RigidBody(world, "fixed", "cuboid")
body.add(new THREE.Mesh(new THREE.BoxGeometry())

@angular-three/cannon library has class wrappers around cannon-es.

Here’s some examples using that library.