Skip to content

Commit

Permalink
Merge branch 'master' into duplicate-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 27, 2019
2 parents c23d2b4 + 9a52732 commit e6786bc
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 77 deletions.
7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Change Log
==========

### 2.2.0 - 2019-??-??
### 2.?.? - 2019-??-??

* Fixed writing duplicate resource that are referenced multiple times. [#483](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/483)

### 2.1.4 - 2019-10-04

* Added removal of unused materials, nodes and meshes. [#465](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/465)
* Added `keepUnusedElements` flag to keep unused materials, nodes and meshes. [#465](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/465)
* Fixed writing duplicate resource that are referenced multiple times. [#483](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/483)

### 2.1.3 - 2019-03-21

Expand Down
2 changes: 1 addition & 1 deletion bin/gltf-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const run = inputIsBinary ? (outputIsBinary ? processGlb : glbToGltf) : (outputI
function saveSeparateResources(separateResources) {
const resourcePromises = [];
for (const relativePath in separateResources) {
if (separateResources.hasOwnProperty(relativePath)) {
if (Object.prototype.hasOwnProperty.call(separateResources, relativePath)) {
const resource = separateResources[relativePath];
const resourcePath = path.join(outputDirectory, relativePath);
resourcePromises.push(fsExtra.outputFile(resourcePath, resource));
Expand Down
32 changes: 12 additions & 20 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function amdify(source, subDependencyMapping) {
const subdependencyMapping = {};
const removeRequireMapping = [];
for (requireVariable in requireMapping) {
if (requireMapping.hasOwnProperty(requireVariable)) {
if (Object.prototype.hasOwnProperty.call(requireMapping, requireVariable)) {
requirePath = requireMapping[requireVariable];
const findSubdependencyString = 'var\\s+(.+?)\\s*?=\\s*?' + requireVariable + '\\.(.+?);\n';
const findSubdependencyRegex = new RegExp(findSubdependencyString, 'g');
Expand Down Expand Up @@ -178,35 +178,27 @@ function amdify(source, subDependencyMapping) {
}
// join sub-dependencies with requireMapping
for (const subdependencyVariable in subdependencyMapping) {
if (subdependencyMapping.hasOwnProperty(subdependencyVariable)) {
if (Object.prototype.hasOwnProperty.call(subdependencyMapping, subdependencyVariable)) {
requireMapping[subdependencyVariable] = subdependencyMapping[subdependencyVariable];
}
}
// amdify source
// indent
outputSource = outputSource.replace(/\n/g, '\n ');
outputSource = outputSource.replace(/'use strict';/g, '');

// wrap define header
const variables = [];
const paths = [];
const lines = [];
for (const variable in requireMapping) {
if (requireMapping.hasOwnProperty(variable)) {
variables.push(variable);
paths.push(requireMapping[variable]);
if (Object.prototype.hasOwnProperty.call(requireMapping, variable)) {
lines.push('import ' + variable + ' from \'' + requireMapping[variable] + '\'');
}
}
let defineHeader = 'define([], function() {\n ';
if (paths.length > 0) {
const definePathsHeader = '\'' + paths.join('\',\n \'') + '\'';
const defineVariablesHeader = variables.join(',\n ');
defineHeader =
'define([\n' +
' ' + definePathsHeader + '\n' +
' ], function(\n' +
' ' + defineVariablesHeader + ') {\n ';
let defineHeader = '';
if (lines.length > 0) {
defineHeader = lines.join('\n') + '\n';
}
let defineFooter = '\n});\n';
let defineFooter = '\n';
if (defined(returnValue)) {
defineFooter = '\n return ' + returnValue + ';' + defineFooter;
defineFooter = '\nexport default ' + returnValue + ';\n';
}
outputSource = defineHeader + outputSource + defineFooter;
// remove repeat newlines
Expand Down
16 changes: 8 additions & 8 deletions lib/ForEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function ForEach() {
ForEach.objectLegacy = function(objects, handler) {
if (defined(objects)) {
for (const objectId in objects) {
if (objects.hasOwnProperty(objectId)) {
if (Object.prototype.hasOwnProperty.call(objects, objectId)) {
const object = objects[objectId];
const value = handler(object, objectId);

Expand Down Expand Up @@ -190,7 +190,7 @@ ForEach.compressedImage = function(image, handler) {
if (defined(image.extras)) {
const compressedImages = image.extras.compressedImage3DTiles;
for (const type in compressedImages) {
if (compressedImages.hasOwnProperty(type)) {
if (Object.prototype.hasOwnProperty.call(compressedImages, type)) {
const compressedImage = compressedImages[type];
const value = handler(compressedImage, type);

Expand All @@ -213,7 +213,7 @@ ForEach.materialValue = function(material, handler) {
}

for (const name in values) {
if (values.hasOwnProperty(name)) {
if (Object.prototype.hasOwnProperty.call(values, name)) {
const value = handler(values[name], name);

if (defined(value)) {
Expand Down Expand Up @@ -245,7 +245,7 @@ ForEach.meshPrimitive = function(mesh, handler) {
ForEach.meshPrimitiveAttribute = function(primitive, handler) {
const attributes = primitive.attributes;
for (const semantic in attributes) {
if (attributes.hasOwnProperty(semantic)) {
if (Object.prototype.hasOwnProperty.call(attributes, semantic)) {
const value = handler(attributes[semantic], semantic);

if (defined(value)) {
Expand All @@ -271,7 +271,7 @@ ForEach.meshPrimitiveTarget = function(primitive, handler) {

ForEach.meshPrimitiveTargetAttribute = function(target, handler) {
for (const semantic in target) {
if (target.hasOwnProperty(semantic)) {
if (Object.prototype.hasOwnProperty.call(target, semantic)) {
const accessorId = target[semantic];
const value = handler(accessorId, semantic);

Expand Down Expand Up @@ -366,7 +366,7 @@ ForEach.skinJoint = function(skin, handler) {
ForEach.techniqueAttribute = function(technique, handler) {
const attributes = technique.attributes;
for (const attributeName in attributes) {
if (attributes.hasOwnProperty(attributeName)) {
if (Object.prototype.hasOwnProperty.call(attributes, attributeName)) {
const value = handler(attributes[attributeName], attributeName);

if (defined(value)) {
Expand All @@ -379,7 +379,7 @@ ForEach.techniqueAttribute = function(technique, handler) {
ForEach.techniqueUniform = function(technique, handler) {
const uniforms = technique.uniforms;
for (const uniformName in uniforms) {
if (uniforms.hasOwnProperty(uniformName)) {
if (Object.prototype.hasOwnProperty.call(uniforms, uniformName)) {
const value = handler(uniforms[uniformName], uniformName);

if (defined(value)) {
Expand All @@ -392,7 +392,7 @@ ForEach.techniqueUniform = function(technique, handler) {
ForEach.techniqueParameter = function(technique, handler) {
const parameters = technique.parameters;
for (const parameterName in parameters) {
if (parameters.hasOwnProperty(parameterName)) {
if (Object.prototype.hasOwnProperty.call(parameters, parameterName)) {
const value = handler(parameters[parameterName], parameterName);

if (defined(value)) {
Expand Down
2 changes: 2 additions & 0 deletions lib/getImageExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function getImageExtension(data) {
return '.ktx';
} else if (header.equals(Buffer.from([0x48, 0x78]))) {
return '.crn';
} else if (header.equals(Buffer.from([0x73, 0x42]))) {
return '.basis';
} else if (webpHeaderRIFFChars.equals(Buffer.from([0x52, 0x49, 0x46, 0x46])) && webpHeaderWEBPChars.equals(Buffer.from([0x57, 0x45, 0x42, 0x50]))) {
// See https://developers.google.com/speed/webp/docs/riff_container#webp_file_header
return '.webp';
Expand Down
2 changes: 1 addition & 1 deletion lib/mergeBuffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function mergeBuffers(gltf, defaultName) {
gltf.buffers = new Array(buffersLength);

for (const mergedName in buffersToMerge) {
if (buffersToMerge.hasOwnProperty(mergedName)) {
if (Object.prototype.hasOwnProperty.call(buffersToMerge, mergedName)) {
const buffers = buffersToMerge[mergedName].buffers;
const byteLength = buffersToMerge[mergedName].byteLength;
const index = buffersToMerge[mergedName].index;
Expand Down
2 changes: 1 addition & 1 deletion lib/removeExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function removeExtensionAndTraverse(object, extension) {
}
}
for (const key in object) {
if (object.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
removeExtensionAndTraverse(object[key], extension);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/replaceWithDecompressedPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function replaceWithDecompressedPrimitive(gltf, primitive, dracoEncodedBuffer, u

const dracoAttributes = primitive.extensions.KHR_draco_mesh_compression.attributes;
for (const semantic in dracoAttributes) {
if (dracoAttributes.hasOwnProperty(semantic)) {
if (Object.prototype.hasOwnProperty.call(dracoAttributes, semantic)) {
const attributeAccessor = gltf.accessors[primitive.attributes[semantic]];
attributeAccessor.count = dracoEncodedBuffer.numberOfPoints;

Expand Down
6 changes: 3 additions & 3 deletions lib/splitPrimitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function splitPrimitives(gltf) {
});

for (hash in primitivesWithSharedAttributes) {
if (primitivesWithSharedAttributes.hasOwnProperty(hash)) {
if (Object.prototype.hasOwnProperty.call(primitivesWithSharedAttributes, hash)) {
primitives = primitivesWithSharedAttributes[hash];
primitivesLength = primitives.length;
if (primitivesLength === 1) {
Expand All @@ -81,7 +81,7 @@ function splitPrimitives(gltf) {

if (primitivesSplit) {
for (hash in duplicatePrimitives) {
if (duplicatePrimitives.hasOwnProperty(hash)) {
if (Object.prototype.hasOwnProperty.call(duplicatePrimitives, hash)) {
const primitiveToCopy = hashPrimitives[hash];
primitives = duplicatePrimitives[hash];
primitivesLength = primitives.length;
Expand Down Expand Up @@ -148,7 +148,7 @@ function createNewAttribute(gltf, accessorId, semantic, attributeData, mappedInd

function remapData(dataArray, newDataArray, mappedIndices, numberOfComponents) {
for (const index in mappedIndices) {
if (mappedIndices.hasOwnProperty(index)) {
if (Object.prototype.hasOwnProperty.call(mappedIndices, index)) {
const mappedIndex = mappedIndices[index];
for (let i = 0; i < numberOfComponents; ++i) {
newDataArray[mappedIndex * numberOfComponents + i] = dataArray[index * numberOfComponents + i];
Expand Down
34 changes: 17 additions & 17 deletions lib/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ function updateVersion(gltf, options) {
version = defaultValue(version, gltf.asset.version).toString();

// Invalid version
if (!updateFunctions.hasOwnProperty(version)) {
if (!Object.prototype.hasOwnProperty.call(updateFunctions, version)) {
// Try truncating trailing version numbers, could be a number as well if it is 0.8
if (defined(version)) {
version = version.substring(0, 3);
}
// Default to 1.0 if it cannot be determined
if (!updateFunctions.hasOwnProperty(version)) {
if (!Object.prototype.hasOwnProperty.call(updateFunctions, version)) {
version = '1.0';
}
}
Expand All @@ -82,7 +82,7 @@ function updateVersion(gltf, options) {
function updateInstanceTechniques(gltf) {
const materials = gltf.materials;
for (const materialId in materials) {
if (materials.hasOwnProperty(materialId)) {
if (Object.prototype.hasOwnProperty.call(materials, materialId)) {
const material = materials[materialId];
const instanceTechnique = material.instanceTechnique;
if (defined(instanceTechnique)) {
Expand All @@ -97,7 +97,7 @@ function updateInstanceTechniques(gltf) {
function setPrimitiveModes(gltf) {
const meshes = gltf.meshes;
for (const meshId in meshes) {
if (meshes.hasOwnProperty(meshId)) {
if (Object.prototype.hasOwnProperty.call(meshes, meshId)) {
const mesh = meshes[meshId];
const primitives = mesh.primitives;
if (defined(primitives)) {
Expand All @@ -118,7 +118,7 @@ function updateNodes(gltf) {
const axis = new Cartesian3();
const quat = new Quaternion();
for (const nodeId in nodes) {
if (nodes.hasOwnProperty(nodeId)) {
if (Object.prototype.hasOwnProperty.call(nodes, nodeId)) {
const node = nodes[nodeId];
if (defined(node.rotation)) {
const rotation = node.rotation;
Expand Down Expand Up @@ -146,7 +146,7 @@ function updateAnimations(gltf) {
const axis = new Cartesian3();
const quat = new Quaternion();
for (const animationId in animations) {
if (animations.hasOwnProperty(animationId)) {
if (Object.prototype.hasOwnProperty.call(animations, animationId)) {
const animation = animations[animationId];
const channels = animation.channels;
const parameters = animation.parameters;
Expand Down Expand Up @@ -189,12 +189,12 @@ function updateAnimations(gltf) {
function removeTechniquePasses(gltf) {
const techniques = gltf.techniques;
for (const techniqueId in techniques) {
if (techniques.hasOwnProperty(techniqueId)) {
if (Object.prototype.hasOwnProperty.call(techniques, techniqueId)) {
const technique = techniques[techniqueId];
const passes = technique.passes;
if (defined(passes)) {
const passName = defaultValue(technique.pass, 'defaultPass');
if (passes.hasOwnProperty(passName)) {
if (Object.prototype.hasOwnProperty.call(passes, passName)) {
const pass = passes[passName];
const instanceProgram = pass.instanceProgram;
technique.attributes = defaultValue(technique.attributes, instanceProgram.attributes);
Expand Down Expand Up @@ -261,13 +261,13 @@ function glTF08to10(gltf) {
function removeAnimationSamplersIndirection(gltf) {
const animations = gltf.animations;
for (const animationId in animations) {
if (animations.hasOwnProperty(animationId)) {
if (Object.prototype.hasOwnProperty.call(animations, animationId)) {
const animation = animations[animationId];
const parameters = animation.parameters;
if (defined(parameters)) {
const samplers = animation.samplers;
for (const samplerId in samplers) {
if (samplers.hasOwnProperty(samplerId)) {
if (Object.prototype.hasOwnProperty.call(samplers, samplerId)) {
const sampler = samplers[samplerId];
sampler.input = parameters[sampler.input];
sampler.output = parameters[sampler.output];
Expand All @@ -282,7 +282,7 @@ function removeAnimationSamplersIndirection(gltf) {
function objectToArray(object, mapping) {
const array = [];
for (const id in object) {
if (object.hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(object, id)) {
const value = object[id];
mapping[id] = array.length;
array.push(value);
Expand Down Expand Up @@ -320,7 +320,7 @@ function objectsToArrays(gltf) {
const jointNameToId = {};
const nodes = gltf.nodes;
for (const id in nodes) {
if (nodes.hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(nodes, id)) {
jointName = nodes[id].jointName;
if (defined(jointName)) {
jointNameToId[jointName] = id;
Expand All @@ -330,7 +330,7 @@ function objectsToArrays(gltf) {

// Convert top level objects to arrays
for (const topLevelId in gltf) {
if (gltf.hasOwnProperty(topLevelId) && defined(globalMapping[topLevelId])) {
if (Object.prototype.hasOwnProperty.call(gltf, topLevelId) && defined(globalMapping[topLevelId])) {
const objectMapping = {};
const object = gltf[topLevelId];
gltf[topLevelId] = objectToArray(object, objectMapping);
Expand All @@ -340,7 +340,7 @@ function objectsToArrays(gltf) {

// Remap joint names to array indexes
for (jointName in jointNameToId) {
if (jointNameToId.hasOwnProperty(jointName)) {
if (Object.prototype.hasOwnProperty.call(jointNameToId, jointName)) {
jointNameToId[jointName] = globalMapping.nodes[jointNameToId[jointName]];
}
}
Expand Down Expand Up @@ -570,7 +570,7 @@ function removeAnimationSamplerNames(gltf) {

function removeEmptyArrays(gltf) {
for (const topLevelId in gltf) {
if (gltf.hasOwnProperty(topLevelId)) {
if (Object.prototype.hasOwnProperty.call(gltf, topLevelId)) {
const array = gltf[topLevelId];
if (isArray(array) && array.length === 0) {
delete gltf[topLevelId];
Expand Down Expand Up @@ -691,7 +691,7 @@ function underscoreApplicationSpecificSemantics(gltf) {
}
});
for (const semantic in mappedSemantics) {
if (mappedSemantics.hasOwnProperty(semantic)) {
if (Object.prototype.hasOwnProperty.call(mappedSemantics, semantic)) {
const mappedSemantic = mappedSemantics[semantic];
const accessorId = primitive.attributes[semantic];
if (defined(accessorId)) {
Expand Down Expand Up @@ -774,7 +774,7 @@ function moveByteStrideToBufferView(gltf) {

// Split accessors with different byte strides
for (const bufferViewId in bufferViewMap) {
if (bufferViewMap.hasOwnProperty(bufferViewId)) {
if (Object.prototype.hasOwnProperty.call(bufferViewMap, bufferViewId)) {
bufferView = bufferViews[bufferViewId];
const accessors = bufferViewMap[bufferViewId];
accessors.sort(function(a, b) {
Expand Down
6 changes: 5 additions & 1 deletion lib/writeResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ mime.define({'image/crn': ['crn']}, true);
// .glsl shaders are text/plain type
mime.define({'text/plain': ['glsl']}, true);

// .basis is not a supported mime type, so add it
mime.define({'image/basis': ['basis']}, true);

module.exports = writeResources;

/**
Expand Down Expand Up @@ -188,9 +191,10 @@ function getRelativePath(gltf, object, index, extension, options) {
relativePath = name + extension;

// Check if a file of the same name already exists, and if so, append a number
const number = 1;
let number = 1;
while (defined(options.separateResources[relativePath])) {
relativePath = name + '_' + number + extension;
number++;
}
return relativePath;
}
Expand Down
Loading

0 comments on commit e6786bc

Please sign in to comment.