Merge branch 'master' into gltf-2.0

This commit is contained in:
Sean Lilley 2017-07-17 14:38:20 -04:00
commit df20748d60
29 changed files with 526 additions and 499 deletions

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
node_modules/**
coverage/**
doc/**

3
.eslintrc.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "cesium/node"
}

4
.gitignore vendored
View File

@ -7,8 +7,8 @@ npm-debug.log
.idea/tasks.xml .idea/tasks.xml
# Generate data # Generate data
.eslintcache
coverage coverage
doc doc
output
test
*.tgz *.tgz
.nyc_output

View File

@ -1,6 +1,6 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="JSHint" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="Eslint" enabled="true" level="ERROR" enabled_by_default="true" />
</profile> </profile>
</component> </component>

View File

@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JSHintConfiguration" version="2.8.0" use-config-file="true">
<option asi="false" />
<option bitwise="true" />
<option boss="false" />
<option browser="true" />
<option browserify="false" />
<option camelcase="false" />
<option couch="false" />
<option curly="true" />
<option debug="false" />
<option devel="false" />
<option dojo="false" />
<option elision="false" />
<option enforceall="false" />
<option eqeqeq="true" />
<option eqnull="false" />
<option es3="false" />
<option es5="false" />
<option esnext="false" />
<option evil="false" />
<option expr="false" />
<option forin="true" />
<option freeze="false" />
<option funcscope="false" />
<option futurehostile="false" />
<option gcl="false" />
<option globalstrict="false" />
<option immed="false" />
<option iterator="false" />
<option jasmine="false" />
<option jquery="false" />
<option lastsemic="false" />
<option latedef="false" />
<option laxbreak="false" />
<option laxcomma="false" />
<option loopfunc="false" />
<option maxerr="50" />
<option mocha="false" />
<option mootools="false" />
<option moz="false" />
<option multistr="false" />
<option newcap="false" />
<option noarg="true" />
<option nocomma="false" />
<option node="false" />
<option noempty="true" />
<option nomen="false" />
<option nonbsp="false" />
<option nonew="true" />
<option nonstandard="false" />
<option notypeof="false" />
<option noyield="false" />
<option onevar="false" />
<option passfail="false" />
<option phantom="false" />
<option plusplus="false" />
<option proto="false" />
<option prototypejs="false" />
<option qunit="false" />
<option quotmark="false" />
<option rhino="false" />
<option scripturl="false" />
<option shadow="false" />
<option shelljs="false" />
<option singleGroups="false" />
<option smarttabs="false" />
<option strict="true" />
<option sub="false" />
<option supernew="false" />
<option trailing="false" />
<option typed="false" />
<option undef="true" />
<option unused="false" />
<option validthis="false" />
<option white="false" />
<option withstmt="false" />
<option worker="false" />
<option wsh="false" />
<option yui="false" />
</component>
</project>

View File

@ -1,60 +0,0 @@
{
"bitwise": false,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"immed": true,
"latedef": "nofunc",
"newcap": true,
"noarg": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": false,
"undef": true,
"unused": "strict",
"strict": true,
"asi": false,
"boss": false,
"debug": false,
"eqnull": false,
"moz": false,
"evil": false,
"expr": false,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": false,
"multistr": true,
"noyield": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"shadow": false,
"sub": false,
"supernew": false,
"validthis": false,
"browser": false,
"browserify": false,
"couch": false,
"devel": true,
"dojo": false,
"jasmine": false,
"jquery": false,
"mocha": true,
"mootools": false,
"node": true,
"nonstandard": false,
"prototypejs": false,
"qunit": false,
"rhino": false,
"shelljs": false,
"worker": false,
"wsh": false,
"yui": false
}

View File

@ -1,12 +1,13 @@
/.idea /.idea
/coverage /coverage
/doc /doc
/output
/specs /specs
/test /test
/output
.editorconfig .editorconfig
.jshintrc .eslintcache
.eslintignore
.eslintrc.json
.nyc_output
.npmignore .npmignore
.travis.yml .travis.yml
gulpfile.js gulpfile.js

View File

@ -3,7 +3,7 @@ node_js:
- "4" - "4"
- "6" - "6"
script: script:
- npm run jsHint -- --failTaskOnError - npm run eslint
- npm run test -- --failTaskOnError --suppressPassed - npm run test -- --failTaskOnError --suppressPassed
after_success: after_success:

View File

@ -1,6 +1,11 @@
Change Log Change Log
========== ==========
### 1.2.0 2017-07-11
* Change texture sampling to use `NEAREST_MIPMAP_LINEAR` by default [#83](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/83).
* Fixed lighting when generating normals. [#89](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/89)
### 1.1.1 2017-04-25 ### 1.1.1 2017-04-25
* Fixed `CHANGES.md` formatting. * Fixed `CHANGES.md` formatting.

View File

@ -1,10 +1,207 @@
Copyright 2016 Analytical Graphics, Inc. Copyright 2016-2017 Analytical Graphics, Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
http://www.apache.org/licenses/LICENSE-2.0 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2016-2017 Analytical Graphics, Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Third-Party Code Third-Party Code
================ ================
@ -49,35 +246,6 @@ http://cesiumjs.org/
See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
### event-stream
https://www.npmjs.com/package/event-stream
> The MIT License (MIT)
>
> Copyright (c) 2011 Dominic Tarr
>
> Permission is hereby granted, free of charge,
> to any person obtaining a copy of this software and
> associated documentation files (the "Software"), to
> deal in the Software without restriction, including
> without limitation the rights to use, copy, modify,
> merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom
> the Software is furnished to do so,
> subject to the following conditions:
>
> The above copyright notice and this permission notice
> shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
> OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
> ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
### fs-extra ### fs-extra
https://www.npmjs.com/package/fs-extra https://www.npmjs.com/package/fs-extra

View File

@ -58,18 +58,18 @@ Run the tests:
``` ```
npm run test npm run test
``` ```
To run JSHint on the entire codebase, run: To run ESLint on the entire codebase, run:
``` ```
npm run jsHint npm run eslint
``` ```
To run JSHint automatically when a file is saved, run the following and leave it open in a console window: To run ESLint automatically when a file is saved, run the following and leave it open in a console window:
``` ```
npm run jsHint-watch npm run eslint-watch
``` ```
## Running Test Coverage ## Running Test Coverage
Coverage uses [istanbul](https://github.com/gotwarlost/istanbul). Run: Coverage uses [nyc](https://github.com/istanbuljs/nyc). Run:
``` ```
npm run coverage npm run coverage
``` ```

View File

@ -4,7 +4,6 @@ var Cesium = require('cesium');
var child_process = require('child_process'); var child_process = require('child_process');
var fsExtra = require('fs-extra'); var fsExtra = require('fs-extra');
var gulp = require('gulp'); var gulp = require('gulp');
var gulpJshint = require('gulp-jshint');
var Jasmine = require('jasmine'); var Jasmine = require('jasmine');
var JasmineSpecReporter = require('jasmine-spec-reporter').SpecReporter; var JasmineSpecReporter = require('jasmine-spec-reporter').SpecReporter;
var open = require('open'); var open = require('open');
@ -20,25 +19,8 @@ var environmentSeparator = process.platform === 'win32' ? ';' : ':';
var nodeBinaries = path.join(__dirname, 'node_modules', '.bin'); var nodeBinaries = path.join(__dirname, 'node_modules', '.bin');
process.env.PATH += environmentSeparator + nodeBinaries; process.env.PATH += environmentSeparator + nodeBinaries;
var jsHintFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!doc/**'];
var specFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!doc/**', '!bin/**']; var specFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!doc/**', '!bin/**'];
gulp.task('jsHint', function () {
var stream = gulp.src(jsHintFiles)
.pipe(gulpJshint())
.pipe(gulpJshint.reporter('jshint-stylish'));
if (argv.failTaskOnError) {
stream = stream.pipe(gulpJshint.reporter('fail'));
}
return stream;
});
gulp.task('jsHint-watch', function () {
gulp.watch(jsHintFiles, ['jsHint']);
});
gulp.task('test', function (done) { gulp.task('test', function (done) {
var jasmine = new Jasmine(); var jasmine = new Jasmine();
jasmine.loadConfigFile('specs/jasmine.json'); jasmine.loadConfigFile('specs/jasmine.json');
@ -67,9 +49,9 @@ gulp.task('test-watch', function () {
gulp.task('coverage', function () { gulp.task('coverage', function () {
fsExtra.removeSync('coverage/server'); fsExtra.removeSync('coverage/server');
child_process.execSync('istanbul' + child_process.execSync('nyc' +
' cover' + ' --all' +
' --include-all-sources' + ' --reporter=lcov' +
' --dir coverage' + ' --dir coverage' +
' -x "specs/**" -x "coverage/**" -x "doc/**" -x "bin/**" -x "index.js" -x "gulpfile.js"' + ' -x "specs/**" -x "coverage/**" -x "doc/**" -x "bin/**" -x "index.js" -x "gulpfile.js"' +
' node_modules/jasmine/bin/jasmine.js' + ' node_modules/jasmine/bin/jasmine.js' +

View File

@ -1 +1,2 @@
'use strict';
module.exports = require('./lib/obj2gltf'); module.exports = require('./lib/obj2gltf');

View File

@ -91,7 +91,7 @@ function createGltf(objData, options) {
if (gltf.images.length > 0) { if (gltf.images.length > 0) {
gltf.samplers.push({ gltf.samplers.push({
magFilter : WebGLConstants.LINEAR, magFilter : WebGLConstants.LINEAR,
minFilter : WebGLConstants.LINEAR, minFilter : WebGLConstants.NEAREST_MIPMAP_LINEAR,
wrapS : WebGLConstants.REPEAT, wrapS : WebGLConstants.REPEAT,
wrapT : WebGLConstants.REPEAT wrapT : WebGLConstants.REPEAT
}); });
@ -607,7 +607,7 @@ function convertTraditionalToMetallicRoughness(material) {
material.specularShininess = roughnessFactor; material.specularShininess = roughnessFactor;
} }
function createMaterialsCommonMaterial(gltf, images, material, hasNormals) { function createMaterialsCommonMaterial(gltf, images, material, hasNormals, options) {
var materialName = material.name; var materialName = material.name;
var ambientImage = getImage(images, material.ambientTexture); var ambientImage = getImage(images, material.ambientTexture);
@ -643,7 +643,7 @@ function createMaterialsCommonMaterial(gltf, images, material, hasNormals) {
var doubleSided = transparent; var doubleSided = transparent;
if (!hasNormals) { if (!hasNormals && !options.generateNormals) {
// Constant technique only factors in ambient and emission sources - set emission to diffuse // Constant technique only factors in ambient and emission sources - set emission to diffuse
emission = diffuse; emission = diffuse;
diffuse = [0, 0, 0, 1]; diffuse = [0, 0, 0, 1];
@ -683,7 +683,7 @@ function addMaterial(gltf, images, material, hasNormals, options) {
} else if (options.metallicRoughness) { } else if (options.metallicRoughness) {
gltfMaterial = createMetallicRoughnessMaterial(gltf, images, material, options); gltfMaterial = createMetallicRoughnessMaterial(gltf, images, material, options);
} else if (options.materialsCommon) { } else if (options.materialsCommon) {
gltfMaterial = createMaterialsCommonMaterial(gltf, images, material, hasNormals); gltfMaterial = createMaterialsCommonMaterial(gltf, images, material, hasNormals, options);
} else { } else {
convertTraditionalToMetallicRoughness(material); convertTraditionalToMetallicRoughness(material);
gltfMaterial = createMetallicRoughnessMaterial(gltf, images, material, options); gltfMaterial = createMetallicRoughnessMaterial(gltf, images, material, options);

View File

@ -4,11 +4,10 @@ var fsExtra = require('fs-extra');
var jpeg = require('jpeg-js'); var jpeg = require('jpeg-js');
var path = require('path'); var path = require('path');
var PNG = require('pngjs').PNG; var PNG = require('pngjs').PNG;
var Promise = require('bluebird');
var fsExtraReadFile = Promise.promisify(fsExtra.readFile);
var defaultValue = Cesium.defaultValue; var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;
var WebGLConstants = Cesium.WebGLConstants;
module.exports = loadImage; module.exports = loadImage;
@ -28,7 +27,7 @@ function loadImage(imagePath, options) {
options.checkTransparency = defaultValue(options.checkTransparency, false); options.checkTransparency = defaultValue(options.checkTransparency, false);
options.decode = defaultValue(options.decode, false); options.decode = defaultValue(options.decode, false);
return fsExtraReadFile(imagePath) return fsExtra.readFile(imagePath)
.then(function(data) { .then(function(data) {
var extension = path.extname(imagePath).toLowerCase(); var extension = path.extname(imagePath).toLowerCase();

View File

@ -75,7 +75,7 @@ function loadMtl(mtlPath, options) {
material.alpha = parseFloat(value); material.alpha = parseFloat(value);
} else if (/^Tr /i.test(line)) { } else if (/^Tr /i.test(line)) {
value = line.substring(3).trim(); value = line.substring(3).trim();
material.alpha = parseFloat(value); material.alpha = 1.0 - parseFloat(value);
} else if (/^map_Ka /i.test(line)) { } else if (/^map_Ka /i.test(line)) {
material.ambientTexture = path.resolve(mtlDirectory, line.substring(7).trim()); material.ambientTexture = path.resolve(mtlDirectory, line.substring(7).trim());
} else if (/^map_Ke /i.test(line)) { } else if (/^map_Ke /i.test(line)) {

View File

@ -10,8 +10,6 @@ var createGltf = require('./createGltf');
var loadObj = require('./loadObj'); var loadObj = require('./loadObj');
var writeUris = require('./writeUris'); var writeUris = require('./writeUris');
var fsExtraOutputJson = Promise.promisify(fsExtra.outputJson);
var defaultValue = Cesium.defaultValue; var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined; var defined = Cesium.defined;
var DeveloperError = Cesium.DeveloperError; var DeveloperError = Cesium.DeveloperError;
@ -69,6 +67,7 @@ function obj2gltf(objPath, gltfPath, options) {
var materialsCommon = defaultValue(options.materialsCommon, defaults.materialsCommon); var materialsCommon = defaultValue(options.materialsCommon, defaults.materialsCommon);
var logger = defaultValue(options.logger, defaults.logger); var logger = defaultValue(options.logger, defaults.logger);
options.generateNormals = generateNormals;
options.separate = separate; options.separate = separate;
options.separateTextures = separateTextures; options.separateTextures = separateTextures;
options.checkTransparency = checkTransparency; options.checkTransparency = checkTransparency;
@ -133,10 +132,9 @@ function obj2gltf(objPath, gltfPath, options) {
}) })
.then(function(gltf) { .then(function(gltf) {
if (bypassPipeline) { if (bypassPipeline) {
return obj2gltf._outputJson(gltfPath, gltf); return fsExtra.outputJson(gltfPath, gltf);
} else {
return GltfPipeline.processJSONToDisk(gltf, gltfPath, pipelineOptions);
} }
return GltfPipeline.processJSONToDisk(gltf, gltfPath, pipelineOptions);
}) })
.finally(function() { .finally(function() {
return cleanup(resourcesDirectory, options); return cleanup(resourcesDirectory, options);
@ -268,13 +266,6 @@ obj2gltf.defaults = {
} }
}; };
/**
* Exposed for testing
*
* @private
*/
obj2gltf._outputJson = fsExtraOutputJson;
/** /**
* Exposed for testing * Exposed for testing
* *

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
var eventStream = require('event-stream');
var fsExtra = require('fs-extra'); var fsExtra = require('fs-extra');
var Promise = require('bluebird'); var Promise = require('bluebird');
var readline = require('readline');
module.exports = readLines; module.exports = readLines;
@ -15,13 +15,14 @@ module.exports = readLines;
* @private * @private
*/ */
function readLines(path, callback) { function readLines(path, callback) {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
fsExtra.createReadStream(path) var stream = fsExtra.createReadStream(path);
.on('error', reject) stream.on('error', reject);
.on('end', resolve) stream.on('end', resolve);
.pipe(eventStream.split())
.pipe(eventStream.mapSync(function (line) { var lineReader = readline.createInterface({
callback(line); input: stream
})); });
lineReader.on('line', callback);
}); });
} }

