Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glTF 2.0 #67

Merged
merged 25 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ce5221c
2.0
lilleyse Apr 18, 2017
d0e8b90
Merge branch 'master' into gltf-2.0
lilleyse Apr 20, 2017
d6d0d39
Remove occurences of khr_materials_common for code (not tests yet)
lilleyse Apr 20, 2017
c9ad66f
Add metallicRoughness and specularGlosiness output
lilleyse May 3, 2017
dc4ba7f
Merge branch 'master' into gltf-2.0
lilleyse May 4, 2017
44e9d5f
Add back KHR_materials_common
lilleyse May 4, 2017
c2af8f5
Tests
lilleyse May 4, 2017
df20748
Merge branch 'master' into gltf-2.0
lilleyse Jul 17, 2017
608234d
Rounded out materialCommon, pbrMetallicRoughness, and pbrSpecularGlos…
lilleyse Jul 17, 2017
ab6786e
Remove dependence on gltf-pipeline and added gltfToGlb function
lilleyse Jul 19, 2017
aaf44e7
Fix incompatible byte strides
lilleyse Jul 19, 2017
b52f635
Small fixes
lilleyse Jul 24, 2017
3b4e30d
Supply images on the command line
lilleyse Jul 24, 2017
8d491af
bin script tweaks
lilleyse Jul 25, 2017
b8c5ebc
Fix texture index when texture is shared by multiple material values
lilleyse Jul 25, 2017
2a44e0d
Misc fixes
lilleyse Jul 25, 2017
d85e72b
Updates to package.json, README, and CHANGES
lilleyse Jul 25, 2017
125eddd
Fix eslint error
lilleyse Jul 25, 2017
e54f3af
Async image reading/writing and other cleanup
lilleyse Jul 27, 2017
3da691d
Cleanup overriding images
lilleyse Jul 28, 2017
487eca9
Move incompatible argument checking to bin file
lilleyse Jul 28, 2017
cda657e
Fixed interleaving and added comment
lilleyse Jul 28, 2017
60a080b
Reorganization of material loading and returning buffer rather than w…
lilleyse Jul 29, 2017
72baced
Merge branch 'master' into gltf-2.0
lilleyse Aug 10, 2017
b2e4fb6
Add doc
lilleyse Aug 11, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ npm-debug.log
# Generate data
.eslintcache
coverage
doc
*.tgz
.nyc_output
doc/*
!doc/cesium.png
2 changes: 2 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.idea
/coverage
/doc
/doc/*
/specs
/test
.editorconfig
Expand All @@ -12,3 +12,4 @@
.travis.yml
gulpfile.js
*.tgz
!doc/cesium.png
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change Log
==========

### 2.0.0 2017-07-XX

* Breaking changes
* Obj models now convert to glTF 2.0. Possible material profiles are `metallicRoughness`, `specGlossiness` (using the `KHR_materials_pbrSpecularGlossiness` extension), and `materialsCommon` (using the `KHR_materials_common` extension).
* Removed `gltf-pipeline` dependency. The following options have been removed: `compress`, `optimize`, `generateNormals`, `optimizeForCesium`, `ao`, and `bypassPipeline`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also remove binary gltf compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, nevermind.

* Removed `inputUpAxis` and `outputUpAxis`. This stage will be incorporated into `gltf-pipeline` instead.
* `obj2gltf` no longer takes a `gltfPath` argument and saves a glTF file. Instead it returns a promise that resolves to the glTF JSON or glb buffer.

### 1.2.0 2017-07-11

* Change texture sampling to use `NEAREST_MIPMAP_LINEAR` by default [#83](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/83).
Expand Down
92 changes: 65 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
# OBJ2GLTF

Convert OBJ assets to [glTF](https://www.khronos.org/gltf) 1.0.
Convert OBJ assets to [glTF](https://www.khronos.org/gltf) 2.0.

## Getting Started

Install [Node.js](https://nodejs.org/en/) if you don't already have it, and then:
```
npm install --save obj2gltf
```
Using obj2gltf as a library:

### Using obj2gltf as a command-line tool:

`node bin/obj2gltf.js -i model.obj`

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

`node bin/obj2gltf.js -i model.obj -o model.glb`

### Using obj2gltf as a library:

#### Converting an obj model to gltf:

```javascript
var obj2gltf = require('obj2gltf');
obj2gltf('model.obj')
.then(function(gltf) {
console.log(gltf.asset);
});
```

#### Converting an obj model to glb

```javascript
var obj2gltf = require('obj2gltf');
var options = {
separateTextures : true // Don't embed textures in the converted glTF
binary : true
}
obj2gltf('model.obj', 'model.gltf', options)
.then(function() {
console.log('Converted model');
obj2gltf('model.obj', options)
.then(function(glb) {
console.log(glb.length);
});
```
Using obj2gltf as a command-line tool:

`node bin/obj2gltf.js -i model.obj`
## Material types

`node bin/obj2gltf.js -i model.obj -o model.gltf`
Traditionally the .mtl file format describes the Blinn-Phong shading model. Meanwhile glTF 2.0 introduces physically-based
materials.

There are three shading models supported by `obj2gltf`:

* Metallic roughness PBR
* Specular glossiness PBR (via `KHR_materials_pbrSpecularGlossiness` extension)
* Materials common (via `KHR_materials_common` extension)

If the material type is known in advance, it should be specified with either the `metallicRoughness`, `specularGlossiness`, or `materialsCommon` flag.

In general, if a model is authored with traditional diffuse, specular, and shininess textures the `materialsCommon` flag should be passed in.
The glTF will be saved with the `KHR_materials_common` extension and the Blinn-Phong shading model will be used.

However if the model is created with PBR textures, either the `metallicRoughness` or `specularGlossiness` flag should be passed in.
See the command line flags below for more information about how to specify PBR values inside the .mtl file.

If none of these flags are provided, the .mtl is assumed to contain traditional Blinn-Phong materials which will be converted to metallic-roughness PBR.
There may be some quality loss as traditional materials do not map perfectly to PBR materials.

Commonly in PBR workflows the the .mtl file may not exist or its values may be outdated or incorrect.
As a convenience the PBR textures may be supplied directly to the command line. See the options below.

## Usage

Expand All @@ -33,21 +75,22 @@ Using obj2gltf as a command-line tool:
|----|-----------|--------|
|`-h`, `--help`|Display help.|No|
|`-i`, `--input`|Path to the obj file.| :white_check_mark: Yes|
|`-o`, `--output`|Path of the converted glTF file.|No|
|`-b`, `--binary`|Save as binary glTF.|No, default `false`|
|`-s`, `--separate`|Writes out separate geometry data files, shader files, and textures instead of embedding them in the glTF file.|No, default `false`|
|`-o`, `--output`|Path of the converted glTF or glb file.|No|
|`-b`, `--binary`|Save as binary glTF (.glb).|No, default `false`|
|`-s`, `--separate`|Writes out separate buffers and textures instead of embedding them in the glTF file.|No, default `false`|
|`-t`, `--separateTextures`|Write out separate textures only.|No, default `false`|
|`-c`, `--compress`|Quantize positions, compress texture coordinates, and oct-encode normals.|No, default `false`|
|`-z`, `--optimize`|Use the optimization stages in the glTF pipeline.|No, default `false`|
|`-n`, `--generateNormals`|Generate normals if they are missing.|No, default `false`|
|`--optimizeForCesium`|Optimize the glTF for Cesium by using the sun as a default light source.|No, default `false`|
|`--ao`|Apply ambient occlusion to the converted model.|No, default `false`|
|`--kmc`|Output glTF with the KHR_materials_common extension.|No, default `false`|
|`--bypassPipeline`|Bypass 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`|
|`--checkTransparency`|Do 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`|
|`--secure`|Prevent the converter from reading image or mtl files outside of the input obj directory.|No, default `false`|
|`--inputUpAxis`|Up axis of the obj. Choices are 'X', 'Y', and 'Z'.|No, default `Y`|
|`--outputUpAxis`|Up axis of the converted glTF. Choices are 'X', 'Y', and 'Z'.|No, default `Y`|
|`--secure`|Prevent the converter from reading texture or mtl files outside of the input obj directory.|No, default `false`|
|`--packOcclusion`|Pack the occlusion texture in the red channel of metallic-roughness texture.|No, default `false`|
|`--metallicRoughness`|The values in the mtl file are already metallic-roughness PBR values and no conversion step should be applied. Metallic is stored in the Ks and map_Ks slots and roughness is stored in the Ns and map_Ns slots.|No, default `false`|
|`--specularGlossiness`|The values in the mtl file are already specular-glossiness PBR values and no conversion step should be applied. Specular is stored in the Ks and map_Ks slots and glossiness is stored in the Ns and map_Ns slots. The glTF will be saved with the `KHR_materials_pbrSpecularGlossiness` extension.|No, default `false`|
|`--materialsCommon`|The glTF will be saved with the KHR_materials_common extension.|No, default `false`|
|`--metallicRoughnessOcclusionTexture`|Path to the metallic-roughness-occlusion texture that should override textures in the .mtl file, where occlusion is stored in the red channel, roughness is stored in the green channel, and metallic is stored in the blue channel. The model will be saved with a pbrMetallicRoughness material. This is often convenient in workflows where the .mtl does not exist or is not set up to use PBR materials. Intended for models with a single material.|No|
|`--specularGlossinessTexture`|Path to the specular-glossiness texture that should override textures in the .mtl file, where specular color is stored in the red, green, and blue channels and specular glossiness is stored in the alpha channel. The model will be saved with a material using the KHR_materials_pbrSpecularGlossiness extension.|No|
|`--occlusionTexture`|Path to the occlusion texture that should override textures in the .mtl file.|No|
|`--normalTexture`|Path to the normal texture that should override textures in the .mtl file.|No|
|`--baseColorTexture`|Path to the baseColor/diffuse texture that should override textures in the .mtl file.|No|
|`--emissiveTexture`|Path to the emissive texture that should override textures in the .mtl file.|No|

## Build Instructions

Expand Down Expand Up @@ -83,11 +126,6 @@ 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)](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/CONTRIBUTING.md) used for [Cesium](http://cesiumjs.org/).
Expand Down
Loading