Skip to content

Voxel world ​

A 96×96 simplex-noise island under a generated night sky. The terrain renders as greedy-merged instanced boxes; its physics streams — static bodies materialize around the player as they walk and evaporate behind them.

The whole game ​

ts
import * as THREE from 'three';

import { FPS } from '@maomi/sge';
import { Player } from '@maomi/sge/player';
import { VoxelTerrain } from '@maomi/sge/terrain/voxels';
import { createSkybox } from '@maomi/sge/skybox';
import { defaultLights } from '@maomi/sge/lights';

/* A procedurally generated voxel island under a night sky: simplex-noise heights, greedy
   block merging, and physics streamed in around the player as they walk. */
export const createGame = (): HTMLElement => {
  const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 4000);
  const fps = new FPS();

  fps.scene.add(createSkybox('/assets/skybox/night'));
  fps.scene.add(defaultLights({ shadowExtent: 60 }));

  const size = 96;
  const materials = {
    types: {
      grass: new THREE.MeshLambertMaterial({ color: 0x4c9f45 }),
      rock: new THREE.MeshLambertMaterial({ color: 0x8a8577 }),
    },
    getTypeAt(_x: number, y: number): string {
      return y > 6 ? 'rock' : 'grass';
    },
  };
  const terrain = new VoxelTerrain(size, materials, { seed: 31, scale: 60, magnitude: 9, offset: 1 });
  terrain.generate();
  fps.add(terrain);

  const player = new Player({ camera });
  player.position = new THREE.Vector3(size / 2, 16, size / 2);
  fps.add(player);

  return fps.start(player);
};

Things to notice:

  • The MaterialMap picks grass or rock per block from its height — content logic stays in your hands, the engine only asks.
  • createSkybox('/assets/skybox/night') points at a directory following the six-face convention; the faces here were generated for this site.
  • Try walking to an edge: the island simply ends — heights come from the noise params, and a different seed is a different island.