• Stars
    star
    1,915
  • Rank 24,206 (Top 0.5 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Content pipeline tools for optimizing glTF assets. 🌐

glTF Pipeline

License Build Status

Content pipeline tools for optimizing glTF assets by Richard Lee and the Cesium team.

Supports common operations including:

  • Converting glTF to glb (and reverse)
  • Saving buffers/textures as embedded or separate files
  • Converting glTF 1.0 models to glTF 2.0
  • Applying Draco mesh compression

gltf-pipeline can be used as a command-line tool or Node.js module.

Getting Started

Install Node.js if you don't already have it, and then:

npm install -g gltf-pipeline

Using gltf-pipeline as a command-line tool:

Converting a glTF to glb

gltf-pipeline -i model.gltf -o model.glb

gltf-pipeline -i model.gltf -b

Converting a glb to glTF

gltf-pipeline -i model.glb -o model.gltf

gltf-pipeline -i model.glb -j

Converting a glTF to Draco glTF

gltf-pipeline -i model.gltf -o modelDraco.gltf -d

Saving separate textures

gltf-pipeline -i model.gltf -t

Using gltf-pipeline as a library:

Converting a glTF to glb:

const gltfPipeline = require("gltf-pipeline");
const fsExtra = require("fs-extra");
const gltfToGlb = gltfPipeline.gltfToGlb;
const gltf = fsExtra.readJsonSync("./input/model.gltf");
const options = { resourceDirectory: "./input/" };
gltfToGlb(gltf, options).then(function (results) {
  fsExtra.writeFileSync("model.glb", results.glb);
});

Converting a glb to embedded glTF

const gltfPipeline = require("gltf-pipeline");
const fsExtra = require("fs-extra");
const glbToGltf = gltfPipeline.glbToGltf;
const glb = fsExtra.readFileSync("model.glb");
glbToGltf(glb).then(function (results) {
  fsExtra.writeJsonSync("model.gltf", results.gltf);
});

Converting a glTF to Draco glTF

const gltfPipeline = require("gltf-pipeline");
const fsExtra = require("fs-extra");
const processGltf = gltfPipeline.processGltf;
const gltf = fsExtra.readJsonSync("model.gltf");
const options = {
  dracoOptions: {
    compressionLevel: 10,
  },
};
processGltf(gltf, options).then(function (results) {
  fsExtra.writeJsonSync("model-draco.gltf", results.gltf);
});

Saving separate textures

const gltfPipeline = require("gltf-pipeline");
const fsExtra = require("fs-extra");
const processGltf = gltfPipeline.processGltf;
const gltf = fsExtra.readJsonSync("model.gltf");
const options = {
  separateTextures: true,
};
processGltf(gltf, options).then(function (results) {
  fsExtra.writeJsonSync("model-separate.gltf", results.gltf);
  // Save separate resources
  const separateResources = results.separateResources;
  for (const relativePath in separateResources) {
    if (separateResources.hasOwnProperty(relativePath)) {
      const resource = separateResources[relativePath];
      fsExtra.writeFileSync(relativePath, resource);
    }
  }
});

Command-Line Flags

Flag Description Required
--help, -h Display help No
--input, -i Path to the glTF or glb file. βœ… Yes
--output, -o Output path of the glTF or glb file. Separate resources will be saved to the same directory. No
--binary, -b Convert the input glTF to glb. No, default false
--json, -j Convert the input glb to glTF. No, default false
--separate, -s Write separate buffers, shaders, and textures instead of embedding them in the glTF. No, default false
--separateTextures, -t Write out separate textures only. No, default false
--stats Print statistics to console for output glTF file. No, default false
--keepUnusedElements Keep unused materials, nodes and meshes. No, default false
--keepLegacyExtensions When false, materials with KHR_techniques_webgl, KHR_blend, or KHR_materials_common will be converted to PBR. No, default false
--draco.compressMeshes, -d Compress the meshes using Draco. Adds the KHR_draco_mesh_compression extension. No, default false
--draco.compressionLevel Draco compression level [0-10], most is 10, least is 0. A value of 0 will apply sequential encoding and preserve face order. No, default 7
--draco.quantizePositionBits Quantization bits for position attribute when using Draco compression. No, default 11
--draco.quantizeNormalBits Quantization bits for normal attribute when using Draco compression. No, default 8
--draco.quantizeTexcoordBits Quantization bits for texture coordinate attribute when using Draco compression. No, default 10
--draco.quantizeColorBits Quantization bits for color attribute when using Draco compression. No, default 8
--draco.quantizeGenericBits Quantization bits for skinning attribute (joint indices and joint weights) and custom attributes when using Draco compression. No, default 8
--draco.unifiedQuantization Quantize positions of all primitives using the same quantization grid. If not set, quantization is applied separately. No, default false
--draco.uncompressedFallback Adds uncompressed fallback versions of the compressed meshes. No, default false
--baseColorTextureNames Names of uniforms that should be considered to refer to base color textures
when updating from the KHR_techniques_webgl extension to PBR materials.
No. (The defaults are not specified here)
--baseColorFactorNames Names of uniforms that should be considered to refer to base color factors
when updating from the KHR_techniques_webgl extension to PBR materials.
No. (The defaults are not specified here)

Build Instructions

Run the tests:

npm run test

To run ESLint on the entire codebase, run:

npm run eslint

To run ESLint automatically when a file is saved, run the following and leave it open in a console window:

npm run eslint-watch

Building for CesiumJS integration

Some functionality of gltf-pipeline is used by CesiumJS as a third party library. The necessary files can be generated using:

npm run build-cesium

This will output a portion of the gltf-pipeline code into the dist/cesium folder for use with CesiumJS in the browser. Copy the files into Source/Scene/GltfPipeline/ in the cesium repository and submit a pull request.

Running Test Coverage

Coverage uses nyc. Run:

npm run coverage

For complete coverage details, open coverage/lcov-report/index.html.

The tests and coverage covers the Node.js module; it does not cover the command-line interface, which is tiny.

Generating Documentation

To generate the documentation:

npm run jsdoc

The documentation will be placed in the doc folder.

Contributions

Pull requests are appreciated! Please use the same Contributor License Agreement (CLA) and Coding Guide used for Cesium.

More Repositories

1

cesium

An open-source JavaScript library for world-class 3D globes and maps 🌎
JavaScript
12,828
star
2

3d-tiles

Specification for streaming massive heterogeneous 3D geospatial datasets 🌎
Batchfile
2,110
star
3

obj2gltf

Convert OBJ assets to glTF
JavaScript
1,706
star
4

cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
C++
924
star
5

cesium-native

C++
423
star
6

3d-tiles-validator

Validator for 3D Tiles 🚦
TypeScript
420
star
7

webglreport

A web page that reports a browser's WebGL capabilities, including supported extensions and implementation specific capabilities, such as the maximum number of texture units.
JavaScript
401
star
8

cesium-unity

Bringing the 3D geospatial ecosystem to Unity
C#
349
star
9

3d-tiles-tools

TypeScript
295
star
10

3d-tiles-samples

Sample tilesets for learning how to use 3D Tiles πŸ“š
JavaScript
274
star
11

cesium-webpack-example

The minimal recommended setup for an application using Cesium with Webpack.
JavaScript
246
star
12

quantized-mesh

Specification for streaming massive terrain datasets for 3D visualization.
238
star
13

cesium-unity-samples

Sample project for Cesium for Unity
C#
229
star
14

cesium-threejs-experiment

A small example for using Three JS on Cesium to emulate a combined scene.
JavaScript
187
star
15

cesium-unreal-samples

Getting Started Sample Project for Cesium for Unreal
183
star
16

cesium-workshop

An example application that visualizes and annotates a 3D city using the Cesium platform.
JavaScript
164
star
17

wetzel

Generate Markdown documentation from JSON Schema
JavaScript
133
star
18

cesium-google-earth-examples

Google Earth plugin API samples ported to Cesium
JavaScript
94
star
19

cesium-materials-pack

A Cesium plugin with procedurally-shaded materials such as bricks, wood, and noise patterns
JavaScript
85
star
20

cdb-to-3dtiles

Convert CDB to 3D Tiles
C++
76
star
21

cesium-o3de

Cesium for O3DE
C++
74
star
22

cesium-omniverse

Bringing the 3D geospatial ecosystem to Omniverse
C++
56
star
23

cesium-ion-rest-api-examples

Code examples for using the Cesium ion REST API 🌎
JavaScript
35
star
24

cesium-vite-example

The minimal recommended setup for an application using Cesium with Vite.
JavaScript
34
star
25

cesium-unreal-vr-tutorial

Unreal Engine project, assets, and code used in the Cesium for Unreal VR Tutorial Series
33
star
26

cesium-ion-blender-addon

Blender add-on for uploading and tiling models with Cesium ion. https://cesium.com
Python
22
star
27

collada2gltf-web-service

Simple Node.js web service to convert 3D models from COLLADA to glTF
JavaScript
20
star
28

cesium-ion-3ds-max-plugin

Autodesk 3DS Max plugin for uploading and tiling models with Cesium ion.
MAXScript
15
star
29

cesium-omniverse-samples

Sample projects for Cesium for Omniverse
14
star
30

3d-tiles-samples-generator

TypeScript
12
star
31

webstorm-plugin

Kotlin
8
star
32

cesium-ion-sketchup-extension

SketchUp extension for uploading and tiling models with Cesium ion.
Ruby
8
star
33

OpenPhillyGlobe

"Google Earth for Philadelphia" with open source and open data.
JavaScript
7
star
34

cesium-o3de-samples

Samples project for Cesium for O3DE
CMake
6
star
35

cesium-concierge

I automate common GitHub tasks
JavaScript
6
star
36

strip-pragma-loader

JavaScript
4
star
37

eslint-config-cesium

ESLint Configuration for Cesium
JavaScript
1
star
38

cesium-ion-plugin-template

1
star