Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bengsfort/rollup-plugin-gltf

Rollup plugin for importing glTF 3D models as ES6 modules.
https://github.com/bengsfort/rollup-plugin-gltf

Last synced: 27 days ago
JSON representation

Rollup plugin for importing glTF 3D models as ES6 modules.

Awesome Lists containing this project

README

        

# rollup-plugin-gltf

![build status](https://api.travis-ci.org/bengsfort/rollup-plugin-gltf.svg?branch=master) [![npm version](https://badge.fury.io/js/rollup-plugin-gltf.svg)](https://www.npmjs.com/package/rollup-plugin-gltf) ![coverage](coverage/coverage.svg)

Rollup plugin for embedding or copying glTF models into your bundles.

## Installation

```shell
npm install --save-dev rollup-plugin-gltf
```

## Usage

```js
// rollup.config.js
import gltf from 'rollup-plugin-gltf';

export default {
entry: 'src/index.js',
dest: 'dist/js/bundle.js',
plugins: [
gltf({
include: '**/*.gltf',
exclude: 'artwork/*.gltf',
inlineAssetLimit: 250 * 1024, // 250kb
inline: false,
}),
],
};
```
The importer will read through the `gltf` file and copy over / embed any assets within the file, then expose the file to JS as either a json object or uri.

```js
// three.js usecase example
import chestModel from './assets/chest.gltf';

const loader = new GLTFLoader();

// If `options.inline` is true
loader.parse(chestModel, function(gltf) {
scene.add(gltf.scene);
});

// If `options.inline` is false
loader.load(chestModel, function(gltf) {
scene.add(gltf.scene);
});
```

### Options

- `include`: **(optional)** The glob for file patterns that should be included. Defaults to all `.gltf` files.
- `exclude`: **(optional)** The glob for file patterns that should be excluded.
- `inlineAssetLimit`: **(optional)** The size (in bytes) at which to copy asset files over rather than embed them into the gltf file. Defaults to 76800.
- `inline`: Boolean determining whether to expose the resolved gltf file as json rather than a uri to the asset.

## License

MIT