# Bones

> A rigged model is a skin over bones: a fox that surveys, walks and runs, easing between movements at the joints.

Example `gltf-skinned`, running at https://nacatamalon.com/en/examples/gltf-skinned. The whole catalogue: https://nacatamalon.com/llms/examples.md.

A rigged model is a skin stretched over bones. A movement turns the bones and the skin follows, which is why one fox can survey, walk and run without three copies of it existing. **Press 1, 2 or 3.**

It does not cut between them. `fade` says how long to take turning the bones from where one movement has them to where the next does, and the mixing happens **at the joints**, not between the two shapes: that is what makes a change of gait look like an animal rather than a dissolve.

## Code

`index.ts`:

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

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

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

`components/fox.ts`:

```ts
import { createModel, useKeyboard, useLoadModel, useSkeletalAnimation, useUpdate } from 'nacatamalon';
import * as Settings from '../settings';

export const Fox = () => {
    const fox = useLoadModel(Settings.MODEL);

    const model = createModel({
        model: fox
    });

    const moves = useSkeletalAnimation(model, {
        play: 'Walk',
        fade: Settings.FADE
    });

    const keys = useKeyboard();

    useUpdate((delta) => {
        // Turning the whole model so the gait reads: the bones are moving it from the inside, the
        // placement is moving all of it at once, and the two do not know about each other.
        model.transform.rotationY += delta * Settings.TURN_SPEED;

        if (keys.justPressed('1')) {
            moves.play('Survey');
        }

        if (keys.justPressed('2')) {
            moves.play('Walk');
        }

        if (keys.justPressed('3')) {
            moves.play('Run');
        }
    });
};
```

`scenes/demo.ts`:

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

import { Fox } from '../components/fox';

export const Level = () => {
    useCamera3d(Settings.CAMERA);
    useDirectionalLight({
        color: '#fff2e0',
        intensity: 1.1,
        ambient: 0.35,
        transform: {
            rotationX: -0.5,
            rotationY: 0.5
        }
    });

    useSpawn(Fox)();

    return createScene();
};
```

`settings.ts`:

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

export const CAMERA = {
    projection: 'perspective',
    fov: 45,
    transform: {
        y: 55,
        z: 170,
        rotationX: -0.12
    }
} satisfies TCamera3dOptions;
export const MODEL = {
    src: '/example-assets/assets/3d/gltf/Fox/Fox.gltf'
};
export const TURN_SPEED = 0.6;
export const FADE = 0.35;
```
