Skip to content

Commit

Permalink
Style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 3, 2017
1 parent 1406b32 commit 8c909e8
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 75 deletions.
1 change: 0 additions & 1 deletion lib/ForEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var defined = Cesium.defined;

module.exports = ForEach;


/**
* Contains traversal functions for processing elements of the glTF hierarchy.
* @constructor
Expand Down
2 changes: 1 addition & 1 deletion lib/addCesiumRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions lib/byteLengthForComponentType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions lib/cesiumGeometryToGltfPrimitive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var Cesium = require('cesium');

var createAccessor = require('./createAccessor');
var findAccessorMinMax = require('./findAccessorMinMax');
var getPrimitiveAttributeSemantics = require('./getPrimitiveAttributeSemantics');
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/combineNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/createAccessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>|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)
Expand Down
2 changes: 1 addition & 1 deletion lib/createAccessorUsageTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function createAccessorUsageTables(gltf) {
}
}
}
}) ;
});
});
var finalTables = [];
var tablesLength = tables.length;
Expand Down
1 change: 1 addition & 0 deletions lib/getAccessorByteStride.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/getPrimitiveAttributeSemantics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string>} The primitive semantics starting with semanticPrefix.
* @returns {String[]} The primitive semantics starting with semanticPrefix.
*/
function getPrimitiveAttributeSemantics(primitive, semanticPrefix) {
var attributes = primitive.attributes;
Expand Down
2 changes: 1 addition & 1 deletion lib/numberOfComponentsForType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = numberOfComponentsForType;
* 'VEC2' : 2
* 'VEC3' : 3
* 'VEC4' : 4
* 'MAT2' : 4
* 'MAT2' : 4
* 'MAT3' : 9
* 'MAT4' : 16
*
Expand Down
122 changes: 60 additions & 62 deletions lib/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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';
}
}
});
});
}

Expand All @@ -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) {
Expand Down Expand Up @@ -626,15 +625,14 @@ function removeScissorFromTechniques(gltf) {
}

function clampTechniqueFunctionStates(gltf) {
var i;
ForEach.technique(gltf, function(technique) {
var techniqueStates = technique.states;
if (defined(techniqueStates)) {
var functions = techniqueStates.functions;
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);
}
}
Expand Down Expand Up @@ -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;
}
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/writeAccessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 8c909e8

Please sign in to comment.