Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Apr 30, 2018
1 parent d629634 commit dc84a54
Show file tree
Hide file tree
Showing 44 changed files with 1,966 additions and 528 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var fsExtra = require('fs-extra');
var gltfToGlb = gltfPipeline.gltfToGlb;
var gltf = fsExtra.readJsonSync('model.gltf');
var options = {
separateTextures : true
separateTextures: true
};
processGltf(gltf, options)
.then(function(results) {
Expand Down
120 changes: 60 additions & 60 deletions bin/gltf-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,57 @@ var argv = yargs
.help('h')
.alias('h', 'help')
.options({
input : {
alias : 'i',
describe : 'Path to the glTF or glb file.',
type : 'string',
normalize : true,
demandOption : true
},
output : {
alias : 'o',
describe : 'Output path of the glTF or glb file. Separate resources will be saved to the same directory.',
type : 'string',
normalize : true
},
binary : {
alias : 'b',
describe : 'Convert the input glTF to glb.',
type : 'boolean',
default : false
},
json : {
alias : 'j',
describe : 'Convert the input glb to glTF.',
type : 'boolean',
default : false
},
separate : {
alias : 's',
describe : 'Write separate buffers, shaders, and textures instead of embedding them in the glTF.',
type : 'boolean',
default : defaults.separate
},
separateTextures : {
alias : 't',
describe : 'Write out separate textures only.',
type : 'boolean',
default : defaults.separateTextures
},
checkTransparency : {
describe : 'Do a more exhaustive check for texture transparency by looking at the alpha channel of each pixel. By default textures are considered to be opaque.',
type : 'boolean',
default : defaults.checkTransparency
},
secure : {
describe : 'Prevent the converter from reading textures or mtl files outside of the input obj directory.',
type : 'boolean',
default : defaults.secure
},
stats : {
describe : 'Print statistics to console for input and output glTF files.',
type : 'boolean',
default : defaults.stats
input: {
alias: 'i',
describe: 'Path to the glTF or glb file.',
type: 'string',
normalize: true,
demandOption: true
},
output: {
alias: 'o',
describe: 'Output path of the glTF or glb file. Separate resources will be saved to the same directory.',
type: 'string',
normalize: true
},
binary: {
alias: 'b',
describe: 'Convert the input glTF to glb.',
type: 'boolean',
default: false
},
json: {
alias: 'j',
describe: 'Convert the input glb to glTF.',
type: 'boolean',
default: false
},
separate: {
alias: 's',
describe: 'Write separate buffers, shaders, and textures instead of embedding them in the glTF.',
type: 'boolean',
default: defaults.separate
},
separateTextures: {
alias: 't',
describe: 'Write out separate textures only.',
type: 'boolean',
default: defaults.separateTextures
},
checkTransparency: {
describe: 'Do a more exhaustive check for texture transparency by looking at the alpha channel of each pixel. By default textures are considered to be opaque.',
type: 'boolean',
default: defaults.checkTransparency
},
secure: {
describe: 'Prevent the converter from reading textures or mtl files outside of the input directory.',
type: 'boolean',
default: defaults.secure
},
stats: {
describe: 'Print statistics to console for input and output glTF files.',
type: 'boolean',
default: defaults.stats
},
'draco.compressMeshes': {
alias: 'd',
Expand Down Expand Up @@ -107,7 +107,7 @@ var argv = yargs
type: 'number'
},
'draco.unifiedQuantization': {
default : false,
default: false,
describe: 'Quantize positions of all primitives using the same quantization grid defined by the unified bounding box of all primitives. If this option is not set, quantization is applied on each primitive separately which can result in gaps appearing between different primitives. Default is false.',
type: 'boolean'
}
Expand Down Expand Up @@ -155,21 +155,21 @@ for (i = 0; i < length; ++i) {
}

var options = {
resourceDirectory : inputDirectory,
separate : argv.separate,
separateTextures : argv.separateTextures,
secure : argv.secure,
checkTransparency : argv.checkTransparency,
stats : argv.stats,
name : outputName,
resourceDirectory: inputDirectory,
separate: argv.separate,
separateTextures: argv.separateTextures,
secure: argv.secure,
checkTransparency: argv.checkTransparency,
stats: argv.stats,
name: outputName,
dracoOptions: dracoOptions
};

var inputIsBinary = inputExtension === '.glb';
var outputIsBinary = outputExtension === '.glb';

var jsonOptions = {
spaces : 2
spaces: 2
};

var read = inputIsBinary ? fsExtra.readFile : fsExtra.readJson;
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*eslint-disable global-require*/
'use strict';
module.exports = {
getStatistics : require('./lib/getStatistics'),
glbToGltf : require('./lib/glbToGltf'),
gltfToGlb : require('./lib/gltfToGlb'),
processGlb : require('./lib/processGlb'),
processGltf : require('./lib/processGltf')
getStatistics: require('./lib/getStatistics'),
glbToGltf: require('./lib/glbToGltf'),
gltfToGlb: require('./lib/gltfToGlb'),
processGlb: require('./lib/processGlb'),
processGltf: require('./lib/processGltf')
};
64 changes: 32 additions & 32 deletions lib/addDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,61 +148,61 @@ function addDefaults(gltf) {
}

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

var defaultTechnique = {
attributes : {
a_position : 'position'
attributes: {
a_position: 'position'
},
parameters : {
modelViewMatrix : {
semantic : 'MODELVIEW',
type : WebGLConstants.FLOAT_MAT4
parameters: {
modelViewMatrix: {
semantic: 'MODELVIEW',
type: WebGLConstants.FLOAT_MAT4
},
projectionMatrix : {
semantic : 'PROJECTION',
type : WebGLConstants.FLOAT_MAT4
projectionMatrix: {
semantic: 'PROJECTION',
type: WebGLConstants.FLOAT_MAT4
},
emission : {
type : WebGLConstants.FLOAT_VEC4,
value : [
emission: {
type: WebGLConstants.FLOAT_VEC4,
value: [
0.5, 0.5, 0.5, 1.0
]
},
position : {
semantic : 'POSITION',
type : WebGLConstants.FLOAT_VEC3
position: {
semantic: 'POSITION',
type: WebGLConstants.FLOAT_VEC3
}
},
states : {
enable : [
states: {
enable: [
WebGLConstants.CULL_FACE,
WebGLConstants.DEPTH_TEST
]
},
uniforms : {
u_modelViewMatrix : 'modelViewMatrix',
u_projectionMatrix : 'projectionMatrix',
u_emission : 'emission'
uniforms: {
u_modelViewMatrix: 'modelViewMatrix',
u_projectionMatrix: 'projectionMatrix',
u_emission: 'emission'
}
};

var defaultProgram = {
attributes : [
attributes: [
'a_position'
]
};

var defaultVertexShader = {
type : WebGLConstants.VERTEX_SHADER,
extras : {
_pipeline : {
source :
type: WebGLConstants.VERTEX_SHADER,
extras: {
_pipeline: {
source:
'precision highp float;\n' +
'uniform mat4 u_modelViewMatrix;\n' +
'uniform mat4 u_projectionMatrix;\n' +
Expand All @@ -216,10 +216,10 @@ var defaultVertexShader = {
};

var defaultFragmentShader = {
type : WebGLConstants.FRAGMENT_SHADER,
extras : {
_pipeline : {
source :
type: WebGLConstants.FRAGMENT_SHADER,
extras: {
_pipeline: {
source:
'precision highp float;\n' +
'uniform vec4 u_emission;\n' +
'void main(void)\n' +
Expand Down
55 changes: 27 additions & 28 deletions lib/compressDracoMeshes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ function getNamedAttributeData(gltf, primitive, semantic) {
var packed = readAccessorPacked(gltf, accessor);

return {
numberOfComponents : componentsPerAttribute,
numberOfVertices : accessor.count,
data : packed
numberOfComponents: componentsPerAttribute,
numberOfVertices: accessor.count,
data: packed
};
}

function addCompressionExtensionToPrimitive(gltf, primitive, attributeToId, encodedLength, encodedData) {
// Remove properties from accessors.
// Remove indices bufferView.

var indicesAccessor = gltf.accessors[primitive.indices];
var newIndicesAccessor = {
componentType : indicesAccessor.componentType,
count : indicesAccessor.count,
max : indicesAccessor.max,
min : indicesAccessor.min,
type : indicesAccessor.type
componentType: indicesAccessor.componentType,
count: indicesAccessor.count,
max: indicesAccessor.max,
min: indicesAccessor.min,
type: indicesAccessor.type
};
var indicesAccessorId = addToArray(gltf.accessors, newIndicesAccessor);
primitive.indices = indicesAccessorId;
Expand All @@ -54,29 +53,29 @@ function addCompressionExtensionToPrimitive(gltf, primitive, attributeToId, enco
ForEach.meshPrimitiveAttribute(primitive, function(accessorId, semantic) {
var attributeAccessor = gltf.accessors[primitive.attributes[semantic]];
var newAttributeAccessor = {
componentType : attributeAccessor.componentType,
count : attributeAccessor.count,
max : attributeAccessor.max,
min : attributeAccessor.min,
type : attributeAccessor.type
componentType: attributeAccessor.componentType,
count: attributeAccessor.count,
max: attributeAccessor.max,
min: attributeAccessor.min,
type: attributeAccessor.type
};
var attributeAccessorId = addToArray(gltf.accessors, newAttributeAccessor);
primitive.attributes[semantic] = attributeAccessorId;
});

var buffer = {
byteLength : encodedLength,
extras : {
_pipeline : {
source : encodedData
byteLength: encodedLength,
extras: {
_pipeline: {
source: encodedData
}
}
};
var bufferId = addToArray(gltf.buffers, buffer);
var bufferView = {
buffer : bufferId,
byteOffset : 0,
byteLength : encodedLength
buffer: bufferId,
byteOffset: 0,
byteLength: encodedLength
};
var bufferViewId = addToArray(gltf.bufferViews, bufferView);

Expand All @@ -86,8 +85,8 @@ function addCompressionExtensionToPrimitive(gltf, primitive, attributeToId, enco
primitive.extensions = extensions;
}
var dracoExtension = {
bufferView : bufferViewId,
attributes : attributeToId
bufferView: bufferViewId,
attributes: attributeToId
};
extensions.KHR_draco_mesh_compression = dracoExtension;
}
Expand All @@ -105,8 +104,8 @@ function copyCompressedExtensionToPrimitive(primitive, compressedPrimitive) {
var extensions = {};
primitive.extensions = extensions;
var copiedExtension = {
bufferView : dracoExtension.bufferView,
attributes : dracoExtension.attributes
bufferView: dracoExtension.bufferView,
attributes: dracoExtension.attributes
};
extensions.KHR_draco_mesh_compression = copiedExtension;
}
Expand Down Expand Up @@ -186,9 +185,9 @@ function compressDracoMeshes(gltf, options) {
}

var primitiveGeometry = {
attributes : primitive.attributes,
indices : primitive.indices,
mode : primitive.mode
attributes: primitive.attributes,
indices: primitive.indices,
mode: primitive.mode
};
var hashValue = hashObject(primitiveGeometry);
if (defined(hashPrimitives[hashValue])) {
Expand Down
Loading

0 comments on commit dc84a54

Please sign in to comment.