# 3D floor

> usePlaneGeometry as a ground plane under a cube, with the camera raised and pitched down so the plane is visible.

Example `floor-3d`, running at https://nacatamalon.com/en/examples/floor-3d. The whole catalogue: https://nacatamalon.com/llms/examples.md.

`usePlaneGeometry` used as a ground plane: a flat 10×10 quad facing `+Y`, with a cube resting on top.

The camera is raised and pitched down (`y` and `rotationX`) so the floor is not viewed edge-on. That edge-on view, not the geometry, is what made the plane look broken in front of a camera looking straight ahead.

## Code

`index.ts`:

```ts
import { createGame } from 'nacatamalon';
import { WIDTH, HEIGHT } from './settings';
import { Scene } from './scenes/demo';

const game = createGame('#app', {
    width: WIDTH,
    height: HEIGHT,
    background: '#0a0a18',
});

// Declare Scenes
game({
    Scene
});
```

`components/floordisplay.ts`:

```ts
import { createMesh, useCubeGeometry, usePlaneGeometry, useUpdate } from 'nacatamalon';
import * as Settings from '../settings';

export const FloorDisplay = () => {
    const floor = usePlaneGeometry(Settings.FLOOR);

    createMesh({
        geometry: floor,
        transform: {
            y: 0
        },
        tint: '#3a3a4a'
    });

    const cube = useCubeGeometry();

    const cubeMesh = createMesh({
        geometry: cube,
        transform: {
            y: 0.5
        },
        tint: '#4cff91'
    });

    useUpdate((dt) => {
        cubeMesh.transform.rotationY += dt * Settings.TURN_SPEED;
    });
};
```

`scenes/demo.ts`:

```ts
import { createScene, useCamera3d, useSpawn } from 'nacatamalon';
import * as Settings from '../settings';

import { FloorDisplay } from '../components/floordisplay';

export const Scene = () => {
    useCamera3d(Settings.CAMERA);

    useSpawn(FloorDisplay)();

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 480;
export const HEIGHT = 320;
import type { TCamera3dOptions } from 'nacatamalon';

export const CAMERA = {
    projection: 'perspective',
    fov: 55,
    near: 0.1,
    far: 100,
    transform: {
        y: 2.2,
        z: 5,
        rotationX: -0.42
    },
} satisfies TCamera3dOptions;
export const FLOOR = {
    width: 10,
    depth: 10
};
export const TURN_SPEED = 0.6;
```
