Skip to content

Commit

Permalink
Merge branch 'master' into duplicate-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Mar 3, 2020
2 parents 67f8e54 + 176827d commit 1d1990e
Show file tree
Hide file tree
Showing 20 changed files with 693 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ clone_depth: 50

environment:
matrix:
- nodejs_version: "8"
- nodejs_version: "10"

install:
# Get the latest stable version of Node.js
Expand Down
8 changes: 0 additions & 8 deletions .idea/encodings.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/gltf-pipeline.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/jsLibraryMappings.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ os:
language: node_js

node_js:
- "8"
- "10"

script:
- npm run eslint
Expand All @@ -14,4 +14,4 @@ script:
after_success:
## We only need to run coveralls for one node version (doesn't matter which one).
## We also ignore publishing failures, since restarting an existing travis build would otherwise break.
- if node --version | grep -q ^v8 ; npm run coverage && npm run coveralls; fi
- npm run coverage && npm run coveralls;
112 changes: 62 additions & 50 deletions CHANGES.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2015-2017 Richard Lee, Analytical Graphics, Inc., and Contributors
Copyright 2015-2020 Richard Lee, Cesium GS, Inc., and Contributors

Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -188,7 +188,7 @@ Copyright 2015-2017 Richard Lee, Analytical Graphics, Inc., and Contributors
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2015-2017 Richard Lee, Analytical Graphics, Inc., and Contributors
Copyright 2015-2020 Richard Lee, Cesium GS, 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.
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# glTF Pipeline

