Skip to content

1. A world ​

Four steps from an empty Vite app to a lit 3D world you can look at. The tutorial assumes you followed Getting started — package installed, the two Vite settings in place.

The shell ​

A game is a function returning an element, so the shell is three lines:

ts
// main.ts
import { createGame } from './game';

document.body.appendChild(createGame());

Give the page a full-viewport body (html, body { height: 100%; margin: 0 }) — the engine sizes its canvas to the window.

An empty world ​

ts
// game.ts
import * as THREE from 'three';
import { FPS } from '@maomi/sge';
import { defaultLights } from '@maomi/sge/lights';
import { Grid } from '@maomi/sge/terrain/grid';

export const createGame = (): HTMLElement => {
  const camera = new THREE.PerspectiveCamera(70, innerWidth / innerHeight, 0.1, 4000);
  const fps = new FPS();

  fps.scene.add(defaultLights());
  fps.add(new Grid(100));

  return fps.start({ camera });   // fixed camera for now — no player yet
};

Run vite and you have a floor under a default sky-less void, lit and shadowed. The start({ camera }) form runs the same world loop without a player — we'll replace it in part 2.

Add a sky ​

ts
import { createSkybox } from '@maomi/sge/skybox';

fps.scene.add(createSkybox('/assets/skybox/night'));

Point it at any directory holding the six faces (left/right/up/down/front/back.webp) — grab this site's night sky from the repo, or generate your own.

The first thing you'll notice on a reload: a brief dark cover while the six faces stream in. That's the loading gate — it armed itself when you constructed the FPS, counted the skybox loads, and revealed a complete scene.