Skip to content

Repository files navigation

OBJ2GLTF

Convert OBJ assets to glTF 1.0.

Getting Started

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

npm install --save obj2gltf

Using obj2gltf as a library:

varobj2gltf=require('obj2gltf');varoptions={separateTextures : true// Don't embed textures in the converted glTF}obj2gltf('model.obj','model.gltf',options).then(function(){console.log('Converted model');});

Using obj2gltf as a command-line tool:

node bin/obj2gltf.js -i model.obj

node bin/obj2gltf.js -i model.obj -o model.gltf

Usage

Command line flags:

FlagDescriptionRequired
-h, --helpDisplay help.No
-i, --inputPath to the obj file.✅ Yes
-o, --outputPath of the converted glTF file.No
-b, --binarySave as binary glTF.No, default false
-s, --separateWrites out separate geometry data files, shader files, and textures instead of embedding them in the glTF file.No, default false
-t, --separateTexturesWrite out separate textures only.No, default false
-c, --compressQuantize positions, compress texture coordinates, and oct-encode normals.No, default false
-z, --optimizeUse the optimization stages in the glTF pipeline.No, default false
-n, --generateNormalsGenerate normals if they are missing.No, default false
--optimizeForCesiumOptimize the glTF for Cesium by using the sun as a default light source.No, default false
--aoApply ambient occlusion to the converted model.No, default false
--kmcOutput glTF with the KHR_materials_common extension.No, default false
--bypassPipelineBypass the gltf-pipeline for debugging purposes. This option overrides many of the options above and will save the glTF with the KHR_materials_common extension.No, default false
--checkTransparencyDo a more exhaustive check for texture transparency by looking at the alpha channel of each pixel. By default textures are considered to be opaque.No, default false
--securePrevent the converter from reading image or mtl files outside of the input obj directory.No, default false
--inputUpAxisUp axis of the obj. Choices are 'X', 'Y', and 'Z'.No, default Y
--outputUpAxisUp axis of the converted glTF. Choices are 'X', 'Y', and 'Z'.No, default Y

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

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.

Debugging

  • To debug the tests in Webstorm, open the Gulp tab, right click the test task, and click Debug 'test'.
  • To run a single test, change the test function from it to fit.

Contributions

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


Developed by the Cesium team.

About

Convert OBJ assets to glTF

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages