Fix image uris and use better naming for separate resources

This commit is contained in:
Sean Lilley 2016-06-23 22:01:36 -04:00
parent 462c80fbc0
commit 139f473785
3 changed files with 27 additions and 12 deletions

View File

@ -104,7 +104,7 @@ function createGltf(data, inputPath, modelName, done) {
vertexByteStride = sizeOfFloat32 * 3;
}
var bufferId = 'buffer_' + modelName;
var bufferId = modelName + '_buffer';
var bufferViewVertexId = 'bufferView_vertex';
var bufferViewIndexId = 'bufferView_index';
var accessorPositionId = 'accessor_position';
@ -131,7 +131,7 @@ function createGltf(data, inputPath, modelName, done) {
}
function getImageId(image) {
return 'image_' + path.basename(image).substr(0, image.lastIndexOf('.'));
return path.basename(image, path.extname(image));
}
var gltf = {

View File

@ -19,19 +19,39 @@ function getChannels(colorType) {
}
}
function getUriType(extension) {
switch (extension) {
case 'png':
return 'data:image/png';
case 'jpg':
return 'data:image/jpeg';
case 'jpeg':
return 'data:image/jpeg';
case 'gif':
return 'data:image/gif';
default:
return 'data:image/' + extension;
}
}
function loadImage(imagePath, done) {
fs.readFile(imagePath, function(error, data) {
if (error) {
throw(error);
}
var extension = path.extname(imagePath).slice(1);
var uriType = getUriType(extension);
var uri = uriType + ';base64,' + data.toString('base64');
var info = {
transparent : false,
channels : 3,
data : data
transparent: false,
channels: 3,
data: data,
uri: uri
};
if (path.extname(imagePath) === '.png') {
if (path.extname(imagePath) === 'png') {
// Color type is encoded in the 25th bit of the png
var colorType = data[25];
var channels = getChannels(colorType);

View File

@ -268,12 +268,7 @@ function getImages(inputPath, materials, done) {
imagePath = path.join(inputPath, image);
}
loadImage(imagePath, function(info) {
var uri = 'data:application/octet-stream;base64,' + info.data.toString('base64');
imagesInfo[image] = {
transparent : info.transparent,
channels : info.channels,
uri : uri
};
imagesInfo[image] = info;
callback();
});
}, function (error) {