From 5524a73ae09313dac39cf731f6e07bb4dc48e8ba Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 10 Aug 2016 13:41:42 -0400 Subject: [PATCH 01/21] Export all lib js as index.js --- gulpfile.js | 30 ++++++++++++++++++++ index.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++---- package.json | 1 + 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 313aa317..07806148 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,10 @@ 'use strict'; var Cesium = require('cesium'); +var Promise = require('bluebird'); var child_process = require('child_process'); var fsExtra = require('fs-extra'); +var glob = require('glob'); var gulp = require('gulp'); var gulpJshint = require('gulp-jshint'); var Jasmine = require('jasmine'); @@ -15,6 +17,9 @@ var yargs = require('yargs'); var defined = Cesium.defined; var argv = yargs.argv; +var fsWriteFile = Promise.promisify(fsExtra.writeFile); +var globPromise = Promise.promisify(glob); + // Add third-party node module binaries to the system path // since some tasks need to call them directly. var environmentSeparator = process.platform === 'win32' ? ';' : ':'; @@ -80,6 +85,31 @@ gulp.task('coverage', function () { open('coverage/lcov-report/index.html'); }); +/** + * Regenerates index.js to export the contents of the 'lib/' directory + */ +gulp.task('regenerate-index', function() { + var indexJS = 'module.exports = {\n'; + var first = false; + globPromise('lib/**/*.js', undefined) + .then(function(files) { + return Promise.map(files, function (fileName) { + var exportName = path.basename(fileName, '.js'); + if (!first) { + first = true; + } else { + indexJS += ',\n'; + } + indexJS += ' ' + exportName + ' : require(\'./' + fileName + '\')'; + }); + }) + .then(function() { + indexJS += '\n};'; + return fsWriteFile('index.js', indexJS); + }); + +}); + function copyModule(module) { var tsName = module + '.d.ts'; var srcUrl = 'https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/' + module + '/' + tsName; diff --git a/index.js b/index.js index e87993c9..05ecb0c5 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,73 @@ module.exports = { - gltfPipeline : require('./lib/gltfPipeline'), - readGltf : require('./lib/readGltf'), - writeBinaryGltf : require('./lib/writeBinaryGltf'), - writeGltf : require('./lib/writeGltf') -}; + AccessorReader : require('./lib/AccessorReader.js'), + addCesiumRTC : require('./lib/addCesiumRTC.js'), + addDefaults : require('./lib/addDefaults.js'), + addExtensionsUsed : require('./lib/addExtensionsUsed.js'), + addPipelineExtras : require('./lib/addPipelineExtras.js'), + bakeAmbientOcclusion : require('./lib/bakeAmbientOcclusion.js'), + byteLengthForComponentType : require('./lib/byteLengthForComponentType.js'), + cacheOptimization : require('./lib/cacheOptimization.js'), + cesiumGeometryToGltfPrimitive : require('./lib/cesiumGeometryToGltfPrimitive.js'), + combineMeshes : require('./lib/combineMeshes.js'), + combineNodes : require('./lib/combineNodes.js'), + combinePrimitives : require('./lib/combinePrimitives.js'), + compressIntegerAccessors : require('./lib/compressIntegerAccessors.js'), + compressTextureCoordinates : require('./lib/compressTextureCoordinates.js'), + convertDagToTree : require('./lib/convertDagToTree.js'), + createAccessorUsageTables : require('./lib/createAccessorUsageTables.js'), + encodeImages : require('./lib/encodeImages.js'), + findAccessorMinMax : require('./lib/findAccessorMinMax.js'), + findUsedIds : require('./lib/findUsedIds.js'), + generateNormals : require('./lib/generateNormals.js'), + GeometryMath : require('./lib/GeometryMath.js'), + getAccessorByteStride : require('./lib/getAccessorByteStride.js'), + getAccessorsForSemantic : require('./lib/getAccessorsForSemantic.js'), + getBinaryGltf : require('./lib/getBinaryGltf.js'), + getUniqueId : require('./lib/getUniqueId.js'), + gltfPipeline : require('./lib/gltfPipeline.js'), + gltfPrimitiveToCesiumGeometry : require('./lib/gltfPrimitiveToCesiumGeometry.js'), + isDataUri : require('./lib/isDataUri.js'), + loadGltfUris : require('./lib/loadGltfUris.js'), + mergeBuffers : require('./lib/mergeBuffers.js'), + mergeDuplicateAccessors : require('./lib/mergeDuplicateAccessors.js'), + mergeDuplicateVertices : require('./lib/mergeDuplicateVertices.js'), + modelMaterialsCommon : require('./lib/modelMaterialsCommon.js'), + NodeHelpers : require('./lib/NodeHelpers.js'), + numberOfComponentsForType : require('./lib/numberOfComponentsForType.js'), + octEncodeNormals : require('./lib/octEncodeNormals.js'), + OptimizationStatistics : require('./lib/OptimizationStatistics.js'), + packArray : require('./lib/packArray.js'), + parseBinaryGltf : require('./lib/parseBinaryGltf.js'), + quantizeAttributes : require('./lib/quantizeAttributes.js'), + readAccessor : require('./lib/readAccessor.js'), + readBufferComponentType : require('./lib/readBufferComponentType.js'), + readGltf : require('./lib/readGltf.js'), + removeDuplicatePrimitives : require('./lib/removeDuplicatePrimitives.js'), + removeObject : require('./lib/removeObject.js'), + removePipelineExtras : require('./lib/removePipelineExtras.js'), + removeUnused : require('./lib/removeUnused.js'), + removeUnusedAccessors : require('./lib/removeUnusedAccessors.js'), + removeUnusedBuffers : require('./lib/removeUnusedBuffers.js'), + removeUnusedBufferViews : require('./lib/removeUnusedBufferViews.js'), + removeUnusedCameras : require('./lib/removeUnusedCameras.js'), + removeUnusedImages : require('./lib/removeUnusedImages.js'), + removeUnusedMaterials : require('./lib/removeUnusedMaterials.js'), + removeUnusedMeshes : require('./lib/removeUnusedMeshes.js'), + removeUnusedNodes : require('./lib/removeUnusedNodes.js'), + removeUnusedPrimitiveAttributes : require('./lib/removeUnusedPrimitiveAttributes.js'), + removeUnusedPrograms : require('./lib/removeUnusedPrograms.js'), + removeUnusedSamplers : require('./lib/removeUnusedSamplers.js'), + removeUnusedShaders : require('./lib/removeUnusedShaders.js'), + removeUnusedSkins : require('./lib/removeUnusedSkins.js'), + removeUnusedTechniques : require('./lib/removeUnusedTechniques.js'), + removeUnusedTextures : require('./lib/removeUnusedTextures.js'), + removeUnusedVertices : require('./lib/removeUnusedVertices.js'), + StaticUniformGrid : require('./lib/StaticUniformGrid.js'), + triangleAxisAlignedBoundingBoxOverlap : require('./lib/triangleAxisAlignedBoundingBoxOverlap.js'), + uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers.js'), + writeAccessor : require('./lib/writeAccessor.js'), + writeBinaryGltf : require('./lib/writeBinaryGltf.js'), + writeBufferComponentType : require('./lib/writeBufferComponentType.js'), + writeGltf : require('./lib/writeGltf.js'), + writeSource : require('./lib/writeSource.js') +}; \ No newline at end of file diff --git a/package.json b/package.json index dc35a1db..d17f4f98 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ }, "devDependencies": { "coveralls": "2.11.9", + "glob": "7.0.5", "gulp": "3.9.1", "gulp-jshint": "2.0.1", "istanbul": "0.4.4", From 863be074ec948e34333dec01bada1bc6579c41f5 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 10 Aug 2016 13:44:07 -0400 Subject: [PATCH 02/21] Updated CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 70347b12..870e68ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ Change Log ### Next Release * cacheOptimization no longer crashes on primitives without indices. [#154](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/154) +* lib/**/*.js is exposed as the Public API via index.js [#153](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/153) ### 0.1.0-alpha3 - 2016-07-25 From 0f6298d3d8b8c202b62230437f622501a862dcc0 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Thu, 11 Aug 2016 13:28:32 -0400 Subject: [PATCH 03/21] All exposed functions have defined headers for API --- index.js | 16 +---- lib/AccessorReader.js | 37 ++++++++++ lib/NodeHelpers.js | 58 +++++++++++++-- lib/addDefaults.js | 98 ++++---------------------- lib/addExtensionsUsed.js | 8 +++ lib/addPipelineExtras.js | 8 ++- lib/bakeAmbientOcclusion.js | 13 ++-- lib/byteLengthForComponentType.js | 1 + lib/cacheOptimization.js | 17 ++++- lib/cesiumGeometryToGltfPrimitive.js | 8 ++- lib/combineMeshes.js | 11 ++- lib/combineNodes.js | 13 +++- lib/compressIntegerAccessors.js | 8 ++- lib/compressTextureCoordinates.js | 6 +- lib/convertDagToTree.js | 8 +++ lib/createAccessorUsageTables.js | 3 + lib/encodeImages.js | 4 +- lib/findAccessorMinMax.js | 8 +++ lib/generateNormals.js | 10 ++- lib/getAccessorByteStride.js | 2 +- lib/getBinaryGltf.js | 8 +++ lib/getUniqueId.js | 8 ++- lib/gltfPipeline.js | 31 ++++++++ lib/isDataUri.js | 1 + lib/loadGltfUris.js | 6 +- lib/mergeBuffers.js | 11 ++- lib/mergeDuplicateAccessors.js | 4 +- lib/mergeDuplicateVertices.js | 4 +- lib/modelMaterialsCommon.js | 76 ++++++++++++++++++++ lib/numberOfComponentsForType.js | 4 +- lib/octEncodeNormals.js | 4 +- lib/packArray.js | 7 ++ lib/parseBinaryGltf.js | 14 +++- lib/readAccessor.js | 10 +-- lib/readBufferComponentType.js | 9 +++ lib/readGltf.js | 7 ++ lib/removeDuplicatePrimitives.js | 12 +++- lib/removePipelineExtras.js | 9 ++- lib/removeUnused.js | 7 ++ lib/removeUnusedAccessors.js | 7 ++ lib/removeUnusedBufferViews.js | 7 ++ lib/removeUnusedBuffers.js | 7 ++ lib/removeUnusedCameras.js | 7 ++ lib/removeUnusedImages.js | 7 ++ lib/removeUnusedMaterials.js | 11 ++- lib/removeUnusedMeshes.js | 11 ++- lib/removeUnusedNodes.js | 11 ++- lib/removeUnusedPrimitiveAttributes.js | 4 +- lib/removeUnusedPrograms.js | 7 ++ lib/removeUnusedSamplers.js | 7 ++ lib/removeUnusedShaders.js | 15 ++-- lib/removeUnusedSkins.js | 7 ++ lib/removeUnusedTechniques.js | 7 ++ lib/removeUnusedTextures.js | 11 ++- lib/removeUnusedVertices.js | 6 +- lib/uninterleaveAndPackBuffers.js | 5 +- lib/writeAccessor.js | 7 ++ lib/writeBinaryGltf.js | 11 +++ lib/writeBufferComponentType.js | 8 +++ lib/writeGltf.js | 11 +++ lib/writeSource.js | 2 +- 61 files changed, 575 insertions(+), 170 deletions(-) diff --git a/index.js b/index.js index 05ecb0c5..93fe2bca 100644 --- a/index.js +++ b/index.js @@ -7,35 +7,25 @@ module.exports = { bakeAmbientOcclusion : require('./lib/bakeAmbientOcclusion.js'), byteLengthForComponentType : require('./lib/byteLengthForComponentType.js'), cacheOptimization : require('./lib/cacheOptimization.js'), - cesiumGeometryToGltfPrimitive : require('./lib/cesiumGeometryToGltfPrimitive.js'), combineMeshes : require('./lib/combineMeshes.js'), combineNodes : require('./lib/combineNodes.js'), - combinePrimitives : require('./lib/combinePrimitives.js'), compressIntegerAccessors : require('./lib/compressIntegerAccessors.js'), compressTextureCoordinates : require('./lib/compressTextureCoordinates.js'), convertDagToTree : require('./lib/convertDagToTree.js'), - createAccessorUsageTables : require('./lib/createAccessorUsageTables.js'), encodeImages : require('./lib/encodeImages.js'), findAccessorMinMax : require('./lib/findAccessorMinMax.js'), - findUsedIds : require('./lib/findUsedIds.js'), generateNormals : require('./lib/generateNormals.js'), - GeometryMath : require('./lib/GeometryMath.js'), getAccessorByteStride : require('./lib/getAccessorByteStride.js'), - getAccessorsForSemantic : require('./lib/getAccessorsForSemantic.js'), getBinaryGltf : require('./lib/getBinaryGltf.js'), getUniqueId : require('./lib/getUniqueId.js'), gltfPipeline : require('./lib/gltfPipeline.js'), - gltfPrimitiveToCesiumGeometry : require('./lib/gltfPrimitiveToCesiumGeometry.js'), - isDataUri : require('./lib/isDataUri.js'), loadGltfUris : require('./lib/loadGltfUris.js'), mergeBuffers : require('./lib/mergeBuffers.js'), mergeDuplicateAccessors : require('./lib/mergeDuplicateAccessors.js'), mergeDuplicateVertices : require('./lib/mergeDuplicateVertices.js'), - modelMaterialsCommon : require('./lib/modelMaterialsCommon.js'), NodeHelpers : require('./lib/NodeHelpers.js'), numberOfComponentsForType : require('./lib/numberOfComponentsForType.js'), octEncodeNormals : require('./lib/octEncodeNormals.js'), - OptimizationStatistics : require('./lib/OptimizationStatistics.js'), packArray : require('./lib/packArray.js'), parseBinaryGltf : require('./lib/parseBinaryGltf.js'), quantizeAttributes : require('./lib/quantizeAttributes.js'), @@ -43,7 +33,6 @@ module.exports = { readBufferComponentType : require('./lib/readBufferComponentType.js'), readGltf : require('./lib/readGltf.js'), removeDuplicatePrimitives : require('./lib/removeDuplicatePrimitives.js'), - removeObject : require('./lib/removeObject.js'), removePipelineExtras : require('./lib/removePipelineExtras.js'), removeUnused : require('./lib/removeUnused.js'), removeUnusedAccessors : require('./lib/removeUnusedAccessors.js'), @@ -62,12 +51,9 @@ module.exports = { removeUnusedTechniques : require('./lib/removeUnusedTechniques.js'), removeUnusedTextures : require('./lib/removeUnusedTextures.js'), removeUnusedVertices : require('./lib/removeUnusedVertices.js'), - StaticUniformGrid : require('./lib/StaticUniformGrid.js'), - triangleAxisAlignedBoundingBoxOverlap : require('./lib/triangleAxisAlignedBoundingBoxOverlap.js'), uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers.js'), writeAccessor : require('./lib/writeAccessor.js'), writeBinaryGltf : require('./lib/writeBinaryGltf.js'), writeBufferComponentType : require('./lib/writeBufferComponentType.js'), - writeGltf : require('./lib/writeGltf.js'), - writeSource : require('./lib/writeSource.js') + writeGltf : require('./lib/writeGltf.js') }; \ No newline at end of file diff --git a/lib/AccessorReader.js b/lib/AccessorReader.js index fb0b8168..7ecefbd5 100644 --- a/lib/AccessorReader.js +++ b/lib/AccessorReader.js @@ -10,6 +10,14 @@ var writeBufferComponentType = require('./writeBufferComponentType'); module.exports = AccessorReader; +/** + * Reads an accessor incrementally. This is useful to keep overhead low when + * memory consumption is important. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} accessor The accessor object from glTF to read . + * @constructor + */ function AccessorReader(gltf, accessor) { var bufferViews = gltf.bufferViews; var buffers = gltf.buffers; @@ -30,6 +38,14 @@ function AccessorReader(gltf, accessor) { this.source = buffer.extras._pipeline.source; } +/** + * Read data at the current index into components. + * Data will be read into components starting at index 0. + * Components will be grown if the number of components for the accessor is greater than the array size. + * + * @param {Array} components The array to read the data into. + * @returns {Array} components with data written into it. + */ AccessorReader.prototype.read = function(components) { if (this.index >= this.count) { return undefined; @@ -49,6 +65,16 @@ AccessorReader.prototype.read = function(components) { return components; }; +/** + * Write data at the current index into the accessor data. + * Specifying a componentType different from the accessor's componentType can be done for a use case like attribute compression. + * The data is being read, compressed, and then written back as a different, smaller data type. This is done in place + * and then the gaps can be removed using uninterleaveAndPackBuffers. + * + * @param {Array} data The data to write into the accessor. + * @param {Number} [componentType=this.componentType] The component type to use for writing the data. + * @param {Number} [dataOffset=0] Read starting from a different position in the data array. + */ AccessorReader.prototype.write = function(data, componentType, dataOffset) { componentType = defaultValue(componentType, this.componentType); dataOffset = defaultValue(dataOffset, 0); @@ -66,14 +92,25 @@ AccessorReader.prototype.write = function(data, componentType, dataOffset) { } }; +/** + * Get if the AccessorReader is at the end of the accessor data. + * + * @returns {Boolean} true if there is more data to read, false if not. + */ AccessorReader.prototype.hasNext = function() { return this.index < this.count; }; +/** + * Increment AccessorReader.index by one. + */ AccessorReader.prototype.next = function() { this.index++; }; +/** + * Set AccessorReader.index to zero. + */ AccessorReader.prototype.reset = function() { this.index = 0; }; \ No newline at end of file diff --git a/lib/NodeHelpers.js b/lib/NodeHelpers.js index 2003a776..ab783e9f 100644 --- a/lib/NodeHelpers.js +++ b/lib/NodeHelpers.js @@ -35,8 +35,13 @@ function flattenTransform(parameters, node, parent) { node.extras._pipeline.flatTransform = Matrix4.multiply(parentTransform, localTransform, new Matrix4()); } -// computes flattened Matrix4 transforms for every node in the scene -// store these matrices for each node in extras._pipeline.flatTransform +/** + * Computes flattened Matrix4 transforms for every node in the scene. + * Store these matrices for each node in extras._pipeline.flatTransform. + * + * @param {Object} scene The glTF scene to traverse. + * @param {Object} nodes glTF top-level nodes object. + */ function computeFlatTransformScene(scene, nodes) { var rootNodeIDs = scene.nodes; var parameters = { @@ -56,6 +61,16 @@ function addNodeToArray(parameters, node) { } // get all the nodes in a scene + +/** + * Get all the nodes in a scene. + * If resultArray is undefined, a new array will be created. + * + * @param {scene} The glTF scene to traverse. + * @param {Object} nodes glTF top-level nodes object. + * @param {Array} [resultArray] Store the nodes into resultArray. + * @returns {Array} An array of all nodes in the scene. + */ function getAllNodesInScene(scene, nodes, resultArray) { var rootNodeIDs = scene.nodes; if (!defined(resultArray)) { @@ -73,9 +88,16 @@ function getAllNodesInScene(scene, nodes, resultArray) { return resultArray; } -// Perform a stack based iterative depth first traversal on the specified node. -// Apply functionChildParent to all of its children. -// functionChildParent functions take this node and the parent as arguments +/** + * Perform a stack based iterative depth first traversal on the specified node. + * Apply functionChildParent to all of its children. + * functionChildParent has the signature: function(parameters, childNode, parentNode). + * + * @param {Object} rootNode The glTF node to traverse. + * @param {Object} allNodes glTF top-level nodes object. + * @param {Function} functionChildParent Function to apply to the child and parent. + * @param {Object} parameters Parameters to pass as the first argument to functionChildParent. + */ function depthFirstTraversal(rootNode, allNodes, functionChildParent, parameters) { // process the root node functionChildParent(parameters, rootNode); @@ -102,6 +124,15 @@ function depthFirstTraversal(rootNode, allNodes, functionChildParent, parameters } // gets the local matrix of a node, or computes it from TRS + +/** + * Gets the local matrix of a node, or computes it from TRS. + * If result is undefined, creates a new Matrix4. + * + * @param {Object} node glTF node with a transform. + * @param {Matrix4} [result] Store the transform matrix into result. + * @returns {Matrix4} The node transform matrix. + */ function getLocalMatrix4(node, result) { if (!defined(result)) { result = new Matrix4(); @@ -139,8 +170,15 @@ var packedParametersScratch = { primitiveFunction : undefined }; -// Perform an operation on each primitive in a scene. -// PrimitiveFunction should expect primitive, a meshPrimitiveID, some parameters, and the node itself +/** + * Perform an operation on each primitive in a scene. + * primitiveFunction has the signature: function(primitive, meshPrimitiveId, parameters, node). + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} scene The glTF scene to traverse. + * @param {Function} primitiveFunction The function to apply to each primitive. + * @param {Object} parameters Parameters to pass to primitiveFunction. + */ function forEachPrimitiveInScene(gltf, scene, primitiveFunction, parameters) { var rootNodeNames = scene.nodes; var allNodes = gltf.nodes; @@ -176,6 +214,12 @@ function forEachPrimitiveInNode(packedParameters, node) { } } +/** + * Generates a mapping for each meshId to the nodeIds of the nodes that use that mesh. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} An object with meshIds as keys with arrays of corresponding nodeIds as values. + */ function mapMeshesToNodes(gltf) { var meshesToNodes = {}; var nodes = gltf.nodes; diff --git a/lib/addDefaults.js b/lib/addDefaults.js index 44e357ee..9ff51790 100644 --- a/lib/addDefaults.js +++ b/lib/addDefaults.js @@ -1,12 +1,15 @@ 'use strict'; var Cesium = require('cesium'); + var Cartesian3 = Cesium.Cartesian3; var defaultValue = Cesium.defaultValue; var defined = Cesium.defined; var Quaternion = Cesium.Quaternion; var WebGLConstants = Cesium.WebGLConstants; -var modelMaterialsCommon = require('./modelMaterialsCommon'); + +var addExtensionsUsed = require('./addExtensionsUsed'); var findAccessorMinMax = require('./findAccessorMinMax'); +var modelMaterialsCommon = require('./modelMaterialsCommon'); module.exports = addDefaults; @@ -121,82 +124,6 @@ function imageDefaults(gltf) { } } -// TODO: move lightDefaults() for KHR_materials_common elsewhere? -function lightDefaults(gltf) { - if (!defined(gltf.extensions)) { - gltf.extensions = {}; - } - var extensions = gltf.extensions; - - if (!defined(extensions.KHR_materials_common)) { - extensions.KHR_materials_common = {}; - } - var khrMaterialsCommon = extensions.KHR_materials_common; - - if (defined(gltf.lights)) { - // glTF 0.8 backward compatibility - khrMaterialsCommon.lights = gltf.lights; - delete gltf.lights; - } - else if (!defined(khrMaterialsCommon.lights)) { - khrMaterialsCommon.lights = {}; - } - var lights = khrMaterialsCommon.lights; - - for (var name in lights) { - if (lights.hasOwnProperty(name)) { - var light = lights[name]; - if (light.type === 'ambient') { - if (!defined(light.ambient)) { - light.ambient = {}; - } - var ambientLight = light.ambient; - - if (!defined(ambientLight.color)) { - ambientLight.color = [1.0, 1.0, 1.0]; - } - } else if (light.type === 'directional') { - if (!defined(light.directional)) { - light.directional = {}; - } - var directionalLight = light.directional; - - if (!defined(directionalLight.color)) { - directionalLight.color = [1.0, 1.0, 1.0]; - } - } else if (light.type === 'point') { - if (!defined(light.point)) { - light.point = {}; - } - var pointLight = light.point; - - if (!defined(pointLight.color)) { - pointLight.color = [1.0, 1.0, 1.0]; - } - - pointLight.constantAttenuation = defaultValue(pointLight.constantAttenuation, 1.0); - pointLight.linearAttenuation = defaultValue(pointLight.linearAttenuation, 0.0); - pointLight.quadraticAttenuation = defaultValue(pointLight.quadraticAttenuation, 0.0); - } else if (light.type === 'spot') { - if (!defined(light.spot)) { - light.spot = {}; - } - var spotLight = light.spot; - - if (!defined(spotLight.color)) { - spotLight.color = [1.0, 1.0, 1.0]; - } - - spotLight.constantAttenuation = defaultValue(spotLight.constantAttenuation, 1.0); - spotLight.fallOffAngle = defaultValue(spotLight.fallOffAngle, 3.14159265); - spotLight.fallOffExponent = defaultValue(spotLight.fallOffExponent, 0.0); - spotLight.linearAttenuation = defaultValue(spotLight.linearAttenuation, 0.0); - spotLight.quadraticAttenuation = defaultValue(spotLight.quadraticAttenuation, 0.0); - } - } - } -} - function checkIfFloatVec4(value) { if (defined(value) && value.length === 4) { if (typeof(value[0]) === 'number' && @@ -280,14 +207,7 @@ function materialDefaults(gltf, options) { if (!defined(material.technique)) { if (!defined(material.extensions)) { guessExtensionTechnique(gltf, material, options); - - if (!defined(gltf.extensionsUsed)) { - gltf.extensionsUsed = []; - } - var extensionsUsed = gltf.extensionsUsed; - if (extensionsUsed.indexOf('KHR_materials_common') === -1) { - extensionsUsed.push('KHR_materials_common'); - } + addExtensionsUsed(gltf, 'KHR_materials_common'); } } else if (!defined(material.values)) { @@ -584,6 +504,13 @@ function textureDefaults(gltf) { } } +/** + * Adds default glTF values if they don't exist. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} [options={}] + * @returns {Object} The modified glTF. + */ function addDefaults(gltf, options) { options = defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT); @@ -604,7 +531,6 @@ function addDefaults(gltf, options) { bufferViewDefaults(gltf); cameraDefaults(gltf); imageDefaults(gltf); - lightDefaults(gltf); techniqueDefaults(gltf); materialDefaults(gltf, options); meshDefaults(gltf); diff --git a/lib/addExtensionsUsed.js b/lib/addExtensionsUsed.js index 30f91609..0feddbea 100644 --- a/lib/addExtensionsUsed.js +++ b/lib/addExtensionsUsed.js @@ -1,9 +1,17 @@ 'use strict'; var Cesium = require('cesium'); + var defined = Cesium.defined; module.exports = addExtensionsUsed; +/** + * Adds an extension to gltf.extensionsUsed if it does not already exist. + * Initializes extensionsUsed if it is not defined. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {String} extension The extension to add. + */ function addExtensionsUsed(gltf, extension) { var extensionsUsed = gltf.extensionsUsed; if (!defined(extensionsUsed)) { diff --git a/lib/addPipelineExtras.js b/lib/addPipelineExtras.js index 8f6d3beb..780f342e 100755 --- a/lib/addPipelineExtras.js +++ b/lib/addPipelineExtras.js @@ -1,10 +1,16 @@ 'use strict'; var Cesium = require('cesium'); + var defined = Cesium.defined; module.exports = addPipelineExtras; -//Add the pipeline extras object to each glTF object. +/** + * Adds extras._pipeline to each object in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with the added pipeline extras. + */ function addPipelineExtras(gltf) { var reference = { "accessors": { "accessorObject": { "addPipelineExtra": true } }, diff --git a/lib/bakeAmbientOcclusion.js b/lib/bakeAmbientOcclusion.js index 2076b1ef..0bd1e029 100644 --- a/lib/bakeAmbientOcclusion.js +++ b/lib/bakeAmbientOcclusion.js @@ -1,12 +1,6 @@ 'use strict'; var Cesium = require('cesium'); var clone = require('clone'); -var GeometryMath = require('./GeometryMath'); -var getUniqueId = require('./getUniqueId'); -var Jimp = require('jimp'); -var NodeHelpers = require('./NodeHelpers'); -var readAccessor = require('./readAccessor'); -var StaticUniformGrid = require('./StaticUniformGrid'); var baryCentricCoordinates = Cesium.barycentricCoordinates; var Cartesian2 = Cesium.Cartesian2; @@ -23,6 +17,13 @@ var ShaderSource = Cesium.ShaderSource; var WebGLConstants = Cesium.WebGLConstants; var IntersectionTests = Cesium.IntersectionTests; +var GeometryMath = require('./GeometryMath'); +var getUniqueId = require('./getUniqueId'); +var Jimp = require('jimp'); +var NodeHelpers = require('./NodeHelpers'); +var readAccessor = require('./readAccessor'); +var StaticUniformGrid = require('./StaticUniformGrid'); + module.exports = { bakeAmbientOcclusion: bakeAmbientOcclusion, // For unit testing: diff --git a/lib/byteLengthForComponentType.js b/lib/byteLengthForComponentType.js index ca5d0085..afe81611 100644 --- a/lib/byteLengthForComponentType.js +++ b/lib/byteLengthForComponentType.js @@ -1,5 +1,6 @@ 'use strict'; var Cesium = require('cesium'); + var WebGLConstants = Cesium.WebGLConstants; module.exports = byteLengthForComponentType; diff --git a/lib/cacheOptimization.js b/lib/cacheOptimization.js index 5dbea7f0..4ec3e05a 100644 --- a/lib/cacheOptimization.js +++ b/lib/cacheOptimization.js @@ -1,11 +1,13 @@ 'use strict'; -var gltfPrimitiveToCesiumGeometry = require('./gltfPrimitiveToCesiumGeometry'); -var cesiumGeometryToGltfPrimitive = require('./cesiumGeometryToGltfPrimitive'); -var createAccessorUsageTables = require('./createAccessorUsageTables'); var Cesium = require('cesium'); + var GeometryPipeline = Cesium.GeometryPipeline; var defined = Cesium.defined; +var gltfPrimitiveToCesiumGeometry = require('./gltfPrimitiveToCesiumGeometry'); +var cesiumGeometryToGltfPrimitive = require('./cesiumGeometryToGltfPrimitive'); +var createAccessorUsageTables = require('./createAccessorUsageTables'); + module.exports = cacheOptimization; // Helper method to map accessor collections from the usageTable to an independent primitive (if there is one) @@ -62,6 +64,14 @@ function getIndependentPrimitive(dictionary, indicesId, attributeAccessors) { } } +/** + * Uses Cesium's geometry optimizations to reorder attributes so that they are accessed + * optimally by WebGL. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Number} cacheSize The cacheSize to use for Cesium.GeometryPipeline.reorderForPostVertexCache. + * @returns {Object} gltf with cache-optimized primitives. + */ function cacheOptimization(gltf, cacheSize) { // perform post vertex cache optimization var primitive; @@ -103,4 +113,5 @@ function cacheOptimization(gltf, cacheSize) { } } } + return gltf; } diff --git a/lib/cesiumGeometryToGltfPrimitive.js b/lib/cesiumGeometryToGltfPrimitive.js index 467edfa9..a3000ac4 100644 --- a/lib/cesiumGeometryToGltfPrimitive.js +++ b/lib/cesiumGeometryToGltfPrimitive.js @@ -1,5 +1,8 @@ 'use strict'; var Cesium = require('cesium'); + +var WebGLConstants = Cesium.WebGLConstants; + var findAccessorMinMax = require('./findAccessorMinMax'); var getUniqueId = require('./getUniqueId'); var mergeBuffers = require('./mergeBuffers'); @@ -7,8 +10,6 @@ var numberOfComponentsForType = require('./numberOfComponentsForType'); var uninterleaveAndPackBuffers = require('./uninterleaveAndPackBuffers'); var writeAccessor = require('./writeAccessor'); -var WebGLConstants = Cesium.WebGLConstants; - module.exports = cesiumGeometryToGltfPrimitive; // Creates a buffer location to write the new values to. mapGeometryAttributeToPrimitive does the actual writing @@ -111,6 +112,9 @@ function mapGeometryAttributeToPrimitive(gltf, primitive, geometry, semantic) { accessor.max = minMax.max; } +/** + * @private + */ function cesiumGeometryToGltfPrimitive(gltf, primitive, geometry) { var attributes = geometry.attributes; for (var semantic in attributes) { diff --git a/lib/combineMeshes.js b/lib/combineMeshes.js index 29564286..86d2d2fc 100755 --- a/lib/combineMeshes.js +++ b/lib/combineMeshes.js @@ -1,10 +1,17 @@ 'use strict'; var Cesium = require('cesium'); + var defined = Cesium.defined; + module.exports = combineMeshes; -//Combines meshes in a node. -//Should be run before the combinePrimitives stage to merge all primitives for a node into one mesh. +/** + * Combines meshes in a node. + * Should be run before the combinePrimitives stage to merge all primitives for a node into one mesh. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with combined meshes + */ function combineMeshes(gltf) { var nodes = gltf.nodes; var meshes = gltf.meshes; diff --git a/lib/combineNodes.js b/lib/combineNodes.js index 66712818..ab552fc8 100644 --- a/lib/combineNodes.js +++ b/lib/combineNodes.js @@ -18,6 +18,17 @@ module.exports = combineNodes; var rootNodePrefix = 'rootNode'; var scratchTransform = new Matrix4(); + +/** + * Combines nodes where possible. + * Primitives in meshes on child nodes are transformed by their node's transform and passed up the node chain + * if the primitive does not share data with primitives on another node. Meshes used by multiple nodes + * cannot be collapsed. Camera nodes and nodes targeted as joints or skeletons will be preserved. + * Should be run before the combineMeshes stage so that all combinable meshes are contained by one node. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with combined meshes + */ function combineNodes(gltf) { var nodes = gltf.nodes; var exclude = {}; @@ -48,8 +59,8 @@ function combineNodes(gltf) { } return scene; }); - removeUnusedNodes(gltf); + return gltf; } function getAnimationTargets(gltf, targets) { diff --git a/lib/compressIntegerAccessors.js b/lib/compressIntegerAccessors.js index 99dda04d..9840abd6 100644 --- a/lib/compressIntegerAccessors.js +++ b/lib/compressIntegerAccessors.js @@ -44,9 +44,10 @@ var unsignedComponentTypes = [ * in either a floating-point data type, or an integer one with more precision * than necessary. The data is rewritten to the most optimal data type. * - * @param {Object} gltf - * @param {Object} options - * @param {Array} options.semantics An array of semantics to compress + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} [options] Options defining custom behavior. + * @param {Array} [options.semantics] An array of semantics to compress. + * @returns {Promise} A promise that resolves to gltf with compressed integer accessors. */ function compressIntegerAccessors(gltf, options) { var semantics = defaultValue(options.semantics, []); @@ -58,6 +59,7 @@ function compressIntegerAccessors(gltf, options) { } return Promise.all(promises).then(function() { uninterLeaveAndPackBuffers(gltf); + return gltf; }); } diff --git a/lib/compressTextureCoordinates.js b/lib/compressTextureCoordinates.js index 06facb6b..4d980886 100644 --- a/lib/compressTextureCoordinates.js +++ b/lib/compressTextureCoordinates.js @@ -24,8 +24,8 @@ module.exports = compressTextureCoordinates; * Compresses the texture coordinates of this model, packing each texture coordinates from two floating-point numbers * into one. Modifies the model shader for decoding. * - * @param {Object} gltf A glTF hierarchy. - * @returns {Promise} A promise that resolves when the operation completes. + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Promise} A promise that resolves to gltf with compressed texture coordinates. */ function compressTextureCoordinates(gltf) { return new Promise(function(resolve) { @@ -87,7 +87,7 @@ function compressTextureCoordinates(gltf) { } }).then(function() { uninterleaveAndPackBuffers(gltf); - resolve(); + resolve(gltf); }); }); } diff --git a/lib/convertDagToTree.js b/lib/convertDagToTree.js index 1ff0dbff..6a4889e1 100755 --- a/lib/convertDagToTree.js +++ b/lib/convertDagToTree.js @@ -5,6 +5,14 @@ var defined = Cesium.defined; module.exports = convertDagToTree; +/** + * Walks the node graph and corrects from a DAG (directed acyclic graph) + * to a tree. If multiple nodes have the same child node, the child will be duplicated + * so that they no longer refer to the same node. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with any DAGs resolved to trees. + */ function convertDagToTree(gltf) { var scenes = gltf.scenes; var nodes = gltf.nodes; diff --git a/lib/createAccessorUsageTables.js b/lib/createAccessorUsageTables.js index eec5a5c1..df2ad8b1 100644 --- a/lib/createAccessorUsageTables.js +++ b/lib/createAccessorUsageTables.js @@ -66,6 +66,9 @@ function markUsageForIndexAccessor(gltf, accessor, usage) { return usage; } +/** + * @private + */ function createAccessorUsageTables(gltf) { var accessors = gltf.accessors; var meshes = gltf.meshes; diff --git a/lib/encodeImages.js b/lib/encodeImages.js index 59d5a2d6..ade4e6d9 100644 --- a/lib/encodeImages.js +++ b/lib/encodeImages.js @@ -9,8 +9,8 @@ module.exports = encodeImages; /** * Encodes Jimp images in pipeline extras to buffers. * - * @param {Object} gltf - * @returns {Promise} A promise that resolves when encoding is complete for all images. + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Promise} A promise that resolves to gltf when encoding is complete for all images. */ function encodeImages(gltf) { var images = gltf.images; diff --git a/lib/findAccessorMinMax.js b/lib/findAccessorMinMax.js index a6553d89..ff1ab616 100644 --- a/lib/findAccessorMinMax.js +++ b/lib/findAccessorMinMax.js @@ -1,5 +1,6 @@ 'use strict'; var Cesium = require('cesium'); + var defined = Cesium.defined; var byteLengthForComponentType = require('./byteLengthForComponentType'); @@ -9,6 +10,13 @@ var readBufferComponentType = require('./readBufferComponentType'); module.exports = findAccessorMinMax; +/** + * Finds the min and max for an accessor in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} accessor The accessor object from gltf to read. + * @returns {{min: Array, max: Array}} min holding the array of minimum values and max holding the array of maximum values. + */ function findAccessorMinMax(gltf, accessor) { var bufferViews = gltf.bufferViews; var buffers = gltf.buffers; diff --git a/lib/generateNormals.js b/lib/generateNormals.js index 5e9235ce..e1dafd44 100644 --- a/lib/generateNormals.js +++ b/lib/generateNormals.js @@ -1,17 +1,20 @@ 'use strict'; -var gltfPrimitiveToCesiumGeometry = require('./gltfPrimitiveToCesiumGeometry'); -var cesiumGeometryToGltfPrimitive = require('./cesiumGeometryToGltfPrimitive'); var Cesium = require('cesium'); + var defined = Cesium.defined; var WebGLConstants = Cesium.WebGLConstants; var GeometryPipeline = Cesium.GeometryPipeline; +var gltfPrimitiveToCesiumGeometry = require('./gltfPrimitiveToCesiumGeometry'); +var cesiumGeometryToGltfPrimitive = require('./cesiumGeometryToGltfPrimitive'); + module.exports = generateNormals; /** * Generates normals for primitives if they do not exist. * - * @param gltf + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns gltf with generated normals. */ function generateNormals(gltf) { var primitives = getPrimitives(gltf); @@ -28,6 +31,7 @@ function generateNormals(gltf) { cesiumGeometryToGltfPrimitive(gltf, primitive, geometry); } } + return gltf; } function getPrimitives(gltf) { diff --git a/lib/getAccessorByteStride.js b/lib/getAccessorByteStride.js index 41c007c7..68003eef 100644 --- a/lib/getAccessorByteStride.js +++ b/lib/getAccessorByteStride.js @@ -8,7 +8,7 @@ module.exports = getAccessorByteStride; * Returns the byte stride of the provided accessor. * If the byteStride is 0, it is calculated based on type and componentType * - * @param {Object} [accessor] The accessor. + * @param {Object} accessor The accessor. * @returns {Number} The byte stride of the accessor. */ function getAccessorByteStride(accessor) { diff --git a/lib/getBinaryGltf.js b/lib/getBinaryGltf.js index 30100333..496252a4 100644 --- a/lib/getBinaryGltf.js +++ b/lib/getBinaryGltf.js @@ -58,6 +58,14 @@ function updateBinaryObject(gltf, pipelineExtras, name, state) { } } +/** + * Get binary gltf representation of gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Boolean} embed Embed shaders into the binary. + * @param {Boolean} embedImage Embed images into the binary + * @returns {{glb: Buffer, header: Buffer, scene: Buffer, body: Buffer}} glb holds the whole buffer, each piece is also available via the returned object. + */ function getBinaryGltf(gltf, embed, embedImage) { // Create the special binary buffer from the existing buffers gltf.bufferViews = defaultValue(gltf.bufferViews, {}); diff --git a/lib/getUniqueId.js b/lib/getUniqueId.js index 15108040..02164e78 100644 --- a/lib/getUniqueId.js +++ b/lib/getUniqueId.js @@ -4,7 +4,13 @@ var defined = Cesium.defined; module.exports = getUniqueId; -// Given a prefix for a new ID, checks the gltf for matching prefixes in top-level objects with IDs and returns a unique ID. +/** + * Given a prefix for a new ID, checks the gltf for matching prefixes in top-level objects with IDs and returns a unique ID. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {String} prefix The string to try to use as the id. + * @returns {String} A unique id beginning with prefix. + */ function getUniqueId(gltf, prefix) { var prefixMatches = {}; diff --git a/lib/gltfPipeline.js b/lib/gltfPipeline.js index 9e5f2700..f1c3e6ec 100644 --- a/lib/gltfPipeline.js +++ b/lib/gltfPipeline.js @@ -33,6 +33,7 @@ var writeSource = require('./writeSource'); module.exports = { processJSON : processJSON, + processJSONWithExtras : processJSONWithExtras, processFile : processFile, processJSONToDisk : processJSONToDisk, processFileToDisk : processFileToDisk @@ -52,6 +53,13 @@ function writeSources(gltf) { }); } +/** + * Add pipeline extras and load uris, then process the gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} options Options to apply to stages during optimization. + * @returns {Promise} A promise that resolves to the processed gltf. + */ function processJSON(gltf, options) { addPipelineExtras(gltf); return loadGltfUris(gltf, options) @@ -63,6 +71,13 @@ function processJSON(gltf, options) { }); } +/** + * Process a gltf that already has extras and loaded uris. + * + * @param {Object} gltfWithExtras A javascript object holding a glTF hierarchy with extras. + * @param {Object} options Options to apply to stages during optimization. + * @returns {Promise} A promise that resolves to the processed gltf. + */ function processJSONWithExtras(gltfWithExtras, options) { var stats = new OptimizationStatistics(); addDefaults(gltfWithExtras, options); @@ -155,6 +170,14 @@ function writeFile(gltf, outputPath, options) { return writeGltf(gltf, writeOptions); } +/** + * Process a gltf in memory and writes it out to disk. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {String} outputPath The output file destination. + * @param {Object} options Options to apply to stages during optimization. + * @returns {Promise} A promise that resolves when the operation is complete. + */ function processJSONToDisk(gltf, outputPath, options) { addPipelineExtras(gltf); return loadGltfUris(gltf, options) @@ -166,6 +189,14 @@ function processJSONToDisk(gltf, outputPath, options) { }); } +/** + * Processes a gltf on disk and writes it out to disk. + * + * @param {String} inputPath The input file path. + * @param {String} outputPath The output file destination + * @param {Object} options Options to apply to stages during optimization. + * @returns {Promise} A promise that resolves when the operation is complete. + */ function processFileToDisk(inputPath, outputPath, options) { return readGltf(inputPath, options) .then(function(gltf) { diff --git a/lib/isDataUri.js b/lib/isDataUri.js index ae501103..bd8f2db1 100755 --- a/lib/isDataUri.js +++ b/lib/isDataUri.js @@ -1,5 +1,6 @@ 'use strict'; var Cesium = require('cesium'); + var defined = Cesium.defined; module.exports = isDataUri; diff --git a/lib/loadGltfUris.js b/lib/loadGltfUris.js index 7fcaae55..93b93baf 100644 --- a/lib/loadGltfUris.js +++ b/lib/loadGltfUris.js @@ -20,8 +20,10 @@ module.exports = loadGltfUris; * Load uris in the glTF into buffers. * The buffer data is placed into extras._pipeline.source for the corresponding object. * - * @param {Object} gltf - * @param {Object} [options] + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} options Options for loading uris. + * @param {String} options.basePath The path to look in when loading external files. + * @returns {Promise} A promise that resolves to gltf when all uris are loaded. */ function loadGltfUris(gltf, options) { var basePath = options.basePath; diff --git a/lib/mergeBuffers.js b/lib/mergeBuffers.js index e4c8ccae..eb3e6c7c 100755 --- a/lib/mergeBuffers.js +++ b/lib/mergeBuffers.js @@ -1,12 +1,19 @@ /*jshint loopfunc: true */ 'use strict'; var Cesium = require('cesium'); -var defined = Cesium.defined; var objectValues = require('object-values'); +var defined = Cesium.defined; + module.exports = mergeBuffers; -//Merge all buffers into one buffer +/** + * Merge all buffers into one buffer. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {String} bufferName The id to use for the combined buffer. + * @returns {Object} gltf with one combined buffer. + */ function mergeBuffers(gltf, bufferName) { var buffers = gltf.buffers; var bufferViews = gltf.bufferViews; diff --git a/lib/mergeDuplicateAccessors.js b/lib/mergeDuplicateAccessors.js index 25dcf25f..28bfda32 100644 --- a/lib/mergeDuplicateAccessors.js +++ b/lib/mergeDuplicateAccessors.js @@ -12,7 +12,8 @@ module.exports = mergeDuplicateAccessors; * Looks for accessors in a glTf hierarchy that contain the same data, removes all of the copies * and changes references to point to a single copy. * - * @param {Object} [gltf] A glTF hierarchy. + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with merged duplicate accessors. */ function mergeDuplicateAccessors(gltf) { var accessors = gltf.accessors; @@ -33,6 +34,7 @@ function mergeDuplicateAccessors(gltf) { } } } + return gltf; } function replaceAccessorIdInstances(gltf, accessorId, newAccessorId) { diff --git a/lib/mergeDuplicateVertices.js b/lib/mergeDuplicateVertices.js index c2adb84b..2fdf283d 100644 --- a/lib/mergeDuplicateVertices.js +++ b/lib/mergeDuplicateVertices.js @@ -15,7 +15,8 @@ module.exports = mergeDuplicateVertices; * Looks for duplicated vertices in a glTF hierarchy and merges them, * modifying indices to account for the change if they exist. * - * @param {Object} gltf A glTF hierarchy. + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with merged duplicate vertices. */ function mergeDuplicateVertices(gltf) { var meshes = gltf.meshes; @@ -29,6 +30,7 @@ function mergeDuplicateVertices(gltf) { } mergeDuplicateVerticesFromMapping(gltf, indexAccessors); removeUnusedVertices(gltf); + return gltf; } function mergeDuplicateVerticesFromMapping(gltf, indexAccessors) { diff --git a/lib/modelMaterialsCommon.js b/lib/modelMaterialsCommon.js index 89146e32..26ddfeb2 100644 --- a/lib/modelMaterialsCommon.js +++ b/lib/modelMaterialsCommon.js @@ -652,6 +652,81 @@ function getTechniqueKey(khrMaterialsCommon) { return techniqueKey; } +function lightDefaults(gltf) { + if (!defined(gltf.extensions)) { + gltf.extensions = {}; + } + var extensions = gltf.extensions; + + if (!defined(extensions.KHR_materials_common)) { + extensions.KHR_materials_common = {}; + } + var khrMaterialsCommon = extensions.KHR_materials_common; + + if (defined(gltf.lights)) { + // glTF 0.8 backward compatibility + khrMaterialsCommon.lights = gltf.lights; + delete gltf.lights; + } + else if (!defined(khrMaterialsCommon.lights)) { + khrMaterialsCommon.lights = {}; + } + var lights = khrMaterialsCommon.lights; + + for (var name in lights) { + if (lights.hasOwnProperty(name)) { + var light = lights[name]; + if (light.type === 'ambient') { + if (!defined(light.ambient)) { + light.ambient = {}; + } + var ambientLight = light.ambient; + + if (!defined(ambientLight.color)) { + ambientLight.color = [1.0, 1.0, 1.0]; + } + } else if (light.type === 'directional') { + if (!defined(light.directional)) { + light.directional = {}; + } + var directionalLight = light.directional; + + if (!defined(directionalLight.color)) { + directionalLight.color = [1.0, 1.0, 1.0]; + } + } else if (light.type === 'point') { + if (!defined(light.point)) { + light.point = {}; + } + var pointLight = light.point; + + if (!defined(pointLight.color)) { + pointLight.color = [1.0, 1.0, 1.0]; + } + + pointLight.constantAttenuation = defaultValue(pointLight.constantAttenuation, 1.0); + pointLight.linearAttenuation = defaultValue(pointLight.linearAttenuation, 0.0); + pointLight.quadraticAttenuation = defaultValue(pointLight.quadraticAttenuation, 0.0); + } else if (light.type === 'spot') { + if (!defined(light.spot)) { + light.spot = {}; + } + var spotLight = light.spot; + + if (!defined(spotLight.color)) { + spotLight.color = [1.0, 1.0, 1.0]; + } + + spotLight.constantAttenuation = defaultValue(spotLight.constantAttenuation, 1.0); + spotLight.fallOffAngle = defaultValue(spotLight.fallOffAngle, 3.14159265); + spotLight.fallOffExponent = defaultValue(spotLight.fallOffExponent, 0.0); + spotLight.linearAttenuation = defaultValue(spotLight.linearAttenuation, 0.0); + spotLight.quadraticAttenuation = defaultValue(spotLight.quadraticAttenuation, 0.0); + } + } + } +} + /** * Modifies gltf in place. * @@ -685,6 +760,7 @@ function modelMaterialsCommon(gltf, options) { if (!defined(gltf.techniques)) { gltf.techniques = {}; } + lightDefaults(gltf); var lightParameters = generateLightParameters(gltf); diff --git a/lib/numberOfComponentsForType.js b/lib/numberOfComponentsForType.js index b9cbc709..fa44e94b 100644 --- a/lib/numberOfComponentsForType.js +++ b/lib/numberOfComponentsForType.js @@ -13,8 +13,8 @@ module.exports = numberOfComponentsForType; * 'MAT3' : 9 * 'MAT4' : 16 * - * @param {String} type - * @returns {Number} + * @param {String} type glTF type + * @returns {Number} The number of components in that type. */ function numberOfComponentsForType(type) { switch (type) { diff --git a/lib/octEncodeNormals.js b/lib/octEncodeNormals.js index 4e51dd94..8f44a1fa 100644 --- a/lib/octEncodeNormals.js +++ b/lib/octEncodeNormals.js @@ -25,7 +25,7 @@ module.exports = octEncodeNormals; * down to two bytes. Modifies the model shader for decoding. * * @param {Object} gltf A glTF hierarchy. - * @returns {Promise} A promise that resolves when the operation completes. + * @returns {Promise} A promise that resolves to gltf when the operation completes. */ function octEncodeNormals(gltf) { return new Promise(function(resolve) { @@ -91,7 +91,7 @@ function octEncodeNormals(gltf) { } }).then(function() { uninterleaveAndPackBuffers(gltf); - resolve(); + resolve(gltf); }); }); } diff --git a/lib/packArray.js b/lib/packArray.js index 675ec9bc..e95434ba 100644 --- a/lib/packArray.js +++ b/lib/packArray.js @@ -10,6 +10,13 @@ var WebGLConstants = Cesium.WebGLConstants; module.exports = packArray; +/** + * Packs Cesium types into an array of values. + * + * @param {Array} data An array of Cesium types to pack. + * @param {Number} type The WebGL type to use for packing (e.g. WebGLConstants.FLOAT_VEC3 for Cartesian3) + * @returns {Array} An array containing the packed data. + */ function packArray(data, type) { var length = data.length; var packFunction; diff --git a/lib/parseBinaryGltf.js b/lib/parseBinaryGltf.js index 493223fd..2bdc4fb4 100755 --- a/lib/parseBinaryGltf.js +++ b/lib/parseBinaryGltf.js @@ -1,15 +1,23 @@ 'use strict'; var Cesium = require('cesium'); +var StringDecoder = require('string_decoder').StringDecoder; +var bufferEqual = require('buffer-equal'); +var objectValues = require('object-values'); + var defined = Cesium.defined; var DeveloperError = Cesium.DeveloperError; var defaultValue = Cesium.defaultValue; -var bufferEqual = require('buffer-equal'); -var objectValues = require('object-values'); -var StringDecoder = require('string_decoder').StringDecoder; + var addPipelineExtras = require('./addPipelineExtras'); module.exports = parseBinaryGltf; +/** + * Parses a binary glTF buffer into glTF JSON. + * + * @param {Buffer} data The binary glTF buffer to parse. + * @returns {Object} Parsed gltf from binary. + */ function parseBinaryGltf(data) { var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; var byteOffset = 0; diff --git a/lib/readAccessor.js b/lib/readAccessor.js index db4cd327..afbe4446 100644 --- a/lib/readAccessor.js +++ b/lib/readAccessor.js @@ -15,12 +15,12 @@ var AccessorReader = require('./AccessorReader'); module.exports = readAccessor; /** - * Reads data from + * Reads data from the provided accessor into an array of Cesium types. * - * @param {Object} gltf - * @param {Object} accessor - * @param {Array} results - * @returns {Number} + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} accessor The glTF accessor to read. + * @param {Array} results The resulting Cesium data structures are pushed into results. + * @returns {Number} The WebGLConstants type used to generate the Cesium data structures. (e.g. WebGLConstants.FLOAT_VEC3 for Cartesian3) */ function readAccessor(gltf, accessor, results) { var generateAttributeFunction; diff --git a/lib/readBufferComponentType.js b/lib/readBufferComponentType.js index 2878a21f..f78415dc 100644 --- a/lib/readBufferComponentType.js +++ b/lib/readBufferComponentType.js @@ -1,9 +1,18 @@ 'use strict'; var Cesium = require('cesium'); + var WebGLConstants = Cesium.WebGLConstants; module.exports = readBufferComponentType; +/** + * Read from a buffer at an offset for a particular component type. + * + * @param {Buffer} buffer The buffer to read. + * @param {Number} componentType WebGLConstants componentType to use for reading. + * @param {Number} byteOffset Read starting from this offset. + * @returns {Number} The resulting number value. + */ function readBufferComponentType(buffer, componentType, byteOffset) { switch (componentType) { case WebGLConstants.BYTE: diff --git a/lib/readGltf.js b/lib/readGltf.js index e5e2ec1f..9ed68abd 100644 --- a/lib/readGltf.js +++ b/lib/readGltf.js @@ -15,6 +15,13 @@ var fsReadFile = Promise.promisify(fs.readFile); module.exports = readGltf; +/** + * Reads a glTF file from the disk. + * @param {String} gltfPath The file path for the glTF. + * @param {Object} options Options defining custom behavior. + * @param {String} [options.basePath] The base path to use for resolving external references. Defaults to the directory containing the glTF. + * @returns {Object} A javascript object containing a glTF hierarchy. + */ function readGltf(gltfPath, options) { if (!defined(gltfPath)) { throw new DeveloperError('Input path is undefined.'); diff --git a/lib/removeDuplicatePrimitives.js b/lib/removeDuplicatePrimitives.js index 861aa5d7..e81a488f 100644 --- a/lib/removeDuplicatePrimitives.js +++ b/lib/removeDuplicatePrimitives.js @@ -2,13 +2,20 @@ var Cesium = require('cesium'); var _ = require('underscore'); +var defined = Cesium.defined; + var NodeHelpers = require('./NodeHelpers'); var getUniqueId = require('./getUniqueId'); -var defined = Cesium.defined; - module.exports = removeDuplicatePrimitives; +/** + * Removes duplicate primitives from gltf. + * Duplicate primitives are primitives within meshes that access the same data. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object}gltf without duplicate primitives. + */ function removeDuplicatePrimitives(gltf) { var meshes = gltf.meshes; var seenPrimitives = []; @@ -44,6 +51,7 @@ function removeDuplicatePrimitives(gltf) { } removeDuplicatesFromTraversal(gltf, seenPrimitives, primitivesCount, primitivesToMeshes); finalizeRemoval(gltf); + return gltf; } var splitMeshPrefix = 'mesh-split'; diff --git a/lib/removePipelineExtras.js b/lib/removePipelineExtras.js index bd927c3d..37810a76 100755 --- a/lib/removePipelineExtras.js +++ b/lib/removePipelineExtras.js @@ -1,11 +1,16 @@ 'use strict'; var Cesium = require('cesium'); + var defined = Cesium.defined; var defaultValue = Cesium.defaultValue; module.exports = removePipelineExtras; - -//Iterate through the objects within each glTF object and delete their pipeline extras object +/** + * Iterate through the objects within each glTF object and delete their pipeline extras object. + * + * @param {Object} object Root object to remove pipeline extras. + * @returns {Object} glTF with no pipeline extras. + */ function removePipelineExtras(object) { if (defined(object) && typeof object === 'object') { if (defined(object.extras) && defined(object.extras._pipeline)) { diff --git a/lib/removeUnused.js b/lib/removeUnused.js index e8d53f78..4dda4603 100644 --- a/lib/removeUnused.js +++ b/lib/removeUnused.js @@ -17,6 +17,13 @@ var removeUnusedPrimitiveAttributes = require('./removeUnusedPrimitiveAttributes module.exports = removeUnused; +/** + * Removes all unused elements in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused elements. + */ function removeUnused(gltf, stats) { //Remove in top-down order so newly unused objects down the hierarchy will be removed as well removeUnusedNodes(gltf, stats); diff --git a/lib/removeUnusedAccessors.js b/lib/removeUnusedAccessors.js index 0a920193..d54eaeb0 100755 --- a/lib/removeUnusedAccessors.js +++ b/lib/removeUnusedAccessors.js @@ -5,6 +5,13 @@ var defined = Cesium.defined; module.exports = removeUnusedAccessors; +/** + * Remove all unused accessors in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused accessors. + */ function removeUnusedAccessors(gltf, stats) { var usedAccessorIds = {}; var meshes = gltf.meshes; diff --git a/lib/removeUnusedBufferViews.js b/lib/removeUnusedBufferViews.js index 0c6d60f6..74d67bb2 100755 --- a/lib/removeUnusedBufferViews.js +++ b/lib/removeUnusedBufferViews.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedBufferViews; +/** + * Remove all unused buffer views in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused buffers views. + */ function removeUnusedBufferViews(gltf, stats) { var usedBufferViewIds = findUsedIds(gltf, 'accessors', 'bufferView'); // TODO: remove orphan uris diff --git a/lib/removeUnusedBuffers.js b/lib/removeUnusedBuffers.js index c3abced0..c451fddd 100755 --- a/lib/removeUnusedBuffers.js +++ b/lib/removeUnusedBuffers.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedBuffers; +/** + * Remove all unused buffers in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused buffers. + */ function removeUnusedBuffers(gltf, stats) { var usedBufferIds = findUsedIds(gltf, 'bufferViews', 'buffer'); // TODO: remove orphan uris diff --git a/lib/removeUnusedCameras.js b/lib/removeUnusedCameras.js index a8b7e309..bd5750bb 100755 --- a/lib/removeUnusedCameras.js +++ b/lib/removeUnusedCameras.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedCameras; +/** + * Remove all unused cameras in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused cameras. + */ function removeUnusedCameras(gltf, stats) { var usedCameraIds = findUsedIds(gltf, 'nodes', 'camera'); return removeObject(gltf, 'cameras', usedCameraIds, stats); diff --git a/lib/removeUnusedImages.js b/lib/removeUnusedImages.js index a7759ebe..771b9056 100644 --- a/lib/removeUnusedImages.js +++ b/lib/removeUnusedImages.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedImages; +/** + * Remove all unused images in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused images. + */ function removeUnusedImages(gltf, stats) { var usedImageIds = findUsedIds(gltf, 'textures', 'source'); // TODO: remove orphan uris diff --git a/lib/removeUnusedMaterials.js b/lib/removeUnusedMaterials.js index c846c60a..49ddfd4c 100755 --- a/lib/removeUnusedMaterials.js +++ b/lib/removeUnusedMaterials.js @@ -1,10 +1,19 @@ 'use strict'; -var removeObject = require('./removeObject'); var Cesium = require('cesium'); + var defined = Cesium.defined; +var removeObject = require('./removeObject'); + module.exports = removeUnusedMaterials; +/** + * Remove all unused materials in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused images. + */ function removeUnusedMaterials(gltf, stats) { var usedMaterialIds = {}; var meshes = gltf.meshes; diff --git a/lib/removeUnusedMeshes.js b/lib/removeUnusedMeshes.js index 0cfd3f7c..c5897ebe 100755 --- a/lib/removeUnusedMeshes.js +++ b/lib/removeUnusedMeshes.js @@ -1,10 +1,19 @@ 'use strict'; -var removeObject = require('./removeObject'); var Cesium = require('cesium'); + var defined = Cesium.defined; +var removeObject = require('./removeObject'); + module.exports = removeUnusedMeshes; +/** + * Remove all unused meshes in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused meshes. + */ function removeUnusedMeshes(gltf, stats) { var usedMeshIds = {}; var nodes = gltf.nodes; diff --git a/lib/removeUnusedNodes.js b/lib/removeUnusedNodes.js index 1d5cb377..05d2ebcb 100755 --- a/lib/removeUnusedNodes.js +++ b/lib/removeUnusedNodes.js @@ -1,10 +1,19 @@ 'use strict'; -var removeObject = require('./removeObject'); var Cesium = require('cesium'); + var defined = Cesium.defined; +var removeObject = require('./removeObject'); + module.exports = removeUnusedNodes; +/** + * Remove all unused nodes in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused nodes. + */ function removeUnusedNodes(gltf, stats) { var usedNodeIds = {}; var scenes = gltf.scenes; diff --git a/lib/removeUnusedPrimitiveAttributes.js b/lib/removeUnusedPrimitiveAttributes.js index 490a5ae0..367f0aaf 100644 --- a/lib/removeUnusedPrimitiveAttributes.js +++ b/lib/removeUnusedPrimitiveAttributes.js @@ -8,7 +8,8 @@ module.exports = removeUnusedPrimitiveAttributes; /** * Removes references to primitive attributes that aren't defined in the material's technique. * - * @param {Object} gltf + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused primitive attributes. */ function removeUnusedPrimitiveAttributes(gltf) { var meshes = gltf.meshes; @@ -52,4 +53,5 @@ function removeUnusedPrimitiveAttributes(gltf) { } } } + return gltf; } \ No newline at end of file diff --git a/lib/removeUnusedPrograms.js b/lib/removeUnusedPrograms.js index 103dda7c..f20f7982 100755 --- a/lib/removeUnusedPrograms.js +++ b/lib/removeUnusedPrograms.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedPrograms; +/** + * Remove all unused programs in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused programs. + */ function removeUnusedPrograms(gltf, stats) { var usedProgramIds = findUsedIds(gltf, 'techniques', 'program'); // TODO: remove orphan uris diff --git a/lib/removeUnusedSamplers.js b/lib/removeUnusedSamplers.js index 36c900f3..996568cc 100644 --- a/lib/removeUnusedSamplers.js +++ b/lib/removeUnusedSamplers.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedSamplers; +/** + * Remove all unused samplers in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused samplers. + */ function removeUnusedSamplers(gltf, stats) { var usedSamplerIds = findUsedIds(gltf, 'textures', 'sampler'); return removeObject(gltf, 'samplers', usedSamplerIds, stats); diff --git a/lib/removeUnusedShaders.js b/lib/removeUnusedShaders.js index 68f1618d..e28da3c0 100755 --- a/lib/removeUnusedShaders.js +++ b/lib/removeUnusedShaders.js @@ -1,10 +1,19 @@ 'use strict'; -var removeObject = require('./removeObject'); var Cesium = require('cesium'); + var defined = Cesium.defined; +var removeObject = require('./removeObject'); + module.exports = removeUnusedShaders; +/** + * Remove all unused shaders in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused shaders. + */ function removeUnusedShaders(gltf, stats) { var usedShaderIds = {}; var programs = gltf.programs; @@ -20,8 +29,6 @@ function removeUnusedShaders(gltf, stats) { } } } - -// TODO: remove orphan uris - + // TODO: remove orphan uris return removeObject(gltf, 'shaders', usedShaderIds, stats); } \ No newline at end of file diff --git a/lib/removeUnusedSkins.js b/lib/removeUnusedSkins.js index cfdc6901..dd807d5d 100755 --- a/lib/removeUnusedSkins.js +++ b/lib/removeUnusedSkins.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedSkins; +/** + * Remove all unused skins in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused skins. + */ function removeUnusedSkins(gltf, stats) { var usedSkinIds = findUsedIds(gltf, 'nodes', 'skin'); return removeObject(gltf, 'skins', usedSkinIds, stats); diff --git a/lib/removeUnusedTechniques.js b/lib/removeUnusedTechniques.js index 39e4a283..fdb363c2 100755 --- a/lib/removeUnusedTechniques.js +++ b/lib/removeUnusedTechniques.js @@ -4,6 +4,13 @@ var removeObject = require('./removeObject'); module.exports = removeUnusedTechniques; +/** + * Remove all unused techniques in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused techniques + */ function removeUnusedTechniques(gltf, stats) { var usedTechniqueIds = findUsedIds(gltf, 'materials', 'technique'); return removeObject(gltf, 'techniques', usedTechniqueIds, stats); diff --git a/lib/removeUnusedTextures.js b/lib/removeUnusedTextures.js index 1f89721d..2f86506c 100755 --- a/lib/removeUnusedTextures.js +++ b/lib/removeUnusedTextures.js @@ -1,10 +1,19 @@ 'use strict'; -var removeObject = require('./removeObject'); var Cesium = require('cesium'); + var defined = Cesium.defined; +var removeObject = require('./removeObject'); + module.exports = removeUnusedTextures; +/** + * Remove all unused textures in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {OptimizationStatistics} stats Record removal statistics. + * @returns {Object} gltf with removed unused textures. + */ function removeUnusedTextures(gltf, stats) { var usedTextureIds = {}; var materials = gltf.materials; diff --git a/lib/removeUnusedVertices.js b/lib/removeUnusedVertices.js index 9d709e2a..767747db 100755 --- a/lib/removeUnusedVertices.js +++ b/lib/removeUnusedVertices.js @@ -13,7 +13,11 @@ var uninterleaveAndPackBuffers = require('./uninterleaveAndPackBuffers'); module.exports = removeUnusedVertices; -//Removes attributes from indexed primitives that aren't used +/** + * Removes attributes from indexed primitives that are not used. + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf without unused vertices. + */ function removeUnusedVertices(gltf) { if (defined(gltf.accessors) && defined(gltf.buffers) && defined(gltf.bufferViews) && defined(gltf.meshes)) { removeUnusedVerticesFromAccessors(gltf); diff --git a/lib/uninterleaveAndPackBuffers.js b/lib/uninterleaveAndPackBuffers.js index d0dbf6d7..3cfe6df4 100644 --- a/lib/uninterleaveAndPackBuffers.js +++ b/lib/uninterleaveAndPackBuffers.js @@ -1,5 +1,6 @@ 'use strict'; var Cesium = require('cesium'); + var WebGLConstants = Cesium.WebGLConstants; var defined = Cesium.defined; var defaultValue = Cesium.defaultValue; @@ -14,7 +15,8 @@ module.exports = uninterleaveAndPackBuffers; * Repacks the accessed buffer data into contiguous chunks. * Also has the effect of un-interleaving interleaved accessors. * - * @param gltf + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with repacked buffers. */ function uninterleaveAndPackBuffers(gltf) { var accessors = gltf.accessors; @@ -35,6 +37,7 @@ function uninterleaveAndPackBuffers(gltf) { accessor.bufferView = accessor.extras._pipeline.bufferView; } } + return gltf; } function packGltfBuffer(gltf, bufferId, packBufferViews) { diff --git a/lib/writeAccessor.js b/lib/writeAccessor.js index 129cf21d..d0521627 100644 --- a/lib/writeAccessor.js +++ b/lib/writeAccessor.js @@ -4,6 +4,13 @@ var numberOfComponentsForType = require('./numberOfComponentsForType'); module.exports = writeAccessor; +/** + * Writes the contents of dataArray into an accessor. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} accessor glTF accessor where data should be written. + * @param {Array} dataArray Data to write into the accessor. + */ function writeAccessor(gltf, accessor, dataArray) { var accessorReader = new AccessorReader(gltf, accessor); var componentType = accessor.componentType; diff --git a/lib/writeBinaryGltf.js b/lib/writeBinaryGltf.js index 2f95da3f..4c9ba89c 100644 --- a/lib/writeBinaryGltf.js +++ b/lib/writeBinaryGltf.js @@ -14,6 +14,17 @@ fsExtra.outputFileAsync = Promise.promisify(fsExtra.outputFile); module.exports = writeBinaryGltf; +/** + * Writes gltf to file as binary glTF. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} options Defines custom behavior for writing. + * @param {String} options.outputPath The file path where the binary glTF should be written. + * @param {Boolean} options.embed Flag to embed shader uris. + * @param {Boolean} options.embedImage Flag to embed image uris. + * @param {Boolean} options.createDirectory If true, a directory named 'output' will be created at options.outputPath and the output will be written there. + * @returns {Promise} A promise resolving when the write operation completes. + */ function writeBinaryGltf(gltf, options) { var outputPath = options.outputPath; var embed = options.embed; diff --git a/lib/writeBufferComponentType.js b/lib/writeBufferComponentType.js index f2810647..f352bd36 100644 --- a/lib/writeBufferComponentType.js +++ b/lib/writeBufferComponentType.js @@ -4,6 +4,14 @@ var WebGLConstants = Cesium.WebGLConstants; module.exports = writeBufferComponentType; +/** + * Writes a value to a buffer as a particular component type. + * + * @param {Buffer} buffer The buffer to be written. + * @param {Number} componentType WebGLConstants value for component type. + * @param {Number} value The value to write. + * @param {Number} byteOffset The offset into the buffer to be written. + */ function writeBufferComponentType(buffer, componentType, value, byteOffset) { switch (componentType) { case WebGLConstants.BYTE: diff --git a/lib/writeGltf.js b/lib/writeGltf.js index afac7289..b4b93bfb 100755 --- a/lib/writeGltf.js +++ b/lib/writeGltf.js @@ -14,6 +14,17 @@ fsExtra.outputJsonAsync = Promise.promisify(fsExtra.outputJson); module.exports = writeGltf; +/** + * Writes gltf to a file. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} options Defines custom behavior for writing. + * @param {String} options.outputPath The file path where the glTF should be written. + * @param {Boolean} options.embed Flag to embed shader uris. + * @param {Boolean} options.embedImage Flag to embed image uris. + * @param {Boolean} options.createDirectory If true, a directory named 'output' will be created at options.outputPath and the output will be written there. + * @returns {Promise} A promise resolving when the write operation completes. + */ function writeGltf(gltf, options) { var outputPath = options.outputPath; var embed = options.embed; diff --git a/lib/writeSource.js b/lib/writeSource.js index d9869eca..b9f4d941 100644 --- a/lib/writeSource.js +++ b/lib/writeSource.js @@ -1,9 +1,9 @@ 'use strict'; var Cesium = require('cesium'); var DataUri = require('datauri'); +var Promise = require('bluebird'); var fsExtra = require('fs-extra'); var path = require('path'); -var Promise = require('bluebird'); var defined = Cesium.defined; From da16e7b5faa1c36394cd9cce988e4251a47f4af4 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Thu, 11 Aug 2016 13:29:28 -0400 Subject: [PATCH 04/21] Removed index generation function --- gulpfile.js | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 07806148..313aa317 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,10 +1,8 @@ 'use strict'; var Cesium = require('cesium'); -var Promise = require('bluebird'); var child_process = require('child_process'); var fsExtra = require('fs-extra'); -var glob = require('glob'); var gulp = require('gulp'); var gulpJshint = require('gulp-jshint'); var Jasmine = require('jasmine'); @@ -17,9 +15,6 @@ var yargs = require('yargs'); var defined = Cesium.defined; var argv = yargs.argv; -var fsWriteFile = Promise.promisify(fsExtra.writeFile); -var globPromise = Promise.promisify(glob); - // Add third-party node module binaries to the system path // since some tasks need to call them directly. var environmentSeparator = process.platform === 'win32' ? ';' : ':'; @@ -85,31 +80,6 @@ gulp.task('coverage', function () { open('coverage/lcov-report/index.html'); }); -/** - * Regenerates index.js to export the contents of the 'lib/' directory - */ -gulp.task('regenerate-index', function() { - var indexJS = 'module.exports = {\n'; - var first = false; - globPromise('lib/**/*.js', undefined) - .then(function(files) { - return Promise.map(files, function (fileName) { - var exportName = path.basename(fileName, '.js'); - if (!first) { - first = true; - } else { - indexJS += ',\n'; - } - indexJS += ' ' + exportName + ' : require(\'./' + fileName + '\')'; - }); - }) - .then(function() { - indexJS += '\n};'; - return fsWriteFile('index.js', indexJS); - }); - -}); - function copyModule(module) { var tsName = module + '.d.ts'; var srcUrl = 'https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/' + module + '/' + tsName; From ef85de6430cc8dcb79a3ef04b5f7a8924bb90f70 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Thu, 11 Aug 2016 13:30:27 -0400 Subject: [PATCH 05/21] Updated CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 870e68ee..9cd11e4d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ Change Log ### Next Release * cacheOptimization no longer crashes on primitives without indices. [#154](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/154) -* lib/**/*.js is exposed as the Public API via index.js [#153](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/153) +* Public API is exposed via index.js [#153](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/153) ### 0.1.0-alpha3 - 2016-07-25 From 6b66d6f031d3282a7097e61af16e204190ae378c Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 12 Aug 2016 13:22:42 -0400 Subject: [PATCH 06/21] Small fixes --- lib/AccessorReader.js | 2 +- lib/NodeHelpers.js | 2 -- lib/cacheOptimization.js | 9 ++++----- lib/generateNormals.js | 7 +++---- lib/gltfPipeline.js | 6 +++--- lib/removeDuplicatePrimitives.js | 7 +++---- lib/removeUnusedMaterials.js | 3 +-- lib/removeUnusedMeshes.js | 3 +-- lib/removeUnusedNodes.js | 3 +-- lib/removeUnusedShaders.js | 3 +-- lib/removeUnusedTextures.js | 3 +-- package.json | 1 - 12 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/AccessorReader.js b/lib/AccessorReader.js index 7ecefbd5..8ba14f38 100644 --- a/lib/AccessorReader.js +++ b/lib/AccessorReader.js @@ -15,7 +15,7 @@ module.exports = AccessorReader; * memory consumption is important. * * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {Object} accessor The accessor object from glTF to read . + * @param {Object} accessor The accessor object from glTF to read. * @constructor */ function AccessorReader(gltf, accessor) { diff --git a/lib/NodeHelpers.js b/lib/NodeHelpers.js index ab783e9f..27bd0f91 100644 --- a/lib/NodeHelpers.js +++ b/lib/NodeHelpers.js @@ -60,8 +60,6 @@ function addNodeToArray(parameters, node) { parameters.nodeArray.push(node); } -// get all the nodes in a scene - /** * Get all the nodes in a scene. * If resultArray is undefined, a new array will be created. diff --git a/lib/cacheOptimization.js b/lib/cacheOptimization.js index 4ec3e05a..e272c569 100644 --- a/lib/cacheOptimization.js +++ b/lib/cacheOptimization.js @@ -1,13 +1,12 @@ 'use strict'; var Cesium = require('cesium'); - -var GeometryPipeline = Cesium.GeometryPipeline; -var defined = Cesium.defined; - var gltfPrimitiveToCesiumGeometry = require('./gltfPrimitiveToCesiumGeometry'); var cesiumGeometryToGltfPrimitive = require('./cesiumGeometryToGltfPrimitive'); var createAccessorUsageTables = require('./createAccessorUsageTables'); +var GeometryPipeline = Cesium.GeometryPipeline; +var defined = Cesium.defined; + module.exports = cacheOptimization; // Helper method to map accessor collections from the usageTable to an independent primitive (if there is one) @@ -69,7 +68,7 @@ function getIndependentPrimitive(dictionary, indicesId, attributeAccessors) { * optimally by WebGL. * * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {Number} cacheSize The cacheSize to use for Cesium.GeometryPipeline.reorderForPostVertexCache. + * @param {Number} [cacheSize=24] The cacheSize to use for Cesium.GeometryPipeline.reorderForPostVertexCache. * @returns {Object} gltf with cache-optimized primitives. */ function cacheOptimization(gltf, cacheSize) { diff --git a/lib/generateNormals.js b/lib/generateNormals.js index e1dafd44..db5b407d 100644 --- a/lib/generateNormals.js +++ b/lib/generateNormals.js @@ -1,20 +1,19 @@ 'use strict'; var Cesium = require('cesium'); +var gltfPrimitiveToCesiumGeometry = require('./gltfPrimitiveToCesiumGeometry'); +var cesiumGeometryToGltfPrimitive = require('./cesiumGeometryToGltfPrimitive'); var defined = Cesium.defined; var WebGLConstants = Cesium.WebGLConstants; var GeometryPipeline = Cesium.GeometryPipeline; -var gltfPrimitiveToCesiumGeometry = require('./gltfPrimitiveToCesiumGeometry'); -var cesiumGeometryToGltfPrimitive = require('./cesiumGeometryToGltfPrimitive'); - module.exports = generateNormals; /** * Generates normals for primitives if they do not exist. * * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns gltf with generated normals. + * @returns {Object} gltf with generated normals. */ function generateNormals(gltf) { var primitives = getPrimitives(gltf); diff --git a/lib/gltfPipeline.js b/lib/gltfPipeline.js index f1c3e6ec..05e8d16c 100644 --- a/lib/gltfPipeline.js +++ b/lib/gltfPipeline.js @@ -3,9 +3,6 @@ var Cesium = require('cesium'); var Promise = require('bluebird'); var path = require('path'); -var defaultValue = Cesium.defaultValue; -var defined = Cesium.defined; - var OptimizationStatistics = require('./OptimizationStatistics'); var addDefaults = require('./addDefaults'); var addPipelineExtras = require('./addPipelineExtras'); @@ -31,6 +28,9 @@ var writeGltf = require('./writeGltf'); var writeBinaryGltf = require('./writeBinaryGltf'); var writeSource = require('./writeSource'); +var defaultValue = Cesium.defaultValue; +var defined = Cesium.defined; + module.exports = { processJSON : processJSON, processJSONWithExtras : processJSONWithExtras, diff --git a/lib/removeDuplicatePrimitives.js b/lib/removeDuplicatePrimitives.js index e81a488f..b9747b1a 100644 --- a/lib/removeDuplicatePrimitives.js +++ b/lib/removeDuplicatePrimitives.js @@ -1,12 +1,11 @@ 'use strict'; var Cesium = require('cesium'); var _ = require('underscore'); - -var defined = Cesium.defined; - var NodeHelpers = require('./NodeHelpers'); var getUniqueId = require('./getUniqueId'); +var defined = Cesium.defined; + module.exports = removeDuplicatePrimitives; /** @@ -14,7 +13,7 @@ module.exports = removeDuplicatePrimitives; * Duplicate primitives are primitives within meshes that access the same data. * * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object}gltf without duplicate primitives. + * @returns {Object} gltf without duplicate primitives. */ function removeDuplicatePrimitives(gltf) { var meshes = gltf.meshes; diff --git a/lib/removeUnusedMaterials.js b/lib/removeUnusedMaterials.js index 49ddfd4c..62354936 100755 --- a/lib/removeUnusedMaterials.js +++ b/lib/removeUnusedMaterials.js @@ -1,10 +1,9 @@ 'use strict'; var Cesium = require('cesium'); +var removeObject = require('./removeObject'); var defined = Cesium.defined; -var removeObject = require('./removeObject'); - module.exports = removeUnusedMaterials; /** diff --git a/lib/removeUnusedMeshes.js b/lib/removeUnusedMeshes.js index c5897ebe..d92d03d3 100755 --- a/lib/removeUnusedMeshes.js +++ b/lib/removeUnusedMeshes.js @@ -1,10 +1,9 @@ 'use strict'; var Cesium = require('cesium'); +var removeObject = require('./removeObject'); var defined = Cesium.defined; -var removeObject = require('./removeObject'); - module.exports = removeUnusedMeshes; /** diff --git a/lib/removeUnusedNodes.js b/lib/removeUnusedNodes.js index 05d2ebcb..8a39621b 100755 --- a/lib/removeUnusedNodes.js +++ b/lib/removeUnusedNodes.js @@ -1,10 +1,9 @@ 'use strict'; var Cesium = require('cesium'); +var removeObject = require('./removeObject'); var defined = Cesium.defined; -var removeObject = require('./removeObject'); - module.exports = removeUnusedNodes; /** diff --git a/lib/removeUnusedShaders.js b/lib/removeUnusedShaders.js index e28da3c0..06955dbd 100755 --- a/lib/removeUnusedShaders.js +++ b/lib/removeUnusedShaders.js @@ -1,10 +1,9 @@ 'use strict'; var Cesium = require('cesium'); +var removeObject = require('./removeObject'); var defined = Cesium.defined; -var removeObject = require('./removeObject'); - module.exports = removeUnusedShaders; /** diff --git a/lib/removeUnusedTextures.js b/lib/removeUnusedTextures.js index 2f86506c..d969e8be 100755 --- a/lib/removeUnusedTextures.js +++ b/lib/removeUnusedTextures.js @@ -1,10 +1,9 @@ 'use strict'; var Cesium = require('cesium'); +var removeObject = require('./removeObject'); var defined = Cesium.defined; -var removeObject = require('./removeObject'); - module.exports = removeUnusedTextures; /** diff --git a/package.json b/package.json index d17f4f98..dc35a1db 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ }, "devDependencies": { "coveralls": "2.11.9", - "glob": "7.0.5", "gulp": "3.9.1", "gulp-jshint": "2.0.1", "istanbul": "0.4.4", From 0b22358bc9401b370ba6f5bd6a6e46f80590f31b Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Fri, 12 Aug 2016 14:17:01 -0400 Subject: [PATCH 07/21] Add pipeline notes to the functions that need them --- lib/AccessorReader.js | 4 ++++ lib/addDefaults.js | 4 ++++ lib/bakeAmbientOcclusion.js | 4 ++++ lib/cacheOptimization.js | 4 ++++ lib/combineMeshes.js | 4 ++++ lib/combineNodes.js | 4 ++++ lib/compressIntegerAccessors.js | 4 ++++ lib/compressTextureCoordinates.js | 4 ++++ lib/convertDagToTree.js | 4 ++++ lib/encodeImages.js | 4 ++++ lib/findAccessorMinMax.js | 4 ++++ lib/generateNormals.js | 4 ++++ lib/getBinaryGltf.js | 4 ++++ lib/loadGltfUris.js | 3 +++ lib/mergeBuffers.js | 4 ++++ lib/mergeDuplicateAccessors.js | 4 ++++ lib/mergeDuplicateVertices.js | 4 ++++ lib/octEncodeNormals.js | 4 ++++ lib/quantizeAttributes.js | 4 ++++ lib/readAccessor.js | 4 ++++ lib/uninterleaveAndPackBuffers.js | 4 ++++ lib/writeAccessor.js | 4 ++++ lib/writeBinaryGltf.js | 4 ++++ lib/writeGltf.js | 4 ++++ 24 files changed, 95 insertions(+) diff --git a/lib/AccessorReader.js b/lib/AccessorReader.js index 8ba14f38..743b7873 100644 --- a/lib/AccessorReader.js +++ b/lib/AccessorReader.js @@ -17,6 +17,10 @@ module.exports = AccessorReader; * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} accessor The accessor object from glTF to read. * @constructor + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function AccessorReader(gltf, accessor) { var bufferViews = gltf.bufferViews; diff --git a/lib/addDefaults.js b/lib/addDefaults.js index 9ff51790..2fdf3247 100644 --- a/lib/addDefaults.js +++ b/lib/addDefaults.js @@ -510,6 +510,10 @@ function textureDefaults(gltf) { * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} [options={}] * @returns {Object} The modified glTF. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function addDefaults(gltf, options) { options = defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT); diff --git a/lib/bakeAmbientOcclusion.js b/lib/bakeAmbientOcclusion.js index 0bd1e029..e5392f82 100644 --- a/lib/bakeAmbientOcclusion.js +++ b/lib/bakeAmbientOcclusion.js @@ -70,6 +70,10 @@ var computeAmbientOcclusionAtScratch = new ComputeAmbientOcclusionAtOptions(); * @param {Number} [aoOptions.nearCull=0.0001] Near cull depth for ray-triangle collisions. Specified in scene space coordinates. * @param {String} [aoOptions.shaderMode='blend'] How should the shader use per-vertex AO? Valid settings are multiply, replace, and blend. * @param {String} [aoOptions.scene=aoOptions.gltfWithExtras.scene] Which scene to use when baking AO. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function bakeAmbientOcclusion(aoOptions) { var options = generateOptions(aoOptions); diff --git a/lib/cacheOptimization.js b/lib/cacheOptimization.js index e272c569..eba632d5 100644 --- a/lib/cacheOptimization.js +++ b/lib/cacheOptimization.js @@ -70,6 +70,10 @@ function getIndependentPrimitive(dictionary, indicesId, attributeAccessors) { * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Number} [cacheSize=24] The cacheSize to use for Cesium.GeometryPipeline.reorderForPostVertexCache. * @returns {Object} gltf with cache-optimized primitives. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function cacheOptimization(gltf, cacheSize) { // perform post vertex cache optimization diff --git a/lib/combineMeshes.js b/lib/combineMeshes.js index 86d2d2fc..22831b4a 100755 --- a/lib/combineMeshes.js +++ b/lib/combineMeshes.js @@ -11,6 +11,10 @@ module.exports = combineMeshes; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} gltf with combined meshes + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function combineMeshes(gltf) { var nodes = gltf.nodes; diff --git a/lib/combineNodes.js b/lib/combineNodes.js index ab552fc8..a9638050 100644 --- a/lib/combineNodes.js +++ b/lib/combineNodes.js @@ -28,6 +28,10 @@ var scratchTransform = new Matrix4(); * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} gltf with combined meshes + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function combineNodes(gltf) { var nodes = gltf.nodes; diff --git a/lib/compressIntegerAccessors.js b/lib/compressIntegerAccessors.js index 9840abd6..6ebb2491 100644 --- a/lib/compressIntegerAccessors.js +++ b/lib/compressIntegerAccessors.js @@ -48,6 +48,10 @@ var unsignedComponentTypes = [ * @param {Object} [options] Options defining custom behavior. * @param {Array} [options.semantics] An array of semantics to compress. * @returns {Promise} A promise that resolves to gltf with compressed integer accessors. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function compressIntegerAccessors(gltf, options) { var semantics = defaultValue(options.semantics, []); diff --git a/lib/compressTextureCoordinates.js b/lib/compressTextureCoordinates.js index 4d980886..da67f7f2 100644 --- a/lib/compressTextureCoordinates.js +++ b/lib/compressTextureCoordinates.js @@ -26,6 +26,10 @@ module.exports = compressTextureCoordinates; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Promise} A promise that resolves to gltf with compressed texture coordinates. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function compressTextureCoordinates(gltf) { return new Promise(function(resolve) { diff --git a/lib/convertDagToTree.js b/lib/convertDagToTree.js index 6a4889e1..c99319a3 100755 --- a/lib/convertDagToTree.js +++ b/lib/convertDagToTree.js @@ -12,6 +12,10 @@ module.exports = convertDagToTree; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} gltf with any DAGs resolved to trees. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function convertDagToTree(gltf) { var scenes = gltf.scenes; diff --git a/lib/encodeImages.js b/lib/encodeImages.js index ade4e6d9..4d4206f3 100644 --- a/lib/encodeImages.js +++ b/lib/encodeImages.js @@ -11,6 +11,10 @@ module.exports = encodeImages; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Promise} A promise that resolves to gltf when encoding is complete for all images. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function encodeImages(gltf) { var images = gltf.images; diff --git a/lib/findAccessorMinMax.js b/lib/findAccessorMinMax.js index ff1ab616..57812d5b 100644 --- a/lib/findAccessorMinMax.js +++ b/lib/findAccessorMinMax.js @@ -16,6 +16,10 @@ module.exports = findAccessorMinMax; * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} accessor The accessor object from gltf to read. * @returns {{min: Array, max: Array}} min holding the array of minimum values and max holding the array of maximum values. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function findAccessorMinMax(gltf, accessor) { var bufferViews = gltf.bufferViews; diff --git a/lib/generateNormals.js b/lib/generateNormals.js index db5b407d..28c707ad 100644 --- a/lib/generateNormals.js +++ b/lib/generateNormals.js @@ -14,6 +14,10 @@ module.exports = generateNormals; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} gltf with generated normals. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function generateNormals(gltf) { var primitives = getPrimitives(gltf); diff --git a/lib/getBinaryGltf.js b/lib/getBinaryGltf.js index 496252a4..a9db8b69 100644 --- a/lib/getBinaryGltf.js +++ b/lib/getBinaryGltf.js @@ -65,6 +65,10 @@ function updateBinaryObject(gltf, pipelineExtras, name, state) { * @param {Boolean} embed Embed shaders into the binary. * @param {Boolean} embedImage Embed images into the binary * @returns {{glb: Buffer, header: Buffer, scene: Buffer, body: Buffer}} glb holds the whole buffer, each piece is also available via the returned object. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function getBinaryGltf(gltf, embed, embedImage) { // Create the special binary buffer from the existing buffers diff --git a/lib/loadGltfUris.js b/lib/loadGltfUris.js index 93b93baf..c575e1d6 100644 --- a/lib/loadGltfUris.js +++ b/lib/loadGltfUris.js @@ -24,6 +24,9 @@ module.exports = loadGltfUris; * @param {Object} options Options for loading uris. * @param {String} options.basePath The path to look in when loading external files. * @returns {Promise} A promise that resolves to gltf when all uris are loaded. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras */ function loadGltfUris(gltf, options) { var basePath = options.basePath; diff --git a/lib/mergeBuffers.js b/lib/mergeBuffers.js index eb3e6c7c..e3eaabc8 100755 --- a/lib/mergeBuffers.js +++ b/lib/mergeBuffers.js @@ -13,6 +13,10 @@ module.exports = mergeBuffers; * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {String} bufferName The id to use for the combined buffer. * @returns {Object} gltf with one combined buffer. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function mergeBuffers(gltf, bufferName) { var buffers = gltf.buffers; diff --git a/lib/mergeDuplicateAccessors.js b/lib/mergeDuplicateAccessors.js index 28bfda32..393d1427 100644 --- a/lib/mergeDuplicateAccessors.js +++ b/lib/mergeDuplicateAccessors.js @@ -14,6 +14,10 @@ module.exports = mergeDuplicateAccessors; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} gltf with merged duplicate accessors. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function mergeDuplicateAccessors(gltf) { var accessors = gltf.accessors; diff --git a/lib/mergeDuplicateVertices.js b/lib/mergeDuplicateVertices.js index 2fdf283d..2c3f1c26 100644 --- a/lib/mergeDuplicateVertices.js +++ b/lib/mergeDuplicateVertices.js @@ -17,6 +17,10 @@ module.exports = mergeDuplicateVertices; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} gltf with merged duplicate vertices. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function mergeDuplicateVertices(gltf) { var meshes = gltf.meshes; diff --git a/lib/octEncodeNormals.js b/lib/octEncodeNormals.js index 8f44a1fa..51ae52a5 100644 --- a/lib/octEncodeNormals.js +++ b/lib/octEncodeNormals.js @@ -26,6 +26,10 @@ module.exports = octEncodeNormals; * * @param {Object} gltf A glTF hierarchy. * @returns {Promise} A promise that resolves to gltf when the operation completes. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function octEncodeNormals(gltf) { return new Promise(function(resolve) { diff --git a/lib/quantizeAttributes.js b/lib/quantizeAttributes.js index db144484..e5c95387 100644 --- a/lib/quantizeAttributes.js +++ b/lib/quantizeAttributes.js @@ -28,6 +28,10 @@ module.exports = quantizeAttributes; * * @returns glTF with quantized attributes * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris + * * @example * // Quantize all valid attributes * quantizeAttributes(gltf); diff --git a/lib/readAccessor.js b/lib/readAccessor.js index afbe4446..145b7c7d 100644 --- a/lib/readAccessor.js +++ b/lib/readAccessor.js @@ -21,6 +21,10 @@ module.exports = readAccessor; * @param {Object} accessor The glTF accessor to read. * @param {Array} results The resulting Cesium data structures are pushed into results. * @returns {Number} The WebGLConstants type used to generate the Cesium data structures. (e.g. WebGLConstants.FLOAT_VEC3 for Cartesian3) + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function readAccessor(gltf, accessor, results) { var generateAttributeFunction; diff --git a/lib/uninterleaveAndPackBuffers.js b/lib/uninterleaveAndPackBuffers.js index 3cfe6df4..fcd03e7f 100644 --- a/lib/uninterleaveAndPackBuffers.js +++ b/lib/uninterleaveAndPackBuffers.js @@ -17,6 +17,10 @@ module.exports = uninterleaveAndPackBuffers; * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} gltf with repacked buffers. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function uninterleaveAndPackBuffers(gltf) { var accessors = gltf.accessors; diff --git a/lib/writeAccessor.js b/lib/writeAccessor.js index d0521627..daa99dcc 100644 --- a/lib/writeAccessor.js +++ b/lib/writeAccessor.js @@ -10,6 +10,10 @@ module.exports = writeAccessor; * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} accessor glTF accessor where data should be written. * @param {Array} dataArray Data to write into the accessor. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function writeAccessor(gltf, accessor, dataArray) { var accessorReader = new AccessorReader(gltf, accessor); diff --git a/lib/writeBinaryGltf.js b/lib/writeBinaryGltf.js index 4c9ba89c..56239cc2 100644 --- a/lib/writeBinaryGltf.js +++ b/lib/writeBinaryGltf.js @@ -24,6 +24,10 @@ module.exports = writeBinaryGltf; * @param {Boolean} options.embedImage Flag to embed image uris. * @param {Boolean} options.createDirectory If true, a directory named 'output' will be created at options.outputPath and the output will be written there. * @returns {Promise} A promise resolving when the write operation completes. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function writeBinaryGltf(gltf, options) { var outputPath = options.outputPath; diff --git a/lib/writeGltf.js b/lib/writeGltf.js index b4b93bfb..7f6a72e0 100755 --- a/lib/writeGltf.js +++ b/lib/writeGltf.js @@ -24,6 +24,10 @@ module.exports = writeGltf; * @param {Boolean} options.embedImage Flag to embed image uris. * @param {Boolean} options.createDirectory If true, a directory named 'output' will be created at options.outputPath and the output will be written there. * @returns {Promise} A promise resolving when the write operation completes. + * + * gltf must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function writeGltf(gltf, options) { var outputPath = options.outputPath; From a880aab2b28d99ed4558216613658e8b97b02509 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Fri, 12 Aug 2016 14:24:35 -0400 Subject: [PATCH 08/21] Added reference doc for options --- lib/gltfPipeline.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/gltfPipeline.js b/lib/gltfPipeline.js index 05e8d16c..d444a324 100644 --- a/lib/gltfPipeline.js +++ b/lib/gltfPipeline.js @@ -59,6 +59,10 @@ function writeSources(gltf) { * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} options Options to apply to stages during optimization. * @returns {Promise} A promise that resolves to the processed gltf. + * + * options is passed to the functions called by this one + * @see loadGltfUris + * @see processJSONWithExtras */ function processJSON(gltf, options) { addPipelineExtras(gltf); @@ -76,6 +80,10 @@ function processJSON(gltf, options) { * * @param {Object} gltfWithExtras A javascript object holding a glTF hierarchy with extras. * @param {Object} options Options to apply to stages during optimization. + * @param {Object} [options.aoOptions=undefined] Options to pass to the bakeAmbientOcclusion stage, if undefined, stage is not run. + * @param {Object} [options.encodeNormals=false] Flag to run octEncodeNormals stage. + * @param {Object} [options.compressTextureCoordinates=false] Flag to run compressTextureCoordinates stage. + * @param {Object} [options.quantize] Flag to run quantizeAttributes stage. * @returns {Promise} A promise that resolves to the processed gltf. */ function processJSONWithExtras(gltfWithExtras, options) { @@ -177,6 +185,12 @@ function writeFile(gltf, outputPath, options) { * @param {String} outputPath The output file destination. * @param {Object} options Options to apply to stages during optimization. * @returns {Promise} A promise that resolves when the operation is complete. + * + * options is passed to the functions called by this one + * @see loadGltfUris + * @see processJSONWithExtras + * @see writeGltf + * @see writeBinaryGltf */ function processJSONToDisk(gltf, outputPath, options) { addPipelineExtras(gltf); @@ -196,6 +210,12 @@ function processJSONToDisk(gltf, outputPath, options) { * @param {String} outputPath The output file destination * @param {Object} options Options to apply to stages during optimization. * @returns {Promise} A promise that resolves when the operation is complete. + * + * options is passed to the functions called by this one + * @see processJSONWithExtras + * @see readGltf + * @see writeGltf + * @see writeBinaryGltf */ function processFileToDisk(inputPath, outputPath, options) { return readGltf(inputPath, options) From 8d43261db463e0f4b5cc0539563f66fb3a8432c8 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Fri, 12 Aug 2016 14:26:43 -0400 Subject: [PATCH 09/21] Added computeFlatTransformScene pipeline note --- lib/NodeHelpers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/NodeHelpers.js b/lib/NodeHelpers.js index 27bd0f91..946c0ca6 100644 --- a/lib/NodeHelpers.js +++ b/lib/NodeHelpers.js @@ -41,6 +41,10 @@ function flattenTransform(parameters, node, parent) { * * @param {Object} scene The glTF scene to traverse. * @param {Object} nodes glTF top-level nodes object. + * + * scene and nodes must be initialized for the pipeline. + * @see addPipelineExtras + * @see loadGltfUris */ function computeFlatTransformScene(scene, nodes) { var rootNodeIDs = scene.nodes; From c58e5de2e07b3b6b17c0ca27ab0f8a1e72c9b492 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Tue, 16 Aug 2016 16:33:00 -0400 Subject: [PATCH 10/21] Wrap objects with scope to have names for doc, remove OptimizationStatistics --- lib/AccessorReader.js | 4 +- ...mbientOcclusion.js => AmbientOcclusion.js} | 25 +- lib/GeometryMath.js | 34 +- lib/OptimizationStatistics.js | 22 - lib/{gltfPipeline.js => Pipeline.js} | 150 +- lib/RemoveUnusedElements.js | 419 ++++++ lib/StaticUniformGrid.js | 1 + lib/combineNodes.js | 2 +- lib/loadGltfUris.js | 9 +- lib/removeObject.js | 9 +- lib/removeUnused.js | 46 - lib/removeUnusedAccessors.js | 72 - lib/removeUnusedBufferViews.js | 18 - lib/removeUnusedBuffers.js | 18 - lib/removeUnusedCameras.js | 17 - lib/removeUnusedImages.js | 18 - lib/removeUnusedMaterials.js | 37 - lib/removeUnusedMeshes.js | 37 - lib/removeUnusedNodes.js | 53 - lib/removeUnusedPrimitiveAttributes.js | 57 - lib/removeUnusedPrograms.js | 18 - lib/removeUnusedSamplers.js | 17 - lib/removeUnusedShaders.js | 33 - lib/removeUnusedSkins.js | 17 - lib/removeUnusedTechniques.js | 17 - lib/removeUnusedTextures.js | 61 - lib/triangleAxisAlignedBoundingBoxOverlap.js | 10 +- ...clusionSpec.js => AmbientOcclusionSpec.js} | 42 +- .../{gltfPipelineSpec.js => PipelineSpec.js} | 12 +- specs/lib/RemoveUnusedElementsSpec.js | 1311 +++++++++++++++++ specs/lib/getBinaryGltfSpec.js | 1 - specs/lib/removeObjectSpec.js | 13 +- specs/lib/removeUnusedAccessorsSpec.js | 148 -- specs/lib/removeUnusedBufferViewsSpec.js | 68 - specs/lib/removeUnusedBuffersSpec.js | 61 - specs/lib/removeUnusedCamerasSpec.js | 67 - specs/lib/removeUnusedImagesSpec.js | 62 - specs/lib/removeUnusedMaterialsSpec.js | 72 - specs/lib/removeUnusedMeshesSpec.js | 47 - specs/lib/removeUnusedNodesSpec.js | 165 --- specs/lib/removeUnusedProgramsSpec.js | 107 -- specs/lib/removeUnusedSamplersSpec.js | 68 - specs/lib/removeUnusedShadersSpec.js | 73 - specs/lib/removeUnusedSkinsSpec.js | 58 - specs/lib/removeUnusedSpec.js | 108 -- specs/lib/removeUnusedTechniquesSpec.js | 126 -- specs/lib/removeUnusedTexturesSpec.js | 148 -- .../removedUnusedPrimitiveAttributesSpec.js | 54 - specs/lib/writeBinaryGltfSpec.js | 1 - 49 files changed, 1895 insertions(+), 2138 deletions(-) rename lib/{bakeAmbientOcclusion.js => AmbientOcclusion.js} (98%) delete mode 100644 lib/OptimizationStatistics.js rename lib/{gltfPipeline.js => Pipeline.js} (81%) create mode 100644 lib/RemoveUnusedElements.js delete mode 100644 lib/removeUnused.js delete mode 100755 lib/removeUnusedAccessors.js delete mode 100755 lib/removeUnusedBufferViews.js delete mode 100755 lib/removeUnusedBuffers.js delete mode 100755 lib/removeUnusedCameras.js delete mode 100644 lib/removeUnusedImages.js delete mode 100755 lib/removeUnusedMaterials.js delete mode 100755 lib/removeUnusedMeshes.js delete mode 100755 lib/removeUnusedNodes.js delete mode 100644 lib/removeUnusedPrimitiveAttributes.js delete mode 100755 lib/removeUnusedPrograms.js delete mode 100644 lib/removeUnusedSamplers.js delete mode 100755 lib/removeUnusedShaders.js delete mode 100755 lib/removeUnusedSkins.js delete mode 100755 lib/removeUnusedTechniques.js delete mode 100755 lib/removeUnusedTextures.js rename specs/lib/{bakeAmbientOcclusionSpec.js => AmbientOcclusionSpec.js} (94%) rename specs/lib/{gltfPipelineSpec.js => PipelineSpec.js} (95%) create mode 100644 specs/lib/RemoveUnusedElementsSpec.js delete mode 100755 specs/lib/removeUnusedAccessorsSpec.js delete mode 100755 specs/lib/removeUnusedBufferViewsSpec.js delete mode 100755 specs/lib/removeUnusedBuffersSpec.js delete mode 100755 specs/lib/removeUnusedCamerasSpec.js delete mode 100644 specs/lib/removeUnusedImagesSpec.js delete mode 100755 specs/lib/removeUnusedMaterialsSpec.js delete mode 100755 specs/lib/removeUnusedMeshesSpec.js delete mode 100755 specs/lib/removeUnusedNodesSpec.js delete mode 100755 specs/lib/removeUnusedProgramsSpec.js delete mode 100644 specs/lib/removeUnusedSamplersSpec.js delete mode 100755 specs/lib/removeUnusedShadersSpec.js delete mode 100755 specs/lib/removeUnusedSkinsSpec.js delete mode 100644 specs/lib/removeUnusedSpec.js delete mode 100755 specs/lib/removeUnusedTechniquesSpec.js delete mode 100755 specs/lib/removeUnusedTexturesSpec.js delete mode 100644 specs/lib/removedUnusedPrimitiveAttributesSpec.js diff --git a/lib/AccessorReader.js b/lib/AccessorReader.js index 743b7873..8ab39c3b 100644 --- a/lib/AccessorReader.js +++ b/lib/AccessorReader.js @@ -13,12 +13,12 @@ module.exports = AccessorReader; /** * Reads an accessor incrementally. This is useful to keep overhead low when * memory consumption is important. + * glTF must be initialized for the pipeline. * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} accessor The accessor object from glTF to read. * @constructor * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ @@ -99,7 +99,7 @@ AccessorReader.prototype.write = function(data, componentType, dataOffset) { /** * Get if the AccessorReader is at the end of the accessor data. * - * @returns {Boolean} true if there is more data to read, false if not. + * @returns {Boolean} True if there is more data to read, false if not. */ AccessorReader.prototype.hasNext = function() { return this.index < this.count; diff --git a/lib/bakeAmbientOcclusion.js b/lib/AmbientOcclusion.js similarity index 98% rename from lib/bakeAmbientOcclusion.js rename to lib/AmbientOcclusion.js index e5392f82..094c6f6c 100644 --- a/lib/bakeAmbientOcclusion.js +++ b/lib/AmbientOcclusion.js @@ -24,7 +24,7 @@ var NodeHelpers = require('./NodeHelpers'); var readAccessor = require('./readAccessor'); var StaticUniformGrid = require('./StaticUniformGrid'); -module.exports = { +/*module.exports = { bakeAmbientOcclusion: bakeAmbientOcclusion, // For unit testing: generateOptions: generateOptions, @@ -34,7 +34,7 @@ module.exports = { raytraceOverTriangleSamples: raytraceOverTriangleSamples, extractInstructionWithFunctionCall: extractInstructionWithFunctionCall, injectGlslAfterInstructionContaining: injectGlslAfterInstructionContaining -}; +};*/ var scratchRay = new Ray(); var barycentricCoordinateScratch = new Cartesian3(); @@ -47,6 +47,14 @@ var matrix4Scratch = new Matrix4(); var trianglePixelMarchScratch = new TrianglePixelMarchOptions(); var computeAmbientOcclusionAtScratch = new ComputeAmbientOcclusionAtOptions(); +module.exports = AmbientOcclusion; + +/** + * Pipeline stage and utilities for generating ambient occlusion. + * @constructor + */ +function AmbientOcclusion() {} + /** * Bakes ambient occlusion (AO) to all models in a specific scene of the gltf. * @@ -75,7 +83,7 @@ var computeAmbientOcclusionAtScratch = new ComputeAmbientOcclusionAtOptions(); * @see addPipelineExtras * @see loadGltfUris */ -function bakeAmbientOcclusion(aoOptions) { +AmbientOcclusion.bakeAmbientOcclusion = function(aoOptions) { var options = generateOptions(aoOptions); var gltf = aoOptions.gltfWithExtras; @@ -112,7 +120,16 @@ function bakeAmbientOcclusion(aoOptions) { ambientShadowContribution : options.ambientShadowContribution }); } -} +}; + +AmbientOcclusion.generateOptions = generateOptions; +AmbientOcclusion.generateRaytracerScene = generateRaytracerScene; +AmbientOcclusion.computeAmbientOcclusionAt = computeAmbientOcclusionAt; +AmbientOcclusion.raytraceAtTriangleCenters = raytraceAtTriangleCenters; +AmbientOcclusion.raytraceOverTriangleSamples = raytraceOverTriangleSamples; +AmbientOcclusion.extractInstructionWithFunctionCall = extractInstructionWithFunctionCall; +AmbientOcclusion.injectGlslAfterInstructionContaining = injectGlslAfterInstructionContaining; + function generateOptions(aoOptions) { if (!defined(aoOptions.gltfWithExtras)) { diff --git a/lib/GeometryMath.js b/lib/GeometryMath.js index 28b28484..e6b165eb 100644 --- a/lib/GeometryMath.js +++ b/lib/GeometryMath.js @@ -1,16 +1,18 @@ 'use strict'; var Cesium = require('cesium'); + var Cartesian3 = Cesium.Cartesian3; var defined = Cesium.defined; var DeveloperError = Cesium.DeveloperError; -module.exports = { - sumCartesian3sBarycentric: sumCartesian3sBarycentric, - flattenTriangle: flattenTriangle, - pointLineDistanceParametric: pointLineDistanceParametric -}; +module.exports = GeometryMath; -// Functions for working with geometry like triangles and lines +/** + * Functions for working with geometry, like triangles and lines. + * @constructor + * @private + */ +function GeometryMath() {} var sumBarycentricScratch = new Cartesian3(); /** @@ -23,7 +25,7 @@ var sumBarycentricScratch = new Cartesian3(); * @param {Cartesian3} result The object onto which to store the result. * @returns {Cartesian3} The modified result parameter. */ -function sumCartesian3sBarycentric(barycentric, vector0, vector1, vector2, result) { +GeometryMath.sumCartesian3sBarycentric = function(barycentric, vector0, vector1, vector2, result) { if (!defined(barycentric)) { throw new DeveloperError('barycentric is required'); } @@ -50,7 +52,7 @@ function sumCartesian3sBarycentric(barycentric, vector0, vector1, vector2, resul Cartesian3.multiplyByScalar(vector2, barycentric.z, sumBarycentricScratch); Cartesian3.add(result, sumBarycentricScratch, result); return result; -} +}; var pointOnLineScratch = new Cartesian3(); /** @@ -62,7 +64,7 @@ var pointOnLineScratch = new Cartesian3(); * @param {Cartesian3} lineDirection A direction specifying the line's orientation. * @returns {Number} The parametric position on the line closest to the given point. */ -function pointLineDistanceParametric(point, linePosition, lineDirection) { +GeometryMath.pointLineDistanceParametric = function(point, linePosition, lineDirection) { if (!defined(point)) { throw new DeveloperError('point is required'); } @@ -78,7 +80,7 @@ function pointLineDistanceParametric(point, linePosition, lineDirection) { var p3 = point; var length2 = Cartesian3.magnitudeSquared(lineDirection); return ((p3.x - p1.x) * (p2.x - p1.x) + (p3.y - p1.y) * (p2.y - p1.y) + (p3.z - p1.z) * (p2.z - p1.z)) / length2; -} +}; var xAxis = new Cartesian3(); var zAxis = new Cartesian3(); @@ -90,7 +92,7 @@ var yAxis = new Cartesian3(); * @param {Cartesian2[]} results The objects onto which to store the results. * @returns {Cartesian2[]} The triangle's vertex positions in its own plane. */ -function flattenTriangle(positions, results) { +GeometryMath.flattenTriangle = function(positions, results) { if (!defined(positions)) { throw new DeveloperError('positions is required'); } @@ -111,10 +113,10 @@ function flattenTriangle(positions, results) { // Compute x/y coordinates by getting distance to normalized x and y axes in 3D results[0].x = 0.0; results[0].y = 0.0; - results[1].x = pointLineDistanceParametric(positions[1], positions[0], xAxis); - results[1].y = pointLineDistanceParametric(positions[1], positions[0], yAxis); - results[2].x = pointLineDistanceParametric(positions[2], positions[0], xAxis); - results[2].y = pointLineDistanceParametric(positions[2], positions[0], yAxis); + results[1].x = GeometryMath.pointLineDistanceParametric(positions[1], positions[0], xAxis); + results[1].y = GeometryMath.pointLineDistanceParametric(positions[1], positions[0], yAxis); + results[2].x = GeometryMath.pointLineDistanceParametric(positions[2], positions[0], xAxis); + results[2].y = GeometryMath.pointLineDistanceParametric(positions[2], positions[0], yAxis); return results; -} +}; diff --git a/lib/OptimizationStatistics.js b/lib/OptimizationStatistics.js deleted file mode 100644 index d823d043..00000000 --- a/lib/OptimizationStatistics.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -module.exports = OptimizationStatistics; - -function OptimizationStatistics() { - this.numberRemoved = { - nodes : 0, - skins : 0, - cameras : 0, - meshes : 0, - accessors : 0, - materials : 0, - bufferViews : 0, - techniques : 0, - textures : 0, - buffers : 0, - programs : 0, - images : 0, - samplers : 0, - shaders : 0 - }; -} diff --git a/lib/gltfPipeline.js b/lib/Pipeline.js similarity index 81% rename from lib/gltfPipeline.js rename to lib/Pipeline.js index d444a324..817a3b80 100644 --- a/lib/gltfPipeline.js +++ b/lib/Pipeline.js @@ -3,10 +3,10 @@ var Cesium = require('cesium'); var Promise = require('bluebird'); var path = require('path'); -var OptimizationStatistics = require('./OptimizationStatistics'); +var AmbientOcclusion = require('./AmbientOcclusion'); +var RemoveUnusedElements = require('./RemoveUnusedElements'); var addDefaults = require('./addDefaults'); var addPipelineExtras = require('./addPipelineExtras'); -var bakeAmbientOcclusion = require('./bakeAmbientOcclusion').bakeAmbientOcclusion; var cacheOptimization = require('./cacheOptimization'); var combineMeshes = require('./combineMeshes'); var combineNodes = require('./combineNodes'); @@ -22,7 +22,6 @@ var mergeDuplicateAccessors = require('./mergeDuplicateAccessors'); var octEncodeNormals = require('./octEncodeNormals'); var readGltf = require('./readGltf'); var removeDuplicatePrimitives = require('./removeDuplicatePrimitives'); -var removeUnused = require('./removeUnused'); var quantizeAttributes = require('./quantizeAttributes'); var writeGltf = require('./writeGltf'); var writeBinaryGltf = require('./writeBinaryGltf'); @@ -31,49 +30,38 @@ var writeSource = require('./writeSource'); var defaultValue = Cesium.defaultValue; var defined = Cesium.defined; -module.exports = { - processJSON : processJSON, - processJSONWithExtras : processJSONWithExtras, - processFile : processFile, - processJSONToDisk : processJSONToDisk, - processFileToDisk : processFileToDisk -}; +var bakeAmbientOcclusion = AmbientOcclusion.bakeAmbientOcclusion; +var removeAllUnused = RemoveUnusedElements.removeAllUnused; -function writeSources(gltf) { - var embed = true; - var embedImage = true; - var writeSourcePromises = [ - writeSource(gltf, undefined, 'buffers', embed, embedImage), - writeSource(gltf, undefined, 'images', embed, embedImage), - writeSource(gltf, undefined, 'shaders', embed, embedImage) - ]; - return Promise.all(writeSourcePromises) - .then(function() { - return gltf; - }); -} +module.exports = Pipeline; + +/** + * Main optimization pipeline. + * @constructor + */ +function Pipeline() {} /** * Add pipeline extras and load uris, then process the gltf. + * Options are passed to loadGltfUris and processJSONWithExtras. * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} options Options to apply to stages during optimization. * @returns {Promise} A promise that resolves to the processed gltf. * - * options is passed to the functions called by this one * @see loadGltfUris - * @see processJSONWithExtras + * @see Pipeline.processJSONWithExtras */ -function processJSON(gltf, options) { +Pipeline.processJSON = function(gltf, options) { addPipelineExtras(gltf); return loadGltfUris(gltf, options) .then(function(gltf) { - return processJSONWithExtras(gltf, options); + return Pipeline.processJSONWithExtras(gltf, options); }) .then(function(gltf) { return writeSources(gltf); }); -} +}; /** * Process a gltf that already has extras and loaded uris. @@ -86,13 +74,9 @@ function processJSON(gltf, options) { * @param {Object} [options.quantize] Flag to run quantizeAttributes stage. * @returns {Promise} A promise that resolves to the processed gltf. */ -function processJSONWithExtras(gltfWithExtras, options) { - var stats = new OptimizationStatistics(); +Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { addDefaults(gltfWithExtras, options); - removeUnused(gltfWithExtras, stats); - if (options.printStats) { - printStats(stats); - } + removeAllUnused(gltfWithExtras); // It is generally better to merge the duplicate vertices before merging accessors. // Once accessors merge, there is more likely to be overlap in accessor usage between primitives // which limits the effectiveness of merging duplicate vertices. @@ -108,7 +92,7 @@ function processJSONWithExtras(gltfWithExtras, options) { // Merging duplicate vertices again to prevent repeat data in newly combined primitives // mergeDuplicateVertices(gltfWithExtras); cacheOptimization(gltfWithExtras); - + // run AO after cacheOptimization since AO adds new attributes. var aoOptions = options.aoOptions; if (defined(aoOptions)) { @@ -116,8 +100,8 @@ function processJSONWithExtras(gltfWithExtras, options) { bakeAmbientOcclusion(aoOptions); } - // Run removeUnused stage again after all pipeline stages have been run to remove objects that become unused - removeUnused(gltfWithExtras); + // Run removeAllUnused stage again after all pipeline stages have been run to remove objects that become unused + removeAllUnused(gltfWithExtras); var waitForStages = [new Promise(function(resolve) {resolve();})]; if (options.encodeNormals) { waitForStages.push(octEncodeNormals(gltfWithExtras)); @@ -146,85 +130,109 @@ function processJSONWithExtras(gltfWithExtras, options) { // Remove duplicates again after all stages to minimize the buffer size mergeDuplicateVertices(gltfWithExtras); return encodeImages(gltfWithExtras); - }); -} + }); +}; -function processFile(inputPath, options) { +/** + * Process a gltf on disk into memory. + * Options are passed to processJSONWithExtras. + * + * @param {String} inputPath The input file path. + * @param {Object} options Options to apply tos tages during optimization. + * @returns {Object} The processed gltf. + * + * @see Pipeline.processJSONWithExtras + */ +Pipeline.processFile =function processFile(inputPath, options) { return readGltf(inputPath, options) .then(function(gltf) { - return processJSONWithExtras(gltf, options); + return Pipeline.processJSONWithExtras(gltf, options); }) .then(function(gltf) { return writeSources(gltf); }); -} - -function writeFile(gltf, outputPath, options) { - var fileExtension = path.extname(outputPath); - var binary = defaultValue(options.binary, false); - var embed = defaultValue(options.embed, true); - var embedImage = defaultValue(options.embedImage, true); - var createDirectory = defaultValue(options.createDirectory, true); - var writeOptions = { - outputPath : outputPath, - embed : embed, - embedImage : embedImage, - createDirectory : createDirectory - }; - - if (binary || fileExtension === '.glb') { - return writeBinaryGltf(gltf, writeOptions); - } - return writeGltf(gltf, writeOptions); -} +}; /** * Process a gltf in memory and writes it out to disk. + * Options are passed to loadGltfUris, processJSONWithExtras, writeGltf, and writeBinaryGltf. * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {String} outputPath The output file destination. * @param {Object} options Options to apply to stages during optimization. * @returns {Promise} A promise that resolves when the operation is complete. * - * options is passed to the functions called by this one * @see loadGltfUris - * @see processJSONWithExtras + * @see Pipeline.processJSONWithExtras * @see writeGltf * @see writeBinaryGltf */ -function processJSONToDisk(gltf, outputPath, options) { +Pipeline.processJSONToDisk = function(gltf, outputPath, options) { addPipelineExtras(gltf); return loadGltfUris(gltf, options) .then(function(gltf) { - return processJSONWithExtras(gltf, options); + return Pipeline.processJSONWithExtras(gltf, options); }) .then(function(gltf) { return writeFile(gltf, outputPath, options); }); -} +}; /** * Processes a gltf on disk and writes it out to disk. + * Options are passed to processJSONWithExtras, readGltf, writeGltf, and writeBinaryGltf. * * @param {String} inputPath The input file path. * @param {String} outputPath The output file destination * @param {Object} options Options to apply to stages during optimization. * @returns {Promise} A promise that resolves when the operation is complete. * - * options is passed to the functions called by this one - * @see processJSONWithExtras + * @see Pipeline.processJSONWithExtras * @see readGltf * @see writeGltf * @see writeBinaryGltf */ -function processFileToDisk(inputPath, outputPath, options) { +Pipeline.processFileToDisk = function(inputPath, outputPath, options) { return readGltf(inputPath, options) .then(function(gltf) { - return processJSONWithExtras(gltf, options); + return Pipeline.processJSONWithExtras(gltf, options); }) .then(function(gltf) { - return writeFile(gltf, outputPath, options); + return writeFile(gltf, outputPath, options); }); +}; + +function writeSources(gltf) { + var embed = true; + var embedImage = true; + var writeSourcePromises = [ + writeSource(gltf, undefined, 'buffers', embed, embedImage), + writeSource(gltf, undefined, 'images', embed, embedImage), + writeSource(gltf, undefined, 'shaders', embed, embedImage) + ]; + return Promise.all(writeSourcePromises) + .then(function() { + return gltf; + }); +} + +function writeFile(gltf, outputPath, options) { + var fileExtension = path.extname(outputPath); + var binary = defaultValue(options.binary, false); + var embed = defaultValue(options.embed, true); + var embedImage = defaultValue(options.embedImage, true); + var createDirectory = defaultValue(options.createDirectory, true); + var writeOptions = { + outputPath : outputPath, + embed : embed, + embedImage : embedImage, + createDirectory : createDirectory + }; + + if (binary || fileExtension === '.glb') { + return writeBinaryGltf(gltf, writeOptions); + } + return writeGltf(gltf, writeOptions); } function printStats(stats) { diff --git a/lib/RemoveUnusedElements.js b/lib/RemoveUnusedElements.js new file mode 100644 index 00000000..502bb8b0 --- /dev/null +++ b/lib/RemoveUnusedElements.js @@ -0,0 +1,419 @@ +'use strict'; +var Cesium = require('cesium'); +var findUsedIds = require('./findUsedIds'); +var removeObject = require('./removeObject'); + +var defined = Cesium.defined; + +module.exports = RemoveUnusedElements; + +/** + * Contains stages to remove unused glTF elements. + * An unused element is one that is not referred to by any other element. + * @constructor + */ +function RemoveUnusedElements() {} + +/** + * Removes all unused elements in gltf in top-down order so newly unused objects down the hierarchy will be removed as well. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused elements. + */ +RemoveUnusedElements.removeAllUnused = function(gltf) { + RemoveUnusedElements.removeUnusedNodes(gltf); + RemoveUnusedElements.removeUnusedSkins(gltf); + RemoveUnusedElements.removeUnusedCameras(gltf); + RemoveUnusedElements.removeUnusedMeshes(gltf); + RemoveUnusedElements.removeUnusedAccessors(gltf); + RemoveUnusedElements.removeUnusedMaterials(gltf); + RemoveUnusedElements.removeUnusedBufferViews(gltf); + RemoveUnusedElements.removeUnusedTechniques(gltf); + RemoveUnusedElements.removeUnusedTextures(gltf); + RemoveUnusedElements.removeUnusedBuffers(gltf); + RemoveUnusedElements.removeUnusedPrograms(gltf); + RemoveUnusedElements.removeUnusedImages(gltf); + RemoveUnusedElements.removeUnusedSamplers(gltf); + RemoveUnusedElements.removeUnusedShaders(gltf); + RemoveUnusedElements.removeUnusedPrimitiveAttributes(gltf); +}; + +/** + * Remove all unused nodes in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused nodes. + */ +RemoveUnusedElements.removeUnusedNodes = function(gltf) { + var usedNodeIds = {}; + var scenes = gltf.scenes; + var nodes = gltf.nodes; + + // Build hash of used nodes by traversing through node trees starting at scenes + if (defined(scenes)) { + for (var sceneId in scenes) { + if (scenes.hasOwnProperty(sceneId)) { + var roots = scenes[sceneId].nodes; + if (defined(roots)) { + var nodeStack = []; + var rootsLength = roots.length; + for (var i = 0; i < rootsLength; i++) { + var root = roots[i]; + nodeStack.push(root); + } + + while (nodeStack.length > 0) { + var node = nodeStack.pop(); + usedNodeIds[node] = true; + + var children = nodes[node].children; + if (defined(children)) { + var childrenLength = children.length; + for (var j = 0; j < childrenLength; j++) { + var child = children[j]; + nodeStack.push(child); + } + } + } + } + } + } + } + + return removeObject(gltf, 'nodes', usedNodeIds); +}; + +/** + * Remove all unused skins in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused skins. + */ +RemoveUnusedElements.removeUnusedSkins = function(gltf) { + var usedSkinIds = findUsedIds(gltf, 'nodes', 'skin'); + return removeObject(gltf, 'skins', usedSkinIds); +}; + +/** + * Remove all unused cameras in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused cameras. + */ +RemoveUnusedElements.removeUnusedCameras = function(gltf) { + var usedCameraIds = findUsedIds(gltf, 'nodes', 'camera'); + return removeObject(gltf, 'cameras', usedCameraIds); +}; + +/** + * Remove all unused meshes in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused meshes. + */ +RemoveUnusedElements.removeUnusedMeshes = function(gltf) { + var usedMeshIds = {}; + var nodes = gltf.nodes; + + // Build hash of used meshes by iterating through nodes + if (defined(nodes)) { + for (var nodeId in nodes) { + if (nodes.hasOwnProperty(nodeId)) { + if (defined(nodes[nodeId].meshes)) { + var nodeMeshes = nodes[nodeId].meshes; + var length = nodeMeshes.length; + for (var i = 0; i < length; i++) { + var id = nodeMeshes[i]; + usedMeshIds[id] = true; + } + } + } + } + } + return removeObject(gltf, 'meshes', usedMeshIds); +}; + +/** + * Remove all unused accessors in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused accessors. + */ +RemoveUnusedElements.removeUnusedAccessors = function(gltf) { + var usedAccessorIds = {}; + var meshes = gltf.meshes; + var skins = gltf.skins; + var animations = gltf.animations; + + // Build hash of used accessors by iterating through meshes, skins, and animations + if (defined(meshes)) { + for (var meshId in meshes) { + if (meshes.hasOwnProperty(meshId)) { + var primitives = meshes[meshId].primitives; + if (defined(primitives)) { + var length = primitives.length; + for (var i = 0; i < length; i++) { + var attributes = primitives[i].attributes; + if (defined(attributes)) { + for (var attributeId in attributes) { + if (attributes.hasOwnProperty(attributeId)) { + var primitiveAccessorId = attributes[attributeId]; + usedAccessorIds[primitiveAccessorId] = true; + } + } + } + var indicesId = primitives[i].indices; + if (defined(indicesId)) { + usedAccessorIds[indicesId] = true; + } + } + } + } + } + } + if (defined(skins)) { + for (var skinId in skins) { + if (skins.hasOwnProperty(skinId)) { + var skinAccessorId = skins[skinId].inverseBindMatrices; + usedAccessorIds[skinAccessorId] = true; + } + } + } + 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; + } + } + } + } + } + } + return removeObject(gltf, 'accessors', usedAccessorIds); +}; + +/** + * Remove all unused materials in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused images. + */ +RemoveUnusedElements.removeUnusedMaterials = function(gltf) { + var usedMaterialIds = {}; + var meshes = gltf.meshes; + + // Build hash of used materials by iterating through meshes + if (defined(meshes)) { + for (var meshId in meshes) { + if (meshes.hasOwnProperty(meshId)) { + if (defined(meshes[meshId].primitives)) { + var primitives = meshes[meshId].primitives; + var length = primitives.length; + for (var i = 0; i < length; i++) { + var id = primitives[i].material; + usedMaterialIds[id] = true; + } + } + } + } + } + return removeObject(gltf, 'materials', usedMaterialIds); +}; + +/** + * Remove all unused buffer views in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused buffers views. + */ +RemoveUnusedElements.removeUnusedBufferViews = function(gltf) { + var usedBufferViewIds = findUsedIds(gltf, 'accessors', 'bufferView'); + return removeObject(gltf, 'bufferViews', usedBufferViewIds); +}; + +/** + * Remove all unused techniques in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused techniques + */ +RemoveUnusedElements.removeUnusedTechniques = function(gltf) { + var usedTechniqueIds = findUsedIds(gltf, 'materials', 'technique'); + return removeObject(gltf, 'techniques', usedTechniqueIds); +}; + +/** + * Remove all unused textures in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused textures. + */ +RemoveUnusedElements.removeUnusedTextures = function(gltf) { + var usedTextureIds = {}; + var materials = gltf.materials; + var techniques = gltf.techniques; + + // Build hash of used textures by iterating through materials and techniques + if (defined(materials)) { + for (var materialId in materials) { + if (materials.hasOwnProperty(materialId)) { + if (defined(materials[materialId].values)) { + var 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; + } + } + } + } + } + } + } + if (defined(techniques)) { + for (var techniqueId in techniques) { + if (techniques.hasOwnProperty(techniqueId)) { + if (defined(techniques[techniqueId].parameters)) { + 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; + } + } + } + } + } + } + } + } + return removeObject(gltf, 'textures', usedTextureIds); +}; + +/** + * Remove all unused buffers in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused buffers. + */ +RemoveUnusedElements.removeUnusedBuffers = function(gltf) { + var usedBufferIds = findUsedIds(gltf, 'bufferViews', 'buffer'); + return removeObject(gltf, 'buffers', usedBufferIds); +}; + +/** + * Remove all unused programs in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused programs. + */ +RemoveUnusedElements.removeUnusedPrograms = function(gltf) { + var usedProgramIds = findUsedIds(gltf, 'techniques', 'program'); + return removeObject(gltf, 'programs', usedProgramIds); +}; + +/** + * Remove all unused images in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused images. + */ +RemoveUnusedElements.removeUnusedImages = function(gltf) { + var usedImageIds = findUsedIds(gltf, 'textures', 'source'); + return removeObject(gltf, 'images', usedImageIds); +}; + +/** + * Remove all unused samplers in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused samplers. + */ +RemoveUnusedElements.removeUnusedSamplers = function(gltf) { + var usedSamplerIds = findUsedIds(gltf, 'textures', 'sampler'); + return removeObject(gltf, 'samplers', usedSamplerIds); +}; + +/** + * Remove all unused shaders in gltf. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused shaders. + */ +RemoveUnusedElements.removeUnusedShaders = function(gltf) { + var usedShaderIds = {}; + var programs = gltf.programs; + + // Build hash of used shaders by iterating through programs + if (defined(programs)) { + for (var programId in programs) { + if (programs.hasOwnProperty(programId)) { + var fragId = programs[programId].fragmentShader; + var vertId = programs[programId].vertexShader; + usedShaderIds[fragId] = true; + usedShaderIds[vertId] = true; + } + } + } + return removeObject(gltf, 'shaders', usedShaderIds); +}; + +/** + * Removes references to primitive attributes that aren't defined in the material's technique. + * + * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @returns {Object} gltf with removed unused primitive attributes. + */ +RemoveUnusedElements.removeUnusedPrimitiveAttributes = function(gltf) { + var meshes = gltf.meshes; + var materials = gltf.materials; + var techniques = gltf.techniques; + 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]; + var materialId = primitive.material; + var material = materials[materialId]; + var techniqueId = material.technique; + var technique = techniques[techniqueId]; + var techniqueParameters = technique.parameters; + var attributes = primitive.attributes; + var usedAttributes = {}; + for (var attributeSemantic in attributes) { + if (attributes.hasOwnProperty(attributeSemantic)) { + usedAttributes[attributeSemantic] = false; + } + } + for (var techniqueParameter in techniqueParameters) { + if (techniqueParameters.hasOwnProperty(techniqueParameter)) { + var parameterProperties = techniqueParameters[techniqueParameter]; + var parameterSemantic = parameterProperties.semantic; + if (defined(parameterSemantic)) { + usedAttributes[parameterSemantic] = true; + } + } + } + for (var attribute in usedAttributes) { + if (usedAttributes.hasOwnProperty(attribute)) { + if (!usedAttributes[attribute]) { + delete attributes[attribute]; + } + } + } + } + } + } + return gltf; +}; \ No newline at end of file diff --git a/lib/StaticUniformGrid.js b/lib/StaticUniformGrid.js index 9e79b021..f759f3c5 100644 --- a/lib/StaticUniformGrid.js +++ b/lib/StaticUniformGrid.js @@ -16,6 +16,7 @@ var halfDimensionsScratch = new Cartesian3(); /** * A Uniform Grid for unmoving items. * @alias StaticUniformGrid + * @private * @constructor * * @param {Object[]} items Items that the grid should store. diff --git a/lib/combineNodes.js b/lib/combineNodes.js index a9638050..5113b915 100644 --- a/lib/combineNodes.js +++ b/lib/combineNodes.js @@ -11,7 +11,7 @@ var AccessorReader = require('./AccessorReader'); var getUniqueId = require('./getUniqueId'); var NodeHelpers = require('./NodeHelpers'); var readAccessor = require('./readAccessor'); -var removeUnusedNodes = require('./removeUnusedNodes'); +var removeUnusedNodes = require('./RemoveUnusedElements').removeUnusedNodes; var writeAccessor = require('./writeAccessor'); module.exports = combineNodes; diff --git a/lib/loadGltfUris.js b/lib/loadGltfUris.js index c575e1d6..ed2489af 100644 --- a/lib/loadGltfUris.js +++ b/lib/loadGltfUris.js @@ -19,13 +19,13 @@ module.exports = loadGltfUris; /** * Load uris in the glTF into buffers. * The buffer data is placed into extras._pipeline.source for the corresponding object. + * glTF must be initialized for the pipeline. * * @param {Object} gltf A javascript object holding a glTF hierarchy. * @param {Object} options Options for loading uris. * @param {String} options.basePath The path to look in when loading external files. * @returns {Promise} A promise that resolves to gltf when all uris are loaded. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras */ function loadGltfUris(gltf, options) { @@ -91,7 +91,9 @@ function loadURI(gltf, basePath, name) { } /** - * Return the extension of the data uri + * Return the extension of the data uri. + * + * @private * @param {String} uri * @returns {String} */ @@ -130,8 +132,9 @@ function readImageFromFile(object, name, uriPath) { } /** - * Generate a jimp image for png, jpeg, or bmp + * Generate a jimp image for png, jpeg, or bmp. * + * @private * @param {Object} object * @returns {Promise} */ diff --git a/lib/removeObject.js b/lib/removeObject.js index 3ca16d61..3bb25346 100644 --- a/lib/removeObject.js +++ b/lib/removeObject.js @@ -7,13 +7,12 @@ module.exports = removeObject; /** * @private */ -function removeObject(gltf, name, usedId, stats) { +function removeObject(gltf, name, usedId) { // Iterate through objects and remove those that are not in the hash var numberRemoved = 0; var objects = gltf[name]; if (defined(objects)) { var used = {}; - for (var id in objects) { if (objects.hasOwnProperty(id)) { // If this object is in the hash, then keep it in the glTF asset @@ -24,13 +23,7 @@ function removeObject(gltf, name, usedId, stats) { } } } - - if (defined(stats)) { - stats.numberRemoved[name] += numberRemoved; - } - gltf[name] = used; } - return gltf; } \ No newline at end of file diff --git a/lib/removeUnused.js b/lib/removeUnused.js deleted file mode 100644 index 4dda4603..00000000 --- a/lib/removeUnused.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; -var removeUnusedNodes = require('./removeUnusedNodes'); -var removeUnusedSkins = require('./removeUnusedSkins'); -var removeUnusedCameras = require('./removeUnusedCameras'); -var removeUnusedMeshes = require('./removeUnusedMeshes'); -var removeUnusedAccessors = require('./removeUnusedAccessors'); -var removeUnusedMaterials = require('./removeUnusedMaterials'); -var removeUnusedBufferViews = require('./removeUnusedBufferViews'); -var removeUnusedTechniques = require('./removeUnusedTechniques'); -var removeUnusedTextures = require('./removeUnusedTextures'); -var removeUnusedBuffers = require('./removeUnusedBuffers'); -var removeUnusedPrograms = require('./removeUnusedPrograms'); -var removeUnusedImages = require('./removeUnusedImages'); -var removeUnusedSamplers = require('./removeUnusedSamplers'); -var removeUnusedShaders = require('./removeUnusedShaders'); -var removeUnusedPrimitiveAttributes = require('./removeUnusedPrimitiveAttributes'); - -module.exports = removeUnused; - -/** - * Removes all unused elements in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused elements. - */ -function removeUnused(gltf, stats) { - //Remove in top-down order so newly unused objects down the hierarchy will be removed as well - removeUnusedNodes(gltf, stats); - removeUnusedSkins(gltf, stats); - removeUnusedCameras(gltf, stats); - removeUnusedMeshes(gltf, stats); - removeUnusedAccessors(gltf, stats); - removeUnusedMaterials(gltf, stats); - removeUnusedBufferViews(gltf, stats); - removeUnusedTechniques(gltf, stats); - removeUnusedTextures(gltf, stats); - removeUnusedBuffers(gltf, stats); - removeUnusedPrograms(gltf, stats); - removeUnusedImages(gltf, stats); - removeUnusedSamplers(gltf, stats); - removeUnusedShaders(gltf, stats); - removeUnusedPrimitiveAttributes(gltf); - - return gltf; -} \ No newline at end of file diff --git a/lib/removeUnusedAccessors.js b/lib/removeUnusedAccessors.js deleted file mode 100755 index d54eaeb0..00000000 --- a/lib/removeUnusedAccessors.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; -var removeObject = require('./removeObject'); -var Cesium = require('cesium'); -var defined = Cesium.defined; - -module.exports = removeUnusedAccessors; - -/** - * Remove all unused accessors in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused accessors. - */ -function removeUnusedAccessors(gltf, stats) { - var usedAccessorIds = {}; - var meshes = gltf.meshes; - var skins = gltf.skins; - var animations = gltf.animations; - - // Build hash of used accessors by iterating through meshes, skins, and animations - if (defined(meshes)) { - for (var meshId in meshes) { - if (meshes.hasOwnProperty(meshId)) { - var primitives = meshes[meshId].primitives; - if (defined(primitives)) { - var length = primitives.length; - for (var i = 0; i < length; i++) { - var attributes = primitives[i].attributes; - if (defined(attributes)) { - for (var attributeId in attributes) { - if (attributes.hasOwnProperty(attributeId)) { - var primitiveAccessorId = attributes[attributeId]; - usedAccessorIds[primitiveAccessorId] = true; - } - } - } - var indicesId = primitives[i].indices; - if (defined(indicesId)) { - usedAccessorIds[indicesId] = true; - } - } - } - } - } - } - if (defined(skins)) { - for (var skinId in skins) { - if (skins.hasOwnProperty(skinId)) { - var skinAccessorId = skins[skinId].inverseBindMatrices; - usedAccessorIds[skinAccessorId] = true; - } - } - } - 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; - } - } - } - } - } - } - - return removeObject(gltf, 'accessors', usedAccessorIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedBufferViews.js b/lib/removeUnusedBufferViews.js deleted file mode 100755 index 74d67bb2..00000000 --- a/lib/removeUnusedBufferViews.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedBufferViews; - -/** - * Remove all unused buffer views in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused buffers views. - */ -function removeUnusedBufferViews(gltf, stats) { - var usedBufferViewIds = findUsedIds(gltf, 'accessors', 'bufferView'); -// TODO: remove orphan uris - return removeObject(gltf, 'bufferViews', usedBufferViewIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedBuffers.js b/lib/removeUnusedBuffers.js deleted file mode 100755 index c451fddd..00000000 --- a/lib/removeUnusedBuffers.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedBuffers; - -/** - * Remove all unused buffers in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused buffers. - */ -function removeUnusedBuffers(gltf, stats) { - var usedBufferIds = findUsedIds(gltf, 'bufferViews', 'buffer'); -// TODO: remove orphan uris - return removeObject(gltf, 'buffers', usedBufferIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedCameras.js b/lib/removeUnusedCameras.js deleted file mode 100755 index bd5750bb..00000000 --- a/lib/removeUnusedCameras.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedCameras; - -/** - * Remove all unused cameras in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused cameras. - */ -function removeUnusedCameras(gltf, stats) { - var usedCameraIds = findUsedIds(gltf, 'nodes', 'camera'); - return removeObject(gltf, 'cameras', usedCameraIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedImages.js b/lib/removeUnusedImages.js deleted file mode 100644 index 771b9056..00000000 --- a/lib/removeUnusedImages.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedImages; - -/** - * Remove all unused images in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused images. - */ -function removeUnusedImages(gltf, stats) { - var usedImageIds = findUsedIds(gltf, 'textures', 'source'); -// TODO: remove orphan uris - return removeObject(gltf, 'images', usedImageIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedMaterials.js b/lib/removeUnusedMaterials.js deleted file mode 100755 index 62354936..00000000 --- a/lib/removeUnusedMaterials.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; -var Cesium = require('cesium'); -var removeObject = require('./removeObject'); - -var defined = Cesium.defined; - -module.exports = removeUnusedMaterials; - -/** - * Remove all unused materials in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused images. - */ -function removeUnusedMaterials(gltf, stats) { - var usedMaterialIds = {}; - var meshes = gltf.meshes; - - // Build hash of used materials by iterating through meshes - if (defined(meshes)) { - for (var meshId in meshes) { - if (meshes.hasOwnProperty(meshId)) { - if (defined(meshes[meshId].primitives)) { - var primitives = meshes[meshId].primitives; - var length = primitives.length; - for (var i = 0; i < length; i++) { - var id = primitives[i].material; - usedMaterialIds[id] = true; - } - } - } - } - } - - return removeObject(gltf, 'materials', usedMaterialIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedMeshes.js b/lib/removeUnusedMeshes.js deleted file mode 100755 index d92d03d3..00000000 --- a/lib/removeUnusedMeshes.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; -var Cesium = require('cesium'); -var removeObject = require('./removeObject'); - -var defined = Cesium.defined; - -module.exports = removeUnusedMeshes; - -/** - * Remove all unused meshes in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused meshes. - */ -function removeUnusedMeshes(gltf, stats) { - var usedMeshIds = {}; - var nodes = gltf.nodes; - - // Build hash of used meshes by iterating through nodes - if (defined(nodes)) { - for (var nodeId in nodes) { - if (nodes.hasOwnProperty(nodeId)) { - if (defined(nodes[nodeId].meshes)) { - var nodeMeshes = nodes[nodeId].meshes; - var length = nodeMeshes.length; - for (var i = 0; i < length; i++) { - var id = nodeMeshes[i]; - usedMeshIds[id] = true; - } - } - } - } - } - - return removeObject(gltf, 'meshes', usedMeshIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedNodes.js b/lib/removeUnusedNodes.js deleted file mode 100755 index 8a39621b..00000000 --- a/lib/removeUnusedNodes.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; -var Cesium = require('cesium'); -var removeObject = require('./removeObject'); - -var defined = Cesium.defined; - -module.exports = removeUnusedNodes; - -/** - * Remove all unused nodes in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused nodes. - */ -function removeUnusedNodes(gltf, stats) { - var usedNodeIds = {}; - var scenes = gltf.scenes; - var nodes = gltf.nodes; - - // Build hash of used nodes by traversing through node trees starting at scenes - if (defined(scenes)) { - for (var sceneId in scenes) { - if (scenes.hasOwnProperty(sceneId)) { - var roots = scenes[sceneId].nodes; - if (defined(roots)) { - var nodeStack = []; - var rootsLength = roots.length; - for (var i = 0; i < rootsLength; i++) { - var root = roots[i]; - nodeStack.push(root); - } - - while (nodeStack.length > 0) { - var node = nodeStack.pop(); - usedNodeIds[node] = true; - - var children = nodes[node].children; - if (defined(children)) { - var childrenLength = children.length; - for (var j = 0; j < childrenLength; j++) { - var child = children[j]; - nodeStack.push(child); - } - } - } - } - } - } - } - - return removeObject(gltf, 'nodes', usedNodeIds, stats); -} diff --git a/lib/removeUnusedPrimitiveAttributes.js b/lib/removeUnusedPrimitiveAttributes.js deleted file mode 100644 index 367f0aaf..00000000 --- a/lib/removeUnusedPrimitiveAttributes.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; -var Cesium = require('cesium'); - -var defined = Cesium.defined; - -module.exports = removeUnusedPrimitiveAttributes; - -/** - * Removes references to primitive attributes that aren't defined in the material's technique. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused primitive attributes. - */ -function removeUnusedPrimitiveAttributes(gltf) { - var meshes = gltf.meshes; - var materials = gltf.materials; - var techniques = gltf.techniques; - 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]; - var materialId = primitive.material; - var material = materials[materialId]; - var techniqueId = material.technique; - var technique = techniques[techniqueId]; - var techniqueParameters = technique.parameters; - var attributes = primitive.attributes; - var usedAttributes = {}; - for (var attributeSemantic in attributes) { - if (attributes.hasOwnProperty(attributeSemantic)) { - usedAttributes[attributeSemantic] = false; - } - } - for (var techniqueParameter in techniqueParameters) { - if (techniqueParameters.hasOwnProperty(techniqueParameter)) { - var parameterProperties = techniqueParameters[techniqueParameter]; - var parameterSemantic = parameterProperties.semantic; - if (defined(parameterSemantic)) { - usedAttributes[parameterSemantic] = true; - } - } - } - for (var attribute in usedAttributes) { - if (usedAttributes.hasOwnProperty(attribute)) { - if (!usedAttributes[attribute]) { - delete attributes[attribute]; - } - } - } - } - } - } - return gltf; -} \ No newline at end of file diff --git a/lib/removeUnusedPrograms.js b/lib/removeUnusedPrograms.js deleted file mode 100755 index f20f7982..00000000 --- a/lib/removeUnusedPrograms.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedPrograms; - -/** - * Remove all unused programs in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused programs. - */ -function removeUnusedPrograms(gltf, stats) { - var usedProgramIds = findUsedIds(gltf, 'techniques', 'program'); -// TODO: remove orphan uris - return removeObject(gltf, 'programs', usedProgramIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedSamplers.js b/lib/removeUnusedSamplers.js deleted file mode 100644 index 996568cc..00000000 --- a/lib/removeUnusedSamplers.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedSamplers; - -/** - * Remove all unused samplers in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused samplers. - */ -function removeUnusedSamplers(gltf, stats) { - var usedSamplerIds = findUsedIds(gltf, 'textures', 'sampler'); - return removeObject(gltf, 'samplers', usedSamplerIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedShaders.js b/lib/removeUnusedShaders.js deleted file mode 100755 index 06955dbd..00000000 --- a/lib/removeUnusedShaders.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; -var Cesium = require('cesium'); -var removeObject = require('./removeObject'); - -var defined = Cesium.defined; - -module.exports = removeUnusedShaders; - -/** - * Remove all unused shaders in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused shaders. - */ -function removeUnusedShaders(gltf, stats) { - var usedShaderIds = {}; - var programs = gltf.programs; - - // Build hash of used shaders by iterating through programs - if (defined(programs)) { - for (var programId in programs) { - if (programs.hasOwnProperty(programId)) { - var fragId = programs[programId].fragmentShader; - var vertId = programs[programId].vertexShader; - usedShaderIds[fragId] = true; - usedShaderIds[vertId] = true; - } - } - } - // TODO: remove orphan uris - return removeObject(gltf, 'shaders', usedShaderIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedSkins.js b/lib/removeUnusedSkins.js deleted file mode 100755 index dd807d5d..00000000 --- a/lib/removeUnusedSkins.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedSkins; - -/** - * Remove all unused skins in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused skins. - */ -function removeUnusedSkins(gltf, stats) { - var usedSkinIds = findUsedIds(gltf, 'nodes', 'skin'); - return removeObject(gltf, 'skins', usedSkinIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedTechniques.js b/lib/removeUnusedTechniques.js deleted file mode 100755 index fdb363c2..00000000 --- a/lib/removeUnusedTechniques.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; -var findUsedIds = require('./findUsedIds'); -var removeObject = require('./removeObject'); - -module.exports = removeUnusedTechniques; - -/** - * Remove all unused techniques in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused techniques - */ -function removeUnusedTechniques(gltf, stats) { - var usedTechniqueIds = findUsedIds(gltf, 'materials', 'technique'); - return removeObject(gltf, 'techniques', usedTechniqueIds, stats); -} \ No newline at end of file diff --git a/lib/removeUnusedTextures.js b/lib/removeUnusedTextures.js deleted file mode 100755 index d969e8be..00000000 --- a/lib/removeUnusedTextures.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; -var Cesium = require('cesium'); -var removeObject = require('./removeObject'); - -var defined = Cesium.defined; - -module.exports = removeUnusedTextures; - -/** - * Remove all unused textures in gltf. - * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {OptimizationStatistics} stats Record removal statistics. - * @returns {Object} gltf with removed unused textures. - */ -function removeUnusedTextures(gltf, stats) { - var usedTextureIds = {}; - var materials = gltf.materials; - var techniques = gltf.techniques; - - // Build hash of used textures by iterating through materials and techniques - if (defined(materials)) { - for (var materialId in materials) { - if (materials.hasOwnProperty(materialId)) { - if (defined(materials[materialId].values)) { - var 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; - } - } - } - } - } - } - } - if (defined(techniques)) { - for (var techniqueId in techniques) { - if (techniques.hasOwnProperty(techniqueId)) { - if (defined(techniques[techniqueId].parameters)) { - 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; - } - } - } - } - } - } - } - } - - return removeObject(gltf, 'textures', usedTextureIds, stats); -} \ No newline at end of file diff --git a/lib/triangleAxisAlignedBoundingBoxOverlap.js b/lib/triangleAxisAlignedBoundingBoxOverlap.js index 688123ce..a26297c3 100644 --- a/lib/triangleAxisAlignedBoundingBoxOverlap.js +++ b/lib/triangleAxisAlignedBoundingBoxOverlap.js @@ -1,10 +1,5 @@ 'use strict'; -/** - * Function and helpers for computing the intersection between a static triangle and a static AABB. - * Adapted from Tomas Akenine-Möller's public domain implementation: http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/ - */ - var Cesium = require('cesium'); var Cartesian3 = Cesium.Cartesian3; @@ -21,6 +16,11 @@ var v2 = new Cartesian3(); var triangleNormalScratch = new Cartesian3(); var halfHeightScratch = new Cartesian3(); +/** + * Function and helpers for computing the intersection between a static triangle and a static AABB. + * Adapted from Tomas Akenine-Möller's public domain implementation: http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/ + * @private + */ function triangleAxisAlignedBoundingBoxOverlap(axisAlignedBoundingBox, triangle) { // Use the separating axis theorem to test overlap between triangle and box. // Need to test for overlap in these directions: diff --git a/specs/lib/bakeAmbientOcclusionSpec.js b/specs/lib/AmbientOcclusionSpec.js similarity index 94% rename from specs/lib/bakeAmbientOcclusionSpec.js rename to specs/lib/AmbientOcclusionSpec.js index 9ac29cc7..1b16cfff 100644 --- a/specs/lib/bakeAmbientOcclusionSpec.js +++ b/specs/lib/AmbientOcclusionSpec.js @@ -6,7 +6,7 @@ var CesiumMath = Cesium.Math; var Cartesian3 = Cesium.Cartesian3; var Matrix4 = Cesium.Matrix4; -var bakeAmbientOcclusion = require('../../lib/bakeAmbientOcclusion'); +var AmbientOcclusion = require('../../lib/AmbientOcclusion'); var NodeHelpers = require('../../lib/NodeHelpers'); var readGltf = require('../../lib/readGltf'); var StaticUniformGrid = require('../../lib/StaticUniformGrid'); @@ -30,7 +30,7 @@ function cloneGltfWithJimps(gltf) { return gltfClone; } -describe('bakeAmbientOcclusion', function() { +describe('AmbientOcclusion', function() { var boxOverGroundGltf; var indices = [0,1,2,0,2,3]; @@ -235,7 +235,7 @@ describe('bakeAmbientOcclusion', function() { gltfWithExtras : testGltf, rayDistance : 10.0 }; - var raytracerScene = bakeAmbientOcclusion.generateRaytracerScene(options); + var raytracerScene = AmbientOcclusion.generateRaytracerScene(options); var triangleSoup = raytracerScene.triangleGrid.items; // because of the uniform scale, expect triangles to be bigger @@ -276,7 +276,7 @@ describe('bakeAmbientOcclusion', function() { sceneID : testGltf.scene, gltfWithExtras : testGltf }; - var raytracerScene = bakeAmbientOcclusion.generateRaytracerScene(options); + var raytracerScene = AmbientOcclusion.generateRaytracerScene(options); var triangleSoup = raytracerScene.triangleGrid.items; // ground plane size is based on the near culling distance, scene size, and maximum ray depth. @@ -323,7 +323,7 @@ describe('bakeAmbientOcclusion', function() { for (i = 0; i < 6; i++) { var texel = texelPoints[i]; - samples[i] = bakeAmbientOcclusion.computeAmbientOcclusionAt({ + samples[i] = AmbientOcclusion.computeAmbientOcclusionAt({ position : texel.position, normal : texel.normal, numberRays : 16, @@ -362,7 +362,7 @@ describe('bakeAmbientOcclusion', function() { for (var i = 0; i < 3; i++) { var texel = texelPoints[i]; - samples[i] += bakeAmbientOcclusion.computeAmbientOcclusionAt({ + samples[i] += AmbientOcclusion.computeAmbientOcclusionAt({ position : texel.position, normal : texel.normal, numberRays : 16, @@ -386,7 +386,7 @@ describe('bakeAmbientOcclusion', function() { toTexture: true, gltfWithExtras: boxOverGroundGltfClone }; - bakeAmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(2); expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -415,7 +415,7 @@ describe('bakeAmbientOcclusion', function() { toTexture: true, gltfWithExtras: boxOverGroundGltfClone }; - bakeAmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(2); expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -444,7 +444,7 @@ describe('bakeAmbientOcclusion', function() { toTexture: true, gltfWithExtras: boxOverGroundGltfClone }; - bakeAmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 images with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -473,7 +473,7 @@ describe('bakeAmbientOcclusion', function() { toTexture: true, gltfWithExtras: boxOverGroundGltfClone }; - bakeAmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(3); // 1 unused texture, 2 with AO @@ -500,7 +500,7 @@ describe('bakeAmbientOcclusion', function() { toTexture: true, gltfWithExtras: boxOverGroundGltfClone }; - bakeAmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 images with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(3); // 1 unused texture, 2 with AO @@ -515,7 +515,7 @@ describe('bakeAmbientOcclusion', function() { toVertex: true, gltfWithExtras: boxOverGroundGltfClone }; - bakeAmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(options); expect(Object.keys(boxOverGroundGltfClone.accessors).length).toEqual(10); var cubeMeshPrimitives = boxOverGroundGltfClone.meshes.Cube_mesh.primitives; @@ -534,7 +534,7 @@ describe('bakeAmbientOcclusion', function() { toVertex: true, gltfWithExtras: boxOverGroundGltfClone }; - bakeAmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(options); expect(Object.keys(boxOverGroundGltfClone.materials).length).toEqual(4); expect(Object.keys(boxOverGroundGltfClone.techniques).length).toEqual(2); @@ -586,7 +586,7 @@ describe('bakeAmbientOcclusion', function() { } }; - bakeAmbientOcclusion.raytraceAtTriangleCenters(primitive, 'meshPrimitiveID', parameters, node); + AmbientOcclusion.raytraceAtTriangleCenters(primitive, 'meshPrimitiveID', parameters, node); var samples = aoBuffer.samples; var counts = aoBuffer.count; @@ -636,7 +636,7 @@ describe('bakeAmbientOcclusion', function() { } }; - bakeAmbientOcclusion.raytraceOverTriangleSamples(primitive, 'meshPrimitiveID', parameters, node); + AmbientOcclusion.raytraceOverTriangleSamples(primitive, 'meshPrimitiveID', parameters, node); var samples = aoBuffer.samples; var counts = aoBuffer.count; @@ -655,7 +655,7 @@ describe('bakeAmbientOcclusion', function() { gltfWithExtras: boxOverGroundGltf }; - var options = bakeAmbientOcclusion.generateOptions(aoOptions); + var options = AmbientOcclusion.generateOptions(aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -672,7 +672,7 @@ describe('bakeAmbientOcclusion', function() { quality: 'medium', gltfWithExtras: boxOverGroundGltf }; - options = bakeAmbientOcclusion.generateOptions(aoOptions); + options = AmbientOcclusion.generateOptions(aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -689,7 +689,7 @@ describe('bakeAmbientOcclusion', function() { quality: 'high', gltfWithExtras: boxOverGroundGltf }; - options = bakeAmbientOcclusion.generateOptions(aoOptions); + options = AmbientOcclusion.generateOptions(aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -711,7 +711,7 @@ describe('bakeAmbientOcclusion', function() { rayDistance: 10.0, gltfWithExtras: boxOverGroundGltf }; - var options = bakeAmbientOcclusion.generateOptions(aoOptions); + var options = AmbientOcclusion.generateOptions(aoOptions); expect(options.toTexture).toEqual(true); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -745,7 +745,7 @@ describe('bakeAmbientOcclusion', function() { functionArguments : ['arg0', 'arg1', 'arg2'] }; - var extractedCommand = bakeAmbientOcclusion.extractInstructionWithFunctionCall(options); + var extractedCommand = AmbientOcclusion.extractInstructionWithFunctionCall(options); expect(extractedCommand).toEqual('val = command(arg0, arg1 * (arg2 + innerCommand(innerArg0))) + 0.0'); }); @@ -769,7 +769,7 @@ describe('bakeAmbientOcclusion', function() { snippet : 'innerCommand' }; - bakeAmbientOcclusion.injectGlslAfterInstructionContaining(options); + AmbientOcclusion.injectGlslAfterInstructionContaining(options); var newSource = shader.extras._pipeline.source.toString(); expect(newSource).toEqual('function(arg0, arg1, arg2, arg3, innerArg0) {' + 'command(arg3);' + diff --git a/specs/lib/gltfPipelineSpec.js b/specs/lib/PipelineSpec.js similarity index 95% rename from specs/lib/gltfPipelineSpec.js rename to specs/lib/PipelineSpec.js index 327af7c8..60c7e4fe 100644 --- a/specs/lib/gltfPipelineSpec.js +++ b/specs/lib/PipelineSpec.js @@ -4,14 +4,14 @@ var fsExtra = require('fs-extra'); var path = require('path'); var Promise = require('bluebird'); +var Pipeline = require('../../lib/Pipeline'); var addPipelineExtras = require('../../lib/addPipelineExtras'); -var gltfPipeline = require('../../lib/gltfPipeline'); var readGltf = require('../../lib/readGltf'); -var processFile = gltfPipeline.processFile; -var processFileToDisk = gltfPipeline.processFileToDisk; -var processJSON = gltfPipeline.processJSON; -var processJSONToDisk = gltfPipeline.processJSONToDisk; +var processFile = Pipeline.processFile; +var processFileToDisk = Pipeline.processFileToDisk; +var processJSON = Pipeline.processJSON; +var processJSONToDisk = Pipeline.processJSONToDisk; var fsExtraReadFile = Promise.promisify(fsExtra.readFile); @@ -21,7 +21,7 @@ var glbPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.glb'; var outputGltfPath = './output/CesiumTexturedBoxTest.gltf'; var outputGlbPath = './output/CesiumTexturedBoxTest.glb'; -describe('gltfPipeline', function() { +describe('Pipeline', function() { it('optimizes a gltf JSON with embedded resources', function(done) { var options = {}; var gltfCopy; diff --git a/specs/lib/RemoveUnusedElementsSpec.js b/specs/lib/RemoveUnusedElementsSpec.js new file mode 100644 index 00000000..80422183 --- /dev/null +++ b/specs/lib/RemoveUnusedElementsSpec.js @@ -0,0 +1,1311 @@ +'use strict'; + +var Promise = require('bluebird'); +var fs = require('fs-extra'); + +var RemoveUnusedElements = require('../../lib/RemoveUnusedElements'); + +var fsReadFile = Promise.promisify(fs.readFile); + +var gltfPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTestUnusedTree.gltf'; + +describe('RemoveUnusedElements', function() { + var removeUnusedNodes = RemoveUnusedElements.removeUnusedNodes; + describe('removeUnusedNodes', function () { + it('removes an isolated node', function () { + var gltf = { + "nodes": { + "node_3": { + "children": [ + "left_node", + "right_node" + ] + }, + "left_node": {}, + "right_node": { + "children": [ + "txtrLocator026Node" + ] + }, + "txtrLocator026Node": {}, + "unusedNodeId": {} + }, + "scenes": { + "defaultScene": { + "nodes": [ + "node_3" + ] + } + } + }; + removeUnusedNodes(gltf); + expect(gltf.nodes.unusedNodeId).not.toBeDefined(); + expect(Object.keys(gltf.nodes).length).toEqual(4); + }); + + it('removes an unused tree', function () { + var gltf = { + "nodes": { + "node_3": { + "children": [ + "left_node", + "right_node" + ] + }, + "left_node": {}, + "right_node": { + "children": [ + "txtrLocator026Node" + ] + }, + "txtrLocator026Node": {} + }, + "scenes": { + "defaultScene": {} + } + }; + removeUnusedNodes(gltf); + expect(gltf.nodes.node_3).not.toBeDefined(); + expect(gltf.nodes.left_node).not.toBeDefined(); + expect(gltf.nodes.right_node).not.toBeDefined(); + expect(gltf.nodes.txtrLocator026Node).not.toBeDefined(); + expect(Object.keys(gltf.nodes).length).toEqual(0); + }); + + it('removes an extra tree', function () { + var gltf = { + "nodes": { + "node_3": { + "children": [ + "left_node", + "right_node" + ] + }, + "left_node": {}, + "right_node": { + "children": [ + "txtrLocator026Node" + ] + }, + "txtrLocator026Node": {}, + "unusedRootId": { + "children": [ + "unusedLeftId", + "unusedRightId" + ] + }, + "unusedLeftId": {}, + "unusedRightId": { + "children": [ + "unusedChildId" + ] + }, + "unusedChildId": {} + }, + "scenes": { + "defaultScene": { + "nodes": [ + "node_3" + ] + } + } + }; + removeUnusedNodes(gltf); + expect(gltf.nodes.unusedRootId).not.toBeDefined(); + expect(gltf.nodes.unusedLeftId).not.toBeDefined(); + expect(gltf.nodes.unusedRightId).not.toBeDefined(); + expect(gltf.nodes.unusedChildId).not.toBeDefined(); + expect(Object.keys(gltf.nodes).length).toEqual(4); + }); + + it('does not remove any nodes', function () { + var gltf = { + "nodes": { + "node_3": { + "children": [ + "left_node", + "right_node" + ] + }, + "left_node": {}, + "right_node": { + "children": [ + "txtrLocator026Node" + ] + }, + "txtrLocator026Node": {} + }, + "scenes": { + "defaultScene": { + "nodes": [ + "node_3" + ] + } + } + }; + + removeUnusedNodes(gltf); + expect(gltf.nodes.node_3).toBeDefined(); + expect(gltf.nodes.left_node).toBeDefined(); + expect(gltf.nodes.right_node).toBeDefined(); + expect(gltf.nodes.txtrLocator026Node).toBeDefined(); + expect(Object.keys(gltf.nodes).length).toEqual(4); + }); + }); + + var removeUnusedSkins = RemoveUnusedElements.removeUnusedSkins; + describe('removeUnusedSkins', function () { + it('removes a skin', function () { + var gltf = { + "nodes": { + "Cylinder": { + "skin": "Armature_Cylinder-skin" + } + }, + "skins": { + "Armature_Cylinder-skin": { + "inverseBindMatrices": "IBM_Armature_Cylinder-skin", + "jointNames": [ + "Bone" + ] + }, + "unusedSkinId": { + "inverseBindMatrices": "IBM_Armature_Cylinder-skin", + "jointNames": [ + "Bone" + ] + } + } + }; + removeUnusedSkins(gltf); + expect(gltf.skins.unusedSkinId).not.toBeDefined(); + expect(Object.keys(gltf.skins).length).toEqual(1); + }); + + it('does not remove any skins', function () { + var gltf = { + "nodes": { + "Cylinder": { + "skin": "Armature_Cylinder-skin" + } + }, + "skins": { + "Armature_Cylinder-skin": { + "inverseBindMatrices": "IBM_Armature_Cylinder-skin", + "jointNames": [ + "Bone" + ] + } + } + }; + removeUnusedSkins(gltf); + expect(gltf.skins["Armature_Cylinder-skin"]).toBeDefined(); + expect(Object.keys(gltf.skins).length).toEqual(1); + }); + }); + + var removeUnusedCameras = RemoveUnusedElements.removeUnusedCameras; + describe('removeUnusedCameras', function () { + it('removes a camera', function () { + var gltf = { + "cameras": { + "camera_0": { + "perspective": { + "aspectRatio": 1.5, + "yfov": 0.660593, + "zfar": 100, + "znear": 0.01 + }, + "type": "perspective" + }, + "unusedCameraId": { + "perspective": { + "aspectRatio": 1.5, + "yfov": 0.660593, + "zfar": 100, + "znear": 0.01 + }, + "type": "perspective" + } + }, + "nodes": { + "node_3": { + "camera": "camera_0" + } + } + }; + removeUnusedCameras(gltf); + expect(gltf.cameras.unusedCameraId).not.toBeDefined(); + expect(Object.keys(gltf.cameras).length).toEqual(1); + }); + + it('does not remove any cameras', function () { + var gltf = { + "cameras": { + "camera_0": { + "perspective": { + "aspectRatio": 1.5, + "yfov": 0.660593, + "zfar": 100, + "znear": 0.01 + }, + "type": "perspective" + } + }, + "nodes": { + "node_3": { + "camera": "camera_0" + } + } + }; + removeUnusedCameras(gltf); + expect(gltf.cameras.camera_0).toBeDefined(); + expect(Object.keys(gltf.cameras).length).toEqual(1); + }); + }); + + var removeUnusedMeshes = RemoveUnusedElements.removeUnusedMeshes; + describe('removeUnusedMeshes', function () { + it('removes a mesh', function () { + var gltf = { + "meshes": { + "Geometry-mesh002": {}, + "unusedMeshId": {} + }, + "nodes": { + "Geometry-mesh002Node": { + "meshes": [ + "Geometry-mesh002" + ] + } + } + }; + removeUnusedMeshes(gltf); + expect(gltf.meshes.unusedMeshId).not.toBeDefined(); + expect(Object.keys(gltf.meshes).length).toEqual(1); + }); + + it('does not remove any meshes', function () { + var gltf = { + "meshes": { + "Geometry-mesh002": {} + }, + "nodes": { + "Geometry-mesh002Node": { + "meshes": [ + "Geometry-mesh002" + ] + } + } + }; + removeUnusedMeshes(gltf); + expect(gltf.meshes["Geometry-mesh002"]).toBeDefined(); + expect(Object.keys(gltf.meshes).length).toEqual(1); + }); + }); + + var removeUnusedAccessors = RemoveUnusedElements.removeUnusedAccessors; + describe('removeUnusedAccessors', function () { + it('removes an accessor', function () { + var gltf = { + "accessors": { + "IBM_Armature_Cylinder-skin": { + "bufferView": "bufferView_43", + "byteOffset": 0, + "componentType": 5126, + "count": 2, + "type": "MAT4" + }, + "accessor_16": { + "bufferView": "bufferView_44", + "byteOffset": 0, + "componentType": 5123, + "count": 564, + "type": "SCALAR" + }, + "accessor_18": { + "bufferView": "bufferView_45", + "byteOffset": 0, + "componentType": 5126, + "count": 160, + "type": "VEC3" + }, + "animAccessor_0": { + "bufferView": "bufferView_43", + "byteOffset": 128, + "componentType": 5126, + "count": 3, + "type": "SCALAR" + }, + "unusedAccessorId": { + "bufferView": "bufferView_43", + "byteOffset": 128, + "componentType": 5126, + "count": 3, + "type": "SCALAR" + } + }, + "animations": { + "animation_0": { + "parameters": { + "TIME": "animAccessor_0" + } + } + }, + "meshes": { + "Cylinder-mesh": { + "primitives": [ + { + "attributes": { + "POSITION": "accessor_18" + }, + "indices": "accessor_16", + "material": "Material_001-effect" + } + ] + } + }, + "skins": { + "Armature_Cylinder-skin": { + "inverseBindMatrices": "IBM_Armature_Cylinder-skin", + "jointNames": [] + } + } + }; + removeUnusedAccessors(gltf); + expect(gltf.accessors.unusedAccessorId).not.toBeDefined(); + expect(Object.keys(gltf.accessors).length).toEqual(4); + }); + + it('does not remove any accessors', function () { + var gltf = { + "accessors": { + "IBM_Armature_Cylinder-skin": { + "bufferView": "bufferView_43", + "byteOffset": 0, + "componentType": 5126, + "count": 2, + "type": "MAT4" + }, + "accessor_16": { + "bufferView": "bufferView_44", + "byteOffset": 0, + "componentType": 5123, + "count": 564, + "type": "SCALAR" + }, + "accessor_18": { + "bufferView": "bufferView_45", + "byteOffset": 0, + "componentType": 5126, + "count": 160, + "type": "VEC3" + }, + "animAccessor_0": { + "bufferView": "bufferView_43", + "byteOffset": 128, + "componentType": 5126, + "count": 3, + "type": "SCALAR" + } + }, + "animations": { + "animation_0": { + "parameters": { + "TIME": "animAccessor_0" + } + } + }, + "meshes": { + "Cylinder-mesh": { + "primitives": [ + { + "attributes": { + "POSITION": "accessor_18" + }, + "indices": "accessor_16", + "material": "Material_001-effect" + } + ] + } + }, + "skins": { + "Armature_Cylinder-skin": { + "inverseBindMatrices": "IBM_Armature_Cylinder-skin", + "jointNames": [] + } + } + }; + + removeUnusedAccessors(gltf); + expect(gltf.accessors["IBM_Armature_Cylinder-skin"]).toBeDefined(); + expect(gltf.accessors.accessor_16).toBeDefined(); + expect(gltf.accessors.accessor_18).toBeDefined(); + expect(gltf.accessors.animAccessor_0).toBeDefined(); + expect(Object.keys(gltf.accessors).length).toEqual(4); + }); + }); + + var removeUnusedMaterials = RemoveUnusedElements.removeUnusedMaterials; + describe('removeUnusedMaterials', function () { + it('removes a material', function () { + var gltf = { + "materials": { + "Effect-Texture": { + "name": "Texture", + "technique": "technique0", + "values": { + "diffuse": "texture_Image0001", + "shininess": 256 + } + }, + "unusedMaterialId": { + "name": "Texture", + "technique": "technique0", + "values": { + "diffuse": "texture_Image0001", + "shininess": 256 + } + } + }, + "meshes": { + "Geometry-mesh002": { + "primitives": [ + { + "material": "Effect-Texture" + } + ] + } + } + }; + removeUnusedMaterials(gltf); + expect(gltf.materials.unusedMaterialId).not.toBeDefined(); + expect(Object.keys(gltf.materials).length).toEqual(1); + }); + + it('does not remove any materials', function () { + var gltf = { + "materials": { + "Effect-Texture": { + "name": "Texture", + "technique": "technique0", + "values": { + "diffuse": "texture_Image0001", + "shininess": 256 + } + } + }, + "meshes": { + "Geometry-mesh002": { + "primitives": [ + { + "material": "Effect-Texture" + } + ] + } + } + }; + removeUnusedMaterials(gltf); + expect(gltf.materials["Effect-Texture"]).toBeDefined(); + expect(Object.keys(gltf.materials).length).toEqual(1); + }); + }); + + var removeUnusedBufferViews = RemoveUnusedElements.removeUnusedBufferViews; + describe('removeUnusedBufferViews', function () { + it('removes a bufferView', function () { + var gltf = { + "accessors": { + "accessor_21": { + "bufferView": "bufferView_29", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5123, + "count": 36, + "type": "SCALAR" + } + }, + "bufferViews": { + "bufferView_29": { + "buffer": "CesiumTexturedBoxTest", + "byteLength": 72, + "byteOffset": 0, + "target": 34963 + }, + "unusedBufferViewId": { + "buffer": "CesiumTexturedBoxTest", + "byteLength": 768, + "byteOffset": 72, + "target": 34962 + } + } + }; + removeUnusedBufferViews(gltf); + expect(gltf.bufferViews.unusedBufferViewId).not.toBeDefined(); + expect(Object.keys(gltf.bufferViews).length).toEqual(1); + }); + + it('does not remove any buffers', function () { + var gltf = { + "accessors": { + "accessor_21": { + "bufferView": "bufferView_29", + "byteOffset": 0, + "byteStride": 0, + "componentType": 5123, + "count": 36, + "type": "SCALAR" + } + }, + "bufferViews": { + "bufferView_29": { + "buffer": "CesiumTexturedBoxTest", + "byteLength": 72, + "byteOffset": 0, + "target": 34963 + } + } + }; + removeUnusedBufferViews(gltf); + expect(gltf.bufferViews.bufferView_29).toBeDefined(); + expect(Object.keys(gltf.bufferViews).length).toEqual(1); + }); + }); + + var removeUnusedTechniques = RemoveUnusedElements.removeUnusedTechniques; + describe('removeUnusedTechniques', function () { + it('removes a technique', function () { + var gltf = { + "materials": { + "Effect-Texture": { + "name": "Texture", + "technique": "technique0", + "values": { + "diffuse": "texture_Image0001" + } + } + }, + "techniques": { + "technique0": { + "attributes": { + "a_position": "position" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + } + }, + "program": "program_0", + "states": { + "enable": [ + 2929, + 2884 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix" + } + }, + "unusedTechniqueId": { + "attributes": { + "a_position": "position" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + } + }, + "program": "program_0", + "states": { + "enable": [ + 2929, + 2884 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix" + } + } + } + }; + removeUnusedTechniques(gltf); + expect(gltf.techniques.unusedTechniqueId).not.toBeDefined(); + expect(Object.keys(gltf.techniques).length).toEqual(1); + }); + + it('does not remove any techniques', function () { + var gltf = { + "materials": { + "Effect-Texture": { + "name": "Texture", + "technique": "technique0", + "values": { + "diffuse": "texture_Image0001" + } + } + }, + "techniques": { + "technique0": { + "attributes": { + "a_position": "position" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + } + }, + "program": "program_0", + "states": { + "enable": [ + 2929, + 2884 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix" + } + } + } + }; + removeUnusedTechniques(gltf); + expect(gltf.techniques.technique0).toBeDefined(); + expect(Object.keys(gltf.techniques).length).toEqual(1); + }); + }); + + var removeUnusedTextures = RemoveUnusedElements.removeUnusedTextures; + describe('removeUnusedTextures', function () { + it('removes a texture', function () { + var gltf = { + "materials": { + "Effect-Texture": { + "name": "Texture", + "technique": "technique0", + "values": { + "diffuse": "texture_Image0001", + "shininess": 256, + "specular": [ + 0.2, + 0.2, + 0.2, + 1 + ] + } + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + }, + "unusedTextureId": { + "sampler": "sampler_0", + "source": "Image0001" + } + } + }; + removeUnusedTextures(gltf); + expect(gltf.textures.unusedTextureId).not.toBeDefined(); + expect(Object.keys(gltf.textures).length).toEqual(1); + }); + + it('removes a texture', function () { + var gltf = { + "techniques": { + "technique0": { + "parameters": { + "diffuse": { + "type": 35678, + "value": "texture_Image0001" + } + }, + "program": "program_0" + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + }, + "unusedTextureId": { + "sampler": "sampler_0", + "source": "Image0001" + } + } + }; + removeUnusedTextures(gltf); + expect(gltf.textures.unusedTextureId).not.toBeDefined(); + expect(Object.keys(gltf.textures).length).toEqual(1); + }); + + it('does not remove any textures', function () { + var gltf = { + "materials": { + "Effect-Texture": { + "name": "Texture", + "technique": "technique0", + "values": { + "diffuse": "texture_Image0001", + "shininess": 256, + "specular": [ + 0.2, + 0.2, + 0.2, + 1 + ] + } + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + } + } + }; + removeUnusedTextures(gltf); + expect(gltf.textures.texture_Image0001).toBeDefined(); + expect(Object.keys(gltf.textures).length).toEqual(1); + }); + + it('does not remove any textures', function () { + var gltf = { + "techniques": { + "technique0": { + "parameters": { + "diffuse": { + "type": 35678, + "value": "texture_Image0001" + } + }, + "program": "program_0" + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + } + } + }; + removeUnusedTextures(gltf); + expect(gltf.textures.texture_Image0001).toBeDefined(); + expect(Object.keys(gltf.textures).length).toEqual(1); + }); + }); + + var removeUnusedBuffers = RemoveUnusedElements.removeUnusedBuffers; + describe('removeUnusedBuffers', function () { + it('removes a buffer', function () { + var gltf = { + "bufferViews": { + "bufferView_29": { + "buffer": "CesiumTexturedBoxTest", + "byteLength": 72, + "byteOffset": 0, + "target": 34963 + } + }, + "buffers": { + "CesiumTexturedBoxTest": { + "byteLength": 840, + "type": "arraybuffer", + "uri": "CesiumTexturedBoxTest.bin" + }, + "unusedBufferId": { + "byteLength": 840, + "type": "arraybuffer", + "uri": "CesiumTexturedBoxTest.bin" + } + } + }; + removeUnusedBuffers(gltf); + expect(gltf.buffers.unusedBufferId).not.toBeDefined(); + expect(Object.keys(gltf.buffers).length).toEqual(1); + }); + + it('does not remove any buffers', function () { + var gltf = { + "bufferViews": { + "bufferView_29": { + "buffer": "CesiumTexturedBoxTest", + "byteLength": 72, + "byteOffset": 0, + "target": 34963 + } + }, + "buffers": { + "CesiumTexturedBoxTest": { + "byteLength": 840, + "type": "arraybuffer", + "uri": "CesiumTexturedBoxTest.bin" + } + } + }; + removeUnusedBuffers(gltf); + expect(gltf.buffers.CesiumTexturedBoxTest).toBeDefined(); + expect(Object.keys(gltf.buffers).length).toEqual(1); + }); + }); + + var removeUnusedPrograms = RemoveUnusedElements.removeUnusedPrograms; + describe('removeUnusedPrograms', function () { + it('removes a program', function () { + var gltf = { + "programs": { + "program_0": { + "attributes": [ + "a_position" + ], + "fragmentShader": "CesiumTexturedBoxTest0FS", + "vertexShader": "CesiumTexturedBoxTest0VS" + }, + "unusedProgramId": { + "attributes": [ + "a_position" + ], + "fragmentShader": "CesiumTexturedBoxTest0FS", + "vertexShader": "CesiumTexturedBoxTest0VS" + } + }, + "techniques": { + "technique0": { + "attributes": { + "a_position": "position" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + } + }, + "program": "program_0", + "states": { + "enable": [ + 2929, + 2884 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix" + } + } + } + }; + removeUnusedPrograms(gltf); + expect(gltf.programs.unusedProgramId).not.toBeDefined(); + expect(Object.keys(gltf.programs).length).toEqual(1); + }); + + it('does not remove any programs', function () { + var gltf = { + "programs": { + "program_0": { + "attributes": [ + "a_position" + ], + "fragmentShader": "CesiumTexturedBoxTest0FS", + "vertexShader": "CesiumTexturedBoxTest0VS" + } + }, + "techniques": { + "technique0": { + "attributes": { + "a_position": "position" + }, + "parameters": { + "modelViewMatrix": { + "semantic": "MODELVIEW", + "type": 35676 + }, + "projectionMatrix": { + "semantic": "PROJECTION", + "type": 35676 + } + }, + "program": "program_0", + "states": { + "enable": [ + 2929, + 2884 + ] + }, + "uniforms": { + "u_modelViewMatrix": "modelViewMatrix", + "u_projectionMatrix": "projectionMatrix" + } + } + } + }; + removeUnusedPrograms(gltf); + expect(gltf.programs.program_0).toBeDefined(); + expect(Object.keys(gltf.programs).length).toEqual(1); + }); + }); + + var removeUnusedImages = RemoveUnusedElements.removeUnusedImages; + describe('removeUnusedImages', function() { + it('removes an image', function() { + var gltf = { + "images": { + "Image0001": { + "name": "Image0001", + "uri": "Cesium_Logo_Flat.png" + }, + "unusedId": { + "name": "An unused image for testing removal", + "uri": "unused.png" + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + } + } + }; + removeUnusedImages(gltf); + expect(gltf.images.unusedId).not.toBeDefined(); + expect(Object.keys(gltf.images).length).toEqual(1); + }); + + it('does not remove any images', function() { + var gltf = { + "images": { + "Image0001": { + "name": "Image0001", + "uri": "Cesium_Logo_Flat.png" + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + } + } + }; + removeUnusedImages(gltf); + expect(gltf.images.Image0001).toBeDefined(); + expect(Object.keys(gltf.images).length).toEqual(1); + }); + }); + + var removeUnusedSamplers = RemoveUnusedElements.removeUnusedSamplers; + describe('removeUnusedSamplers', function() { + it('removes a sampler', function() { + var gltf = { + "samplers": { + "sampler_0": { + "magFilter": 9729, + "minFilter": 9987, + "wrapS": 10497, + "wrapT": 10497 + }, + "unusedSamplerId": { + "magFilter": 9729, + "minFilter": 9987, + "wrapS": 10497, + "wrapT": 10497 + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + } + } + }; + removeUnusedSamplers(gltf); + expect(gltf.samplers.unusedSamplerId).not.toBeDefined(); + expect(Object.keys(gltf.samplers).length).toEqual(1); + }); + + it('does not remove any samplers', function() { + var gltf = { + "samplers": { + "sampler_0": { + "magFilter": 9729, + "minFilter": 9987, + "wrapS": 10497, + "wrapT": 10497 + } + }, + "textures": { + "texture_Image0001": { + "format": 6408, + "internalFormat": 6408, + "sampler": "sampler_0", + "source": "Image0001", + "target": 3553, + "type": 5121 + } + } + }; + removeUnusedSamplers(gltf); + expect(gltf.samplers.sampler_0).toBeDefined(); + expect(Object.keys(gltf.samplers).length).toEqual(1); + }); + }); + + var removeUnusedShaders = RemoveUnusedElements.removeUnusedShaders; + describe('removeUnusedShaders', function() { + it('removes a shader', function() { + var gltf = { + "programs": { + "program_0": { + "attributes": [ + "a_normal", + "a_position", + "a_texcoord0" + ], + "fragmentShader": "CesiumTexturedBoxTest0FS", + "vertexShader": "CesiumTexturedBoxTest0VS" + } + }, + "shaders": { + "CesiumTexturedBoxTest0FS": { + "type": 35632, + "uri": "CesiumTexturedBoxTest0FS.glsl" + }, + "CesiumTexturedBoxTest0VS": { + "type": 35633, + "uri": "CesiumTexturedBoxTest0VS.glsl" + }, + "unusedShaderId": { + "type": 35633, + "uri": "CesiumTexturedBoxTest0VS.glsl" + } + } + }; + removeUnusedShaders(gltf); + expect(gltf.shaders.unusedShaderId).not.toBeDefined(); + expect(Object.keys(gltf.shaders).length).toEqual(2); + }); + + it('does not remove any shaders', function() { + var gltf = { + "programs": { + "program_0": { + "attributes": [ + "a_normal", + "a_position", + "a_texcoord0" + ], + "fragmentShader": "CesiumTexturedBoxTest0FS", + "vertexShader": "CesiumTexturedBoxTest0VS" + } + }, + "shaders": { + "CesiumTexturedBoxTest0FS": { + "type": 35632, + "uri": "CesiumTexturedBoxTest0FS.glsl" + }, + "CesiumTexturedBoxTest0VS": { + "type": 35633, + "uri": "CesiumTexturedBoxTest0VS.glsl" + } + } + }; + removeUnusedShaders(gltf); + expect(gltf.shaders.CesiumTexturedBoxTest0FS).toBeDefined(); + expect(gltf.shaders.CesiumTexturedBoxTest0VS).toBeDefined(); + expect(Object.keys(gltf.shaders).length).toEqual(2); + }); + }); + + var removeUnusedPrimitiveAttributes = RemoveUnusedElements.removeUnusedPrimitiveAttributes; + describe('removeUnusedPrimitiveAttributes', function() { + it('removes unused primitive attributes', function() { + var gltf = { + meshes : { + mesh : { + primitives: [ + { + attributes : { + KEEP_ATTRIBUTE_1 : 'accessor_1', + KEEP_ATTRIBUTE_2 : 'accessor_2', + DROP_ATTRIBUTE_3 : 'accessor_3', + KEEP_ATTRIBUTE_4 : 'accessor_4', + DROP_ATTRIBUTE_5 : 'accessor_5' + }, + material : 'material' + } + ] + } + }, + materials : { + material : { + technique : 'technique' + } + }, + techniques : { + technique : { + parameters : { + attribute1: { + semantic : 'KEEP_ATTRIBUTE_1' + }, + attribute2: { + semantic : 'KEEP_ATTRIBUTE_2' + }, + attribute3: {}, + attribute4 : { + semantic : 'KEEP_ATTRIBUTE_4' + } + } + } + } + }; + removeUnusedPrimitiveAttributes(gltf); + var attributes = gltf.meshes.mesh.primitives[0].attributes; + expect(attributes.KEEP_ATTRIBUTE_1).toBeDefined(); + expect(attributes.KEEP_ATTRIBUTE_2).toBeDefined(); + expect(attributes.DROP_ATTRIBUTE_3).not.toBeDefined(); + expect(attributes.KEEP_ATTRIBUTE_4).toBeDefined(); + expect(attributes.DROP_ATTRIBUTE_5).not.toBeDefined(); + }); + }); + + var removeAllUnused = RemoveUnusedElements.removeAllUnused; + describe('removeAllUnused', function() { + it('removes a tree of objects', function (done) { + expect(fsReadFile(gltfPath) + .then(function (data) { + var gltf = JSON.parse(data); + removeAllUnused(gltf); + + expect(gltf.accessors.accessor_23).not.toBeDefined(); + expect(gltf.accessors.animAccessor_0).not.toBeDefined(); + expect(gltf.accessors['IBM_Armature_Cylinder-skin']).not.toBeDefined(); + expect(gltf.bufferViews.bufferView_30).not.toBeDefined(); + expect(gltf.buffers.CesiumTexturedBoxTest).not.toBeDefined(); + expect(gltf.cameras.camera_0).not.toBeDefined(); + expect(gltf.images.Image0001).not.toBeDefined(); + expect(gltf.materials['Effect-Texture']).not.toBeDefined(); + expect(gltf.meshes['Geometry-mesh002']).not.toBeDefined(); + expect(gltf.nodes['Geometry-mesh002Node']).not.toBeDefined(); + expect(gltf.nodes.groupLocator030Node).not.toBeDefined(); + expect(gltf.nodes.node_3).not.toBeDefined(); + expect(gltf.nodes.txtrLocator026Node).not.toBeDefined(); + expect(gltf.programs.program_0).not.toBeDefined(); + expect(gltf.samplers.sampler_0).not.toBeDefined(); + expect(gltf.shaders.CesiumTexturedBoxTest0FS).not.toBeDefined(); + expect(gltf.shaders.CesiumTexturedBoxTest0VS).not.toBeDefined(); + expect(gltf.skins['Armature_Cylinder-skin']).not.toBeDefined(); + expect(gltf.techniques.technique0).not.toBeDefined(); + expect(gltf.textures.texture_Image0001).not.toBeDefined(); + + expect(Object.keys(gltf.nodes).length).toEqual(0); + expect(Object.keys(gltf.skins).length).toEqual(0); + expect(Object.keys(gltf.cameras).length).toEqual(0); + expect(Object.keys(gltf.meshes).length).toEqual(0); + expect(Object.keys(gltf.accessors).length).toEqual(0); + expect(Object.keys(gltf.materials).length).toEqual(0); + expect(Object.keys(gltf.bufferViews).length).toEqual(0); + expect(Object.keys(gltf.techniques).length).toEqual(0); + expect(Object.keys(gltf.textures).length).toEqual(0); + expect(Object.keys(gltf.buffers).length).toEqual(0); + expect(Object.keys(gltf.programs).length).toEqual(0); + expect(Object.keys(gltf.images).length).toEqual(0); + expect(Object.keys(gltf.samplers).length).toEqual(0); + expect(Object.keys(gltf.shaders).length).toEqual(0); + }), done).toResolve(); + }); + + it('does not remove any objects', function (done) { + expect(fsReadFile(gltfPath) + .then(function (data) { + var gltf = JSON.parse(data); + gltf.scenes.defaultScene.nodes[0] = 'node_3'; + gltf.animations.animation_0.parameters.TIME = 'animAccessor_0'; + removeAllUnused(gltf); + + expect(gltf.accessors.accessor_23).toBeDefined(); + expect(gltf.accessors.animAccessor_0).toBeDefined(); + expect(gltf.accessors['IBM_Armature_Cylinder-skin']).toBeDefined(); + expect(gltf.bufferViews.bufferView_30).toBeDefined(); + expect(gltf.buffers.CesiumTexturedBoxTest).toBeDefined(); + expect(gltf.cameras.camera_0).toBeDefined(); + expect(gltf.images.Image0001).toBeDefined(); + expect(gltf.materials['Effect-Texture']).toBeDefined(); + expect(gltf.meshes['Geometry-mesh002']).toBeDefined(); + expect(gltf.nodes['Geometry-mesh002Node']).toBeDefined(); + expect(gltf.nodes.groupLocator030Node).toBeDefined(); + expect(gltf.nodes.node_3).toBeDefined(); + expect(gltf.nodes.txtrLocator026Node).toBeDefined(); + expect(gltf.programs.program_0).toBeDefined(); + expect(gltf.samplers.sampler_0).toBeDefined(); + expect(gltf.shaders.CesiumTexturedBoxTest0FS).toBeDefined(); + expect(gltf.shaders.CesiumTexturedBoxTest0VS).toBeDefined(); + expect(gltf.skins['Armature_Cylinder-skin']).toBeDefined(); + expect(gltf.techniques.technique0).toBeDefined(); + expect(gltf.textures.texture_Image0001).toBeDefined(); + + expect(Object.keys(gltf.nodes).length).toEqual(4); + expect(Object.keys(gltf.skins).length).toEqual(1); + expect(Object.keys(gltf.cameras).length).toEqual(1); + expect(Object.keys(gltf.meshes).length).toEqual(1); + expect(Object.keys(gltf.accessors).length).toEqual(3); + expect(Object.keys(gltf.materials).length).toEqual(1); + expect(Object.keys(gltf.bufferViews).length).toEqual(1); + expect(Object.keys(gltf.techniques).length).toEqual(1); + expect(Object.keys(gltf.textures).length).toEqual(1); + expect(Object.keys(gltf.buffers).length).toEqual(1); + expect(Object.keys(gltf.programs).length).toEqual(1); + expect(Object.keys(gltf.images).length).toEqual(1); + expect(Object.keys(gltf.samplers).length).toEqual(1); + expect(Object.keys(gltf.shaders).length).toEqual(2); + }), done).toResolve(); + }); + }); +}); \ No newline at end of file diff --git a/specs/lib/getBinaryGltfSpec.js b/specs/lib/getBinaryGltfSpec.js index a68dbf60..af68109b 100644 --- a/specs/lib/getBinaryGltfSpec.js +++ b/specs/lib/getBinaryGltfSpec.js @@ -6,7 +6,6 @@ var Promise = require('bluebird'); var getBinaryGltf = require('../../lib/getBinaryGltf'); var readGltf = require('../../lib/readGltf'); -var removeUnused = require('../../lib/removeUnused'); var fsReadFile = Promise.promisify(fs.readFile); diff --git a/specs/lib/removeObjectSpec.js b/specs/lib/removeObjectSpec.js index 18a65f61..71eb0152 100644 --- a/specs/lib/removeObjectSpec.js +++ b/specs/lib/removeObjectSpec.js @@ -1,7 +1,6 @@ 'use strict'; var removeObject = require('../../lib/removeObject'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); describe('removeObject', function() { it('removes an object', function() { @@ -31,11 +30,9 @@ describe('removeObject', function() { } } }; - - var stats = new OptimizationStatistics(); - gltf = removeObject(gltf, 'samplers', { sampler_0 : true }, stats); + gltf = removeObject(gltf, 'samplers', { sampler_0 : true }); expect(gltf.samplers.unusedSamplerId).not.toBeDefined(); - expect(stats.numberRemoved.samplers).toEqual(1); + expect(Object.keys(gltf.samplers).length).toEqual(1); }); it('does not remove any objects', function() { @@ -59,10 +56,8 @@ describe('removeObject', function() { } } }; - - var stats = new OptimizationStatistics(); - gltf = removeObject(gltf, 'samplers', { sampler_0 : true }, stats); + gltf = removeObject(gltf, 'samplers', { sampler_0 : true }); expect(gltf.samplers.sampler_0).toBeDefined(); - expect(stats.numberRemoved.samplers).toEqual(0); + expect(Object.keys(gltf.samplers).length).toEqual(1); }); }); \ No newline at end of file diff --git a/specs/lib/removeUnusedAccessorsSpec.js b/specs/lib/removeUnusedAccessorsSpec.js deleted file mode 100755 index 0bc1cc16..00000000 --- a/specs/lib/removeUnusedAccessorsSpec.js +++ /dev/null @@ -1,148 +0,0 @@ -'use strict'; - -var removeUnusedAccessors = require('../../lib/removeUnusedAccessors'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedAccessors', function() { - it('removes an accessor', function() { - var gltf = { - "accessors": { - "IBM_Armature_Cylinder-skin": { - "bufferView": "bufferView_43", - "byteOffset": 0, - "componentType": 5126, - "count": 2, - "type": "MAT4" - }, - "accessor_16": { - "bufferView": "bufferView_44", - "byteOffset": 0, - "componentType": 5123, - "count": 564, - "type": "SCALAR" - }, - "accessor_18": { - "bufferView": "bufferView_45", - "byteOffset": 0, - "componentType": 5126, - "count": 160, - "type": "VEC3" - }, - "animAccessor_0": { - "bufferView": "bufferView_43", - "byteOffset": 128, - "componentType": 5126, - "count": 3, - "type": "SCALAR" - }, - "unusedAccessorId": { - "bufferView": "bufferView_43", - "byteOffset": 128, - "componentType": 5126, - "count": 3, - "type": "SCALAR" - } - }, - "animations": { - "animation_0": { - "parameters": { - "TIME": "animAccessor_0" - } - } - }, - "meshes": { - "Cylinder-mesh": { - "primitives": [ - { - "attributes": { - "POSITION": "accessor_18" - }, - "indices": "accessor_16", - "material": "Material_001-effect" - } - ] - } - }, - "skins": { - "Armature_Cylinder-skin": { - "inverseBindMatrices": "IBM_Armature_Cylinder-skin", - "jointNames": [] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedAccessors(gltf, stats); - expect(gltf.accessors.unusedAccessorId).not.toBeDefined(); - expect(stats.numberRemoved.accessors).toEqual(1); - }); - - it('does not remove any accessors', function() { - var gltf = { - "accessors": { - "IBM_Armature_Cylinder-skin": { - "bufferView": "bufferView_43", - "byteOffset": 0, - "componentType": 5126, - "count": 2, - "type": "MAT4" - }, - "accessor_16": { - "bufferView": "bufferView_44", - "byteOffset": 0, - "componentType": 5123, - "count": 564, - "type": "SCALAR" - }, - "accessor_18": { - "bufferView": "bufferView_45", - "byteOffset": 0, - "componentType": 5126, - "count": 160, - "type": "VEC3" - }, - "animAccessor_0": { - "bufferView": "bufferView_43", - "byteOffset": 128, - "componentType": 5126, - "count": 3, - "type": "SCALAR" - } - }, - "animations": { - "animation_0": { - "parameters": { - "TIME": "animAccessor_0" - } - } - }, - "meshes": { - "Cylinder-mesh": { - "primitives": [ - { - "attributes": { - "POSITION": "accessor_18" - }, - "indices": "accessor_16", - "material": "Material_001-effect" - } - ] - } - }, - "skins": { - "Armature_Cylinder-skin": { - "inverseBindMatrices": "IBM_Armature_Cylinder-skin", - "jointNames": [] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedAccessors(gltf, stats); - expect(gltf.accessors["IBM_Armature_Cylinder-skin"]).toBeDefined(); - expect(gltf.accessors.accessor_16).toBeDefined(); - expect(gltf.accessors.accessor_18).toBeDefined(); - expect(gltf.accessors.animAccessor_0).toBeDefined(); - expect(stats.numberRemoved.accessors).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedBufferViewsSpec.js b/specs/lib/removeUnusedBufferViewsSpec.js deleted file mode 100755 index 3534f4df..00000000 --- a/specs/lib/removeUnusedBufferViewsSpec.js +++ /dev/null @@ -1,68 +0,0 @@ -'use strict'; - -var removeUnusedBufferViews = require('../../lib/removeUnusedBufferViews'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedBufferViews', function() { - it('removes a bufferView', function() { - var gltf = { - "accessors": { - "accessor_21": { - "bufferView": "bufferView_29", - "byteOffset": 0, - "byteStride": 0, - "componentType": 5123, - "count": 36, - "type": "SCALAR" - } - }, - "bufferViews": { - "bufferView_29": { - "buffer": "CesiumTexturedBoxTest", - "byteLength": 72, - "byteOffset": 0, - "target": 34963 - }, - "unusedBufferViewId": { - "buffer": "CesiumTexturedBoxTest", - "byteLength": 768, - "byteOffset": 72, - "target": 34962 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedBufferViews(gltf, stats); - expect(gltf.bufferViews.unusedBufferViewId).not.toBeDefined(); - expect(stats.numberRemoved.bufferViews).toEqual(1); - }); - - it('does not remove any buffers', function() { - var gltf = { - "accessors": { - "accessor_21": { - "bufferView": "bufferView_29", - "byteOffset": 0, - "byteStride": 0, - "componentType": 5123, - "count": 36, - "type": "SCALAR" - } - }, - "bufferViews": { - "bufferView_29": { - "buffer": "CesiumTexturedBoxTest", - "byteLength": 72, - "byteOffset": 0, - "target": 34963 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedBufferViews(gltf, stats); - expect(gltf.bufferViews.bufferView_29).toBeDefined(); - expect(stats.numberRemoved.bufferViews).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedBuffersSpec.js b/specs/lib/removeUnusedBuffersSpec.js deleted file mode 100755 index bca3b371..00000000 --- a/specs/lib/removeUnusedBuffersSpec.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -var removeUnusedBuffers = require('../../lib/removeUnusedBuffers'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedBuffers', function() { - it('removes a buffer', function() { - var gltf = { - "bufferViews": { - "bufferView_29": { - "buffer": "CesiumTexturedBoxTest", - "byteLength": 72, - "byteOffset": 0, - "target": 34963 - } - }, - "buffers": { - "CesiumTexturedBoxTest": { - "byteLength": 840, - "type": "arraybuffer", - "uri": "CesiumTexturedBoxTest.bin" - }, - "unusedBufferId": { - "byteLength": 840, - "type": "arraybuffer", - "uri": "CesiumTexturedBoxTest.bin" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedBuffers(gltf, stats); - expect(gltf.buffers.unusedBufferId).not.toBeDefined(); - expect(stats.numberRemoved.buffers).toEqual(1); - }); - - it('does not remove any buffers', function() { - var gltf = { - "bufferViews": { - "bufferView_29": { - "buffer": "CesiumTexturedBoxTest", - "byteLength": 72, - "byteOffset": 0, - "target": 34963 - } - }, - "buffers": { - "CesiumTexturedBoxTest": { - "byteLength": 840, - "type": "arraybuffer", - "uri": "CesiumTexturedBoxTest.bin" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedBuffers(gltf, stats); - expect(gltf.buffers.CesiumTexturedBoxTest).toBeDefined(); - expect(stats.numberRemoved.buffers).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedCamerasSpec.js b/specs/lib/removeUnusedCamerasSpec.js deleted file mode 100755 index aebafdc8..00000000 --- a/specs/lib/removeUnusedCamerasSpec.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -var removeUnusedCameras = require('../../lib/removeUnusedCameras'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedCameras', function() { - it('removes a camera', function() { - var gltf = { - "cameras": { - "camera_0": { - "perspective": { - "aspectRatio": 1.5, - "yfov": 0.660593, - "zfar": 100, - "znear": 0.01 - }, - "type": "perspective" - }, - "unusedCameraId": { - "perspective": { - "aspectRatio": 1.5, - "yfov": 0.660593, - "zfar": 100, - "znear": 0.01 - }, - "type": "perspective" - } - }, - "nodes": { - "node_3": { - "camera": "camera_0" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedCameras(gltf, stats); - expect(gltf.cameras.unusedCameraId).not.toBeDefined(); - expect(stats.numberRemoved.cameras).toEqual(1); - }); - - it('does not remove any cameras', function() { - var gltf = { - "cameras": { - "camera_0": { - "perspective": { - "aspectRatio": 1.5, - "yfov": 0.660593, - "zfar": 100, - "znear": 0.01 - }, - "type": "perspective" - } - }, - "nodes": { - "node_3": { - "camera": "camera_0" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedCameras(gltf, stats); - expect(gltf.cameras.camera_0).toBeDefined(); - expect(stats.numberRemoved.cameras).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedImagesSpec.js b/specs/lib/removeUnusedImagesSpec.js deleted file mode 100644 index c71d8dc1..00000000 --- a/specs/lib/removeUnusedImagesSpec.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -var removeUnusedImages = require('../../lib/removeUnusedImages'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedImages', function() { - it('removes an image', function() { - var gltf = { - "images": { - "Image0001": { - "name": "Image0001", - "uri": "Cesium_Logo_Flat.png" - }, - "unusedId": { - "name": "An unused image for testing removal", - "uri": "unused.png" - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedImages(gltf, stats); - expect(gltf.images.unusedId).not.toBeDefined(); - expect(stats.numberRemoved.images).toEqual(1); - }); - - it('does not remove any images', function() { - var gltf = { - "images": { - "Image0001": { - "name": "Image0001", - "uri": "Cesium_Logo_Flat.png" - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedImages(gltf, stats); - expect(gltf.images.Image0001).toBeDefined(); - expect(stats.numberRemoved.images).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedMaterialsSpec.js b/specs/lib/removeUnusedMaterialsSpec.js deleted file mode 100755 index 7b04f56e..00000000 --- a/specs/lib/removeUnusedMaterialsSpec.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; - -var removeUnusedMaterials = require('../../lib/removeUnusedMaterials'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedMaterials', function() { - it('removes a material', function() { - var gltf = { - "materials": { - "Effect-Texture": { - "name": "Texture", - "technique": "technique0", - "values": { - "diffuse": "texture_Image0001", - "shininess": 256 - } - }, - "unusedMaterialId": { - "name": "Texture", - "technique": "technique0", - "values": { - "diffuse": "texture_Image0001", - "shininess": 256 - } - } - }, - "meshes": { - "Geometry-mesh002": { - "primitives": [ - { - "material": "Effect-Texture" - } - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedMaterials(gltf, stats); - expect(gltf.materials.unusedMaterialId).not.toBeDefined(); - expect(stats.numberRemoved.materials).toEqual(1); - }); - - it('does not remove any materials', function() { - var gltf = { - "materials": { - "Effect-Texture": { - "name": "Texture", - "technique": "technique0", - "values": { - "diffuse": "texture_Image0001", - "shininess": 256 - } - } - }, - "meshes": { - "Geometry-mesh002": { - "primitives": [ - { - "material": "Effect-Texture" - } - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedMaterials(gltf, stats); - expect(gltf.materials["Effect-Texture"]).toBeDefined(); - expect(stats.numberRemoved.materials).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedMeshesSpec.js b/specs/lib/removeUnusedMeshesSpec.js deleted file mode 100755 index 6ebe86a6..00000000 --- a/specs/lib/removeUnusedMeshesSpec.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -var removeUnusedMeshes = require('../../lib/removeUnusedMeshes'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedMeshes', function() { - it('removes a mesh', function() { - var gltf = { - "meshes": { - "Geometry-mesh002": {}, - "unusedMeshId": {} - }, - "nodes": { - "Geometry-mesh002Node": { - "meshes": [ - "Geometry-mesh002" - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedMeshes(gltf, stats); - expect(gltf.meshes.unusedMeshId).not.toBeDefined(); - expect(stats.numberRemoved.meshes).toEqual(1); - }); - - it('does not remove any meshes', function() { - var gltf = { - "meshes": { - "Geometry-mesh002": {} - }, - "nodes": { - "Geometry-mesh002Node": { - "meshes": [ - "Geometry-mesh002" - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedMeshes(gltf, stats); - expect(gltf.meshes["Geometry-mesh002"]).toBeDefined(); - expect(stats.numberRemoved.meshes).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedNodesSpec.js b/specs/lib/removeUnusedNodesSpec.js deleted file mode 100755 index cba046af..00000000 --- a/specs/lib/removeUnusedNodesSpec.js +++ /dev/null @@ -1,165 +0,0 @@ -'use strict'; - -var removeUnusedNodes = require('../../lib/removeUnusedNodes'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedNodes', function() { - it('removes an isolated node', function() { - var gltf = { - "nodes": { - "node_3": { - "children": [ - "left_node", - "right_node" - ] - }, - "left_node": { - }, - "right_node": { - "children": [ - "txtrLocator026Node" - ] - }, - "txtrLocator026Node": { - }, - "unusedNodeId": { - } - }, - "scenes": { - "defaultScene": { - "nodes": [ - "node_3" - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedNodes(gltf, stats); - expect(gltf.nodes.unusedNodeId).not.toBeDefined(); - expect(stats.numberRemoved.nodes).toEqual(1); - }); - - it('removes an unused tree', function() { - var gltf = { - "nodes": { - "node_3": { - "children": [ - "left_node", - "right_node" - ] - }, - "left_node": { - }, - "right_node": { - "children": [ - "txtrLocator026Node" - ] - }, - "txtrLocator026Node": { - } - }, - "scenes": { - "defaultScene": { - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedNodes(gltf, stats); - expect(gltf.nodes.node_3).not.toBeDefined(); - expect(gltf.nodes.left_node).not.toBeDefined(); - expect(gltf.nodes.right_node).not.toBeDefined(); - expect(gltf.nodes.txtrLocator026Node).not.toBeDefined(); - expect(stats.numberRemoved.nodes).toEqual(4); - }); - - it('removes an extra tree', function() { - var gltf = { - "nodes": { - "node_3": { - "children": [ - "left_node", - "right_node" - ] - }, - "left_node": { - }, - "right_node": { - "children": [ - "txtrLocator026Node" - ] - }, - "txtrLocator026Node": { - }, - "unusedRootId": { - "children": [ - "unusedLeftId", - "unusedRightId" - ] - }, - "unusedLeftId": { - }, - "unusedRightId": { - "children": [ - "unusedChildId" - ] - }, - "unusedChildId": { - } - }, - "scenes": { - "defaultScene": { - "nodes": [ - "node_3" - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedNodes(gltf, stats); - expect(gltf.nodes.unusedRootId).not.toBeDefined(); - expect(gltf.nodes.unusedLeftId).not.toBeDefined(); - expect(gltf.nodes.unusedRightId).not.toBeDefined(); - expect(gltf.nodes.unusedChildId).not.toBeDefined(); - expect(stats.numberRemoved.nodes).toEqual(4); - }); - - it('does not remove any nodes', function() { - var gltf = { - "nodes": { - "node_3": { - "children": [ - "left_node", - "right_node" - ] - }, - "left_node": { - }, - "right_node": { - "children": [ - "txtrLocator026Node" - ] - }, - "txtrLocator026Node": { - } - }, - "scenes": { - "defaultScene": { - "nodes": [ - "node_3" - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedNodes(gltf, stats); - expect(gltf.nodes.node_3).toBeDefined(); - expect(gltf.nodes.left_node).toBeDefined(); - expect(gltf.nodes.right_node).toBeDefined(); - expect(gltf.nodes.txtrLocator026Node).toBeDefined(); - expect(stats.numberRemoved.nodes).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedProgramsSpec.js b/specs/lib/removeUnusedProgramsSpec.js deleted file mode 100755 index 54d3f2a1..00000000 --- a/specs/lib/removeUnusedProgramsSpec.js +++ /dev/null @@ -1,107 +0,0 @@ -'use strict'; - -var removeUnusedPrograms = require('../../lib/removeUnusedPrograms'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedPrograms', function() { - it('removes a program', function() { - var gltf = { - "programs": { - "program_0": { - "attributes": [ - "a_position" - ], - "fragmentShader": "CesiumTexturedBoxTest0FS", - "vertexShader": "CesiumTexturedBoxTest0VS" - }, - "unusedProgramId": { - "attributes": [ - "a_position" - ], - "fragmentShader": "CesiumTexturedBoxTest0FS", - "vertexShader": "CesiumTexturedBoxTest0VS" - } - }, - "techniques": { - "technique0": { - "attributes": { - "a_position": "position" - }, - "parameters": { - "modelViewMatrix": { - "semantic": "MODELVIEW", - "type": 35676 - }, - "projectionMatrix": { - "semantic": "PROJECTION", - "type": 35676 - } - }, - "program": "program_0", - "states": { - "enable": [ - 2929, - 2884 - ] - }, - "uniforms": { - "u_modelViewMatrix": "modelViewMatrix", - "u_projectionMatrix": "projectionMatrix" - } - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedPrograms(gltf, stats); - expect(gltf.programs.unusedProgramId).not.toBeDefined(); - expect(stats.numberRemoved.programs).toEqual(1); - }); - - it('does not remove any programs', function() { - var gltf = { - "programs": { - "program_0": { - "attributes": [ - "a_position" - ], - "fragmentShader": "CesiumTexturedBoxTest0FS", - "vertexShader": "CesiumTexturedBoxTest0VS" - } - }, - "techniques": { - "technique0": { - "attributes": { - "a_position": "position" - }, - "parameters": { - "modelViewMatrix": { - "semantic": "MODELVIEW", - "type": 35676 - }, - "projectionMatrix": { - "semantic": "PROJECTION", - "type": 35676 - } - }, - "program": "program_0", - "states": { - "enable": [ - 2929, - 2884 - ] - }, - "uniforms": { - "u_modelViewMatrix": "modelViewMatrix", - "u_projectionMatrix": "projectionMatrix" - } - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedPrograms(gltf, stats); - expect(gltf.programs.program_0).toBeDefined(); - expect(stats.numberRemoved.programs).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedSamplersSpec.js b/specs/lib/removeUnusedSamplersSpec.js deleted file mode 100644 index c88b42cd..00000000 --- a/specs/lib/removeUnusedSamplersSpec.js +++ /dev/null @@ -1,68 +0,0 @@ -'use strict'; - -var removeUnusedSamplers = require('../../lib/removeUnusedSamplers'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedSamplers', function() { - it('removes a sampler', function() { - var gltf = { - "samplers": { - "sampler_0": { - "magFilter": 9729, - "minFilter": 9987, - "wrapS": 10497, - "wrapT": 10497 - }, - "unusedSamplerId": { - "magFilter": 9729, - "minFilter": 9987, - "wrapS": 10497, - "wrapT": 10497 - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedSamplers(gltf, stats); - expect(gltf.samplers.unusedSamplerId).not.toBeDefined(); - expect(stats.numberRemoved.samplers).toEqual(1); - }); - - it('does not remove any samplers', function() { - var gltf = { - "samplers": { - "sampler_0": { - "magFilter": 9729, - "minFilter": 9987, - "wrapS": 10497, - "wrapT": 10497 - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedSamplers(gltf, stats); - expect(gltf.samplers.sampler_0).toBeDefined(); - expect(stats.numberRemoved.samplers).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedShadersSpec.js b/specs/lib/removeUnusedShadersSpec.js deleted file mode 100755 index 87d2b066..00000000 --- a/specs/lib/removeUnusedShadersSpec.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var removeUnusedShaders = require('../../lib/removeUnusedShaders'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedShaders', function() { - it('removes a shader', function() { - var gltf = { - "programs": { - "program_0": { - "attributes": [ - "a_normal", - "a_position", - "a_texcoord0" - ], - "fragmentShader": "CesiumTexturedBoxTest0FS", - "vertexShader": "CesiumTexturedBoxTest0VS" - } - }, - "shaders": { - "CesiumTexturedBoxTest0FS": { - "type": 35632, - "uri": "CesiumTexturedBoxTest0FS.glsl" - }, - "CesiumTexturedBoxTest0VS": { - "type": 35633, - "uri": "CesiumTexturedBoxTest0VS.glsl" - }, - "unusedShaderId": { - "type": 35633, - "uri": "CesiumTexturedBoxTest0VS.glsl" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedShaders(gltf, stats); - expect(gltf.shaders.unusedShaderId).not.toBeDefined(); - expect(stats.numberRemoved.shaders).toEqual(1); - }); - - it('does not remove any shaders', function() { - var gltf = { - "programs": { - "program_0": { - "attributes": [ - "a_normal", - "a_position", - "a_texcoord0" - ], - "fragmentShader": "CesiumTexturedBoxTest0FS", - "vertexShader": "CesiumTexturedBoxTest0VS" - } - }, - "shaders": { - "CesiumTexturedBoxTest0FS": { - "type": 35632, - "uri": "CesiumTexturedBoxTest0FS.glsl" - }, - "CesiumTexturedBoxTest0VS": { - "type": 35633, - "uri": "CesiumTexturedBoxTest0VS.glsl" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedShaders(gltf, stats); - expect(gltf.shaders.CesiumTexturedBoxTest0FS).toBeDefined(); - expect(gltf.shaders.CesiumTexturedBoxTest0VS).toBeDefined(); - expect(stats.numberRemoved.shaders).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedSkinsSpec.js b/specs/lib/removeUnusedSkinsSpec.js deleted file mode 100755 index ff08dfad..00000000 --- a/specs/lib/removeUnusedSkinsSpec.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -var removeUnusedSkins = require('../../lib/removeUnusedSkins'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedSkins', function() { - it('removes a skin', function() { - var gltf = { - "nodes": { - "Cylinder": { - "skin": "Armature_Cylinder-skin" - } - }, - "skins": { - "Armature_Cylinder-skin": { - "inverseBindMatrices": "IBM_Armature_Cylinder-skin", - "jointNames": [ - "Bone" - ] - }, - "unusedSkinId": { - "inverseBindMatrices": "IBM_Armature_Cylinder-skin", - "jointNames": [ - "Bone" - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedSkins(gltf, stats); - expect(gltf.skins.unusedSkinId).not.toBeDefined(); - expect(stats.numberRemoved.skins).toEqual(1); - }); - - it('does not remove any skins', function() { - var gltf = { - "nodes": { - "Cylinder": { - "skin": "Armature_Cylinder-skin" - } - }, - "skins": { - "Armature_Cylinder-skin": { - "inverseBindMatrices": "IBM_Armature_Cylinder-skin", - "jointNames": [ - "Bone" - ] - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedSkins(gltf, stats); - expect(gltf.skins["Armature_Cylinder-skin"]).toBeDefined(); - expect(stats.numberRemoved.skins).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedSpec.js b/specs/lib/removeUnusedSpec.js deleted file mode 100644 index ebebf01d..00000000 --- a/specs/lib/removeUnusedSpec.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var removeUnused = require('../../lib/removeUnused'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); -var gltfPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTestUnusedTree.gltf'; - -describe('removeUnused', function() { - it('removes a tree of objects', function(done) { - fs.readFile(gltfPath, function (err, data) { - if (err) { - throw err; - } - - var gltf = JSON.parse(data); - var stats = new OptimizationStatistics(); - removeUnused(gltf, stats); - - expect(gltf.accessors.accessor_23).not.toBeDefined(); - expect(gltf.accessors.animAccessor_0).not.toBeDefined(); - expect(gltf.accessors['IBM_Armature_Cylinder-skin']).not.toBeDefined(); - expect(gltf.bufferViews.bufferView_30).not.toBeDefined(); - expect(gltf.buffers.CesiumTexturedBoxTest).not.toBeDefined(); - expect(gltf.cameras.camera_0).not.toBeDefined(); - expect(gltf.images.Image0001).not.toBeDefined(); - expect(gltf.materials['Effect-Texture']).not.toBeDefined(); - expect(gltf.meshes['Geometry-mesh002']).not.toBeDefined(); - expect(gltf.nodes['Geometry-mesh002Node']).not.toBeDefined(); - expect(gltf.nodes.groupLocator030Node).not.toBeDefined(); - expect(gltf.nodes.node_3).not.toBeDefined(); - expect(gltf.nodes.txtrLocator026Node).not.toBeDefined(); - expect(gltf.programs.program_0).not.toBeDefined(); - expect(gltf.samplers.sampler_0).not.toBeDefined(); - expect(gltf.shaders.CesiumTexturedBoxTest0FS).not.toBeDefined(); - expect(gltf.shaders.CesiumTexturedBoxTest0VS).not.toBeDefined(); - expect(gltf.skins['Armature_Cylinder-skin']).not.toBeDefined(); - expect(gltf.techniques.technique0).not.toBeDefined(); - expect(gltf.textures.texture_Image0001).not.toBeDefined(); - - expect(stats.numberRemoved.nodes).toEqual(4); - expect(stats.numberRemoved.skins).toEqual(1); - expect(stats.numberRemoved.cameras).toEqual(1); - expect(stats.numberRemoved.meshes).toEqual(1); - expect(stats.numberRemoved.accessors).toEqual(3); - expect(stats.numberRemoved.materials).toEqual(1); - expect(stats.numberRemoved.bufferViews).toEqual(1); - expect(stats.numberRemoved.techniques).toEqual(1); - expect(stats.numberRemoved.textures).toEqual(1); - expect(stats.numberRemoved.buffers).toEqual(1); - expect(stats.numberRemoved.programs).toEqual(1); - expect(stats.numberRemoved.images).toEqual(1); - expect(stats.numberRemoved.samplers).toEqual(1); - expect(stats.numberRemoved.shaders).toEqual(2); - done(); - }); - }); - - it('does not remove any objects', function(done) { - fs.readFile(gltfPath, function (err, data) { - if (err) { - throw err; - } - - var gltf = JSON.parse(data); - gltf.scenes.defaultScene.nodes[0] = 'node_3'; - gltf.animations.animation_0.parameters.TIME = 'animAccessor_0'; - var stats = new OptimizationStatistics(); - removeUnused(gltf, stats); - - expect(gltf.accessors.accessor_23).toBeDefined(); - expect(gltf.accessors.animAccessor_0).toBeDefined(); - expect(gltf.accessors['IBM_Armature_Cylinder-skin']).toBeDefined(); - expect(gltf.bufferViews.bufferView_30).toBeDefined(); - expect(gltf.buffers.CesiumTexturedBoxTest).toBeDefined(); - expect(gltf.cameras.camera_0).toBeDefined(); - expect(gltf.images.Image0001).toBeDefined(); - expect(gltf.materials['Effect-Texture']).toBeDefined(); - expect(gltf.meshes['Geometry-mesh002']).toBeDefined(); - expect(gltf.nodes['Geometry-mesh002Node']).toBeDefined(); - expect(gltf.nodes.groupLocator030Node).toBeDefined(); - expect(gltf.nodes.node_3).toBeDefined(); - expect(gltf.nodes.txtrLocator026Node).toBeDefined(); - expect(gltf.programs.program_0).toBeDefined(); - expect(gltf.samplers.sampler_0).toBeDefined(); - expect(gltf.shaders.CesiumTexturedBoxTest0FS).toBeDefined(); - expect(gltf.shaders.CesiumTexturedBoxTest0VS).toBeDefined(); - expect(gltf.skins['Armature_Cylinder-skin']).toBeDefined(); - expect(gltf.techniques.technique0).toBeDefined(); - expect(gltf.textures.texture_Image0001).toBeDefined(); - - expect(stats.numberRemoved.nodes).toEqual(0); - expect(stats.numberRemoved.skins).toEqual(0); - expect(stats.numberRemoved.cameras).toEqual(0); - expect(stats.numberRemoved.meshes).toEqual(0); - expect(stats.numberRemoved.accessors).toEqual(0); - expect(stats.numberRemoved.materials).toEqual(0); - expect(stats.numberRemoved.bufferViews).toEqual(0); - expect(stats.numberRemoved.techniques).toEqual(0); - expect(stats.numberRemoved.textures).toEqual(0); - expect(stats.numberRemoved.buffers).toEqual(0); - expect(stats.numberRemoved.programs).toEqual(0); - expect(stats.numberRemoved.images).toEqual(0); - expect(stats.numberRemoved.samplers).toEqual(0); - expect(stats.numberRemoved.shaders).toEqual(0); - done(); - }); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedTechniquesSpec.js b/specs/lib/removeUnusedTechniquesSpec.js deleted file mode 100755 index 76f2d345..00000000 --- a/specs/lib/removeUnusedTechniquesSpec.js +++ /dev/null @@ -1,126 +0,0 @@ -'use strict'; - -var removeUnusedTechniques = require('../../lib/removeUnusedTechniques'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedTechniques', function() { - it('removes a technique', function() { - var gltf = { - "materials": { - "Effect-Texture": { - "name": "Texture", - "technique": "technique0", - "values": { - "diffuse": "texture_Image0001" - } - } - }, - "techniques": { - "technique0": { - "attributes": { - "a_position": "position" - }, - "parameters": { - "modelViewMatrix": { - "semantic": "MODELVIEW", - "type": 35676 - }, - "projectionMatrix": { - "semantic": "PROJECTION", - "type": 35676 - } - }, - "program": "program_0", - "states": { - "enable": [ - 2929, - 2884 - ] - }, - "uniforms": { - "u_modelViewMatrix": "modelViewMatrix", - "u_projectionMatrix": "projectionMatrix" - } - }, - "unusedTechniqueId": { - "attributes": { - "a_position": "position" - }, - "parameters": { - "modelViewMatrix": { - "semantic": "MODELVIEW", - "type": 35676 - }, - "projectionMatrix": { - "semantic": "PROJECTION", - "type": 35676 - } - }, - "program": "program_0", - "states": { - "enable": [ - 2929, - 2884 - ] - }, - "uniforms": { - "u_modelViewMatrix": "modelViewMatrix", - "u_projectionMatrix": "projectionMatrix" - } - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedTechniques(gltf, stats); - expect(gltf.techniques.unusedTechniqueId).not.toBeDefined(); - expect(stats.numberRemoved.techniques).toEqual(1); - }); - - it('does not remove any techniques', function() { - var gltf = { - "materials": { - "Effect-Texture": { - "name": "Texture", - "technique": "technique0", - "values": { - "diffuse": "texture_Image0001" - } - } - }, - "techniques": { - "technique0": { - "attributes": { - "a_position": "position" - }, - "parameters": { - "modelViewMatrix": { - "semantic": "MODELVIEW", - "type": 35676 - }, - "projectionMatrix": { - "semantic": "PROJECTION", - "type": 35676 - } - }, - "program": "program_0", - "states": { - "enable": [ - 2929, - 2884 - ] - }, - "uniforms": { - "u_modelViewMatrix": "modelViewMatrix", - "u_projectionMatrix": "projectionMatrix" - } - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedTechniques(gltf, stats); - expect(gltf.techniques.technique0).toBeDefined(); - expect(stats.numberRemoved.techniques).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removeUnusedTexturesSpec.js b/specs/lib/removeUnusedTexturesSpec.js deleted file mode 100755 index b8bbce41..00000000 --- a/specs/lib/removeUnusedTexturesSpec.js +++ /dev/null @@ -1,148 +0,0 @@ -'use strict'; - -var removeUnusedTextures = require('../../lib/removeUnusedTextures'); -var OptimizationStatistics = require('../../lib/OptimizationStatistics'); - -describe('removeUnusedTextures', function() { - it('removes a texture', function() { - var gltf = { - "materials": { - "Effect-Texture": { - "name": "Texture", - "technique": "technique0", - "values": { - "diffuse": "texture_Image0001", - "shininess": 256, - "specular": [ - 0.2, - 0.2, - 0.2, - 1 - ] - } - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - }, - "unusedTextureId": { - "sampler": "sampler_0", - "source": "Image0001" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedTextures(gltf, stats); - expect(gltf.textures.unusedTextureId).not.toBeDefined(); - expect(stats.numberRemoved.textures).toEqual(1); - }); - - it('removes a texture', function() { - var gltf = { - "techniques": { - "technique0": { - "parameters": { - "diffuse": { - "type": 35678, - "value": "texture_Image0001" - } - }, - "program": "program_0" - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - }, - "unusedTextureId": { - "sampler": "sampler_0", - "source": "Image0001" - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedTextures(gltf, stats); - expect(gltf.textures.unusedTextureId).not.toBeDefined(); - expect(stats.numberRemoved.textures).toEqual(1); - }); - - it('does not remove any textures', function() { - var gltf = { - "materials": { - "Effect-Texture": { - "name": "Texture", - "technique": "technique0", - "values": { - "diffuse": "texture_Image0001", - "shininess": 256, - "specular": [ - 0.2, - 0.2, - 0.2, - 1 - ] - } - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedTextures(gltf, stats); - expect(gltf.textures.texture_Image0001).toBeDefined(); - expect(stats.numberRemoved.textures).toEqual(0); - }); - - it('does not remove any textures', function() { - var gltf = { - "techniques": { - "technique0": { - "parameters": { - "diffuse": { - "type": 35678, - "value": "texture_Image0001" - } - }, - "program": "program_0" - } - }, - "textures": { - "texture_Image0001": { - "format": 6408, - "internalFormat": 6408, - "sampler": "sampler_0", - "source": "Image0001", - "target": 3553, - "type": 5121 - } - } - }; - - var stats = new OptimizationStatistics(); - removeUnusedTextures(gltf, stats); - expect(gltf.textures.texture_Image0001).toBeDefined(); - expect(stats.numberRemoved.textures).toEqual(0); - }); -}); \ No newline at end of file diff --git a/specs/lib/removedUnusedPrimitiveAttributesSpec.js b/specs/lib/removedUnusedPrimitiveAttributesSpec.js deleted file mode 100644 index e460458b..00000000 --- a/specs/lib/removedUnusedPrimitiveAttributesSpec.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; - -var removeUnusedPrimitiveAttributes = require('../../lib/removeUnusedPrimitiveAttributes'); - -describe('removeUnusedPrimitiveAttributes', function() { - it('removes unused primitive attributes', function() { - var gltf = { - meshes : { - mesh : { - primitives: [ - { - attributes : { - KEEP_ATTRIBUTE_1 : 'accessor_1', - KEEP_ATTRIBUTE_2 : 'accessor_2', - DROP_ATTRIBUTE_3 : 'accessor_3', - KEEP_ATTRIBUTE_4 : 'accessor_4', - DROP_ATTRIBUTE_5 : 'accessor_5' - }, - material : 'material' - } - ] - } - }, - materials : { - material : { - technique : 'technique' - } - }, - techniques : { - technique : { - parameters : { - attribute1: { - semantic : 'KEEP_ATTRIBUTE_1' - }, - attribute2: { - semantic : 'KEEP_ATTRIBUTE_2' - }, - attribute3: {}, - attribute4 : { - semantic : 'KEEP_ATTRIBUTE_4' - } - } - } - } - }; - removeUnusedPrimitiveAttributes(gltf); - var attributes = gltf.meshes.mesh.primitives[0].attributes; - expect(attributes.KEEP_ATTRIBUTE_1).toBeDefined(); - expect(attributes.KEEP_ATTRIBUTE_2).toBeDefined(); - expect(attributes.DROP_ATTRIBUTE_3).not.toBeDefined(); - expect(attributes.KEEP_ATTRIBUTE_4).toBeDefined(); - expect(attributes.DROP_ATTRIBUTE_5).not.toBeDefined(); - }); -}); diff --git a/specs/lib/writeBinaryGltfSpec.js b/specs/lib/writeBinaryGltfSpec.js index 515cf5e8..7282495c 100644 --- a/specs/lib/writeBinaryGltfSpec.js +++ b/specs/lib/writeBinaryGltfSpec.js @@ -6,7 +6,6 @@ var path = require('path'); var addPipelineExtras = require('../../lib/addPipelineExtras'); var loadGltfUris = require('../../lib/loadGltfUris'); var readGltf = require('../../lib/readGltf'); -var removeUnused = require('../../lib/removeUnused'); var writeBinaryGltf = require('../../lib/writeBinaryGltf'); var gltfPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.gltf'; From 545fce1918440cd952c6867f831f809860d4109f Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Tue, 16 Aug 2016 16:50:35 -0400 Subject: [PATCH 11/21] Tweaks --- lib/NodeHelpers.js | 56 +++++++++++++++++++++------------------------- lib/Pipeline.js | 17 -------------- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/lib/NodeHelpers.js b/lib/NodeHelpers.js index 946c0ca6..5fd205d4 100644 --- a/lib/NodeHelpers.js +++ b/lib/NodeHelpers.js @@ -6,17 +6,15 @@ var Matrix4 = Cesium.Matrix4; var Cartesian3 = Cesium.Cartesian3; var Quaternion = Cesium.Quaternion; -// A set of helper functions for working with gltf nodes -// Should be called after convertDagToTree - -module.exports = { - computeFlatTransformScene : computeFlatTransformScene, - getLocalMatrix4 : getLocalMatrix4, - getAllNodesInScene : getAllNodesInScene, - depthFirstTraversal : depthFirstTraversal, - forEachPrimitiveInScene : forEachPrimitiveInScene, - mapMeshesToNodes : mapMeshesToNodes -}; + +module.exports = NodeHelpers; + +/** + * A set of helper function for working with glTF nodes. + * Should be called after convertDagToTree + * @constructor + */ +function NodeHelpers() {} var cartesian3Scratch1 = new Cartesian3(); var cartesian3Scratch2 = new Cartesian3(); @@ -24,10 +22,9 @@ var quaternionScratch = new Quaternion(); var matrix4Scratch = new Matrix4(); var arrayScratch = []; -// helper for computeFlatTransformScene function flattenTransform(parameters, node, parent) { var scratch = parameters.matrix4Scratch; - var localTransform = getLocalMatrix4(node, scratch); + var localTransform = NodeHelpers.getLocalMatrix4(node, scratch); var parentTransform = Matrix4.IDENTITY; if (defined(parent)) { parentTransform = parent.extras._pipeline.flatTransform; @@ -38,15 +35,15 @@ function flattenTransform(parameters, node, parent) { /** * Computes flattened Matrix4 transforms for every node in the scene. * Store these matrices for each node in extras._pipeline.flatTransform. + * Scene and nodes must be initialized for the pipeline. * * @param {Object} scene The glTF scene to traverse. * @param {Object} nodes glTF top-level nodes object. * - * scene and nodes must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ -function computeFlatTransformScene(scene, nodes) { +NodeHelpers.computeFlatTransformScene = function(scene, nodes) { var rootNodeIDs = scene.nodes; var parameters = { matrix4Scratch: matrix4Scratch @@ -54,10 +51,10 @@ function computeFlatTransformScene(scene, nodes) { for (var id in rootNodeIDs) { if (rootNodeIDs.hasOwnProperty(id)) { var rootNode = nodes[rootNodeIDs[id]]; - depthFirstTraversal(rootNode, nodes, flattenTransform, parameters); + NodeHelpers.depthFirstTraversal(rootNode, nodes, flattenTransform, parameters); } } -} +}; // helper for getAllNodesInScene function addNodeToArray(parameters, node) { @@ -73,7 +70,7 @@ function addNodeToArray(parameters, node) { * @param {Array} [resultArray] Store the nodes into resultArray. * @returns {Array} An array of all nodes in the scene. */ -function getAllNodesInScene(scene, nodes, resultArray) { +NodeHelpers.getAllNodesInScene = function(scene, nodes, resultArray) { var rootNodeIDs = scene.nodes; if (!defined(resultArray)) { resultArray = []; @@ -84,11 +81,11 @@ function getAllNodesInScene(scene, nodes, resultArray) { for (var id in rootNodeIDs) { if (rootNodeIDs.hasOwnProperty(id)) { var rootNode = nodes[rootNodeIDs[id]]; - depthFirstTraversal(rootNode, nodes, addNodeToArray, parameters); + NodeHelpers.depthFirstTraversal(rootNode, nodes, addNodeToArray, parameters); } } return resultArray; -} +}; /** * Perform a stack based iterative depth first traversal on the specified node. @@ -100,7 +97,7 @@ function getAllNodesInScene(scene, nodes, resultArray) { * @param {Function} functionChildParent Function to apply to the child and parent. * @param {Object} parameters Parameters to pass as the first argument to functionChildParent. */ -function depthFirstTraversal(rootNode, allNodes, functionChildParent, parameters) { +NodeHelpers.depthFirstTraversal = function(rootNode, allNodes, functionChildParent, parameters) { // process the root node functionChildParent(parameters, rootNode); @@ -123,9 +120,8 @@ function depthFirstTraversal(rootNode, allNodes, functionChildParent, parameters } } } -} +}; -// gets the local matrix of a node, or computes it from TRS /** * Gets the local matrix of a node, or computes it from TRS. @@ -135,7 +131,7 @@ function depthFirstTraversal(rootNode, allNodes, functionChildParent, parameters * @param {Matrix4} [result] Store the transform matrix into result. * @returns {Matrix4} The node transform matrix. */ -function getLocalMatrix4(node, result) { +NodeHelpers.getLocalMatrix4 = function(node, result) { if (!defined(result)) { result = new Matrix4(); } @@ -164,7 +160,7 @@ function getLocalMatrix4(node, result) { rotation.w = rotationArray[3]; return Matrix4.fromTranslationQuaternionRotationScale(translation, rotation, scale, result); -} +}; var packedParametersScratch = { meshes : undefined, @@ -181,7 +177,7 @@ var packedParametersScratch = { * @param {Function} primitiveFunction The function to apply to each primitive. * @param {Object} parameters Parameters to pass to primitiveFunction. */ -function forEachPrimitiveInScene(gltf, scene, primitiveFunction, parameters) { +NodeHelpers.forEachPrimitiveInScene = function(gltf, scene, primitiveFunction, parameters) { var rootNodeNames = scene.nodes; var allNodes = gltf.nodes; packedParametersScratch.meshes = gltf.meshes; @@ -190,10 +186,10 @@ function forEachPrimitiveInScene(gltf, scene, primitiveFunction, parameters) { for (var nodeID in rootNodeNames) { if (rootNodeNames.hasOwnProperty(nodeID)) { var rootNodeName = rootNodeNames[nodeID]; - depthFirstTraversal(allNodes[rootNodeName], allNodes, forEachPrimitiveInNode, packedParametersScratch); + NodeHelpers.depthFirstTraversal(allNodes[rootNodeName], allNodes, forEachPrimitiveInNode, packedParametersScratch); } } -} +}; function forEachPrimitiveInNode(packedParameters, node) { var meshes = packedParameters.meshes; @@ -222,7 +218,7 @@ function forEachPrimitiveInNode(packedParameters, node) { * @param {Object} gltf A javascript object holding a glTF hierarchy. * @returns {Object} An object with meshIds as keys with arrays of corresponding nodeIds as values. */ -function mapMeshesToNodes(gltf) { +NodeHelpers.mapMeshesToNodes = function(gltf) { var meshesToNodes = {}; var nodes = gltf.nodes; for (var nodeId in nodes) { @@ -244,5 +240,5 @@ function mapMeshesToNodes(gltf) { } } return meshesToNodes; -} +}; diff --git a/lib/Pipeline.js b/lib/Pipeline.js index 817a3b80..50cce02e 100644 --- a/lib/Pipeline.js +++ b/lib/Pipeline.js @@ -234,20 +234,3 @@ function writeFile(gltf, outputPath, options) { } return writeGltf(gltf, writeOptions); } - -function printStats(stats) { - process.stdout.write('Nodes removed: ' + stats.numberRemoved.nodes + '\n'); - process.stdout.write('Skins removed: ' + stats.numberRemoved.skins + '\n'); - process.stdout.write('Cameras removed: ' + stats.numberRemoved.cameras + '\n'); - process.stdout.write('Meshes removed: ' + stats.numberRemoved.meshes + '\n'); - process.stdout.write('Accessors removed: ' + stats.numberRemoved.accessors + '\n'); - process.stdout.write('Materials removed: ' + stats.numberRemoved.materials + '\n'); - process.stdout.write('BufferViews removed: ' + stats.numberRemoved.bufferViews + '\n'); - process.stdout.write('Techniques removed: ' + stats.numberRemoved.techniques + '\n'); - process.stdout.write('Textures removed: ' + stats.numberRemoved.textures + '\n'); - process.stdout.write('Buffers removed: ' + stats.numberRemoved.buffers + '\n'); - process.stdout.write('Programs removed: ' + stats.numberRemoved.programs + '\n'); - process.stdout.write('Images removed: ' + stats.numberRemoved.images + '\n'); - process.stdout.write('Samplers removed: ' + stats.numberRemoved.samplers + '\n'); - process.stdout.write('Shaders removed: ' + stats.numberRemoved.shaders + '\n'); -} From c5bf89562453f2e04bf7964b76ecb0025647b2ab Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Tue, 16 Aug 2016 16:51:31 -0400 Subject: [PATCH 12/21] Renamed nodeHelpersSpec to NodeHelpersSpec --- specs/lib/{nodeHelpersSpec.js => NodeHelpersSpec.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename specs/lib/{nodeHelpersSpec.js => NodeHelpersSpec.js} (100%) diff --git a/specs/lib/nodeHelpersSpec.js b/specs/lib/NodeHelpersSpec.js similarity index 100% rename from specs/lib/nodeHelpersSpec.js rename to specs/lib/NodeHelpersSpec.js From 4bf4745bd4cd2d2df4aecadaa982323432f1240a Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Tue, 16 Aug 2016 16:51:58 -0400 Subject: [PATCH 13/21] Updated bin, CHANGES and README --- CHANGES.md | 5 +++ README.md | 15 +++++-- bin/gltf-pipeline.js | 10 +++-- index.js | 98 ++++++++++++++++++-------------------------- 4 files changed, 65 insertions(+), 63 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9cd11e4d..a2e8d716 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,11 @@ Change Log * cacheOptimization no longer crashes on primitives without indices. [#154](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/154) * Public API is exposed via index.js [#153](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/153) + * Documentation has been added for all exposed functions. + * OptimizationStats is removed from removeUnusedStages. + * gltfPipeline.js is now named Pipeline.js. + * bakeAmbientOcclusion.js is now named AmbientOcclusion.js, bakeAmbientOcclusion is accessible via this object. + * All removeUnusedElement type stages have been consolidated to RemoveUnusedElements to clean up the global scope. ### 0.1.0-alpha3 - 2016-07-25 diff --git a/README.md b/README.md index b9e43908..3236ecc2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Coverage Status](https://coveralls.io/repos/AnalyticalGraphicsInc/gltf-pipeline/badge.svg?branch=master)](https://coveralls.io/r/AnalyticalGraphicsInc/gltf-pipeline?branch=master)

- +

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/). @@ -60,7 +60,7 @@ To run JSHint automatically when a file is saved, run the following and leave it npm run jsHint-watch ``` -### Running test coverage +### Running Test Coverage Coverage uses [istanbul](https://github.com/gotwarlost/istanbul). Run: ``` @@ -70,6 +70,15 @@ For complete coverage details, open `coverage/lcov-report/index.html`. The tests and coverage covers the Node.js module; it does not cover the command-line interface, which is tiny. +## Generating Documentation + +To generate the documentation: +``` +npm run jsdoc +``` + +The documentation will be placed in the `doc` folder. + ### Debugging * To debug the tests in Webstorm, open the Gulp tab, right click the `test` task, and click `Debug 'test'`. @@ -82,5 +91,5 @@ Pull requests are appreciated! Please use the same [Contributor License Agreeme ---

- +

diff --git a/bin/gltf-pipeline.js b/bin/gltf-pipeline.js index 615c7257..f98ca078 100644 --- a/bin/gltf-pipeline.js +++ b/bin/gltf-pipeline.js @@ -7,9 +7,9 @@ var path = require('path'); var defaultValue = Cesium.defaultValue; var defined = Cesium.defined; -var gltfPipeline = require('../lib/gltfPipeline'); +var Pipeline = require('../lib/Pipeline'); -var processFileToDisk = gltfPipeline.processFileToDisk; +var processFileToDisk = Pipeline.processFileToDisk; if (process.argv.length < 3 || defined(argv.h) || defined(argv.help)) { var help = @@ -72,5 +72,9 @@ var options = { optimizeForCesium : optimizeForCesium }; +console.time('optimize'); // Node automatically waits for all promises to terminate -processFileToDisk(gltfPath, outputPath, options); +processFileToDisk(gltfPath, outputPath, options) + .then(function() { + console.timeEnd('optimize'); + }); diff --git a/index.js b/index.js index 93fe2bca..40180d2b 100644 --- a/index.js +++ b/index.js @@ -1,59 +1,43 @@ module.exports = { - AccessorReader : require('./lib/AccessorReader.js'), - addCesiumRTC : require('./lib/addCesiumRTC.js'), - addDefaults : require('./lib/addDefaults.js'), - addExtensionsUsed : require('./lib/addExtensionsUsed.js'), - addPipelineExtras : require('./lib/addPipelineExtras.js'), - bakeAmbientOcclusion : require('./lib/bakeAmbientOcclusion.js'), - byteLengthForComponentType : require('./lib/byteLengthForComponentType.js'), - cacheOptimization : require('./lib/cacheOptimization.js'), - combineMeshes : require('./lib/combineMeshes.js'), - combineNodes : require('./lib/combineNodes.js'), - compressIntegerAccessors : require('./lib/compressIntegerAccessors.js'), - compressTextureCoordinates : require('./lib/compressTextureCoordinates.js'), - convertDagToTree : require('./lib/convertDagToTree.js'), - encodeImages : require('./lib/encodeImages.js'), - findAccessorMinMax : require('./lib/findAccessorMinMax.js'), - generateNormals : require('./lib/generateNormals.js'), - getAccessorByteStride : require('./lib/getAccessorByteStride.js'), - getBinaryGltf : require('./lib/getBinaryGltf.js'), - getUniqueId : require('./lib/getUniqueId.js'), - gltfPipeline : require('./lib/gltfPipeline.js'), - loadGltfUris : require('./lib/loadGltfUris.js'), - mergeBuffers : require('./lib/mergeBuffers.js'), - mergeDuplicateAccessors : require('./lib/mergeDuplicateAccessors.js'), - mergeDuplicateVertices : require('./lib/mergeDuplicateVertices.js'), - NodeHelpers : require('./lib/NodeHelpers.js'), - numberOfComponentsForType : require('./lib/numberOfComponentsForType.js'), - octEncodeNormals : require('./lib/octEncodeNormals.js'), - packArray : require('./lib/packArray.js'), - parseBinaryGltf : require('./lib/parseBinaryGltf.js'), - quantizeAttributes : require('./lib/quantizeAttributes.js'), - readAccessor : require('./lib/readAccessor.js'), - readBufferComponentType : require('./lib/readBufferComponentType.js'), - readGltf : require('./lib/readGltf.js'), - removeDuplicatePrimitives : require('./lib/removeDuplicatePrimitives.js'), - removePipelineExtras : require('./lib/removePipelineExtras.js'), - removeUnused : require('./lib/removeUnused.js'), - removeUnusedAccessors : require('./lib/removeUnusedAccessors.js'), - removeUnusedBuffers : require('./lib/removeUnusedBuffers.js'), - removeUnusedBufferViews : require('./lib/removeUnusedBufferViews.js'), - removeUnusedCameras : require('./lib/removeUnusedCameras.js'), - removeUnusedImages : require('./lib/removeUnusedImages.js'), - removeUnusedMaterials : require('./lib/removeUnusedMaterials.js'), - removeUnusedMeshes : require('./lib/removeUnusedMeshes.js'), - removeUnusedNodes : require('./lib/removeUnusedNodes.js'), - removeUnusedPrimitiveAttributes : require('./lib/removeUnusedPrimitiveAttributes.js'), - removeUnusedPrograms : require('./lib/removeUnusedPrograms.js'), - removeUnusedSamplers : require('./lib/removeUnusedSamplers.js'), - removeUnusedShaders : require('./lib/removeUnusedShaders.js'), - removeUnusedSkins : require('./lib/removeUnusedSkins.js'), - removeUnusedTechniques : require('./lib/removeUnusedTechniques.js'), - removeUnusedTextures : require('./lib/removeUnusedTextures.js'), - removeUnusedVertices : require('./lib/removeUnusedVertices.js'), - uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers.js'), - writeAccessor : require('./lib/writeAccessor.js'), - writeBinaryGltf : require('./lib/writeBinaryGltf.js'), - writeBufferComponentType : require('./lib/writeBufferComponentType.js'), - writeGltf : require('./lib/writeGltf.js') + AccessorReader : require('./lib/AccessorReader'), + Pipeline : require('./lib/Pipeline'), + RemoveUnusedElements : require('./RemoveUnusedElements'), + addCesiumRTC : require('./lib/addCesiumRTC'), + addDefaults : require('./lib/addDefaults'), + addExtensionsUsed : require('./lib/addExtensionsUsed'), + addPipelineExtras : require('./lib/addPipelineExtras'), + bakeAmbientOcclusion : require('./lib/AmbientOcclusion').bakeAmbientOcclusion, + byteLengthForComponentType : require('./lib/byteLengthForComponentType'), + cacheOptimization : require('./lib/cacheOptimization'), + combineMeshes : require('./lib/combineMeshes'), + combineNodes : require('./lib/combineNodes'), + compressIntegerAccessors : require('./lib/compressIntegerAccessors'), + compressTextureCoordinates : require('./lib/compressTextureCoordinates'), + convertDagToTree : require('./lib/convertDagToTree'), + encodeImages : require('./lib/encodeImages'), + findAccessorMinMax : require('./lib/findAccessorMinMax'), + generateNormals : require('./lib/generateNormals'), + getAccessorByteStride : require('./lib/getAccessorByteStride'), + getBinaryGltf : require('./lib/getBinaryGltf'), + getUniqueId : require('./lib/getUniqueId'), + loadGltfUris : require('./lib/loadGltfUris'), + mergeBuffers : require('./lib/mergeBuffers'), + mergeDuplicateAccessors : require('./lib/mergeDuplicateAccessors'), + mergeDuplicateVertices : require('./lib/mergeDuplicateVertices'), + numberOfComponentsForType : require('./lib/numberOfComponentsForType'), + octEncodeNormals : require('./lib/octEncodeNormals'), + packArray : require('./lib/packArray'), + parseBinaryGltf : require('./lib/parseBinaryGltf'), + quantizeAttributes : require('./lib/quantizeAttributes'), + readAccessor : require('./lib/readAccessor'), + readBufferComponentType : require('./lib/readBufferComponentType'), + readGltf : require('./lib/readGltf'), + removeDuplicatePrimitives : require('./lib/removeDuplicatePrimitives'), + removePipelineExtras : require('./lib/removePipelineExtras'), + removeUnusedVertices : require('./lib/removeUnusedVertices'), + uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers'), + writeAccessor : require('./lib/writeAccessor'), + writeBinaryGltf : require('./lib/writeBinaryGltf'), + writeBufferComponentType : require('./lib/writeBufferComponentType'), + writeGltf : require('./lib/writeGltf') }; \ No newline at end of file From c752a1ad1da32e82d973f1aed4b9535d37b376b8 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Tue, 16 Aug 2016 16:52:23 -0400 Subject: [PATCH 14/21] Exclude doc from jsHint and jsdoc npm script --- gulpfile.js | 2 +- package.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 313aa317..780bdc7e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,7 +21,7 @@ var environmentSeparator = process.platform === 'win32' ? ';' : ':'; var nodeBinaries = path.join(__dirname, 'node_modules', '.bin'); process.env.PATH += environmentSeparator + nodeBinaries; -var jsHintFiles = ['**/*.js', '!node_modules/**', '!coverage/**']; +var jsHintFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!doc/**']; var specFiles = ['**/*.js', '!node_modules/**', '!coverage/**']; gulp.task('jsHint', function () { diff --git a/package.json b/package.json index dc35a1db..69925bf3 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "istanbul": "0.4.4", "jasmine": "2.4.1", "jasmine-spec-reporter": "2.5.0", + "jsdoc": "3.4.0", "jshint": "2.9.2", "jshint-stylish": "2.2.0", "open": "0.0.5", @@ -58,6 +59,7 @@ "requirejs": "2.2.0" }, "scripts": { + "jsdoc": "jsdoc ./lib -R ./README.md -d doc", "jsHint": "gulp jsHint", "jsHint-watch": "gulp jsHint-watch", "test": "gulp test", From 0c9d382dcde9f9b71a1dbda632a39b5dfac07de7 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 17 Aug 2016 11:32:05 -0400 Subject: [PATCH 15/21] Made some function names and signatures more uniform, updated doc. --- CHANGES.md | 16 +- index.js | 6 +- lib/AccessorReader.js | 6 +- lib/AmbientOcclusion.js | 69 +++----- lib/NodeHelpers.js | 4 +- lib/Pipeline.js | 30 ++-- ...dElements.js => RemoveUnusedProperties.js} | 162 +++++++++--------- lib/addCesiumRTC.js | 2 +- lib/addDefaults.js | 5 +- lib/addExtensionsUsed.js | 2 +- lib/addPipelineExtras.js | 6 +- lib/combineMeshes.js | 8 +- lib/combineNodes.js | 10 +- lib/combinePrimitives.js | 4 +- lib/compressIntegerAccessors.js | 7 +- lib/compressTextureCoordinates.js | 11 +- lib/convertDagToTree.js | 7 +- lib/createAccessorUsageTables.js | 2 +- lib/encodeImages.js | 7 +- lib/findAccessorMinMax.js | 9 +- lib/generateNormals.js | 7 +- lib/getBinaryGltf.js | 7 +- lib/getUniqueId.js | 4 +- lib/loadGltfUris.js | 4 +- lib/mergeBuffers.js | 7 +- lib/mergeDuplicateAccessors.js | 7 +- lib/mergeDuplicateVertices.js | 12 +- lib/modelMaterialsCommon.js | 2 - lib/octEncodeNormals.js | 9 +- ...{cacheOptimization.js => optimizeCache.js} | 11 +- lib/parseBinaryGltf.js | 2 +- lib/quantizeAttributes.js | 7 +- lib/readAccessor.js | 5 +- ...omponentType.js => readBufferComponent.js} | 0 lib/readGltf.js | 4 +- lib/removeDuplicatePrimitives.js | 6 +- lib/removeUnusedVertices.js | 13 +- lib/uninterleaveAndPackBuffers.js | 7 +- lib/writeAccessor.js | 15 +- lib/writeBinaryGltf.js | 7 +- ...mponentType.js => writeBufferComponent.js} | 0 lib/writeGltf.js | 7 +- specs/lib/AmbientOcclusionSpec.js | 67 +++----- ...sSpec.js => RemoveUnusedPropertiesSpec.js} | 36 ++-- ...timizationSpec.js => optimizeCacheSpec.js} | 10 +- 45 files changed, 309 insertions(+), 320 deletions(-) rename lib/{RemoveUnusedElements.js => RemoveUnusedProperties.js} (68%) rename lib/{cacheOptimization.js => optimizeCache.js} (93%) rename lib/{readBufferComponentType.js => readBufferComponent.js} (100%) rename lib/{writeBufferComponentType.js => writeBufferComponent.js} (100%) rename specs/lib/{RemoveUnusedElementsSpec.js => RemoveUnusedPropertiesSpec.js} (97%) rename specs/lib/{cacheOptimizationSpec.js => optimizeCacheSpec.js} (94%) diff --git a/CHANGES.md b/CHANGES.md index a2e8d716..538fb31a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,14 +3,16 @@ Change Log ### Next Release -* cacheOptimization no longer crashes on primitives without indices. [#154](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/154) -* Public API is exposed via index.js [#153](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/153) +* `cacheOptimization` no longer crashes on primitives without indices. [#154](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/154) +* Public API is exposed via `index.js` [#153](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/153) * Documentation has been added for all exposed functions. - * OptimizationStats is removed from removeUnusedStages. - * gltfPipeline.js is now named Pipeline.js. - * bakeAmbientOcclusion.js is now named AmbientOcclusion.js, bakeAmbientOcclusion is accessible via this object. - * All removeUnusedElement type stages have been consolidated to RemoveUnusedElements to clean up the global scope. - + * `OptimizationStats` is removed from `removeUnused` stages. + * `gltfPipeline.js` is now named `Pipeline.js`. + * `bakeAmbientOcclusion.js` is now named `AmbientOcclusion.js`, `bakeAmbientOcclusion` is accessible via this object. + * `bakeAmbientOcclusion` now takes a glTF asset as its first parameter to match the function signature of other stages. + * All `removeUnused` stages have been consolidated to `RemoveUnusedProperties` to clean up the global scope. + * `readBufferComponentType` and `writeBufferComponentType` have been renamed to `readBufferComponent` and `writeBufferComponent` respectively. + ### 0.1.0-alpha3 - 2016-07-25 * Converted the API to now use promises instead of callbacks. [#135](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/135) diff --git a/index.js b/index.js index 40180d2b..618f61dd 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,6 @@ module.exports = { addPipelineExtras : require('./lib/addPipelineExtras'), bakeAmbientOcclusion : require('./lib/AmbientOcclusion').bakeAmbientOcclusion, byteLengthForComponentType : require('./lib/byteLengthForComponentType'), - cacheOptimization : require('./lib/cacheOptimization'), combineMeshes : require('./lib/combineMeshes'), combineNodes : require('./lib/combineNodes'), compressIntegerAccessors : require('./lib/compressIntegerAccessors'), @@ -26,11 +25,12 @@ module.exports = { mergeDuplicateVertices : require('./lib/mergeDuplicateVertices'), numberOfComponentsForType : require('./lib/numberOfComponentsForType'), octEncodeNormals : require('./lib/octEncodeNormals'), + optimizeCache : require('./lib/optimizeCache'), packArray : require('./lib/packArray'), parseBinaryGltf : require('./lib/parseBinaryGltf'), quantizeAttributes : require('./lib/quantizeAttributes'), readAccessor : require('./lib/readAccessor'), - readBufferComponentType : require('./lib/readBufferComponentType'), + readBufferComponentType : require('./lib/readBufferComponent'), readGltf : require('./lib/readGltf'), removeDuplicatePrimitives : require('./lib/removeDuplicatePrimitives'), removePipelineExtras : require('./lib/removePipelineExtras'), @@ -38,6 +38,6 @@ module.exports = { uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers'), writeAccessor : require('./lib/writeAccessor'), writeBinaryGltf : require('./lib/writeBinaryGltf'), - writeBufferComponentType : require('./lib/writeBufferComponentType'), + writeBufferComponentType : require('./lib/writeBufferComponent'), writeGltf : require('./lib/writeGltf') }; \ No newline at end of file diff --git a/lib/AccessorReader.js b/lib/AccessorReader.js index 8ab39c3b..68460262 100644 --- a/lib/AccessorReader.js +++ b/lib/AccessorReader.js @@ -5,8 +5,8 @@ var defaultValue = Cesium.defaultValue; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponentType'); -var writeBufferComponentType = require('./writeBufferComponentType'); +var readBufferComponentType = require('./readBufferComponent'); +var writeBufferComponentType = require('./writeBufferComponent'); module.exports = AccessorReader; @@ -15,7 +15,7 @@ module.exports = AccessorReader; * memory consumption is important. * glTF must be initialized for the pipeline. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} accessor The accessor object from glTF to read. * @constructor * diff --git a/lib/AmbientOcclusion.js b/lib/AmbientOcclusion.js index 094c6f6c..c60db7ea 100644 --- a/lib/AmbientOcclusion.js +++ b/lib/AmbientOcclusion.js @@ -24,18 +24,6 @@ var NodeHelpers = require('./NodeHelpers'); var readAccessor = require('./readAccessor'); var StaticUniformGrid = require('./StaticUniformGrid'); -/*module.exports = { - bakeAmbientOcclusion: bakeAmbientOcclusion, - // For unit testing: - generateOptions: generateOptions, - generateRaytracerScene: generateRaytracerScene, - computeAmbientOcclusionAt: computeAmbientOcclusionAt, - raytraceAtTriangleCenters: raytraceAtTriangleCenters, - raytraceOverTriangleSamples: raytraceOverTriangleSamples, - extractInstructionWithFunctionCall: extractInstructionWithFunctionCall, - injectGlslAfterInstructionContaining: injectGlslAfterInstructionContaining -};*/ - var scratchRay = new Ray(); var barycentricCoordinateScratch = new Cartesian3(); var worldPositionScratch = new Cartesian3(); @@ -56,10 +44,12 @@ module.exports = AmbientOcclusion; function AmbientOcclusion() {} /** - * Bakes ambient occlusion (AO) to all models in a specific scene of the gltf. + * Bakes ambient occlusion (AO) to all models in a specific scene of the glTF asset. + * + * The glTF asset must be initialized for the pipeline. * - * @param {Object} aoOptions All options for baking AO including a gltf with extras and AO parameters - * @param {Object} aoOptions.gltfWithExtras A gltf with standard pipeline extras + * @param {Object} gltf A javascript object containing a glTF asset. + * @param {Object} aoOptions All options for baking AO including a glTF asset with extras and AO parameters * * Basic options: * @param {Boolean} [aoOptions.toTexture=false] Bake AO to existing diffuse textures instead of to vertices. Does not modify shaders. @@ -79,18 +69,16 @@ function AmbientOcclusion() {} * @param {String} [aoOptions.shaderMode='blend'] How should the shader use per-vertex AO? Valid settings are multiply, replace, and blend. * @param {String} [aoOptions.scene=aoOptions.gltfWithExtras.scene] Which scene to use when baking AO. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ -AmbientOcclusion.bakeAmbientOcclusion = function(aoOptions) { - var options = generateOptions(aoOptions); - var gltf = aoOptions.gltfWithExtras; +AmbientOcclusion.bakeAmbientOcclusion = function(gltf, aoOptions) { + var options = generateOptions(gltf, aoOptions); ////// Generate triangle soup ////// // Requires each mesh to occur only once in the scene var scene = gltf.scenes[options.sceneID]; - var raytracerScene = generateRaytracerScene(options); + var raytracerScene = generateRaytracerScene(gltf, options); ////// Raytrace for each primitive and add to the gltf ////// var parameters = { @@ -101,8 +89,7 @@ AmbientOcclusion.bakeAmbientOcclusion = function(aoOptions) { if (options.toTexture) { NodeHelpers.forEachPrimitiveInScene(gltf, scene, raytraceToTexels, parameters); - bakeToTexture({ - gltf : gltf, + bakeToTexture(gltf, { scene : scene, resolution : options.resolution, aoBufferByPrimitive : raytracerScene.aoBufferByPrimitive @@ -112,8 +99,7 @@ AmbientOcclusion.bakeAmbientOcclusion = function(aoOptions) { if (!options.triangleCenterOnly) { NodeHelpers.forEachPrimitiveInScene(gltf, scene, raytraceOverTriangleSamples, parameters); } - bakeToVertices({ - gltf : gltf, + bakeToVertices(gltf, { scene : scene, aoBufferByPrimitive : raytracerScene.aoBufferByPrimitive, shaderMode : options.shaderMode, @@ -131,11 +117,7 @@ AmbientOcclusion.extractInstructionWithFunctionCall = extractInstructionWithFunc AmbientOcclusion.injectGlslAfterInstructionContaining = injectGlslAfterInstructionContaining; -function generateOptions(aoOptions) { - if (!defined(aoOptions.gltfWithExtras)) { - throw new DeveloperError('gltfWithExtras is required'); - } - +function generateOptions(gltf, aoOptions) { var options = { toTexture: false, groundPlane: false, @@ -147,7 +129,7 @@ function generateOptions(aoOptions) { rayDistance : -1.0, // indicates that rayDistance must be computed nearCull : 0.0001, shaderMode : 'blend', - sceneID : aoOptions.gltfWithExtras.scene, + sceneID : gltf.scene, gltfWithExtras : aoOptions.gltfWithExtras }; @@ -241,14 +223,12 @@ function cloneShadingChain(primitive, meshPrimitiveID, parameters) { } } -function bakeToVertices(options) { - var gltf = options.gltf; +function bakeToVertices(gltf, options) { var scene = options.scene; var aoBufferByPrimitive = options.aoBufferByPrimitive; // Add the new vertex data to the buffers along with bufferViews and accessors - addVertexData({ - gltf : gltf, + addVertexData(gltf, { scene : scene, aoBufferByPrimitive : aoBufferByPrimitive }); @@ -284,8 +264,7 @@ function bakeToVertices(options) { // Edit the shaders. // This can mean tracking down the unlit diffuse color input from the technique. - addAoToShaders({ - gltf : gltf, + addAoToShaders(gltf, { techniqueIds : Object.keys(parameters.techniqueCloneIDs), shaderMode : options.shaderMode, ambientShadowContribution : options.ambientShadowContribution @@ -330,8 +309,7 @@ function concatenateAoBuffers(primitive, meshPrimitiveID, parameters) { } } -function addVertexData(options) { - var gltf = options.gltf; +function addVertexData(gltf, options) { var scene = options.scene; var aoBufferByPrimitive = options.aoBufferByPrimitive; @@ -393,8 +371,7 @@ function addVertexData(options) { } } -function addAoToShaders(options) { - var gltf = options.gltf; +function addAoToShaders(gltf, options) { var techniqueIds = options.techniqueIds; var shaderMode = options.shaderMode; var ambientShadowContribution = options.ambientShadowContribution; @@ -590,9 +567,8 @@ function editShader(options) { ////////// adding to the gltf by texture ////////// -function bakeToTexture(options) { +function bakeToTexture(gltf, options) { // find material with a diffuse texture parameter to clone as needed - var gltf = options.gltf; var scene = options.scene; var resolution = options.resolution; var aoBufferByPrimitive = options.aoBufferByPrimitive; @@ -642,8 +618,7 @@ function bakeToTexture(options) { function addAoToImage(primitive, meshPrimitiveID, parameters) { // Enforce material/texture/image uniqueness var gltf = parameters.gltf; - var diffuseImage = ensureImageUniqueness({ - gltf : gltf, + var diffuseImage = ensureImageUniqueness(gltf, { primitive : primitive, meshPrimitiveID : meshPrimitiveID, state : parameters @@ -729,8 +704,7 @@ function cloneAndSetupMaterialTextureImage(options) { } // Check and modify the given material to ensure every primitive gets a unique material, texture, and image -function ensureImageUniqueness(options) { - var gltf = options.gltf; +function ensureImageUniqueness(gltf, options) { var primitive = options.primitive; var meshPrimitiveID = options.meshPrimitiveID; var state = options.state; @@ -847,9 +821,8 @@ function ensureImageUniqueness(options) { ////////// loading ////////// -function generateRaytracerScene(options) { +function generateRaytracerScene(gltf, options) { // Set up data we need for sampling. generate "triangle soup" over the whole scene. - var gltf = options.gltfWithExtras; var accessors = gltf.accessors; var scene = gltf.scenes[options.sceneID]; diff --git a/lib/NodeHelpers.js b/lib/NodeHelpers.js index 5fd205d4..5453a108 100644 --- a/lib/NodeHelpers.js +++ b/lib/NodeHelpers.js @@ -172,7 +172,7 @@ var packedParametersScratch = { * Perform an operation on each primitive in a scene. * primitiveFunction has the signature: function(primitive, meshPrimitiveId, parameters, node). * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} scene The glTF scene to traverse. * @param {Function} primitiveFunction The function to apply to each primitive. * @param {Object} parameters Parameters to pass to primitiveFunction. @@ -215,7 +215,7 @@ function forEachPrimitiveInNode(packedParameters, node) { /** * Generates a mapping for each meshId to the nodeIds of the nodes that use that mesh. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @returns {Object} An object with meshIds as keys with arrays of corresponding nodeIds as values. */ NodeHelpers.mapMeshesToNodes = function(gltf) { diff --git a/lib/Pipeline.js b/lib/Pipeline.js index 50cce02e..8d9da01a 100644 --- a/lib/Pipeline.js +++ b/lib/Pipeline.js @@ -4,10 +4,9 @@ var Promise = require('bluebird'); var path = require('path'); var AmbientOcclusion = require('./AmbientOcclusion'); -var RemoveUnusedElements = require('./RemoveUnusedElements'); +var RemoveUnusedProperties = require('./RemoveUnusedProperties'); var addDefaults = require('./addDefaults'); var addPipelineExtras = require('./addPipelineExtras'); -var cacheOptimization = require('./cacheOptimization'); var combineMeshes = require('./combineMeshes'); var combineNodes = require('./combineNodes'); var compressIntegerAccessors = require('./compressIntegerAccessors'); @@ -20,6 +19,7 @@ var loadGltfUris = require('./loadGltfUris'); var mergeDuplicateVertices = require('./mergeDuplicateVertices'); var mergeDuplicateAccessors = require('./mergeDuplicateAccessors'); var octEncodeNormals = require('./octEncodeNormals'); +var optimizeCache = require('./optimizeCache'); var readGltf = require('./readGltf'); var removeDuplicatePrimitives = require('./removeDuplicatePrimitives'); var quantizeAttributes = require('./quantizeAttributes'); @@ -31,7 +31,7 @@ var defaultValue = Cesium.defaultValue; var defined = Cesium.defined; var bakeAmbientOcclusion = AmbientOcclusion.bakeAmbientOcclusion; -var removeAllUnused = RemoveUnusedElements.removeAllUnused; +var removeAllUnused = RemoveUnusedProperties.removeAllUnused; module.exports = Pipeline; @@ -42,12 +42,12 @@ module.exports = Pipeline; function Pipeline() {} /** - * Add pipeline extras and load uris, then process the gltf. + * Add pipeline extras and load uris, then process the glTF asset. * Options are passed to loadGltfUris and processJSONWithExtras. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} options Options to apply to stages during optimization. - * @returns {Promise} A promise that resolves to the processed gltf. + * @returns {Promise} A promise that resolves to the processed glTF asset. * * @see loadGltfUris * @see Pipeline.processJSONWithExtras @@ -64,7 +64,7 @@ Pipeline.processJSON = function(gltf, options) { }; /** - * Process a gltf that already has extras and loaded uris. + * Process a glTF asset that already has extras and loaded uris. * * @param {Object} gltfWithExtras A javascript object holding a glTF hierarchy with extras. * @param {Object} options Options to apply to stages during optimization. @@ -72,7 +72,7 @@ Pipeline.processJSON = function(gltf, options) { * @param {Object} [options.encodeNormals=false] Flag to run octEncodeNormals stage. * @param {Object} [options.compressTextureCoordinates=false] Flag to run compressTextureCoordinates stage. * @param {Object} [options.quantize] Flag to run quantizeAttributes stage. - * @returns {Promise} A promise that resolves to the processed gltf. + * @returns {Promise} A promise that resolves to the processed glTF asset. */ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { addDefaults(gltfWithExtras, options); @@ -91,13 +91,13 @@ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { // combinePrimitives(gltfWithExtras); // Merging duplicate vertices again to prevent repeat data in newly combined primitives // mergeDuplicateVertices(gltfWithExtras); - cacheOptimization(gltfWithExtras); + optimizeCache(gltfWithExtras); // run AO after cacheOptimization since AO adds new attributes. var aoOptions = options.aoOptions; if (defined(aoOptions)) { aoOptions.gltfWithExtras = gltfWithExtras; - bakeAmbientOcclusion(aoOptions); + bakeAmbientOcclusion(gltfWithExtras, aoOptions); } // Run removeAllUnused stage again after all pipeline stages have been run to remove objects that become unused @@ -134,12 +134,12 @@ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { }; /** - * Process a gltf on disk into memory. + * Process a glTF asset on disk into memory. * Options are passed to processJSONWithExtras. * * @param {String} inputPath The input file path. - * @param {Object} options Options to apply tos tages during optimization. - * @returns {Object} The processed gltf. + * @param {Object} options Options to apply to stages during optimization. + * @returns {Object} The processed glTF asset. * * @see Pipeline.processJSONWithExtras */ @@ -157,7 +157,7 @@ Pipeline.processFile =function processFile(inputPath, options) { * Process a gltf in memory and writes it out to disk. * Options are passed to loadGltfUris, processJSONWithExtras, writeGltf, and writeBinaryGltf. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {String} outputPath The output file destination. * @param {Object} options Options to apply to stages during optimization. * @returns {Promise} A promise that resolves when the operation is complete. @@ -179,7 +179,7 @@ Pipeline.processJSONToDisk = function(gltf, outputPath, options) { }; /** - * Processes a gltf on disk and writes it out to disk. + * Processes a glTF asset on disk and writes it out to disk. * Options are passed to processJSONWithExtras, readGltf, writeGltf, and writeBinaryGltf. * * @param {String} inputPath The input file path. diff --git a/lib/RemoveUnusedElements.js b/lib/RemoveUnusedProperties.js similarity index 68% rename from lib/RemoveUnusedElements.js rename to lib/RemoveUnusedProperties.js index 502bb8b0..e4fd98e5 100644 --- a/lib/RemoveUnusedElements.js +++ b/lib/RemoveUnusedProperties.js @@ -5,46 +5,46 @@ var removeObject = require('./removeObject'); var defined = Cesium.defined; -module.exports = RemoveUnusedElements; +module.exports = RemoveUnusedProperties; /** * Contains stages to remove unused glTF elements. * An unused element is one that is not referred to by any other element. * @constructor */ -function RemoveUnusedElements() {} +function RemoveUnusedProperties() {} /** - * Removes all unused elements in gltf in top-down order so newly unused objects down the hierarchy will be removed as well. + * Removes all unused elements in the glTF asset in top-down order so newly unused objects down the hierarchy will be removed as well. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused elements. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused elements. */ -RemoveUnusedElements.removeAllUnused = function(gltf) { - RemoveUnusedElements.removeUnusedNodes(gltf); - RemoveUnusedElements.removeUnusedSkins(gltf); - RemoveUnusedElements.removeUnusedCameras(gltf); - RemoveUnusedElements.removeUnusedMeshes(gltf); - RemoveUnusedElements.removeUnusedAccessors(gltf); - RemoveUnusedElements.removeUnusedMaterials(gltf); - RemoveUnusedElements.removeUnusedBufferViews(gltf); - RemoveUnusedElements.removeUnusedTechniques(gltf); - RemoveUnusedElements.removeUnusedTextures(gltf); - RemoveUnusedElements.removeUnusedBuffers(gltf); - RemoveUnusedElements.removeUnusedPrograms(gltf); - RemoveUnusedElements.removeUnusedImages(gltf); - RemoveUnusedElements.removeUnusedSamplers(gltf); - RemoveUnusedElements.removeUnusedShaders(gltf); - RemoveUnusedElements.removeUnusedPrimitiveAttributes(gltf); +RemoveUnusedProperties.removeAllUnused = function(gltf) { + RemoveUnusedProperties.removeUnusedNodes(gltf); + RemoveUnusedProperties.removeUnusedSkins(gltf); + RemoveUnusedProperties.removeUnusedCameras(gltf); + RemoveUnusedProperties.removeUnusedMeshes(gltf); + RemoveUnusedProperties.removeUnusedAccessors(gltf); + RemoveUnusedProperties.removeUnusedMaterials(gltf); + RemoveUnusedProperties.removeUnusedBufferViews(gltf); + RemoveUnusedProperties.removeUnusedTechniques(gltf); + RemoveUnusedProperties.removeUnusedTextures(gltf); + RemoveUnusedProperties.removeUnusedBuffers(gltf); + RemoveUnusedProperties.removeUnusedPrograms(gltf); + RemoveUnusedProperties.removeUnusedImages(gltf); + RemoveUnusedProperties.removeUnusedSamplers(gltf); + RemoveUnusedProperties.removeUnusedShaders(gltf); + RemoveUnusedProperties.removeUnusedPrimitiveAttributes(gltf); }; /** - * Remove all unused nodes in gltf. + * Remove all unused nodes in the glTF asset * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused nodes. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused nodes. */ -RemoveUnusedElements.removeUnusedNodes = function(gltf) { +RemoveUnusedProperties.removeUnusedNodes = function(gltf) { var usedNodeIds = {}; var scenes = gltf.scenes; var nodes = gltf.nodes; @@ -84,34 +84,34 @@ RemoveUnusedElements.removeUnusedNodes = function(gltf) { }; /** - * Remove all unused skins in gltf. + * Remove all unused skins in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused skins. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused skins. */ -RemoveUnusedElements.removeUnusedSkins = function(gltf) { +RemoveUnusedProperties.removeUnusedSkins = function(gltf) { var usedSkinIds = findUsedIds(gltf, 'nodes', 'skin'); return removeObject(gltf, 'skins', usedSkinIds); }; /** - * Remove all unused cameras in gltf. + * Remove all unused cameras in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused cameras. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused cameras. */ -RemoveUnusedElements.removeUnusedCameras = function(gltf) { +RemoveUnusedProperties.removeUnusedCameras = function(gltf) { var usedCameraIds = findUsedIds(gltf, 'nodes', 'camera'); return removeObject(gltf, 'cameras', usedCameraIds); }; /** - * Remove all unused meshes in gltf. + * Remove all unused meshes in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused meshes. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused meshes. */ -RemoveUnusedElements.removeUnusedMeshes = function(gltf) { +RemoveUnusedProperties.removeUnusedMeshes = function(gltf) { var usedMeshIds = {}; var nodes = gltf.nodes; @@ -134,12 +134,12 @@ RemoveUnusedElements.removeUnusedMeshes = function(gltf) { }; /** - * Remove all unused accessors in gltf. + * Remove all unused accessors in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused accessors. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused accessors. */ -RemoveUnusedElements.removeUnusedAccessors = function(gltf) { +RemoveUnusedProperties.removeUnusedAccessors = function(gltf) { var usedAccessorIds = {}; var meshes = gltf.meshes; var skins = gltf.skins; @@ -198,12 +198,12 @@ RemoveUnusedElements.removeUnusedAccessors = function(gltf) { }; /** - * Remove all unused materials in gltf. + * Remove all unused materials in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused images. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused images. */ -RemoveUnusedElements.removeUnusedMaterials = function(gltf) { +RemoveUnusedProperties.removeUnusedMaterials = function(gltf) { var usedMaterialIds = {}; var meshes = gltf.meshes; @@ -226,34 +226,34 @@ RemoveUnusedElements.removeUnusedMaterials = function(gltf) { }; /** - * Remove all unused buffer views in gltf. + * Remove all unused buffer views in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused buffers views. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused buffers views. */ -RemoveUnusedElements.removeUnusedBufferViews = function(gltf) { +RemoveUnusedProperties.removeUnusedBufferViews = function(gltf) { var usedBufferViewIds = findUsedIds(gltf, 'accessors', 'bufferView'); return removeObject(gltf, 'bufferViews', usedBufferViewIds); }; /** - * Remove all unused techniques in gltf. + * Remove all unused techniques in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused techniques + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused techniques */ -RemoveUnusedElements.removeUnusedTechniques = function(gltf) { +RemoveUnusedProperties.removeUnusedTechniques = function(gltf) { var usedTechniqueIds = findUsedIds(gltf, 'materials', 'technique'); return removeObject(gltf, 'techniques', usedTechniqueIds); }; /** - * Remove all unused textures in gltf. + * Remove all unused textures in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused textures. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused textures. */ -RemoveUnusedElements.removeUnusedTextures = function(gltf) { +RemoveUnusedProperties.removeUnusedTextures = function(gltf) { var usedTextureIds = {}; var materials = gltf.materials; var techniques = gltf.techniques; @@ -300,56 +300,56 @@ RemoveUnusedElements.removeUnusedTextures = function(gltf) { }; /** - * Remove all unused buffers in gltf. + * Remove all unused buffers in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused buffers. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused buffers. */ -RemoveUnusedElements.removeUnusedBuffers = function(gltf) { +RemoveUnusedProperties.removeUnusedBuffers = function(gltf) { var usedBufferIds = findUsedIds(gltf, 'bufferViews', 'buffer'); return removeObject(gltf, 'buffers', usedBufferIds); }; /** - * Remove all unused programs in gltf. + * Remove all unused programs in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused programs. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused programs. */ -RemoveUnusedElements.removeUnusedPrograms = function(gltf) { +RemoveUnusedProperties.removeUnusedPrograms = function(gltf) { var usedProgramIds = findUsedIds(gltf, 'techniques', 'program'); return removeObject(gltf, 'programs', usedProgramIds); }; /** - * Remove all unused images in gltf. + * Remove all unused images in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused images. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused images. */ -RemoveUnusedElements.removeUnusedImages = function(gltf) { +RemoveUnusedProperties.removeUnusedImages = function(gltf) { var usedImageIds = findUsedIds(gltf, 'textures', 'source'); return removeObject(gltf, 'images', usedImageIds); }; /** - * Remove all unused samplers in gltf. + * Remove all unused samplers in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused samplers. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused samplers. */ -RemoveUnusedElements.removeUnusedSamplers = function(gltf) { +RemoveUnusedProperties.removeUnusedSamplers = function(gltf) { var usedSamplerIds = findUsedIds(gltf, 'textures', 'sampler'); return removeObject(gltf, 'samplers', usedSamplerIds); }; /** - * Remove all unused shaders in gltf. + * Remove all unused shaders in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused shaders. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused shaders. */ -RemoveUnusedElements.removeUnusedShaders = function(gltf) { +RemoveUnusedProperties.removeUnusedShaders = function(gltf) { var usedShaderIds = {}; var programs = gltf.programs; @@ -368,12 +368,12 @@ RemoveUnusedElements.removeUnusedShaders = function(gltf) { }; /** - * Removes references to primitive attributes that aren't defined in the material's technique. + * Removes references to primitive attributes that aren't defined in the primitive material's technique. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with removed unused primitive attributes. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with removed unused primitive attributes. */ -RemoveUnusedElements.removeUnusedPrimitiveAttributes = function(gltf) { +RemoveUnusedProperties.removeUnusedPrimitiveAttributes = function(gltf) { var meshes = gltf.meshes; var materials = gltf.materials; var techniques = gltf.techniques; diff --git a/lib/addCesiumRTC.js b/lib/addCesiumRTC.js index e579c9da..99835c73 100644 --- a/lib/addCesiumRTC.js +++ b/lib/addCesiumRTC.js @@ -15,7 +15,7 @@ module.exports = addCesiumRTC; * Either specify options.position directly or calculate it from longitude, latitude and height * along with an ellipsoid (WGS84 if not specified). * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} [options] Defines the relationship with the center position * @param {Cartesian3} [options.position] Places the model relative to a particular position. * @param {Number} [options.longitude] The longitude to map onto the ellipsoid. diff --git a/lib/addDefaults.js b/lib/addDefaults.js index 2fdf3247..eee3253b 100644 --- a/lib/addDefaults.js +++ b/lib/addDefaults.js @@ -507,11 +507,12 @@ function textureDefaults(gltf) { /** * Adds default glTF values if they don't exist. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} [options={}] * @returns {Object} The modified glTF. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/addExtensionsUsed.js b/lib/addExtensionsUsed.js index 0feddbea..3c33136c 100644 --- a/lib/addExtensionsUsed.js +++ b/lib/addExtensionsUsed.js @@ -9,7 +9,7 @@ module.exports = addExtensionsUsed; * Adds an extension to gltf.extensionsUsed if it does not already exist. * Initializes extensionsUsed if it is not defined. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {String} extension The extension to add. */ function addExtensionsUsed(gltf, extension) { diff --git a/lib/addPipelineExtras.js b/lib/addPipelineExtras.js index 780f342e..d03dffcf 100755 --- a/lib/addPipelineExtras.js +++ b/lib/addPipelineExtras.js @@ -6,10 +6,10 @@ var defined = Cesium.defined; module.exports = addPipelineExtras; /** - * Adds extras._pipeline to each object in gltf. + * Adds extras._pipeline to each object in the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with the added pipeline extras. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with the added pipeline extras. */ function addPipelineExtras(gltf) { var reference = { diff --git a/lib/combineMeshes.js b/lib/combineMeshes.js index 22831b4a..92db73c8 100755 --- a/lib/combineMeshes.js +++ b/lib/combineMeshes.js @@ -9,12 +9,14 @@ module.exports = combineMeshes; * Combines meshes in a node. * Should be run before the combinePrimitives stage to merge all primitives for a node into one mesh. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with combined meshes + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with combined meshes. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris + * @see combinePrimitives */ function combineMeshes(gltf) { var nodes = gltf.nodes; diff --git a/lib/combineNodes.js b/lib/combineNodes.js index 5113b915..f10d4d05 100644 --- a/lib/combineNodes.js +++ b/lib/combineNodes.js @@ -11,7 +11,7 @@ var AccessorReader = require('./AccessorReader'); var getUniqueId = require('./getUniqueId'); var NodeHelpers = require('./NodeHelpers'); var readAccessor = require('./readAccessor'); -var removeUnusedNodes = require('./RemoveUnusedElements').removeUnusedNodes; +var removeUnusedNodes = require('./RemoveUnusedProperties').removeUnusedNodes; var writeAccessor = require('./writeAccessor'); module.exports = combineNodes; @@ -26,12 +26,14 @@ var scratchTransform = new Matrix4(); * cannot be collapsed. Camera nodes and nodes targeted as joints or skeletons will be preserved. * Should be run before the combineMeshes stage so that all combinable meshes are contained by one node. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with combined meshes + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with combined nodes. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris + * @see combineMeshes */ function combineNodes(gltf) { var nodes = gltf.nodes; diff --git a/lib/combinePrimitives.js b/lib/combinePrimitives.js index dd858f6e..cfcd87ae 100755 --- a/lib/combinePrimitives.js +++ b/lib/combinePrimitives.js @@ -7,8 +7,8 @@ var DeveloperError = Cesium.DeveloperError; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponentType'); -var writeBufferComponentType = require('./writeBufferComponentType'); +var readBufferComponentType = require('./readBufferComponent'); +var writeBufferComponentType = require('./writeBufferComponent'); module.exports = combinePrimitives; diff --git a/lib/compressIntegerAccessors.js b/lib/compressIntegerAccessors.js index 6ebb2491..155d0529 100644 --- a/lib/compressIntegerAccessors.js +++ b/lib/compressIntegerAccessors.js @@ -44,12 +44,13 @@ var unsignedComponentTypes = [ * in either a floating-point data type, or an integer one with more precision * than necessary. The data is rewritten to the most optimal data type. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} [options] Options defining custom behavior. * @param {Array} [options.semantics] An array of semantics to compress. - * @returns {Promise} A promise that resolves to gltf with compressed integer accessors. + * @returns {Promise} A promise that resolves to the glTF asset with compressed integer accessors. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/compressTextureCoordinates.js b/lib/compressTextureCoordinates.js index da67f7f2..848cff5a 100644 --- a/lib/compressTextureCoordinates.js +++ b/lib/compressTextureCoordinates.js @@ -14,9 +14,9 @@ var findAccessorMinMax = require('./findAccessorMinMax'); var getAccessorByteStride = require('./getAccessorByteStride'); var getAccessorsForSemantic = require('./getAccessorsForSemantic'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponentType'); +var readBufferComponentType = require('./readBufferComponent'); var uninterleaveAndPackBuffers = require('./uninterleaveAndPackBuffers'); -var writeBufferComponentType = require('./writeBufferComponentType'); +var writeBufferComponentType = require('./writeBufferComponent'); module.exports = compressTextureCoordinates; @@ -24,10 +24,11 @@ module.exports = compressTextureCoordinates; * Compresses the texture coordinates of this model, packing each texture coordinates from two floating-point numbers * into one. Modifies the model shader for decoding. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Promise} A promise that resolves to gltf with compressed texture coordinates. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Promise} A promise that resolves to the glTF asset with compressed texture coordinates. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/convertDagToTree.js b/lib/convertDagToTree.js index c99319a3..2a21dcfb 100755 --- a/lib/convertDagToTree.js +++ b/lib/convertDagToTree.js @@ -10,10 +10,11 @@ module.exports = convertDagToTree; * to a tree. If multiple nodes have the same child node, the child will be duplicated * so that they no longer refer to the same node. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with any DAGs resolved to trees. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with any DAGs resolved to trees. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/createAccessorUsageTables.js b/lib/createAccessorUsageTables.js index df2ad8b1..157775f4 100644 --- a/lib/createAccessorUsageTables.js +++ b/lib/createAccessorUsageTables.js @@ -2,7 +2,7 @@ var Cesium = require('cesium'); var defined = Cesium.defined; var getAccessorByteStride = require('./getAccessorByteStride'); -var readBufferComponentType = require('./readBufferComponentType'); +var readBufferComponentType = require('./readBufferComponent'); module.exports = createAccessorUsageTables; diff --git a/lib/encodeImages.js b/lib/encodeImages.js index 4d4206f3..282afc46 100644 --- a/lib/encodeImages.js +++ b/lib/encodeImages.js @@ -8,11 +8,12 @@ module.exports = encodeImages; /** * Encodes Jimp images in pipeline extras to buffers. + * + * The glTF asset must be initialized for the pipeline. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Promise} A promise that resolves to gltf when encoding is complete for all images. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Promise} A promise that resolves to the glTF asset when encoding is complete for all images. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/findAccessorMinMax.js b/lib/findAccessorMinMax.js index 57812d5b..0ef7675d 100644 --- a/lib/findAccessorMinMax.js +++ b/lib/findAccessorMinMax.js @@ -6,18 +6,19 @@ var defined = Cesium.defined; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponentType'); +var readBufferComponentType = require('./readBufferComponent'); module.exports = findAccessorMinMax; /** * Finds the min and max for an accessor in gltf. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {Object} accessor The accessor object from gltf to read. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @param {Object} accessor The accessor object from the glTF asset to read. * @returns {{min: Array, max: Array}} min holding the array of minimum values and max holding the array of maximum values. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/generateNormals.js b/lib/generateNormals.js index 28c707ad..909cd816 100644 --- a/lib/generateNormals.js +++ b/lib/generateNormals.js @@ -12,10 +12,11 @@ module.exports = generateNormals; /** * Generates normals for primitives if they do not exist. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with generated normals. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with generated normals. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/getBinaryGltf.js b/lib/getBinaryGltf.js index a9db8b69..bee4fc25 100644 --- a/lib/getBinaryGltf.js +++ b/lib/getBinaryGltf.js @@ -59,14 +59,15 @@ function updateBinaryObject(gltf, pipelineExtras, name, state) { } /** - * Get binary gltf representation of gltf. + * Get binary glTF representation of the glTF asset. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Boolean} embed Embed shaders into the binary. * @param {Boolean} embedImage Embed images into the binary * @returns {{glb: Buffer, header: Buffer, scene: Buffer, body: Buffer}} glb holds the whole buffer, each piece is also available via the returned object. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/getUniqueId.js b/lib/getUniqueId.js index 02164e78..1230faec 100644 --- a/lib/getUniqueId.js +++ b/lib/getUniqueId.js @@ -5,9 +5,9 @@ var defined = Cesium.defined; module.exports = getUniqueId; /** - * Given a prefix for a new ID, checks the gltf for matching prefixes in top-level objects with IDs and returns a unique ID. + * Given a prefix for a new ID, checks the glTF asset for matching prefixes in top-level objects with IDs and returns a unique ID. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {String} prefix The string to try to use as the id. * @returns {String} A unique id beginning with prefix. */ diff --git a/lib/loadGltfUris.js b/lib/loadGltfUris.js index ed2489af..060911ca 100644 --- a/lib/loadGltfUris.js +++ b/lib/loadGltfUris.js @@ -21,10 +21,10 @@ module.exports = loadGltfUris; * The buffer data is placed into extras._pipeline.source for the corresponding object. * glTF must be initialized for the pipeline. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} options Options for loading uris. * @param {String} options.basePath The path to look in when loading external files. - * @returns {Promise} A promise that resolves to gltf when all uris are loaded. + * @returns {Promise} A promise that resolves to the glTF asset when all uris are loaded. * * @see addPipelineExtras */ diff --git a/lib/mergeBuffers.js b/lib/mergeBuffers.js index e3eaabc8..a711aebf 100755 --- a/lib/mergeBuffers.js +++ b/lib/mergeBuffers.js @@ -10,11 +10,12 @@ module.exports = mergeBuffers; /** * Merge all buffers into one buffer. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {String} bufferName The id to use for the combined buffer. - * @returns {Object} gltf with one combined buffer. + * @returns {Object} The glTF asset with one combined buffer. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/mergeDuplicateAccessors.js b/lib/mergeDuplicateAccessors.js index 393d1427..a281f1ab 100644 --- a/lib/mergeDuplicateAccessors.js +++ b/lib/mergeDuplicateAccessors.js @@ -11,11 +11,12 @@ module.exports = mergeDuplicateAccessors; /** * Looks for accessors in a glTf hierarchy that contain the same data, removes all of the copies * and changes references to point to a single copy. + * + * The glTF asset must be initialized for the pipeline. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with merged duplicate accessors. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with merged duplicate accessors. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/mergeDuplicateVertices.js b/lib/mergeDuplicateVertices.js index 2c3f1c26..45499664 100644 --- a/lib/mergeDuplicateVertices.js +++ b/lib/mergeDuplicateVertices.js @@ -5,8 +5,8 @@ var defined = Cesium.defined; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponentType'); -var writeBufferComponentType = require('./writeBufferComponentType'); +var readBufferComponentType = require('./readBufferComponent'); +var writeBufferComponentType = require('./writeBufferComponent'); var removeUnusedVertices = require('./removeUnusedVertices'); module.exports = mergeDuplicateVertices; @@ -15,12 +15,14 @@ module.exports = mergeDuplicateVertices; * Looks for duplicated vertices in a glTF hierarchy and merges them, * modifying indices to account for the change if they exist. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with merged duplicate vertices. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with merged duplicate vertices. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris + * @see removeUnusedVertices */ function mergeDuplicateVertices(gltf) { var meshes = gltf.meshes; diff --git a/lib/modelMaterialsCommon.js b/lib/modelMaterialsCommon.js index 26ddfeb2..80f6c253 100644 --- a/lib/modelMaterialsCommon.js +++ b/lib/modelMaterialsCommon.js @@ -728,8 +728,6 @@ function lightDefaults(gltf) { } /** - * Modifies gltf in place. - * * @private */ function modelMaterialsCommon(gltf, options) { diff --git a/lib/octEncodeNormals.js b/lib/octEncodeNormals.js index 51ae52a5..80f7efb9 100644 --- a/lib/octEncodeNormals.js +++ b/lib/octEncodeNormals.js @@ -14,8 +14,8 @@ var findAccessorMinMax = require('./findAccessorMinMax'); var getAccessorByteStride = require('./getAccessorByteStride'); var getAccessorsForSemantic = require('./getAccessorsForSemantic'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponentType'); -var writeBufferComponentType = require('./writeBufferComponentType'); +var readBufferComponentType = require('./readBufferComponent'); +var writeBufferComponentType = require('./writeBufferComponent'); var uninterleaveAndPackBuffers = require('./uninterleaveAndPackBuffers'); module.exports = octEncodeNormals; @@ -23,11 +23,12 @@ module.exports = octEncodeNormals; /** * Oct-encodes the normal vectors of this model, converting each normal vector from three floating point numbers * down to two bytes. Modifies the model shader for decoding. + * + * The glTF asset must be initialized for the pipeline. * * @param {Object} gltf A glTF hierarchy. - * @returns {Promise} A promise that resolves to gltf when the operation completes. + * @returns {Promise} A promise that resolves to the glTF asset with oct-encoded normals when the operation completes. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/cacheOptimization.js b/lib/optimizeCache.js similarity index 93% rename from lib/cacheOptimization.js rename to lib/optimizeCache.js index eba632d5..8b386c82 100644 --- a/lib/cacheOptimization.js +++ b/lib/optimizeCache.js @@ -7,7 +7,7 @@ var createAccessorUsageTables = require('./createAccessorUsageTables'); var GeometryPipeline = Cesium.GeometryPipeline; var defined = Cesium.defined; -module.exports = cacheOptimization; +module.exports = optimizeCache; // Helper method to map accessor collections from the usageTable to an independent primitive (if there is one) function createIndicesToAttributeDictionary(gltf) { @@ -67,15 +67,16 @@ function getIndependentPrimitive(dictionary, indicesId, attributeAccessors) { * Uses Cesium's geometry optimizations to reorder attributes so that they are accessed * optimally by WebGL. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Number} [cacheSize=24] The cacheSize to use for Cesium.GeometryPipeline.reorderForPostVertexCache. - * @returns {Object} gltf with cache-optimized primitives. + * @returns {Object} The glTF asset with its indexed primitive attributes optimized for cache access. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ -function cacheOptimization(gltf, cacheSize) { +function optimizeCache(gltf, cacheSize) { // perform post vertex cache optimization var primitive; var geometry; diff --git a/lib/parseBinaryGltf.js b/lib/parseBinaryGltf.js index 2bdc4fb4..45da694d 100755 --- a/lib/parseBinaryGltf.js +++ b/lib/parseBinaryGltf.js @@ -16,7 +16,7 @@ module.exports = parseBinaryGltf; * Parses a binary glTF buffer into glTF JSON. * * @param {Buffer} data The binary glTF buffer to parse. - * @returns {Object} Parsed gltf from binary. + * @returns {Object} The parsed binary glTF. */ function parseBinaryGltf(data) { var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; diff --git a/lib/quantizeAttributes.js b/lib/quantizeAttributes.js index e5c95387..c7ae0c10 100644 --- a/lib/quantizeAttributes.js +++ b/lib/quantizeAttributes.js @@ -19,16 +19,17 @@ module.exports = quantizeAttributes; * If options.attributes is undefined, all quantizable attributes will be quantized with the provided options. * If options.precision is undefined, the decodeMatrix be written in its full form. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} [options=undefined] Defines more specific quantization behavior. * @param {Object} [options.semantics=undefined] Defines which semantics should be quantized. * @param {Object} [options.exclude=undefined] Don't quantize the specified semantics * @param {Number} [options.precision=undefined] Restricts the number of decimal places in the decodeMatrix. * @param {Boolean} [options.findMinMax=false] If this is true, the accessor min and max will be calculated. * - * @returns glTF with quantized attributes + * @returns The glTF asset with quantized attributes. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris * diff --git a/lib/readAccessor.js b/lib/readAccessor.js index 145b7c7d..6e6478f1 100644 --- a/lib/readAccessor.js +++ b/lib/readAccessor.js @@ -17,12 +17,13 @@ module.exports = readAccessor; /** * Reads data from the provided accessor into an array of Cesium types. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} accessor The glTF accessor to read. * @param {Array} results The resulting Cesium data structures are pushed into results. * @returns {Number} The WebGLConstants type used to generate the Cesium data structures. (e.g. WebGLConstants.FLOAT_VEC3 for Cartesian3) * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/readBufferComponentType.js b/lib/readBufferComponent.js similarity index 100% rename from lib/readBufferComponentType.js rename to lib/readBufferComponent.js diff --git a/lib/readGltf.js b/lib/readGltf.js index 9ed68abd..71ddbeb2 100644 --- a/lib/readGltf.js +++ b/lib/readGltf.js @@ -16,8 +16,8 @@ var fsReadFile = Promise.promisify(fs.readFile); module.exports = readGltf; /** - * Reads a glTF file from the disk. - * @param {String} gltfPath The file path for the glTF. + * Reads a glTF asset from the disk. + * @param {String} gltfPath The file path for the glTF asset. * @param {Object} options Options defining custom behavior. * @param {String} [options.basePath] The base path to use for resolving external references. Defaults to the directory containing the glTF. * @returns {Object} A javascript object containing a glTF hierarchy. diff --git a/lib/removeDuplicatePrimitives.js b/lib/removeDuplicatePrimitives.js index b9747b1a..9a58ab0a 100644 --- a/lib/removeDuplicatePrimitives.js +++ b/lib/removeDuplicatePrimitives.js @@ -9,11 +9,11 @@ var defined = Cesium.defined; module.exports = removeDuplicatePrimitives; /** - * Removes duplicate primitives from gltf. + * Removes duplicate primitives from the glTF asset. * Duplicate primitives are primitives within meshes that access the same data. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf without duplicate primitives. + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset without duplicate primitives. */ function removeDuplicatePrimitives(gltf) { var meshes = gltf.meshes; diff --git a/lib/removeUnusedVertices.js b/lib/removeUnusedVertices.js index 767747db..2c02163b 100755 --- a/lib/removeUnusedVertices.js +++ b/lib/removeUnusedVertices.js @@ -14,9 +14,16 @@ var uninterleaveAndPackBuffers = require('./uninterleaveAndPackBuffers'); module.exports = removeUnusedVertices; /** - * Removes attributes from indexed primitives that are not used. - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf without unused vertices. + * Removes attributes from indexed primitives in the glTF asset that are not used. + * + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset without unused vertices. + * + * @see addPipelineExtras + * @see loadGltfUris + * @see uninterleaveAndPackBuffers */ function removeUnusedVertices(gltf) { if (defined(gltf.accessors) && defined(gltf.buffers) && defined(gltf.bufferViews) && defined(gltf.meshes)) { diff --git a/lib/uninterleaveAndPackBuffers.js b/lib/uninterleaveAndPackBuffers.js index fcd03e7f..0efcf4fc 100644 --- a/lib/uninterleaveAndPackBuffers.js +++ b/lib/uninterleaveAndPackBuffers.js @@ -15,10 +15,11 @@ module.exports = uninterleaveAndPackBuffers; * Repacks the accessed buffer data into contiguous chunks. * Also has the effect of un-interleaving interleaved accessors. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @returns {Object} gltf with repacked buffers. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @returns {Object} The glTF asset with repacked buffers. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/writeAccessor.js b/lib/writeAccessor.js index daa99dcc..952992f7 100644 --- a/lib/writeAccessor.js +++ b/lib/writeAccessor.js @@ -5,22 +5,23 @@ var numberOfComponentsForType = require('./numberOfComponentsForType'); module.exports = writeAccessor; /** - * Writes the contents of dataArray into an accessor. + * Writes the contents of dataArray into a glTF accessor. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. - * @param {Object} accessor glTF accessor where data should be written. - * @param {Array} dataArray Data to write into the accessor. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. + * @param {Object} accessor The glTF accessor where data should be written. + * @param {Array} values Values to write into the accessor. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ -function writeAccessor(gltf, accessor, dataArray) { +function writeAccessor(gltf, accessor, values) { var accessorReader = new AccessorReader(gltf, accessor); var componentType = accessor.componentType; var numberOfComponents = numberOfComponentsForType(accessor.type); do { - accessorReader.write(dataArray, componentType, numberOfComponents * accessorReader.index); + accessorReader.write(values, componentType, numberOfComponents * accessorReader.index); accessorReader.next(); } while (accessorReader.hasNext()); diff --git a/lib/writeBinaryGltf.js b/lib/writeBinaryGltf.js index 56239cc2..3a458573 100644 --- a/lib/writeBinaryGltf.js +++ b/lib/writeBinaryGltf.js @@ -15,9 +15,11 @@ fsExtra.outputFileAsync = Promise.promisify(fsExtra.outputFile); module.exports = writeBinaryGltf; /** - * Writes gltf to file as binary glTF. + * Writes a glTF asset to a file as binary glTF. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} options Defines custom behavior for writing. * @param {String} options.outputPath The file path where the binary glTF should be written. * @param {Boolean} options.embed Flag to embed shader uris. @@ -25,7 +27,6 @@ module.exports = writeBinaryGltf; * @param {Boolean} options.createDirectory If true, a directory named 'output' will be created at options.outputPath and the output will be written there. * @returns {Promise} A promise resolving when the write operation completes. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/lib/writeBufferComponentType.js b/lib/writeBufferComponent.js similarity index 100% rename from lib/writeBufferComponentType.js rename to lib/writeBufferComponent.js diff --git a/lib/writeGltf.js b/lib/writeGltf.js index 7f6a72e0..b0b2c475 100755 --- a/lib/writeGltf.js +++ b/lib/writeGltf.js @@ -15,9 +15,11 @@ fsExtra.outputJsonAsync = Promise.promisify(fsExtra.outputJson); module.exports = writeGltf; /** - * Writes gltf to a file. + * Writes the glTF asset to a file. * - * @param {Object} gltf A javascript object holding a glTF hierarchy. + * The glTF asset must be initialized for the pipeline. + * + * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} options Defines custom behavior for writing. * @param {String} options.outputPath The file path where the glTF should be written. * @param {Boolean} options.embed Flag to embed shader uris. @@ -25,7 +27,6 @@ module.exports = writeGltf; * @param {Boolean} options.createDirectory If true, a directory named 'output' will be created at options.outputPath and the output will be written there. * @returns {Promise} A promise resolving when the write operation completes. * - * gltf must be initialized for the pipeline. * @see addPipelineExtras * @see loadGltfUris */ diff --git a/specs/lib/AmbientOcclusionSpec.js b/specs/lib/AmbientOcclusionSpec.js index 1b16cfff..78153b2e 100644 --- a/specs/lib/AmbientOcclusionSpec.js +++ b/specs/lib/AmbientOcclusionSpec.js @@ -232,10 +232,9 @@ describe('AmbientOcclusion', function() { resolution : 10, toTexture : true, sceneID : testGltf.scene, - gltfWithExtras : testGltf, rayDistance : 10.0 }; - var raytracerScene = AmbientOcclusion.generateRaytracerScene(options); + var raytracerScene = AmbientOcclusion.generateRaytracerScene(testGltf, options); var triangleSoup = raytracerScene.triangleGrid.items; // because of the uniform scale, expect triangles to be bigger @@ -273,10 +272,9 @@ describe('AmbientOcclusion', function() { rayDistance : 1.0, groundPlane : true, nearCull : CesiumMath.EPSILON4, - sceneID : testGltf.scene, - gltfWithExtras : testGltf + sceneID : testGltf.scene }; - var raytracerScene = AmbientOcclusion.generateRaytracerScene(options); + var raytracerScene = AmbientOcclusion.generateRaytracerScene(testGltf, options); var triangleSoup = raytracerScene.triangleGrid.items; // ground plane size is based on the near culling distance, scene size, and maximum ray depth. @@ -383,10 +381,9 @@ describe('AmbientOcclusion', function() { var options = { numberRays: 0, resolution: 4, - toTexture: true, - gltfWithExtras: boxOverGroundGltfClone + toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(2); expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -412,10 +409,9 @@ describe('AmbientOcclusion', function() { var options = { numberRays: 0, resolution: 4, - toTexture: true, - gltfWithExtras: boxOverGroundGltfClone + toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(2); expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -441,10 +437,9 @@ describe('AmbientOcclusion', function() { var options = { numberRays: 0, resolution: 4, - toTexture: true, - gltfWithExtras: boxOverGroundGltfClone + toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 images with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -465,15 +460,14 @@ describe('AmbientOcclusion', function() { primitive.material = materialID; }; - NodeHelpers.forEachPrimitiveInScene(boxOverGroundGltfClone, scene, primitiveFunction); + NodeHelpers.forEachPrimitiveInScene(boxOverGroundGltfClone, scene, primitiveFunction, {}); var options = { numberRays: 0, resolution: 4, - toTexture: true, - gltfWithExtras: boxOverGroundGltfClone + toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(3); // 1 unused texture, 2 with AO @@ -497,10 +491,9 @@ describe('AmbientOcclusion', function() { var options = { numberRays: 0, resolution: 4, - toTexture: true, - gltfWithExtras: boxOverGroundGltfClone + toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 images with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(3); // 1 unused texture, 2 with AO @@ -512,10 +505,9 @@ describe('AmbientOcclusion', function() { var options = { numberRays: 0, - toVertex: true, - gltfWithExtras: boxOverGroundGltfClone + toVertex: true }; - AmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.accessors).length).toEqual(10); var cubeMeshPrimitives = boxOverGroundGltfClone.meshes.Cube_mesh.primitives; @@ -531,10 +523,9 @@ describe('AmbientOcclusion', function() { var options = { numberRays: 0, - toVertex: true, - gltfWithExtras: boxOverGroundGltfClone + toVertex: true }; - AmbientOcclusion.bakeAmbientOcclusion(options); + AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.materials).length).toEqual(4); expect(Object.keys(boxOverGroundGltfClone.techniques).length).toEqual(2); @@ -651,11 +642,8 @@ describe('AmbientOcclusion', function() { }); it('generates options given nothing but a gltf or just a quality setting', function() { - var aoOptions = { - gltfWithExtras: boxOverGroundGltf - }; - - var options = AmbientOcclusion.generateOptions(aoOptions); + var aoOptions = {}; + var options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -669,10 +657,9 @@ describe('AmbientOcclusion', function() { expect(options.sceneID).toEqual('defaultScene'); aoOptions = { - quality: 'medium', - gltfWithExtras: boxOverGroundGltf + quality: 'medium' }; - options = AmbientOcclusion.generateOptions(aoOptions); + options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -686,10 +673,9 @@ describe('AmbientOcclusion', function() { expect(options.sceneID).toEqual('defaultScene'); aoOptions = { - quality: 'high', - gltfWithExtras: boxOverGroundGltf + quality: 'high' }; - options = AmbientOcclusion.generateOptions(aoOptions); + options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -708,10 +694,9 @@ describe('AmbientOcclusion', function() { quality: 'medium', toTexture: true, triangleCenterOnly: true, - rayDistance: 10.0, - gltfWithExtras: boxOverGroundGltf + rayDistance: 10.0 }; - var options = AmbientOcclusion.generateOptions(aoOptions); + var options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(true); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); diff --git a/specs/lib/RemoveUnusedElementsSpec.js b/specs/lib/RemoveUnusedPropertiesSpec.js similarity index 97% rename from specs/lib/RemoveUnusedElementsSpec.js rename to specs/lib/RemoveUnusedPropertiesSpec.js index 80422183..29b8cc35 100644 --- a/specs/lib/RemoveUnusedElementsSpec.js +++ b/specs/lib/RemoveUnusedPropertiesSpec.js @@ -3,14 +3,14 @@ var Promise = require('bluebird'); var fs = require('fs-extra'); -var RemoveUnusedElements = require('../../lib/RemoveUnusedElements'); +var RemoveUnusedProperties = require('../../lib/RemoveUnusedProperties'); var fsReadFile = Promise.promisify(fs.readFile); var gltfPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTestUnusedTree.gltf'; -describe('RemoveUnusedElements', function() { - var removeUnusedNodes = RemoveUnusedElements.removeUnusedNodes; +describe('RemoveUnusedProperties', function() { + var removeUnusedNodes = RemoveUnusedProperties.removeUnusedNodes; describe('removeUnusedNodes', function () { it('removes an isolated node', function () { var gltf = { @@ -153,7 +153,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedSkins = RemoveUnusedElements.removeUnusedSkins; + var removeUnusedSkins = RemoveUnusedProperties.removeUnusedSkins; describe('removeUnusedSkins', function () { it('removes a skin', function () { var gltf = { @@ -204,7 +204,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedCameras = RemoveUnusedElements.removeUnusedCameras; + var removeUnusedCameras = RemoveUnusedProperties.removeUnusedCameras; describe('removeUnusedCameras', function () { it('removes a camera', function () { var gltf = { @@ -264,7 +264,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedMeshes = RemoveUnusedElements.removeUnusedMeshes; + var removeUnusedMeshes = RemoveUnusedProperties.removeUnusedMeshes; describe('removeUnusedMeshes', function () { it('removes a mesh', function () { var gltf = { @@ -304,7 +304,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedAccessors = RemoveUnusedElements.removeUnusedAccessors; + var removeUnusedAccessors = RemoveUnusedProperties.removeUnusedAccessors; describe('removeUnusedAccessors', function () { it('removes an accessor', function () { var gltf = { @@ -446,7 +446,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedMaterials = RemoveUnusedElements.removeUnusedMaterials; + var removeUnusedMaterials = RemoveUnusedProperties.removeUnusedMaterials; describe('removeUnusedMaterials', function () { it('removes a material', function () { var gltf = { @@ -511,7 +511,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedBufferViews = RemoveUnusedElements.removeUnusedBufferViews; + var removeUnusedBufferViews = RemoveUnusedProperties.removeUnusedBufferViews; describe('removeUnusedBufferViews', function () { it('removes a bufferView', function () { var gltf = { @@ -572,7 +572,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedTechniques = RemoveUnusedElements.removeUnusedTechniques; + var removeUnusedTechniques = RemoveUnusedProperties.removeUnusedTechniques; describe('removeUnusedTechniques', function () { it('removes a technique', function () { var gltf = { @@ -691,7 +691,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedTextures = RemoveUnusedElements.removeUnusedTextures; + var removeUnusedTextures = RemoveUnusedProperties.removeUnusedTextures; describe('removeUnusedTextures', function () { it('removes a texture', function () { var gltf = { @@ -828,7 +828,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedBuffers = RemoveUnusedElements.removeUnusedBuffers; + var removeUnusedBuffers = RemoveUnusedProperties.removeUnusedBuffers; describe('removeUnusedBuffers', function () { it('removes a buffer', function () { var gltf = { @@ -882,7 +882,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedPrograms = RemoveUnusedElements.removeUnusedPrograms; + var removeUnusedPrograms = RemoveUnusedProperties.removeUnusedPrograms; describe('removeUnusedPrograms', function () { it('removes a program', function () { var gltf = { @@ -982,7 +982,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedImages = RemoveUnusedElements.removeUnusedImages; + var removeUnusedImages = RemoveUnusedProperties.removeUnusedImages; describe('removeUnusedImages', function() { it('removes an image', function() { var gltf = { @@ -1037,7 +1037,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedSamplers = RemoveUnusedElements.removeUnusedSamplers; + var removeUnusedSamplers = RemoveUnusedProperties.removeUnusedSamplers; describe('removeUnusedSamplers', function() { it('removes a sampler', function() { var gltf = { @@ -1098,7 +1098,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedShaders = RemoveUnusedElements.removeUnusedShaders; + var removeUnusedShaders = RemoveUnusedProperties.removeUnusedShaders; describe('removeUnusedShaders', function() { it('removes a shader', function() { var gltf = { @@ -1164,7 +1164,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeUnusedPrimitiveAttributes = RemoveUnusedElements.removeUnusedPrimitiveAttributes; + var removeUnusedPrimitiveAttributes = RemoveUnusedProperties.removeUnusedPrimitiveAttributes; describe('removeUnusedPrimitiveAttributes', function() { it('removes unused primitive attributes', function() { var gltf = { @@ -1216,7 +1216,7 @@ describe('RemoveUnusedElements', function() { }); }); - var removeAllUnused = RemoveUnusedElements.removeAllUnused; + var removeAllUnused = RemoveUnusedProperties.removeAllUnused; describe('removeAllUnused', function() { it('removes a tree of objects', function (done) { expect(fsReadFile(gltfPath) diff --git a/specs/lib/cacheOptimizationSpec.js b/specs/lib/optimizeCacheSpec.js similarity index 94% rename from specs/lib/cacheOptimizationSpec.js rename to specs/lib/optimizeCacheSpec.js index 6110fbea..540c11e1 100644 --- a/specs/lib/cacheOptimizationSpec.js +++ b/specs/lib/optimizeCacheSpec.js @@ -3,7 +3,7 @@ var Cesium = require('cesium'); var GeometryPipeline = Cesium.GeometryPipeline; var addDefaults = require('../../lib/addDefaults'); -var cacheOptimization = require('../../lib/cacheOptimization'); +var optimizeCache = require('../../lib/optimizeCache'); var readAccessor = require('../../lib/readAccessor'); var readGltf = require('../../lib/readGltf'); var writeAccessor = require('../../lib/writeAccessor'); @@ -23,7 +23,7 @@ var optimizedVertices = [ 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5 ]; -describe('cacheOptimization', function() { +describe('optimizeCache', function() { it('reorders indices', function(done) { var options = {}; expect(readGltf(gltfPath, options) @@ -34,7 +34,7 @@ describe('cacheOptimization', function() { // Rewrite indices to be forcibly unoptimized writeAccessor(gltf, indexAccessor, unoptimizedIndices); - cacheOptimization(gltf); + optimizeCache(gltf); var indices = []; readAccessor(gltf, gltf.accessors[indexAccessorId], indices); @@ -57,7 +57,7 @@ describe('cacheOptimization', function() { var positions = []; readAccessor(gltf, positionAccessor, positions); - cacheOptimization(gltf); + optimizeCache(gltf); expect(positions).toEqual(unpackedOptimizedVertices); }), done).toResolve(); @@ -79,7 +79,7 @@ describe('cacheOptimization', function() { } }; spyOn(GeometryPipeline, 'reorderForPostVertexCache'); - cacheOptimization(gltf); + optimizeCache(gltf); expect(GeometryPipeline.reorderForPostVertexCache).not.toHaveBeenCalled(); }); }); From 5687191d81e881654970ba05d686164fe277994b Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 17 Aug 2016 11:44:23 -0400 Subject: [PATCH 16/21] NodeHelpers should be private --- lib/NodeHelpers.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/NodeHelpers.js b/lib/NodeHelpers.js index 5453a108..506e5cde 100644 --- a/lib/NodeHelpers.js +++ b/lib/NodeHelpers.js @@ -13,6 +13,8 @@ module.exports = NodeHelpers; * A set of helper function for working with glTF nodes. * Should be called after convertDagToTree * @constructor + * + * @private */ function NodeHelpers() {} @@ -42,6 +44,8 @@ function flattenTransform(parameters, node, parent) { * * @see addPipelineExtras * @see loadGltfUris + * + * @private */ NodeHelpers.computeFlatTransformScene = function(scene, nodes) { var rootNodeIDs = scene.nodes; @@ -69,6 +73,8 @@ function addNodeToArray(parameters, node) { * @param {Object} nodes glTF top-level nodes object. * @param {Array} [resultArray] Store the nodes into resultArray. * @returns {Array} An array of all nodes in the scene. + * + * @private */ NodeHelpers.getAllNodesInScene = function(scene, nodes, resultArray) { var rootNodeIDs = scene.nodes; @@ -96,6 +102,8 @@ NodeHelpers.getAllNodesInScene = function(scene, nodes, resultArray) { * @param {Object} allNodes glTF top-level nodes object. * @param {Function} functionChildParent Function to apply to the child and parent. * @param {Object} parameters Parameters to pass as the first argument to functionChildParent. + * + * @private */ NodeHelpers.depthFirstTraversal = function(rootNode, allNodes, functionChildParent, parameters) { // process the root node @@ -130,6 +138,8 @@ NodeHelpers.depthFirstTraversal = function(rootNode, allNodes, functionChildPare * @param {Object} node glTF node with a transform. * @param {Matrix4} [result] Store the transform matrix into result. * @returns {Matrix4} The node transform matrix. + * + * @private */ NodeHelpers.getLocalMatrix4 = function(node, result) { if (!defined(result)) { @@ -176,6 +186,8 @@ var packedParametersScratch = { * @param {Object} scene The glTF scene to traverse. * @param {Function} primitiveFunction The function to apply to each primitive. * @param {Object} parameters Parameters to pass to primitiveFunction. + * + * @private */ NodeHelpers.forEachPrimitiveInScene = function(gltf, scene, primitiveFunction, parameters) { var rootNodeNames = scene.nodes; @@ -217,6 +229,8 @@ function forEachPrimitiveInNode(packedParameters, node) { * * @param {Object} gltf A javascript object containing a glTF asset. * @returns {Object} An object with meshIds as keys with arrays of corresponding nodeIds as values. + * + * @private */ NodeHelpers.mapMeshesToNodes = function(gltf) { var meshesToNodes = {}; From d3c8e018eba6acfc6916c272e157caf3b6c919bc Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 17 Aug 2016 11:45:09 -0400 Subject: [PATCH 17/21] Fixed doc error --- lib/NodeHelpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/NodeHelpers.js b/lib/NodeHelpers.js index 506e5cde..fb0bf8af 100644 --- a/lib/NodeHelpers.js +++ b/lib/NodeHelpers.js @@ -69,7 +69,7 @@ function addNodeToArray(parameters, node) { * Get all the nodes in a scene. * If resultArray is undefined, a new array will be created. * - * @param {scene} The glTF scene to traverse. + * @param {Object} scene The glTF scene to traverse. * @param {Object} nodes glTF top-level nodes object. * @param {Array} [resultArray] Store the nodes into resultArray. * @returns {Array} An array of all nodes in the scene. From 3395a4f235ab8118475a7f59e9a85e0d8a3f6ec6 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 17 Aug 2016 15:11:27 -0400 Subject: [PATCH 18/21] Cleanup --- index.js | 8 +-- lib/AccessorReader.js | 11 ++-- lib/AmbientOcclusion.js | 2 +- lib/Pipeline.js | 17 +++-- lib/addCesiumRTC.js | 63 +++++++++---------- lib/addDefaults.js | 22 ++++--- lib/combineMeshes.js | 2 +- lib/combinePrimitives.js | 8 +-- lib/compressIntegerAccessors.js | 1 + lib/compressTextureCoordinates.js | 8 +-- lib/createAccessorUsageTables.js | 4 +- lib/findAccessorMinMax.js | 4 +- lib/getAccessorsForSemantic.js | 1 + lib/getBinaryGltf.js | 2 +- lib/gltfPrimitiveToCesiumGeometry.js | 3 + lib/loadGltfUris.js | 1 + lib/mergeDuplicateVertices.js | 10 +-- lib/modelMaterialsCommon.js | 2 + lib/octEncodeNormals.js | 10 +-- lib/quantizeAttributes.js | 37 +++++------ lib/readBufferComponent.js | 4 +- lib/readGltf.js | 5 +- lib/writeBufferComponent.js | 4 +- specs/lib/PipelineSpec.js | 32 +++++----- specs/lib/addDefaultsSpec.js | 52 ++++++++------- .../lib/cesiumGeometryToGltfPrimitiveSpec.js | 3 +- specs/lib/combinePrimitivesSpec.js | 14 ++--- specs/lib/generateNormalsSpec.js | 6 +- specs/lib/getBinaryGltfSpec.js | 3 +- .../lib/gltfPrimitiveToCesiumGeometrySpec.js | 3 +- specs/lib/isDataUriSpec.js | 2 +- specs/lib/optimizeCacheSpec.js | 6 +- specs/lib/readAccessorSpec.js | 3 +- specs/lib/readGltfSpec.js | 10 ++- specs/lib/writeBinaryGltfSpec.js | 9 +-- specs/lib/writeGltfSpec.js | 9 +-- 36 files changed, 189 insertions(+), 192 deletions(-) diff --git a/index.js b/index.js index 618f61dd..26f1c6ab 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,5 @@ module.exports = { AccessorReader : require('./lib/AccessorReader'), - Pipeline : require('./lib/Pipeline'), - RemoveUnusedElements : require('./RemoveUnusedElements'), addCesiumRTC : require('./lib/addCesiumRTC'), addDefaults : require('./lib/addDefaults'), addExtensionsUsed : require('./lib/addExtensionsUsed'), @@ -28,16 +26,18 @@ module.exports = { optimizeCache : require('./lib/optimizeCache'), packArray : require('./lib/packArray'), parseBinaryGltf : require('./lib/parseBinaryGltf'), + Pipeline : require('./lib/Pipeline'), quantizeAttributes : require('./lib/quantizeAttributes'), readAccessor : require('./lib/readAccessor'), - readBufferComponentType : require('./lib/readBufferComponent'), + readBufferComponent : require('./lib/readBufferComponent'), readGltf : require('./lib/readGltf'), removeDuplicatePrimitives : require('./lib/removeDuplicatePrimitives'), removePipelineExtras : require('./lib/removePipelineExtras'), + RemoveUnusedProperties : require('./lib/RemoveUnusedProperties'), removeUnusedVertices : require('./lib/removeUnusedVertices'), uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers'), writeAccessor : require('./lib/writeAccessor'), writeBinaryGltf : require('./lib/writeBinaryGltf'), - writeBufferComponentType : require('./lib/writeBufferComponent'), + writeBufferComponent : require('./lib/writeBufferComponent'), writeGltf : require('./lib/writeGltf') }; \ No newline at end of file diff --git a/lib/AccessorReader.js b/lib/AccessorReader.js index 68460262..52da7a46 100644 --- a/lib/AccessorReader.js +++ b/lib/AccessorReader.js @@ -5,15 +5,16 @@ var defaultValue = Cesium.defaultValue; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponent'); -var writeBufferComponentType = require('./writeBufferComponent'); +var readBufferComponent = require('./readBufferComponent'); +var writeBufferComponent = require('./writeBufferComponent'); module.exports = AccessorReader; /** * Reads an accessor incrementally. This is useful to keep overhead low when * memory consumption is important. - * glTF must be initialized for the pipeline. + * + * The glTF asset must be initialized for the pipeline. * * @param {Object} gltf A javascript object containing a glTF asset. * @param {Object} accessor The accessor object from glTF to read. @@ -56,7 +57,7 @@ AccessorReader.prototype.read = function(components) { } var componentByteLength = byteLengthForComponentType(this.componentType); for (var i = 0; i < this.numberOfComponents; i++) { - var data = readBufferComponentType(this.source, + var data = readBufferComponent(this.source, this.componentType, this.byteOffset + (this.byteStride * this.index) + (componentByteLength * i) ); @@ -88,7 +89,7 @@ AccessorReader.prototype.write = function(data, componentType, dataOffset) { byteStride = byteLengthForComponentType(componentType) * this.numberOfComponents; } for (var i = 0; i < this.numberOfComponents; i++) { - writeBufferComponentType(this.source, + writeBufferComponent(this.source, componentType, data[i + dataOffset], this.byteOffset + (byteStride * this.index) + (componentByteLength * i) diff --git a/lib/AmbientOcclusion.js b/lib/AmbientOcclusion.js index c60db7ea..8577c27d 100644 --- a/lib/AmbientOcclusion.js +++ b/lib/AmbientOcclusion.js @@ -49,7 +49,7 @@ function AmbientOcclusion() {} * The glTF asset must be initialized for the pipeline. * * @param {Object} gltf A javascript object containing a glTF asset. - * @param {Object} aoOptions All options for baking AO including a glTF asset with extras and AO parameters + * @param {Object} [aoOptions] All options for baking AO including a glTF asset with extras and AO parameters * * Basic options: * @param {Boolean} [aoOptions.toTexture=false] Bake AO to existing diffuse textures instead of to vertices. Does not modify shaders. diff --git a/lib/Pipeline.js b/lib/Pipeline.js index 8d9da01a..9f5c1061 100644 --- a/lib/Pipeline.js +++ b/lib/Pipeline.js @@ -46,13 +46,14 @@ function Pipeline() {} * Options are passed to loadGltfUris and processJSONWithExtras. * * @param {Object} gltf A javascript object containing a glTF asset. - * @param {Object} options Options to apply to stages during optimization. + * @param {Object} [options] Options to apply to stages during optimization. * @returns {Promise} A promise that resolves to the processed glTF asset. * * @see loadGltfUris * @see Pipeline.processJSONWithExtras */ Pipeline.processJSON = function(gltf, options) { + options = defaultValue(options, {}); addPipelineExtras(gltf); return loadGltfUris(gltf, options) .then(function(gltf) { @@ -67,7 +68,7 @@ Pipeline.processJSON = function(gltf, options) { * Process a glTF asset that already has extras and loaded uris. * * @param {Object} gltfWithExtras A javascript object holding a glTF hierarchy with extras. - * @param {Object} options Options to apply to stages during optimization. + * @param {Object} [options] Options to apply to stages during optimization. * @param {Object} [options.aoOptions=undefined] Options to pass to the bakeAmbientOcclusion stage, if undefined, stage is not run. * @param {Object} [options.encodeNormals=false] Flag to run octEncodeNormals stage. * @param {Object} [options.compressTextureCoordinates=false] Flag to run compressTextureCoordinates stage. @@ -75,6 +76,7 @@ Pipeline.processJSON = function(gltf, options) { * @returns {Promise} A promise that resolves to the processed glTF asset. */ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { + options = defaultValue(options, {}); addDefaults(gltfWithExtras, options); removeAllUnused(gltfWithExtras); // It is generally better to merge the duplicate vertices before merging accessors. @@ -138,12 +140,13 @@ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { * Options are passed to processJSONWithExtras. * * @param {String} inputPath The input file path. - * @param {Object} options Options to apply to stages during optimization. + * @param {Object} [options] Options to apply to stages during optimization. * @returns {Object} The processed glTF asset. * * @see Pipeline.processJSONWithExtras */ -Pipeline.processFile =function processFile(inputPath, options) { +Pipeline.processFile = function processFile(inputPath, options) { + options = defaultValue(options, {}); return readGltf(inputPath, options) .then(function(gltf) { return Pipeline.processJSONWithExtras(gltf, options); @@ -159,7 +162,7 @@ Pipeline.processFile =function processFile(inputPath, options) { * * @param {Object} gltf A javascript object containing a glTF asset. * @param {String} outputPath The output file destination. - * @param {Object} options Options to apply to stages during optimization. + * @param {Object} [options] Options to apply to stages during optimization. * @returns {Promise} A promise that resolves when the operation is complete. * * @see loadGltfUris @@ -168,6 +171,7 @@ Pipeline.processFile =function processFile(inputPath, options) { * @see writeBinaryGltf */ Pipeline.processJSONToDisk = function(gltf, outputPath, options) { + options = defaultValue(options, {}); addPipelineExtras(gltf); return loadGltfUris(gltf, options) .then(function(gltf) { @@ -184,7 +188,7 @@ Pipeline.processJSONToDisk = function(gltf, outputPath, options) { * * @param {String} inputPath The input file path. * @param {String} outputPath The output file destination - * @param {Object} options Options to apply to stages during optimization. + * @param {Object} [options] Options to apply to stages during optimization. * @returns {Promise} A promise that resolves when the operation is complete. * * @see Pipeline.processJSONWithExtras @@ -193,6 +197,7 @@ Pipeline.processJSONToDisk = function(gltf, outputPath, options) { * @see writeBinaryGltf */ Pipeline.processFileToDisk = function(inputPath, outputPath, options) { + options = defaultValue(options, {}); return readGltf(inputPath, options) .then(function(gltf) { return Pipeline.processJSONWithExtras(gltf, options); diff --git a/lib/addCesiumRTC.js b/lib/addCesiumRTC.js index 99835c73..e9dbf7fa 100644 --- a/lib/addCesiumRTC.js +++ b/lib/addCesiumRTC.js @@ -24,39 +24,38 @@ module.exports = addCesiumRTC; * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to use for lat-long mapping. */ function addCesiumRTC(gltf, options) { - if (defined(options)) { - var positionArray = []; - var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); - var position = options.position; - if (!defined(position)) { - if (defined(options.longitude) && defined(options.latitude && defined(options.height))) { - position = Cartesian3.fromRadians(options.longitude, options.latitude, options.height, ellipsoid); - } else { - throw new DeveloperError('Either a position or lat/long/height must be provided'); - } - } - Cartesian3.pack(position, positionArray); - var extensions = gltf.extensions; - if (!defined(extensions)) { - extensions = {}; - gltf.extensions = extensions; + options = defaultValue(options, {}); + var positionArray = []; + var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + var position = options.position; + if (!defined(position)) { + if (defined(options.longitude) && defined(options.latitude) && defined(options.height)) { + position = Cartesian3.fromRadians(options.longitude, options.latitude, options.height, ellipsoid); + } else { + throw new DeveloperError('Either a position or lat/long/height must be provided'); } - extensions.CESIUM_RTC = { - center : positionArray - }; - addExtensionsUsed(gltf, 'CESIUM_RTC'); - var techniques = gltf.techniques; - for (var techniqueId in techniques) { - if (techniques.hasOwnProperty(techniqueId)) { - var technique = techniques[techniqueId]; - var parameters = technique.parameters; - if (defined(parameters)) { - for (var parameterId in parameters) { - if (parameters.hasOwnProperty(parameterId)) { - if (parameterId === 'modelViewMatrix') { - var parameter = parameters[parameterId]; - parameter.semantic = 'CESIUM_RTC_MODELVIEW'; - } + } + Cartesian3.pack(position, positionArray); + var extensions = gltf.extensions; + if (!defined(extensions)) { + extensions = {}; + gltf.extensions = extensions; + } + extensions.CESIUM_RTC = { + center : positionArray + }; + addExtensionsUsed(gltf, 'CESIUM_RTC'); + var techniques = gltf.techniques; + for (var techniqueId in techniques) { + if (techniques.hasOwnProperty(techniqueId)) { + var technique = techniques[techniqueId]; + var parameters = technique.parameters; + if (defined(parameters)) { + for (var parameterId in parameters) { + if (parameters.hasOwnProperty(parameterId)) { + if (parameterId === 'modelViewMatrix') { + var parameter = parameters[parameterId]; + parameter.semantic = 'CESIUM_RTC_MODELVIEW'; } } } diff --git a/lib/addDefaults.js b/lib/addDefaults.js index eee3253b..4ccdb096 100644 --- a/lib/addDefaults.js +++ b/lib/addDefaults.js @@ -139,7 +139,7 @@ function checkIfFloatVec4(value) { function guessExtensionTechnique(gltf, material, options) { // Replaces the material technique, extension, and values with a close equivalent from KHR_materials_common. // If no equivalent can be found, defaults to blinn for specular materials and lambert otherwise - var technique = defaultValue(options.diffuseTechnique, 'LAMBERT'); + var technique = options.technique; var values = defined(material.values) ? material.values : {}; var ambient = checkIfFloatVec4(values.ambient); @@ -147,9 +147,15 @@ function guessExtensionTechnique(gltf, material, options) { var emission = typeof(values.emission) === 'string' ? values.emission : checkIfFloatVec4(values.emission); var specular = typeof(values.specular) === 'string' ? values.specular : checkIfFloatVec4(values.specular); var shininess = typeof(values.shininess) === 'number' ? values.shininess : 0.0; - if (defined(values.specular) || defined(values.shininess)) { - technique = defaultValue(options.specularTechnique, 'BLINN'); + + if (!defined(technique)) { + if (defined(values.specular) || defined(values.shininess)) { + technique = 'BLINN'; + } else { + technique = 'LAMBERT'; + } } + var transparency = typeof(values.transparency) === 'number' ? values.transparency : 1.0; var diffuseTransparent = false; @@ -510,18 +516,16 @@ function textureDefaults(gltf) { * The glTF asset must be initialized for the pipeline. * * @param {Object} gltf A javascript object containing a glTF asset. - * @param {Object} [options={}] + * @param {Object} [options] An object with the following properties: + * @param {String} [options.technique] The shading technique to use. Possible techniques are 'CONSTANT', 'LAMBERT', 'BLINN', and 'PHONG'. + * @param {Boolean} [options.optimizeForCesium] Optimize the defaults for Cesium. Uses the Cesium sun as the default light source. * @returns {Object} The modified glTF. * * @see addPipelineExtras * @see loadGltfUris */ function addDefaults(gltf, options) { - options = defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT); - - if (!defined(gltf)) { - return undefined; - } + options = defaultValue(options, {}); if (defined(gltf.allExtensions)) { gltf.extensionsUsed = gltf.allExtensions; diff --git a/lib/combineMeshes.js b/lib/combineMeshes.js index 92db73c8..f667a370 100755 --- a/lib/combineMeshes.js +++ b/lib/combineMeshes.js @@ -7,7 +7,7 @@ module.exports = combineMeshes; /** * Combines meshes in a node. - * Should be run before the combinePrimitives stage to merge all primitives for a node into one mesh. + * Should be run before the {@link combinePrimitives} stage to merge all primitives for a node into one mesh. * * The glTF asset must be initialized for the pipeline. * diff --git a/lib/combinePrimitives.js b/lib/combinePrimitives.js index cfcd87ae..f9ef053e 100755 --- a/lib/combinePrimitives.js +++ b/lib/combinePrimitives.js @@ -7,8 +7,8 @@ var DeveloperError = Cesium.DeveloperError; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponent'); -var writeBufferComponentType = require('./writeBufferComponent'); +var readBufferComponent = require('./readBufferComponent'); +var writeBufferComponent = require('./writeBufferComponent'); module.exports = combinePrimitives; @@ -190,7 +190,7 @@ function mergeAccessors(gltf, meshId, attributeType, primitiveGroup, referencePr var accessorSourceOffset = 0; for (var j = 0; j < accessorCount; j++) { for (var k = 0; k < numberOfComponents; k++) { - var value = readBufferComponentType(bufferSource, accessor.componentType, byteOffset + k * componentByteLength); + var value = readBufferComponent(bufferSource, accessor.componentType, byteOffset + k * componentByteLength); //If we are creating an index accessor, offset the indices based on the current primitive. if (attributeKey === 'INDEX') { value += indexOffset; @@ -198,7 +198,7 @@ function mergeAccessors(gltf, meshId, attributeType, primitiveGroup, referencePr maxIndex = value; } } - writeBufferComponentType(accessorSource, accessor.componentType, value, accessorSourceOffset + k * componentByteLength); + writeBufferComponent(accessorSource, accessor.componentType, value, accessorSourceOffset + k * componentByteLength); min[k] = Math.min(min[k], value); max[k] = Math.max(max[k], value); } diff --git a/lib/compressIntegerAccessors.js b/lib/compressIntegerAccessors.js index 155d0529..fb77fca3 100644 --- a/lib/compressIntegerAccessors.js +++ b/lib/compressIntegerAccessors.js @@ -55,6 +55,7 @@ var unsignedComponentTypes = [ * @see loadGltfUris */ function compressIntegerAccessors(gltf, options) { + options = defaultValue(options, {}); var semantics = defaultValue(options.semantics, []); var semanticsLength = semantics.length; var promises = []; diff --git a/lib/compressTextureCoordinates.js b/lib/compressTextureCoordinates.js index 848cff5a..a55bb550 100644 --- a/lib/compressTextureCoordinates.js +++ b/lib/compressTextureCoordinates.js @@ -14,9 +14,9 @@ var findAccessorMinMax = require('./findAccessorMinMax'); var getAccessorByteStride = require('./getAccessorByteStride'); var getAccessorsForSemantic = require('./getAccessorsForSemantic'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponent'); +var readBufferComponent = require('./readBufferComponent'); var uninterleaveAndPackBuffers = require('./uninterleaveAndPackBuffers'); -var writeBufferComponentType = require('./writeBufferComponent'); +var writeBufferComponent = require('./writeBufferComponent'); module.exports = compressTextureCoordinates; @@ -61,12 +61,12 @@ function compressTextureCoordinates(gltf) { for (var j = 0; j < numElements; j++) { var elementArray = []; for (var k = 0; k < numComponents; k++) { - var element = readBufferComponentType(source, componentType, byteOffset + componentByteLength * k); + var element = readBufferComponent(source, componentType, byteOffset + componentByteLength * k); elementArray.push(element); } var texCoord = Cartesian2.fromArray(elementArray); var compressed = AttributeCompression.compressTextureCoordinates(texCoord); - writeBufferComponentType(source, newComponentType, compressed, byteOffset); + writeBufferComponent(source, newComponentType, compressed, byteOffset); byteOffset += byteStride; } accessor.byteStride = byteStride; diff --git a/lib/createAccessorUsageTables.js b/lib/createAccessorUsageTables.js index 157775f4..5b10164c 100644 --- a/lib/createAccessorUsageTables.js +++ b/lib/createAccessorUsageTables.js @@ -2,7 +2,7 @@ var Cesium = require('cesium'); var defined = Cesium.defined; var getAccessorByteStride = require('./getAccessorByteStride'); -var readBufferComponentType = require('./readBufferComponent'); +var readBufferComponent = require('./readBufferComponent'); module.exports = createAccessorUsageTables; @@ -57,7 +57,7 @@ function markUsageForIndexAccessor(gltf, accessor, usage) { var byteOffset = accessor.byteOffset + bufferView.byteOffset; var byteStride = getAccessorByteStride(accessor); for (var i = 0; i < accessor.count; i++) { - var index = readBufferComponentType(source, accessor.componentType, byteOffset + i * byteStride); + var index = readBufferComponent(source, accessor.componentType, byteOffset + i * byteStride); if (index > usage.length) { usage = growUsageTable(usage, index); } diff --git a/lib/findAccessorMinMax.js b/lib/findAccessorMinMax.js index 0ef7675d..ba245410 100644 --- a/lib/findAccessorMinMax.js +++ b/lib/findAccessorMinMax.js @@ -6,7 +6,7 @@ var defined = Cesium.defined; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponent'); +var readBufferComponent = require('./readBufferComponent'); module.exports = findAccessorMinMax; @@ -43,7 +43,7 @@ function findAccessorMinMax(gltf, accessor) { for (var i = 0; i < count; i++) { for (var j = 0; j < numberOfComponents; j++) { - var value = readBufferComponentType(source, componentType, byteOffset + j * componentByteLength); + var value = readBufferComponent(source, componentType, byteOffset + j * componentByteLength); min[j] = Math.min(min[j], value); max[j] = Math.max(max[j], value); } diff --git a/lib/getAccessorsForSemantic.js b/lib/getAccessorsForSemantic.js index b50fbe24..9a33427e 100644 --- a/lib/getAccessorsForSemantic.js +++ b/lib/getAccessorsForSemantic.js @@ -12,6 +12,7 @@ module.exports = getAccessorsForSemantic; * @param {Function} callback This gets called when a match is found with the arguments (gltf, primitive, accessorId, matchedSemantic) * * @returns {Promise} A promise that resolves when all primitives have been searched. + * @private */ function getAccessorsForSemantic(gltf, semantic, callback) { return new Promise(function(resolve) { diff --git a/lib/getBinaryGltf.js b/lib/getBinaryGltf.js index bee4fc25..54cabb14 100644 --- a/lib/getBinaryGltf.js +++ b/lib/getBinaryGltf.js @@ -3,8 +3,8 @@ var Cesium = require('cesium'); var mime = require('mime'); var sizeOf = require('image-size'); -var defined = Cesium.defined; var defaultValue = Cesium.defaultValue; +var defined = Cesium.defined; var mergeBuffers = require('./mergeBuffers'); var removePipelineExtras = require('./removePipelineExtras'); diff --git a/lib/gltfPrimitiveToCesiumGeometry.js b/lib/gltfPrimitiveToCesiumGeometry.js index cdca66aa..d6bbd6e2 100644 --- a/lib/gltfPrimitiveToCesiumGeometry.js +++ b/lib/gltfPrimitiveToCesiumGeometry.js @@ -64,6 +64,9 @@ function mapPrimitiveAttributeToGeometry(gltf, primitive, semantic, geometryAttr }; } +/** + * @private + */ function gltfPrimitiveToCesiumGeometry(gltf, primitive) { var geometryAttributes = {}; var attributes = primitive.attributes; diff --git a/lib/loadGltfUris.js b/lib/loadGltfUris.js index 060911ca..e0ef60a6 100644 --- a/lib/loadGltfUris.js +++ b/lib/loadGltfUris.js @@ -29,6 +29,7 @@ module.exports = loadGltfUris; * @see addPipelineExtras */ function loadGltfUris(gltf, options) { + options = defaultValue(options, {}); var basePath = options.basePath; var loadURIs = [ loadURI(gltf, basePath, 'buffers'), diff --git a/lib/mergeDuplicateVertices.js b/lib/mergeDuplicateVertices.js index 45499664..d86cc65c 100644 --- a/lib/mergeDuplicateVertices.js +++ b/lib/mergeDuplicateVertices.js @@ -5,8 +5,8 @@ var defined = Cesium.defined; var byteLengthForComponentType = require('./byteLengthForComponentType'); var getAccessorByteStride = require('./getAccessorByteStride'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponent'); -var writeBufferComponentType = require('./writeBufferComponent'); +var readBufferComponent = require('./readBufferComponent'); +var writeBufferComponent = require('./writeBufferComponent'); var removeUnusedVertices = require('./removeUnusedVertices'); module.exports = mergeDuplicateVertices; @@ -56,10 +56,10 @@ function mergeDuplicateVerticesFromMapping(gltf, indexAccessors) { var numIndices = accessor.count; var duplicateMapping = indexAccessors[indexAccessorId]; for (var i = 0; i < numIndices; i++) { - var index = readBufferComponentType(source, accessor.componentType, byteOffset + byteStride * i); + var index = readBufferComponent(source, accessor.componentType, byteOffset + byteStride * i); var mappedIndex = duplicateMapping[index]; if (defined(mappedIndex) && mappedIndex !== index) { - writeBufferComponentType(source, accessor.componentType, mappedIndex, byteOffset + byteStride * i); + writeBufferComponent(source, accessor.componentType, mappedIndex, byteOffset + byteStride * i); } } } @@ -115,7 +115,7 @@ function findDuplicateVerticesInMesh(gltf, mesh, indexAccessors) { var indexByteOffset = indexAccessor.byteOffset + indexBufferView.byteOffset; var valueTree = {}; for (var i = 0; i < indexAccessor.count; i++) { - var index = readBufferComponentType(indexSource, indexComponentType, indexByteOffset + indexByteStride * i); + var index = readBufferComponent(indexSource, indexComponentType, indexByteOffset + indexByteStride * i); var mapping = duplicateMapping[index]; var subTree = valueTree; var numAttributes = attributeArray.length; diff --git a/lib/modelMaterialsCommon.js b/lib/modelMaterialsCommon.js index 80f6c253..569fd687 100644 --- a/lib/modelMaterialsCommon.js +++ b/lib/modelMaterialsCommon.js @@ -731,6 +731,8 @@ function lightDefaults(gltf) { * @private */ function modelMaterialsCommon(gltf, options) { + options = defaultValue(options, {}); + if (!defined(gltf)) { return undefined; } diff --git a/lib/octEncodeNormals.js b/lib/octEncodeNormals.js index 80f7efb9..172ef09b 100644 --- a/lib/octEncodeNormals.js +++ b/lib/octEncodeNormals.js @@ -14,8 +14,8 @@ var findAccessorMinMax = require('./findAccessorMinMax'); var getAccessorByteStride = require('./getAccessorByteStride'); var getAccessorsForSemantic = require('./getAccessorsForSemantic'); var numberOfComponentsForType = require('./numberOfComponentsForType'); -var readBufferComponentType = require('./readBufferComponent'); -var writeBufferComponentType = require('./writeBufferComponent'); +var readBufferComponent = require('./readBufferComponent'); +var writeBufferComponent = require('./writeBufferComponent'); var uninterleaveAndPackBuffers = require('./uninterleaveAndPackBuffers'); module.exports = octEncodeNormals; @@ -62,15 +62,15 @@ function octEncodeNormals(gltf) { for (var j = 0; j < numElements; j++) { var elementArray = []; for (var k = 0; k < numComponents; k++) { - var element = readBufferComponentType(source, componentType, byteOffset + componentByteLength * k); + var element = readBufferComponent(source, componentType, byteOffset + componentByteLength * k); elementArray.push(element); } var normalVector = Cartesian3.fromArray(elementArray); Cartesian3.normalize(normalVector, normalVector); var octEncodedVector = new Cartesian2(); AttributeCompression.octEncode(normalVector, octEncodedVector); - writeBufferComponentType(source, newComponentType, octEncodedVector.x, byteOffset); - writeBufferComponentType(source, newComponentType, octEncodedVector.y, byteOffset + newComponentByteLength); + writeBufferComponent(source, newComponentType, octEncodedVector.x, byteOffset); + writeBufferComponent(source, newComponentType, octEncodedVector.y, byteOffset + newComponentByteLength); byteOffset += byteStride; } accessor.byteStride = byteStride; diff --git a/lib/quantizeAttributes.js b/lib/quantizeAttributes.js index c7ae0c10..67b3427c 100644 --- a/lib/quantizeAttributes.js +++ b/lib/quantizeAttributes.js @@ -53,6 +53,8 @@ module.exports = quantizeAttributes; * }); */ function quantizeAttributes(gltf, options) { + options = defaultValue(options, {}); + var accessors = gltf.accessors; var value; var i; @@ -63,27 +65,26 @@ function quantizeAttributes(gltf, options) { // Retrieve the accessors that should be quantized var validSemantics; var excludeSemantics; - var findMinMax = false; - if (defined(options)) { - if (defined(options.precision)) { - precision = Math.pow(10, options.precision); - } - var semantics = options.semantics; - if (defined(semantics)) { - validSemantics = {}; - for (i = 0; i < semantics.length; i++) { - validSemantics[semantics[i]] = true; - } + var findMinMax = defaultValue(options.findMinMax, false); + + if (defined(options.precision)) { + precision = Math.pow(10, options.precision); + } + var semantics = options.semantics; + if (defined(semantics)) { + validSemantics = {}; + for (i = 0; i < semantics.length; i++) { + validSemantics[semantics[i]] = true; } - var exclude = options.exclude; - if (defined(exclude)) { - excludeSemantics = {}; - for (i = 0; i < exclude.length; i++) { - excludeSemantics[exclude[i]] = true; - } + } + var exclude = options.exclude; + if (defined(exclude)) { + excludeSemantics = {}; + for (i = 0; i < exclude.length; i++) { + excludeSemantics[exclude[i]] = true; } - findMinMax = defaultValue(options.findMinMax, false); } + // Quantize all valid attributes accessorIds = getAllQuantizableAttributes(gltf, validSemantics, excludeSemantics); diff --git a/lib/readBufferComponent.js b/lib/readBufferComponent.js index f78415dc..b80b939d 100644 --- a/lib/readBufferComponent.js +++ b/lib/readBufferComponent.js @@ -3,7 +3,7 @@ var Cesium = require('cesium'); var WebGLConstants = Cesium.WebGLConstants; -module.exports = readBufferComponentType; +module.exports = readBufferComponent; /** * Read from a buffer at an offset for a particular component type. @@ -13,7 +13,7 @@ module.exports = readBufferComponentType; * @param {Number} byteOffset Read starting from this offset. * @returns {Number} The resulting number value. */ -function readBufferComponentType(buffer, componentType, byteOffset) { +function readBufferComponent(buffer, componentType, byteOffset) { switch (componentType) { case WebGLConstants.BYTE: return buffer.readInt8(byteOffset); diff --git a/lib/readGltf.js b/lib/readGltf.js index 71ddbeb2..26f5be68 100644 --- a/lib/readGltf.js +++ b/lib/readGltf.js @@ -4,6 +4,7 @@ var fs = require('fs'); var path = require('path'); var Promise = require('bluebird'); +var defaultValue = Cesium.defaultValue; var defined = Cesium.defined; var DeveloperError = Cesium.DeveloperError; @@ -18,11 +19,13 @@ module.exports = readGltf; /** * Reads a glTF asset from the disk. * @param {String} gltfPath The file path for the glTF asset. - * @param {Object} options Options defining custom behavior. + * @param {Object} [options] Object with the following properties. * @param {String} [options.basePath] The base path to use for resolving external references. Defaults to the directory containing the glTF. * @returns {Object} A javascript object containing a glTF hierarchy. */ function readGltf(gltfPath, options) { + options = defaultValue(options, {}); + if (!defined(gltfPath)) { throw new DeveloperError('Input path is undefined.'); } diff --git a/lib/writeBufferComponent.js b/lib/writeBufferComponent.js index f352bd36..096b8821 100644 --- a/lib/writeBufferComponent.js +++ b/lib/writeBufferComponent.js @@ -2,7 +2,7 @@ var Cesium = require('cesium'); var WebGLConstants = Cesium.WebGLConstants; -module.exports = writeBufferComponentType; +module.exports = writeBufferComponent; /** * Writes a value to a buffer as a particular component type. @@ -12,7 +12,7 @@ module.exports = writeBufferComponentType; * @param {Number} value The value to write. * @param {Number} byteOffset The offset into the buffer to be written. */ -function writeBufferComponentType(buffer, componentType, value, byteOffset) { +function writeBufferComponent(buffer, componentType, value, byteOffset) { switch (componentType) { case WebGLConstants.BYTE: return buffer.writeInt8(value, byteOffset); diff --git a/specs/lib/PipelineSpec.js b/specs/lib/PipelineSpec.js index 60c7e4fe..f400f1b7 100644 --- a/specs/lib/PipelineSpec.js +++ b/specs/lib/PipelineSpec.js @@ -23,12 +23,11 @@ var outputGlbPath = './output/CesiumTexturedBoxTest.glb'; describe('Pipeline', function() { it('optimizes a gltf JSON with embedded resources', function(done) { - var options = {}; var gltfCopy; - expect(readGltf(gltfEmbeddedPath, options) + expect(readGltf(gltfEmbeddedPath) .then(function(gltf) { gltfCopy = clone(gltf); - return processJSON(gltf, options); + return processJSON(gltf); }) .then(function(gltf) { expect(gltf).toBeDefined(); @@ -37,7 +36,9 @@ describe('Pipeline', function() { }); it('optimizes a gltf JSON with external resources', function(done) { - var options = { basePath : path.dirname(gltfPath) }; + var options = { + basePath : path.dirname(gltfPath) + }; var gltfCopy; expect(fsExtraReadFile(gltfPath, options) .then(function(data) { @@ -54,11 +55,10 @@ describe('Pipeline', function() { it('optimizes a glTF file', function(done) { var gltfCopy; - var options = {}; - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { gltfCopy = clone(gltf); - return processFile(gltfPath, options); + return processFile(gltfPath); }) .then(function(gltf) { expect(gltf).toBeDefined(); @@ -68,11 +68,10 @@ describe('Pipeline', function() { it('optimizes a glb file', function(done) { var gltfCopy; - var options = {}; - expect(readGltf(glbPath, options) + expect(readGltf(glbPath) .then(function(gltf) { gltfCopy = clone(gltf); - return processFile(glbPath, options); + return processFile(glbPath); }) .then(function(gltf) { expect(gltf).toBeDefined(); @@ -112,12 +111,11 @@ describe('Pipeline', function() { it('will write a file from JSON', function(done) { var spy = spyOn(fsExtra, 'outputJsonAsync').and.callFake(function() {}); - var readOptions = {}; var processOptions = { createDirectory : false, basePath : path.dirname(gltfPath) }; - expect(readGltf(gltfPath, readOptions) + expect(readGltf(gltfPath) .then(function(gltf) { return processJSONToDisk(gltf, outputGltfPath, processOptions); }) @@ -131,11 +129,10 @@ describe('Pipeline', function() { it('will write sources from JSON', function(done) { var initialUri; - var options = {}; - expect(readGltf(gltfEmbeddedPath, options) + expect(readGltf(gltfEmbeddedPath) .then(function(gltf) { initialUri = gltf.buffers.CesiumTexturedBoxTest.uri; - return processJSON(gltf, options); + return processJSON(gltf); }) .then(function(gltf) { var firstBufferId = Object.keys(gltf.buffers)[0]; @@ -147,11 +144,10 @@ describe('Pipeline', function() { it('will write sources from file', function(done) { var initialUri; - var options = {}; - expect(readGltf(gltfEmbeddedPath, options) + expect(readGltf(gltfEmbeddedPath) .then(function(gltf) { initialUri = gltf.buffers.CesiumTexturedBoxTest.uri; - return processFile(gltfEmbeddedPath, options); + return processFile(gltfEmbeddedPath); }) .then(function(gltfFinal) { var firstBufferId = Object.keys(gltfFinal.buffers)[0]; diff --git a/specs/lib/addDefaultsSpec.js b/specs/lib/addDefaultsSpec.js index af832203..bb9dd94a 100644 --- a/specs/lib/addDefaultsSpec.js +++ b/specs/lib/addDefaultsSpec.js @@ -31,7 +31,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); var accessor = gltf.accessors.accessorId; expect(accessor.byteStride).toEqual(0); expect(accessor.min).toBeDefined(); @@ -65,7 +65,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.animations.animationId.samplers.samplerId.interpolation).toEqual('LINEAR'); }); @@ -77,7 +77,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.animations.animationId.channels).toEqual([]); expect(gltf.animations.animationId.parameters).toEqual({}); expect(gltf.animations.animationId.samplers).toEqual({}); @@ -86,7 +86,7 @@ describe('addDefaults', function() { it('Adds asset properties', function() { var gltf = {}; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.asset).toBeDefined(); expect(gltf.asset.premultipliedAlpha).toEqual(false); expect(gltf.asset.profile).toBeDefined(); @@ -99,7 +99,7 @@ describe('addDefaults', function() { "version" : 0.8 }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.asset.version).toEqual('0.8'); }); @@ -113,7 +113,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.buffers.bufferId.type).toEqual('arraybuffer'); }); @@ -200,8 +200,7 @@ describe('addDefaults', function() { }; var options = { - specularTechnique: 'PHONG', - diffuseTechnique: 'CONSTANT' + technique: 'PHONG' }; var gltfClone; @@ -339,7 +338,7 @@ describe('addDefaults', function() { }; addPipelineExtras(gltf); - loadGltfUris(gltf, {}) + loadGltfUris(gltf) .then(function() { addDefaults(gltf); var technique = gltf.techniques[Object.keys(gltf.techniques)[0]]; @@ -375,7 +374,7 @@ describe('addDefaults', function() { var gltf = JSON.parse(data); var originalState = gltf.techniques[Object.keys(gltf.techniques)[0]].states; expect(originalState).not.toEqual(alphaBlendState); - return readGltf(gltfTransparentPath, {}); + return readGltf(gltfTransparentPath); }) .then(function (gltf) { addDefaults(gltf); @@ -391,8 +390,7 @@ describe('addDefaults', function() { var originalState = gltf.techniques[Object.keys(gltf.techniques)[0]].states; expect(originalState).not.toEqual(alphaBlendState); - var options = {}; - return readGltf(gltfTransparentPath, options); + return readGltf(gltfTransparentPath); }) .then(function (gltf) { var material = gltf.materials[Object.keys(gltf.materials)[0]]; @@ -561,7 +559,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.meshes.meshId.primitives).toEqual([]); gltf = { @@ -577,7 +575,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.meshes.meshId.primitives[0].attributes).toBeDefined(); expect(gltf.meshes.meshId.primitives[0].mode).toEqual(WebGLConstants.TRIANGLES); }); @@ -597,7 +595,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.meshes.meshId.primitives[0].mode).toEqual(WebGLConstants.TRIANGLE_STRIP); }); @@ -609,7 +607,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.nodes.nodeId.children).toEqual([]); expect(gltf.nodes.nodeId.matrix).toEqual([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); @@ -621,7 +619,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.nodes.nodeId.rotation).toEqual([0.0, 0.0, 0.0, 1.0]); expect(gltf.nodes.nodeId.scale).toEqual([1.0, 1.0, 1.0]); @@ -633,7 +631,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.nodes.nodeId.translation).toEqual([0.0, 0.0, 0.0]); expect(gltf.nodes.nodeId.rotation).toEqual([0.0, 0.0, 0.0, 1.0]); }); @@ -651,7 +649,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.nodes.nodeId.skeletons).toBeDefined(); expect(gltf.nodes.nodeId.skin).toBeDefined(); expect(gltf.nodes.nodeId.meshes).toBeDefined(); @@ -668,7 +666,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.nodes.nodeId.rotation).toEqual([0.0, 0.0, 0.0, 1.0]); }); @@ -682,7 +680,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.programs.programId.attributes).toEqual([]); }); @@ -694,7 +692,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.samplers.samplerId.magFilter).toEqual(WebGLConstants.LINEAR); expect(gltf.samplers.samplerId.minFilter).toEqual(WebGLConstants.NEAREST_MIPMAP_LINEAR); expect(gltf.samplers.samplerId.wrapS).toEqual(WebGLConstants.REPEAT); @@ -709,7 +707,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.scenes.defaultScene.nodes).toEqual([]); }); @@ -726,7 +724,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.skins.skinId.bindShapeMatrix).toEqual([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); }); @@ -743,7 +741,7 @@ describe('addDefaults', function() { } }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.textures.textureId.format).toEqual(WebGLConstants.RGBA); expect(gltf.textures.textureId.internalFormat).toEqual(6408); expect(gltf.textures.textureId.target).toEqual(WebGLConstants.TEXTURE_2D); @@ -758,7 +756,7 @@ describe('addDefaults', function() { ] }; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.allExtensions).not.toBeDefined(); expect(gltf.extensionsUsed).toBeDefined(); }); @@ -766,7 +764,7 @@ describe('addDefaults', function() { it('Adds empty top-level properties', function() { var gltf = {}; - addDefaults(gltf, undefined); + addDefaults(gltf); expect(gltf.extensionsUsed).toBeDefined(); expect(gltf.accessors).toBeDefined(); expect(gltf.animations).toBeDefined(); diff --git a/specs/lib/cesiumGeometryToGltfPrimitiveSpec.js b/specs/lib/cesiumGeometryToGltfPrimitiveSpec.js index f250f2dd..8a4bac24 100644 --- a/specs/lib/cesiumGeometryToGltfPrimitiveSpec.js +++ b/specs/lib/cesiumGeometryToGltfPrimitiveSpec.js @@ -49,8 +49,7 @@ var geometry = new Geometry({ describe('cesiumGeometryToGltfPrimitive', function() { it('writes geometry data to a glTF', function(done) { - var options = {}; - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { addDefaults(gltf); var primitive = gltf.meshes[Object.keys(gltf.meshes)[0]].primitives[0]; diff --git a/specs/lib/combinePrimitivesSpec.js b/specs/lib/combinePrimitivesSpec.js index dc49ead0..1859bbe1 100755 --- a/specs/lib/combinePrimitivesSpec.js +++ b/specs/lib/combinePrimitivesSpec.js @@ -9,10 +9,8 @@ var doubleBoxNotCombinedPath = './specs/data/combineObjects/doubleBoxNotCombined var fiveBoxPath = './specs/data/combineObjects/fiveBox.gltf'; describe('combinePrimitives', function() { - var options = {}; - it('does not affect single primitives', function(done){ - expect(readGltf(boxPath, options) + expect(readGltf(boxPath) .then(function(gltf) { var box = gltf; var stringBox = JSON.stringify(box); @@ -22,7 +20,7 @@ describe('combinePrimitives', function() { }); it('does not combine two primitives', function(done) { - expect(readGltf(doubleBoxNotCombinedPath, options) + expect(readGltf(doubleBoxNotCombinedPath) .then(function(gltf) { var doubleBoxNotCombined = gltf; var stringDoubleBoxNotCombined = JSON.stringify(doubleBoxNotCombined); @@ -32,7 +30,7 @@ describe('combinePrimitives', function() { }); it('combines two primitives', function(done) { - expect(readGltf(doubleBoxToCombinePath, options) + expect(readGltf(doubleBoxToCombinePath) .then(function(gltf) { var doubleBoxToCombine = gltf; @@ -76,7 +74,7 @@ describe('combinePrimitives', function() { }); it('combines some primitives', function(done){ - expect(readGltf(fiveBoxPath, options) + expect(readGltf(fiveBoxPath) .then(function(gltf){ var fiveBox = gltf; combinePrimitives(fiveBox); @@ -101,7 +99,7 @@ describe('combinePrimitives', function() { }); it('throws a type error', function(done) { - expect(readGltf(doubleBoxToCombinePath, options) + expect(readGltf(doubleBoxToCombinePath) .then(function (gltf) { var typeError = gltf; typeError.accessors.accessor_29.type = 'VEC3'; @@ -112,7 +110,7 @@ describe('combinePrimitives', function() { }); it ('throws a componentType error', function(done) { - expect(readGltf(doubleBoxToCombinePath, options) + expect(readGltf(doubleBoxToCombinePath) .then(function(gltf){ var componentTypeError = gltf; componentTypeError.accessors.accessor_29.componentType = 5126; diff --git a/specs/lib/generateNormalsSpec.js b/specs/lib/generateNormalsSpec.js index 6464dce5..06d5737f 100644 --- a/specs/lib/generateNormalsSpec.js +++ b/specs/lib/generateNormalsSpec.js @@ -9,8 +9,7 @@ var gltfNormalsPath = './specs/data/generateNormals/box_normals.gltf'; describe('generateNormals', function(){ it('generates normals if they do not exist', function(done) { - var options = {}; - expect(readGltf(gltfNoNormalsPath, options) + expect(readGltf(gltfNoNormalsPath) .then(function(gltf){ var byteLengthBefore = 168; generateNormals(gltf); @@ -24,8 +23,7 @@ describe('generateNormals', function(){ }); it('does not generate normals if they already exist', function(done) { - var options = {}; - expect(readGltf(gltfNormalsPath, options) + expect(readGltf(gltfNormalsPath) .then(function(gltf) { var gltfCopy = clone(gltf); generateNormals(gltf); diff --git a/specs/lib/getBinaryGltfSpec.js b/specs/lib/getBinaryGltfSpec.js index af68109b..265ac45a 100644 --- a/specs/lib/getBinaryGltfSpec.js +++ b/specs/lib/getBinaryGltfSpec.js @@ -27,8 +27,7 @@ describe('getBinaryGltf', function() { }; beforeAll(function(done) { - var options = {}; - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { testData.gltf = gltf; return fsReadFile(scenePath); diff --git a/specs/lib/gltfPrimitiveToCesiumGeometrySpec.js b/specs/lib/gltfPrimitiveToCesiumGeometrySpec.js index b3aa1c53..57a6788f 100644 --- a/specs/lib/gltfPrimitiveToCesiumGeometrySpec.js +++ b/specs/lib/gltfPrimitiveToCesiumGeometrySpec.js @@ -10,8 +10,7 @@ var primitiveType = 4; describe('gltfPrimitiveToCesiumGeometry', function() { it('returns a geometry', function(done) { - var options = {}; - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { addDefaults(gltf); var primitive = gltf.meshes[Object.keys(gltf.meshes)[0]].primitives[0]; diff --git a/specs/lib/isDataUriSpec.js b/specs/lib/isDataUriSpec.js index 98e95287..78404232 100755 --- a/specs/lib/isDataUriSpec.js +++ b/specs/lib/isDataUriSpec.js @@ -14,6 +14,6 @@ describe('isDataUri', function() { }); it('is undefined', function() { - expect(isDataUri(undefined)).toBe(false); + expect(isDataUri()).toBe(false); }); }); diff --git a/specs/lib/optimizeCacheSpec.js b/specs/lib/optimizeCacheSpec.js index 540c11e1..eb42febd 100644 --- a/specs/lib/optimizeCacheSpec.js +++ b/specs/lib/optimizeCacheSpec.js @@ -25,8 +25,7 @@ var optimizedVertices = [ 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0 describe('optimizeCache', function() { it('reorders indices', function(done) { - var options = {}; - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { addDefaults(gltf); var indexAccessorId = gltf.meshes[Object.keys(gltf.meshes)[0]].primitives[0].indices; @@ -43,8 +42,7 @@ describe('optimizeCache', function() { }); it('reorders independent attribute accessors', function(done) { - var options = {}; - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { addDefaults(gltf); var positionAccessor = gltf.accessors.accessor_23; diff --git a/specs/lib/readAccessorSpec.js b/specs/lib/readAccessorSpec.js index 9f66a270..df9b5c06 100644 --- a/specs/lib/readAccessorSpec.js +++ b/specs/lib/readAccessorSpec.js @@ -16,10 +16,9 @@ var gltfPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.gltf'; describe('readAccessor', function() { var boxGltf; - var options = {}; beforeAll(function(done) { - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { boxGltf = gltf; }), done).toResolve(); diff --git a/specs/lib/readGltfSpec.js b/specs/lib/readGltfSpec.js index 986fb13f..453bba7a 100644 --- a/specs/lib/readGltfSpec.js +++ b/specs/lib/readGltfSpec.js @@ -6,17 +6,15 @@ var glbPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.glb'; var invalidPath = './specs/data/boxTexturedUnoptimized/README.md'; describe('readGltf', function() { - var options = {}; - it('parses a .gltf input path, checks that a gltf JSON is defined', function(done) { - expect(readGltf(gltfPath, options) + expect(readGltf(gltfPath) .then(function(gltf) { expect(gltf).toBeDefined(); }), done).toResolve(); }); it('parses a .glb input path, checks that a gltf JSON is defined', function(done) { - expect(readGltf(glbPath, options) + expect(readGltf(glbPath) .then(function(gltf) { expect(gltf).toBeDefined(); }), done).toResolve(); @@ -24,13 +22,13 @@ describe('readGltf', function() { it('throws error when an input path is undefined', function() { expect(function() { - readGltf(undefined, options); + readGltf(); }).toThrowDeveloperError(); }); it('throws error when file extension of input file is invalid', function() { expect(function() { - readGltf(invalidPath, options); + readGltf(invalidPath); }).toThrowDeveloperError(); }); }); diff --git a/specs/lib/writeBinaryGltfSpec.js b/specs/lib/writeBinaryGltfSpec.js index 7282495c..79bd671e 100644 --- a/specs/lib/writeBinaryGltfSpec.js +++ b/specs/lib/writeBinaryGltfSpec.js @@ -15,7 +15,6 @@ var invalidPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.exe describe('writeBinaryGltf', function() { it('will write a file to the correct directory', function(done) { var spy = spyOn(fsExtra, 'outputFileAsync').and.callFake(function() {}); - var readOptions = {}; var writeOptions = { outputPath : outputGltfPath, embed : true, @@ -23,7 +22,7 @@ describe('writeBinaryGltf', function() { createDirectory : false }; - expect(readGltf(gltfPath, readOptions) + expect(readGltf(gltfPath) .then(function(gltf) { return writeBinaryGltf(gltf, writeOptions); }) @@ -36,7 +35,6 @@ describe('writeBinaryGltf', function() { }); it('throws an invalid output path error', function(done) { - var readOptions = {}; var writeOptions = { outputPath : undefined, embed : true, @@ -44,7 +42,7 @@ describe('writeBinaryGltf', function() { createDirectory : true }; - expect(readGltf(gltfPath, readOptions) + expect(readGltf(gltfPath) .then(function(gltf) { expect(function() { writeBinaryGltf(gltf, writeOptions); @@ -53,7 +51,6 @@ describe('writeBinaryGltf', function() { }); it('throws an invalid output extension error', function(done) { - var readOptions = {}; var writeOptions = { outputPath : invalidPath, embed : true, @@ -61,7 +58,7 @@ describe('writeBinaryGltf', function() { createDirectory : true }; - expect(readGltf(gltfPath, readOptions) + expect(readGltf(gltfPath) .then(function(gltf) { expect(function() { writeBinaryGltf(gltf, writeOptions); diff --git a/specs/lib/writeGltfSpec.js b/specs/lib/writeGltfSpec.js index 5e3e38a4..61c9cac5 100644 --- a/specs/lib/writeGltfSpec.js +++ b/specs/lib/writeGltfSpec.js @@ -12,7 +12,6 @@ var invalidPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.exe describe('writeGltf', function() { it('will write a file to the correct directory', function(done) { var spy = spyOn(fsExtra, 'outputJsonAsync').and.callFake(function() {}); - var readOptions = {}; var writeOptions = { outputPath : outputGltfPath, embed : true, @@ -20,7 +19,7 @@ describe('writeGltf', function() { createDirectory : false }; - expect(readGltf(gltfPath, readOptions) + expect(readGltf(gltfPath) .then(function(gltf) { return writeGltf(gltf, writeOptions); }) @@ -33,7 +32,6 @@ describe('writeGltf', function() { }); it('throws an invalid output path error', function(done) { - var readOptions = {}; var writeOptions = { outputPath : undefined, embed : true, @@ -41,7 +39,7 @@ describe('writeGltf', function() { createDirectory : true }; - expect(readGltf(gltfPath, readOptions) + expect(readGltf(gltfPath) .then(function(gltf) { expect(function() { writeGltf(gltf, writeOptions); @@ -50,7 +48,6 @@ describe('writeGltf', function() { }); it('throws an invalid output extension error', function(done) { - var readOptions = {}; var writeOptions = { outputPath : invalidPath, embed : true, @@ -58,7 +55,7 @@ describe('writeGltf', function() { createDirectory : true }; - expect(readGltf(gltfPath, readOptions) + expect(readGltf(gltfPath) .then(function(gltf) { expect(function() { writeGltf(gltf, writeOptions); From a64d119eea3c12b776a8d5cfac58d76732cf9485 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 17 Aug 2016 15:35:40 -0400 Subject: [PATCH 19/21] Rename optimizeCache to optimizeForVertexCache --- index.js | 2 +- lib/Pipeline.js | 4 ++-- lib/{optimizeCache.js => optimizeForVertexCache.js} | 4 ++-- ...imizeCacheSpec.js => optimizeForVertexCacheSpec.js} | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) rename lib/{optimizeCache.js => optimizeForVertexCache.js} (98%) rename specs/lib/{optimizeCacheSpec.js => optimizeForVertexCacheSpec.js} (93%) diff --git a/index.js b/index.js index 26f1c6ab..fe8222d7 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ module.exports = { mergeDuplicateVertices : require('./lib/mergeDuplicateVertices'), numberOfComponentsForType : require('./lib/numberOfComponentsForType'), octEncodeNormals : require('./lib/octEncodeNormals'), - optimizeCache : require('./lib/optimizeCache'), + optimizeForVertexCache : require('./lib/optimizeForVertexCache'), packArray : require('./lib/packArray'), parseBinaryGltf : require('./lib/parseBinaryGltf'), Pipeline : require('./lib/Pipeline'), diff --git a/lib/Pipeline.js b/lib/Pipeline.js index 9f5c1061..ed776e5a 100644 --- a/lib/Pipeline.js +++ b/lib/Pipeline.js @@ -19,7 +19,7 @@ var loadGltfUris = require('./loadGltfUris'); var mergeDuplicateVertices = require('./mergeDuplicateVertices'); var mergeDuplicateAccessors = require('./mergeDuplicateAccessors'); var octEncodeNormals = require('./octEncodeNormals'); -var optimizeCache = require('./optimizeCache'); +var optimizeForVertexCache = require('./optimizeForVertexCache'); var readGltf = require('./readGltf'); var removeDuplicatePrimitives = require('./removeDuplicatePrimitives'); var quantizeAttributes = require('./quantizeAttributes'); @@ -93,7 +93,7 @@ Pipeline.processJSONWithExtras = function(gltfWithExtras, options) { // combinePrimitives(gltfWithExtras); // Merging duplicate vertices again to prevent repeat data in newly combined primitives // mergeDuplicateVertices(gltfWithExtras); - optimizeCache(gltfWithExtras); + optimizeForVertexCache(gltfWithExtras); // run AO after cacheOptimization since AO adds new attributes. var aoOptions = options.aoOptions; diff --git a/lib/optimizeCache.js b/lib/optimizeForVertexCache.js similarity index 98% rename from lib/optimizeCache.js rename to lib/optimizeForVertexCache.js index 8b386c82..87a29b00 100644 --- a/lib/optimizeCache.js +++ b/lib/optimizeForVertexCache.js @@ -7,7 +7,7 @@ var createAccessorUsageTables = require('./createAccessorUsageTables'); var GeometryPipeline = Cesium.GeometryPipeline; var defined = Cesium.defined; -module.exports = optimizeCache; +module.exports = optimizeForVertexCache; // Helper method to map accessor collections from the usageTable to an independent primitive (if there is one) function createIndicesToAttributeDictionary(gltf) { @@ -76,7 +76,7 @@ function getIndependentPrimitive(dictionary, indicesId, attributeAccessors) { * @see addPipelineExtras * @see loadGltfUris */ -function optimizeCache(gltf, cacheSize) { +function optimizeForVertexCache(gltf, cacheSize) { // perform post vertex cache optimization var primitive; var geometry; diff --git a/specs/lib/optimizeCacheSpec.js b/specs/lib/optimizeForVertexCacheSpec.js similarity index 93% rename from specs/lib/optimizeCacheSpec.js rename to specs/lib/optimizeForVertexCacheSpec.js index eb42febd..bd1dff06 100644 --- a/specs/lib/optimizeCacheSpec.js +++ b/specs/lib/optimizeForVertexCacheSpec.js @@ -3,7 +3,7 @@ var Cesium = require('cesium'); var GeometryPipeline = Cesium.GeometryPipeline; var addDefaults = require('../../lib/addDefaults'); -var optimizeCache = require('../../lib/optimizeCache'); +var optimizeForVertexCache = require('../../lib/optimizeForVertexCache'); var readAccessor = require('../../lib/readAccessor'); var readGltf = require('../../lib/readGltf'); var writeAccessor = require('../../lib/writeAccessor'); @@ -23,7 +23,7 @@ var optimizedVertices = [ 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5 ]; -describe('optimizeCache', function() { +describe('optimizeForVertexCache', function() { it('reorders indices', function(done) { expect(readGltf(gltfPath) .then(function(gltf) { @@ -33,7 +33,7 @@ describe('optimizeCache', function() { // Rewrite indices to be forcibly unoptimized writeAccessor(gltf, indexAccessor, unoptimizedIndices); - optimizeCache(gltf); + optimizeForVertexCache(gltf); var indices = []; readAccessor(gltf, gltf.accessors[indexAccessorId], indices); @@ -55,7 +55,7 @@ describe('optimizeCache', function() { var positions = []; readAccessor(gltf, positionAccessor, positions); - optimizeCache(gltf); + optimizeForVertexCache(gltf); expect(positions).toEqual(unpackedOptimizedVertices); }), done).toResolve(); @@ -77,7 +77,7 @@ describe('optimizeCache', function() { } }; spyOn(GeometryPipeline, 'reorderForPostVertexCache'); - optimizeCache(gltf); + optimizeForVertexCache(gltf); expect(GeometryPipeline.reorderForPostVertexCache).not.toHaveBeenCalled(); }); }); From 9f292b55e986b525a45f5868f26228b0d43284c5 Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Mon, 22 Aug 2016 09:56:49 -0400 Subject: [PATCH 20/21] Expose test function as private members of bakeAmbientOcclusion --- CHANGES.md | 2 +- lib/Pipeline.js | 3 +- ...ntOcclusion.js => bakeAmbientOcclusion.js} | 28 +++++------ ...ionSpec.js => bakeAmbientOcclusionSpec.js} | 48 +++++++++++-------- 4 files changed, 41 insertions(+), 40 deletions(-) rename lib/{AmbientOcclusion.js => bakeAmbientOcclusion.js} (98%) rename specs/lib/{AmbientOcclusionSpec.js => bakeAmbientOcclusionSpec.js} (93%) diff --git a/CHANGES.md b/CHANGES.md index 538fb31a..03f2c92a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Change Log * Documentation has been added for all exposed functions. * `OptimizationStats` is removed from `removeUnused` stages. * `gltfPipeline.js` is now named `Pipeline.js`. - * `bakeAmbientOcclusion.js` is now named `AmbientOcclusion.js`, `bakeAmbientOcclusion` is accessible via this object. + * `bakeAmbientOcclusion.js` now directly exports the `bakeAmbientOcclusion` function. * `bakeAmbientOcclusion` now takes a glTF asset as its first parameter to match the function signature of other stages. * All `removeUnused` stages have been consolidated to `RemoveUnusedProperties` to clean up the global scope. * `readBufferComponentType` and `writeBufferComponentType` have been renamed to `readBufferComponent` and `writeBufferComponent` respectively. diff --git a/lib/Pipeline.js b/lib/Pipeline.js index ed776e5a..975f4fd0 100644 --- a/lib/Pipeline.js +++ b/lib/Pipeline.js @@ -3,10 +3,10 @@ var Cesium = require('cesium'); var Promise = require('bluebird'); var path = require('path'); -var AmbientOcclusion = require('./AmbientOcclusion'); var RemoveUnusedProperties = require('./RemoveUnusedProperties'); var addDefaults = require('./addDefaults'); var addPipelineExtras = require('./addPipelineExtras'); +var bakeAmbientOcclusion = require('./bakeAmbientOcclusion'); var combineMeshes = require('./combineMeshes'); var combineNodes = require('./combineNodes'); var compressIntegerAccessors = require('./compressIntegerAccessors'); @@ -30,7 +30,6 @@ var writeSource = require('./writeSource'); var defaultValue = Cesium.defaultValue; var defined = Cesium.defined; -var bakeAmbientOcclusion = AmbientOcclusion.bakeAmbientOcclusion; var removeAllUnused = RemoveUnusedProperties.removeAllUnused; module.exports = Pipeline; diff --git a/lib/AmbientOcclusion.js b/lib/bakeAmbientOcclusion.js similarity index 98% rename from lib/AmbientOcclusion.js rename to lib/bakeAmbientOcclusion.js index 8577c27d..dc83d61f 100644 --- a/lib/AmbientOcclusion.js +++ b/lib/bakeAmbientOcclusion.js @@ -35,13 +35,7 @@ var matrix4Scratch = new Matrix4(); var trianglePixelMarchScratch = new TrianglePixelMarchOptions(); var computeAmbientOcclusionAtScratch = new ComputeAmbientOcclusionAtOptions(); -module.exports = AmbientOcclusion; - -/** - * Pipeline stage and utilities for generating ambient occlusion. - * @constructor - */ -function AmbientOcclusion() {} +module.exports = bakeAmbientOcclusion; /** * Bakes ambient occlusion (AO) to all models in a specific scene of the glTF asset. @@ -72,7 +66,7 @@ function AmbientOcclusion() {} * @see addPipelineExtras * @see loadGltfUris */ -AmbientOcclusion.bakeAmbientOcclusion = function(gltf, aoOptions) { +function bakeAmbientOcclusion(gltf, aoOptions) { var options = generateOptions(gltf, aoOptions); ////// Generate triangle soup ////// @@ -106,15 +100,15 @@ AmbientOcclusion.bakeAmbientOcclusion = function(gltf, aoOptions) { ambientShadowContribution : options.ambientShadowContribution }); } -}; - -AmbientOcclusion.generateOptions = generateOptions; -AmbientOcclusion.generateRaytracerScene = generateRaytracerScene; -AmbientOcclusion.computeAmbientOcclusionAt = computeAmbientOcclusionAt; -AmbientOcclusion.raytraceAtTriangleCenters = raytraceAtTriangleCenters; -AmbientOcclusion.raytraceOverTriangleSamples = raytraceOverTriangleSamples; -AmbientOcclusion.extractInstructionWithFunctionCall = extractInstructionWithFunctionCall; -AmbientOcclusion.injectGlslAfterInstructionContaining = injectGlslAfterInstructionContaining; +} + +bakeAmbientOcclusion._generateOptions = generateOptions; +bakeAmbientOcclusion._generateRaytracerScene = generateRaytracerScene; +bakeAmbientOcclusion._computeAmbientOcclusionAt = computeAmbientOcclusionAt; +bakeAmbientOcclusion._raytraceAtTriangleCenters = raytraceAtTriangleCenters; +bakeAmbientOcclusion._raytraceOverTriangleSamples = raytraceOverTriangleSamples; +bakeAmbientOcclusion._extractInstructionWithFunctionCall = extractInstructionWithFunctionCall; +bakeAmbientOcclusion._injectGlslAfterInstructionContaining = injectGlslAfterInstructionContaining; function generateOptions(gltf, aoOptions) { diff --git a/specs/lib/AmbientOcclusionSpec.js b/specs/lib/bakeAmbientOcclusionSpec.js similarity index 93% rename from specs/lib/AmbientOcclusionSpec.js rename to specs/lib/bakeAmbientOcclusionSpec.js index 78153b2e..e5c89dea 100644 --- a/specs/lib/AmbientOcclusionSpec.js +++ b/specs/lib/bakeAmbientOcclusionSpec.js @@ -6,11 +6,19 @@ var CesiumMath = Cesium.Math; var Cartesian3 = Cesium.Cartesian3; var Matrix4 = Cesium.Matrix4; -var AmbientOcclusion = require('../../lib/AmbientOcclusion'); +var bakeAmbientOcclusion = require('../../lib/bakeAmbientOcclusion'); var NodeHelpers = require('../../lib/NodeHelpers'); var readGltf = require('../../lib/readGltf'); var StaticUniformGrid = require('../../lib/StaticUniformGrid'); +var generateOptions = bakeAmbientOcclusion._generateOptions; +var generateRaytracerScene = bakeAmbientOcclusion._generateRaytracerScene; +var computeAmbientOcclusionAt = bakeAmbientOcclusion._computeAmbientOcclusionAt; +var raytraceAtTriangleCenters = bakeAmbientOcclusion._raytraceAtTriangleCenters; +var raytraceOverTriangleSamples = bakeAmbientOcclusion._raytraceOverTriangleSamples; +var extractInstructionWithFunctionCall = bakeAmbientOcclusion._extractInstructionWithFunctionCall; +var injectGlslAfterInstructionContaining = bakeAmbientOcclusion._injectGlslAfterInstructionContaining; + var boxOverGroundGltfPath = './specs/data/ambientOcclusion/cube_over_ground.gltf'; function cloneGltfWithJimps(gltf) { @@ -234,7 +242,7 @@ describe('AmbientOcclusion', function() { sceneID : testGltf.scene, rayDistance : 10.0 }; - var raytracerScene = AmbientOcclusion.generateRaytracerScene(testGltf, options); + var raytracerScene = generateRaytracerScene(testGltf, options); var triangleSoup = raytracerScene.triangleGrid.items; // because of the uniform scale, expect triangles to be bigger @@ -274,7 +282,7 @@ describe('AmbientOcclusion', function() { nearCull : CesiumMath.EPSILON4, sceneID : testGltf.scene }; - var raytracerScene = AmbientOcclusion.generateRaytracerScene(testGltf, options); + var raytracerScene = generateRaytracerScene(testGltf, options); var triangleSoup = raytracerScene.triangleGrid.items; // ground plane size is based on the near culling distance, scene size, and maximum ray depth. @@ -321,7 +329,7 @@ describe('AmbientOcclusion', function() { for (i = 0; i < 6; i++) { var texel = texelPoints[i]; - samples[i] = AmbientOcclusion.computeAmbientOcclusionAt({ + samples[i] = computeAmbientOcclusionAt({ position : texel.position, normal : texel.normal, numberRays : 16, @@ -360,7 +368,7 @@ describe('AmbientOcclusion', function() { for (var i = 0; i < 3; i++) { var texel = texelPoints[i]; - samples[i] += AmbientOcclusion.computeAmbientOcclusionAt({ + samples[i] += computeAmbientOcclusionAt({ position : texel.position, normal : texel.normal, numberRays : 16, @@ -383,7 +391,7 @@ describe('AmbientOcclusion', function() { resolution: 4, toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); + bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(2); expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -411,7 +419,7 @@ describe('AmbientOcclusion', function() { resolution: 4, toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); + bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(2); expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -439,7 +447,7 @@ describe('AmbientOcclusion', function() { resolution: 4, toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); + bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 images with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(2); @@ -467,7 +475,7 @@ describe('AmbientOcclusion', function() { resolution: 4, toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); + bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(3); // 1 unused texture, 2 with AO @@ -493,7 +501,7 @@ describe('AmbientOcclusion', function() { resolution: 4, toTexture: true }; - AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); + bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.images).length).toEqual(3); // 1 unused image and 2 images with AO expect(Object.keys(boxOverGroundGltfClone.textures).length).toEqual(3); // 1 unused texture, 2 with AO @@ -507,7 +515,7 @@ describe('AmbientOcclusion', function() { numberRays: 0, toVertex: true }; - AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); + bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.accessors).length).toEqual(10); var cubeMeshPrimitives = boxOverGroundGltfClone.meshes.Cube_mesh.primitives; @@ -525,7 +533,7 @@ describe('AmbientOcclusion', function() { numberRays: 0, toVertex: true }; - AmbientOcclusion.bakeAmbientOcclusion(boxOverGroundGltfClone, options); + bakeAmbientOcclusion(boxOverGroundGltfClone, options); expect(Object.keys(boxOverGroundGltfClone.materials).length).toEqual(4); expect(Object.keys(boxOverGroundGltfClone.techniques).length).toEqual(2); @@ -577,7 +585,7 @@ describe('AmbientOcclusion', function() { } }; - AmbientOcclusion.raytraceAtTriangleCenters(primitive, 'meshPrimitiveID', parameters, node); + raytraceAtTriangleCenters(primitive, 'meshPrimitiveID', parameters, node); var samples = aoBuffer.samples; var counts = aoBuffer.count; @@ -627,7 +635,7 @@ describe('AmbientOcclusion', function() { } }; - AmbientOcclusion.raytraceOverTriangleSamples(primitive, 'meshPrimitiveID', parameters, node); + raytraceOverTriangleSamples(primitive, 'meshPrimitiveID', parameters, node); var samples = aoBuffer.samples; var counts = aoBuffer.count; @@ -643,7 +651,7 @@ describe('AmbientOcclusion', function() { it('generates options given nothing but a gltf or just a quality setting', function() { var aoOptions = {}; - var options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); + var options = generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -659,7 +667,7 @@ describe('AmbientOcclusion', function() { aoOptions = { quality: 'medium' }; - options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); + options = generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -675,7 +683,7 @@ describe('AmbientOcclusion', function() { aoOptions = { quality: 'high' }; - options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); + options = generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(false); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -696,7 +704,7 @@ describe('AmbientOcclusion', function() { triangleCenterOnly: true, rayDistance: 10.0 }; - var options = AmbientOcclusion.generateOptions(boxOverGroundGltf, aoOptions); + var options = generateOptions(boxOverGroundGltf, aoOptions); expect(options.toTexture).toEqual(true); expect(options.groundPlane).toEqual(false); expect(options.ambientShadowContribution).toEqual(0.5); @@ -730,7 +738,7 @@ describe('AmbientOcclusion', function() { functionArguments : ['arg0', 'arg1', 'arg2'] }; - var extractedCommand = AmbientOcclusion.extractInstructionWithFunctionCall(options); + var extractedCommand = extractInstructionWithFunctionCall(options); expect(extractedCommand).toEqual('val = command(arg0, arg1 * (arg2 + innerCommand(innerArg0))) + 0.0'); }); @@ -754,7 +762,7 @@ describe('AmbientOcclusion', function() { snippet : 'innerCommand' }; - AmbientOcclusion.injectGlslAfterInstructionContaining(options); + injectGlslAfterInstructionContaining(options); var newSource = shader.extras._pipeline.source.toString(); expect(newSource).toEqual('function(arg0, arg1, arg2, arg3, innerArg0) {' + 'command(arg3);' + From 404401b774579114f2ee5f432c1d078785dc93dd Mon Sep 17 00:00:00 2001 From: Robert Taglang Date: Wed, 24 Aug 2016 11:38:53 -0400 Subject: [PATCH 21/21] Missed a change --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fe8222d7..6c6fd52d 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ module.exports = { addDefaults : require('./lib/addDefaults'), addExtensionsUsed : require('./lib/addExtensionsUsed'), addPipelineExtras : require('./lib/addPipelineExtras'), - bakeAmbientOcclusion : require('./lib/AmbientOcclusion').bakeAmbientOcclusion, + bakeAmbientOcclusion : require('./lib/bakeAmbientOcclusion'), byteLengthForComponentType : require('./lib/byteLengthForComponentType'), combineMeshes : require('./lib/combineMeshes'), combineNodes : require('./lib/combineNodes'),