mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-02-06 23:13:02 -05:00
Merge branch 'master' into gltf-2.0
This commit is contained in:
commit
df20748d60
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules/**
|
||||
coverage/**
|
||||
doc/**
|
3
.eslintrc.json
Normal file
3
.eslintrc.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "cesium/node"
|
||||
}
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -7,8 +7,8 @@ npm-debug.log
|
||||
.idea/tasks.xml
|
||||
|
||||
# Generate data
|
||||
.eslintcache
|
||||
coverage
|
||||
doc
|
||||
output
|
||||
test
|
||||
*.tgz
|
||||
.nyc_output
|
||||
|
2
.idea/inspectionProfiles/Project_Default.xml
generated
2
.idea/inspectionProfiles/Project_Default.xml
generated
@ -1,6 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<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>
|
||||
</component>
|
83
.idea/jsLinters/jshint.xml
generated
83
.idea/jsLinters/jshint.xml
generated
@ -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>
|
60
.jshintrc
60
.jshintrc
@ -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
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
/.idea
|
||||
/coverage
|
||||
/doc
|
||||
/output
|
||||
/specs
|
||||
/test
|
||||
/output
|
||||
.editorconfig
|
||||
.jshintrc
|
||||
.eslintcache
|
||||
.eslintignore
|
||||
.eslintrc.json
|
||||
.nyc_output
|
||||
.npmignore
|
||||
.travis.yml
|
||||
gulpfile.js
|
||||
|
@ -3,7 +3,7 @@ node_js:
|
||||
- "4"
|
||||
- "6"
|
||||
script:
|
||||
- npm run jsHint -- --failTaskOnError
|
||||
- npm run eslint
|
||||
- npm run test -- --failTaskOnError --suppressPassed
|
||||
|
||||
after_success:
|
||||
|
@ -1,6 +1,11 @@
|
||||
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
|
||||
|
||||
* Fixed `CHANGES.md` formatting.
|
||||
|
234
LICENSE.md
234
LICENSE.md
@ -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
|
||||
================
|
||||
@ -49,35 +246,6 @@ http://cesiumjs.org/
|
||||
|
||||
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
|
||||
|
||||
https://www.npmjs.com/package/fs-extra
|
||||
|
10
README.md
10
README.md
@ -58,18 +58,18 @@ Run the tests:
|
||||
```
|
||||
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
|
||||
|
||||
Coverage uses [istanbul](https://github.com/gotwarlost/istanbul). Run:
|
||||
Coverage uses [nyc](https://github.com/istanbuljs/nyc). Run:
|
||||
```
|
||||
npm run coverage
|
||||
```
|
||||
|
24
gulpfile.js
24
gulpfile.js
@ -4,7 +4,6 @@ var Cesium = require('cesium');
|
||||
var child_process = require('child_process');
|
||||
var fsExtra = require('fs-extra');
|
||||
var gulp = require('gulp');
|
||||
var gulpJshint = require('gulp-jshint');
|
||||
var Jasmine = require('jasmine');
|
||||
var JasmineSpecReporter = require('jasmine-spec-reporter').SpecReporter;
|
||||
var open = require('open');
|
||||
@ -20,25 +19,8 @@ var environmentSeparator = process.platform === 'win32' ? ';' : ':';
|
||||
var nodeBinaries = path.join(__dirname, 'node_modules', '.bin');
|
||||
process.env.PATH += environmentSeparator + nodeBinaries;
|
||||
|
||||
var jsHintFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!doc/**'];
|
||||
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) {
|
||||
var jasmine = new Jasmine();
|
||||
jasmine.loadConfigFile('specs/jasmine.json');
|
||||
@ -67,9 +49,9 @@ gulp.task('test-watch', function () {
|
||||
|
||||
gulp.task('coverage', function () {
|
||||
fsExtra.removeSync('coverage/server');
|
||||
child_process.execSync('istanbul' +
|
||||
' cover' +
|
||||
' --include-all-sources' +
|
||||
child_process.execSync('nyc' +
|
||||
' --all' +
|
||||
' --reporter=lcov' +
|
||||
' --dir coverage' +
|
||||
' -x "specs/**" -x "coverage/**" -x "doc/**" -x "bin/**" -x "index.js" -x "gulpfile.js"' +
|
||||
' node_modules/jasmine/bin/jasmine.js' +
|
||||
|
@ -91,7 +91,7 @@ function createGltf(objData, options) {
|
||||
if (gltf.images.length > 0) {
|
||||
gltf.samplers.push({
|
||||
magFilter : WebGLConstants.LINEAR,
|
||||
minFilter : WebGLConstants.LINEAR,
|
||||
minFilter : WebGLConstants.NEAREST_MIPMAP_LINEAR,
|
||||
wrapS : WebGLConstants.REPEAT,
|
||||
wrapT : WebGLConstants.REPEAT
|
||||
});
|
||||
@ -607,7 +607,7 @@ function convertTraditionalToMetallicRoughness(material) {
|
||||
material.specularShininess = roughnessFactor;
|
||||
}
|
||||
|
||||
function createMaterialsCommonMaterial(gltf, images, material, hasNormals) {
|
||||
function createMaterialsCommonMaterial(gltf, images, material, hasNormals, options) {
|
||||
var materialName = material.name;
|
||||
|
||||
var ambientImage = getImage(images, material.ambientTexture);
|
||||
@ -643,7 +643,7 @@ function createMaterialsCommonMaterial(gltf, images, material, hasNormals) {
|
||||
|
||||
var doubleSided = transparent;
|
||||
|
||||
if (!hasNormals) {
|
||||
if (!hasNormals && !options.generateNormals) {
|
||||
// Constant technique only factors in ambient and emission sources - set emission to diffuse
|
||||
emission = diffuse;
|
||||
diffuse = [0, 0, 0, 1];
|
||||
@ -683,7 +683,7 @@ function addMaterial(gltf, images, material, hasNormals, options) {
|
||||
} else if (options.metallicRoughness) {
|
||||
gltfMaterial = createMetallicRoughnessMaterial(gltf, images, material, options);
|
||||
} else if (options.materialsCommon) {
|
||||
gltfMaterial = createMaterialsCommonMaterial(gltf, images, material, hasNormals);
|
||||
gltfMaterial = createMaterialsCommonMaterial(gltf, images, material, hasNormals, options);
|
||||
} else {
|
||||
convertTraditionalToMetallicRoughness(material);
|
||||
gltfMaterial = createMetallicRoughnessMaterial(gltf, images, material, options);
|
||||
|
@ -4,11 +4,10 @@ var fsExtra = require('fs-extra');
|
||||
var jpeg = require('jpeg-js');
|
||||
var path = require('path');
|
||||
var PNG = require('pngjs').PNG;
|
||||
var Promise = require('bluebird');
|
||||
|
||||
var fsExtraReadFile = Promise.promisify(fsExtra.readFile);
|
||||
|
||||
var defaultValue = Cesium.defaultValue;
|
||||
var defined = Cesium.defined;
|
||||
var WebGLConstants = Cesium.WebGLConstants;
|
||||
|
||||
module.exports = loadImage;
|
||||
|
||||
@ -28,7 +27,7 @@ function loadImage(imagePath, options) {
|
||||
options.checkTransparency = defaultValue(options.checkTransparency, false);
|
||||
options.decode = defaultValue(options.decode, false);
|
||||
|
||||
return fsExtraReadFile(imagePath)
|
||||
return fsExtra.readFile(imagePath)
|
||||
.then(function(data) {
|
||||
var extension = path.extname(imagePath).toLowerCase();
|
||||
|
||||
|
@ -75,7 +75,7 @@ function loadMtl(mtlPath, options) {
|
||||
material.alpha = parseFloat(value);
|
||||
} else if (/^Tr /i.test(line)) {
|
||||
value = line.substring(3).trim();
|
||||
material.alpha = parseFloat(value);
|
||||
material.alpha = 1.0 - parseFloat(value);
|
||||
} else if (/^map_Ka /i.test(line)) {
|
||||
material.ambientTexture = path.resolve(mtlDirectory, line.substring(7).trim());
|
||||
} else if (/^map_Ke /i.test(line)) {
|
||||
|
@ -10,8 +10,6 @@ var createGltf = require('./createGltf');
|
||||
var loadObj = require('./loadObj');
|
||||
var writeUris = require('./writeUris');
|
||||
|
||||
var fsExtraOutputJson = Promise.promisify(fsExtra.outputJson);
|
||||
|
||||
var defaultValue = Cesium.defaultValue;
|
||||
var defined = Cesium.defined;
|
||||
var DeveloperError = Cesium.DeveloperError;
|
||||
@ -69,6 +67,7 @@ function obj2gltf(objPath, gltfPath, options) {
|
||||
var materialsCommon = defaultValue(options.materialsCommon, defaults.materialsCommon);
|
||||
var logger = defaultValue(options.logger, defaults.logger);
|
||||
|
||||
options.generateNormals = generateNormals;
|
||||
options.separate = separate;
|
||||
options.separateTextures = separateTextures;
|
||||
options.checkTransparency = checkTransparency;
|
||||
@ -133,10 +132,9 @@ function obj2gltf(objPath, gltfPath, options) {
|
||||
})
|
||||
.then(function(gltf) {
|
||||
if (bypassPipeline) {
|
||||
return obj2gltf._outputJson(gltfPath, gltf);
|
||||
} else {
|
||||
return GltfPipeline.processJSONToDisk(gltf, gltfPath, pipelineOptions);
|
||||
return fsExtra.outputJson(gltfPath, gltf);
|
||||
}
|
||||
return GltfPipeline.processJSONToDisk(gltf, gltfPath, pipelineOptions);
|
||||
})
|
||||
.finally(function() {
|
||||
return cleanup(resourcesDirectory, options);
|
||||
@ -268,13 +266,6 @@ obj2gltf.defaults = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Exposed for testing
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
obj2gltf._outputJson = fsExtraOutputJson;
|
||||
|
||||
/**
|
||||
* Exposed for testing
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
var eventStream = require('event-stream');
|
||||
var fsExtra = require('fs-extra');
|
||||
var Promise = require('bluebird');
|
||||
var readline = require('readline');
|
||||
|
||||
module.exports = readLines;
|
||||
|
||||
@ -15,13 +15,14 @@ module.exports = readLines;
|
||||
* @private
|
||||
*/
|
||||
function readLines(path, callback) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
fsExtra.createReadStream(path)
|
||||
.on('error', reject)
|
||||
.on('end', resolve)
|
||||
.pipe(eventStream.split())
|
||||
.pipe(eventStream.mapSync(function (line) {
|
||||
callback(line);
|
||||
}));
|
||||
return new Promise(function (resolve, reject) {
|
||||
var stream = fsExtra.createReadStream(path);
|
||||
stream.on('error', reject);
|
||||
stream.on('end', resolve);
|
||||
|
||||
var lineReader = readline.createInterface({
|
||||
input: stream
|
||||
});
|
||||
lineReader.on('line', callback);
|
||||
});
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ var mime = require('mime');
|
||||
var path = require('path');
|
||||
var Promise = require('bluebird');
|
||||
|
||||
var fsExtraOutputFile = Promise.promisify(fsExtra.outputFile);
|
||||
|
||||
var defined = Cesium.defined;
|
||||
var RuntimeError = Cesium.RuntimeError;
|
||||
|
||||
@ -107,7 +105,7 @@ function writeSeparateBuffer(gltf, resourcesDirectory, name) {
|
||||
var bufferUri = name + '.bin';
|
||||
buffer.uri = bufferUri;
|
||||
var bufferPath = path.join(resourcesDirectory, bufferUri);
|
||||
return writeUris._outputFile(bufferPath, source);
|
||||
return fsExtra.outputFile(bufferPath, source);
|
||||
}
|
||||
|
||||
function writeSeparateTextures(gltf, resourcesDirectory) {
|
||||
@ -117,7 +115,7 @@ function writeSeparateTextures(gltf, resourcesDirectory) {
|
||||
var imageUri = image.name + extras.extension;
|
||||
image.uri = imageUri;
|
||||
var imagePath = path.join(resourcesDirectory, imageUri);
|
||||
return writeUris._outputFile(imagePath, extras.source);
|
||||
return fsExtra.outputFile(imagePath, extras.source);
|
||||
}, {concurrency : 10});
|
||||
}
|
||||
|
||||
@ -136,10 +134,3 @@ function writeEmbeddedTextures(gltf) {
|
||||
image.uri = 'data:' + mime.lookup(extras.extension) + ';base64,' + extras.source.toString('base64');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposed for testing.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
writeUris._outputFile = fsExtraOutputFile;
|
||||
|
39
package.json
39
package.json
@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "obj2gltf",
|
||||
"version": "1.1.1",
|
||||
"version": "1.2.0",
|
||||
"description": "Convert OBJ model format to glTF",
|
||||
"license": "Apache-2.0",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Analytical Graphics, Inc., and Contributors",
|
||||
"name": "Analytical Graphics, Inc. and Contributors",
|
||||
"url": "https://github.com/AnalyticalGraphicsInc/obj2gltf/graphs/contributors"
|
||||
}
|
||||
],
|
||||
@ -26,34 +26,31 @@
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bluebird": "^3.4.7",
|
||||
"cesium": "^1.31.0",
|
||||
"event-stream": "^3.3.4",
|
||||
"fs-extra": "^2.0.0",
|
||||
"gltf-pipeline": "^0.1.0-alpha11",
|
||||
"jpeg-js": "^0.2.0",
|
||||
"mime": "^1.3.4",
|
||||
"bluebird": "^3.5.0",
|
||||
"cesium": "^1.35.2",
|
||||
"fs-extra": "^4.0.0",
|
||||
"gltf-pipeline": "^1.0.0",
|
||||
"jpeg-js": "^0.3.3",
|
||||
"mime": "^1.3.6",
|
||||
"pngjs": "^3.2.0",
|
||||
"uuid": "^3.0.1",
|
||||
"yargs": "^7.0.1"
|
||||
"uuid": "^3.1.0",
|
||||
"yargs": "^8.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.12.0",
|
||||
"coveralls": "^2.13.1",
|
||||
"eslint": "^4.2.0",
|
||||
"eslint-config-cesium": "^2.0.1",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-jshint": "^2.0.4",
|
||||
"istanbul": "^0.4.5",
|
||||
"jasmine": "^2.5.3",
|
||||
"jasmine-spec-reporter": "^3.2.0",
|
||||
"jsdoc": "^3.4.3",
|
||||
"jshint": "^2.9.4",
|
||||
"jshint-stylish": "^2.2.1",
|
||||
"jasmine": "^2.6.0",
|
||||
"jasmine-spec-reporter": "^4.1.1",
|
||||
"jsdoc": "^3.5.3",
|
||||
"nyc": "^11.0.3",
|
||||
"open": "^0.0.5",
|
||||
"requirejs": "^2.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"jsdoc": "jsdoc ./lib -R ./README.md -d doc",
|
||||
"jsHint": "gulp jsHint",
|
||||
"jsHint-watch": "gulp jsHint-watch",
|
||||
"eslint": "eslint \"./**/*.js\" --cache --quiet",
|
||||
"test": "gulp test",
|
||||
"test-watch": "gulp test-watch",
|
||||
"coverage": "gulp coverage",
|
||||
|
6
specs/.eslintrc.json
Normal file
6
specs/.eslintrc.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../.eslintrc.json",
|
||||
"env": {
|
||||
"jasmine": true
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"extends": "../.jshintrc",
|
||||
"jasmine": true,
|
||||
"unused": false
|
||||
}
|
@ -9,7 +9,7 @@ Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.100000 0.100000 0.100000
|
||||
Ni 1.000000
|
||||
d 0.900000
|
||||
Tr 0.900000
|
||||
Tr 0.100000
|
||||
map_Ka ambient.gif
|
||||
map_Ke emission.jpg
|
||||
map_Kd diffuse.png
|
||||
|
@ -1,24 +1,17 @@
|
||||
'use strict';
|
||||
var Cesium = require('cesium');
|
||||
var fsExtra = require('fs-extra');
|
||||
var path = require('path');
|
||||
var Promise = require('bluebird');
|
||||
var obj2gltf = require('../../lib/obj2gltf');
|
||||
var createGltf = require('../../lib/createGltf');
|
||||
var loadImage = require('../../lib/loadImage');
|
||||
var loadObj = require('../../lib/loadObj');
|
||||
var Material = require('../../lib/Material');
|
||||
var writeUris = require('../../lib/writeUris');
|
||||
|
||||
var clone = Cesium.clone;
|
||||
var WebGLConstants = Cesium.WebGLConstants;
|
||||
|
||||
var fsExtraReadJson = Promise.promisify(fsExtra.readJson);
|
||||
|
||||
var boxObjUrl = 'specs/data/box/box.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 transparentDiffuseTextureUrl = 'specs/data/box-complex-material/diffuse.png';
|
||||
|
||||
@ -37,8 +30,6 @@ function setDefaultMaterial(objData) {
|
||||
describe('createGltf', function() {
|
||||
var boxObjData;
|
||||
var groupObjData;
|
||||
var boxGltf;
|
||||
var groupGltf;
|
||||
var diffuseTexture;
|
||||
var transparentDiffuseTexture;
|
||||
|
||||
@ -52,14 +43,6 @@ describe('createGltf', function() {
|
||||
.then(function(data) {
|
||||
groupObjData = data;
|
||||
}),
|
||||
fsExtraReadJson(boxGltfUrl)
|
||||
.then(function(gltf) {
|
||||
boxGltf = gltf;
|
||||
}),
|
||||
fsExtraReadJson(groupGltfUrl)
|
||||
.then(function(gltf) {
|
||||
groupGltf = gltf;
|
||||
}),
|
||||
loadImage(diffuseTextureUrl, defaultOptions)
|
||||
.then(function(image) {
|
||||
diffuseTexture = image;
|
||||
@ -71,33 +54,43 @@ describe('createGltf', function() {
|
||||
]).then(done);
|
||||
});
|
||||
|
||||
it('simple gltf', function(done) {
|
||||
it('simple gltf', function() {
|
||||
var gltf = createGltf(boxObjData, defaultOptions);
|
||||
expect(writeUris(gltf, boxGltfUrl, path.dirname(boxGltfUrl), defaultOptions)
|
||||
.then(function() {
|
||||
expect(gltf).toEqual(boxGltf);
|
||||
}), done).toResolve();
|
||||
|
||||
expect(gltf.materials.length).toBe(1);
|
||||
expect(gltf.nodes.length).toBe(1);
|
||||
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);
|
||||
|
||||
expect(writeUris(gltf, groupGltfUrl, path.dirname(groupGltfUrl), defaultOptions)
|
||||
.then(function() {
|
||||
expect(gltf).toEqual(groupGltf);
|
||||
expect(gltf.materials.length).toBe(3);
|
||||
expect(gltf.nodes.length).toBe(4);
|
||||
expect(gltf.nodes[0].mesh).toBeUndefined();
|
||||
expect(gltf.nodes[0].children.length).toBe(3);
|
||||
expect(gltf.meshes.length).toBe(3);
|
||||
expect(gltf.materials.length).toBe(3);
|
||||
expect(gltf.nodes.length).toBe(4);
|
||||
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
|
||||
var length = gltf.meshes.length;
|
||||
for (var i = 0; i < length; ++i) {
|
||||
var mesh = gltf.meshes[i];
|
||||
expect(mesh.primitives.length).toBe(2);
|
||||
}
|
||||
}), done).toResolve();
|
||||
// Check for two primitives in each mesh
|
||||
var length = gltf.meshes.length;
|
||||
for (var i = 0; i < length; ++i) {
|
||||
var mesh = gltf.meshes[i];
|
||||
expect(mesh.primitives.length).toBe(2);
|
||||
}
|
||||
});
|
||||
|
||||
it('sets default material values', function() {
|
||||
@ -140,175 +133,6 @@ describe('createGltf', function() {
|
||||
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() {
|
||||
boxObjData.nodes[0].meshes[0].normals.length = 0;
|
||||
|
||||
@ -384,12 +208,212 @@ describe('createGltf', function() {
|
||||
expect(positionAccessor.count).toBe(vertexCount);
|
||||
});
|
||||
|
||||
it('ambient of [1, 1, 1] is treated as [0, 0, 0]', function() {
|
||||
boxObjData.materials.Material.ambientColor = [1.0, 1.0, 1.0, 1.0];
|
||||
describe('materialsCommon', function() {
|
||||
it('sets default material values for materialsCommon', function() {
|
||||
var options = clone(defaultOptions);
|
||||
options.materialsCommon = true;
|
||||
|
||||
var gltf = createGltf(boxObjData);
|
||||
var ambient = gltf.materials.Material.extensions.KHR_materials_common.values.ambient;
|
||||
setDefaultMaterial(boxObjData);
|
||||
|
||||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,7 +6,6 @@ var os = require('os');
|
||||
var path = require('path');
|
||||
var Promise = require('bluebird');
|
||||
var obj2gltf = require('../../lib/obj2gltf');
|
||||
var writeUris = require('../../lib/writeUris');
|
||||
|
||||
var RuntimeError = Cesium.RuntimeError;
|
||||
|
||||
@ -22,8 +21,8 @@ describe('obj2gltf', function() {
|
||||
expect(obj2gltf._getTempDirectory()).toContain(os.tmpdir());
|
||||
tempDirectory = path.join(os.tmpdir(), 'testPath');
|
||||
spyOn(obj2gltf, '_getTempDirectory').and.returnValue(tempDirectory);
|
||||
spyOn(obj2gltf, '_outputJson');
|
||||
spyOn(writeUris, '_outputFile');
|
||||
spyOn(fsExtra, 'outputJson');
|
||||
spyOn(fsExtra, 'outputFile');
|
||||
spyOn(fsExtra, 'remove');
|
||||
});
|
||||
|
||||
@ -100,7 +99,7 @@ describe('obj2gltf', function() {
|
||||
textureCompressionOptions : textureCompressionOptions,
|
||||
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();
|
||||
});
|
||||
|
||||
@ -119,7 +118,7 @@ describe('obj2gltf', function() {
|
||||
};
|
||||
expect(obj2gltf(objPath, gltfPath, options)
|
||||
.then(function() {
|
||||
expect(obj2gltf._outputJson).toHaveBeenCalled();
|
||||
expect(fsExtra.outputJson).toHaveBeenCalled();
|
||||
expect(GltfPipeline.processJSONToDisk).not.toHaveBeenCalled();
|
||||
}), done).toResolve();
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
//This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/addDefaultMatchers.js
|
||||
/*global define*/
|
||||
/*jshint unused:false*/
|
||||
/*eslint strict: ["error", "function"]*/
|
||||
/*eslint-env amd*/
|
||||
/*eslint-disable no-unused-vars*/
|
||||
define([
|
||||
'./equals',
|
||||
'Cesium/Core/defined',
|
||||
|
@ -1,4 +1,5 @@
|
||||
/*global define*/
|
||||
/*eslint strict: ["error", "function"]*/
|
||||
/*eslint-env amd*/
|
||||
define([
|
||||
'./addDefaultMatchers',
|
||||
'./equalsMethodEqualityTester'
|
||||
|
@ -1,5 +1,6 @@
|
||||
//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([
|
||||
'Cesium/Core/FeatureDetection'
|
||||
], function(
|
||||
|
@ -1,5 +1,6 @@
|
||||
//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([
|
||||
'Cesium/Core/defined'
|
||||
], function(
|
||||
|
Loading…
x
Reference in New Issue
Block a user