From 8c909e82be1a519f08ad9f30367fb073f0143bc0 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 3 May 2017 12:06:25 -0400 Subject: [PATCH] Style tweaks --- lib/ForEach.js | 1 - lib/addCesiumRTC.js | 2 +- lib/byteLengthForComponentType.js | 2 - lib/cesiumGeometryToGltfPrimitive.js | 4 +- lib/combineNodes.js | 3 +- lib/createAccessor.js | 2 +- lib/createAccessorUsageTables.js | 2 +- lib/getAccessorByteStride.js | 1 + lib/getPrimitiveAttributeSemantics.js | 2 +- lib/numberOfComponentsForType.js | 2 +- lib/updateVersion.js | 122 +++++++++++++------------- lib/writeAccessor.js | 2 +- 12 files changed, 70 insertions(+), 75 deletions(-) diff --git a/lib/ForEach.js b/lib/ForEach.js index e4880ea9..ac248fce 100644 --- a/lib/ForEach.js +++ b/lib/ForEach.js @@ -6,7 +6,6 @@ var defined = Cesium.defined; module.exports = ForEach; - /** * Contains traversal functions for processing elements of the glTF hierarchy. * @constructor diff --git a/lib/addCesiumRTC.js b/lib/addCesiumRTC.js index b9d196b4..d600fd83 100644 --- a/lib/addCesiumRTC.js +++ b/lib/addCesiumRTC.js @@ -25,7 +25,7 @@ module.exports = addCesiumRTC; * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to use for lat-long mapping. */ function addCesiumRTC(gltf, options) { - options = defaultValue(options, {}); + options = defaultValue(options, []); var positionArray = []; var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); var position = options.position; diff --git a/lib/byteLengthForComponentType.js b/lib/byteLengthForComponentType.js index afe81611..4803b22c 100644 --- a/lib/byteLengthForComponentType.js +++ b/lib/byteLengthForComponentType.js @@ -13,8 +13,6 @@ module.exports = byteLengthForComponentType; * 5122 (SHORT) : 2 * 5123 (UNSIGNED_SHORT) : 2 * 5126 (FLOAT) : 4 - * - * Allowed by extension: * 5125 (UNSIGNED_INT) : 4 * * @param {Number} [componentType] diff --git a/lib/cesiumGeometryToGltfPrimitive.js b/lib/cesiumGeometryToGltfPrimitive.js index a6fd9510..62ead8a6 100644 --- a/lib/cesiumGeometryToGltfPrimitive.js +++ b/lib/cesiumGeometryToGltfPrimitive.js @@ -1,6 +1,5 @@ 'use strict'; var Cesium = require('cesium'); - var createAccessor = require('./createAccessor'); var findAccessorMinMax = require('./findAccessorMinMax'); var getPrimitiveAttributeSemantics = require('./getPrimitiveAttributeSemantics'); @@ -32,13 +31,12 @@ function getFirstAttributeSemantic(gltf, primitive, semantic, packedLength) { return semantics[0]; } -// Helper function to write attributes to gltf primitive from cesium geometry function mapGeometryAttributeToPrimitive(gltf, primitive, geometry, semantic) { var attributeSemantic; var values; var packedAttributeLength = geometry.attributes.position.values.length; - switch(semantic) { + switch (semantic) { case 'position': attributeSemantic = getFirstAttributeSemantic(gltf, primitive, 'POSITION', packedAttributeLength); values = geometry.attributes.position.values; diff --git a/lib/combineNodes.js b/lib/combineNodes.js index cc87eab5..78c6c0fd 100644 --- a/lib/combineNodes.js +++ b/lib/combineNodes.js @@ -5,8 +5,9 @@ var NodeHelpers = require('./NodeHelpers'); var PrimitiveHelpers = require('./PrimitiveHelpers'); var RemoveUnusedProperties = require('./RemoveUnusedProperties'); -var Matrix4 = Cesium.Matrix4; var defined = Cesium.defined; +var Matrix4 = Cesium.Matrix4; + var removeMeshes = RemoveUnusedProperties.removeMeshes; var removeNodes = RemoveUnusedProperties.removeNodes; diff --git a/lib/createAccessor.js b/lib/createAccessor.js index b7d74f28..285f7663 100644 --- a/lib/createAccessor.js +++ b/lib/createAccessor.js @@ -15,7 +15,7 @@ module.exports = createAccessor; * Creates an accessor from data and adds it to the glTF asset. * * @param {Object} gltf A javascript object containing a glTF asset. - * @param {Array.|Number} dataOrLength The data to store in the accessor buffer or the length of data to allocate. + * @param {Number[]|Number} dataOrLength The data to store in the accessor buffer or the length of data to allocate. * @param {String} type glTF type (e.g. 'scalar', 'vec3') * @param {Number} componentType glTF component type (e.g. 5126 (float)) * @param {Number} target glTF bufferView target (e.g. 34962 (ARRAY_BUFFER), 34963 (ELEMENT_ARRAY_BUFFER) diff --git a/lib/createAccessorUsageTables.js b/lib/createAccessorUsageTables.js index c3301b97..b06b2aa2 100644 --- a/lib/createAccessorUsageTables.js +++ b/lib/createAccessorUsageTables.js @@ -151,7 +151,7 @@ function createAccessorUsageTables(gltf) { } } } - }) ; + }); }); var finalTables = []; var tablesLength = tables.length; diff --git a/lib/getAccessorByteStride.js b/lib/getAccessorByteStride.js index f691e5d3..c144b7f4 100644 --- a/lib/getAccessorByteStride.js +++ b/lib/getAccessorByteStride.js @@ -11,6 +11,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} gltf A javascript object containing a glTF asset. * @param {Object} accessor The accessor. * @returns {Number} The byte stride of the accessor. */ diff --git a/lib/getPrimitiveAttributeSemantics.js b/lib/getPrimitiveAttributeSemantics.js index ac8ec211..10c71f01 100644 --- a/lib/getPrimitiveAttributeSemantics.js +++ b/lib/getPrimitiveAttributeSemantics.js @@ -10,7 +10,7 @@ module.exports = getPrimitiveAttributeSemantics; * * @param {Object} primitive A javascript object containing a glTF primitive. * @param {String} semanticPrefix The search string for semantics. Matched semantics start with this string. - * @returns {Array.} The primitive semantics starting with semanticPrefix. + * @returns {String[]} The primitive semantics starting with semanticPrefix. */ function getPrimitiveAttributeSemantics(primitive, semanticPrefix) { var attributes = primitive.attributes; diff --git a/lib/numberOfComponentsForType.js b/lib/numberOfComponentsForType.js index fa44e94b..600cda8a 100644 --- a/lib/numberOfComponentsForType.js +++ b/lib/numberOfComponentsForType.js @@ -9,7 +9,7 @@ module.exports = numberOfComponentsForType; * 'VEC2' : 2 * 'VEC3' : 3 * 'VEC4' : 4 - * 'MAT2' : 4 + * 'MAT2' : 4 * 'MAT3' : 9 * 'MAT4' : 16 * diff --git a/lib/updateVersion.js b/lib/updateVersion.js index 91eae7d9..83767d28 100644 --- a/lib/updateVersion.js +++ b/lib/updateVersion.js @@ -2,16 +2,16 @@ var Cesium = require('cesium'); var addExtensionsRequired = require('./addExtensionsRequired'); var addToArray = require('./addToArray'); -var ForEach = require('./ForEach'); var findAccessorMinMax = require('./findAccessorMinMax'); +var ForEach = require('./ForEach'); var Cartesian3 = Cesium.Cartesian3; var CesiumMath = Cesium.Math; -var Quaternion = Cesium.Quaternion; -var WebGLConstants = Cesium.WebGLConstants; var clone = Cesium.clone; var defaultValue = Cesium.defaultValue; var defined = Cesium.defined; +var Quaternion = Cesium.Quaternion; +var WebGLConstants = Cesium.WebGLConstants; module.exports = updateVersion; @@ -507,45 +507,44 @@ function requireKnownExtensions(gltf) { function removeBufferType(gltf) { ForEach.buffer(gltf, function(buffer) { delete buffer.type; - }); } function makeMaterialValuesArrays(gltf) { ForEach.material(gltf, function(material) { - ForEach.materialValue(material, function(value, name) { - if (!Array.isArray(value)) { - material.values[name] = [value]; - } - }) ; + ForEach.materialValue(material, function(value, name) { + if (!Array.isArray(value)) { + material.values[name] = [value]; + } + }); }); } function requireAttributeSetIndex(gltf) { ForEach.mesh(gltf, function(mesh) { - ForEach.meshPrimitive(mesh, function(primitive) { - ForEach.meshPrimitiveAttribute(primitive, function(accessorId, semantic) { - if (semantic === 'TEXCOORD') { - primitive.attributes.TEXCOORD_0 = accessorId; - } else if (semantic === 'COLOR') { - primitive.attributes.COLOR_0 = accessorId; - } - }); - delete primitive.attributes.TEXCOORD; - delete primitive.attributes.COLOR; - }); + ForEach.meshPrimitive(mesh, function(primitive) { + ForEach.meshPrimitiveAttribute(primitive, function(accessorId, semantic) { + if (semantic === 'TEXCOORD') { + primitive.attributes.TEXCOORD_0 = accessorId; + } else if (semantic === 'COLOR') { + primitive.attributes.COLOR_0 = accessorId; + } + }); + delete primitive.attributes.TEXCOORD; + delete primitive.attributes.COLOR; + }); }); ForEach.technique(gltf, function(technique) { - ForEach.techniqueParameter(technique, function(parameter) { - var semantic = parameter.semantic; - if (defined(semantic)) { - if (semantic === 'TEXCOORD') { - parameter.semantic = 'TEXCOORD_0'; - } else if (semantic === 'COLOR') { - parameter.semantic = 'COLOR_0'; - } - } - }); + ForEach.techniqueParameter(technique, function(parameter) { + var semantic = parameter.semantic; + if (defined(semantic)) { + if (semantic === 'TEXCOORD') { + parameter.semantic = 'TEXCOORD_0'; + } else if (semantic === 'COLOR') { + parameter.semantic = 'COLOR_0'; + } + } + }); }); } @@ -560,30 +559,30 @@ var knownSemantics = { function underscoreApplicationSpecificSemantics(gltf) { var mappedSemantics = {}; ForEach.mesh(gltf, function(mesh) { - ForEach.meshPrimitive(mesh, function(primitive) { - /* jshint unused:vars */ - ForEach.meshPrimitiveAttribute(primitive, function(accessorId, semantic) { - if (semantic.charAt(0) !== '_') { - var setIndex = semantic.search(/_[0-9]+/g); - var strippedSemantic = semantic; - if (setIndex >= 0) { - strippedSemantic = semantic.substring(0, setIndex); - } - if (!defined(knownSemantics[strippedSemantic])) { - var newSemantic = '_' + semantic; - mappedSemantics[semantic] = newSemantic; - } - } - }); - for(var semantic in mappedSemantics) { - if (mappedSemantics.hasOwnProperty(semantic)) { - var mappedSemantic = mappedSemantics[semantic]; - var accessorId = primitive.attributes[semantic]; - delete primitive.attributes[semantic]; - primitive.attributes[mappedSemantic] = accessorId; - } - } - }); + ForEach.meshPrimitive(mesh, function(primitive) { + /* jshint unused:vars */ + ForEach.meshPrimitiveAttribute(primitive, function(accessorId, semantic) { + if (semantic.charAt(0) !== '_') { + var setIndex = semantic.search(/_[0-9]+/g); + var strippedSemantic = semantic; + if (setIndex >= 0) { + strippedSemantic = semantic.substring(0, setIndex); + } + if (!defined(knownSemantics[strippedSemantic])) { + var newSemantic = '_' + semantic; + mappedSemantics[semantic] = newSemantic; + } + } + }); + for (var semantic in mappedSemantics) { + if (mappedSemantics.hasOwnProperty(semantic)) { + var mappedSemantic = mappedSemantics[semantic]; + var accessorId = primitive.attributes[semantic]; + delete primitive.attributes[semantic]; + primitive.attributes[mappedSemantic] = accessorId; + } + } + }); }); ForEach.technique(gltf, function(technique) { ForEach.techniqueParameter(technique, function(parameter) { @@ -626,7 +625,6 @@ function removeScissorFromTechniques(gltf) { } function clampTechniqueFunctionStates(gltf) { - var i; ForEach.technique(gltf, function(technique) { var techniqueStates = technique.states; if (defined(techniqueStates)) { @@ -634,7 +632,7 @@ function clampTechniqueFunctionStates(gltf) { if (defined(functions)) { var blendColor = functions.blendColor; if (defined(blendColor)) { - for (i = 0; i < 4; i++) { + for (var i = 0; i < 4; i++) { blendColor[i] = CesiumMath.clamp(blendColor[i], 0.0, 1.0); } } @@ -709,12 +707,12 @@ function requireAccessorMinMax(gltf) { function stripTechniqueAttributeValues(gltf) { ForEach.technique(gltf, function(technique) { - ForEach.techniqueAttribute(technique, function(attribute) { - var parameter = technique.parameters[attribute]; - if (defined(parameter.value)) { - delete parameter.value; - } - }); + ForEach.techniqueAttribute(technique, function(attribute) { + var parameter = technique.parameters[attribute]; + if (defined(parameter.value)) { + delete parameter.value; + } + }); }); } diff --git a/lib/writeAccessor.js b/lib/writeAccessor.js index 7f1eac7e..1d568db0 100644 --- a/lib/writeAccessor.js +++ b/lib/writeAccessor.js @@ -5,7 +5,7 @@ var numberOfComponentsForType = require('./numberOfComponentsForType'); module.exports = writeAccessor; /** - * Writes the contents of dataArray into a glTF accessor. + * Writes values into a glTF accessor. * * The glTF asset must be initialized for the pipeline. *