Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version #191

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a5f1ad8
Added updateVersion stage as well as some refactoring
lasalvavida Dec 5, 2016
74c6635
Merge branch 'master' of https://github.com/AnalyticalGraphicsInc/glt…
lasalvavida Dec 5, 2016
b4ff281
Split out into multiple functions
lasalvavida Dec 14, 2016
96160e5
Merge branch 'master' of https://github.com/AnalyticalGraphicsInc/glt…
lasalvavida Dec 14, 2016
318d2b8
Cleaned up a few failing tests
lasalvavida Dec 14, 2016
77cd995
Added new upgrades to specs
lasalvavida Dec 14, 2016
6478c98
Application specific parameters are prefixed with underscores
lasalvavida Dec 14, 2016
1ef43e3
Merge branch 'master' of github.com:AnalyticalGraphicsInc/gltf-pipeli…
Jan 17, 2017
cf697a9
Merge branch 'updateVersion' of github.com:AnalyticalGraphicsInc/gltf…
Jan 17, 2017
a6db842
Migrated changes back from cesium
Jan 17, 2017
439f0fa
Merge branch 'master' of github.com:AnalyticalGraphicsInc/gltf-pipeli…
Jan 25, 2017
611d148
Merge branch 'cleanup-add-defaults' of github.com:AnalyticalGraphicsI…
Jan 25, 2017
e882790
Changed 1.1 to 2.0
Jan 25, 2017
d2cb44c
Merge branch 'master' of github.com:AnalyticalGraphicsInc/gltf-pipeli…
Jan 25, 2017
e88fd50
Lots of 1.0->2.0 changes in pipeline stages
Jan 25, 2017
f2557af
Tweaks from model generation
Jan 26, 2017
3d35c21
Generate default material
Jan 26, 2017
7f8ad7c
Add updateVersion to buildForCesium
Jan 26, 2017
ed61ae7
Select default scene
Jan 26, 2017
7ee3137
A few more small changes
Jan 26, 2017
7b63d22
Add removePipelineExtras to cesium build
Jan 26, 2017
a76c503
kmc fixes
Jan 26, 2017
d8337e1
Build global cesium include
Jan 26, 2017
9bb2d3c
Update
Jan 26, 2017
01b3140
Update CHANGES.md
Jan 26, 2017
3bc06ba
Added two more update functions
Jan 26, 2017
6d58407
Update CHANGES.md
pjcozzi Jan 26, 2017
0d6e895
Strip version numbers when guessing if invalid
Jan 27, 2017
99c98e2
Merge branch 'updateVersion' of github.com:AnalyticalGraphicsInc/gltf…
Jan 27, 2017
843a480
WIP Array-based Traversal
Feb 14, 2017
9f4b12b
More WIP changes
Feb 14, 2017
dee1009
Removed combineMeshes -> nodes only have a singular mesh now
Feb 14, 2017
c9f79c4
Merge branch 'master' of github.com:AnalyticalGraphicsInc/gltf-pipeli…
Feb 15, 2017
2ac3bfd
Operator -> operate
Feb 15, 2017
2ec8545
combineNodes, removeUnused and dagToTree traversal changes
Feb 15, 2017
29e21f2
More WIP
Feb 15, 2017
9ad94f3
Bulk WIP changes for traversal
lasalvavida Feb 17, 2017
f952bc0
Merge branch 'master' of https://github.com/AnalyticalGraphicsInc/glt…
lasalvavida Mar 3, 2017
4c884d5
Fixed a few more failing tests
lasalvavida Mar 3, 2017
13aa73d
Removed findUsedIds
lasalvavida Mar 10, 2017
b5d8002
WIP, switching workspaces
lasalvavida Mar 20, 2017
6427738
WIP, pretty much just AO left
Mar 21, 2017
af0a51a
Fixed a few more tests
Mar 21, 2017
a4a0331
All tests pass
Mar 21, 2017
94ee8e5
Removed riggedSimpleUnoptimized
Mar 21, 2017
d75085e
Delete generateTangentsBitangents models
Mar 21, 2017
37b97c0
Merge branch 'master' of github.com:AnalyticalGraphicsInc/gltf-pipeli…
Mar 21, 2017
9fc99cc
Don't look for slots in array, just append
Mar 21, 2017
d172439
Small fixes from testing
Mar 21, 2017
d4ccb41
More fixes
Mar 21, 2017
edee467
A few test fixes and byteStride -> bufferView
Mar 21, 2017
2e7519e
A few more test fixes
Mar 21, 2017
684c272
Missed a function
Mar 21, 2017
d426433
Removed vestigial byteStride references
Mar 21, 2017
a35e5f7
Some fixes from cesium changes
Mar 22, 2017
7492f57
Fixed cesium dependency list
Mar 22, 2017
ab6daee
Fixed some plurality issues
Apr 2, 2017
34d1c67
Add KHR_technique_webgl extensions if there are techniques
Apr 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Change Log
* Fixed a bug in `addPipelineExtras` that made it try to add extras to null objects.
* Expose `triangleAxisAlignedBoundingBoxOverlap`, an implementation of Tomas Akenine-Möller algorithm for determining if a triangle overlaps an axis aligned bounding box.
* Merged [gltf-statistics](https://github.com/AnalyticalGraphicsInc/gltf-statistics) as a stage in the pipeline.
* Added `updateVersion` stage for patching glTF `0.8` -> `1.0` changes; `addDefaults` no longer calls `processModelMaterialsCommon`. [#223](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/223)
* Added `updateVersion` stage for upgrading the glTF version of an asset, including upgrading from `1.0` to `2.0`. [#223](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/223)
* All pipeline stages now operator on glTF `2.0` assets.
* `addDefaults` no longer automatically upgrades glTF `0.8` to `1.0`.

### 0.1.0-alpha10 - 2017-01-10
* Added `tangentsBitangents` generation option
Expand Down
20 changes: 13 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,17 @@ function amdify(source, subDependencyMapping) {
paths.push(requireMapping[variable]);
}
}
var definePathsHeader = '\'' + paths.join('\',\n \'') + '\'';
var defineVariablesHeader = variables.join(',\n ');
var defineHeader = '/*global define*/\n' +
'define([\n' +
' ' + definePathsHeader + '\n' +
' ], function(\n' +
' ' + defineVariablesHeader + ') {\n ';
'define([], function() {\n ';
if (paths.length > 0) {
var definePathsHeader = '\'' + paths.join('\',\n \'') + '\'';
var defineVariablesHeader = variables.join(',\n ');
defineHeader = '/*global define*/\n' +
'define([\n' +
' ' + definePathsHeader + '\n' +
' ], function(\n' +
' ' + defineVariablesHeader + ') {\n ';
}
var defineFooter = '\n});\n';
if (defined(returnValue)) {
defineFooter = '\n return ' + returnValue + ';' + defineFooter;
Expand All @@ -196,7 +200,9 @@ gulp.task('build-cesium', function () {
'numberOfComponentsForType.js',
'parseBinaryGltf.js',
'processModelMaterialsCommon.js',
'techniqueParameterForSemantic.js'
'removePipelineExtras.js',
'techniqueParameterForSemantic.js',
'updateVersion.js'
];
var subDependencyMapping = {
cesium : {
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
AccessorReader : require('./lib/AccessorReader'),
addCesiumRTC : require('./lib/addCesiumRTC'),
addDefaults : require('./lib/addDefaults'),
addExtensionsRequired : require('./lib/addExtensionsRequired'),
addExtensionsUsed : require('./lib/addExtensionsUsed'),
addPipelineExtras : require('./lib/addPipelineExtras'),
bakeAmbientOcclusion : require('./lib/bakeAmbientOcclusion'),
Expand Down Expand Up @@ -39,6 +40,7 @@ module.exports = {
removeUnusedVertices : require('./lib/removeUnusedVertices'),
triangleAxisAlignedBoundingBoxOverlap : require('./lib/triangleAxisAlignedBoundingBoxOverlap'),
uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers'),
updateVersion : require('./lib/updateVersion'),
writeAccessor : require('./lib/writeAccessor'),
writeBinaryGltf : require('./lib/writeBinaryGltf'),
writeBufferComponent : require('./lib/writeBufferComponent'),
Expand Down
49 changes: 33 additions & 16 deletions lib/RemoveUnusedProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ RemoveUnusedProperties.removeNodes = function(gltf) {
nodeStack.push(child);
}
}
var skeletons = nodes[node].skeletons;
if (defined(skeletons)) {
var skeletonsLength = skeletons.length;
for (var k = 0; k < skeletonsLength; k++) {
var skeleton = skeletons[k];
nodeStack.push(skeleton);
}
}
}
}
}
Expand Down Expand Up @@ -191,13 +199,13 @@ RemoveUnusedProperties.removeAccessors = function(gltf) {
if (defined(animations)) {
for (var animationId in animations) {
if (animations.hasOwnProperty(animationId)) {
var parameters = animations[animationId].parameters;
if (defined(parameters)) {
for (var parameterId in parameters) {
if (parameters.hasOwnProperty(parameterId)) {
var animationAccessorId = parameters[parameterId];
usedAccessorIds[animationAccessorId] = true;
}
var animation = animations[animationId];
var samplers = animation.samplers;
for (var samplerId in samplers) {
if (samplers.hasOwnProperty(samplerId)) {
var sampler = samplers[samplerId];
usedAccessorIds[sampler.input] = true;
usedAccessorIds[sampler.output] = true;
}
}
}
Expand Down Expand Up @@ -268,16 +276,23 @@ RemoveUnusedProperties.removeTextures = function(gltf) {
var techniques = gltf.techniques;

// Build hash of used textures by iterating through materials and techniques
var i;
var values;
var valueLength;
var value;
if (defined(materials)) {
for (var materialId in materials) {
if (materials.hasOwnProperty(materialId)) {
if (defined(materials[materialId].values)) {
var values = materials[materialId].values;
values = materials[materialId].values;
for (var valueId in values) {
if (values.hasOwnProperty(valueId)) {
if (typeof values[valueId] === 'string') {
var materialTextureId = values[valueId];
usedTextureIds[materialTextureId] = true;
value = values[valueId];
valueLength = value.length;
for (i = 0; i < valueLength; i++) {
if (typeof value[i] === 'string') {
usedTextureIds[value[i]] = true;
}
}
}
}
Expand All @@ -292,11 +307,13 @@ RemoveUnusedProperties.removeTextures = function(gltf) {
var parameters = techniques[techniqueId].parameters;
for (var parameterId in parameters) {
if (parameters.hasOwnProperty(parameterId)) {
if (defined(parameters[parameterId].value)) {
var value = parameters[parameterId].value;
if (typeof value === 'string') {
var techniqueTextureId = value;
usedTextureIds[techniqueTextureId] = true;
value = parameters[parameterId].value;
if (defined(value)) {
valueLength = value.length;
for (i = 0; i < valueLength; i++) {
if (typeof value[i] === 'string') {
usedTextureIds[value[i]] = true;
}
}
}
}
Expand Down
60 changes: 53 additions & 7 deletions lib/addDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var gltfTemplate = {
animations : {
'*' : {
channels : [],
parameters : {},
samplers : {
'*' : {
interpolation : 'LINEAR'
Expand All @@ -30,7 +29,7 @@ var gltfTemplate = {
premultipliedAlpha : false,
profile : {
api : 'WebGL',
version : '1.0.3'
version : '1.0'
}
},
buffers : {
Expand Down Expand Up @@ -158,9 +157,7 @@ var gltfTemplate = {
attributes: {},
uniforms: {},
states: {
'*': {
enable: []
}
enable: []
}
}
},
Expand All @@ -172,7 +169,8 @@ var gltfTemplate = {
type: WebGLConstants.UNSIGNED_BYTE
}
},
extensionsUsed : []
extensionsUsed : [],
extensionsRequired : []
};

function addDefaultsFromTemplate(object, template) {
Expand Down Expand Up @@ -221,6 +219,14 @@ function addDefaultsFromTemplate(object, template) {
}
}

var defaultMaterial = {
values : {
emission : [
0.5, 0.5, 0.5, 1.0
]
}
};

var defaultTechnique = {
attributes : {
a_position : 'position'
Expand Down Expand Up @@ -268,6 +274,7 @@ var defaultVertexShader = {
type : WebGLConstants.VERTEX_SHADER,
extras : {
_pipeline : {
extension : '.vert',
source : '' +
'precision highp float;\n' +
'\n' +
Expand All @@ -288,7 +295,7 @@ var defaultFragmentShader = {
type : WebGLConstants.FRAGMENT_SHADER,
extras : {
_pipeline : {
extension : '.vert',
extension: '.frag',
source : '' +
'precision highp float;\n' +
'\n' +
Expand All @@ -302,6 +309,30 @@ var defaultFragmentShader = {
}
};

function addDefaultMaterial(gltf) {
var meshes = gltf.meshes;

var defaultMaterialId;

for (var meshId in meshes) {
if (meshes.hasOwnProperty(meshId)) {
var mesh = meshes[meshId];
var primitives = mesh.primitives;
var primitivesLength = primitives.length;
for (var i = 0; i < primitivesLength; i++) {
var primitive = primitives[i];
if (!defined(primitive.material)) {
if (!defined(defaultMaterialId)) {
defaultMaterialId = getUniqueId(gltf, 'defaultMaterial');
gltf.materials[defaultMaterialId] = clone(defaultMaterial, true);
}
primitive.material = defaultMaterialId;
}
}
}
}
}

function addDefaultTechnique(gltf) {
var materials = gltf.materials;
var techniques = gltf.techniques;
Expand Down Expand Up @@ -394,6 +425,19 @@ function enableDiffuseTransparency(gltf) {
}
}

function selectDefaultScene(gltf) {
var scenes = gltf.scenes;

if (!defined(gltf.scene)) {
for (var sceneId in scenes) {
if (scenes.hasOwnProperty(sceneId)) {
gltf.scene = sceneId;
break;
}
}
}
}

function optimizeForCesium(gltf) {
// Give the diffuse uniform a semantic to support color replacement in 3D Tiles
var techniques = gltf.techniques;
Expand Down Expand Up @@ -424,8 +468,10 @@ function optimizeForCesium(gltf) {
function addDefaults(gltf, options) {
options = defaultValue(options, {});
addDefaultsFromTemplate(gltf, gltfTemplate);
addDefaultMaterial(gltf);
addDefaultTechnique(gltf);
enableDiffuseTransparency(gltf);
selectDefaultScene(gltf);
if (options.optimizeForCesium) {
optimizeForCesium(gltf);
}
Expand Down
26 changes: 26 additions & 0 deletions lib/addExtensionsRequired.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
var Cesium = require('cesium');
var addExtensionsUsed = require('./addExtensionsUsed');

var defined = Cesium.defined;

module.exports = addExtensionsRequired;

/**
* Adds an extension to gltf.extensionsRequired if it does not already exist.
* Initializes extensionsRequired if it is not defined.
*
* @param {Object} gltf A javascript object containing a glTF asset.
* @param {String} extension The extension to add.
*/
function addExtensionsRequired(gltf, extension) {
var extensionsRequired = gltf.extensionsRequired;
if (!defined(extensionsRequired)) {
extensionsRequired = [];
gltf.extensionsRequired = extensionsRequired;
}
if (extensionsRequired.indexOf(extension) < 0) {
extensionsRequired.push(extension);
}
addExtensionsUsed(gltf, extension);
}
49 changes: 18 additions & 31 deletions lib/addPipelineExtras.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ module.exports = addPipelineExtras;
var exceptions = {
attributes: true,
uniforms: true,
extensions: true
extensions: true,
values: true,
samplers: true
};

/**
* Adds extras._pipeline to each object that can have extras in the glTF asset.
*
Expand All @@ -20,47 +23,31 @@ var exceptions = {
*/
function addPipelineExtras(gltf) {
var objectStack = [];
gltf.extras = defaultValue(gltf.extras, {});
gltf.extras._pipeline = defaultValue(gltf.extras._pipeline, {});
for (var rootObjectId in gltf) {
if (gltf.hasOwnProperty(rootObjectId)) {
var rootObject = gltf[rootObjectId];
for (var topLevelObjectId in rootObject) {
if (rootObject.hasOwnProperty(topLevelObjectId)) {
var topLevelObject = rootObject[topLevelObjectId];
if (defined(topLevelObject) && typeof topLevelObject === 'object') {
objectStack.push(topLevelObject);
}
}
}
objectStack.push(rootObject);
}
}
if (defined(gltf.asset)) {
objectStack.push(gltf.asset);
}
while (objectStack.length > 0) {
var object = objectStack.pop();
if (Array.isArray(object)) {
var length = object.length;
for (var i = 0; i < length; i++) {
var item = object[i];
if (defined(item) && typeof item === 'object') {
objectStack.push(item);
}
}
} else {
object.extras = defaultValue(object.extras, {});
object.extras._pipeline = defaultValue(object.extras._pipeline, {});
for (var propertyId in object) {
if (object.hasOwnProperty(propertyId)) {
var property = object[propertyId];
if (defined(property) && typeof property === 'object' && propertyId !== 'extras' && !exceptions[propertyId]) {
objectStack.push(property);
for (var propertyId in object) {
if (object.hasOwnProperty(propertyId)) {
var property = object[propertyId];
if (defined(property) && typeof property === 'object' && propertyId !== 'extras') {
objectStack.push(property);
if (!exceptions[propertyId] && !Array.isArray(property)) {
property.extras = defaultValue(property.extras, {});
property.extras._pipeline = defaultValue(property.extras._pipeline, {});
}
}
}
}
}

gltf.extras = defaultValue(gltf.extras, {});
gltf.extras._pipeline = defaultValue(gltf.extras._pipeline, {});
gltf.asset = defaultValue(gltf.asset, {});
gltf.asset.extras = defaultValue(gltf.asset.extras, {});
gltf.asset.extras._pipeline = defaultValue(gltf.asset.extras._pipeline, {});
return gltf;
}
4 changes: 2 additions & 2 deletions lib/generateModelMaterialsCommon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Cesium = require('cesium');
var addExtensionsUsed = require('./addExtensionsUsed');
var addExtensionsRequired = require('./addExtensionsRequired');

var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;
Expand All @@ -24,7 +24,7 @@ function generateModelMaterialsCommon(gltf, kmcOptions) {
kmcOptions = defaultValue(kmcOptions, {});
kmcOptions.doubleSided = defaultValue(kmcOptions.doubleSided, false);
kmcOptions.technique = defaultValue(kmcOptions.technique, 'PHONG');
addExtensionsUsed(gltf, 'KHR_materials_common');
addExtensionsRequired(gltf, 'KHR_materials_common');
var materialsCommon;
var materials = gltf.materials;
var nodes = gltf.nodes;
Expand Down
Loading