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

Fix output name #126

Merged
merged 3 commits into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
### 2.2.0 ???

* Fixed handling of `usemtl` when appearing before an `o` or `g` token. [#121](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/121)
* Fixed output name when running from the command line. [#126](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/126)

### 2.1.0 2017-12-28

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Convert OBJ assets to [glTF](https://www.khronos.org/gltf) 2.0.

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

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

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

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

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

### Using obj2gltf as a library:

Expand Down
20 changes: 8 additions & 12 deletions bin/obj2gltf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var path = require('path');
var yargs = require('yargs');
var obj2gltf = require('../lib/obj2gltf');

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

var defaults = obj2gltf.defaults;
Expand Down Expand Up @@ -123,18 +124,13 @@ if (defined(argv.metallicRoughnessOcclusionTexture) && defined(argv.specularGlos

var objPath = argv.input;
var gltfPath = argv.output;
var name = path.basename(objPath, path.extname(objPath));

if (!defined(gltfPath)) {
gltfPath = path.join(path.dirname(objPath), name + '.gltf');
}
var filename = defaultValue(gltfPath, objPath);
var name = path.basename(filename, path.extname(filename));
var outputDirectory = path.dirname(filename);
var binary = argv.binary || path.extname(filename).toLowerCase() === '.glb';
var extension = binary ? '.glb' : '.gltf';

var outputDirectory = path.dirname(gltfPath);
var extension = path.extname(gltfPath).toLowerCase();
if (argv.binary || extension === '.glb') {
argv.binary = true;
extension = '.glb';
}
gltfPath = path.join(outputDirectory, name + extension);

var overridingTextures = {
Expand All @@ -147,7 +143,7 @@ var overridingTextures = {
};

var options = {
binary : argv.binary,
binary : binary,
separate : argv.separate,
separateTextures : argv.separateTextures,
checkTransparency : argv.checkTransparency,
Expand All @@ -164,7 +160,7 @@ console.time('Total');

obj2gltf(objPath, options)
.then(function(gltf) {
if (argv.binary) {
if (binary) {
// gltf is a glb buffer
return fsExtra.outputFile(gltfPath, gltf);
}
Expand Down