THREE.Group objects that you add like any other.
Connect the camera
Tell the kernel which camera draws each frame, and when it moves. Level of detail then follows the camera:observeCamera(renderer, camera)uses the first camera seen per renderer frame.setCameraMotion(true)lets the kernel use coarser meshes while the camera moves. Call it from your controls’ change event.
Draw bodies through your own layers
Large scenes often draw many bodies through oneInstancedMesh or BatchedMesh. The kernel must still know which bodies are on screen, because it makes meshes only for displayed bodies.
- Hand the drawing to your layer:
OpenGeometry.setHostDrawn(bodies, true). Each body’svisiblebecomesfalse, so Three.js skips it and everything under it. The kernel keeps the body’s own visibility apart. - Make a group of those bodies:
const group = OpenGeometry.hostGroup(bodies). - In the layer’s
onBeforeRender, callgroup.drawn(). It counts every member as displayed for this render pass, at a cost that does not grow with the number of members. - After each body’s
geometrychangedevent, build your layer frombody.surface.geometryandbody.surface.matrixWorld. - When a body leaves the layer, call
OpenGeometry.setHostDrawn([body], false). Itsvisiblegoes back to its own visibility.
group.set(bodies)replaces the members.group.dispose()ends the group.- For a few bodies,
OpenGeometry.markDisplayed(bodies)does the same asgroup.drawn()without a group. - Do not set
visibleon a host-drawn body. A dispose, a rollback or a reset changes its own visibility instead. markDisplayedskips a body withvisible = falsethat is not host-drawn.
Placement events
Each body dispatchesplacementchanged when a flush moves it. A layer that copies world matrices listens to it.
Moving a surface mesh yourself
A body’ssurface and outline meshes are static: their matrixAutoUpdate is false. If your code writes their position, rotation, quaternion or scale, call updateMatrix() on that mesh after the write. To move a body, use transform.
Free memory
OpenGeometry.releaseIdleGeometry() frees cached display meshes of bodies that do not show them. Call it after a large part of the model leaves the view.