[![License](https://img.shields.io/:license-apache-blue.svg)](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/blob/master/LICENSE.md)
[![Build Status](https://travis-ci.org/AnalyticalGraphicsInc/gltf-pipeline.svg?branch=master)](https://travis-ci.org/AnalyticalGraphicsInc/gltf-pipeline)
[![Coverage Status](https://coveralls.io/repos/AnalyticalGraphicsInc/gltf-pipeline/badge.svg?branch=master)](https://coveralls.io/r/AnalyticalGraphicsInc/gltf-pipeline?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/AnalyticalGraphicsInc/gltf-pipeline.svg)](https://greenkeeper.io/)
[![License](https://img.shields.io/:license-apache-blue.svg)](https://github.com/CesiumGS/gltf-pipeline/blob/master/LICENSE.md)
[![Build Status](https://travis-ci.org/CesiumGS/gltf-pipeline.svg?branch=master)](https://travis-ci.org/CesiumGS/gltf-pipeline)
[![Coverage Status](https://coveralls.io/repos/CesiumGS/gltf-pipeline/badge.svg?branch=master)](https://coveralls.io/r/CesiumGS/gltf-pipeline?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/CesiumGS/gltf-pipeline.svg)](https://greenkeeper.io/)

<p align="center">
<a href="https://www.khronos.org/gltf"><img src="doc/gltf.png" onerror="this.src='gltf.png'"/></a>
</p>

Content pipeline tools for optimizing [glTF](https://www.khronos.org/gltf) assets by [Richard Lee](http://leerichard.net/) and the [Cesium team](http://cesiumjs.org/).
Content pipeline tools for optimizing [glTF](https://www.khronos.org/gltf) assets by [Richard Lee](http://leerichard.net/) and the [Cesium team](https://cesium.com/).

Supports common operations including:
* Converting glTF to glb (and reverse)
Expand Down Expand Up @@ -150,15 +150,15 @@ To run ESLint automatically when a file is saved, run the following and leave it
npm run eslint-watch
```

### Building for Cesium integration
### Building for CesiumJS integration

Some functionality of gltf-pipeline is used by Cesium as a third party library. The necessary files can be generated using:
Some functionality of gltf-pipeline is used by CesiumJS as a third party library. The necessary files can be generated using:

```
npm run build-cesium
```

This will output a portion of the gltf-pipeline code into the `dist/cesium` folder, reformatted into AMD style for use with RequireJS and Cesium in the browser.
This will output a portion of the gltf-pipeline code into the `dist/cesium` folder for use with CesiumJS in the browser.

### Running Test Coverage

Expand All @@ -181,4 +181,4 @@ The documentation will be placed in the `doc` folder.

## Contributions

Pull requests are appreciated! Please use the same [Contributor License Agreement (CLA)](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/CONTRIBUTING.md) and [Coding Guide](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Documentation/Contributors/CodingGuide/README.md) used for [Cesium](http://cesiumjs.org/).
Pull requests are appreciated! Please use the same [Contributor License Agreement (CLA)](https://github.com/CesiumGS/cesium/blob/master/CONTRIBUTING.md) and [Coding Guide](https://github.com/CesiumGS/cesium/blob/master/Documentation/Contributors/CodingGuide/README.md) used for [Cesium](https://github.com/CesiumGS/cesium).
1 change: 1 addition & 0 deletions bin/gltf-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const options = {
separate: argv.separate,
separateTextures: argv.separateTextures,
stats: argv.stats,
keepUnusedElements: argv.keepUnusedElements,
name: outputName,
dracoOptions: dracoOptions
};
Expand Down
3 changes: 1 addition & 2 deletions lib/ForEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const Cesium = require('cesium');
const hasExtension = require('./hasExtension');

const defined = Cesium.defined;
const isArray = Cesium.isArray;

module.exports = ForEach;

Expand Down Expand Up @@ -58,7 +57,7 @@ ForEach.object = function(arrayOfObjects, handler) {
*/
ForEach.topLevel = function(gltf, name, handler) {
const gltfProperty = gltf[name];
if (defined(gltfProperty) && !isArray(gltfProperty)) {
if (defined(gltfProperty) && !Array.isArray(gltfProperty)) {
return ForEach.objectLegacy(gltfProperty, handler);
}

Expand Down
135 changes: 135 additions & 0 deletions lib/forEachTextureInMaterial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
'use strict';

const { Check, defined } = require('cesium');
const ForEach = require('./ForEach');

module.exports = forEachTextureInMaterial;

/**
* Calls the provider handler function on each texture used by the material.
* Mimics the behavior of functions in gltf-pipeline ForEach.
* @param {Object} material The glTF material.
* @param {forEachTextureInMaterial~handler} handler Function that is called for each texture in the material.
*/
function forEachTextureInMaterial(material, handler) {
Check.typeOf.object('material', material);
Check.defined('handler', handler);

// Metallic roughness
const pbrMetallicRoughness = material.pbrMetallicRoughness;
if (defined(pbrMetallicRoughness)) {
if (defined(pbrMetallicRoughness.baseColorTexture)) {
const textureInfo = pbrMetallicRoughness.baseColorTexture;
const value = handler(textureInfo.index, textureInfo);
if (defined(value)) {
return value;
}
}
if (defined(pbrMetallicRoughness.metallicRoughnessTexture)) {
const textureInfo = pbrMetallicRoughness.metallicRoughnessTexture;
const value = handler(textureInfo.index, textureInfo);
if (defined(value)) {
return value;
}
}
}

if (defined(material.extensions)) {
// Spec gloss extension
const pbrSpecularGlossiness = material.extensions.KHR_materials_pbrSpecularGlossiness;
if (defined(pbrSpecularGlossiness)) {
if (defined(pbrSpecularGlossiness.diffuseTexture)) {
const textureInfo = pbrSpecularGlossiness.diffuseTexture;
const value = handler(textureInfo.index, textureInfo);
if (defined(value)) {
return value;
}
}
if (defined(pbrSpecularGlossiness.specularGlossinessTexture)) {
const textureInfo = pbrSpecularGlossiness.specularGlossinessTexture;
const value = handler(textureInfo.index, textureInfo);
if (defined(value)) {
return value;
}
}
}

// Materials common extension (may be present in models converted from glTF 1.0)
const materialsCommon = material.extensions.KHR_materials_common;
if (defined(materialsCommon)) {
const diffuse = materialsCommon.values.diffuse;
const ambient = materialsCommon.values.ambient;
const emission = materialsCommon.values.emission;
const specular = materialsCommon.values.specular;
if (defined(diffuse) && defined(diffuse.index)) {
const value = handler(diffuse.index, diffuse);
if (defined(value)) {
return value;
}
}
if (defined(ambient) && defined(ambient.index)) {
const value = handler(ambient.index, ambient);
if (defined(value)) {
return value;
}
}
if (defined(emission) && defined(emission.index)) {
const value = handler(emission.index, emission);
if (defined(value)) {
return value;
}
}
if (defined(specular) && defined(specular.index)) {
const value = handler(specular.index, specular);
if (defined(value)) {
return value;
}
}
}
}

// KHR_techniques_webgl extension
const value = ForEach.materialValue(material, function (materialValue) {
if (defined(materialValue.index)) {
const value = handler(materialValue.index, materialValue);
if (defined(value)) {
return value;
}
}
});
if (defined(value)) {
return value;
}

// Top level textures
if (defined(material.emissiveTexture)) {
const textureInfo = material.emissiveTexture;
const value = handler(textureInfo.index, textureInfo);
if (defined(value)) {
return value;
}
}

if (defined(material.normalTexture)) {
const textureInfo = material.normalTexture;
const value = handler(textureInfo.index, textureInfo);
if (defined(value)) {
return value;
}
}

if (defined(material.occlusionTexture)) {
const textureInfo = material.occlusionTexture;
const value = handler(textureInfo.index, textureInfo);
if (defined(value)) {
return value;
}
}
}

/**
* Function that is called for each texture in the material. If this function returns a value the for each stops and returns that value.
* @callback forEachTextureInMaterial~handler
* @param {Number} The texture index.
* @param {Object} The texture info object.
*/
3 changes: 1 addition & 2 deletions lib/removeExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const ForEach = require('./ForEach');
const removeExtensionsUsed = require('./removeExtensionsUsed');

const defined = Cesium.defined;
const isArray = Cesium.isArray;

module.exports = removeExtension;

Expand Down Expand Up @@ -37,7 +36,7 @@ function removeCesiumRTC(gltf) {
}

function removeExtensionAndTraverse(object, extension) {
if (isArray(object)) {
if (Array.isArray(object)) {
const length = object.length;
for (let i = 0; i < length; ++i) {
removeExtensionAndTraverse(object[i], extension);
Expand Down
Loading

0 comments on commit 1d1990e

Please sign in to comment.