cull3dplugin
Many copies of a mesh drawn only where the camera sees them, at the detail their distance picks.
Putting it in a scene
List it before whatever hands it crowds or asks it to split a mesh.
"plugins": ["loader", "scenemanager", "player", "cull3d", "shipped", "render3d"],
"world": {
"cull3d": { "cell": 50, "tile": 100 }
}
Properties
Read from world.cull3d.
.cell : number
Metres. The side of the ground squares the copies are sorted into. Each square is tested against the camera's view as a whole first, and only the copies in a square that passes are tested one by one.
.tile : number
Metres. The side of the squares split cuts a mesh into.
Methods
On the page, through plugins.cull3d.
crowd( { matrices, colours?, levels } ) : { copies, drawn, forget }
Hands over many copies of a mesh to draw only where the camera can see them. matrices holds each copy's world matrix and colours each copy's colour. levels lists, nearest first, { meshes, within }: the instanced meshes that draw a copy standing less than within metres from the camera, and no nearer level's. A copy beyond the last level's within is not drawn. Every mesh of a level draws the same copies, each its own part, such as a tree's trunk and its crown.
Add the meshes to the scene yourself, at the world's origin, unturned and unscaled, with any count. From then on cull3d writes their matrices, colours and count. The result has copies, how many were handed over; drawn, how many each level drew last frame; and forget(), which stops cull3d writing those meshes.
A level whose meshes cast shadows also draws copies that are out of view but whose shadows fall in it.
split( geometry ) : BufferGeometry[]
Cuts a geometry into pieces tile metres square by where each triangle's middle stands, so that three.js can skip the pieces that are out of view. The geometry must be plain triangles, with no groups or morph targets. The geometry handed in is released.
Properties of the plugin
drawn : number
The copies drawn the last time the scene was drawn.
crowds : Crowd[]
Every crowd it draws.