View File

@ -5,8 +5,6 @@ var mime = require('mime');
var path = require('path'); var path = require('path');
var Promise = require('bluebird'); var Promise = require('bluebird');
var fsExtraOutputFile = Promise.promisify(fsExtra.outputFile);
var defined = Cesium.defined; var defined = Cesium.defined;
var RuntimeError = Cesium.RuntimeError; var RuntimeError = Cesium.RuntimeError;
@ -107,7 +105,7 @@ function writeSeparateBuffer(gltf, resourcesDirectory, name) {
var bufferUri = name + '.bin'; var bufferUri = name + '.bin';
buffer.uri = bufferUri; buffer.uri = bufferUri;
var bufferPath = path.join(resourcesDirectory, bufferUri); var bufferPath = path.join(resourcesDirectory, bufferUri);
return writeUris._outputFile(bufferPath, source); return fsExtra.outputFile(bufferPath, source);
} }
function writeSeparateTextures(gltf, resourcesDirectory) { function writeSeparateTextures(gltf, resourcesDirectory) {
@ -117,7 +115,7 @@ function writeSeparateTextures(gltf, resourcesDirectory) {
var imageUri = image.name + extras.extension; var imageUri = image.name + extras.extension;
image.uri = imageUri; image.uri = imageUri;
var imagePath = path.join(resourcesDirectory, imageUri); var imagePath = path.join(resourcesDirectory, imageUri);
return writeUris._outputFile(imagePath, extras.source); return fsExtra.outputFile(imagePath, extras.source);
}, {concurrency : 10}); }, {concurrency : 10});
} }
@ -136,10 +134,3 @@ function writeEmbeddedTextures(gltf) {
image.uri = 'data:' + mime.lookup(extras.extension) + ';base64,' + extras.source.toString('base64'); image.uri = 'data:' + mime.lookup(extras.extension) + ';base64,' + extras.source.toString('base64');
} }
} }
/**
* Exposed for testing.
*
* @private
*/
writeUris._outputFile = fsExtraOutputFile;

