# gizlang/models

the meshes of model files of other formats than glTF, in glTF's frame (Y up, meters, right-handed), so that gizlang/gltf reads them and a game draws them the same way as a glTF file. A binary FBX file (version 7.x, as Autodesk tools and game engines export it) is placed by its models' transforms; ASCII FBX, skins and animation are not read. A Wavefront OBJ file (as survey scans and modeling tools write it) is taken as meters with Y up, and its MTL library names its maps. Its files are named without case, as on Windows where they are made: it asks for each in lower case.

```gizlang
import * as Models from "gizlang/models";
```

## Types

### `Mesh`

```gizlang
type Mesh = { name: string; positions: Vec<f32>; normals: Vec<f32>; uvs: Vec<f32>; triangles: Vec<i64>; color: string; normal: string; roughness: string; }
```

One material's part of a model: its corners' positions (x, y, z), normals and texture coordinates (u, v; v grows
down the image, as in glTF), its triangles, and the files of its color, normal and roughness maps that the model
names ("": none).

- `name`: `string`
- `positions`: `Vec<f32>`
- `normals`: `Vec<f32>`
- `uvs`: `Vec<f32>`
- `triangles`: `Vec<i64>`
- `color`: `string`
- `normal`: `string`
- `roughness`: `string`

### `Model`

```gizlang
type Model = { meshes: Vec<Mesh>; files: Map<string, bytes>; }
```

A model file read: its meshes, and the files it holds in itself (an FBX file's embedded maps) by the names its
meshes give them.

- `meshes`: `Vec<gizlang_models.Mesh>`
- `files`: `_gizlang_sdk_collections.Map<string, bytes>`

### `Property`

```gizlang
type Property = { kind: string; number: f64; text: string; data: bytes; }
```

A property of a record: KIND is its FBX type code (Y C I F D L S R, or f d i l b for arrays). A scalar is in
NUMBER, a string or raw data in TEXT and DATA; an array's count is in NUMBER and its values, little endian, in DATA (item).

- `kind`: `string`
- `number`: `f64`
- `text`: `string`
- `data`: `bytes`

### `Record`

```gizlang
type Record = { name: string; properties: Vec<Property>; children: Vec<Record>; }
```

A record of the file's tree.

- `name`: `string`
- `properties`: `Vec<gizlang_models.Property>`
- `children`: `Vec<gizlang_models.Record>`

## Functions

### `is`

```gizlang
function is(data: bytes): bool
```

Whether DATA is a model file of a format this module reads.

Effects: fail, alloc.

### `read`

```gizlang
function read(data: bytes, resolve: (uri: string) => bytes throws string): Model throws string
```

The model file DATA; RESOLVE reads a file it names (an OBJ file's MTL library) by its name.

Effects: fail, read, write, console, io, alloc.

### `records`

```gizlang
function records(data: bytes): Vec<Record> throws string
```

The top records of the binary FBX file DATA.

Effects: fail, alloc.

### `item`

```gizlang
function item(p: Property, k: i64): f64
```

Value K of the array property P. An array stays in its bytes: a scan's arrays are hundreds of megabytes.

Effects: fail.

### `child`

```gizlang
function child(r: Record, name: string): Record | undefined
```

The first child of R named NAME.

Effects: fail.

