Skip to content

Entities ​

Everything placed in a world is an entity. The hierarchy is small:

GraphicEntity            visual only — a THREE.Group, an id, update(), dispose()
└── PhysicEntity         + a Bullet rigid body
    └── CharacterEntity  + a velocity-based CharacterController
        └── Player       + camera, input controllers, inventory

GraphicEntity ​

The base: owns three (a THREE.Group you position and add children to), a unique id, an optional per-frame update(delta, engine), and an idempotent dispose() that frees geometry and instance buffers. Materials are not disposed — they are often shared singletons, and freeing them would break the next mount.

Use it directly for anything that renders but never collides: cursors, skyboxes, exhibit props, a video screen.

PhysicEntity ​

Adds a rigid body. You supply the collision shape (a Bullet shape) and optionally a geometry for the visual — or omit the geometry and add your own visuals to three.

ts
new PhysicEntity({ mass: 0, shape, geometry })  // mass 0 → static
new PhysicEntity({ shape, geometry })           // mass 1 (default) → dynamic

entity.position = new THREE.Vector3(…) places body and mesh together. The engine stamps the entity's id onto its collision shape, which is how raycasts and collision callbacks map a Bullet hit back to your object.

Ready-made primitives ​

Box, Sphere, Icosahedron, Torus (from @maomi/sge/object) build the shape and the matching geometry from friendly dimensions. The icosahedron and torus collide via a convex hull of their vertices (convexHullShape) — exact for convex geometry, a filled-in solid for anything with holes.

StaticMesh ​

For level geometry from a modeling tool: collision is an arbitrary mesh. Pass one object for both, or a simplified collision proxy plus the full-detail visual:

ts
new StaticMesh(collisionRoot)          // collide with what you see
new StaticMesh(proxyRoot, visualRoot)  // decimated collider + full visual

Instanced geometry is shared, not duplicated: a glTF that places one pillar four times stores its triangles (and BVH) once, referenced by four compound-shape children.

CharacterEntity ​

A dynamic body set up the way Bullet's manual recommends for characters: angular factor 0 (can't tip over), no friction or damping, never sleeps — driven by a CharacterController that sets its velocity each frame. Subclass it for NPCs; Player is exactly that plus input and a camera.

Cleanup ​

A no-visual entity that runs a callback when the world is disposed — for tearing down anything you wired up outside the entity system (a timer, a WebSocket, a DOM node):

ts
fps.add(new Cleanup(() => clearInterval(timer)));