Skip to content

Commit

Permalink
Many updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Apr 11, 2017
1 parent 28d081e commit cc8fee1
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 566 deletions.
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,40 @@ npm install --save obj2gltf
Using obj2gltf as a library:
```javascript
var obj2gltf = require('obj2gltf');
var convert = obj2gltf.convert;
var options = {
separateTextures : true // Don't embed textures in the converted glTF
}
convert('model.obj', 'model.gltf', options)
obj2gltf('model.obj', 'model.gltf', options)
.then(function() {
console.log('Converted model');
});
```
Using obj2gltf as a command-line tool:

`node bin/obj2gltf.js model.obj`

`node bin/obj2gltf.js model.obj model.gltf`
`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.gltf -s`

## Usage

###Command line flags:

|Flag|Description|Required|
|----|-----------|--------|
|`-h`|Display help.|No|
|`-i`|Path to the obj file.| :white_check_mark: Yes|
|`-o`|Path of the converted glTF file.|No|
|`-b`|Save as binary glTF.|No, default `false`|
|`-s`|Writes out separate geometry data files, shader files, and textures instead of embedding them in the glTF file.|No, default `false`|
|`-t`|Write out separate textures only.|No, default `false`|
|`-c`|Quantize positions, compress texture coordinates, and oct-encode normals.|No, default `false`|
|`-z`|Use the optimization stages in the glTF pipeline.|No, default `false`|
|`-n`|Generate normals if they are missing.|No, default `false`|
|`--cesium`|Optimize the glTF for Cesium by using the sun as a default light source.|No, default `false`|
|`-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`|
|`-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`|
|`--hasTransparency`|Do a more exhaustive check for texture transparency by looking at the alpha channel of each pixel. By default textures with an alpha channel are considered to be transparent.|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`|

## Build Instructions
Expand Down
65 changes: 31 additions & 34 deletions bin/obj2gltf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ var path = require('path');
var yargs = require('yargs');
var convert = require('../lib/convert');

var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;

var defaults = convert.defaults;

var args = process.argv;
args = args.slice(2, args.length);

var argv = yargs
.usage('Usage: node $0 -i inputPath -o outputPath')
Expand All @@ -21,7 +21,8 @@ var argv = yargs
alias: 'i',
describe: 'Path to the obj file.',
type: 'string',
normalize: true
normalize: true,
demandOption: true
},
output : {
alias: 'o',
Expand All @@ -33,77 +34,72 @@ var argv = yargs
alias: 'b',
describe: 'Save as binary glTF.',
type: 'boolean',
default: false
default: defaults.binary
},
separate : {
alias: 's',
describe: 'Write separate geometry data files, shader files, and textures instead of embedding them in the glTF.',
type: 'boolean',
default: false
default: defaults.separate
},
separateTextures : {
alias: 't',
describe: 'Write out separate textures only.',
type: 'boolean',
default: false
default: defaults.separateTextures
},
compress : {
alias: 'c',
describe: 'Quantize positions, compress texture coordinates, and oct-encode normals.',
type: 'boolean',
default: false
default: defaults.compress
},
optimize : {
alias: 'z',
describe: 'Use the optimization stages in the glTF pipeline.',
describe: 'Optimize the glTF for size and runtime performance.',
type: 'boolean',
default: false
default: defaults.optimize
},
cesium : {
optimizeForCesium : {
describe: 'Optimize the glTF for Cesium by using the sun as a default light source.',
type: 'boolean',
default: false
default: defaults.optimizeForCesium
},
generateNormals : {
alias: 'n',
describe: 'Generate normals if they are missing.',
type: 'boolean',
default: false
default: defaults.generateNormals
},
ao : {
describe: 'Apply ambient occlusion to the converted model.',
type: 'boolean',
default: false
default: defaults.ao
},
kmc : {
describe: 'Output glTF with the KHR_materials_common extension.',
type: 'boolean',
default: false
default: defaults.kmc
},
bypassPipeline : {
describe: '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.',
type: 'boolean',
default: false
default: defaults.bypassPipeline
},
hasTransparency : {
describe: 'Do a more exhaustive check for texture transparency by looking at the alpha channel of each pixel. By default textures with an alpha channel are considered to be transparent.',
checkTransparency : {
describe: '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.',
type: 'boolean',
default: false
default: defaults.checkTransparency
},
secure : {
describe: 'Prevent the converter from reading image or mtl files outside of the input obj directory.',
type: 'boolean',
default: false
default: defaults.secure
}
}).parse(args);

var objPath = defaultValue(argv.i, argv._[0]);
var gltfPath = defaultValue(argv.o, argv._[1]);

if (!defined(objPath)) {
yargs.showHelp();
return;
}
var objPath = argv.i;
var gltfPath = argv.o;

if (!defined(gltfPath)) {
var extension = argv.b ? '.glb' : '.gltf';
Expand All @@ -112,16 +108,17 @@ if (!defined(gltfPath)) {
}

var options = {
binary : argv.b,
separate : argv.s,
separateTextures : argv.t,
compress : argv.c,
optimize : argv.z,
generateNormals : argv.n,
binary : argv.binary,
separate : argv.separate,
separateTextures : argv.separateTextures,
compress : argv.compress,
optimize : argv.optimize,
optimizeForCesium : argv.optimizeForCesium,
generateNormals : argv.generateNormals,
ao : argv.ao,
optimizeForCesium : argv.cesium,
kmc : argv.kmc,
bypassPipeline : argv.bypassPipeline,
hasTransparency : argv.hasTransparency,
checkTransparency : argv.checkTransparency,
secure : argv.secure
};

Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
module.exports = {
convert : require('./lib/convert')
};
module.exports = require('./lib/convert');
19 changes: 19 additions & 0 deletions lib/Material.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = Material;

function Material() {
this.ambientColor = [0.0, 0.0, 0.0, 1.0]; // Ka
this.emissionColor = [0.0, 0.0, 0.0, 1.0]; // Ke
this.diffuseColor = [0.5, 0.5, 0.5, 1.0]; // Kd
this.specularColor = [0.0, 0.0, 0.0, 1.0]; // Ks
this.specularShininess = 0.0; // Ns
this.alpha = 1.0; // d / Tr
this.ambientTexture = undefined; // map_Ka
this.emissionTexture = undefined; // map_Ke
this.diffuseTexture = undefined; // map_Kd
this.specularTexture = undefined; // map_Ks
this.specularShininessMap = undefined; // map_Ns
this.normalMap = undefined; // map_Bump
this.alphaMap = undefined; // map_d
}
54 changes: 0 additions & 54 deletions lib/clone.js

This file was deleted.

Loading

0 comments on commit cc8fee1

Please sign in to comment.