# meshoptInitialize

Function · category: Other

Source: https://github.com/playcanvas/engine/blob/64089771243fe28a9b9d2b4de538b99b07c75097/src/framework/parsers/meshopt-decoder.js#L103

```ts
meshoptInitialize(config: object): void
```

Initializes the decoder used to load glTF files compressed with the `EXT_meshopt_compression`
or `KHR_meshopt_compression` extensions, such as files produced by gltfpack or glTF-Transform.
Without a decoder, these files fail to load unless they also contain uncompressed fallback
data.

The decoder is the meshoptimizer JavaScript decoder (`meshopt_decoder.mjs`). Pass the decoder
object itself, or the URL of the decoder module, which is then imported the first time a
compressed file loads. Files using `KHR_meshopt_compression` need meshoptimizer 1.0 or later.

**Parameters**

- `config` (`object`): The decoder configuration.
    - `config.decoder` (`any`, optional): The decoder object, such as the `MeshoptDecoder` exported by
      the meshoptimizer package.
    - `config.numWorkers` (`number`, optional): The number of web workers to decode on. Defaults to 0,
      which decodes on the main thread.
    - `config.url` (`string`, optional): The URL of the decoder module. Ignored when `decoder` is set.

**Example**

```ts
import { MeshoptDecoder } from 'meshoptimizer';

pc.meshoptInitialize({ decoder: MeshoptDecoder });
```

**Example**

```ts
pc.meshoptInitialize({ url: 'lib/meshopt_decoder.mjs' });
```
