# glTF model

> useLoadModel hands the model back at once, still loading, and createModel puts it in the scene: it appears by itself when the file arrives.

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

`useLoadModel` hands the model back **at once**, still loading, and `createModel` puts it in the scene on the same frame. It appears by itself when the file arrives: no loading screen, no callback, nothing to wait on.

Both shapes of the format are read, and you do not have to know which you have. A `.gltf` keeps its numbers and its picture in files beside it; a `.glb` is all of it in one. The file is asked, not its name.

## 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: '#0a0a18'
});

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

`components/duck.ts`:

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

export const Duck = () => {
    const duck = useLoadModel(Settings.MODEL);

    const model = createModel({
        model: duck,
        transform: {
            y: -0.6
        }
    });

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

`scenes/demo.ts`:

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

import { Duck } from '../components/duck';

export const Level = () => {
    useCamera3d(Settings.CAMERA);
    useDirectionalLight({
        intensity: 1
    });

    useSpawn(Duck)();

    return createScene();
};
```

`settings.ts`:

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

export const CAMERA = {
    projection: 'perspective',
    fov: 50,
    transform: {
        y: 1,
        z: 4,
        rotationX: -0.15
    }
} satisfies TCamera3dOptions;
export const MODEL = {
    src: '/example-assets/assets/3d/gltf/Duck/Duck.gltf'
};
export const TURN_SPEED = 0.5;
```