View File

@ -1,11 +1,11 @@
{ {
"name": "obj2gltf", "name": "obj2gltf",
"version": "1.1.1", "version": "1.2.0",
"description": "Convert OBJ model format to glTF", "description": "Convert OBJ model format to glTF",
"license": "Apache-2.0", "license": "Apache-2.0",
"contributors": [ "contributors": [
{ {
"name": "Analytical Graphics, Inc., and Contributors", "name": "Analytical Graphics, Inc. and Contributors",
"url": "https://github.com/AnalyticalGraphicsInc/obj2gltf/graphs/contributors" "url": "https://github.com/AnalyticalGraphicsInc/obj2gltf/graphs/contributors"
} }
], ],
@ -26,34 +26,31 @@
"node": ">=4.0.0" "node": ">=4.0.0"
}, },
"dependencies": { "dependencies": {
"bluebird": "^3.4.7", "bluebird": "^3.5.0",
"cesium": "^1.31.0", "cesium": "^1.35.2",
"event-stream": "^3.3.4", "fs-extra": "^4.0.0",
"fs-extra": "^2.0.0", "gltf-pipeline": "^1.0.0",
"gltf-pipeline": "^0.1.0-alpha11", "jpeg-js": "^0.3.3",
"jpeg-js": "^0.2.0", "mime": "^1.3.6",
"mime": "^1.3.4",
"pngjs": "^3.2.0", "pngjs": "^3.2.0",
"uuid": "^3.0.1", "uuid": "^3.1.0",
"yargs": "^7.0.1" "yargs": "^8.0.2"
}, },
"devDependencies": { "devDependencies": {
"coveralls": "^2.12.0", "coveralls": "^2.13.1",
"eslint": "^4.2.0",
"eslint-config-cesium": "^2.0.1",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-jshint": "^2.0.4", "jasmine": "^2.6.0",
"istanbul": "^0.4.5", "jasmine-spec-reporter": "^4.1.1",
"jasmine": "^2.5.3", "jsdoc": "^3.5.3",
"jasmine-spec-reporter": "^3.2.0", "nyc": "^11.0.3",
"jsdoc": "^3.4.3",
"jshint": "^2.9.4",
"jshint-stylish": "^2.2.1",
"open": "^0.0.5", "open": "^0.0.5",
"requirejs": "^2.3.3" "requirejs": "^2.3.3"
}, },
"scripts": { "scripts": {
"jsdoc": "jsdoc ./lib -R ./README.md -d doc", "jsdoc": "jsdoc ./lib -R ./README.md -d doc",
"jsHint": "gulp jsHint", "eslint": "eslint \"./**/*.js\" --cache --quiet",
"jsHint-watch": "gulp jsHint-watch",
"test": "gulp test", "test": "gulp test",
"test-watch": "gulp test-watch", "test-watch": "gulp test-watch",
"coverage": "gulp coverage", "coverage": "gulp coverage",

6
specs/.eslintrc.json Normal file
View File

@ -0,0 +1,6 @@
{
"extends": "../.eslintrc.json",
"env": {
"jasmine": true
}
}

View File

@ -1,5 +0,0 @@
{
"extends": "../.jshintrc",
"jasmine": true,
"unused": false
}

View File

@ -9,7 +9,7 @@ Ks 0.500000 0.500000 0.500000
Ke 0.100000 0.100000 0.100000 Ke 0.100000 0.100000 0.100000
Ni 1.000000 Ni 1.000000
d 0.900000 d 0.900000
Tr 0.900000 Tr 0.100000
map_Ka ambient.gif map_Ka ambient.gif
map_Ke emission.jpg map_Ke emission.jpg
map_Kd diffuse.png map_Kd diffuse.png

View File

@ -1,24 +1,17 @@
'use strict'; 'use strict';
var Cesium = require('cesium'); var Cesium = require('cesium');
var fsExtra = require('fs-extra');
var path = require('path');
var Promise = require('bluebird'); var Promise = require('bluebird');
var obj2gltf = require('../../lib/obj2gltf'); var obj2gltf = require('../../lib/obj2gltf');
var createGltf = require('../../lib/createGltf'); var createGltf = require('../../lib/createGltf');
var loadImage = require('../../lib/loadImage'); var loadImage = require('../../lib/loadImage');
var loadObj = require('../../lib/loadObj'); var loadObj = require('../../lib/loadObj');
var Material = require('../../lib/Material'); var Material = require('../../lib/Material');
var writeUris = require('../../lib/writeUris');
var clone = Cesium.clone; var clone = Cesium.clone;
var WebGLConstants = Cesium.WebGLConstants; var WebGLConstants = Cesium.WebGLConstants;
var fsExtraReadJson = Promise.promisify(fsExtra.readJson);
var boxObjUrl = 'specs/data/box/box.obj'; var boxObjUrl = 'specs/data/box/box.obj';
var groupObjUrl = 'specs/data/box-objects-groups-materials/box-objects-groups-materials.obj'; var groupObjUrl = 'specs/data/box-objects-groups-materials/box-objects-groups-materials.obj';
var boxGltfUrl = 'specs/data/box/box.gltf';
var groupGltfUrl = 'specs/data/box-objects-groups-materials/box-objects-groups-materials.gltf';
var diffuseTextureUrl = 'specs/data/box-textured/cesium.png'; var diffuseTextureUrl = 'specs/data/box-textured/cesium.png';
var transparentDiffuseTextureUrl = 'specs/data/box-complex-material/diffuse.png'; var transparentDiffuseTextureUrl = 'specs/data/box-complex-material/diffuse.png';
@ -37,8 +30,6 @@ function setDefaultMaterial(objData) {
describe('createGltf', function() { describe('createGltf', function() {
var boxObjData; var boxObjData;
var groupObjData; var groupObjData;
var boxGltf;
var groupGltf;
var diffuseTexture; var diffuseTexture;
var transparentDiffuseTexture; var transparentDiffuseTexture;
@ -52,14 +43,6 @@ describe('createGltf', function() {
.then(function(data) { .then(function(data) {
groupObjData = data; groupObjData = data;
}), }),
fsExtraReadJson(boxGltfUrl)
.then(function(gltf) {
boxGltf = gltf;
}),
fsExtraReadJson(groupGltfUrl)
.then(function(gltf) {
groupGltf = gltf;
}),
loadImage(diffuseTextureUrl, defaultOptions) loadImage(diffuseTextureUrl, defaultOptions)
.then(function(image) { .then(function(image) {
diffuseTexture = image; diffuseTexture = image;
@ -71,33 +54,43 @@ describe('createGltf', function() {
]).then(done); ]).then(done);
}); });
it('simple gltf', function(done) { it('simple gltf', function() {
var gltf = createGltf(boxObjData, defaultOptions); var gltf = createGltf(boxObjData, defaultOptions);
expect(writeUris(gltf, boxGltfUrl, path.dirname(boxGltfUrl), defaultOptions)
.then(function() { expect(gltf.materials.length).toBe(1);
expect(gltf).toEqual(boxGltf); expect(gltf.nodes.length).toBe(1);
}), done).toResolve(); expect(gltf.meshes.length).toBe(1);
var primitives = gltf.meshes[0].primitives;
var primitive = primitives[0];
var attributes = primitive.attributes;
var positionAccessor = gltf.accessors[attributes.POSITION];
var normalAccessor = gltf.accessors[attributes.NORMAL];
var uvAccessor = gltf.accessors[attributes.TEXCOORD_0];
var indexAccessor = gltf.accessors[primitive.indices];
expect(primitives.length).toBe(1);
expect(positionAccessor.count).toBe(24);
expect(normalAccessor.count).toBe(24);
expect(uvAccessor.count).toBe(24);
expect(indexAccessor.count).toBe(36);
}); });
it('multiple nodes, meshes, and primitives', function(done) { it('multiple nodes, meshes, and primitives', function() {
var gltf = createGltf(groupObjData, defaultOptions); var gltf = createGltf(groupObjData, defaultOptions);
expect(writeUris(gltf, groupGltfUrl, path.dirname(groupGltfUrl), defaultOptions) expect(gltf.materials.length).toBe(3);
.then(function() { expect(gltf.nodes.length).toBe(4);
expect(gltf).toEqual(groupGltf); expect(gltf.nodes[0].mesh).toBeUndefined();
expect(gltf.materials.length).toBe(3); expect(gltf.nodes[0].children.length).toBe(3);
expect(gltf.nodes.length).toBe(4); expect(gltf.meshes.length).toBe(3);
expect(gltf.nodes[0].mesh).toBeUndefined();
expect(gltf.nodes[0].children.length).toBe(3);
expect(gltf.meshes.length).toBe(3);
// Check for two primitives in each mesh // Check for two primitives in each mesh
var length = gltf.meshes.length; var length = gltf.meshes.length;
for (var i = 0; i < length; ++i) { for (var i = 0; i < length; ++i) {
var mesh = gltf.meshes[i]; var mesh = gltf.meshes[i];
expect(mesh.primitives.length).toBe(2); expect(mesh.primitives.length).toBe(2);
} }
}), done).toResolve();
}); });
it('sets default material values', function() { it('sets default material values', function() {
@ -140,175 +133,6 @@ describe('createGltf', function() {
expect(material.emissiveFactor).toEqual([0.0, 0.0, 0.0]); expect(material.emissiveFactor).toEqual([0.0, 0.0, 0.0]);
}); });
it('sets default material values for materialsCommon', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
setDefaultMaterial(boxObjData);
var gltf = createGltf(boxObjData, options);
var material = gltf.materials[0];
var kmc = material.extensions.KHR_materials_common;
var values = kmc.values;
expect(kmc.technique).toBe('LAMBERT');
expect(values.ambient).toEqual([0.0, 0.0, 0.0, 1]);
expect(values.diffuse).toEqual([0.5, 0.5, 0.5, 1]);
expect(values.emission).toEqual([0.0, 0.0, 0.0, 1]);
expect(values.specular).toEqual([0.0, 0.0, 0.0, 1]);
expect(values.shininess).toEqual(0.0);
expect(values.transparency).toBe(1.0);
expect(values.transparent).toBe(false);
expect(values.doubleSided).toBe(false);
});
it('sets material for diffuse texture', function() {
var material = new Material();
material.diffuseTexture = diffuseTextureUrl;
boxObjData.materials[0] = material;
boxObjData.images[diffuseTextureUrl] = diffuseTexture;
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
var texture = gltf.textures.texture_cesium;
var image = gltf.images.cesium;
expect(kmc.technique).toBe('LAMBERT');
expect(kmc.values.diffuse).toEqual('texture_cesium');
expect(kmc.values.transparency).toBe(1.0);
expect(kmc.values.transparent).toBe(false);
expect(kmc.values.doubleSided).toBe(false);
expect(texture).toEqual({
format : WebGLConstants.RGB,
internalFormat : WebGLConstants.RGB,
sampler : 'sampler',
source : 'cesium',
target : WebGLConstants.TEXTURE_2D,
type : WebGLConstants.UNSIGNED_BYTE
});
expect(image).toBeDefined();
expect(image.name).toBe('cesium');
expect(image.extras._obj2gltf.source).toBeDefined();
expect(image.extras._obj2gltf.extension).toBe('.png');
expect(gltf.samplers.sampler).toEqual({
magFilter : WebGLConstants.LINEAR,
minFilter : WebGLConstants.LINEAR,
wrapS : WebGLConstants.REPEAT,
wrapT : WebGLConstants.REPEAT
});
});
it('sets material for alpha less than 1', function() {
var material = new Material();
material.alpha = 0.4;
boxObjData.materials[0] = material;
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 0.4]);
expect(kmc.values.transparency).toBe(1.0);
expect(kmc.values.transparent).toBe(true);
expect(kmc.values.doubleSided).toBe(true);
});
it('sets material for diffuse texture and alpha less than 1', function() {
var material = new Material();
material.diffuseTexture = diffuseTextureUrl;
material.alpha = 0.4;
boxObjData.materials[0] = material;
boxObjData.images[diffuseTextureUrl] = diffuseTexture;
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual('texture_cesium');
expect(kmc.values.transparency).toBe(0.4);
expect(kmc.values.transparent).toBe(true);
expect(kmc.values.doubleSided).toBe(true);
});
it('sets material for transparent diffuse texture', function() {
var material = new Material();
material.diffuseTexture = transparentDiffuseTextureUrl;
boxObjData.materials[0] = material;
boxObjData.images[transparentDiffuseTextureUrl] = transparentDiffuseTexture;
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.values.diffuse).toBe('texture_diffuse');
expect(kmc.values.transparency).toBe(1.0);
expect(kmc.values.transparent).toBe(true);
expect(kmc.values.doubleSided).toBe(true);
});
it('sets material for specular', function() {
var material = new Material();
material.specularColor = [0.1, 0.1, 0.2, 1];
material.specularShininess = 0.1;
boxObjData.materials[0] = material;
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.technique).toBe('PHONG');
expect(kmc.values.specular).toEqual([0.1, 0.1, 0.2, 1]);
expect(kmc.values.shininess).toEqual(0.1);
});
it('sets constant material when there are no normals', function() {
boxObjData.nodes[0].meshes[0].normals.length = 0;
var material = new Material();
material.diffuseTexture = diffuseTextureUrl;
boxObjData.materials[0] = material;
boxObjData.images[diffuseTextureUrl] = diffuseTexture;
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.technique).toBe('CONSTANT');
expect(kmc.values.emission).toEqual('texture_cesium');
});
it('sets default material when texture is missing', function() {
var material = new Material();
material.diffuseTexture = diffuseTextureUrl;
boxObjData.materials[0] = material;
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials[0].extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 1.0]);
});
it('uses default material (1)', function() {
boxObjData.nodes[0].meshes[0].primitives[0].material = undefined;
// Creates a material called "default"
var gltf = createGltf(boxObjData, defaultOptions);
expect(gltf.materials[0].name).toBe('default');
var kmc = gltf.materials[0].extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 1.0]);
});
it('uses default material (2)', function() {
boxObjData.materials = {};
// Uses the original name of the material
var gltf = createGltf(boxObjData, defaultOptions);
var kmc = gltf.materials[0].extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 1.0]);
});
it('runs without normals', function() { it('runs without normals', function() {
boxObjData.nodes[0].meshes[0].normals.length = 0; boxObjData.nodes[0].meshes[0].normals.length = 0;
@ -384,12 +208,212 @@ describe('createGltf', function() {
expect(positionAccessor.count).toBe(vertexCount); expect(positionAccessor.count).toBe(vertexCount);
}); });
it('ambient of [1, 1, 1] is treated as [0, 0, 0]', function() { describe('materialsCommon', function() {
boxObjData.materials.Material.ambientColor = [1.0, 1.0, 1.0, 1.0]; it('sets default material values for materialsCommon', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
var gltf = createGltf(boxObjData); setDefaultMaterial(boxObjData);
var ambient = gltf.materials.Material.extensions.KHR_materials_common.values.ambient;
expect(ambient).toEqual([0.0, 0.0, 0.0, 1.0]); var gltf = createGltf(boxObjData, options);
var material = gltf.materials[0];
var kmc = material.extensions.KHR_materials_common;
var values = kmc.values;
expect(kmc.technique).toBe('LAMBERT');
expect(values.ambient).toEqual([0.0, 0.0, 0.0, 1]);
expect(values.diffuse).toEqual([0.5, 0.5, 0.5, 1]);
expect(values.emission).toEqual([0.0, 0.0, 0.0, 1]);
expect(values.specular).toEqual([0.0, 0.0, 0.0, 1]);
expect(values.shininess).toEqual(0.0);
expect(values.transparency).toBe(1.0);
expect(values.transparent).toBe(false);
expect(values.doubleSided).toBe(false);
});
it('sets material for diffuse texture', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
var defaultMaterial = setDefaultMaterial(boxObjData);
defaultMaterial.diffuseTexture = diffuseTextureUrl;
boxObjData.images[diffuseTextureUrl] = diffuseTexture;
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials[0].extensions.KHR_materials_common;
var texture = gltf.textures.texture_cesium;
var image = gltf.images.cesium;
expect(kmc.technique).toBe('LAMBERT');
expect(kmc.values.diffuse).toEqual('texture_cesium');
expect(kmc.values.transparency).toBe(1.0);
expect(kmc.values.transparent).toBe(false);
expect(kmc.values.doubleSided).toBe(false);
expect(texture).toEqual({
format : WebGLConstants.RGB,
internalFormat : WebGLConstants.RGB,
sampler : 'sampler',
source : 'cesium',
target : WebGLConstants.TEXTURE_2D,
type : WebGLConstants.UNSIGNED_BYTE
});
expect(image).toBeDefined();
expect(image.name).toBe('cesium');
expect(image.extras._obj2gltf.source).toBeDefined();
expect(image.extras._obj2gltf.extension).toBe('.png');
expect(gltf.samplers.sampler).toEqual({
magFilter : WebGLConstants.LINEAR,
minFilter : WebGLConstants.NEAREST_MIPMAP_LINEAR,
wrapS : WebGLConstants.REPEAT,
wrapT : WebGLConstants.REPEAT
});
});
it('sets material for alpha less than 1', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
var material = new Material();
material.alpha = 0.4;
boxObjData.materials[0] = material;
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 0.4]);
expect(kmc.values.transparency).toBe(1.0);
expect(kmc.values.transparent).toBe(true);
expect(kmc.values.doubleSided).toBe(true);
});
it('sets material for diffuse texture and alpha less than 1', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
var material = new Material();
material.diffuseTexture = diffuseTextureUrl;
material.alpha = 0.4;
boxObjData.materials[0] = material;
boxObjData.images[diffuseTextureUrl] = diffuseTexture;
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual('texture_cesium');
expect(kmc.values.transparency).toBe(0.4);
expect(kmc.values.transparent).toBe(true);
expect(kmc.values.doubleSided).toBe(true);
});
it('sets material for transparent diffuse texture', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
var material = new Material();
material.diffuseTexture = transparentDiffuseTextureUrl;
boxObjData.materials[0] = material;
boxObjData.images[transparentDiffuseTextureUrl] = transparentDiffuseTexture;
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.values.diffuse).toBe('texture_diffuse');
expect(kmc.values.transparency).toBe(1.0);
expect(kmc.values.transparent).toBe(true);
expect(kmc.values.doubleSided).toBe(true);
});
it('sets material for specular', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
var material = new Material();
material.specularColor = [0.1, 0.1, 0.2, 1];
material.specularShininess = 0.1;
boxObjData.materials[0] = material;
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.technique).toBe('PHONG');
expect(kmc.values.specular).toEqual([0.1, 0.1, 0.2, 1]);
expect(kmc.values.shininess).toEqual(0.1);
});
it('sets constant material when there are no normals', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
boxObjData.nodes[0].meshes[0].normals.length = 0;
var material = new Material();
material.diffuseTexture = diffuseTextureUrl;
boxObjData.materials[0] = material;
boxObjData.images[diffuseTextureUrl] = diffuseTexture;
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials.Material.extensions.KHR_materials_common;
expect(kmc.technique).toBe('CONSTANT');
expect(kmc.values.emission).toEqual('texture_cesium');
});
it('sets default material when texture is missing', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
var material = new Material();
material.diffuseTexture = diffuseTextureUrl;
boxObjData.materials[0] = material;
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials[0].extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 1.0]);
});
it('uses default material (1)', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
boxObjData.nodes[0].meshes[0].primitives[0].material = undefined;
// Creates a material called "default"
var gltf = createGltf(boxObjData, options);
expect(gltf.materials[0].name).toBe('default');
var kmc = gltf.materials[0].extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 1.0]);
});
it('uses default material (2)', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
boxObjData.materials = {};
// Uses the original name of the material
var gltf = createGltf(boxObjData, options);
var kmc = gltf.materials[0].extensions.KHR_materials_common;
expect(kmc.values.diffuse).toEqual([0.5, 0.5, 0.5, 1.0]);
});
it('ambient of [1, 1, 1] is treated as [0, 0, 0]', function() {
var options = clone(defaultOptions);
options.materialsCommon = true;
boxObjData.materials.Material.ambientColor = [1.0, 1.0, 1.0, 1.0];
var gltf = createGltf(boxObjData, options);
var ambient = gltf.materials.Material.extensions.KHR_materials_common.values.ambient;
expect(ambient).toEqual([0.0, 0.0, 0.0, 1.0]);
});
}); });
}); });

