Home

Awesome

rollup-plugin-gltf

build status npm version coverage

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

Installation

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

Usage

// 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.

// 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

License

MIT