Skip to content

Realtime JavaScript voxel renderer and physics simulator.

Notifications You must be signed in to change notification settings

nowaythisworks/Voxel-Engine

Repository files navigation

Voxel-Engine

This is my JavaScript voxel game/physics engine.

It can render a few million voxels at a solid framerate (on my ancient PC), and compute physics and realtime destruction.
My goal is to have it be as large-scale as Teardown, but much more efficient in both rendering and physics calculations.

Features

Automatic Chunk Calculator

The chunk calculator can take a voxel map (in this case, of around 700,000 voxels) and split it into even chunks to optimize raycasting and physics sim.

image

Realtime Physics

The physics sim creates a box mesh for each destroyed piece of the voxel map. (Very WIP)

Debug Mode Screenshot

Currently, custom models can be imported using the Voxelizer, exporting as JSON. The loader does not support transparency (yet) but it shouldn't be very difficult to implement.

The engine will divide the model into chunks (of gpu-instanced cubes) and will save the same chunks in memory for physics calculations. The rendering uses Three.js (WebGL), with a separate raycasting system.

TODO:

The physics implemented are cannones-based and are quite poor. Using something that can support convex hulls would be much preferred, but I can't find a JavaScript-compaible engine that has support for that in 3D yet, so maybe I'll build my own. For now, a square mesh is created (see the colorful lines in the screenshot above) that acts as a box collider.

Alternatively, particle physics could work (rounded to one world unit), with interpolation to make it look smooth.