View File

@ -6,7 +6,6 @@ var os = require('os');
var path = require('path'); var path = require('path');
var Promise = require('bluebird'); var Promise = require('bluebird');
var obj2gltf = require('../../lib/obj2gltf'); var obj2gltf = require('../../lib/obj2gltf');
var writeUris = require('../../lib/writeUris');
var RuntimeError = Cesium.RuntimeError; var RuntimeError = Cesium.RuntimeError;
@ -22,8 +21,8 @@ describe('obj2gltf', function() {
expect(obj2gltf._getTempDirectory()).toContain(os.tmpdir()); expect(obj2gltf._getTempDirectory()).toContain(os.tmpdir());
tempDirectory = path.join(os.tmpdir(), 'testPath'); tempDirectory = path.join(os.tmpdir(), 'testPath');
spyOn(obj2gltf, '_getTempDirectory').and.returnValue(tempDirectory); spyOn(obj2gltf, '_getTempDirectory').and.returnValue(tempDirectory);
spyOn(obj2gltf, '_outputJson'); spyOn(fsExtra, 'outputJson');
spyOn(writeUris, '_outputFile'); spyOn(fsExtra, 'outputFile');
spyOn(fsExtra, 'remove'); spyOn(fsExtra, 'remove');
}); });
@ -100,7 +99,7 @@ describe('obj2gltf', function() {
textureCompressionOptions : textureCompressionOptions, textureCompressionOptions : textureCompressionOptions,
preserve : false preserve : false
}); });
expect(writeUris._outputFile.calls.count()).toBe(2); // Saves out .png and .bin expect(fsExtra.outputFile.calls.count()).toBe(2); // Saves out .png and .bin
}), done).toResolve(); }), done).toResolve();
}); });
@ -119,7 +118,7 @@ describe('obj2gltf', function() {
}; };
expect(obj2gltf(objPath, gltfPath, options) expect(obj2gltf(objPath, gltfPath, options)
.then(function() { .then(function() {
expect(obj2gltf._outputJson).toHaveBeenCalled(); expect(fsExtra.outputJson).toHaveBeenCalled();
expect(GltfPipeline.processJSONToDisk).not.toHaveBeenCalled(); expect(GltfPipeline.processJSONToDisk).not.toHaveBeenCalled();
}), done).toResolve(); }), done).toResolve();
}); });

View File

@ -1,6 +1,7 @@
//This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/addDefaultMatchers.js //This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/addDefaultMatchers.js
/*global define*/ /*eslint strict: ["error", "function"]*/
/*jshint unused:false*/ /*eslint-env amd*/
/*eslint-disable no-unused-vars*/
define([ define([
'./equals', './equals',
'Cesium/Core/defined', 'Cesium/Core/defined',

View File

@ -1,4 +1,5 @@
/*global define*/ /*eslint strict: ["error", "function"]*/
/*eslint-env amd*/
define([ define([
'./addDefaultMatchers', './addDefaultMatchers',
'./equalsMethodEqualityTester' './equalsMethodEqualityTester'

View File

@ -1,5 +1,6 @@
//This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/equals.js //This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/equals.js
/*global define*/ /*eslint strict: ["error", "function"]*/
/*eslint-env amd*/
define([ define([
'Cesium/Core/FeatureDetection' 'Cesium/Core/FeatureDetection'
], function( ], function(

View File

@ -1,5 +1,6 @@
//This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/equalsMethodEqualityTester.js //This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/equalsMethodEqualityTester.js
/*global define*/ /*eslint strict: ["error", "function"]*/
/*eslint-env amd*/
define([ define([
'Cesium/Core/defined' 'Cesium/Core/defined'
], function( ], function(